import type { WebSocketUpgrade } from './serve-http.js'; import type { TwinStream } from './twin-fetch.js'; /** The slice of a generated surface the dispatch reads. */ export type DerivedOperation = { id: string; method: string; path: string; class: string; resource?: string; /** query values that tell this operation from another at the same method and path */ discriminator?: Record; /** request headers that name the operation, for a wire whose operations share a path (AWS JSON's X-Amz-Target) */ headers?: Record; /** the status the vendor answers success with (201 for a create, 204 for an empty answer) */ successStatus?: number; /** how the spec says the request body is encoded (the derivation: json, form, multipart, none) */ bodyEncoding?: string; /** the success is documented with no content (a setting's update answered 200 and nothing else) */ emptySuccess?: boolean; /** a form-encoded operation's number and boolean fields, by bracket path (`items.[].quantity`, `metadata.*`) */ scalars?: Readonly>; /** a form-encoded operation's string fields that take only listed values, by the same bracket path */ enums?: Readonly>>; /** what the success answer is: a resource, a list of them, and the envelope key holding it */ answers?: { resource: string; list: boolean; key?: string; }; /** the path its own server puts before it, where the operation names a server other than the surface's */ basePath?: string; /** the query's declared parameters (a strict body checks what is not one of them) */ query?: ReadonlyArray<{ name: string; type: string; required?: boolean; }>; /** the credential scopes any one of which lets a caller make the call, and the security schemes it is made with * (`anonymous` where it may also go without; absent when it takes none), from the spec's security */ scopes?: ReadonlyArray; credentials?: ReadonlyArray; /** the body's declared fields: name, type, and the numeric bounds the spec states (a strict body, `ctx.fields`) */ body?: ReadonlyArray<{ name: string; type: string; required?: boolean; minimum?: number | string; maximum?: number | string; }>; }; /** `basePath` is what the vendor's server URL puts before every operation path; `spanning` names the * path parameters whose values may hold slashes (a git ref, a file path), which no spec says. */ export type DerivedSurface = { graphql?: { sdl: string; }; format?: string; commands?: ReadonlyArray<{ id: string; }>; version: string; basePath?: string; spanning?: ReadonlyArray; operations: ReadonlyArray; /** Generated schema facts a handler can read without importing or interpreting the vendor spec. */ resources?: ReadonlyArray<{ name: string; variants?: { discriminator: string; required: Readonly>; }; }>; }; /** What a semantics handler receives: the request, the operation it matched, and its path parameters. */ export type DerivedCall = { request: Request; operation: DerivedOperation; params: Record; /** a World screen's call, which no perform sends again: a body in a media type the core does not read (anything * but JSON, a form, multipart or text) is the handler's alone, left unread and unrecorded, so an upload streams */ streamed?: true; }; export declare function bodyTextOf(request: Request): Promise; /** The body's text, as JSON, or undefined when it is not JSON; the parse is kept for the first taker. */ export declare function checkJsonBody(request: Request): Promise; /** The guard's parse of this request's body, taken once (a clone of a tagged request shares its key). */ export declare function takeParsedBody(request: Request): { value: unknown; } | undefined; export type DerivedHandler = (call: DerivedCall) => Promise; /** What the derived core made of an operation: an answer, or why it cannot model it. */ export type DerivedCoreOutcome = { served: Response; } | { unmodeled: string; }; export type DerivedFetchOptions = { surface: DerivedSurface; /** Semantics handlers by operationId. A handler naming an operation the surface lacks is refused. */ handlers?: Record; /** The derived core, and which operations it owns (those of the resources the manifest declares). */ core?: { owns: (operation: DerivedOperation) => boolean; serve: (call: DerivedCall) => Promise; }; /** An RPC wire: every method is reached by any HTTP method (Slack's clients POST reads too). */ anyMethod?: boolean; /** What every operation a handler or the core serves passes through (read-only refusal, version * checks, idempotent replay). */ around?: (call: DerivedCall, next: () => Promise) => Promise; /** The vendor's answer for an operation nothing models: the pack's gap. */ gap: (request: Request, operation: DerivedOperation | undefined, reason: string) => Response | Promise; }; type Route = { operation: DerivedOperation; pattern: RegExp; names: string[]; literals: number; }; /** Routes per method, most literal segments first, so `/v1/customers/search` wins over `/v1/customers/{customer}`. */ export declare function compileSurface(surface: DerivedSurface): Map; export declare function matchOperation(routes: Map, method: string, pathname: string, query?: URLSearchParams, headers?: Headers): { operation: DerivedOperation; params: Record; } | undefined; /** The path's template parameters for a request no operation matches (a CORS preflight, a method the path is not * served by): read from the most literal route of any method whose path the request's path fits, discriminators * aside, so `around` and `gap` know the resource the URL names without parsing it (S3's OPTIONS on `/{Bucket}/{Key+}`). */ export declare function pathParams(routes: Map, pathname: string): Record; export type DerivedOwner = 'handler' | 'core' | 'gap'; /** The header the kernel carries a path prefix's named groups in, from routing to the call (never a client's). */ export declare const PREFIX_PARAMS_HEADER = "x-volter-path-prefix-params"; export type DerivedFetch = ((request: Request) => Promise) & { /** Per operationId, who serves it: a semantics handler, the derived core, the pack's existing * fetch while it moves, or nothing (the vendor's gap). */ owners(): Record; /** A vendor's owners by unit: its own API's under `''`, each lane's under the lane's name, each keyed by the unit's own * operation ids (an id two units share is two operations, each served or the gap on its own). `owners()` is this map * flat, a lane's ids written `:`. A fetch with no lanes may leave it out: its one unit is `owners()`. */ ownersByUnit?(): Record>; /** The vendor's sockets (sockets.ts), for the serve seam to upgrade to, when its manifest declares any. */ upgrade?: WebSocketUpgrade; /** The vendor's RTMP ingest (live/ingest.ts), for its server to serve on its side port (`serveStream`), when its * manifest declares `live`. */ ingest?: TwinStream; maxRequestBodySize?: number; /** The workspace screens it draws, its lanes' too (`GET /twin`'s `screens`). */ workspaces?(): Workspace[]; /** Whether it lays out frames of the World's board (`semantics/board.ts`). */ boards?: boolean; /** Whether a built screen of it takes a URL: a board frame it draws. */ draws?(url: string): boolean; /** The hosts its built content screens name: a vendor's lane router sends `/@/` for one of them to * this fetch (pack-fetch.ts). */ contentHosts?: ReadonlyArray; }; /** A workspace screen a pack draws, as `GET /twin` lists it: its id and path (Viewing a World). */ export type Workspace = { id: string; path: string; host?: string; }; /** A page of the World's board (architecture, "The board"): a page there is to see at the vendor, a record's own (an * account's profile, each of its posts, a site and each page it serves), as the vendor's pack lists them from its state * (`semantics/board.ts`). Every field is a fact of the World's state: which of them a person looks at is the board's * choice, never the pack's. `GET /twin/board` lists them. */ export type BoardFrame = { /** stable within the vendor, whatever the World's ids: what a saved board names the frame by */ id: string; /** what it is, in the vendor's own word (a site, a repository, a board) */ kind: string; title: string; /** the vendor's container it is grouped under (an account, an organization, a project); `aka`, the ids it was known * by before (an account a deploy adopted), so a board that included it under one still holds it */ section: { id: string; title: string; aka?: string[]; }; /** where the vendor shows it: an absolute URL on the vendor's host, or on a hostname the vendor serves for its customer */ url: string; /** the records whose changes are this frame's changes */ covers: Array<{ type: string; id: string; }>; /** the id of the page it sits under at the vendor (a post under its author's profile, a site's page under its site): * a board showing everything shows a page with no parent and opens the pages under it from there */ parent?: string; /** the World's own: an account the World's applications or people act as, a page of one, a site the World serves */ ours?: boolean; /** set by the kernel, never the pack: whether a built screen of the vendor's (any of its lanes') draws the url */ drawn?: boolean; }; /** Host-side measurement of actual dispatch, including declared gaps. It changes no request or answer. */ export type DerivedDispatch = { surface: DerivedSurface; operation: DerivedOperation; owner: DerivedOwner; }; export declare function observeDerivedDispatch(observer: (dispatch: DerivedDispatch) => void): () => void; export declare function createDerivedFetch(options: DerivedFetchOptions): DerivedFetch; export {};