import type { NavigationOptions } from './navigation/get-navigation-options.js'; import { type OpenApiDocument, type OperationObject, type PathsObject } from './schemas/v3.2/strict/openapi-document.js'; import type { Workspace, WorkspaceDocumentMeta, WorkspaceMeta } from './schemas/workspace.js'; export declare const WORKSPACE_FILE_NAME = "scalar-workspace.json"; type WorkspaceDocumentMetaInput = { name: string; meta?: WorkspaceDocumentMeta; }; type UrlDoc = { url: string; } & WorkspaceDocumentMetaInput; type FileDoc = { path: string; } & WorkspaceDocumentMetaInput; type ObjectDoc = { document: Record; } & WorkspaceDocumentMetaInput; type WorkspaceDocumentInput = UrlDoc | ObjectDoc | FileDoc; type CreateServerWorkspaceStoreBase = { documents: WorkspaceDocumentInput[]; meta?: WorkspaceMeta; navigationOptions?: NavigationOptions; /** * Sends the sparse document in its compact form, for documents large enough that the sparse * document is itself a cost. * * It changes the wire shape only. The per-node chunk references under `components` and `paths` * are replaced by the `x-scalar-chunk-index` extension, which lists what exists and how a * reference to it is spelled, and `x-scalar-navigation` keeps its document entry but leaves its * children in a chunk. The client store expands the index as it ingests the document and loads * the children on request, so what it holds in memory — and everything reading from it — is * exactly what it would have held without this option. * * `getResolvedDocument()` is unaffected: it carries the whole document and its navigation either * way. AsyncAPI documents are unaffected too, since nothing about them is externalized. * * @default false */ compact?: boolean; }; type CreateServerWorkspaceStoreProps = ({ directory?: string; mode: 'static'; } & CreateServerWorkspaceStoreBase) | ({ baseUrl: string; mode: 'ssr'; } & CreateServerWorkspaceStoreBase); /** * Filters an OpenAPI PathsObject to only include standard HTTP methods. * Removes any vendor extensions or other non-HTTP properties. * * @param paths - The OpenAPI PathsObject to filter * @returns A new PathsObject containing only standard HTTP methods * * @example * Input: { * "/users": { * "get": {...}, * "x-custom": {...}, * "post": {...} * } * } * Output: { * "/users": { * "get": {...}, * "post": {...} * } * } */ export declare function filterHttpMethodsOnly(paths: PathsObject): Record>; /** * Escapes path keys in an OpenAPI PathsObject to be JSON Pointer compatible. * This is necessary because OpenAPI paths can contain characters that need to be escaped * when used as JSON Pointer references (like '/' and '~'). * * @example * Input: { "/users/{id}": { ... } } * Output: { "/users~1{id}": { ... } } */ export declare function escapePaths(paths: Record>): Record>; /** * Externalizes components by turning them into refs. */ export declare function externalizeComponentReferences(document: OpenApiDocument, meta: { mode: 'ssr'; name: string; baseUrl: string; } | { mode: 'static'; name: string; directory: string; }): Record>; /** * Externalizes paths operations by turning them into refs. */ export declare function externalizePathReferences(document: OpenApiDocument, meta: { mode: 'ssr'; name: string; baseUrl: string; } | { mode: 'static'; name: string; directory: string; }): Record; type ServerWorkspace = Omit; /** * Server workspace store interface */ export type ServerWorkspaceStore = { /** * Loads and registers a document in the workspace. * * Supported inputs include: * - `url`: fetch and parse an OpenAPI or AsyncAPI document from a remote URL * - `path`: read and parse an OpenAPI or AsyncAPI document from the filesystem * - `document`: use an in-memory OpenAPI or AsyncAPI object directly * * If loading fails, the document is not added. * * @example * ```ts * await store.addDocument({ * url: 'https://example.com/openapi.json', * name: 'petstore', * }) * * await store.addDocument({ * path: './specs/billing.yaml', * name: 'billing', * }) * ``` * * @param input - Source and metadata used to load and register the document */ addDocument: (input: WorkspaceDocumentInput, navigationOptions?: NavigationOptions) => Promise; /** * Generates chunk files for all loaded documents. * * Only available in `static` mode. Writes chunk files for: * - workspace metadata * - components (schemas, parameters, responses, etc.) * - operations (grouped by path and HTTP method) * * After generation, workspace references point to relative file paths. * * @example * ```ts * const store = await createServerWorkspaceStore({ * mode: 'static', * outputPath: './dist/workspace', * meta: { title: 'Docs' }, * }) * * await store.generateWorkspaceChunks() * ``` * * @throws {Error} If called when mode is not 'static' */ generateWorkspaceChunks: () => Promise; /** * Returns the current workspace payload. * * The payload contains workspace metadata plus sparse documents whose heavy * sections are replaced by references: * - in `ssr` mode, references resolve from in-memory assets * - in `static` mode, references point to generated chunk files * * @example * ```ts * const workspace = store.getWorkspace() * * // Read available document names * const names = Object.keys(workspace.documents) * ``` * * @returns Workspace metadata and document references used by the client */ getWorkspace: () => ServerWorkspace; /** * Resolves a chunk by JSON Pointer. * * Pointers can target component and operation chunks for loaded documents. * Returns `undefined` when the pointer does not resolve. * * @example * ```ts * // Resolve a component chunk * const userSchema = store.get('#/petstore/components/schemas/User') * * // Resolve an operation chunk * const listPets = store.get('#/petstore/operations/pets/get') * ``` * * @param pointer - JSON Pointer to the desired chunk * @returns The resolved chunk, or `undefined` when not found */ get: (pointer: string) => unknown; /** * Returns a document whole, with local references resolving, for rendering on the server. * * `getWorkspace()` hands back the sparse document: every component and operation is a reference * to a chunk, which is what the browser wants so it can load only what a page needs. A server * render wants the opposite — the complete document, read through one reference, with `$ref-value` * resolving locally and nothing fetched. That is the document the store built its navigation and * chunks from, so this is that object rather than a second copy: it shares the components and * operations the chunks are written from, and carries the same metadata and navigation as the * sparse document. * * It is a magic proxy, never reactive, so reading it costs a property lookup and a pointer * resolution. Use `getRaw` to serialize it: `$ref-value` is enumerable on the proxy and would * inline every referenced value beside its `$ref`. * * @example * ```ts * const document = store.getResolvedDocument('petstore') * * // A real operation, not a chunk reference * document?.paths?.['/pets']?.get * ``` * * @param name - The document name it was added under * @returns The resolved document, or `undefined` when no document has that name */ getResolvedDocument: (name: string) => ServerWorkspace['documents'][string] | undefined; }; /** * Create server state workspace store */ export declare function createServerWorkspaceStore(workspaceProps: CreateServerWorkspaceStoreProps): Promise; export {}; //# sourceMappingURL=server.d.ts.map