Metreeca Keep
    Preparing search index...

    Interface StoreClient

    Model-driven resource CRUD operations.

    Persists and retrieves linked data resources as shape-validated states and query projections.

    interface StoreClient {
        lookup<T extends Template>(
            request: { entry: string; shape: Lazy<ResourceShape>; model: T },
            opts?: {
                locale?: readonly string[];
                plain?: boolean;
                depth?: number;
                limit?: number;
            },
        ): Promise<Instance<T> | undefined>;
        create(
            request: { entry: string; shape: Lazy<ResourceShape>; state: Resource },
        ): Promise<string | undefined>;
        update(
            request: { entry: string; shape: Lazy<ResourceShape>; state: Resource },
        ): Promise<string | undefined>;
        delete(
            request: { entry: string; shape: Lazy<ResourceShape> },
        ): Promise<string | undefined>;
        insert(
            request: { entry: string; shape: Lazy<ResourceShape>; state: Resource },
            opts?: { depth?: number },
        ): Promise<string>;
        remove(
            request: { entry: string; shape: Lazy<ResourceShape> },
        ): Promise<string>;
    }

    Hierarchy (View Summary)

    Index

    Methods

    • Retrieve a resource.

      The result is shaped by the model Template: plain identifier properties are resolved from the shape's Instance<T> type, while computed bindings are derived from the template value.

      Note

      shape and model are kept distinct so that a single shape can serve many retrieval templates — for example, a server wiring one shape at startup and accepting any admissible model decoded from the client request on each call. Callers wanting the shape's own model as template MUST pass it explicitly via @metreeca/blue/value!model.

      Caution

      By default, model templates support the full query language, including aggregate transforms and nested expansion. When exposing retrieval to untrusted clients, restrict query complexity as required by setting plain to true, depth to 0 or a positive value, and/or limit to a maximum result set size.

      Type Parameters

      • T extends Template

        The retrieval template type

      Parameters

      • request: { entry: string; shape: Lazy<ResourceShape>; model: T }

        Retrieval specifications

        • Readonlyentry: string

          Absolute identifier of the resource to be retrieved

        • Readonlyshape: Lazy<ResourceShape>

          Resource shape driving the operation

        • Readonlymodel: T

          Retrieval template defining the data envelope

      • Optionalopts: { locale?: readonly string[]; plain?: boolean; depth?: number; limit?: number }

        Optional retrieval options

        • Optionallocale?: readonly string[]

          Tag priority list driving language negotiation for localised content; entries are matched in order of preference against the language tags available for each localised value. Implementations default this to ["und"] when omitted

        • Optionalplain?: boolean

          When true, rejects model templates carrying aggregate transforms (count, sum, min, max, avg); defaults to false, admitting the full query language

        • Optionaldepth?: number

          Maximum depth admitted for nested model expansion and query probe paths, each nesting level or path segment counting against the budget; 0 rejects any nested template while still accepting IRI references; omission leaves expansion unbounded

        • Optionallimit?: number

          Maximum value admitted for the # pagination constraint in model selections; a positive value caps the result set, rejecting any # exceeding it or set to 0 (unbounded) and injecting itself as a default where # is absent; omission, like 0, leaves result sets unbounded

      Returns Promise<Instance<T> | undefined>

      A promise resolving to an immutable copy of the resource data matching the specified model, or to undefined if the resource is not present in the store; rejects with a RangeError if entry is not an absolute IRI, a TraceError if model doesn't validate against the shape, or a Problem on network, storage, or other processing errors

      Error if the store has been closed

    • Create a resource.

      Stores the resource's own data if the resource doesn't already exist. Specific reference kinds are handled as follows:

      • embedded references — cascades recursively with the same semantics
      • captive references — accepted only as bare IRI references; inline captive batches are rejected, as state is always validated at depth 0. Use insert to embed a captive tree in a single batch
      • foreign references — skipped, as their data is owned by the defining resource

      Parameters

      • request: { entry: string; shape: Lazy<ResourceShape>; state: Resource }

        Creation specifications

        • Readonlyentry: string

          Absolute identifier of the target resource

        • Readonlyshape: Lazy<ResourceShape>

          Resource shape driving the operation

        • Readonlystate: Resource

          Initial property values for the new resource

      Returns Promise<string | undefined>

      A promise resolving to the entry Reference of the created resource, or to undefined if the resource already exists; rejects with a RangeError if entry is not an absolute IRI or if state carries an id differing from entry, a TraceError if state doesn't validate against the shape, or a Problem on network, storage, or other processing errors

      Error if the store has been closed

      insert for unconditional insertion

    • Update a resource.

      Replaces the resource's own data if the resource already exists, fully removing any previously existing embedded data. Specific reference kinds are handled as follows:

      • embedded references — cascades recursively with the same semantics
      • captive references — accepted only as bare IRI references; inline captive batches are rejected, as state is always validated at depth 0. Use insert to embed a captive tree in a single batch
      • foreign references — skipped, as their data is owned by the defining resource

      Parameters

      • request: { entry: string; shape: Lazy<ResourceShape>; state: Resource }

        Update specifications

        • Readonlyentry: string

          Absolute identifier of the target resource

        • Readonlyshape: Lazy<ResourceShape>

          Resource shape driving the operation

        • Readonlystate: Resource

          Complete replacement state for the resource

      Returns Promise<string | undefined>

      A promise resolving to the entry Reference of the updated resource, or to undefined if the resource doesn't exist; rejects with a RangeError if entry is not an absolute IRI or if state carries an id differing from entry, a TraceError if state doesn't validate against the shape, or a Problem on network, storage, or other processing errors

      Error if the store has been closed

      insert for unconditional insertion

    • Delete a resource.

      Removes the resource's own data and clears references to it from other resources, if the resource exists. Specific reference kinds are handled as follows:

      Parameters

      • request: { entry: string; shape: Lazy<ResourceShape> }

        Deletion specifications

        • Readonlyentry: string

          Absolute identifier of the target resource

        • Readonlyshape: Lazy<ResourceShape>

          Resource shape driving the operation

      Returns Promise<string | undefined>

      A promise resolving to the entry Reference of the deleted resource, or to undefined if the resource doesn't exist; rejects with a RangeError if entry is not an absolute IRI, or a Problem on network, storage, or other processing errors

      Error if the store has been closed

      remove for unconditional removal

    • Insert a resource.

      Unconditionally inserts or replaces the resource's own data, fully removing any previously existing embedded data. Specific reference kinds are handled as follows:

      • embedded references — cascades recursively with the same semantics
      • captive references — accepted as bare IRI references or, up to opts.depth nesting levels, as inline batches creating or updating the captive tree
      • foreign references — skipped, as their data is owned by the defining resource
      Caution

      By default, resources accept captive reference expansion to unbounded depth. To enforce a strict insertion process that admits only bare references, set opts.depth to 0 to reject all expansion; set it to a positive value to cap the nesting depth admitted.

      Parameters

      • request: { entry: string; shape: Lazy<ResourceShape>; state: Resource }

        Insertion specifications

        • Readonlyentry: string

          Absolute identifier of the target resource

        • Readonlyshape: Lazy<ResourceShape>

          Resource shape driving the operation

        • Readonlystate: Resource

          Complete resource state to be inserted

      • Optionalopts: { depth?: number }

        Optional insertion options

        • Optional Readonlydepth?: number

          Maximum nesting depth for expanding captive reference values as inline target resource states, each expansion level counting against the budget; 0 rejects all expansion, accepting bare IRI references only; omission leaves expansion unbounded

      Returns Promise<string>

      A promise resolving to the entry Reference of the inserted resource; rejects with a RangeError if entry is not an absolute IRI or if state carries an id differing from entry, a TraceError if state doesn't validate against the shape, or a Problem on network, storage, or other processing errors

      Error if the store has been closed

      • create for conditional creation
      • update for conditional replacement
    • Remove a resource.

      Unconditionally removes the resource's own data and clears references to it from other resources. Specific reference kinds are handled as follows:

      Parameters

      • request: { entry: string; shape: Lazy<ResourceShape> }

        Removal specifications

        • Readonlyentry: string

          Absolute identifier of the target resource

        • Readonlyshape: Lazy<ResourceShape>

          Resource shape driving the operation

      Returns Promise<string>

      A promise resolving to the entry Reference of the removed resource; rejects with a RangeError if entry is not an absolute IRI, or a Problem on network, storage, or other processing errors

      Error if the store has been closed

      delete for conditional removal