@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.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +97 -2
  3. package/dist/annotation-projection.d.ts +35 -0
  4. package/dist/annotation-projection.js +78 -0
  5. package/dist/annotation-projection.js.map +1 -0
  6. package/dist/artifacts.d.ts +19 -0
  7. package/dist/artifacts.js +33 -0
  8. package/dist/artifacts.js.map +1 -0
  9. package/dist/ask.d.ts +41 -0
  10. package/dist/ask.js +89 -0
  11. package/dist/ask.js.map +1 -0
  12. package/dist/collection-view.d.ts +190 -0
  13. package/dist/collection-view.js +170 -0
  14. package/dist/collection-view.js.map +1 -0
  15. package/dist/composition.d.ts +199 -0
  16. package/dist/composition.js +473 -0
  17. package/dist/composition.js.map +1 -0
  18. package/dist/condition.d.ts +17 -0
  19. package/dist/condition.js +61 -0
  20. package/dist/condition.js.map +1 -0
  21. package/dist/content-schema.d.ts +182 -0
  22. package/dist/content-schema.js +288 -0
  23. package/dist/content-schema.js.map +1 -0
  24. package/dist/context-search.d.ts +168 -0
  25. package/dist/context-search.js +73 -0
  26. package/dist/context-search.js.map +1 -0
  27. package/dist/context-store.d.ts +93 -0
  28. package/dist/context-store.js +438 -0
  29. package/dist/context-store.js.map +1 -0
  30. package/dist/dimension-runtime.d.ts +203 -0
  31. package/dist/dimension-runtime.js +737 -0
  32. package/dist/dimension-runtime.js.map +1 -0
  33. package/dist/dimensions.d.ts +84 -0
  34. package/dist/dimensions.js +136 -0
  35. package/dist/dimensions.js.map +1 -0
  36. package/dist/directory-navigation.d.ts +60 -0
  37. package/dist/directory-navigation.js +41 -0
  38. package/dist/directory-navigation.js.map +1 -0
  39. package/dist/directory-sections.d.ts +9 -0
  40. package/dist/directory-sections.js +76 -0
  41. package/dist/directory-sections.js.map +1 -0
  42. package/dist/document-reader.d.ts +1017 -0
  43. package/dist/document-reader.js +396 -0
  44. package/dist/document-reader.js.map +1 -0
  45. package/dist/document-selection.d.ts +412 -0
  46. package/dist/document-selection.js +45 -0
  47. package/dist/document-selection.js.map +1 -0
  48. package/dist/evidence.d.ts +102 -0
  49. package/dist/evidence.js +104 -0
  50. package/dist/evidence.js.map +1 -0
  51. package/dist/index.d.ts +19 -0
  52. package/dist/index.js +23 -0
  53. package/dist/model.d.ts +89 -0
  54. package/dist/model.js +31 -0
  55. package/dist/model.js.map +1 -0
  56. package/dist/module.d.ts +657 -0
  57. package/dist/module.js +199 -0
  58. package/dist/module.js.map +1 -0
  59. package/dist/navigation-view.d.ts +33 -0
  60. package/dist/navigation-view.js +68 -0
  61. package/dist/navigation-view.js.map +1 -0
  62. package/dist/node.d.ts +2004 -0
  63. package/dist/node.js +210 -0
  64. package/dist/node.js.map +1 -0
  65. package/dist/open-docs.d.ts +1396 -0
  66. package/dist/open-docs.js +198 -0
  67. package/dist/open-docs.js.map +1 -0
  68. package/dist/outline.d.ts +97 -0
  69. package/dist/outline.js +171 -0
  70. package/dist/outline.js.map +1 -0
  71. package/dist/persistence.d.ts +82 -0
  72. package/dist/persistence.js +377 -0
  73. package/dist/persistence.js.map +1 -0
  74. package/dist/projection-catalog.d.ts +23 -0
  75. package/dist/projection-catalog.js +45 -0
  76. package/dist/projection-catalog.js.map +1 -0
  77. package/dist/publication.d.ts +59 -0
  78. package/dist/publication.js +11 -0
  79. package/dist/publication.js.map +1 -0
  80. package/dist/reader.d.ts +236 -0
  81. package/dist/reader.js +400 -0
  82. package/dist/reader.js.map +1 -0
  83. package/dist/references.d.ts +54 -0
  84. package/dist/references.js +70 -0
  85. package/dist/references.js.map +1 -0
  86. package/dist/retrieval.d.ts +82 -0
  87. package/dist/retrieval.js +135 -0
  88. package/dist/retrieval.js.map +1 -0
  89. package/dist/search-view.d.ts +11 -0
  90. package/dist/search-view.js +30 -0
  91. package/dist/search-view.js.map +1 -0
  92. package/dist/search.d.ts +95 -0
  93. package/dist/search.js +234 -0
  94. package/dist/search.js.map +1 -0
  95. package/dist/semantic.d.ts +177 -0
  96. package/dist/semantic.js +104 -0
  97. package/dist/semantic.js.map +1 -0
  98. package/dist/skills.d.ts +21 -0
  99. package/dist/skills.js +42 -0
  100. package/dist/skills.js.map +1 -0
  101. package/docs/index.md +10 -0
  102. package/docs/sdk/composition.md +72 -0
  103. package/docs/sdk/reader-storage.md +70 -0
  104. package/docs/sdk/reader.md +99 -0
  105. package/docs/zh-CN/sdk/composition.md +72 -0
  106. package/docs/zh-CN/sdk/reader-storage.md +70 -0
  107. package/docs/zh-CN/sdk/reader.md +99 -0
  108. package/package.json +69 -4
@@ -0,0 +1,170 @@
1
+ import { DocsError } from "./model.js";
2
+ import { resolveContext, variantId } from "./semantic.js";
3
+
4
+ // src/collection-view.ts
5
+ /** Group an already selected page. Preserve first-seen group order and item order within each group. */
6
+ function groupCollectionItems(items, keysFor) {
7
+ const groups = /* @__PURE__ */ new Map();
8
+ for (const item of items) {
9
+ const keys = keysFor(item);
10
+ for (const key of typeof keys === "string" ? [keys] : new Set(keys)) {
11
+ let group = groups.get(key);
12
+ if (!group) groups.set(key, group = []);
13
+ group.push(item);
14
+ }
15
+ }
16
+ return Array.from(groups, ([key, items]) => ({
17
+ key,
18
+ items
19
+ }));
20
+ }
21
+ /** Resolve editions before filtering. Sort by record ID on ties so paging survives input reordering. */
22
+ function queryCollection(records, query = {}, host = {}) {
23
+ const { context = {}, offset = 0, limit } = query;
24
+ if (!Number.isSafeInteger(offset) || offset < 0 || limit !== void 0 && (!Number.isSafeInteger(limit) || limit < 0)) throw new DocsError("DOCS_QUERY_RANGE", "Collection offset and limit must be non-negative safe integers.");
25
+ const editions = /* @__PURE__ */ new Map();
26
+ for (const record of records) {
27
+ let list = editions.get(record.id);
28
+ if (!list) editions.set(record.id, list = []);
29
+ list.push({
30
+ record,
31
+ context: record.context ?? {},
32
+ priority: record.priority
33
+ });
34
+ }
35
+ const matches = [];
36
+ for (const [id, variants] of editions) {
37
+ const result = resolveContext(variants, context);
38
+ if (result.status === "ambiguous") throw new DocsError("DOCS_QUERY_AMBIGUOUS", `Ambiguous editions of ${id}.`);
39
+ if (result.status !== "exact") continue;
40
+ const { record } = result.value;
41
+ const projection = host.project ? host.project(record) : { value: record.value };
42
+ if (!projection || query.filter && !query.filter(projection.value)) continue;
43
+ matches.push({
44
+ ...record,
45
+ value: projection.value
46
+ });
47
+ }
48
+ matches.sort((a, b) => query.compare?.(a.value, b.value) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
49
+ const items = matches.slice(offset, limit === void 0 ? void 0 : offset + limit).map((record) => ({
50
+ id: record.id,
51
+ variant: variantId(record.id, record.context),
52
+ value: record.value,
53
+ revision: record.revision,
54
+ provenance: record.provenance ?? []
55
+ }));
56
+ const { groupBy } = query;
57
+ return {
58
+ total: matches.length,
59
+ items,
60
+ groups: groupBy ? groupCollectionItems(items, (item) => groupBy(item.value)) : []
61
+ };
62
+ }
63
+ /** Compare two executions of the same query. Re-execution also discovers records outside the previous read set. */
64
+ function diffCollectionViews(before, after) {
65
+ const positions = (view) => {
66
+ const memberships = /* @__PURE__ */ new Map();
67
+ for (const group of view.groups) for (const item of group.items) {
68
+ let keys = memberships.get(item.id);
69
+ if (!keys) memberships.set(item.id, keys = /* @__PURE__ */ new Set());
70
+ keys.add(group.key);
71
+ }
72
+ return new Map(view.items.map((item, index) => [item.id, {
73
+ item,
74
+ index,
75
+ groups: memberships.get(item.id)
76
+ }]));
77
+ };
78
+ const old = positions(before);
79
+ const next = positions(after);
80
+ const added = [], removed = [], updated = [], moved = [];
81
+ for (const [id, current] of next) {
82
+ const previous = old.get(id);
83
+ if (!previous) {
84
+ added.push(id);
85
+ continue;
86
+ }
87
+ if (previous.item.variant !== current.item.variant || previous.item.revision !== current.item.revision) updated.push(id);
88
+ if (previous.index !== current.index || previous.groups?.size !== current.groups?.size || current.groups && [...current.groups].some((key) => !previous.groups?.has(key))) moved.push(id);
89
+ }
90
+ for (const id of old.keys()) if (!next.has(id)) removed.push(id);
91
+ return {
92
+ added,
93
+ removed,
94
+ updated,
95
+ moved,
96
+ totalChange: after.total - before.total
97
+ };
98
+ }
99
+ function resolveQueryView(view, records, host) {
100
+ const selection = queryCollection(records, view.query, host);
101
+ const link = view.link;
102
+ const navigation = link ? selection.items.map((item) => ({
103
+ id: item.id,
104
+ variant: item.variant,
105
+ ...link(item)
106
+ })) : [];
107
+ const list = {
108
+ type: "list",
109
+ ordered: false,
110
+ items: navigation.map((link) => ({ blocks: [{
111
+ type: "paragraph",
112
+ children: [{
113
+ type: "link",
114
+ url: link.href,
115
+ children: [{
116
+ type: "text",
117
+ value: link.title
118
+ }]
119
+ }]
120
+ }] }))
121
+ };
122
+ const content = {
123
+ schemaVersion: 1,
124
+ blocks: navigation.length ? [list] : []
125
+ };
126
+ return {
127
+ placement: {
128
+ id: view.id,
129
+ route: view.route
130
+ },
131
+ selection,
132
+ navigation,
133
+ content
134
+ };
135
+ }
136
+ function matchesFields(value, fields) {
137
+ return Object.entries(fields).every(([key, expected]) => typeof value === "object" && value !== null && Object.hasOwn(value, key) && value[key] === expected);
138
+ }
139
+ function defineView(definition) {
140
+ if ("content" in definition) {
141
+ if ("from" in definition) throw new DocsError("DOCS_QUERY_SOURCE", "A view declares either a source query or composed content.");
142
+ return definition;
143
+ }
144
+ return queryView(definition);
145
+ }
146
+ function queryView(definition) {
147
+ const { from, where, sortBy, groupBy, ...view } = definition;
148
+ return {
149
+ ...definition,
150
+ resolve(sources, page = {}, host) {
151
+ const id = definition.id ?? this?.id;
152
+ if (!id) throw new DocsError("DOCS_QUERY_SOURCE", "Supply a view ID when resolving outside project discovery.");
153
+ const records = sources.get(from);
154
+ if (!records) throw new DocsError("DOCS_QUERY_SOURCE", "Missing collection source " + from + ".");
155
+ return resolveQueryView({
156
+ ...view,
157
+ id,
158
+ query: {
159
+ ...page,
160
+ filter: where && ((value) => matchesFields(value, where)),
161
+ compare: sortBy && ((a, b) => a[sortBy] < b[sortBy] ? -1 : a[sortBy] > b[sortBy] ? 1 : 0),
162
+ groupBy: groupBy && ((value) => value[groupBy])
163
+ }
164
+ }, records, host);
165
+ }
166
+ };
167
+ }
168
+
169
+ export { defineView, diffCollectionViews, groupCollectionItems, matchesFields, queryCollection, resolveQueryView };
170
+ //# sourceMappingURL=collection-view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection-view.js","names":[],"sources":["../src/collection-view.ts"],"sourcesContent":["import type { ListBlock } from \"./content-schema.js\"\nimport type { LocalizedText } from \"./directory-navigation.js\"\nimport { DocsError, type Provenance } from \"./model.js\"\nimport type { ViewPlacement } from \"./composition.js\"\nimport { resolveContext, variantId, type Context } from \"./semantic.js\"\n\n/** One source-owned edition of a record. Revisions cover metadata and content read by the view. */\nexport interface CollectionRecord<Value> {\n id: string\n context?: Context\n priority?: number\n revision: string\n value: Value\n provenance?: readonly Provenance[]\n}\n\nexport interface CollectionQueryHost<Value> {\n /** Project the selected record under host authority. Omit a denied record entirely. */\n project?(record: Readonly<CollectionRecord<Value>>): { value: Value } | undefined\n}\n\nexport interface CollectionQuery<Value> {\n context?: Context\n filter?: (value: Value) => boolean\n compare?: (left: Value, right: Value) => number\n groupBy?: (value: Value) => string | readonly string[]\n offset?: number\n limit?: number\n}\n\n/** Group an already selected page. Preserve first-seen group order and item order within each group. */\nexport function groupCollectionItems<Item>(\n items: readonly Item[],\n keysFor: (item: Item) => string | readonly string[],\n) {\n const groups = new Map<string, Item[]>()\n for (const item of items) {\n const keys = keysFor(item)\n for (const key of typeof keys === \"string\" ? [keys] : new Set(keys)) {\n let group = groups.get(key)\n if (!group) groups.set(key, (group = []))\n group.push(item)\n }\n }\n return Array.from(groups, ([key, items]) => ({ key, items }))\n}\n\n/** Resolve editions before filtering. Sort by record ID on ties so paging survives input reordering. */\nexport function queryCollection<Value>(\n records: Iterable<CollectionRecord<Value>>,\n query: CollectionQuery<Value> = {},\n host: CollectionQueryHost<Value> = {},\n) {\n const { context = {}, offset = 0, limit } = query\n if (\n !Number.isSafeInteger(offset) ||\n offset < 0 ||\n (limit !== undefined && (!Number.isSafeInteger(limit) || limit < 0))\n )\n throw new DocsError(\n \"DOCS_QUERY_RANGE\",\n \"Collection offset and limit must be non-negative safe integers.\",\n )\n const editions = new Map<\n string,\n { context: Context; priority?: number; record: CollectionRecord<Value> }[]\n >()\n for (const record of records) {\n let list = editions.get(record.id)\n if (!list) editions.set(record.id, (list = []))\n list.push({ record, context: record.context ?? {}, priority: record.priority })\n }\n const matches: CollectionRecord<Value>[] = []\n for (const [id, variants] of editions) {\n const result = resolveContext(variants, context)\n if (result.status === \"ambiguous\")\n throw new DocsError(\"DOCS_QUERY_AMBIGUOUS\", `Ambiguous editions of ${id}.`)\n if (result.status !== \"exact\") continue\n const { record } = result.value\n const projection = host.project ? host.project(record) : { value: record.value }\n if (!projection || (query.filter && !query.filter(projection.value))) continue\n matches.push({ ...record, value: projection.value })\n }\n matches.sort(\n (a, b) => query.compare?.(a.value, b.value) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0),\n )\n const page = matches.slice(offset, limit === undefined ? undefined : offset + limit)\n const items = page.map((record) => ({\n id: record.id,\n variant: variantId(record.id, record.context),\n value: record.value,\n revision: record.revision,\n provenance: record.provenance ?? [],\n }))\n const { groupBy } = query\n return {\n total: matches.length,\n items,\n groups: groupBy ? groupCollectionItems(items, (item) => groupBy(item.value)) : [],\n }\n}\n\n/** Compare two executions of the same query. Re-execution also discovers records outside the previous read set. */\nexport function diffCollectionViews<Value>(\n before: ReturnType<typeof queryCollection<Value>>,\n after: ReturnType<typeof queryCollection<Value>>,\n) {\n const positions = (view: typeof before) => {\n const memberships = new Map<string, Set<string>>()\n for (const group of view.groups)\n for (const item of group.items) {\n let keys = memberships.get(item.id)\n if (!keys) memberships.set(item.id, (keys = new Set()))\n keys.add(group.key)\n }\n return new Map(\n view.items.map((item, index) => [item.id, { item, index, groups: memberships.get(item.id) }]),\n )\n }\n const old = positions(before)\n const next = positions(after)\n const added: string[] = [],\n removed: string[] = [],\n updated: string[] = [],\n moved: string[] = []\n for (const [id, current] of next) {\n const previous = old.get(id)\n if (!previous) {\n added.push(id)\n continue\n }\n if (\n previous.item.variant !== current.item.variant ||\n previous.item.revision !== current.item.revision\n )\n updated.push(id)\n if (\n previous.index !== current.index ||\n previous.groups?.size !== current.groups?.size ||\n (current.groups && [...current.groups].some((key) => !previous.groups?.has(key)))\n )\n moved.push(id)\n }\n for (const id of old.keys()) if (!next.has(id)) removed.push(id)\n return { added, removed, updated, moved, totalChange: after.total - before.total }\n}\n\n// A host can place the same query at different routes without changing record identities.\nexport interface QueryView<Value> extends ViewPlacement {\n query: CollectionQuery<Value>\n link?: (record: { id: string; value: Value; variant: string }) => { href: string; title: string }\n}\n\nexport function resolveQueryView<Value>(\n view: QueryView<Value>,\n records: Iterable<CollectionRecord<Value>>,\n host?: CollectionQueryHost<Value>,\n) {\n const selection = queryCollection(records, view.query, host)\n const link = view.link\n const navigation = link\n ? selection.items.map((item) => ({ id: item.id, variant: item.variant, ...link(item) }))\n : []\n const list: ListBlock = {\n type: \"list\",\n ordered: false,\n items: navigation.map((link) => ({\n blocks: [\n {\n type: \"paragraph\",\n children: [\n { type: \"link\", url: link.href, children: [{ type: \"text\", value: link.title }] },\n ],\n },\n ],\n })),\n }\n const content = { schemaVersion: 1 as const, blocks: navigation.length ? [list] : [] }\n return { placement: { id: view.id, route: view.route }, selection, navigation, content }\n}\n\ntype FieldOf<Value, Kind> = Extract<\n { [Key in keyof Value]-?: Value[Key] extends Kind ? Key : never }[keyof Value],\n string\n>\ntype Scalar = string | number | boolean | null\n\n/** Portable record predicates use only own scalar fields. A producer can send the same terms to an adapter. */\nexport type FieldSelection = Readonly<Record<string, string | number | boolean | null>>\nexport function matchesFields(value: unknown, fields: Readonly<Record<string, unknown>>): boolean {\n return Object.entries(fields).every(\n ([key, expected]) =>\n typeof value === \"object\" &&\n value !== null &&\n Object.hasOwn(value, key) &&\n (value as Record<string, unknown>)[key] === expected,\n )\n}\n\n/** Bind a named record source to a placed view using the ordinary edition, paging and dependency rules. */\nexport type QueryDefinition<Value extends object, From = string> = ViewPlacement & {\n dimensionDefinitions?: import(\"./dimensions.js\").DimensionDefinitions\n from: From\n content?: never\n title?: LocalizedText\n where?: Partial<Pick<Value, FieldOf<Value, Scalar>>>\n sortBy?: FieldOf<Value, string | number>\n groupBy?: FieldOf<Value, string | readonly string[]>\n link?: QueryView<Value>[\"link\"]\n}\n\ntype SourceData<From> = From extends { kind: \"docs-source\"; load(...args: any[]): infer Output }\n ? Awaited<Output> extends { records?: readonly (infer Row)[] }\n ? Extract<Row, { data: object }>[\"data\"]\n : never\n : From extends { from: infer Source }\n ? SourceData<Source>\n : From extends readonly (infer Source)[]\n ? SourceData<Source>\n : never\n\ntype InferredQueryDefinition<Value extends object, From> = Omit<\n QueryDefinition<Value, From>,\n \"id\"\n> & {\n id?: string\n}\n\nexport function defineView<\n const Definition extends {\n id?: string\n route?: string\n from?: never\n content: readonly unknown[]\n },\n>(definition: Definition): Definition\nexport function defineView<Value extends object>(\n definition: QueryDefinition<Value>,\n): ReturnType<typeof queryView<Value, string, QueryDefinition<Value>>>\nexport function defineView<From extends object>(\n definition: QueryDefinition<SourceData<From>, From>,\n): ReturnType<typeof queryView<SourceData<From>, From, QueryDefinition<SourceData<From>, From>>>\nexport function defineView<From extends object>(\n definition: InferredQueryDefinition<SourceData<From>, From>,\n): ReturnType<\n typeof queryView<SourceData<From>, From, InferredQueryDefinition<SourceData<From>, From>>\n>\nexport function defineView(\n definition: { id?: string; content: readonly unknown[] } | { id?: string; from: unknown },\n): unknown {\n if (\"content\" in definition) {\n if (\"from\" in definition)\n throw new DocsError(\n \"DOCS_QUERY_SOURCE\",\n \"A view declares either a source query or composed content.\",\n )\n return definition\n }\n return queryView<object, unknown, typeof definition>(definition)\n}\n\nfunction queryView<\n Value extends object,\n From,\n Definition extends InferredQueryDefinition<Value, From>,\n>(definition: Definition) {\n const { from, where, sortBy, groupBy, ...view } = definition\n return {\n ...definition,\n resolve(\n this: { id?: string } | void,\n sources: ReadonlyMap<From, Iterable<CollectionRecord<Value>>>,\n page: Pick<CollectionQuery<Value>, \"offset\" | \"limit\" | \"context\"> = {},\n host?: CollectionQueryHost<Value>,\n ) {\n const id = definition.id ?? this?.id\n if (!id)\n throw new DocsError(\n \"DOCS_QUERY_SOURCE\",\n \"Supply a view ID when resolving outside project discovery.\",\n )\n const records = sources.get(from)\n if (!records)\n throw new DocsError(\"DOCS_QUERY_SOURCE\", \"Missing collection source \" + from + \".\")\n return resolveQueryView<Value>(\n {\n ...view,\n id,\n query: {\n ...page,\n filter: where && ((value) => matchesFields(value, where)),\n compare:\n sortBy && ((a, b) => (a[sortBy] < b[sortBy] ? -1 : a[sortBy] > b[sortBy] ? 1 : 0)),\n groupBy: groupBy && ((value) => value[groupBy] as string | readonly string[]),\n },\n },\n records,\n host,\n )\n },\n }\n}\n"],"mappings":";;;;;AA+BA,SAAgB,qBACd,OACA,SACA;CACA,MAAM,yBAAS,IAAI,IAAoB;CACvC,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,OAAO,QAAQ,IAAI;EACzB,KAAK,MAAM,OAAO,OAAO,SAAS,WAAW,CAAC,IAAI,IAAI,IAAI,IAAI,IAAI,GAAG;GACnE,IAAI,QAAQ,OAAO,IAAI,GAAG;GAC1B,IAAI,CAAC,OAAO,OAAO,IAAI,KAAM,QAAQ,CAAC,CAAE;GACxC,MAAM,KAAK,IAAI;EACjB;CACF;CACA,OAAO,MAAM,KAAK,SAAS,CAAC,KAAK,YAAY;EAAE;EAAK;CAAM,EAAE;AAC9D;;AAGA,SAAgB,gBACd,SACA,QAAgC,CAAC,GACjC,OAAmC,CAAC,GACpC;CACA,MAAM,EAAE,UAAU,CAAC,GAAG,SAAS,GAAG,UAAU;CAC5C,IACE,CAAC,OAAO,cAAc,MAAM,KAC5B,SAAS,KACR,UAAU,WAAc,CAAC,OAAO,cAAc,KAAK,KAAK,QAAQ,IAEjE,MAAM,I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AAI,UACR,qBACA,4DACF;GACF,MAAM,UAAU,QAAQ,IAAI,IAAI;GAChC,IAAI,CAAC,SACH,MAAM,IAAI,UAAU,qBAAqB,+BAA+B,OAAO,GAAG;GACpF,OAAO,iBACL;IACE,GAAG;IACH;IACA,OAAO;KACL,GAAG;KACH,QAAQ,WAAW,UAAU,cAAc,OAAO,KAAK;KACvD,SACE,YAAY,GAAG,MAAO,EAAE,UAAU,EAAE,UAAU,KAAK,EAAE,UAAU,EAAE,UAAU,IAAI;KACjF,SAAS,aAAa,UAAU,MAAM;IACxC;GACF,GACA,SACA,IACF;EACF;CACF;AACF"}
@@ -0,0 +1,199 @@
1
+ import { type ValueReference } from "./content-schema.js";
2
+ import { type Provenance, type ProjectionLoss } from "./model.js";
3
+ import { createSemanticReader } from "./reader.js";
4
+ import type { ReadDocumentExport } from "./module.js";
5
+ import { type Context, type EntityVariant } from "./semantic.js";
6
+ import { type Arguments, type AttributeSchema, type FragmentInclude, type CustomBlockSchema, type JsonValue, type LiteralBlock, type ContentTree } from "./content-schema.js";
7
+ /** A location chosen by a consuming application. Embedded placements can omit a route. */
8
+ export interface ViewPlacement {
9
+ id: string;
10
+ route?: string;
11
+ }
12
+ export interface DocumentView extends ViewPlacement {
13
+ document: string;
14
+ factRevision?: string;
15
+ context: Context;
16
+ arguments?: Arguments;
17
+ overrides?: FragmentInclude["overrides"];
18
+ links?: Readonly<Record<string, string>>;
19
+ }
20
+ type Reader = Pick<ReturnType<typeof createSemanticReader>, "resolve">;
21
+ type ReadFact = (id: string) => EntityVariant;
22
+ /** Owner of content, including the caller that supplied a slot override. */
23
+ export type BlockOrigin = {
24
+ kind: "placement";
25
+ placement: string;
26
+ } | {
27
+ kind: "entity";
28
+ entity: string;
29
+ variant: string;
30
+ provenance: readonly Provenance[];
31
+ };
32
+ export interface ContentRenderGroup {
33
+ type: string;
34
+ props: JsonValue;
35
+ start: number;
36
+ end: number;
37
+ }
38
+ export interface BlockProjection {
39
+ /** Trusted content type dispatched by an optional renderer after semantic projection. */
40
+ renderer?: string;
41
+ /** Host policy, checked before attribute validation, migration and projection. */
42
+ allowsSource?(origin: BlockOrigin): boolean;
43
+ schema?: CustomBlockSchema;
44
+ /** Trusted host code validates attributes, then projects them to portable blocks. Reads are tracked. */
45
+ project(attrs: JsonValue, read: ReadFact, parameters?: Arguments, children?: readonly LiteralBlock[]): readonly LiteralBlock[];
46
+ }
47
+ export interface ContentProjections {
48
+ /** Resolve producer-owned or request-specific data. Untrusted published nodes carry descriptions only. */
49
+ observeValue?(ref: ValueReference, value: JsonValue, variant?: string): void;
50
+ value?(ref: ValueReference, parameters: Arguments, origin: BlockOrigin): JsonValue;
51
+ blocks?: ReadonlyMap<string, BlockProjection>;
52
+ annotations?: ReadonlyMap<string, AnnotationProjection>;
53
+ }
54
+ type Projections = ReadonlyMap<string, BlockProjection> | ContentProjections;
55
+ export interface ViewDependency {
56
+ entity: string;
57
+ variant: string;
58
+ revision: string;
59
+ provenanceRevision?: string;
60
+ provenance: Provenance[];
61
+ }
62
+ /** Resolve the same scalar selector for JSON blocks and authored MDX. */
63
+ export declare function readFactScalar(data: unknown, target: string, selector: string, source: string): string | number | boolean;
64
+ export declare function selectFactValue(data: unknown, target: string, selector: string, source: string): string;
65
+ /** Materialize an independently placed document. Includes and custom blocks read the same context-pinned index. */
66
+ export declare function composeView(view: DocumentView, reader: Reader, extensions?: Projections): {
67
+ view: DocumentView;
68
+ content: {
69
+ schemaVersion: 1;
70
+ blocks: LiteralBlock[];
71
+ renderGroups?: ContentRenderGroup[] | undefined;
72
+ losses?: ProjectionLoss[] | undefined;
73
+ };
74
+ dependencies: ViewDependency[];
75
+ };
76
+ /** Copy the resolved instance into locally owned literal blocks, retaining a receipt for the original reads. */
77
+ export declare function detachFragment(instance: FragmentInclude, context: Context, reader: Reader, extensions?: Projections, links?: DocumentView["links"]): {
78
+ content: {
79
+ schemaVersion: 1;
80
+ blocks: LiteralBlock[];
81
+ renderGroups?: ContentRenderGroup[] | undefined;
82
+ losses?: ProjectionLoss[] | undefined;
83
+ };
84
+ sources: ViewDependency[];
85
+ };
86
+ /** Resolve a directly authored tree with the same reference and projection rules as an included fragment. */
87
+ export declare function composeContent(content: ContentTree, origin: BlockOrigin, context: Context, extensions?: Projections, reader?: Reader): {
88
+ content: {
89
+ schemaVersion: 1;
90
+ blocks: LiteralBlock[];
91
+ renderGroups?: ContentRenderGroup[] | undefined;
92
+ losses?: ProjectionLoss[] | undefined;
93
+ };
94
+ dependencies: ViewDependency[];
95
+ };
96
+ /** Re-resolve recorded reads to catch removed, changed, ambiguous and newly more-specific variants. */
97
+ export declare function affectedViews(previous: readonly ReturnType<typeof composeView>[], next: Reader): string[];
98
+ export declare function blockLosses(block: LiteralBlock): ProjectionLoss[];
99
+ export interface AnnotationProjection {
100
+ renderer?: string;
101
+ schema: AttributeSchema;
102
+ /** Host policy. A restricted projection requires an origin and is checked before running the schema. */
103
+ allowsSource?(origin: BlockOrigin): boolean;
104
+ /** Wrap the annotated children in a portable format. Core retains their text and nested formatting. */
105
+ project(attrs: JsonValue): {
106
+ type: "link";
107
+ url: string;
108
+ title?: string;
109
+ } | {
110
+ type: "strong" | "emphasis" | "strikethrough";
111
+ };
112
+ }
113
+ export type { ContentTree, ContentBlock, LiteralBlock, FragmentInclude } from "./content-schema.js";
114
+ /** A host-selected overlay supplies a semantic content entity for a named slot of a pinned upstream view. */
115
+ export interface SlotOverlay {
116
+ owner: string;
117
+ entity: string;
118
+ slot: string;
119
+ priority: number;
120
+ upstreamFactRevision: string;
121
+ /** Exact applicability dimensions, such as the installed software version. */
122
+ context?: Context;
123
+ /** Optional content pin for reproducible consumption. */
124
+ factRevision?: string;
125
+ }
126
+ export interface OverlayReceipt {
127
+ /** Resolved includes and facts read by projections, including their provenance revision. */
128
+ dependencies: Omit<ViewDependency, "provenance">[];
129
+ publications?: {
130
+ package: string;
131
+ version: string;
132
+ inventoryRevision: string;
133
+ export: string;
134
+ entity: string;
135
+ }[];
136
+ upstream: {
137
+ entity: string;
138
+ variant: string;
139
+ revision: string;
140
+ factRevision: string;
141
+ };
142
+ slots: {
143
+ slot: string;
144
+ owner: string;
145
+ entity: string;
146
+ variant: string;
147
+ revision: string;
148
+ priority: number;
149
+ selected: boolean;
150
+ }[];
151
+ }
152
+ type OverlayDiagnostic = {
153
+ slot?: string;
154
+ owner?: string;
155
+ entity: string;
156
+ reason: string;
157
+ expected?: string;
158
+ actual?: string;
159
+ };
160
+ /** Resolve team overlays first, then feed the resulting includes to the ordinary view materializer. */
161
+ export declare function composeOverlays(view: DocumentView, overlays: readonly SlotOverlay[], reader: Reader, extensions?: Projections): {
162
+ status: "blocked";
163
+ diagnostics: OverlayDiagnostic[];
164
+ } | {
165
+ view: DocumentView;
166
+ content: {
167
+ schemaVersion: 1;
168
+ blocks: LiteralBlock[];
169
+ renderGroups?: ContentRenderGroup[] | undefined;
170
+ losses?: ProjectionLoss[] | undefined;
171
+ };
172
+ dependencies: ViewDependency[];
173
+ diagnostics?: undefined;
174
+ status: "ready";
175
+ receipt: OverlayReceipt;
176
+ };
177
+ type PublishedContent = Extract<ReadDocumentExport, {
178
+ status: "exact";
179
+ }>;
180
+ type PublishedOverlay = Omit<SlotOverlay, "entity"> & {
181
+ content: PublishedContent;
182
+ };
183
+ /** Compose only public exports the host opened. Retain the exact upstream and team releases in the overlay lock. */
184
+ export declare function composePublishedOverlays(view: Omit<DocumentView, "document">, upstream: PublishedContent, overlays: readonly PublishedOverlay[], imports?: readonly PublishedContent[], extensions?: Projections): {
185
+ status: "blocked";
186
+ diagnostics: OverlayDiagnostic[];
187
+ } | {
188
+ view: DocumentView;
189
+ content: {
190
+ schemaVersion: 1;
191
+ blocks: LiteralBlock[];
192
+ renderGroups?: ContentRenderGroup[] | undefined;
193
+ losses?: ProjectionLoss[] | undefined;
194
+ };
195
+ dependencies: ViewDependency[];
196
+ diagnostics?: undefined;
197
+ status: "ready";
198
+ receipt: OverlayReceipt;
199
+ };