@grafctory/gate - v0.18.0
    Preparing search index...

    Type Alias Driver

    Driver: RequestHandler & {
        lookup(
            hooks?: {
                model?: Template | ((request: Request) => Template);
                review?: (
                    match: Resource,
                    request: Request,
                ) => Optional<Resource> | Promise<Optional<Resource>>;
            },
        ): Driver;
        create(
            hooks?: {
                decode?: (
                    state: unknown,
                    request: Request,
                ) => unknown | Promise<unknown>;
            },
        ): Driver;
        update(
            hooks?: {
                decode?: (
                    state: unknown,
                    request: Request,
                ) => unknown | Promise<unknown>;
            },
        ): Driver;
        delete(): Driver;
    }

    Model-driven resource driver.

    Serves a resource through the HTTP methods enabled on it: its retrieval, the creation of new resources in the collection it holds, its replacement and its removal, so that one driver serves containers, items and standalone resources alike, each enabling only the methods its role in the API calls for and answering others with 405.

    Type Declaration

    • lookup: function
      • Enables GET and HEAD, retrieving the resource.

        The query component of the request selects what to retrieve. It may state a @grafctory/qest template, or form-encoded criteria filtering the collection the resource holds, as a client filtering a list would state them. An empty query retrieves the default view the shape describes. Localised content is negotiated through the Accept-Language header, as @grafctory/qest prescribes. The server locale serves requests accepting any language or stating no such header. Values tagged with no language are served whatever the header states.

        Every response is marked as varying by Accept-Language, so that HTTP caches keep each language apart.

        • 200 OK with the resource as JSON
        • 404 Not Found where the store holds no such resource and the driver is not virtual, or review withholds it

        Parameters

        • Optionalhooks: {
              model?: Template | ((request: Request) => Template);
              review?: (
                  match: Resource,
                  request: Request,
              ) => Optional<Resource> | Promise<Optional<Resource>>;
          }

          Retrieval hooks; if omitted, the shape alone describes what clients may retrieve

          • Optional Readonlymodel?: Template | ((request: Request) => Template)

            The server template fixing the entries it states and the collection views clients filter within; if omitted, the shape alone describes what clients may retrieve, hidden members included. A function is called for each request, so the view may depend on the caller, as when scoping a collection to a tenant

          • Optional Readonlyreview?: (
                match: Resource,
                request: Request,
            ) => Optional<Resource> | Promise<Optional<Resource>>

            Reviews the retrieved resource before it is served, returning the resource to send, or undefined to answer 404 Not Found as if the store held none, as when the caller may not see it

        Returns Driver

        This driver

    • create: function
      • Enables POST, creating a resource from the request body in the collection the resource holds.

        The body is validated against the shape of the collected resources. A body stating no identifier is named after the Slug header, or given a generated name where the header is missing or holds no letter or digit.

        • 201 Created with a Location header pointing to the new resource
        • 409 Conflict where the store refuses to create the resource, as when its identifier is taken

        Parameters

        • Optionalhooks: { decode?: (state: unknown, request: Request) => unknown | Promise<unknown> }

          Write hooks

          • Optional Readonlydecode?: (state: unknown, request: Request) => unknown | Promise<unknown>

            Prepares the decoded JSON body of each request before it is validated, so that defaults may be filled in or values derived from the request, as when stamping the resource with its author

        Returns Driver

        This driver

        TypeError Where the driver is virtual, or the shape holds no collection ranging over resources, or several, so that no single collection can receive the new resources

    • update: function
      • Enables PUT, replacing the resource with the request body, validated against the shape.

        The resource keeps the identifier of the request target, so a client cannot redirect the update elsewhere: a body naming another resource is rejected with 422 Unprocessable Content, and one naming none is completed.

        • 204 No Content where the resource is replaced
        • 404 Not Found where the store holds no such resource

        Parameters

        • Optionalhooks: { decode?: (state: unknown, request: Request) => unknown | Promise<unknown> }

          Write hooks

          • Optional Readonlydecode?: (state: unknown, request: Request) => unknown | Promise<unknown>

            Prepares the decoded JSON body of each request before it is validated, so that defaults may be filled in or values derived from the request, as when stamping the resource with its author

        Returns Driver

        This driver

        TypeError Where the driver is virtual

    • delete: function
      • Enables DELETE, removing the resource along with the embedded and captive data the shape ties to it.

        • 204 No Content where the resource is removed
        • 404 Not Found where the store holds no such resource

        Returns Driver

        This driver

        TypeError Where the driver is virtual