@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
package/dist/skills.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { DocsError } from "./model.js";
|
|
2
|
+
|
|
3
|
+
// src/skills.ts
|
|
4
|
+
function skillFiles(publication, name) {
|
|
5
|
+
const prefix = "delivery/skills/" + name + "/";
|
|
6
|
+
const delivery = publication.manifest.projections?.deliveries?.find((item) => item.id === "skills");
|
|
7
|
+
const files = /* @__PURE__ */ new Map();
|
|
8
|
+
for (const path of delivery?.files ?? []) if (path.startsWith(prefix)) files.set(path.slice(prefix.length), publication.artifact(path).sha256);
|
|
9
|
+
if (files.size && !files.has("SKILL.md")) throw new DocsError("DOCS_SKILL_INVALID", "The published skill has no instructions.", { source: name });
|
|
10
|
+
return files;
|
|
11
|
+
}
|
|
12
|
+
/** Compare two pinned releases with a local installation. The caller owns file access and update decisions. */
|
|
13
|
+
async function reviewSkillUpdate(name, before, after, installed) {
|
|
14
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name)) throw new DocsError("DOCS_SKILL_INVALID", "Expected a skill name.", { source: name });
|
|
15
|
+
const original = skillFiles(before, name);
|
|
16
|
+
const candidate = skillFiles(after, name);
|
|
17
|
+
if (!original.size && !candidate.size) throw new DocsError("DOCS_SKILL_INVALID", "Neither pinned publication contains this skill.", { source: name });
|
|
18
|
+
const changes = [];
|
|
19
|
+
for (const file of [.../* @__PURE__ */ new Set([...original.keys(), ...candidate.keys()])].sort()) {
|
|
20
|
+
const bytes = await installed.read(file);
|
|
21
|
+
const local = bytes === void 0 ? void 0 : await installed.sha256(bytes);
|
|
22
|
+
const base = original.get(file), next = candidate.get(file);
|
|
23
|
+
const action = local === next ? "current" : local !== base ? "local-change" : next === void 0 ? "remove" : base === void 0 ? "add" : "update";
|
|
24
|
+
changes.push({
|
|
25
|
+
file,
|
|
26
|
+
action,
|
|
27
|
+
base,
|
|
28
|
+
local,
|
|
29
|
+
next
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
name,
|
|
34
|
+
baseline: before.projectionCatalog().inventoryRevision,
|
|
35
|
+
candidate: after.projectionCatalog().inventoryRevision,
|
|
36
|
+
changes,
|
|
37
|
+
hasLocalChanges: changes.some((row) => row.action === "local-change")
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { reviewSkillUpdate };
|
|
42
|
+
//# sourceMappingURL=skills.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skills.js","names":[],"sources":["../src/skills.ts"],"sourcesContent":["import type { openPinnedReader } from \"./document-reader.js\"\nimport { DocsError } from \"./model.js\"\n\ntype Publication = Awaited<ReturnType<typeof openPinnedReader>>\n\nfunction skillFiles(publication: Publication, name: string) {\n const prefix = \"delivery/skills/\" + name + \"/\"\n const delivery = publication.manifest.projections?.deliveries?.find(\n (item) => item.id === \"skills\",\n )\n const files = new Map<string, string>()\n for (const path of delivery?.files ?? []) {\n if (path.startsWith(prefix))\n files.set(path.slice(prefix.length), publication.artifact(path).sha256)\n }\n if (files.size && !files.has(\"SKILL.md\"))\n throw new DocsError(\"DOCS_SKILL_INVALID\", \"The published skill has no instructions.\", {\n source: name,\n })\n return files\n}\n\n/** Compare two pinned releases with a local installation. The caller owns file access and update decisions. */\nexport async function reviewSkillUpdate(\n name: string,\n before: Publication,\n after: Publication,\n installed: {\n /** Return undefined for a missing file; propagate other read failures. */\n read(path: string): Promise<Uint8Array | undefined>\n sha256(bytes: Uint8Array): string | Promise<string>\n },\n) {\n if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name))\n throw new DocsError(\"DOCS_SKILL_INVALID\", \"Expected a skill name.\", { source: name })\n const original = skillFiles(before, name)\n const candidate = skillFiles(after, name)\n if (!original.size && !candidate.size)\n throw new DocsError(\"DOCS_SKILL_INVALID\", \"Neither pinned publication contains this skill.\", {\n source: name,\n })\n const changes = []\n for (const file of [...new Set([...original.keys(), ...candidate.keys()])].sort()) {\n const bytes = await installed.read(file)\n const local = bytes === undefined ? undefined : await installed.sha256(bytes)\n const base = original.get(file),\n next = candidate.get(file)\n const action =\n local === next\n ? \"current\"\n : local !== base\n ? \"local-change\"\n : next === undefined\n ? \"remove\"\n : base === undefined\n ? \"add\"\n : \"update\"\n changes.push({ file, action, base, local, next })\n }\n return {\n name,\n baseline: before.projectionCatalog().inventoryRevision,\n candidate: after.projectionCatalog().inventoryRevision,\n changes,\n hasLocalChanges: changes.some((row) => row.action === \"local-change\"),\n }\n}\n"],"mappings":";;;AAKA,SAAS,WAAW,aAA0B,MAAc;CAC1D,MAAM,SAAS,qBAAqB,OAAO;CAC3C,MAAM,WAAW,YAAY,SAAS,aAAa,YAAY,MAC5D,SAAS,KAAK,OAAO,QACxB;CACA,MAAM,wBAAQ,IAAI,IAAoB;CACtC,KAAK,MAAM,QAAQ,UAAU,SAAS,CAAC,GACrC,IAAI,KAAK,WAAW,MAAM,GACxB,MAAM,IAAI,KAAK,MAAM,OAAO,MAAM,GAAG,YAAY,SAAS,IAAI,CAAC,CAAC,MAAM;CAE1E,IAAI,MAAM,QAAQ,CAAC,MAAM,IAAI,UAAU,GACrC,MAAM,IAAI,UAAU,sBAAsB,4CAA4C,EACpF,QAAQ,KACV,CAAC;CACH,OAAO;AACT;;AAGA,eAAsB,kBACpB,MACA,QACA,OACA,WAKA;CACA,IAAI,CAAC,6BAA6B,KAAK,IAAI,GACzC,MAAM,IAAI,UAAU,sBAAsB,0BAA0B,EAAE,QAAQ,KAAK,CAAC;CACtF,MAAM,WAAW,WAAW,QAAQ,IAAI;CACxC,MAAM,YAAY,WAAW,OAAO,IAAI;CACxC,IAAI,CAAC,SAAS,QAAQ,CAAC,UAAU,MAC/B,MAAM,IAAI,UAAU,sBAAsB,mDAAmD,EAC3F,QAAQ,KACV,CAAC;CACH,MAAM,UAAU,CAAC;CACjB,KAAK,MAAM,QAAQ,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,SAAS,KAAK,GAAG,GAAG,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG;EACjF,MAAM,QAAQ,MAAM,UAAU,KAAK,IAAI;EACvC,MAAM,QAAQ,UAAU,SAAY,SAAY,MAAM,UAAU,OAAO,KAAK;EAC5E,MAAM,OAAO,SAAS,IAAI,IAAI,GAC5B,OAAO,UAAU,IAAI,IAAI;EAC3B,MAAM,SACJ,UAAU,OACN,YACA,UAAU,OACR,iBACA,SAAS,SACP,WACA,SAAS,SACP,QACA;EACZ,QAAQ,KAAK;GAAE;GAAM;GAAQ;GAAM;GAAO;EAAK,CAAC;CAClD;CACA,OAAO;EACL;EACA,UAAU,OAAO,kBAAkB,CAAC,CAAC;EACrC,WAAW,MAAM,kBAAkB,CAAC,CAAC;EACrC;EACA,iBAAiB,QAAQ,MAAM,QAAQ,IAAI,WAAW,cAAc;CACtE;AACF"}
|
package/docs/index.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Docs SDK guides (@docs-sdk-dev/reader 0.4.0-next.0)
|
|
2
|
+
|
|
3
|
+
Read the guide for your task and verify API signatures in the installed package declarations.
|
|
4
|
+
|
|
5
|
+
- [Read a pinned publication](./sdk/reader.md)
|
|
6
|
+
- [从其他宿主打开 Reader](./zh-CN/sdk/reader-storage.md)
|
|
7
|
+
- [组合集合、模板和视图](./zh-CN/sdk/composition.md)
|
|
8
|
+
- [读取固定修订版的发布物](./zh-CN/sdk/reader.md)
|
|
9
|
+
- [Compose collections, templates and views](./sdk/composition.md)
|
|
10
|
+
- [Open a Reader from another host](./sdk/reader-storage.md)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Compose collections, templates and views
|
|
2
|
+
|
|
3
|
+
Choose the output before choosing a resource. A directory of completed pages can publish directly. A data catalog can contribute records with no article for each one. An API catalog can pair those records with one shared layout and a View for browsing.
|
|
4
|
+
|
|
5
|
+
```ts title="content/catalog/catalog.collection.ts"
|
|
6
|
+
import { defineCollection, defineTemplate } from "@docs-sdk-dev/core/authoring"
|
|
7
|
+
import { defineSource } from "@docs-sdk-dev/core/sources"
|
|
8
|
+
|
|
9
|
+
const source = defineSource({
|
|
10
|
+
discover: ({ glob }) =>
|
|
11
|
+
glob("content/catalog/notes/*.txt").map((path) => ({
|
|
12
|
+
id: path.slice(path.lastIndexOf("/") + 1, -4),
|
|
13
|
+
source: path,
|
|
14
|
+
})),
|
|
15
|
+
extract: async (record, { read }) => ({
|
|
16
|
+
text: (await read(record.source)).text,
|
|
17
|
+
}),
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const template = defineTemplate<{ text: string }>({
|
|
21
|
+
id: "catalog-notes",
|
|
22
|
+
source: "content/catalog/catalog.collection.ts",
|
|
23
|
+
sections: {
|
|
24
|
+
notes: { title: "Notes", content: ({ data }) => data.text },
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
export default defineCollection({ from: source, template })
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Put a file such as `retention.txt` in the selected directory. Build the project and find the generated ID in its manifest. Treat the record ID and section ID `notes` as part of the documentation interface if you link to them.
|
|
32
|
+
|
|
33
|
+
## Choose a collection form
|
|
34
|
+
|
|
35
|
+
A Source-backed Collection accepts one Source or an array of compatible Sources. Use `where` for record selection and `sortBy` for ordering. Without a Template, native document records retain their content and facts-only records can remain a catalog. With a Template, each eligible record supplies data for the shared structure.
|
|
36
|
+
|
|
37
|
+
An explicit Collection supplies `load` and `template` for entries already owned by the producer. Give each entry stable identity, source and title information. Prefer the Source-backed form when several Collections need to reuse the same capture and extracted records.
|
|
38
|
+
|
|
39
|
+
## Place the results
|
|
40
|
+
|
|
41
|
+
Use `defineView({ from: collection, where, sortBy })` to filter or order the same data. A View can also compose explicit document references. When a document appears in two menus, keep its authoritative identity and route. The site [navigation guide](https://docs-sdk.dev/site/navigation/) describes where placement fits.
|
|
42
|
+
|
|
43
|
+
Inherited Templates can add and reorder sections through `extendTemplate`. Publish shared instructions from a reference when multiple documents need the same wording. Run `docs explain` on the generated page to locate the contributing layers, then use `docs impact` to check dependent output before publishing.
|
|
44
|
+
|
|
45
|
+
## Join records before rendering
|
|
46
|
+
|
|
47
|
+
The following helpers are part of the workspace distribution. Check your installed authoring and preset entry points before using them. [Package compatibility](https://docs-sdk.dev/reference/compatibility/)
|
|
48
|
+
|
|
49
|
+
Use `enrichSource` when a catalog entry needs data owned by another Source. The join preserves the primary record's identity and carries the matched records' provenance into the result. For example, add a Markdown note whose record ID and dimensions match the product:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { files } from "@docs-sdk-dev/core/authoring"
|
|
53
|
+
import { enrichSource, type SourceInstance } from "@docs-sdk-dev/core/sources"
|
|
54
|
+
|
|
55
|
+
export function documentProducts(products: SourceInstance<{ sku: string }>) {
|
|
56
|
+
return enrichSource(products, {
|
|
57
|
+
as: "guide",
|
|
58
|
+
from: files("notes/*.md"),
|
|
59
|
+
required: true,
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Here `products` is an existing Source of data records. Supply `key` and `foreignKey` when the records use different IDs. A single match is the default. Set `many: true` for an array, including an empty array when no record matches. `required: true` rejects a missing match. To reject unused secondary records too, set `unmatched: "error"`. The `as` field must be free, and editions must match exactly.
|
|
65
|
+
|
|
66
|
+
## Recompute a generated section
|
|
67
|
+
|
|
68
|
+
Use `defineDerivedSection` inside a Template when its sections depend on different inputs. For example, a reference page can use `defineDerivedSection<{ sample: string }, string>({ id: "example", inputs: ({ data }) => data.sample, generate: (sample) => ({ markdown: sample }) })` from `@docs-sdk-dev/core/authoring`. Declare every input the generator needs in `inputs` and keep the section ID stable. Incremental compilation can reuse output when its selected inputs and dependencies stay unchanged. Keep the generator deterministic and check dependent results with `docs impact`.
|
|
69
|
+
|
|
70
|
+
## Start from a Markdown preset
|
|
71
|
+
|
|
72
|
+
Register `documentation`, `knowledgeBase`, or `changelog` from `@docs-sdk-dev/core/presets` in the project's `presets` array. Each turns a Markdown glob into a collection using the post template. The default scopes are `guide`, `knowledge`, and `releases` respectively. Set `scope` to change the collection ID and scope, or `exclude` to omit matching paths. For example, `presets: [changelog({ pattern: "content/releases/*.md", scope: "updates" })]` publishes the matching notes under the updates collection. Use an explicit Collection and Template if records need different generated sections.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Open a Reader from another host
|
|
2
|
+
|
|
3
|
+
A pinned Reader needs two operations: read bytes at an artifact path and compute their SHA-256. Retain the expected inventory digest when publishing. Use that digest when opening a specific revision later. A mismatch is a verification failure.
|
|
4
|
+
|
|
5
|
+
## Serve over HTTP
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { openDocs } from "@docs-sdk-dev/reader"
|
|
9
|
+
|
|
10
|
+
export function openMirror(baseUrl: URL, inventoryRevision: string) {
|
|
11
|
+
return openDocs({
|
|
12
|
+
revision: inventoryRevision,
|
|
13
|
+
host: {
|
|
14
|
+
async readBytes(path) {
|
|
15
|
+
const response = await fetch(new URL(path, baseUrl), { redirect: "error" })
|
|
16
|
+
if (!response.ok) throw new Error("Artifact request failed: " + response.status)
|
|
17
|
+
return new Uint8Array(await response.arrayBuffer())
|
|
18
|
+
},
|
|
19
|
+
async sha256(bytes) {
|
|
20
|
+
const digest = await crypto.subtle.digest("SHA-256", new Uint8Array(bytes))
|
|
21
|
+
return Array.from(new Uint8Array(digest), (byte) =>
|
|
22
|
+
byte.toString(16).padStart(2, "0"),
|
|
23
|
+
).join("")
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Pass a trusted directory URL ending in `/`. The server must allow the host origin to fetch inventory and artifact files when cross-origin. Choose an origin with access appropriate to the audience, and keep credentials out of the published content. Read through the Reader rather than bypassing its artifact checks.
|
|
31
|
+
|
|
32
|
+
## Select an adapter
|
|
33
|
+
|
|
34
|
+
The [Node adapter](https://docs-sdk.dev/reference/api/reader-node/) discovers package modules relative to the actual importer. The [offline SQLite example](https://github.com/LioRael/docs-sdk/tree/main/examples/react) stages verified artifacts against a revision and only exposes a complete publication. For a database or object store, isolate the artifact namespace by revision and retain old revisions when consumers pin them.
|
|
35
|
+
|
|
36
|
+
Use the [Reader guide](reader.md#compose-a-reading-list-and-inspect-its-evidence) to read or compose documents after opening the publication. In a protected host, open the publication view authorized for the request before building navigation, query results or Markdown delivery.
|
|
37
|
+
|
|
38
|
+
## Edit drafts and publish a release
|
|
39
|
+
|
|
40
|
+
Use a `ContentStore` to keep editable history for an editor. Its `read(id, revision?)` returns the current draft when no revision is supplied and reads historical content when pinned. Its `commit` compares the expected revision and writes atomically. Pass `null` only when creating a previously absent record.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { createHash } from "node:crypto"
|
|
44
|
+
import { createEditSession, createMemoryContentStore } from "@docs-sdk-dev/core/edit"
|
|
45
|
+
import { verifyStoreCapabilities } from "@docs-sdk-dev/core/testing"
|
|
46
|
+
|
|
47
|
+
const create = () =>
|
|
48
|
+
createMemoryContentStore((text) => createHash("sha256").update(text).digest("hex"))
|
|
49
|
+
const store = create()
|
|
50
|
+
const base = await store.commit("guide/returns", null, {
|
|
51
|
+
format: "markdown",
|
|
52
|
+
source: "Thirty days.",
|
|
53
|
+
})
|
|
54
|
+
const session = createEditSession(base, store)
|
|
55
|
+
session.apply([{ type: "source.replace", start: 0, end: 6, expected: "Thirty", text: "Sixty" }])
|
|
56
|
+
console.log(session.review().diff)
|
|
57
|
+
const draft = await session.commit()
|
|
58
|
+
|
|
59
|
+
const live = await store.release()
|
|
60
|
+
await store.publish(live?.revision ?? null, { [draft.id]: draft.revision })
|
|
61
|
+
console.log(await verifyStoreCapabilities(create))
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`apply` checks the expected source text before changing the working copy. Use `preview` to render that copy and `review` to inspect the diff before committing. A stale commit leaves the working copy available for review against the latest draft. Use `commitBatch` only on an adapter that offers atomic multi-document writes.
|
|
65
|
+
|
|
66
|
+
A `PublicationStore` adds a live release pointer. Publishing compares the expected live release and the selected draft revisions, then exposes exactly those documents. Draft writes remain private until published. Pin a historical release with `readPublished(id, release)`, use `createPublishedView` to expose a host-authorized set, and use `rollback` to move the live pointer while leaving drafts intact.
|
|
67
|
+
|
|
68
|
+
## Verify a storage adapter
|
|
69
|
+
|
|
70
|
+
Run `verifyStoreCapabilities` with a factory returning an empty, disposable store each time. It checks draft conflicts and historical reads, then exercises atomic batches and release behavior when those capabilities exist. The fixture owner cleans up after verification. The memory adapter is useful for tests and prototypes. Run the same checks on your durable adapter and exercise restart recovery in the host. [Editor example](https://github.com/LioRael/docs-sdk/tree/main/examples/editor)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Read a pinned publication
|
|
2
|
+
|
|
3
|
+
Use `openDocs` from `@docs-sdk-dev/reader` to open a publication. For earlier Reader entry points, see [package compatibility](https://docs-sdk.dev/reference/compatibility/). The host supplies file access and SHA-256. In Node, use a publication directory and the inventory revision recorded at build or deployment time.
|
|
4
|
+
|
|
5
|
+
```ts twoslash
|
|
6
|
+
import { createHash } from "node:crypto"
|
|
7
|
+
import { readFile } from "node:fs/promises"
|
|
8
|
+
import { join } from "node:path"
|
|
9
|
+
import { openDocs } from "@docs-sdk-dev/reader"
|
|
10
|
+
|
|
11
|
+
export async function readInstallGuide(directory: string, inventoryRevision: string) {
|
|
12
|
+
const docs = await openDocs({
|
|
13
|
+
revision: inventoryRevision,
|
|
14
|
+
host: {
|
|
15
|
+
readBytes: (path) => readFile(join(directory, path)),
|
|
16
|
+
sha256: (bytes) => createHash("sha256").update(bytes).digest("hex"),
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
const result = await docs.withContext({ locale: "en" }).read("get-started/installation")
|
|
20
|
+
if (result.status === "exact") return result.value.markdown
|
|
21
|
+
throw new Error("Install guide unavailable: " + result.status)
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Pass `{ section: "body" }` to `read` for one section. Use `compose` to read several references against the same publication. To consume a package's declared documentation dependency in Node, use `openPackageDocs` from the [Node adapter](https://docs-sdk.dev/reference/api/reader-node/) and branch on the returned status.
|
|
26
|
+
|
|
27
|
+
A browser host can fetch the bytes and supply Web Crypto for hashing. Pin the inventory revision independently of the files being fetched. A hash obtained from the very response it is meant to authenticate cannot establish its origin.
|
|
28
|
+
|
|
29
|
+
## Compose a reading list and inspect its evidence
|
|
30
|
+
|
|
31
|
+
The following script runs against this manual's publication. Save it as `inspect.mts` in a project with the standalone Reader and a TypeScript runner. Pass the published directory and the inventory revision returned by its build. Both reads then describe the same release.
|
|
32
|
+
|
|
33
|
+
```ts twoslash
|
|
34
|
+
import { createHash } from "node:crypto"
|
|
35
|
+
import { readFile } from "node:fs/promises"
|
|
36
|
+
import { join } from "node:path"
|
|
37
|
+
import { openDocs } from "@docs-sdk-dev/reader"
|
|
38
|
+
|
|
39
|
+
const [directory, revision] = process.argv.slice(2)
|
|
40
|
+
if (!directory || !revision) throw new Error("Usage: inspect.mts <directory> <inventory-revision>")
|
|
41
|
+
const docs = await openDocs({
|
|
42
|
+
revision,
|
|
43
|
+
host: {
|
|
44
|
+
readBytes: (path) => readFile(join(directory, path)),
|
|
45
|
+
sha256: (bytes) => createHash("sha256").update(bytes).digest("hex"),
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
const guides = await docs.compose(["sdk/identity", "sdk/reader"])
|
|
49
|
+
for (const guide of guides) {
|
|
50
|
+
if (guide.status !== "exact") throw new Error("Guide unavailable: " + guide.status)
|
|
51
|
+
console.log(guide.identity, guide.value.markdown)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const exports = await docs.entities("symbol", (_data, id) => id, "reference/reader/")
|
|
55
|
+
for (const entry of exports) {
|
|
56
|
+
for (const evidence of entry.provenance ?? []) {
|
|
57
|
+
console.log(entry.id, evidence.source, evidence.range?.start, evidence.revision)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Run `npx tsx inspect.mts dist/site <inventory-revision>`. The reading list preserves the requested order. The query limits the symbol scan to the Reader entry; each row identifies the declaration and source revision behind it. A source location explains where a declaration came from. It does not establish that a particular example ran against those bytes.
|
|
63
|
+
|
|
64
|
+
## Handle resolution outcomes
|
|
65
|
+
|
|
66
|
+
Use `withContext` to scope queries and reads without reopening the pinned data. `read` returns `exact`, `fallback`, `missing`, `unavailable`, or `ambiguous`. An unavailable request gives available edition information. If the product permits a different locale, pass an explicit fallback or honor its published edition policy and display the result as a fallback.
|
|
67
|
+
|
|
68
|
+
Use the lower-level Reader when you need published document entries, headings or exact edition metadata before loading a body. Use the publication's [navigation and outline data](https://docs-sdk.dev/site/navigation/) when presenting the result in a host-owned shell. Text search returns an empty list when the publication has no search target, while a missing named facts Collection is a diagnosed query error. Use `collection` for a curated set of fact members and `entities` for a broader type and subject scan.
|
|
69
|
+
|
|
70
|
+
## Fill a published slot with team content
|
|
71
|
+
|
|
72
|
+
Use an overlay when an upstream document defines a slot and your host needs to insert separately owned content. For example, resolve an upstream fragment with an `example` slot and a team's sandbox guide as two exact public exports. Pass both to `composePublishedOverlays` from `@docs-sdk-dev/reader/composition`.
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import type { ReadDocumentExport } from "@docs-sdk-dev/reader"
|
|
76
|
+
import { composePublishedOverlays } from "@docs-sdk-dev/reader/composition"
|
|
77
|
+
|
|
78
|
+
type Export = Extract<ReadDocumentExport, { status: "exact" }>
|
|
79
|
+
|
|
80
|
+
export function composePortal(
|
|
81
|
+
upstream: Export,
|
|
82
|
+
sandboxGuide: Export,
|
|
83
|
+
upstreamFactRevision: string,
|
|
84
|
+
) {
|
|
85
|
+
const result = composePublishedOverlays({ id: "developer-portal", context: {} }, upstream, [
|
|
86
|
+
{
|
|
87
|
+
owner: "developer-support",
|
|
88
|
+
slot: "example",
|
|
89
|
+
priority: 1,
|
|
90
|
+
upstreamFactRevision,
|
|
91
|
+
content: sandboxGuide,
|
|
92
|
+
},
|
|
93
|
+
])
|
|
94
|
+
if (result.status === "blocked") throw new Error(JSON.stringify(result.diagnostics))
|
|
95
|
+
return result
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Here `upstream` and `sandboxGuide` are exact module export results. Take `upstreamFactRevision` from the upstream fragment you reviewed and retain it with the overlay. The upstream slot supplies its fallback when no overlay is selected. A stale revision, missing slot, or tie at the highest priority blocks composition. Preserve the returned receipt to track both publications and transitive dependencies in a [documentation lock](https://docs-sdk.dev/sdk/linker/#pin-documentation-dependencies).
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# 组合集合、模板和视图
|
|
2
|
+
|
|
3
|
+
先确定需要的输出,再选择资源形式。已有完整页面的目录可以直接发布。数据目录可以只提供记录,无需每条记录都对应文章。API 目录可以给同类记录使用共享结构,再用视图供读者浏览。
|
|
4
|
+
|
|
5
|
+
```ts title="content/catalog/catalog.collection.ts"
|
|
6
|
+
import { defineCollection, defineTemplate } from "@docs-sdk-dev/core/authoring"
|
|
7
|
+
import { defineSource } from "@docs-sdk-dev/core/sources"
|
|
8
|
+
|
|
9
|
+
const source = defineSource({
|
|
10
|
+
discover: ({ glob }) =>
|
|
11
|
+
glob("content/catalog/notes/*.txt").map((path) => ({
|
|
12
|
+
id: path.slice(path.lastIndexOf("/") + 1, -4),
|
|
13
|
+
source: path,
|
|
14
|
+
})),
|
|
15
|
+
extract: async (record, { read }) => ({
|
|
16
|
+
text: (await read(record.source)).text,
|
|
17
|
+
}),
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
const template = defineTemplate<{ text: string }>({
|
|
21
|
+
id: "catalog-notes",
|
|
22
|
+
source: "content/catalog/catalog.collection.ts",
|
|
23
|
+
sections: {
|
|
24
|
+
notes: { title: "Notes", content: ({ data }) => data.text },
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
export default defineCollection({ from: source, template })
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
在选定目录加入 `retention.txt` 等文件,构建后在清单中查找生成的 ID。如果其他页面会链接到这些内容,把记录 ID 和章节 ID `notes` 当作文档公开接口来维护。
|
|
32
|
+
|
|
33
|
+
## 选择集合的形式
|
|
34
|
+
|
|
35
|
+
来源驱动的集合接收一个来源或一组兼容的来源。用 `where` 选择记录,用 `sortBy` 排序。没有模板时,原生文档记录保留自己的正文,只含事实的记录也可以保留为目录。有模板时,每条符合条件的记录为共享结构提供数据。
|
|
36
|
+
|
|
37
|
+
显式集合为生产端已拥有的条目提供 `load` 和 `template`。为每个条目提供稳定的标识、出处及标题。如果几个集合需要复用同一次捕获和提取的记录,可以用来源驱动的形式。
|
|
38
|
+
|
|
39
|
+
## 编排结果
|
|
40
|
+
|
|
41
|
+
使用 `defineView({ from: collection, where, sortBy })` 筛选或排序同一批数据。视图也能组合显式的文档引用。同一份文档出现在两个菜单时,继续使用其规范标识和路由。位置编排参阅[站点导航指南](https://docs-sdk.dev/zh-CN/site/navigation/)。
|
|
42
|
+
|
|
43
|
+
继承的模板可通过 `extendTemplate` 新增或重排章节。多份文档共享同一套说明时,可引用共同的说明来源。对生成的页面运行 `docs explain` 定位各项来源,发布前再用 `docs impact` 核对下游产物。
|
|
44
|
+
|
|
45
|
+
## 渲染前关联来源记录
|
|
46
|
+
|
|
47
|
+
以下辅助函数属于工作区发行。使用前请核对已安装的编写和预设入口。[软件包兼容性](https://docs-sdk.dev/zh-CN/reference/compatibility/)
|
|
48
|
+
|
|
49
|
+
目录条目需要另一个 Source 所有的数据时,使用 `enrichSource`。关联会保留主记录的身份,并把匹配记录的溯源带入结果。例如,为产品加入记录 ID 与维度均匹配的 Markdown 备注:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { files } from "@docs-sdk-dev/core/authoring"
|
|
53
|
+
import { enrichSource, type SourceInstance } from "@docs-sdk-dev/core/sources"
|
|
54
|
+
|
|
55
|
+
export function documentProducts(products: SourceInstance<{ sku: string }>) {
|
|
56
|
+
return enrichSource(products, {
|
|
57
|
+
as: "guide",
|
|
58
|
+
from: files("notes/*.md"),
|
|
59
|
+
required: true,
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
这里的 `products` 是已有的数据记录 Source。两边使用不同 ID 时,提供 `key` 和 `foreignKey`。默认只允许一条匹配。`many: true` 返回数组,无匹配时返回空数组。`required: true` 会拒绝缺少匹配的记录。若也要拒绝没有被使用的次级记录,设置 `unmatched: "error"`。`as` 字段必须空闲,且版本维度必须完全一致。
|
|
65
|
+
|
|
66
|
+
## 重新计算生成小节
|
|
67
|
+
|
|
68
|
+
当模板各小节依赖不同输入时,在 Template 中使用 `defineDerivedSection`。例如,从 `@docs-sdk-dev/core/authoring` 导入后,可传入 `defineDerivedSection<{ sample: string }, string>({ id: "example", inputs: ({ data }) => data.sample, generate: (sample) => ({ markdown: sample }) })`。将生成器需要的所有输入声明在 `inputs` 中,并保持小节 ID 稳定。所选输入和依赖不变时,增量编译可以复用产物。确保生成器结果可复现,并用 `docs impact` 检查依赖产物。
|
|
69
|
+
|
|
70
|
+
## 使用 Markdown 预设
|
|
71
|
+
|
|
72
|
+
从 `@docs-sdk-dev/core/presets` 导入 `documentation`、`knowledgeBase` 或 `changelog`,添加到项目的 `presets`。它们使用 post 模板,把一个 Markdown glob 转成 Collection,默认作用域依次为 `guide`、`knowledge` 和 `releases`。用 `scope` 修改 Collection ID 与作用域,用 `exclude` 排除路径。例如,`presets: [changelog({ pattern: "content/releases/*.md", scope: "updates" })]` 会把匹配的发布说明放入 updates Collection。记录需要其他生成小节时,显式定义 Collection 与 Template。
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# 从其他宿主打开 Reader
|
|
2
|
+
|
|
3
|
+
固定修订版的 Reader 需要能完成两件事:按产物路径读取字节,并计算 SHA-256。发布时保留预期的产物清单摘要。随后用它打开指定修订版,摘要不匹配即验证失败。
|
|
4
|
+
|
|
5
|
+
## 通过 HTTP 提供产物
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { openDocs } from "@docs-sdk-dev/reader"
|
|
9
|
+
|
|
10
|
+
export function openMirror(baseUrl: URL, inventoryRevision: string) {
|
|
11
|
+
return openDocs({
|
|
12
|
+
revision: inventoryRevision,
|
|
13
|
+
host: {
|
|
14
|
+
async readBytes(path) {
|
|
15
|
+
const response = await fetch(new URL(path, baseUrl), { redirect: "error" })
|
|
16
|
+
if (!response.ok) throw new Error("Artifact request failed: " + response.status)
|
|
17
|
+
return new Uint8Array(await response.arrayBuffer())
|
|
18
|
+
},
|
|
19
|
+
async sha256(bytes) {
|
|
20
|
+
const digest = await crypto.subtle.digest("SHA-256", new Uint8Array(bytes))
|
|
21
|
+
return Array.from(new Uint8Array(digest), (byte) =>
|
|
22
|
+
byte.toString(16).padStart(2, "0"),
|
|
23
|
+
).join("")
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
传入以 `/` 结尾且受信任的目录 URL。跨源时,服务器应允许宿主源读取清单和产物。选择访问权限与目标读者匹配的源,并将凭据留在发布内容之外。通过 Reader 读取,即可沿用它的产物检查。
|
|
31
|
+
|
|
32
|
+
## 选择适配器
|
|
33
|
+
|
|
34
|
+
[Node 适配器](https://docs-sdk.dev/zh-CN/reference/api/reader-node/)相对于实际导入方发现软件包模块。[离线 SQLite 示例](https://github.com/LioRael/docs-sdk/tree/main/examples/react)按修订版暂存通过验证的产物,等一个发布物完整后才开放读取。使用数据库或对象存储时,按修订版隔离产物命名空间,并保留已被消费者固定使用的旧修订版。
|
|
35
|
+
|
|
36
|
+
发布物打开后,可以按 [Reader 指南](reader.md#compose-a-reading-list-and-inspect-its-evidence)读取或组合文档。在受保护的宿主上,先打开当前请求有权访问的发布视图,再构建导航、生成查询结果或交付 Markdown。
|
|
37
|
+
|
|
38
|
+
## 编辑草稿并发布修订版
|
|
39
|
+
|
|
40
|
+
使用 `ContentStore` 为编辑器保留可编辑历史。`read(id, revision?)` 在省略修订版时读取当前草稿,传入修订版时读取历史内容。`commit` 比较预期修订版并原子写入。仅在创建原本不存在的记录时传入 `null`。
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { createHash } from "node:crypto"
|
|
44
|
+
import { createEditSession, createMemoryContentStore } from "@docs-sdk-dev/core/edit"
|
|
45
|
+
import { verifyStoreCapabilities } from "@docs-sdk-dev/core/testing"
|
|
46
|
+
|
|
47
|
+
const create = () =>
|
|
48
|
+
createMemoryContentStore((text) => createHash("sha256").update(text).digest("hex"))
|
|
49
|
+
const store = create()
|
|
50
|
+
const base = await store.commit("guide/returns", null, {
|
|
51
|
+
format: "markdown",
|
|
52
|
+
source: "Thirty days.",
|
|
53
|
+
})
|
|
54
|
+
const session = createEditSession(base, store)
|
|
55
|
+
session.apply([{ type: "source.replace", start: 0, end: 6, expected: "Thirty", text: "Sixty" }])
|
|
56
|
+
console.log(session.review().diff)
|
|
57
|
+
const draft = await session.commit()
|
|
58
|
+
|
|
59
|
+
const live = await store.release()
|
|
60
|
+
await store.publish(live?.revision ?? null, { [draft.id]: draft.revision })
|
|
61
|
+
console.log(await verifyStoreCapabilities(create))
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`apply` 会检查预期的源文本,再更新工作副本。提交前用 `preview` 渲染副本,用 `review` 查看差异。提交遇到过期修订版时仍可保留工作副本,与最新草稿比较。只有支持多文档原子写入的适配器才能用 `commitBatch`。
|
|
65
|
+
|
|
66
|
+
`PublicationStore` 增加线上发布版指针。发布时比较预期线上修订版及所选草稿的修订版,然后只公开选中的文档。修改草稿不会自动公开。用 `readPublished(id, release)` 读取固定的历史发布版,用 `createPublishedView` 提供宿主已授权的文档集,用 `rollback` 移动线上指针而保留草稿。
|
|
67
|
+
|
|
68
|
+
## 验证存储适配器
|
|
69
|
+
|
|
70
|
+
为 `verifyStoreCapabilities` 提供一个工厂,每次返回空的可丢弃存储。它检查草稿冲突和历史读取,并在适配器提供相应能力时测试原子批处理和发布行为。验证结束后由测试清理存储。内存适配器适合测试和原型。为持久存储运行相同检查,并在宿主中验证重启恢复。[编辑器示例](https://github.com/LioRael/docs-sdk/tree/main/examples/editor)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# 读取固定修订版的发布物
|
|
2
|
+
|
|
3
|
+
用 `@docs-sdk-dev/reader` 的 `openDocs` 打开发布物。较早版本的入口见[软件包兼容性](https://docs-sdk.dev/zh-CN/reference/compatibility/)。宿主负责文件读取和 SHA-256。Node 宿主可使用发布目录,以及构建或部署时记录的产物清单修订版。
|
|
4
|
+
|
|
5
|
+
```ts twoslash
|
|
6
|
+
import { createHash } from "node:crypto"
|
|
7
|
+
import { readFile } from "node:fs/promises"
|
|
8
|
+
import { join } from "node:path"
|
|
9
|
+
import { openDocs } from "@docs-sdk-dev/reader"
|
|
10
|
+
|
|
11
|
+
export async function readInstallGuide(directory: string, inventoryRevision: string) {
|
|
12
|
+
const docs = await openDocs({
|
|
13
|
+
revision: inventoryRevision,
|
|
14
|
+
host: {
|
|
15
|
+
readBytes: (path) => readFile(join(directory, path)),
|
|
16
|
+
sha256: (bytes) => createHash("sha256").update(bytes).digest("hex"),
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
const result = await docs.withContext({ locale: "zh-CN" }).read("get-started/installation")
|
|
20
|
+
if (result.status === "exact") return result.value.markdown
|
|
21
|
+
throw new Error("Install guide unavailable: " + result.status)
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
读取单个章节时,将 `{ section: "body" }` 传给 `read`。用 `compose` 可从同一发布物读取多条引用。要在 Node 消费包声明的文档依赖,可通过 [Node 适配器](https://docs-sdk.dev/zh-CN/reference/api/reader-node/)的 `openPackageDocs` 打开,再根据返回状态处理。
|
|
26
|
+
|
|
27
|
+
浏览器宿主可以获取字节并通过 Web Crypto 计算哈希。应独立于这些待验证文件确定预期的产物清单修订版。若预期哈希直接从待验证的同一响应取得,便无法据此确认来源。
|
|
28
|
+
|
|
29
|
+
## 组合阅读列表并检查出处
|
|
30
|
+
|
|
31
|
+
下面的脚本针对本手册的发布物运行。在装有独立 Reader 和 TypeScript 运行器的项目中,把它保存为 `inspect.mts`。传入发布后的目录及构建返回的产物清单修订版,即可保证读取自同一次发布。
|
|
32
|
+
|
|
33
|
+
```ts twoslash
|
|
34
|
+
import { createHash } from "node:crypto"
|
|
35
|
+
import { readFile } from "node:fs/promises"
|
|
36
|
+
import { join } from "node:path"
|
|
37
|
+
import { openDocs } from "@docs-sdk-dev/reader"
|
|
38
|
+
|
|
39
|
+
const [directory, revision] = process.argv.slice(2)
|
|
40
|
+
if (!directory || !revision) throw new Error("Usage: inspect.mts <directory> <inventory-revision>")
|
|
41
|
+
const docs = await openDocs({
|
|
42
|
+
revision,
|
|
43
|
+
host: {
|
|
44
|
+
readBytes: (path) => readFile(join(directory, path)),
|
|
45
|
+
sha256: (bytes) => createHash("sha256").update(bytes).digest("hex"),
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
const guides = await docs.compose(["sdk/identity", "sdk/reader"])
|
|
49
|
+
for (const guide of guides) {
|
|
50
|
+
if (guide.status !== "exact") throw new Error("Guide unavailable: " + guide.status)
|
|
51
|
+
console.log(guide.identity, guide.value.markdown)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const exports = await docs.entities("symbol", (_data, id) => id, "reference/reader/")
|
|
55
|
+
for (const entry of exports) {
|
|
56
|
+
for (const evidence of entry.provenance ?? []) {
|
|
57
|
+
console.log(entry.id, evidence.source, evidence.range?.start, evidence.revision)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
运行 `npx tsx inspect.mts dist/site <inventory-revision>`。阅读列表保留请求顺序。查询只扫描 Reader 入口的符号,每行给出声明和源修订版。源位置可以说明声明来自哪里。要证明某个示例确实针对该字节运行,还需要单独的运行记录。
|
|
63
|
+
|
|
64
|
+
## 处理解析结果
|
|
65
|
+
|
|
66
|
+
可用 `withContext` 限定查询和读取的上下文,无需重开固定数据。`read` 返回 `exact`、`fallback`、`missing`、`unavailable` 或 `ambiguous`。不可用的请求会带上可选版本信息。产品允许回退到其他语言时,可以显式传入回退值或遵循已发布的版本策略,并把回退结果告知读者。
|
|
67
|
+
|
|
68
|
+
需要先取得已发布的文档条目、标题或确切版本元数据时,使用底层 Reader,按需再加载正文。宿主有自己的界面框架时,可使用发布物的[导航和目录数据](https://docs-sdk.dev/zh-CN/site/navigation/)。发布物缺少搜索目标时,文本搜索返回空列表。具名事实集合缺失则会返回查询诊断。用 `collection` 读取已整理的事实成员,用 `entities` 按类型和主题做更广的查找。
|
|
69
|
+
|
|
70
|
+
## 用团队内容填充已发布的插槽
|
|
71
|
+
|
|
72
|
+
上游文档定义了插槽,而宿主需要插入另一团队维护的内容时,使用 overlay。例如,分别解析带 `example` 插槽的上游片段和团队沙盒指南,取得两个精确的公开导出结果,再传给 `@docs-sdk-dev/reader/composition` 的 `composePublishedOverlays`。
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import type { ReadDocumentExport } from "@docs-sdk-dev/reader"
|
|
76
|
+
import { composePublishedOverlays } from "@docs-sdk-dev/reader/composition"
|
|
77
|
+
|
|
78
|
+
type Export = Extract<ReadDocumentExport, { status: "exact" }>
|
|
79
|
+
|
|
80
|
+
export function composePortal(
|
|
81
|
+
upstream: Export,
|
|
82
|
+
sandboxGuide: Export,
|
|
83
|
+
upstreamFactRevision: string,
|
|
84
|
+
) {
|
|
85
|
+
const result = composePublishedOverlays({ id: "developer-portal", context: {} }, upstream, [
|
|
86
|
+
{
|
|
87
|
+
owner: "developer-support",
|
|
88
|
+
slot: "example",
|
|
89
|
+
priority: 1,
|
|
90
|
+
upstreamFactRevision,
|
|
91
|
+
content: sandboxGuide,
|
|
92
|
+
},
|
|
93
|
+
])
|
|
94
|
+
if (result.status === "blocked") throw new Error(JSON.stringify(result.diagnostics))
|
|
95
|
+
return result
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
这里的 `upstream` 和 `sandboxGuide` 都是精确的模块导出结果。用审查过的上游片段提供 `upstreamFactRevision`,并将它与 overlay 一同保存。未选中 overlay 时,插槽会使用上游提供的默认内容。修订版过期、插槽缺失或最高优先级并列时,组合会被阻止。保留返回的回执,将两份发布物和传递依赖写入[文档锁](https://docs-sdk.dev/zh-CN/sdk/linker/#pin-documentation-dependencies)。
|
package/package.json
CHANGED
|
@@ -1,6 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docs-sdk-dev/reader",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.4.0-next.0",
|
|
4
|
+
"description": "Dependency-free reader for published Docs SDK documents and semantic shards",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=22.12.0"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/LioRael/docs-sdk.git",
|
|
14
|
+
"directory": "packages/reader"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"docs",
|
|
21
|
+
"dist/*.js",
|
|
22
|
+
"dist/*.js.map",
|
|
23
|
+
"dist/*.d.ts"
|
|
24
|
+
],
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./node": {
|
|
31
|
+
"types": "./dist/node.d.ts",
|
|
32
|
+
"default": "./dist/node.js"
|
|
33
|
+
},
|
|
34
|
+
"./ask": {
|
|
35
|
+
"types": "./dist/ask.d.ts",
|
|
36
|
+
"default": "./dist/ask.js"
|
|
37
|
+
},
|
|
38
|
+
"./composition": {
|
|
39
|
+
"types": "./dist/composition.d.ts",
|
|
40
|
+
"default": "./dist/composition.js"
|
|
41
|
+
},
|
|
42
|
+
"./content-schema": {
|
|
43
|
+
"types": "./dist/content-schema.d.ts",
|
|
44
|
+
"default": "./dist/content-schema.js"
|
|
45
|
+
},
|
|
46
|
+
"./annotation-projection": {
|
|
47
|
+
"types": "./dist/annotation-projection.d.ts",
|
|
48
|
+
"default": "./dist/annotation-projection.js"
|
|
49
|
+
},
|
|
50
|
+
"./evidence": {
|
|
51
|
+
"types": "./dist/evidence.d.ts",
|
|
52
|
+
"default": "./dist/evidence.js"
|
|
53
|
+
},
|
|
54
|
+
"./skills": {
|
|
55
|
+
"types": "./dist/skills.d.ts",
|
|
56
|
+
"default": "./dist/skills.js"
|
|
57
|
+
},
|
|
58
|
+
"./retrieval": {
|
|
59
|
+
"types": "./dist/retrieval.d.ts",
|
|
60
|
+
"default": "./dist/retrieval.js"
|
|
61
|
+
},
|
|
62
|
+
"./search": {
|
|
63
|
+
"types": "./dist/search.d.ts",
|
|
64
|
+
"default": "./dist/search.js"
|
|
65
|
+
},
|
|
66
|
+
"./collection": {
|
|
67
|
+
"types": "./dist/collection-view.d.ts",
|
|
68
|
+
"default": "./dist/collection-view.js"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|