import type { TraversedDocument } from '../schemas/navigation.js'; /** * The extension key a compact sparse document carries its chunk index under. * * It exists on the wire only: the client expands the index back into per-node references while the * document is ingested and removes the key, so nothing downstream ever sees it. */ export declare const CHUNK_INDEX_KEY = "x-scalar-chunk-index"; /** Where a document's chunks live, which decides how each reference to one is spelled. */ export type ChunkMode = 'static' | 'ssr'; /** The `$ref` template for each kind of chunk, with `{…}` slots the writer fills in. */ export type ChunkRefTemplates = { /** Slots: `{type}`, `{name}`. */ components: string; /** Slots: `{path}`, `{method}`. */ operations: string; /** No slots. */ navigation: string; }; /** * The compact stand-in for a sparse document's `components` and `paths`. * * Every reference the non-compact form spells out node by node is derivable from where that node * sits, so the index carries the positions and one template per kind instead. What a path item * keeps besides its operations is not derivable, so it rides along verbatim. */ export type ChunkIndex = { mode: ChunkMode; /** * The templates the reader expands. * * The navigation chunk is not one of them: the document names it directly, under * `x-scalar-navigation-chunk`, because that reference has to outlive the index — it is read when * the navigation children are loaded, long after the index is expanded and dropped. */ refs: Omit; /** Component names per component type, in document order. */ components: Record; /** * Each path item with its operations replaced by a placeholder. * * The whole path item is kept rather than a list of methods so that both its key order and the * keys that were never externalized survive: `parameters`, `summary`, `servers` and extensions * all stay inline in the non-compact form. */ paths: Record>; }; /** * Fills the `{slot}`s of a chunk-reference template. * * `{{` and `}}` stand for literal braces, so text the writer inlined into a template — a document * name, a base URL — may contain braces without being read back as a slot. An unknown slot is left * alone rather than blanked, so a template from a newer writer fails visibly instead of resolving * to the wrong chunk. */ export declare const fillChunkRef: (template: string, values?: Record) => string; /** * Builds the reference templates for one document. * * Filled, these produce exactly the references `externalizeComponentReferences` and * `externalizePathReferences` write, so a client that expands the index lands on the same chunk. */ export declare const chunkRefTemplates: (meta: { mode: "ssr"; name: string; baseUrl: string; } | { mode: "static"; name: string; }) => ChunkRefTemplates; /** The reference a lazily loaded chunk is reached through. */ export declare const chunkReference: (ref: string) => { $ref: string; $global: true; }; /** * The navigation a compact document carries inline: the document entry without its children. * * Navigation is store metadata rather than part of the description, and every reader takes it by * plain property access — `name` keys the auth and history stores, `title` and `icon` render the * document header — so it is never a reference in any mode. Only the children are externalized, * since they are what makes a navigation tree large. They start as an empty array, so a reader * iterating them before they are loaded sees an empty sidebar rather than an error. */ export declare const navigationHeader: ({ children: _children, ...header }: TraversedDocument) => TraversedDocument; /** * Compacts a sparse document's `components` and `paths` into an index. * * Takes the sections the externalizers produced rather than the document itself, so the index is * built from the very references it replaces and the two cannot come to describe different sets of * chunks. */ export declare const buildChunkIndex: ({ mode, refs, components, paths, }: { mode: ChunkMode; refs: ChunkRefTemplates; components: Record>; paths: Record>; }) => ChunkIndex; /** * Expands a compact sparse document into the one a non-compact server store would have sent. * * Mutates the document in place and drops the index key, so what the rest of the store sees is an * ordinary sparse document: `resolve()`, the bundler and anything enumerating `paths` or * `components` are looking at the shape they always have. * * A document without an index is left alone, which is every document a non-compact server store or * an author produces. * * @param document - The document to expand, mutated in place * @returns Whether an index was found and expanded */ export declare const expandChunkIndex: (document: unknown) => boolean; //# sourceMappingURL=chunk-index.d.ts.map