Metreeca Keep
    Preparing search index...

    Module @metreeca/keep-rest - v0.10.0

    REST/JSON proxy connector.

    Exposes the createRESTStore factory, returning an immutable store that forwards every Store call to a remote REST endpoint. Callers see the same Store surface as every other connector, with each operation round-tripped to the service rather than applied to a local backing store.

    Operation HTTP Prefer Behaviour Validated
    lookup GET Template in query string; 404undefined model, response
    create POST Child IRI from Location header; 409undefined state
    update PUT Conditional; 404undefined state
    delete DELETE Conditional; 404undefined
    insert PUT handling=lenient Unconditional upsert state
    remove DELETE handling=lenient Unconditional; 404 silently ignored
    Important

    Each HTTP verb is shared by a conditional and an unconditional method, disambiguated through the RFC 7240 Prefer request header:

    • Conditional (update via PUT, delete via DELETE) send bare requests, so the server rejects a missing target with 404.
    • Unconditional (insert via PUT, remove via DELETE) send Prefer: handling=lenient, so a PUT against a missing resource becomes an upsert and a DELETE against one succeeds silently.

    Servers that ignore the header degrade to the conditional 404 behaviour.

    Beyond the per-operation miss codes tabulated above, every other failure surfaces as a Problem rejection: non-OK responses as well as protocol anomalies on otherwise-successful responses (a missing Location header, a malformed response body). Callers therefore observe a single rejection type for all error origins.

    create resolves the returned Location against the request entry per RFC 3986 § 5.2 and returns it verbatim, including across origins: the proxy applies no same-origin or path-containment check, so callers MUST trust the service's choice of child IRI. Standard merge semantics apply, so an entry without a trailing / strips its last path segment before merging. An unparseable Location surfaces as a RangeError rather than a Problem.

    lookup encodes its model as a URL-safe base64 query string, so any template (filter operators such as ~name and >=price, nested shapes, aggregates) survives transport intact; an empty template omits the query string.

    Important

    entry parameters MUST be bare absolute IRIs with no query string (?…) or fragment (#…): a query string would collide with the base64 template appended by lookup, and a fragment would be stripped by fetch before the request reached the wire. The wrapping createValidatingStore rejects non-conforming entries with a RangeError on every method.

    The wrapping createValidatingStore validates inputs (model on lookup, state on every mutation) against the shape before the network call. Because the remote endpoint is untrusted, lookup responses are re-validated locally against the shape narrowed by the caller's model. Failures reject with a TraceError carrying "invalid model", "invalid state", or "invalid response", per the unified Store error channel.

    Functions

    createRESTStore

    Creates a REST proxy store backed by a remote REST service.