@docs-sdk-dev/reader 0.0.0-stage → 0.4.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +97 -2
- package/dist/annotation-projection.d.ts +35 -0
- package/dist/annotation-projection.js +78 -0
- package/dist/annotation-projection.js.map +1 -0
- package/dist/artifacts.d.ts +19 -0
- package/dist/artifacts.js +33 -0
- package/dist/artifacts.js.map +1 -0
- package/dist/ask.d.ts +41 -0
- package/dist/ask.js +89 -0
- package/dist/ask.js.map +1 -0
- package/dist/collection-view.d.ts +190 -0
- package/dist/collection-view.js +170 -0
- package/dist/collection-view.js.map +1 -0
- package/dist/composition.d.ts +199 -0
- package/dist/composition.js +473 -0
- package/dist/composition.js.map +1 -0
- package/dist/condition.d.ts +17 -0
- package/dist/condition.js +61 -0
- package/dist/condition.js.map +1 -0
- package/dist/content-schema.d.ts +182 -0
- package/dist/content-schema.js +288 -0
- package/dist/content-schema.js.map +1 -0
- package/dist/context-search.d.ts +168 -0
- package/dist/context-search.js +73 -0
- package/dist/context-search.js.map +1 -0
- package/dist/context-store.d.ts +93 -0
- package/dist/context-store.js +438 -0
- package/dist/context-store.js.map +1 -0
- package/dist/dimension-runtime.d.ts +203 -0
- package/dist/dimension-runtime.js +737 -0
- package/dist/dimension-runtime.js.map +1 -0
- package/dist/dimensions.d.ts +84 -0
- package/dist/dimensions.js +136 -0
- package/dist/dimensions.js.map +1 -0
- package/dist/directory-navigation.d.ts +60 -0
- package/dist/directory-navigation.js +41 -0
- package/dist/directory-navigation.js.map +1 -0
- package/dist/directory-sections.d.ts +9 -0
- package/dist/directory-sections.js +76 -0
- package/dist/directory-sections.js.map +1 -0
- package/dist/document-reader.d.ts +1017 -0
- package/dist/document-reader.js +396 -0
- package/dist/document-reader.js.map +1 -0
- package/dist/document-selection.d.ts +412 -0
- package/dist/document-selection.js +45 -0
- package/dist/document-selection.js.map +1 -0
- package/dist/evidence.d.ts +102 -0
- package/dist/evidence.js +104 -0
- package/dist/evidence.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +23 -0
- package/dist/model.d.ts +89 -0
- package/dist/model.js +31 -0
- package/dist/model.js.map +1 -0
- package/dist/module.d.ts +657 -0
- package/dist/module.js +199 -0
- package/dist/module.js.map +1 -0
- package/dist/navigation-view.d.ts +33 -0
- package/dist/navigation-view.js +68 -0
- package/dist/navigation-view.js.map +1 -0
- package/dist/node.d.ts +2004 -0
- package/dist/node.js +210 -0
- package/dist/node.js.map +1 -0
- package/dist/open-docs.d.ts +1396 -0
- package/dist/open-docs.js +198 -0
- package/dist/open-docs.js.map +1 -0
- package/dist/outline.d.ts +97 -0
- package/dist/outline.js +171 -0
- package/dist/outline.js.map +1 -0
- package/dist/persistence.d.ts +82 -0
- package/dist/persistence.js +377 -0
- package/dist/persistence.js.map +1 -0
- package/dist/projection-catalog.d.ts +23 -0
- package/dist/projection-catalog.js +45 -0
- package/dist/projection-catalog.js.map +1 -0
- package/dist/publication.d.ts +59 -0
- package/dist/publication.js +11 -0
- package/dist/publication.js.map +1 -0
- package/dist/reader.d.ts +236 -0
- package/dist/reader.js +400 -0
- package/dist/reader.js.map +1 -0
- package/dist/references.d.ts +54 -0
- package/dist/references.js +70 -0
- package/dist/references.js.map +1 -0
- package/dist/retrieval.d.ts +82 -0
- package/dist/retrieval.js +135 -0
- package/dist/retrieval.js.map +1 -0
- package/dist/search-view.d.ts +11 -0
- package/dist/search-view.js +30 -0
- package/dist/search-view.js.map +1 -0
- package/dist/search.d.ts +95 -0
- package/dist/search.js +234 -0
- package/dist/search.js.map +1 -0
- package/dist/semantic.d.ts +177 -0
- package/dist/semantic.js +104 -0
- package/dist/semantic.js.map +1 -0
- package/dist/skills.d.ts +21 -0
- package/dist/skills.js +42 -0
- package/dist/skills.js.map +1 -0
- package/docs/index.md +10 -0
- package/docs/sdk/composition.md +72 -0
- package/docs/sdk/reader-storage.md +70 -0
- package/docs/sdk/reader.md +99 -0
- package/docs/zh-CN/sdk/composition.md +72 -0
- package/docs/zh-CN/sdk/reader-storage.md +70 -0
- package/docs/zh-CN/sdk/reader.md +99 -0
- package/package.json +69 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reader.js","names":[],"sources":["../src/reader.ts"],"sourcesContent":["export * from \"./document-reader.js\"\nimport { openPinnedReader, type PublicationHost } from \"./document-reader.js\"\nimport { DocsError, type Provenance } from \"./model.js\"\nexport type { Resolution } from \"./semantic.js\"\nimport {\n resolveContext,\n type Resolution,\n canonicalJson,\n relationId,\n shardKey,\n variantId,\n type Context,\n type EntityVariant,\n type ExternalReference,\n type Relation,\n type RelationType,\n type SemanticEntity,\n type SemanticIndex,\n type SemanticPointer,\n type SemanticShard,\n} from \"./semantic.js\"\n\nexport type { ExternalReference } from \"./semantic.js\"\n\nexport function createReferenceReader(\n publications: readonly { project: string; inventoryRevision: string; host: PublicationHost }[],\n) {\n async function open(revision: string, host: PublicationHost) {\n const publication = await openPinnedReader(revision, host)\n if (!publication.manifest.semantic)\n throw new DocsError(\"DOCS_SEMANTIC_MISSING\", \"This publication has no semantic index.\")\n return createSemanticLoader(publication.manifest.semantic, publication.readText)\n }\n type Entry = { host: PublicationHost; reader?: ReturnType<typeof open> }\n const projects = new Map<string, Map<string, Entry>>()\n for (const { project, inventoryRevision, host } of publications) {\n const versions = projects.get(project) ?? new Map<string, Entry>()\n if (\n !project.trim() ||\n !/^[a-f0-9]{64}$/.test(inventoryRevision) ||\n versions.has(inventoryRevision)\n )\n throw new DocsError(\n \"DOCS_REFERENCE_INVALID\",\n \"Expected a distinct project and SHA-256 publication pair.\",\n { source: project },\n )\n versions.set(inventoryRevision, { host })\n projects.set(project, versions)\n }\n async function lookup({ project, inventoryRevision }: ExternalReference) {\n const versions = projects.get(project)\n if (!versions) return { status: \"unknown-project\" as const, project }\n const entry = versions.get(inventoryRevision)\n if (!entry) return { status: \"unknown-publication\" as const, project, inventoryRevision }\n entry.reader ??= open(inventoryRevision, entry.host).catch((error) => {\n delete entry.reader\n throw error\n })\n return { status: \"opened\" as const, reader: await entry.reader }\n }\n async function resolve(reference: ExternalReference) {\n const opened = await lookup(reference)\n return opened.status === \"opened\"\n ? opened.reader.resolve(reference.entity, reference.context)\n : opened\n }\n async function trace(start: ExternalReference, maxSteps = 64) {\n if (!Number.isSafeInteger(maxSteps) || maxSteps < 1)\n throw new DocsError(\"DOCS_TRACE_LIMIT\", \"Expected a positive traversal bound.\")\n const pending: { reference: ExternalReference; from?: number }[] = []\n const seen = new Set<string>()\n function add(reference: ExternalReference, from?: number) {\n const key = canonicalJson([\n reference.project,\n reference.inventoryRevision,\n reference.entity,\n reference.context ?? {},\n ])\n if (seen.has(key)) return\n if (pending.length >= maxSteps)\n throw new DocsError(\"DOCS_TRACE_LIMIT\", `Trace exceeds ${maxSteps} references.`)\n seen.add(key)\n pending.push({ reference, ...(from !== undefined && { from }) })\n }\n add(start)\n const steps: {\n reference: ExternalReference\n from?: number\n result: Awaited<ReturnType<typeof resolve>>\n }[] = []\n for (const [position, step] of pending.entries()) {\n const opened = await lookup(step.reference)\n const context = step.reference.context ?? {}\n const result =\n opened.status === \"opened\"\n ? await opened.reader.resolve(step.reference.entity, context)\n : opened\n steps.push({ ...step, result })\n if (opened.status !== \"opened\" || result.status !== \"exact\") continue\n for (const edge of await opened.reader.relations(step.reference.entity, { context })) {\n if (\n edge.propagatesImpact ||\n edge.type === \"contains\" ||\n edge.type === \"derivedFrom\" ||\n edge.type === \"references\"\n )\n add(\n { ...step.reference, entity: edge.target, context: edge.targetContext ?? context },\n position,\n )\n }\n for (const ref of result.value.externalReferences ?? []) add(ref, position)\n }\n return steps\n }\n\n async function findConsumers(\n target: ExternalReference,\n variant: string,\n roots: readonly ExternalReference[],\n maxSteps: number,\n ) {\n const matches: { root: ExternalReference; path: ExternalReference[] }[] = []\n const unchecked: { root: ExternalReference; reference: ExternalReference; reason: string }[] =\n []\n for (const root of roots) {\n const steps = await trace(root, maxSteps)\n let match: number | undefined\n for (const [index, step] of steps.entries()) {\n if (step.result.status !== \"exact\")\n unchecked.push({ root, reference: step.reference, reason: step.result.status })\n else if (\n match === undefined &&\n step.reference.project === target.project &&\n step.reference.inventoryRevision === target.inventoryRevision &&\n step.result.value.variantId === variant\n )\n match = index\n }\n if (match !== undefined) {\n const path: ExternalReference[] = []\n for (let index: number | undefined = match; index !== undefined; index = steps[index]!.from)\n path.push(steps[index]!.reference)\n matches.push({ root, path: path.reverse() })\n }\n }\n return { consumers: matches, unchecked }\n }\n /** Check only the supplied consumer roots. A missing registration or edition stays visible in the report. */\n async function consumers(\n target: ExternalReference,\n roots: readonly ExternalReference[],\n maxSteps = 64,\n ) {\n const resolved = await resolve(target)\n if (resolved.status !== \"exact\") return resolved\n return {\n status: \"exact\" as const,\n target,\n ...(await findConsumers(target, resolved.value.variantId, roots, maxSteps)),\n }\n }\n /** Review a candidate publication in the same project and context. Consumer paths still refer to the original pin. */\n async function review(\n target: ExternalReference,\n candidateInventoryRevision: string,\n roots: readonly ExternalReference[],\n maxSteps = 64,\n ) {\n const candidate = { ...target, inventoryRevision: candidateInventoryRevision }\n const before = await resolve(target)\n if (before.status !== \"exact\")\n return { status: \"baseline-unavailable\" as const, target, candidate, before }\n const [after, usage] = await Promise.all([\n resolve(candidate),\n findConsumers(target, before.value.variantId, roots, maxSteps),\n ])\n if (after.status !== \"exact\")\n return {\n status: \"candidate-unavailable\" as const,\n target,\n candidate,\n before,\n after,\n ...usage,\n }\n const sorted = (values: readonly unknown[] = []) =>\n canonicalJson(values.map(canonicalJson).sort())\n return {\n status: \"exact\" as const,\n target,\n candidate,\n before,\n after,\n ...usage,\n changes: {\n variant: before.value.variantId !== after.value.variantId,\n facts:\n canonicalJson({ data: before.value.data }) !== canonicalJson({ data: after.value.data }),\n provenance: sorted(before.value.provenance) !== sorted(after.value.provenance),\n externalReferences:\n sorted(before.value.externalReferences) !== sorted(after.value.externalReferences),\n },\n }\n }\n return { resolve, trace, consumers, review }\n}\n\nexport interface TraceOptions {\n maxSteps?: number\n includeEditions?: boolean\n}\n\nexport interface TraceStep {\n entity: string\n type: SemanticEntity[\"type\"]\n variant: string\n /** The relation followed to reach this entity; absent for the starting entity. */\n via?: { relation: string; type: RelationType; from: string; fromVariant?: string }\n /** The variant's facts, such as a prop's type and required flag. Absent when the entity has no variant for the context. */\n data?: unknown\n provenance: Provenance[]\n}\nexport type RelationQuery = { type?: RelationType; direction?: \"out\" | \"in\"; context?: Context }\n\nconst applies = (required?: Context, context?: Context) =>\n !context || !required || Object.entries(required).every(([key, value]) => context[key] === value)\nconst relationOrder = (left: Relation, right: Relation) =>\n (left.order ?? Infinity) - (right.order ?? Infinity)\nconst traceOrder = (left: Relation, right: Relation) =>\n relationOrder(left, right) || (left.id < right.id ? -1 : left.id > right.id ? 1 : 0)\n\n/** Mutable lookup tables shared by the in-memory reader and the shard loader. */\nfunction createStore() {\n const entities = new Map<string, SemanticEntity>()\n const relations = new Map<string, Relation>()\n const outgoing = new Map<string, Relation[]>()\n const incoming = new Map<string, Relation[]>()\n function add(index: Pick<SemanticIndex, \"entities\" | \"relations\">) {\n for (const entity of index.entities) entities.set(entity.id, entity)\n for (const relation of index.relations) {\n if (relations.has(relation.id)) continue\n relations.set(relation.id, relation)\n const out = outgoing.get(relation.source)\n if (out) out.push(relation)\n else outgoing.set(relation.source, [relation])\n const into = incoming.get(relation.target)\n if (into) into.push(relation)\n else incoming.set(relation.target, [relation])\n }\n }\n const resolve = (id: string, context: Context = {}): Resolution<EntityVariant> =>\n resolveContext(entities.get(id)?.variants ?? [], context)\n function matchingRelations(id: string, options: RelationQuery) {\n const list = options.direction === \"in\" ? (incoming.get(id) ?? []) : (outgoing.get(id) ?? [])\n return list.filter(\n (relation) =>\n (!options.type || relation.type === options.type) &&\n applies(\n options.direction === \"in\"\n ? (relation.targetContext ?? relation.context)\n : relation.context,\n options.context,\n ),\n )\n }\n function relationsOf(id: string, options: RelationQuery = {}) {\n return matchingRelations(id, options).sort(relationOrder)\n }\n /** Yield missing entities one frontier at a time so the shard reader can load them before resolving the layer. */\n function* trace(\n id: string,\n context: Context = {},\n { maxSteps, includeEditions }: TraceOptions = {},\n ): Generator<string[], Resolution<TraceStep[]>> {\n if (maxSteps !== undefined && (!Number.isSafeInteger(maxSteps) || maxSteps < 1))\n throw new DocsError(\"DOCS_TRACE_LIMIT\", \"maxSteps must be a positive safe integer.\", {\n field: \"maxSteps\",\n })\n const steps: TraceStep[] = []\n const visitKey = (entity: string, edition: Context) =>\n includeEditions ? canonicalJson([entity, edition]) : entity\n const seen = new Set([visitKey(id, context)])\n type PendingStep = Pick<TraceStep, \"entity\" | \"via\"> & { context: Context }\n let frontier: PendingStep[] = [{ entity: id, context }]\n while (frontier.length) {\n const missing = frontier\n .filter((step) => !entities.has(step.entity))\n .map((step) => step.entity)\n if (missing.length) yield missing\n const next: PendingStep[] = []\n for (const step of frontier) {\n const found = entities.get(step.entity)\n const resolution = resolveContext(found?.variants ?? [], step.context)\n if (resolution.status !== \"exact\") {\n if (!step.via) return resolution\n steps.push({\n entity: step.entity,\n type: found?.type ?? \"unknown\",\n variant: step.entity,\n via: step.via,\n provenance: [],\n })\n continue\n }\n const { variantId, data, provenance } = resolution.value\n steps.push({\n entity: step.entity,\n type: found!.type,\n variant: variantId,\n ...(step.via && { via: step.via }),\n data,\n provenance,\n })\n for (const relation of matchingRelations(step.entity, { context: step.context }).sort(\n traceOrder,\n )) {\n const pinned =\n includeEditions &&\n relation.targetContext !== undefined &&\n [\"derivesFrom\", \"variantOf\", \"supersedes\"].includes(relation.type)\n if (\n !pinned &&\n !relation.propagatesImpact &&\n relation.type !== \"derivedFrom\" &&\n relation.type !== \"contains\"\n )\n continue\n const nextContext = pinned ? relation.targetContext! : step.context\n const key = visitKey(relation.target, nextContext)\n if (seen.has(key)) continue\n if (seen.size === maxSteps)\n throw new DocsError(\n \"DOCS_TRACE_LIMIT\",\n `Trace exceeds the requested limit of ${maxSteps} entities.`,\n { field: \"maxSteps\" },\n )\n seen.add(key)\n next.push({\n entity: relation.target,\n context: nextContext,\n via: {\n relation: relation.id,\n type: relation.type,\n from: step.entity,\n ...(includeEditions && { fromVariant: variantId }),\n },\n })\n }\n }\n frontier = next\n }\n return { status: \"exact\", value: steps }\n }\n return {\n entities,\n all: () => [...relations.values()],\n add,\n resolve,\n relations: relationsOf,\n trace,\n }\n}\n\n/** Read Runtime over a complete in-memory semantic index. It needs no build toolchain, file system or DOM. */\nexport function createSemanticReader(index: SemanticIndex) {\n const store = createStore()\n store.add(index)\n return {\n entity: (id: string): SemanticEntity | null => store.entities.get(id) ?? null,\n entities: (filter: { type?: string } = {}) =>\n index.entities.filter((entity) => !filter.type || entity.type === filter.type),\n resolve: store.resolve,\n relations: store.relations,\n /**\n * Follow derivedFrom and contains edges from an entity to the facts it is built from, breadth first, and report each\n * step's provenance. Entities with no variant for the context are reported once and not expanded.\n */\n trace(id: string, context: Context = {}, options: TraceOptions = {}) {\n const walk = store.trace(id, context, options)\n let current = walk.next()\n while (!current.done) current = walk.next()\n return current.value\n },\n }\n}\n\n/** Expand a serialized shard into entities and relations, restoring the IDs and provenance it stores compactly. */\nexport function decodeSemanticShard(\n shard: SemanticShard,\n): Pick<SemanticIndex, \"entities\" | \"relations\"> {\n const sources = (refs: readonly number[]) =>\n refs.map((ref) => {\n if (!Number.isInteger(ref) || !shard.sources[ref])\n throw new DocsError(\"DOCS_SHARD_INVALID\", \"Invalid provenance reference.\")\n return shard.sources[ref]!\n })\n return {\n entities: shard.entities.map((entity) => ({\n id: entity.id,\n type: entity.type,\n variants: entity.variants.map((variant) => ({\n variantId: variantId(entity.id, variant.context),\n ...variant,\n provenance: sources(variant.provenance),\n })),\n })),\n relations: shard.relations.map(({ provenance, ...relation }) => ({\n id: relationId(\n relation.type,\n relation.source,\n relation.target,\n relation.context,\n relation.targetContext,\n ),\n ...relation,\n provenance: sources(provenance),\n })),\n }\n}\n\n/**\n * Read Runtime over a sharded build. It loads only the shards that hold the requested entities and, for trace, the\n * shards of the entities it reaches. Each shard holds a subject's entities and every relation touching them.\n */\nexport function createSemanticLoader(\n pointer: SemanticPointer,\n readText: (path: string) => Promise<string>,\n options: { digest?: (text: string) => string } = {},\n) {\n if (\n pointer.schemaVersion !== 2 ||\n (options.digest && options.digest(canonicalJson(pointer.shards)) !== pointer.revision)\n )\n throw new DocsError(\"DOCS_SHARD_INVALID\", \"Invalid semantic pointer schema or revision.\")\n const store = createStore()\n const loads = new Map<string, Promise<Pick<SemanticIndex, \"entities\" | \"relations\">>>()\n const load = (id: string) => loadSubject(shardKey(id))\n function loadSubject(subject: string) {\n const shard = Object.hasOwn(pointer.shards, subject) ? pointer.shards[subject] : undefined\n if (!shard) return Promise.resolve(null)\n let pending = loads.get(subject)\n if (!pending) {\n pending = (async () => {\n if (\n /[:\\\\?#%]/.test(shard.path) ||\n shard.path.split(\"/\").some((part) => !part || part === \".\" || part === \"..\")\n )\n throw new DocsError(\"DOCS_SHARD_INVALID\", `Invalid shard path for ${subject}.`)\n const text = await readText(shard.path)\n // Earlier CLI releases appended one LF after hashing the canonical JSON payload.\n if (\n options.digest &&\n options.digest(text) !== shard.revision &&\n !(text.endsWith(\"\\n\") && options.digest(text.slice(0, -1)) === shard.revision)\n )\n throw new DocsError(\"DOCS_SHARD_INVALID\", `Shard revision differs for ${subject}.`)\n const data: SemanticShard = JSON.parse(text)\n if (\n data.schemaVersion !== 1 ||\n data.subject !== subject ||\n !data.entities.every((entity) => shardKey(entity.id) === subject) ||\n !data.relations.every(\n (edge) => shardKey(edge.source) === subject || shardKey(edge.target) === subject,\n )\n )\n throw new DocsError(\"DOCS_SHARD_INVALID\", `Invalid semantic shard for ${subject}.`)\n const decoded = decodeSemanticShard(data)\n decoded.entities.sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))\n store.add(decoded)\n return decoded\n })().catch((error) => {\n loads.delete(subject)\n throw error\n })\n loads.set(subject, pending)\n }\n return pending\n }\n return {\n revision: pointer.revision,\n /** Read one exact published subject, including its entities, ordered variants and touching relations. */\n subject: loadSubject,\n /** Subjects whose shards have been read, for cost reporting. */\n loaded: () => [...loads.keys()],\n /** Discover entities in subject then ID order. A prefix limits shard reads; after resumes after an entity ID. */\n async *entities({\n subjectPrefix = \"\",\n type,\n after,\n }: { subjectPrefix?: string; type?: string; after?: string } = {}) {\n const start = after === undefined ? undefined : shardKey(after)\n for (const subject of Object.keys(pointer.shards).sort()) {\n if (!subject.startsWith(subjectPrefix) || (start !== undefined && subject < start)) continue\n const shard = await loadSubject(subject)\n for (const entity of shard?.entities ?? []) {\n if (subject === start && after !== undefined && entity.id <= after) continue\n if (type === undefined || entity.type === type) yield entity\n }\n }\n },\n async entity(id: string) {\n await load(id)\n return store.entities.get(id) ?? null\n },\n async resolve(id: string, context: Context = {}) {\n await load(id)\n return store.resolve(id, context)\n },\n async relations(id: string, options: RelationQuery = {}) {\n await load(id)\n return store.relations(id, options)\n },\n async trace(id: string, context: Context = {}, options: TraceOptions = {}) {\n const walk = store.trace(id, context, options)\n let current = walk.next()\n while (!current.done) {\n await Promise.all(current.value.map(load))\n current = walk.next()\n }\n return current.value\n },\n /** Read every shard, for full scans such as listing all entities of a type. */\n async loadAll(): Promise<SemanticIndex> {\n await Promise.all(Object.keys(pointer.shards).map(loadSubject))\n const sort = (left: { id: string }, right: { id: string }) =>\n left.id < right.id ? -1 : left.id > right.id ? 1 : 0\n return {\n schemaVersion: 1,\n entities: [...store.entities.values()].sort(sort),\n relations: store.all().sort(sort),\n }\n },\n }\n}\n"],"mappings":";;;;;;AAwBA,SAAgB,sBACd,cACA;CACA,eAAe,KAAK,UAAkB,MAAuB;EAC3D,MAAM,cAAc,MAAM,iBAAiB,UAAU,IAAI;EACzD,IAAI,CAAC,YAAY,SAAS,UACxB,MAAM,IAAI,UAAU,yBAAyB,yCAAyC;EACxF,OAAO,qBAAqB,YAAY,SAAS,UAAU,YAAY,QAAQ;CACjF;CAEA,MAAM,2BAAW,IAAI,IAAgC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,MAAM,IAAI,SAAS,OAAO;GAC7C,IAAI,UAAU,KAAK,KAAK;GACxB,OAAO,CAAC,QAAQ,MAAM;IACpB,MAAM,QAAQ,IAAI,QAAQ,MAAM,IAAI,IAAI,CAAC;IACzC,UAAU,KAAK,KAAK;GACtB;GACA,OAAO,QAAQ;EACjB;;EAEA,MAAM,UAAkC;GACtC,MAAM,QAAQ,IAAI,OAAO,KAAK,QAAQ,MAAM,CAAC,CAAC,IAAI,WAAW,CAAC;GAC9D,MAAM,QAAQ,MAAsB,UAClC,KAAK,KAAK,MAAM,KAAK,KAAK,KAAK,KAAK,MAAM,KAAK,IAAI;GACrD,OAAO;IACL,eAAe;IACf,UAAU,CAAC,GAAG,MAAM,SAAS,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI;IAChD,WAAW,MAAM,IAAI,CAAC,CAAC,KAAK,IAAI;GAClC;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type EntityVariant } from "./semantic.js";
|
|
2
|
+
export declare function doc(path: string, options?: {
|
|
3
|
+
section?: string;
|
|
4
|
+
}): {
|
|
5
|
+
section?: string;
|
|
6
|
+
scope: string;
|
|
7
|
+
id: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function entity(id: string): {
|
|
10
|
+
entity: string;
|
|
11
|
+
};
|
|
12
|
+
/** A public export of a host-selected documentation module. */
|
|
13
|
+
export declare function packageDoc(name: string, exported: string): {
|
|
14
|
+
package: string;
|
|
15
|
+
export: string;
|
|
16
|
+
};
|
|
17
|
+
export type DocumentTarget = ReturnType<typeof doc> | ReturnType<typeof packageDoc>;
|
|
18
|
+
export declare function include<Target extends DocumentTarget>(target: Target): {
|
|
19
|
+
include: Target;
|
|
20
|
+
};
|
|
21
|
+
export interface ContentView {
|
|
22
|
+
id: string;
|
|
23
|
+
route?: string;
|
|
24
|
+
content: readonly ReturnType<typeof include>[];
|
|
25
|
+
}
|
|
26
|
+
export declare function reference(subject: ReturnType<typeof entity>, options?: {
|
|
27
|
+
select?: string;
|
|
28
|
+
factRevision?: string;
|
|
29
|
+
}): {
|
|
30
|
+
reference: {
|
|
31
|
+
entity: string;
|
|
32
|
+
select?: string;
|
|
33
|
+
factRevision?: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/** Classify a resolved link for rendering. URL acceptance and sanitization belong to the projection. */
|
|
37
|
+
export declare function classifyLink(href: string): "anchor" | "external" | "internal";
|
|
38
|
+
export declare const entityRevisionDomains: readonly ["fact", "provenance", "variant"];
|
|
39
|
+
export type EntityRevisionDomain = (typeof entityRevisionDomains)[number];
|
|
40
|
+
export interface RevisionPin<Domain extends string> {
|
|
41
|
+
variant: string;
|
|
42
|
+
domain: Domain;
|
|
43
|
+
version: 1;
|
|
44
|
+
revision: string;
|
|
45
|
+
}
|
|
46
|
+
export type EntityRevisionPin = RevisionPin<EntityRevisionDomain>;
|
|
47
|
+
export interface PageReference {
|
|
48
|
+
object: string;
|
|
49
|
+
pin?: EntityRevisionPin;
|
|
50
|
+
}
|
|
51
|
+
export declare function entityRevision(variant: EntityVariant, domain: EntityRevisionDomain): string | undefined;
|
|
52
|
+
export declare function matchesEntityPin(pin: EntityRevisionPin, variant: EntityVariant): boolean;
|
|
53
|
+
/** Normalize the portable citation used by page frontmatter and inherited folder defaults. */
|
|
54
|
+
export declare function pageReference(value: unknown): PageReference | undefined;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { isSoftwarePackageName } from "./module.js";
|
|
2
|
+
import { DocsError } from "./model.js";
|
|
3
|
+
import { isEntityId, isExactVariantId } from "./semantic.js";
|
|
4
|
+
|
|
5
|
+
// src/references.ts
|
|
6
|
+
function doc(path, options = {}) {
|
|
7
|
+
const parts = path.split("/");
|
|
8
|
+
if (parts.length < 2 || parts.some((part) => !/^[a-z0-9]+(?:[.-][a-z0-9]+)*$/.test(part))) throw new DocsError("DOCS_REFERENCE_INVALID", "Expected a document identity such as guide/installation.", { source: path });
|
|
9
|
+
return {
|
|
10
|
+
scope: parts.slice(0, -1).join("/"),
|
|
11
|
+
id: parts.at(-1),
|
|
12
|
+
...options
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function entity(id) {
|
|
16
|
+
if (!isEntityId(id)) throw new DocsError("DOCS_REFERENCE_INVALID", "Expected a typed entity ID.", { source: id });
|
|
17
|
+
return { entity: id };
|
|
18
|
+
}
|
|
19
|
+
/** A public export of a host-selected documentation module. */
|
|
20
|
+
function packageDoc(name, exported) {
|
|
21
|
+
if (!isSoftwarePackageName(name) || !exported.trim()) throw new DocsError("DOCS_REFERENCE_INVALID", "Expected a package name and public export.");
|
|
22
|
+
return {
|
|
23
|
+
package: name,
|
|
24
|
+
export: exported
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function include(target) {
|
|
28
|
+
return { include: target };
|
|
29
|
+
}
|
|
30
|
+
function reference(subject, options = {}) {
|
|
31
|
+
return { reference: {
|
|
32
|
+
...subject,
|
|
33
|
+
...options
|
|
34
|
+
} };
|
|
35
|
+
}
|
|
36
|
+
/** Classify a resolved link for rendering. URL acceptance and sanitization belong to the projection. */
|
|
37
|
+
function classifyLink(href) {
|
|
38
|
+
return href.startsWith("#") ? "anchor" : /^(?:[a-z][\w+.-]*:|\/\/)/i.test(href) ? "external" : "internal";
|
|
39
|
+
}
|
|
40
|
+
const entityRevisionDomains = [
|
|
41
|
+
"fact",
|
|
42
|
+
"provenance",
|
|
43
|
+
"variant"
|
|
44
|
+
];
|
|
45
|
+
function entityRevision(variant, domain) {
|
|
46
|
+
switch (domain) {
|
|
47
|
+
case "fact": return variant.factRevision;
|
|
48
|
+
case "provenance": return variant.provenanceRevision;
|
|
49
|
+
case "variant": return variant.revision;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function matchesEntityPin(pin, variant) {
|
|
53
|
+
return pin.version === 1 && pin.variant === variant.variantId && pin.revision === entityRevision(variant, pin.domain);
|
|
54
|
+
}
|
|
55
|
+
/** Normalize the portable citation used by page frontmatter and inherited folder defaults. */
|
|
56
|
+
function pageReference(value) {
|
|
57
|
+
const item = typeof value === "string" ? { object: value } : value;
|
|
58
|
+
if (!item || typeof item !== "object" || !("object" in item) || typeof item.object !== "string" || !isEntityId(item.object.trim()) || Object.keys(item).some((key) => key !== "object" && key !== "pin")) return void 0;
|
|
59
|
+
const object = item.object.trim();
|
|
60
|
+
if (!("pin" in item) || item.pin === void 0) return { object };
|
|
61
|
+
const pin = item.pin;
|
|
62
|
+
if (!pin || typeof pin !== "object" || !Object.hasOwn(pin, "variant") || !Object.hasOwn(pin, "domain") || !Object.hasOwn(pin, "version") || !Object.hasOwn(pin, "revision") || Object.keys(pin).length !== 4 || typeof pin.variant !== "string" || pin.variant.split("@", 1)[0] !== object || !isExactVariantId(pin.variant) || !entityRevisionDomains.includes(pin.domain) || pin.version !== 1 || typeof pin.revision !== "string" || !pin.revision.trim()) return void 0;
|
|
63
|
+
return {
|
|
64
|
+
object,
|
|
65
|
+
pin
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { classifyLink, doc, entity, entityRevision, entityRevisionDomains, include, matchesEntityPin, packageDoc, pageReference, reference };
|
|
70
|
+
//# sourceMappingURL=references.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"references.js","names":[],"sources":["../src/references.ts"],"sourcesContent":["import { isSoftwarePackageName } from \"./module.js\"\nimport { DocsError } from \"./model.js\"\nimport { isEntityId, isExactVariantId, type EntityVariant } from \"./semantic.js\"\n\nexport function doc(path: string, options: { section?: string } = {}) {\n const parts = path.split(\"/\")\n if (parts.length < 2 || parts.some((part) => !/^[a-z0-9]+(?:[.-][a-z0-9]+)*$/.test(part)))\n throw new DocsError(\n \"DOCS_REFERENCE_INVALID\",\n \"Expected a document identity such as guide/installation.\",\n { source: path },\n )\n return { scope: parts.slice(0, -1).join(\"/\"), id: parts.at(-1)!, ...options }\n}\n\nexport function entity(id: string) {\n if (!isEntityId(id))\n throw new DocsError(\"DOCS_REFERENCE_INVALID\", \"Expected a typed entity ID.\", { source: id })\n return { entity: id }\n}\n\n/** A public export of a host-selected documentation module. */\nexport function packageDoc(name: string, exported: string) {\n if (!isSoftwarePackageName(name) || !exported.trim())\n throw new DocsError(\"DOCS_REFERENCE_INVALID\", \"Expected a package name and public export.\")\n return { package: name, export: exported }\n}\n\nexport type DocumentTarget = ReturnType<typeof doc> | ReturnType<typeof packageDoc>\nexport function include<Target extends DocumentTarget>(target: Target) {\n return { include: target }\n}\nexport interface ContentView {\n id: string\n route?: string\n content: readonly ReturnType<typeof include>[]\n}\n\nexport function reference(\n subject: ReturnType<typeof entity>,\n options: { select?: string; factRevision?: string } = {},\n) {\n return { reference: { ...subject, ...options } }\n}\n\n/** Classify a resolved link for rendering. URL acceptance and sanitization belong to the projection. */\nexport function classifyLink(href: string) {\n return href.startsWith(\"#\")\n ? \"anchor\"\n : /^(?:[a-z][\\w+.-]*:|\\/\\/)/i.test(href)\n ? \"external\"\n : \"internal\"\n}\n\nexport const entityRevisionDomains = [\"fact\", \"provenance\", \"variant\"] as const\nexport type EntityRevisionDomain = (typeof entityRevisionDomains)[number]\n\nexport interface RevisionPin<Domain extends string> {\n variant: string\n domain: Domain\n version: 1\n revision: string\n}\n\nexport type EntityRevisionPin = RevisionPin<EntityRevisionDomain>\n\nexport interface PageReference {\n object: string\n pin?: EntityRevisionPin\n}\n\nexport function entityRevision(variant: EntityVariant, domain: EntityRevisionDomain) {\n switch (domain) {\n case \"fact\":\n return variant.factRevision\n case \"provenance\":\n return variant.provenanceRevision\n case \"variant\":\n return variant.revision\n }\n}\n\nexport function matchesEntityPin(pin: EntityRevisionPin, variant: EntityVariant) {\n return (\n pin.version === 1 &&\n pin.variant === variant.variantId &&\n pin.revision === entityRevision(variant, pin.domain)\n )\n}\n\n/** Normalize the portable citation used by page frontmatter and inherited folder defaults. */\nexport function pageReference(value: unknown): PageReference | undefined {\n const item = typeof value === \"string\" ? { object: value } : value\n if (\n !item ||\n typeof item !== \"object\" ||\n !(\"object\" in item) ||\n typeof item.object !== \"string\" ||\n !isEntityId(item.object.trim()) ||\n Object.keys(item).some((key) => key !== \"object\" && key !== \"pin\")\n )\n return undefined\n const object = item.object.trim()\n if (!(\"pin\" in item) || item.pin === undefined) return { object }\n const pin = item.pin as NonNullable<PageReference[\"pin\"]>\n if (\n !pin ||\n typeof pin !== \"object\" ||\n !Object.hasOwn(pin, \"variant\") ||\n !Object.hasOwn(pin, \"domain\") ||\n !Object.hasOwn(pin, \"version\") ||\n !Object.hasOwn(pin, \"revision\") ||\n Object.keys(pin).length !== 4 ||\n typeof pin.variant !== \"string\" ||\n pin.variant.split(\"@\", 1)[0] !== object ||\n !isExactVariantId(pin.variant) ||\n !entityRevisionDomains.includes(pin.domain) ||\n pin.version !== 1 ||\n typeof pin.revision !== \"string\" ||\n !pin.revision.trim()\n )\n return undefined\n return { object, pin }\n}\n"],"mappings":";;;;;AAIA,SAAgB,IAAI,MAAc,UAAgC,CAAC,GAAG;CACpE,MAAM,QAAQ,KAAK,MAAM,GAAG;CAC5B,IAAI,MAAM,SAAS,KAAK,MAAM,MAAM,SAAS,CAAC,gCAAgC,KAAK,IAAI,CAAC,GACtF,MAAM,IAAI,UACR,0BACA,4DACA,EAAE,QAAQ,KAAK,CACjB;CACF,OAAO;EAAE,OAAO,MAAM,MAAM,GAAG,EAAE,CAAC,CAAC,KAAK,GAAG;EAAG,IAAI,MAAM,GAAG,EAAE;EAAI,GAAG;CAAQ;AAC9E;AAEA,SAAgB,OAAO,IAAY;CACjC,IAAI,CAAC,WAAW,EAAE,GAChB,MAAM,IAAI,UAAU,0BAA0B,+BAA+B,EAAE,QAAQ,GAAG,CAAC;CAC7F,OAAO,EAAE,QAAQ,GAAG;AACtB;;AAGA,SAAgB,WAAW,MAAc,UAAkB;CACzD,IAAI,CAAC,sBAAsB,IAAI,KAAK,CAAC,SAAS,KAAK,GACjD,MAAM,IAAI,UAAU,0BAA0B,4CAA4C;CAC5F,OAAO;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,OAAO,OAAO,KAAK,UAAU,KAC9B,OAAO,KAAK,GAAG,CAAC,CAAC,WAAW,KAC5B,OAAO,IAAI,YAAY,YACvB,IAAI,QAAQ,MAAM,KAAK,CAAC,CAAC,CAAC,OAAO,UACjC,CAAC,iBAAiB,IAAI,OAAO,KAC7B,CAAC,sBAAsB,SAAS,IAAI,MAAM,KAC1C,IAAI,YAAY,KAChB,OAAO,IAAI,aAAa,YACxB,CAAC,IAAI,SAAS,KAAK,GAEnB,OAAO;CACT,OAAO;EAAE;EAAQ;CAAI;AACvB"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type PublicationHost } from "./document-reader.js";
|
|
2
|
+
import { type SearchIndex, type SearchQueryOptions, type SearchResult } from "./search.js";
|
|
3
|
+
/** Adapters rank candidates for a public revision. Each page uses the same stable ordering. */
|
|
4
|
+
export interface SearchAdapter {
|
|
5
|
+
id: string;
|
|
6
|
+
query(input: SearchAdapterQuery): readonly SearchCandidate[] | Promise<readonly SearchCandidate[]>;
|
|
7
|
+
}
|
|
8
|
+
export interface SearchAdapterQuery {
|
|
9
|
+
/** The inventory pin used to publish the provider index, or the supplied host revision. */
|
|
10
|
+
revision: string;
|
|
11
|
+
text: string;
|
|
12
|
+
/** Offset and limit count engine candidates, before host filtering. */
|
|
13
|
+
offset: number;
|
|
14
|
+
limit: number;
|
|
15
|
+
signal: AbortSignal;
|
|
16
|
+
}
|
|
17
|
+
export interface SearchCandidate {
|
|
18
|
+
section: string;
|
|
19
|
+
score?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface SearchDefinition {
|
|
22
|
+
adapter: SearchAdapter;
|
|
23
|
+
timeoutMs?: number;
|
|
24
|
+
fallback?: "native" | "error";
|
|
25
|
+
/** Maximum provider candidates considered per query, including filtered candidates. */
|
|
26
|
+
scanLimit?: number;
|
|
27
|
+
}
|
|
28
|
+
export declare function defineSearch(definition: SearchDefinition): Readonly<SearchDefinition>;
|
|
29
|
+
export interface RetrievalCitation {
|
|
30
|
+
/** Build revision of the authorized document view. */
|
|
31
|
+
revision: string;
|
|
32
|
+
inventoryRevision?: string;
|
|
33
|
+
document: string;
|
|
34
|
+
section: string;
|
|
35
|
+
route: string;
|
|
36
|
+
context: Readonly<SearchResult["context"]>;
|
|
37
|
+
sources: readonly string[];
|
|
38
|
+
}
|
|
39
|
+
export interface RetrievalHit {
|
|
40
|
+
rank: number;
|
|
41
|
+
result: SearchResult;
|
|
42
|
+
citation: RetrievalCitation;
|
|
43
|
+
}
|
|
44
|
+
/** Attach the publication identity and evidence to a result from an authorized native index. */
|
|
45
|
+
export declare function retrievalHit(result: SearchResult, revision: string, rank: number, inventoryRevision?: string): RetrievalHit;
|
|
46
|
+
export interface RetrievalResponse {
|
|
47
|
+
schemaVersion: 1;
|
|
48
|
+
/** Build revision of the authorized document view. */
|
|
49
|
+
revision: string;
|
|
50
|
+
inventoryRevision?: string;
|
|
51
|
+
engine: string;
|
|
52
|
+
hits: RetrievalHit[];
|
|
53
|
+
/** Provider pagination exhausted the configured candidate budget before filling the page. */
|
|
54
|
+
scanLimitReached?: true;
|
|
55
|
+
fallback?: "adapter-unavailable";
|
|
56
|
+
}
|
|
57
|
+
export interface RetrievalQueryOptions extends SearchQueryOptions {
|
|
58
|
+
signal?: AbortSignal;
|
|
59
|
+
}
|
|
60
|
+
export interface RetrievalCorpus {
|
|
61
|
+
revision: string;
|
|
62
|
+
index: SearchIndex;
|
|
63
|
+
}
|
|
64
|
+
export interface PublicSearchCorpus extends RetrievalCorpus {
|
|
65
|
+
audience: "public";
|
|
66
|
+
}
|
|
67
|
+
/** Prepare a provider's corpus from a verified public publication's own search projection. */
|
|
68
|
+
export declare function openPublicSearchCorpus(revision: string, host: PublicationHost): Promise<PublicSearchCorpus>;
|
|
69
|
+
export type RetrievalInput = RetrievalCorpus & {
|
|
70
|
+
/** Additional artifact pin. When supplied, provider indexing uses this pin. */
|
|
71
|
+
inventoryRevision?: string;
|
|
72
|
+
} & ({
|
|
73
|
+
audience: "public";
|
|
74
|
+
search?: SearchDefinition;
|
|
75
|
+
} | {
|
|
76
|
+
audience?: "authorized";
|
|
77
|
+
search?: never;
|
|
78
|
+
});
|
|
79
|
+
/** Rank only documents in the host's already-authorized index. Provider content is never used as evidence. */
|
|
80
|
+
export declare function createRetrieval(input: RetrievalInput): {
|
|
81
|
+
query(text: string, options?: RetrievalQueryOptions): Promise<RetrievalResponse>;
|
|
82
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { openPinnedReader } from "./document-reader.js";
|
|
2
|
+
import { DocsError } from "./model.js";
|
|
3
|
+
import { acceptsSearchEntry, readPublishedSearchIndex, searchEntryResult } from "./search-view.js";
|
|
4
|
+
import { closestSubheading, createSearch } from "./search.js";
|
|
5
|
+
|
|
6
|
+
// src/retrieval.ts
|
|
7
|
+
function defineSearch(definition) {
|
|
8
|
+
const { adapter } = definition;
|
|
9
|
+
if (!/^[a-z][a-z0-9.-]*$/.test(adapter?.id ?? "") || adapter.id === "native" || typeof adapter.query !== "function") throw new DocsError("DOCS_SEARCH_INVALID", "Expected a named custom search adapter with a query method.");
|
|
10
|
+
integer(definition.timeoutMs ?? 1500, 1, 12e4);
|
|
11
|
+
integer(definition.scanLimit ?? 1e3, 1, 1e5);
|
|
12
|
+
return Object.freeze({ ...definition });
|
|
13
|
+
}
|
|
14
|
+
/** Attach the publication identity and evidence to a result from an authorized native index. */
|
|
15
|
+
function retrievalHit(result, revision, rank, inventoryRevision) {
|
|
16
|
+
const context = { ...result.context };
|
|
17
|
+
const sources = [...result.sources];
|
|
18
|
+
return {
|
|
19
|
+
result: {
|
|
20
|
+
...result,
|
|
21
|
+
context,
|
|
22
|
+
sources
|
|
23
|
+
},
|
|
24
|
+
rank,
|
|
25
|
+
citation: {
|
|
26
|
+
revision,
|
|
27
|
+
...inventoryRevision && { inventoryRevision },
|
|
28
|
+
document: result.document,
|
|
29
|
+
section: result.section,
|
|
30
|
+
route: result.route,
|
|
31
|
+
context,
|
|
32
|
+
sources
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** Prepare a provider's corpus from a verified public publication's own search projection. */
|
|
37
|
+
async function openPublicSearchCorpus(revision, host) {
|
|
38
|
+
const publication = await openPinnedReader(revision, host);
|
|
39
|
+
return {
|
|
40
|
+
revision,
|
|
41
|
+
audience: "public",
|
|
42
|
+
index: await readPublishedSearchIndex(publication)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function integer(value, min, max) {
|
|
46
|
+
if (!Number.isSafeInteger(value) || value < min || value > max) throw new DocsError("DOCS_SEARCH_INVALID", `Expected a search integer between ${min} and ${max}.`);
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
function abortable(run, signal) {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
const abort = () => reject(signal.reason);
|
|
52
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
53
|
+
Promise.resolve().then(() => {
|
|
54
|
+
signal.throwIfAborted();
|
|
55
|
+
return run();
|
|
56
|
+
}).then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/** Rank only documents in the host's already-authorized index. Provider content is never used as evidence. */
|
|
60
|
+
function createRetrieval(input) {
|
|
61
|
+
const { index, revision, inventoryRevision } = input;
|
|
62
|
+
const localeKey = index.localeDimension ?? "locale";
|
|
63
|
+
const external = input.audience === "public" && input.search && defineSearch(input.search);
|
|
64
|
+
let native;
|
|
65
|
+
let sections;
|
|
66
|
+
function response(engine, results, offset, details = {}) {
|
|
67
|
+
return {
|
|
68
|
+
schemaVersion: 1,
|
|
69
|
+
revision,
|
|
70
|
+
...inventoryRevision && { inventoryRevision },
|
|
71
|
+
engine,
|
|
72
|
+
hits: results.map((result, position) => retrievalHit(result, revision, offset + position + 1, inventoryRevision)),
|
|
73
|
+
...details
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return { async query(text, options = {}) {
|
|
77
|
+
options.signal?.throwIfAborted();
|
|
78
|
+
const offset = integer(options.offset ?? 0, 0, 1e5);
|
|
79
|
+
const limit = integer(options.limit ?? 5, 0, 1e3);
|
|
80
|
+
if (!index.entries.length || !text.trim() || !limit) return response(external ? external.adapter.id : "native", [], offset);
|
|
81
|
+
if (external) {
|
|
82
|
+
const { adapter, timeoutMs = 1500, fallback = "native", scanLimit = 1e3 } = external;
|
|
83
|
+
const timeout = AbortSignal.timeout(timeoutMs);
|
|
84
|
+
const signal = options.signal ? AbortSignal.any([timeout, options.signal]) : timeout;
|
|
85
|
+
sections ??= new Map(index.entries.map((entry) => [entry.section, entry]));
|
|
86
|
+
const results = [];
|
|
87
|
+
const seen = /* @__PURE__ */ new Set();
|
|
88
|
+
let matched = 0;
|
|
89
|
+
let exhausted = false;
|
|
90
|
+
let candidateOffset = 0;
|
|
91
|
+
try {
|
|
92
|
+
while (candidateOffset < scanLimit && results.length < limit) {
|
|
93
|
+
const batchLimit = Math.min(50, scanLimit - candidateOffset);
|
|
94
|
+
const candidates = await abortable(() => adapter.query({
|
|
95
|
+
revision: inventoryRevision ?? revision,
|
|
96
|
+
text,
|
|
97
|
+
offset: candidateOffset,
|
|
98
|
+
limit: batchLimit,
|
|
99
|
+
signal
|
|
100
|
+
}), signal);
|
|
101
|
+
if (!Array.isArray(candidates) || candidates.length > batchLimit) throw new DocsError("DOCS_SEARCH_INVALID", "Search adapter returned an invalid page.");
|
|
102
|
+
for (const candidate of candidates) {
|
|
103
|
+
if (typeof candidate?.section !== "string" || candidate.score !== void 0 && !Number.isFinite(candidate.score)) throw new DocsError("DOCS_SEARCH_INVALID", "Search adapter returned an invalid candidate.");
|
|
104
|
+
if (seen.has(candidate.section)) continue;
|
|
105
|
+
seen.add(candidate.section);
|
|
106
|
+
const entry = sections.get(candidate.section);
|
|
107
|
+
if (!entry || !acceptsSearchEntry(entry, options)) continue;
|
|
108
|
+
if (matched < offset) {
|
|
109
|
+
matched++;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
results.push(searchEntryResult(entry, candidate.score ?? 0, closestSubheading(entry.subheadings, text, entry.context[localeKey])));
|
|
113
|
+
if (results.length === limit) break;
|
|
114
|
+
}
|
|
115
|
+
candidateOffset += candidates.length;
|
|
116
|
+
if (candidates.length < batchLimit) {
|
|
117
|
+
exhausted = true;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return response(adapter.id, results, offset, !exhausted && candidateOffset >= scanLimit && results.length < limit ? { scanLimitReached: true } : {});
|
|
122
|
+
} catch {
|
|
123
|
+
options.signal?.throwIfAborted();
|
|
124
|
+
if (fallback === "error") throw new DocsError("DOCS_SEARCH_UNAVAILABLE", "The search adapter is unavailable.");
|
|
125
|
+
native ??= createSearch(index);
|
|
126
|
+
return response("native", native.query(text, options).results, offset, { fallback: "adapter-unavailable" });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
native ??= createSearch(index);
|
|
130
|
+
return response("native", native.query(text, options).results, offset);
|
|
131
|
+
} };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export { createRetrieval, defineSearch, openPublicSearchCorpus, retrievalHit };
|
|
135
|
+
//# sourceMappingURL=retrieval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrieval.js","names":[],"sources":["../src/retrieval.ts"],"sourcesContent":["import { openPinnedReader, type PublicationHost } from \"./document-reader.js\"\nimport { DocsError } from \"./model.js\"\nimport { acceptsSearchEntry, readPublishedSearchIndex, searchEntryResult } from \"./search-view.js\"\nimport {\n closestSubheading,\n createSearch,\n type SearchEntry,\n type SearchIndex,\n type SearchQueryOptions,\n type SearchResult,\n} from \"./search.js\"\n\n/** Adapters rank candidates for a public revision. Each page uses the same stable ordering. */\nexport interface SearchAdapter {\n id: string\n query(input: SearchAdapterQuery): readonly SearchCandidate[] | Promise<readonly SearchCandidate[]>\n}\n\nexport interface SearchAdapterQuery {\n /** The inventory pin used to publish the provider index, or the supplied host revision. */\n revision: string\n text: string\n /** Offset and limit count engine candidates, before host filtering. */\n offset: number\n limit: number\n signal: AbortSignal\n}\n\nexport interface SearchCandidate {\n section: string\n score?: number\n}\n\nexport interface SearchDefinition {\n adapter: SearchAdapter\n timeoutMs?: number\n fallback?: \"native\" | \"error\"\n /** Maximum provider candidates considered per query, including filtered candidates. */\n scanLimit?: number\n}\n\nexport function defineSearch(definition: SearchDefinition): Readonly<SearchDefinition> {\n const { adapter } = definition\n if (\n !/^[a-z][a-z0-9.-]*$/.test(adapter?.id ?? \"\") ||\n adapter.id === \"native\" ||\n typeof adapter.query !== \"function\"\n )\n throw new DocsError(\n \"DOCS_SEARCH_INVALID\",\n \"Expected a named custom search adapter with a query method.\",\n )\n integer(definition.timeoutMs ?? 1500, 1, 120_000)\n integer(definition.scanLimit ?? 1000, 1, 100_000)\n return Object.freeze({ ...definition })\n}\n\nexport interface RetrievalCitation {\n /** Build revision of the authorized document view. */\n revision: string\n inventoryRevision?: string\n document: string\n section: string\n route: string\n context: Readonly<SearchResult[\"context\"]>\n sources: readonly string[]\n}\n\nexport interface RetrievalHit {\n rank: number\n result: SearchResult\n citation: RetrievalCitation\n}\n\n/** Attach the publication identity and evidence to a result from an authorized native index. */\nexport function retrievalHit(\n result: SearchResult,\n revision: string,\n rank: number,\n inventoryRevision?: string,\n): RetrievalHit {\n const context = { ...result.context }\n const sources = [...result.sources]\n return {\n result: { ...result, context, sources },\n rank,\n citation: {\n revision,\n ...(inventoryRevision && { inventoryRevision }),\n document: result.document,\n section: result.section,\n route: result.route,\n context,\n sources,\n },\n }\n}\n\nexport interface RetrievalResponse {\n schemaVersion: 1\n /** Build revision of the authorized document view. */\n revision: string\n inventoryRevision?: string\n engine: string\n hits: RetrievalHit[]\n /** Provider pagination exhausted the configured candidate budget before filling the page. */\n scanLimitReached?: true\n fallback?: \"adapter-unavailable\"\n}\n\nexport interface RetrievalQueryOptions extends SearchQueryOptions {\n signal?: AbortSignal\n}\n\nexport interface RetrievalCorpus {\n revision: string\n index: SearchIndex\n}\n\nexport interface PublicSearchCorpus extends RetrievalCorpus {\n audience: \"public\"\n}\n\n/** Prepare a provider's corpus from a verified public publication's own search projection. */\nexport async function openPublicSearchCorpus(\n revision: string,\n host: PublicationHost,\n): Promise<PublicSearchCorpus> {\n const publication = await openPinnedReader(revision, host)\n return { revision, audience: \"public\", index: await readPublishedSearchIndex(publication) }\n}\n\nexport type RetrievalInput = RetrievalCorpus & {\n /** Additional artifact pin. When supplied, provider indexing uses this pin. */\n inventoryRevision?: string\n} & (\n { audience: \"public\"; search?: SearchDefinition } | { audience?: \"authorized\"; search?: never }\n )\n\nfunction integer(value: number, min: number, max: number) {\n if (!Number.isSafeInteger(value) || value < min || value > max)\n throw new DocsError(\n \"DOCS_SEARCH_INVALID\",\n `Expected a search integer between ${min} and ${max}.`,\n )\n return value\n}\n\nfunction abortable<T>(run: () => Promise<T> | T, signal: AbortSignal): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const abort = () => reject(signal.reason)\n signal.addEventListener(\"abort\", abort, { once: true })\n const work = Promise.resolve().then(() => {\n signal.throwIfAborted()\n return run()\n })\n work.then(resolve, reject).finally(() => signal.removeEventListener(\"abort\", abort))\n })\n}\n\n/** Rank only documents in the host's already-authorized index. Provider content is never used as evidence. */\nexport function createRetrieval(input: RetrievalInput) {\n const { index, revision, inventoryRevision } = input\n const localeKey = index.localeDimension ?? \"locale\"\n const external = input.audience === \"public\" && input.search && defineSearch(input.search)\n let native: ReturnType<typeof createSearch> | undefined\n let sections: Map<string, SearchEntry> | undefined\n\n function response(\n engine: string,\n results: SearchResult[],\n offset: number,\n details: Pick<RetrievalResponse, \"fallback\" | \"scanLimitReached\"> = {},\n ): RetrievalResponse {\n return {\n schemaVersion: 1,\n revision,\n ...(inventoryRevision && { inventoryRevision }),\n engine,\n hits: results.map((result, position) =>\n retrievalHit(result, revision, offset + position + 1, inventoryRevision),\n ),\n ...details,\n }\n }\n\n return {\n async query(text: string, options: RetrievalQueryOptions = {}): Promise<RetrievalResponse> {\n options.signal?.throwIfAborted()\n const offset = integer(options.offset ?? 0, 0, 100_000)\n const limit = integer(options.limit ?? 5, 0, 1000)\n if (!index.entries.length || !text.trim() || !limit)\n return response(external ? external.adapter.id : \"native\", [], offset)\n if (external) {\n const { adapter, timeoutMs = 1500, fallback = \"native\", scanLimit = 1000 } = external\n const timeout = AbortSignal.timeout(timeoutMs)\n const signal = options.signal ? AbortSignal.any([timeout, options.signal]) : timeout\n sections ??= new Map(index.entries.map((entry) => [entry.section, entry]))\n const results: SearchResult[] = []\n const seen = new Set<string>()\n let matched = 0\n let exhausted = false\n let candidateOffset = 0\n try {\n while (candidateOffset < scanLimit && results.length < limit) {\n const batchLimit = Math.min(50, scanLimit - candidateOffset)\n const candidates = await abortable(\n () =>\n adapter.query({\n revision: inventoryRevision ?? revision,\n text,\n offset: candidateOffset,\n limit: batchLimit,\n signal,\n }),\n signal,\n )\n if (!Array.isArray(candidates) || candidates.length > batchLimit)\n throw new DocsError(\"DOCS_SEARCH_INVALID\", \"Search adapter returned an invalid page.\")\n for (const candidate of candidates) {\n if (\n typeof candidate?.section !== \"string\" ||\n (candidate.score !== undefined && !Number.isFinite(candidate.score))\n )\n throw new DocsError(\n \"DOCS_SEARCH_INVALID\",\n \"Search adapter returned an invalid candidate.\",\n )\n if (seen.has(candidate.section)) continue\n seen.add(candidate.section)\n const entry = sections.get(candidate.section)\n if (!entry || !acceptsSearchEntry(entry, options)) continue\n if (matched < offset) {\n matched++\n continue\n }\n results.push(\n searchEntryResult(\n entry,\n candidate.score ?? 0,\n closestSubheading(entry.subheadings, text, entry.context[localeKey]),\n ),\n )\n if (results.length === limit) break\n }\n candidateOffset += candidates.length\n if (candidates.length < batchLimit) {\n exhausted = true\n break\n }\n }\n return response(\n adapter.id,\n results,\n offset,\n !exhausted && candidateOffset >= scanLimit && results.length < limit\n ? { scanLimitReached: true }\n : {},\n )\n } catch {\n options.signal?.throwIfAborted()\n if (fallback === \"error\")\n throw new DocsError(\"DOCS_SEARCH_UNAVAILABLE\", \"The search adapter is unavailable.\")\n native ??= createSearch(index)\n return response(\"native\", native.query(text, options).results, offset, {\n fallback: \"adapter-unavailable\",\n })\n }\n }\n native ??= createSearch(index)\n return response(\"native\", native.query(text, options).results, offset)\n },\n }\n}\n"],"mappings":";;;;;;AAyCA,SAAgB,aAAa,YAA0D;CACrF,MAAM,EAAE,YAAY;CACpB,IACE,CAAC,qBAAqB,KAAK,SAAS,MAAM,EAAE,KAC5C,QAAQ,OAAO,YACf,OAAO,QAAQ,UAAU,YAEzB,MAAM,IAAI,UACR,uBACA,6DACF;CACF,QAAQ,WAAW,aAAa,MAAM,GAAG,IAAO;CAChD,QAAQ,WAAW,aAAa,KAAM,GAAG,GAAO;CAChD,OAAO,OAAO,OAAO,EAAE,GAAG,WAAW,CAAC;AACxC;;AAoBA,SAAgB,aACd,QACA,UACA,MACA,mBACc;CACd,MAAM,UAAU,EAAE,GAAG,OAAO,QAAQ;CACpC,MAAM,UAAU,CAAC,GAAG,OAAO,OAAO;CAClC,OAAO;EACL,QAAQ;GAAE,GAAG;GAAQ;GAAS;EAAQ;EACtC;EACA,UAAU;GACR;GACA,GAAI,qBAAqB,EAAE,kBAAkB;GAC7C,UAAU,OAAO;GACjB,SAAS,OAAO;GAChB,OAAO,OAAO;GACd;GACA;EACF;CACF;AACF;;AA4BA,eAAsB,uBACpB,UACA,MAC6B;CAC7B,MAAM,cAAc,MAAM,iBAAiB,UAAU,IAAI;CACzD,OAAO;EAAE;EAAU,UAAU;EAAU,OAAO,MAAM,yBAAyB,WAAW;CAAE;AAC5F;AASA,SAAS,QAAQ,OAAe,KAAa,KAAa;CACxD,IAAI,CAAC,OAAO,cAAc,KAAK,KAAK,QAAQ,OAAO,QAAQ,KACzD,MAAM,IAAI,UACR,uBACA,qCAAqC,IAAI,OAAO,IAAI,EACtD;CACF,OAAO;AACT;AAEA,SAAS,UAAa,KAA2B,QAAiC;CAChF,OAAO,IAAI,S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,CACP;GACF,QAAQ;IACN,QAAQ,QAAQ,eAAe;IAC/B,IAAI,aAAa,SACf,MAAM,IAAI,UAAU,2BAA2B,oCAAoC;IACrF,WAAW,aAAa,KAAK;IAC7B,OAAO,SAAS,UAAU,OAAO,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,QAAQ,EACrE,UAAU,sBACZ,CAAC;GACH;EACF;EACA,WAAW,aAAa,KAAK;EAC7B,OAAO,SAAS,UAAU,OAAO,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM;CACvE,EACF;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Manifest } from "./document-reader.js";
|
|
2
|
+
import type { SearchEntry, SearchIndex, SearchQueryOptions, SearchResult } from "./search.js";
|
|
3
|
+
export declare function acceptsSearchEntry(entry: SearchEntry, options: SearchQueryOptions): boolean;
|
|
4
|
+
export declare function searchEntryResult(entry: SearchEntry, score: number, best?: {
|
|
5
|
+
anchor: string;
|
|
6
|
+
text: string;
|
|
7
|
+
}): SearchResult;
|
|
8
|
+
export declare function readPublishedSearchIndex(publication: {
|
|
9
|
+
manifest: Manifest;
|
|
10
|
+
readText(path: string): Promise<string>;
|
|
11
|
+
}): Promise<SearchIndex>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DocsError } from "./model.js";
|
|
2
|
+
|
|
3
|
+
// src/search-view.ts
|
|
4
|
+
function acceptsSearchEntry(entry, options) {
|
|
5
|
+
return (!options.acceptDocument || options.acceptDocument(entry.document)) && (!options.context || Object.entries(options.context).every(([key, value]) => !(key in entry.context) || entry.context[key] === value));
|
|
6
|
+
}
|
|
7
|
+
function searchEntryResult(entry, score, best) {
|
|
8
|
+
const { terms: _terms, length: _length, subheadings: _subheadings, ...rest } = entry;
|
|
9
|
+
return {
|
|
10
|
+
...rest,
|
|
11
|
+
...best ? {
|
|
12
|
+
route: `${entry.route.split("#")[0]}#${best.anchor}`,
|
|
13
|
+
subheading: best.text
|
|
14
|
+
} : {},
|
|
15
|
+
score
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
async function readPublishedSearchIndex(publication) {
|
|
19
|
+
const pointer = publication.manifest.search;
|
|
20
|
+
if (!pointer) return {
|
|
21
|
+
schemaVersion: 1,
|
|
22
|
+
entries: []
|
|
23
|
+
};
|
|
24
|
+
const value = JSON.parse(await publication.readText(pointer.path));
|
|
25
|
+
if (value?.schemaVersion !== 1 || !Array.isArray(value.entries) || value.entries.length !== pointer.entries) throw new DocsError("DOCS_SEARCH_INVALID", "Published search index does not match its manifest.");
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { acceptsSearchEntry, readPublishedSearchIndex, searchEntryResult };
|
|
30
|
+
//# sourceMappingURL=search-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-view.js","names":[],"sources":["../src/search-view.ts"],"sourcesContent":["import type { Manifest } from \"./document-reader.js\"\nimport { DocsError } from \"./model.js\"\nimport type { SearchEntry, SearchIndex, SearchQueryOptions, SearchResult } from \"./search.js\"\n\nexport function acceptsSearchEntry(entry: SearchEntry, options: SearchQueryOptions) {\n return (\n (!options.acceptDocument || options.acceptDocument(entry.document)) &&\n (!options.context ||\n Object.entries(options.context).every(\n ([key, value]) => !(key in entry.context) || entry.context[key] === value,\n ))\n )\n}\n\nexport function searchEntryResult(\n entry: SearchEntry,\n score: number,\n best?: { anchor: string; text: string },\n): SearchResult {\n const { terms: _terms, length: _length, subheadings: _subheadings, ...rest } = entry\n return {\n ...rest,\n ...(best\n ? { route: `${entry.route.split(\"#\")[0]}#${best.anchor}`, subheading: best.text }\n : {}),\n score,\n }\n}\n\nexport async function readPublishedSearchIndex(publication: {\n manifest: Manifest\n readText(path: string): Promise<string>\n}): Promise<SearchIndex> {\n const pointer = publication.manifest.search\n if (!pointer) return { schemaVersion: 1, entries: [] }\n const value = JSON.parse(await publication.readText(pointer.path))\n if (\n value?.schemaVersion !== 1 ||\n !Array.isArray(value.entries) ||\n value.entries.length !== pointer.entries\n )\n throw new DocsError(\n \"DOCS_SEARCH_INVALID\",\n \"Published search index does not match its manifest.\",\n )\n return value\n}\n"],"mappings":";;;AAIA,SAAgB,mBAAmB,OAAoB,SAA6B;CAClF,QACG,CAAC,QAAQ,kBAAkB,QAAQ,eAAe,MAAM,QAAQ,OAChE,CAAC,QAAQ,WACR,OAAO,QAAQ,QAAQ,OAAO,CAAC,CAAC,OAC7B,CAAC,KAAK,WAAW,EAAE,OAAO,MAAM,YAAY,MAAM,QAAQ,SAAS,KACtE;AAEN;AAEA,SAAgB,kBACd,OACA,OACA,MACc;CACd,MAAM,EAAE,OAAO,QAAQ,QAAQ,SAAS,aAAa,cAAc,GAAG,SAAS;CAC/E,OAAO;EACL,GAAG;EACH,GAAI,OACA;GAAE,OAAO,GAAG,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,GAAG,KAAK;GAAU,YAAY,KAAK;EAAK,IAC9E,CAAC;EACL;CACF;AACF;AAEA,eAAsB,yBAAyB,aAGtB;CACvB,MAAM,UAAU,YAAY,SAAS;CACrC,IAAI,CAAC,SAAS,OAAO;EAAE,eAAe;EAAG,SAAS,CAAC;CAAE;CACrD,MAAM,QAAQ,KAAK,MAAM,MAAM,YAAY,SAAS,QAAQ,IAAI,CAAC;CACjE,IACE,OAAO,kBAAkB,KACzB,CAAC,MAAM,QAAQ,MAAM,OAAO,KAC5B,MAAM,QAAQ,WAAW,QAAQ,SAEjC,MAAM,IAAI,UACR,uBACA,qDACF;CACF,OAAO;AACT"}
|
package/dist/search.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { Context } from "./semantic.js";
|
|
2
|
+
/** One section edition in the search index. Terms are weighted counts; headings and titles count more than body text. */
|
|
3
|
+
export interface SearchEntry {
|
|
4
|
+
section: string;
|
|
5
|
+
document: string;
|
|
6
|
+
route: string;
|
|
7
|
+
title: string;
|
|
8
|
+
heading?: string;
|
|
9
|
+
/** Headings inside the section, so a result can point at the one the query names. */
|
|
10
|
+
subheadings?: {
|
|
11
|
+
anchor: string;
|
|
12
|
+
text: string;
|
|
13
|
+
}[];
|
|
14
|
+
context: Context;
|
|
15
|
+
/** Preference constraints for this projected result, independent of the document edition. */
|
|
16
|
+
projection?: Context;
|
|
17
|
+
/** Sources of the section's content, for citation checks. */
|
|
18
|
+
sources: string[];
|
|
19
|
+
/** Limited observations from published static Web markup. */
|
|
20
|
+
origin?: "native-ssr-headings";
|
|
21
|
+
length: number;
|
|
22
|
+
terms: Record<string, number>;
|
|
23
|
+
snippet: string;
|
|
24
|
+
}
|
|
25
|
+
export interface SearchIndex {
|
|
26
|
+
schemaVersion: 1;
|
|
27
|
+
entries: SearchEntry[];
|
|
28
|
+
localeDimension?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Statistics of the collection the entries were taken from, when they are a subset of it: BM25 scores depend on how
|
|
31
|
+
* many entries hold each word and on the average entry length, so a subset scores exactly like the whole only with
|
|
32
|
+
* the whole's statistics. Absent for a complete index.
|
|
33
|
+
*/
|
|
34
|
+
collection?: {
|
|
35
|
+
entries: number;
|
|
36
|
+
averageLength: number;
|
|
37
|
+
frequency: Record<string, number>;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface SearchResult extends Omit<SearchEntry, "terms" | "length" | "subheadings"> {
|
|
41
|
+
score: number;
|
|
42
|
+
/** The heading inside the section that shares the most words with the query, when one does; `route` then targets it. */
|
|
43
|
+
subheading?: string;
|
|
44
|
+
}
|
|
45
|
+
/** Insert word boundaries for CJK prose before either search engine builds or queries its index. */
|
|
46
|
+
export declare function segmentSearchText(text: string, locale?: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Lowercase words of letters and digits in any script. camelCase identifiers also yield their parts, so
|
|
49
|
+
* `defaultOpen` matches both "defaultopen" and "open". Single CJK characters remain searchable.
|
|
50
|
+
*/
|
|
51
|
+
export declare function tokenize(text: string, locale?: string): string[];
|
|
52
|
+
/**
|
|
53
|
+
* The words of a query that carry its meaning: its tokens without the function words of its language. The language
|
|
54
|
+
* is the locale's (`fr-CA` uses `fr`); without a locale it is English, the interface's default, and a language
|
|
55
|
+
* without a built-in list keeps every word. A query of only function words keeps them all, so it still finds something.
|
|
56
|
+
*/
|
|
57
|
+
export declare function queryTerms(text: string, locale?: string): string[];
|
|
58
|
+
/**
|
|
59
|
+
* The subheading of a result that shares the most words with a query, as search results point at it: whole words
|
|
60
|
+
* count fully, and indexed words starting with a query word of four or more letters count half. None if nothing is shared.
|
|
61
|
+
*/
|
|
62
|
+
export declare function closestSubheading(subheadings: SearchEntry["subheadings"], query: string, locale?: string): {
|
|
63
|
+
anchor: string;
|
|
64
|
+
text: string;
|
|
65
|
+
} | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Where a query's words appear in a displayed text, as sorted, non-overlapping `[start, end)` offsets, for highlighting
|
|
68
|
+
* a result. Words match as ranking matches them: function words do not count, camelCase parts match on their own, and
|
|
69
|
+
* a query word of four or more letters marks the start of a longer word it prefixes ("valid" in "validation").
|
|
70
|
+
*/
|
|
71
|
+
export declare function matchedRanges(text: string, query: string, locale?: string): [number, number][];
|
|
72
|
+
/**
|
|
73
|
+
* One index per locale for sites with two or more: a locale's index keeps its own entries and those without a locale,
|
|
74
|
+
* which are exactly the entries a search in that locale can return. Empty for sites with fewer locales.
|
|
75
|
+
*/
|
|
76
|
+
export declare function splitSearchIndex(index: SearchIndex): Map<string, SearchIndex>;
|
|
77
|
+
export interface SearchQueryOptions {
|
|
78
|
+
context?: Context;
|
|
79
|
+
locale?: string;
|
|
80
|
+
limit?: number;
|
|
81
|
+
offset?: number;
|
|
82
|
+
acceptDocument?: (variant: string) => boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* BM25 ranking over section editions (k1 1.2, b 0.75), filtered to editions compatible with the context. A query
|
|
86
|
+
* ranks with its `queryTerms`, so function words of its locale's language do not count. Prefix matches stand in for
|
|
87
|
+
* stemming. Ties break by section ID so results are stable.
|
|
88
|
+
*/
|
|
89
|
+
export declare function createSearch(index: SearchIndex): {
|
|
90
|
+
query(text: string, options?: SearchQueryOptions): {
|
|
91
|
+
query: string;
|
|
92
|
+
terms: string[];
|
|
93
|
+
results: SearchResult[];
|
|
94
|
+
};
|
|
95
|
+
};
|