import { type DerivedManifest, type Handler, type HandlerContext, type LanesDecl, type ScreenDecl, type VendorManifest } from './derived-core.js'; import { compileSurface, type DerivedFetch, type DerivedSurface, type BoardFrame } from './derived.js'; import { type PackScenarioAdapter } from './scenario.js'; import type { ApplicationStandIn } from './events.js'; import { type SocketEngine } from './sockets.js'; import type { LiveEngine } from './live/types.js'; import type { WebSocketUpgrade } from './serve-http.js'; import { type GraphqlPart, type GraphqlLibraryLoader } from './graphql-wire.js'; /** What a pack declares and writes, and nothing it assembles itself. */ export type PackParts = { manifest: DerivedManifest; surface: DerivedSurface; /** `semantics/index.ts`: the handlers, by operationId. */ handlers?: Record; /** `semantics/doors.ts`: a door's answer, by the id the manifest's `doors` gives it. */ doors?: Record; /** Each `screens/.tsx`'s answer, by the id the manifest's `screens` gives it. */ screens?: Record; /** `semantics/around.ts`: what the vendor does around every request to its API, one the surface names or not (a key * checked, a plan's limits, a quota counted after a success), over a context whose operation is the request's (or * `unmatched`); `next` answers the request itself, or the one it is given (the vendor's own rewrite of it: a query * token moved to its header, a caller resolved into a header only the vendor's own front sets). */ around?: (ctx: HandlerContext, next: (request?: Request) => Promise) => Promise; /** `semantics/clock.ts`: the vendor's own moves the World clock has made due, caught up before anything is answered. * They are the vendor's, not the caller's: they land under a read-only request too. */ clock?: (ctx: HandlerContext) => Promise; /** `semantics/scenario.ts`: how the World's scenario decides a model vendor's turn — the operations it decides, the * request each is as the scenario reads it, and the vendor's own matchers and fault body (the adapter). */ scenario?: PackScenario; /** `semantics/gap.ts`: the vendor's answer for what it does not serve, where its manifest's `gap` cannot say it (Clerk's * Frontend API: Go's plain-text 404 for a path it does not have, `signed_out` for an operation asked without a * client), over a context whose operation is the one matched, or `unmatched`. */ gap?: (ctx: HandlerContext) => Response | Promise; /** `semantics/tenant.ts`: the tenant the caller acts in, which the core scopes the manifest's `tenant` by. */ tenant?: (ctx: HandlerContext) => string | undefined | Promise; /** The vendor's lanes, by the name the manifest's `lanes` routes give them: each its own pack fetch and manifest. */ lanes?: Record; /** `semantics/graphql.ts` with the vendor's schema (`generated/graphql-sdl.gen.json`): the GraphQL wire over the same * state, served at the manifest's `graphql.paths` (graphql-wire.ts). */ graphql?: GraphqlPart & { sdl: string; loadLibrary?: GraphqlLibraryLoader; }; /** `semantics/sockets.ts`: each socket's engine, by the id the manifest's `sockets` gives it (sockets.ts). */ sockets?: Record>; /** `semantics/board.ts`: the vendor's frames on the World's board, read from its state (`GET /twin/board`). */ board?: (ctx: HandlerContext) => BoardFrame[] | Promise; /** `semantics/live.ts`: each ingest's dialect, by the id the manifest's `live` gives it (live/ingest.ts). */ live?: Record>; }; /** A pack's scenario (`semantics/scenario.ts` exports `scenario`): the adapter the kernel's engine reads the World's * scenario document with, the operations it decides a turn of, and the request an operation is to it (undefined when * the request is not one it decides: the handler answers the vendor's refusal). */ export type PackScenario = { adapter: PackScenarioAdapter; operations: ReadonlyArray; request: (ctx: HandlerContext) => Req | undefined; }; /** A lane as its vendor's fetch is given it: its own pack fetch, and its manifest (the doors it declares). */ export type LanePart = { fetch: ((request: Request) => Promise) & { serves?: (method: string, path: string) => boolean; boards?: boolean; draws?: (url: string) => boolean; /** the hosts the lane's built content screens name: its vendor's router sends `/@/` there */ contentHosts?: ReadonlyArray; upgrade?: WebSocketUpgrade; ingest?: import('./twin-fetch.js').TwinStream; }; manifest: { doors?: ReadonlyArray<{ method: string; path: string; }>; }; }; /** Where a pack serves: its World's root, whether it was started read-only, the World instant when a caller pins it, the * and the World's managed Postgres the runtime binds a pack declaring `managedDatabase` to (a handler's `ctx.engine`). */ export type PackFetchOptions = { root?: string; readOnly?: boolean; clock?: () => string; database?: string; /** the application a walk stands in for: this fetch's requests and declared events are answered by it */ application?: ApplicationStandIn; }; /** The host a request is for: the vendor host the World's injector names, else its own. */ export declare const hostOf: (request: Request) => string; /** Where a workspace asked `?show=:` opens the record (architecture, "Workspace"): the built workspace page * that shows that type, its parameter the id; else the one that lists the type; else the workspace's home (its root * page). Every other parameter a page's path names is the asking page's, and a page that cannot be filled is passed * over. Undefined when nothing is asked; the path (with no `show`) otherwise. */ export declare function shownRecord(url: URL, workspaces: ReadonlyArray, params: Record): string | undefined; /** A declared World door, matched by the same normalized path for serving and response ownership. */ export declare function worldDoorMatcher(doors: ReadonlyArray): (method: string, path: string) => { door: Door; params: Record; } | undefined; /** A request with its path's repeated slashes merged, as a front that merges them routes it (the manifest's * `mergeSlashes`); one with none is itself. */ export declare function slashesMerged(request: Request): Request; /** The selected unit's request transformation, shared by serving and response judgment. */ export declare function unitRequestRouter(m: Pick, surface: DerivedSurface, routes: ReturnType): (request: Request) => Request; export declare function createPackFetch(parts: PackParts, options?: PackFetchOptions): DerivedFetch; /** The lane selected by the vendor gateway, shared by serving and response judgment. */ export declare function laneSelector(decl: LanesDecl, lanes: Record; }>, rootServes?: (method: string, path: string) => boolean): (request: Request) => string | undefined; export declare function createVendorFetch(manifest: VendorManifest, lanes: Record): DerivedFetch;