@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,473 @@
|
|
|
1
|
+
import { bindArguments, isContentTree, isValueReference, record, upgradeCustomBlock } from "./content-schema.js";
|
|
2
|
+
import { materializeAnnotations } from "./annotation-projection.js";
|
|
3
|
+
import { DocsError } from "./model.js";
|
|
4
|
+
import { createSemanticReader } from "./reader.js";
|
|
5
|
+
import { resolveContext, variantId } from "./semantic.js";
|
|
6
|
+
|
|
7
|
+
// src/composition.ts
|
|
8
|
+
/** Resolve the same scalar selector for JSON blocks and authored MDX. */
|
|
9
|
+
function readFactScalar(data, target, selector, source) {
|
|
10
|
+
let value = data;
|
|
11
|
+
for (const key of selector.split(".")) {
|
|
12
|
+
if (!key || !record(value) || !Object.hasOwn(value, key)) throw new DocsError("DOCS_CONTENT_SELECTOR", `Missing ${selector} on ${target} in ${source}.`, { source });
|
|
13
|
+
value = value[key];
|
|
14
|
+
}
|
|
15
|
+
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") throw new DocsError("DOCS_CONTENT_SELECTOR", `Expected a scalar at ${target}.${selector} in ${source}.`, { source });
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
function selectFactValue(data, target, selector, source) {
|
|
19
|
+
return String(readFactScalar(data, target, selector, source));
|
|
20
|
+
}
|
|
21
|
+
/** Materialize an independently placed document. Includes and custom blocks read the same context-pinned index. */
|
|
22
|
+
function composeView(view, reader, extensions = {}) {
|
|
23
|
+
return {
|
|
24
|
+
view,
|
|
25
|
+
...materialize(view, {
|
|
26
|
+
type: "include",
|
|
27
|
+
target: view.document,
|
|
28
|
+
factRevision: view.factRevision,
|
|
29
|
+
arguments: view.arguments,
|
|
30
|
+
overrides: view.overrides
|
|
31
|
+
}, reader, extensions)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Copy the resolved instance into locally owned literal blocks, retaining a receipt for the original reads. */
|
|
35
|
+
function detachFragment(instance, context, reader, extensions = {}, links) {
|
|
36
|
+
const resolved = materialize({
|
|
37
|
+
id: instance.target,
|
|
38
|
+
context,
|
|
39
|
+
links
|
|
40
|
+
}, instance, reader, extensions);
|
|
41
|
+
return {
|
|
42
|
+
content: structuredClone(resolved.content),
|
|
43
|
+
sources: structuredClone(resolved.dependencies)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** Resolve a directly authored tree with the same reference and projection rules as an included fragment. */
|
|
47
|
+
function composeContent(content, origin, context, extensions = {}, reader) {
|
|
48
|
+
return materialize({
|
|
49
|
+
id: origin.kind === "entity" ? origin.entity : origin.placement,
|
|
50
|
+
context
|
|
51
|
+
}, {
|
|
52
|
+
content,
|
|
53
|
+
origin
|
|
54
|
+
}, reader ?? { resolve: () => ({ status: "not-found" }) }, extensions);
|
|
55
|
+
}
|
|
56
|
+
function materialize(view, root, reader, extensions) {
|
|
57
|
+
const { blocks: blockProjections, annotations } = "get" in extensions ? { blocks: extensions } : extensions;
|
|
58
|
+
const valueProvider = "get" in extensions ? void 0 : extensions.value;
|
|
59
|
+
function resolveValue(ref, args, origin) {
|
|
60
|
+
function observed(value, variant) {
|
|
61
|
+
if (!("get" in extensions)) extensions.observeValue?.(ref, value, variant);
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
if (ref.kind === "entity" && ref.select) {
|
|
65
|
+
const fact = read(ref.key);
|
|
66
|
+
return observed(readFactScalar(fact.data, ref.key, ref.select, view.id), fact.variantId);
|
|
67
|
+
}
|
|
68
|
+
if (ref.kind === "param" && Object.hasOwn(args, ref.key) && !ref.select) return observed(args[ref.key]);
|
|
69
|
+
if (ref.kind === "context" && view.context && Object.hasOwn(view.context, ref.key) && !ref.select) return observed(view.context[ref.key]);
|
|
70
|
+
if (valueProvider) return valueProvider(ref, args, origin);
|
|
71
|
+
throw new DocsError("DOCS_VALUE_MISSING", "No value provider for " + ref.key, { source: view.id });
|
|
72
|
+
}
|
|
73
|
+
function resolveAttrs(attrs, args, origin) {
|
|
74
|
+
if (attrs === null || typeof attrs !== "object") return attrs;
|
|
75
|
+
if (Array.isArray(attrs)) return attrs.map((item) => resolveAttrs(item, args, origin));
|
|
76
|
+
if (Object.keys(attrs).length === 1 && Object.hasOwn(attrs, "$value")) {
|
|
77
|
+
if (!isValueReference(attrs.$value)) throw new DocsError("DOCS_VALUE_REFERENCE", "Invalid native value reference.", { source: view.id });
|
|
78
|
+
return resolveValue(attrs.$value, args, origin);
|
|
79
|
+
}
|
|
80
|
+
return Object.fromEntries(Object.entries(attrs).map(([key, value]) => [key, resolveAttrs(value, args, origin)]));
|
|
81
|
+
}
|
|
82
|
+
const dependencies = /* @__PURE__ */ new Map();
|
|
83
|
+
const blocks = [];
|
|
84
|
+
let owners;
|
|
85
|
+
const path = /* @__PURE__ */ new Set();
|
|
86
|
+
function read(entity) {
|
|
87
|
+
const result = reader.resolve(entity, view.context);
|
|
88
|
+
if (result.status !== "exact") throw new DocsError("DOCS_CONTENT_REFERENCE", `${view.id}: ${entity} (${result.status}).`);
|
|
89
|
+
const fact = result.value;
|
|
90
|
+
dependencies.set(entity, {
|
|
91
|
+
entity,
|
|
92
|
+
variant: fact.variantId,
|
|
93
|
+
revision: fact.revision,
|
|
94
|
+
provenanceRevision: fact.provenanceRevision,
|
|
95
|
+
provenance: fact.provenance
|
|
96
|
+
});
|
|
97
|
+
return fact;
|
|
98
|
+
}
|
|
99
|
+
function target(id, pin) {
|
|
100
|
+
const fact = read(id);
|
|
101
|
+
if (pin !== void 0 && fact.factRevision !== pin) throw new DocsError("DOCS_CONTENT_PIN", `Stale fact pin for ${fact.variantId}.`);
|
|
102
|
+
return fact;
|
|
103
|
+
}
|
|
104
|
+
function include({ target: id, factRevision: pin, overrides, arguments: args }, overrideOrigin = {
|
|
105
|
+
kind: "placement",
|
|
106
|
+
placement: view.id
|
|
107
|
+
}) {
|
|
108
|
+
const fact = target(id, pin);
|
|
109
|
+
if (path.has(id)) throw new DocsError("DOCS_CONTENT_CYCLE", [...path, id].join(" -> "));
|
|
110
|
+
if (!isContentTree(fact.data)) throw new DocsError("DOCS_CONTENT_INVALID", `Invalid content tree in ${id}.`);
|
|
111
|
+
const parameters = bindArguments(id, fact.data.parameters, args);
|
|
112
|
+
const owner = {
|
|
113
|
+
kind: "entity",
|
|
114
|
+
entity: id,
|
|
115
|
+
variant: fact.variantId,
|
|
116
|
+
provenance: fact.provenance
|
|
117
|
+
};
|
|
118
|
+
path.add(id);
|
|
119
|
+
const declared = /* @__PURE__ */ new Set();
|
|
120
|
+
for (const { blockId: _address, ...block } of fact.data.blocks) if (block.type === "slot") {
|
|
121
|
+
if (declared.has(block.name)) throw new DocsError("DOCS_CONTENT_SLOT", `Duplicate slot ${block.name} in ${id}.`);
|
|
122
|
+
declared.add(block.name);
|
|
123
|
+
const local = overrides && Object.hasOwn(overrides, block.name);
|
|
124
|
+
for (const child of local ? overrides[block.name] : block.fallback) emit(child, parameters, local ? overrideOrigin : owner);
|
|
125
|
+
} else emit(block, parameters, owner);
|
|
126
|
+
for (const name of Object.keys(overrides ?? {})) if (!declared.has(name)) throw new DocsError("DOCS_CONTENT_SLOT", `Unknown slot ${name} in ${id}.`);
|
|
127
|
+
path.delete(id);
|
|
128
|
+
}
|
|
129
|
+
function emit(block, parameters, origin) {
|
|
130
|
+
if (block.type === "include") include(block, origin);
|
|
131
|
+
else if (block.type === "value") {
|
|
132
|
+
const value = resolveValue(block.ref, parameters, origin);
|
|
133
|
+
if (typeof value === "object" && value !== null) throw new DocsError("DOCS_VALUE_TYPE", "Native text needs a scalar value.", { source: view.id });
|
|
134
|
+
blocks.push({
|
|
135
|
+
type: "paragraph",
|
|
136
|
+
children: [{
|
|
137
|
+
type: "text",
|
|
138
|
+
value: String(value)
|
|
139
|
+
}]
|
|
140
|
+
});
|
|
141
|
+
} else if (block.type === "reference") {
|
|
142
|
+
const fact = target(block.target, block.factRevision);
|
|
143
|
+
if (block.select !== void 0) {
|
|
144
|
+
const value = selectFactValue(fact.data, block.target, block.select, view.id);
|
|
145
|
+
blocks.push({
|
|
146
|
+
type: "paragraph",
|
|
147
|
+
children: [{
|
|
148
|
+
type: "text",
|
|
149
|
+
value
|
|
150
|
+
}]
|
|
151
|
+
});
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const url = view.links && Object.hasOwn(view.links, block.target) ? view.links[block.target] : block.target.startsWith("document:") && record(fact.data) ? fact.data.route : void 0;
|
|
155
|
+
if (typeof url !== "string" || !url.trim()) throw new DocsError("DOCS_CONTENT_PLACEMENT", `Missing link for ${block.target} in ${view.id}.`);
|
|
156
|
+
blocks.push({
|
|
157
|
+
type: "paragraph",
|
|
158
|
+
children: [{
|
|
159
|
+
type: "link",
|
|
160
|
+
url,
|
|
161
|
+
children: [{
|
|
162
|
+
type: "text",
|
|
163
|
+
value: block.label
|
|
164
|
+
}]
|
|
165
|
+
}]
|
|
166
|
+
});
|
|
167
|
+
} else if (block.type === "custom") {
|
|
168
|
+
const extension = blockProjections?.get(block.name);
|
|
169
|
+
if (!extension || extension.allowsSource && !extension.allowsSource(origin)) {
|
|
170
|
+
const source = origin.kind === "entity" ? origin.provenance[0]?.source ?? origin.entity : origin.placement;
|
|
171
|
+
if (extension && !block.fallbackText) throw new DocsError("DOCS_CONTENT_BLOCK_SOURCE", `Projection for ${block.name} does not allow this source in ${view.id}.`, { source });
|
|
172
|
+
if (!block.fallbackText) throw new DocsError("DOCS_CONTENT_BLOCK", `Missing projection for ${block.name} in ${view.id}.`);
|
|
173
|
+
const losses = ["web", "markdown"].map((target) => ({
|
|
174
|
+
target,
|
|
175
|
+
kind: "custom-block",
|
|
176
|
+
severity: "warning",
|
|
177
|
+
source,
|
|
178
|
+
message: `Used the author's text alternative for ${block.name} in ${view.id}.`
|
|
179
|
+
}));
|
|
180
|
+
blocks.push({
|
|
181
|
+
type: "paragraph",
|
|
182
|
+
children: [{
|
|
183
|
+
type: "text",
|
|
184
|
+
value: block.fallbackText
|
|
185
|
+
}],
|
|
186
|
+
losses
|
|
187
|
+
});
|
|
188
|
+
for (const child of block.children ?? []) emit(child, parameters, origin);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (!extension.schema && (block.version ?? 1) !== 1) throw new DocsError("DOCS_BLOCK_SCHEMA", `No versioned schema registered for ${block.name}.`);
|
|
192
|
+
const input = resolveAttrs(block.attrs, parameters, origin);
|
|
193
|
+
const attrs = extension.schema ? upgradeCustomBlock({
|
|
194
|
+
...block,
|
|
195
|
+
attrs: input
|
|
196
|
+
}, extension.schema).attrs : input;
|
|
197
|
+
const start = blocks.length;
|
|
198
|
+
for (const child of block.children ?? []) emit(child, parameters, origin);
|
|
199
|
+
const children = block.children?.length ? blocks.splice(start) : void 0;
|
|
200
|
+
const group = extension.renderer && {
|
|
201
|
+
type: extension.renderer,
|
|
202
|
+
props: attrs
|
|
203
|
+
};
|
|
204
|
+
for (const projected of extension.project(attrs, read, parameters, children)) {
|
|
205
|
+
const output = append(projected, origin);
|
|
206
|
+
if (group) (owners ??= /* @__PURE__ */ new WeakMap()).set(output, [group, ...owners.get(projected) ?? []]);
|
|
207
|
+
}
|
|
208
|
+
} else append(block, origin);
|
|
209
|
+
}
|
|
210
|
+
function append(block, origin) {
|
|
211
|
+
const output = annotations ? materializeAnnotations(block, annotations, origin) : block;
|
|
212
|
+
blocks.push(output);
|
|
213
|
+
return output;
|
|
214
|
+
}
|
|
215
|
+
if ("content" in root) {
|
|
216
|
+
if (!isContentTree(root.content)) throw new DocsError("DOCS_CONTENT_INVALID", "Invalid structured content.", { source: view.id });
|
|
217
|
+
const parameters = bindArguments(view.id, root.content.parameters);
|
|
218
|
+
for (const block of root.content.blocks) if (block.type === "slot") for (const child of block.fallback) emit(child, parameters, root.origin);
|
|
219
|
+
else emit(block, parameters, root.origin);
|
|
220
|
+
} else include(root);
|
|
221
|
+
const renderGroups = [];
|
|
222
|
+
let active = [];
|
|
223
|
+
if (owners) for (const [index, block] of blocks.entries()) active = (owners.get(block) ?? []).map((owner, depth) => {
|
|
224
|
+
const existing = active[depth];
|
|
225
|
+
if (existing?.owner === owner) {
|
|
226
|
+
existing.span.end = index + 1;
|
|
227
|
+
return existing;
|
|
228
|
+
}
|
|
229
|
+
const span = {
|
|
230
|
+
...owner,
|
|
231
|
+
start: index,
|
|
232
|
+
end: index + 1
|
|
233
|
+
};
|
|
234
|
+
renderGroups.push(span);
|
|
235
|
+
return {
|
|
236
|
+
owner,
|
|
237
|
+
span
|
|
238
|
+
};
|
|
239
|
+
});
|
|
240
|
+
const losses = blocks.flatMap(blockLosses);
|
|
241
|
+
return {
|
|
242
|
+
content: {
|
|
243
|
+
schemaVersion: 1,
|
|
244
|
+
blocks,
|
|
245
|
+
...renderGroups.length && { renderGroups },
|
|
246
|
+
...losses.length && { losses }
|
|
247
|
+
},
|
|
248
|
+
dependencies: [...dependencies.values()]
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
/** Re-resolve recorded reads to catch removed, changed, ambiguous and newly more-specific variants. */
|
|
252
|
+
function affectedViews(previous, next) {
|
|
253
|
+
return previous.filter(({ view, dependencies }) => dependencies.some((dep) => {
|
|
254
|
+
const result = next.resolve(dep.entity, view.context);
|
|
255
|
+
return result.status !== "exact" || result.value.variantId !== dep.variant || result.value.revision !== dep.revision || result.value.provenanceRevision !== dep.provenanceRevision;
|
|
256
|
+
})).map((result) => result.view.id);
|
|
257
|
+
}
|
|
258
|
+
function blockLosses(block) {
|
|
259
|
+
const own = block.losses ?? [];
|
|
260
|
+
if (block.type === "blockquote") return [...own, ...block.blocks.flatMap(blockLosses)];
|
|
261
|
+
if (block.type === "list") return [...own, ...block.items.flatMap((item) => item.blocks.flatMap(blockLosses))];
|
|
262
|
+
return own;
|
|
263
|
+
}
|
|
264
|
+
/** Resolve team overlays first, then feed the resulting includes to the ordinary view materializer. */
|
|
265
|
+
function composeOverlays(view, overlays, reader, extensions = {}) {
|
|
266
|
+
const upstream = reader.resolve(view.document, view.context);
|
|
267
|
+
const diagnostics = [];
|
|
268
|
+
if (upstream.status !== "exact" || !upstream.value.factRevision || !isContentTree(upstream.value.data)) return {
|
|
269
|
+
status: "blocked",
|
|
270
|
+
diagnostics: [{
|
|
271
|
+
entity: view.document,
|
|
272
|
+
reason: upstream.status === "exact" ? "unversioned-or-invalid-content" : upstream.status
|
|
273
|
+
}]
|
|
274
|
+
};
|
|
275
|
+
const fact = upstream.value;
|
|
276
|
+
const slots = new Set(upstream.value.data.blocks.flatMap((block) => block.type === "slot" ? [block.name] : []));
|
|
277
|
+
const receipt = {
|
|
278
|
+
dependencies: [],
|
|
279
|
+
upstream: {
|
|
280
|
+
entity: view.document,
|
|
281
|
+
variant: fact.variantId,
|
|
282
|
+
revision: fact.revision,
|
|
283
|
+
factRevision: upstream.value.factRevision
|
|
284
|
+
},
|
|
285
|
+
slots: []
|
|
286
|
+
};
|
|
287
|
+
const groups = /* @__PURE__ */ new Map();
|
|
288
|
+
const compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
289
|
+
const ordered = [...overlays].sort((a, b) => compare(a.slot, b.slot) || b.priority - a.priority || compare(a.owner, b.owner) || compare(a.entity, b.entity));
|
|
290
|
+
for (const overlay of ordered) {
|
|
291
|
+
const { entity, owner, slot, priority } = overlay;
|
|
292
|
+
const report = (reason, expected, actual) => diagnostics.push({
|
|
293
|
+
entity,
|
|
294
|
+
slot,
|
|
295
|
+
owner,
|
|
296
|
+
reason,
|
|
297
|
+
...expected !== void 0 && { expected },
|
|
298
|
+
...actual !== void 0 && { actual }
|
|
299
|
+
});
|
|
300
|
+
if (!owner.trim() || !Number.isSafeInteger(priority)) {
|
|
301
|
+
report("invalid-declaration");
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (overlay.upstreamFactRevision !== fact.factRevision) {
|
|
305
|
+
report("stale-upstream", overlay.upstreamFactRevision, fact.factRevision);
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
if (!slots.has(slot)) {
|
|
309
|
+
report("missing-slot");
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
if (Object.hasOwn(view.overrides ?? {}, slot)) {
|
|
313
|
+
report("placement-conflict");
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
const applicability = resolveContext([{ context: overlay.context ?? {} }], view.context);
|
|
317
|
+
if (applicability.status !== "exact") {
|
|
318
|
+
report(applicability.status);
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
const content = reader.resolve(entity, view.context);
|
|
322
|
+
if (content.status !== "exact") {
|
|
323
|
+
report(content.status);
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
if (!isContentTree(content.value.data)) {
|
|
327
|
+
report("invalid-content");
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
if (overlay.factRevision !== void 0 && overlay.factRevision !== content.value.factRevision) {
|
|
331
|
+
report("stale-overlay", overlay.factRevision, content.value.factRevision);
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
const record = {
|
|
335
|
+
slot,
|
|
336
|
+
owner,
|
|
337
|
+
entity,
|
|
338
|
+
variant: content.value.variantId,
|
|
339
|
+
revision: content.value.revision,
|
|
340
|
+
priority,
|
|
341
|
+
selected: false
|
|
342
|
+
};
|
|
343
|
+
receipt.slots.push(record);
|
|
344
|
+
const existing = groups.get(slot);
|
|
345
|
+
if (existing) existing.push(record);
|
|
346
|
+
else groups.set(slot, [record]);
|
|
347
|
+
}
|
|
348
|
+
const overrides = Object.assign(Object.create(null), view.overrides);
|
|
349
|
+
for (const [slot, group] of groups) {
|
|
350
|
+
const winner = group[0];
|
|
351
|
+
const tied = group.filter((item) => item.priority === winner.priority);
|
|
352
|
+
if (tied.length > 1) {
|
|
353
|
+
for (const item of tied) diagnostics.push({
|
|
354
|
+
slot,
|
|
355
|
+
owner: item.owner,
|
|
356
|
+
entity: item.entity,
|
|
357
|
+
reason: "equal-priority"
|
|
358
|
+
});
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
winner.selected = true;
|
|
362
|
+
overrides[slot] = [{
|
|
363
|
+
type: "include",
|
|
364
|
+
target: winner.entity
|
|
365
|
+
}];
|
|
366
|
+
}
|
|
367
|
+
if (diagnostics.length) return {
|
|
368
|
+
status: "blocked",
|
|
369
|
+
diagnostics
|
|
370
|
+
};
|
|
371
|
+
const composed = composeView({
|
|
372
|
+
...view,
|
|
373
|
+
overrides
|
|
374
|
+
}, reader, extensions);
|
|
375
|
+
receipt.dependencies = composed.dependencies.map(({ entity, variant, revision, provenanceRevision }) => ({
|
|
376
|
+
entity,
|
|
377
|
+
variant,
|
|
378
|
+
revision,
|
|
379
|
+
...provenanceRevision && { provenanceRevision }
|
|
380
|
+
}));
|
|
381
|
+
return {
|
|
382
|
+
status: "ready",
|
|
383
|
+
receipt,
|
|
384
|
+
...composed
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
/** Compose only public exports the host opened. Retain the exact upstream and team releases in the overlay lock. */
|
|
388
|
+
function composePublishedOverlays(view, upstream, overlays, imports = [], extensions = {}) {
|
|
389
|
+
const entities = /* @__PURE__ */ new Map();
|
|
390
|
+
const owners = /* @__PURE__ */ new Map();
|
|
391
|
+
const publications = [];
|
|
392
|
+
const published = /* @__PURE__ */ new Set();
|
|
393
|
+
for (const content of [
|
|
394
|
+
upstream,
|
|
395
|
+
...overlays.map((overlay) => overlay.content),
|
|
396
|
+
...imports
|
|
397
|
+
]) {
|
|
398
|
+
const { entity, software, inventoryRevision } = content;
|
|
399
|
+
const owner = JSON.stringify([software.name, inventoryRevision]);
|
|
400
|
+
if (owners.has(entity) && owners.get(entity) !== owner) return {
|
|
401
|
+
status: "blocked",
|
|
402
|
+
diagnostics: [{
|
|
403
|
+
entity,
|
|
404
|
+
reason: "conflicting-publications"
|
|
405
|
+
}]
|
|
406
|
+
};
|
|
407
|
+
owners.set(entity, owner);
|
|
408
|
+
const source = JSON.stringify([owner, content.export]);
|
|
409
|
+
if (!published.has(source)) {
|
|
410
|
+
publications.push({
|
|
411
|
+
package: software.name,
|
|
412
|
+
version: software.version,
|
|
413
|
+
inventoryRevision,
|
|
414
|
+
export: content.export,
|
|
415
|
+
entity
|
|
416
|
+
});
|
|
417
|
+
published.add(source);
|
|
418
|
+
}
|
|
419
|
+
const variant = content.kind === "entity" ? content.value : {
|
|
420
|
+
context: content.identity.dimensions,
|
|
421
|
+
variantId: variantId(entity, content.identity.dimensions),
|
|
422
|
+
revision: content.contentSha256,
|
|
423
|
+
factRevision: content.contentSha256,
|
|
424
|
+
provenance: content.value.provenance,
|
|
425
|
+
data: {
|
|
426
|
+
schemaVersion: 1,
|
|
427
|
+
blocks: [{
|
|
428
|
+
type: "markdown",
|
|
429
|
+
value: content.value.markdown
|
|
430
|
+
}]
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
const entry = entities.get(entity) ?? {
|
|
434
|
+
id: entity,
|
|
435
|
+
type: entity.split(":")[0],
|
|
436
|
+
variants: []
|
|
437
|
+
};
|
|
438
|
+
const prior = entry.variants.find((item) => item.variantId === variant.variantId);
|
|
439
|
+
if (prior && prior.revision !== variant.revision) return {
|
|
440
|
+
status: "blocked",
|
|
441
|
+
diagnostics: [{
|
|
442
|
+
entity,
|
|
443
|
+
reason: "conflicting-exports"
|
|
444
|
+
}]
|
|
445
|
+
};
|
|
446
|
+
if (!prior) entry.variants.push(variant);
|
|
447
|
+
entities.set(entity, entry);
|
|
448
|
+
}
|
|
449
|
+
const reader = createSemanticReader({
|
|
450
|
+
schemaVersion: 1,
|
|
451
|
+
entities: [...entities.values()],
|
|
452
|
+
relations: []
|
|
453
|
+
});
|
|
454
|
+
const result = composeOverlays({
|
|
455
|
+
...view,
|
|
456
|
+
document: upstream.entity
|
|
457
|
+
}, overlays.map(({ content, ...overlay }) => ({
|
|
458
|
+
...overlay,
|
|
459
|
+
entity: content.entity
|
|
460
|
+
})), reader, extensions);
|
|
461
|
+
if (result.status === "ready") {
|
|
462
|
+
const key = (p) => JSON.stringify([
|
|
463
|
+
p.package,
|
|
464
|
+
p.inventoryRevision,
|
|
465
|
+
p.export
|
|
466
|
+
]);
|
|
467
|
+
result.receipt.publications = publications.sort((a, b) => key(a) < key(b) ? -1 : key(a) > key(b) ? 1 : 0);
|
|
468
|
+
}
|
|
469
|
+
return result;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
export { affectedViews, blockLosses, composeContent, composeOverlays, composePublishedOverlays, composeView, detachFragment, readFactScalar, selectFactValue };
|
|
473
|
+
//# sourceMappingURL=composition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composition.js","names":[],"sources":["../src/composition.ts"],"sourcesContent":["import { isValueReference, type ValueReference } from \"./content-schema.js\"\nimport { materializeAnnotations } from \"./annotation-projection.js\"\nimport { DocsError, type Provenance, type ProjectionLoss } from \"./model.js\"\nimport { createSemanticReader } from \"./reader.js\"\nimport type { ReadDocumentExport } from \"./module.js\"\nimport {\n resolveContext,\n variantId,\n type Context,\n type SemanticEntity,\n type EntityVariant,\n} from \"./semantic.js\"\n\nimport {\n bindArguments,\n isContentTree,\n record,\n upgradeCustomBlock,\n type Arguments,\n type AttributeSchema,\n type FragmentInclude,\n type CustomBlockSchema,\n type JsonValue,\n type LiteralBlock,\n type ContentTree,\n type InstanceBlock,\n} from \"./content-schema.js\"\n\n/** A location chosen by a consuming application. Embedded placements can omit a route. */\nexport interface ViewPlacement {\n id: string\n route?: string\n}\n\nexport interface DocumentView extends ViewPlacement {\n document: string\n factRevision?: string\n context: Context\n arguments?: Arguments\n overrides?: FragmentInclude[\"overrides\"]\n links?: Readonly<Record<string, string>>\n}\ntype Reader = Pick<ReturnType<typeof createSemanticReader>, \"resolve\">\ntype ReadFact = (id: string) => EntityVariant\n/** Owner of content, including the caller that supplied a slot override. */\nexport type BlockOrigin =\n | { kind: \"placement\"; placement: string }\n | { kind: \"entity\"; entity: string; variant: string; provenance: readonly Provenance[] }\n\nexport interface ContentRenderGroup {\n type: string\n props: JsonValue\n start: number\n end: number\n}\nexport interface BlockProjection {\n /** Trusted content type dispatched by an optional renderer after semantic projection. */\n renderer?: string\n /** Host policy, checked before attribute validation, migration and projection. */\n allowsSource?(origin: BlockOrigin): boolean\n schema?: CustomBlockSchema\n /** Trusted host code validates attributes, then projects them to portable blocks. Reads are tracked. */\n project(\n attrs: JsonValue,\n read: ReadFact,\n parameters?: Arguments,\n children?: readonly LiteralBlock[],\n ): readonly LiteralBlock[]\n}\n\nexport interface ContentProjections {\n /** Resolve producer-owned or request-specific data. Untrusted published nodes carry descriptions only. */\n observeValue?(ref: ValueReference, value: JsonValue, variant?: string): void\n value?(ref: ValueReference, parameters: Arguments, origin: BlockOrigin): JsonValue\n blocks?: ReadonlyMap<string, BlockProjection>\n annotations?: ReadonlyMap<string, AnnotationProjection>\n}\ntype Projections = ReadonlyMap<string, BlockProjection> | ContentProjections\n\nexport interface ViewDependency {\n entity: string\n variant: string\n revision: string\n provenanceRevision?: string\n provenance: Provenance[]\n}\n\n/** Resolve the same scalar selector for JSON blocks and authored MDX. */\nexport function readFactScalar(data: unknown, target: string, selector: string, source: string) {\n let value = data\n for (const key of selector.split(\".\")) {\n if (!key || !record(value) || !Object.hasOwn(value, key))\n throw new DocsError(\n \"DOCS_CONTENT_SELECTOR\",\n `Missing ${selector} on ${target} in ${source}.`,\n { source },\n )\n value = value[key]\n }\n if (typeof value !== \"string\" && typeof value !== \"number\" && typeof value !== \"boolean\")\n throw new DocsError(\n \"DOCS_CONTENT_SELECTOR\",\n `Expected a scalar at ${target}.${selector} in ${source}.`,\n { source },\n )\n return value\n}\n\nexport function selectFactValue(data: unknown, target: string, selector: string, source: string) {\n return String(readFactScalar(data, target, selector, source))\n}\n\n/** Materialize an independently placed document. Includes and custom blocks read the same context-pinned index. */\nexport function composeView(view: DocumentView, reader: Reader, extensions: Projections = {}) {\n return {\n view,\n ...materialize(\n view,\n {\n type: \"include\",\n target: view.document,\n factRevision: view.factRevision,\n arguments: view.arguments,\n overrides: view.overrides,\n },\n reader,\n extensions,\n ),\n }\n}\n\n/** Copy the resolved instance into locally owned literal blocks, retaining a receipt for the original reads. */\nexport function detachFragment(\n instance: FragmentInclude,\n context: Context,\n reader: Reader,\n extensions: Projections = {},\n links?: DocumentView[\"links\"],\n) {\n const resolved = materialize(\n { id: instance.target, context, links },\n instance,\n reader,\n extensions,\n )\n return {\n content: structuredClone(resolved.content),\n sources: structuredClone(resolved.dependencies),\n }\n}\n\n/** Resolve a directly authored tree with the same reference and projection rules as an included fragment. */\nexport function composeContent(\n content: ContentTree,\n origin: BlockOrigin,\n context: Context,\n extensions: Projections = {},\n reader?: Reader,\n) {\n return materialize(\n { id: origin.kind === \"entity\" ? origin.entity : origin.placement, context },\n { content, origin },\n reader ?? { resolve: () => ({ status: \"not-found\" as const }) },\n extensions,\n )\n}\n\nfunction materialize(\n view: Pick<DocumentView, \"id\" | \"context\" | \"links\">,\n root: FragmentInclude | { content: ContentTree; origin: BlockOrigin },\n reader: Reader,\n extensions: Projections,\n) {\n const { blocks: blockProjections, annotations } =\n \"get\" in extensions ? { blocks: extensions } : extensions\n const valueProvider = \"get\" in extensions ? undefined : extensions.value\n function resolveValue(ref: ValueReference, args: Arguments, origin: BlockOrigin): JsonValue {\n function observed(value: JsonValue, variant?: string) {\n if (!(\"get\" in extensions)) extensions.observeValue?.(ref, value, variant)\n return value\n }\n if (ref.kind === \"entity\" && ref.select) {\n const fact = read(ref.key)\n return observed(readFactScalar(fact.data, ref.key, ref.select, view.id), fact.variantId)\n }\n if (ref.kind === \"param\" && Object.hasOwn(args, ref.key) && !ref.select)\n return observed(args[ref.key]!)\n if (\n ref.kind === \"context\" &&\n view.context &&\n Object.hasOwn(view.context, ref.key) &&\n !ref.select\n )\n return observed(view.context[ref.key]!)\n if (valueProvider) return valueProvider(ref, args, origin)\n throw new DocsError(\"DOCS_VALUE_MISSING\", \"No value provider for \" + ref.key, {\n source: view.id,\n })\n }\n function resolveAttrs(attrs: JsonValue, args: Arguments, origin: BlockOrigin): JsonValue {\n if (attrs === null || typeof attrs !== \"object\") return attrs\n if (Array.isArray(attrs)) return attrs.map((item) => resolveAttrs(item, args, origin))\n if (Object.keys(attrs).length === 1 && Object.hasOwn(attrs, \"$value\")) {\n if (!isValueReference(attrs.$value))\n throw new DocsError(\"DOCS_VALUE_REFERENCE\", \"Invalid native value reference.\", {\n source: view.id,\n })\n return resolveValue(attrs.$value, args, origin)\n }\n return Object.fromEntries(\n Object.entries(attrs).map(([key, value]) => [key, resolveAttrs(value, args, origin)]),\n )\n }\n const dependencies = new Map<string, ViewDependency>()\n const blocks: LiteralBlock[] = []\n type Group = Pick<ContentRenderGroup, \"type\" | \"props\">\n let owners: WeakMap<LiteralBlock, Group[]> | undefined\n const path = new Set<string>()\n function read(entity: string) {\n const result = reader.resolve(entity, view.context)\n if (result.status !== \"exact\")\n throw new DocsError(\"DOCS_CONTENT_REFERENCE\", `${view.id}: ${entity} (${result.status}).`)\n const fact = result.value\n dependencies.set(entity, {\n entity,\n variant: fact.variantId,\n revision: fact.revision,\n provenanceRevision: fact.provenanceRevision,\n provenance: fact.provenance,\n })\n return fact\n }\n function target(id: string, pin?: string) {\n const fact = read(id)\n if (pin !== undefined && fact.factRevision !== pin)\n throw new DocsError(\"DOCS_CONTENT_PIN\", `Stale fact pin for ${fact.variantId}.`)\n return fact\n }\n function include(\n { target: id, factRevision: pin, overrides, arguments: args }: FragmentInclude,\n overrideOrigin: BlockOrigin = { kind: \"placement\", placement: view.id },\n ) {\n const fact = target(id, pin)\n if (path.has(id)) throw new DocsError(\"DOCS_CONTENT_CYCLE\", [...path, id].join(\" -> \"))\n if (!isContentTree(fact.data))\n throw new DocsError(\"DOCS_CONTENT_INVALID\", `Invalid content tree in ${id}.`)\n const parameters = bindArguments(id, fact.data.parameters, args)\n const owner: BlockOrigin = {\n kind: \"entity\",\n entity: id,\n variant: fact.variantId,\n provenance: fact.provenance,\n }\n path.add(id)\n const declared = new Set<string>()\n for (const { blockId: _address, ...block } of fact.data.blocks) {\n if (block.type === \"slot\") {\n if (declared.has(block.name))\n throw new DocsError(\"DOCS_CONTENT_SLOT\", `Duplicate slot ${block.name} in ${id}.`)\n declared.add(block.name)\n const local = overrides && Object.hasOwn(overrides, block.name)\n for (const child of local ? overrides[block.name]! : block.fallback)\n emit(child, parameters, local ? overrideOrigin : owner)\n } else emit(block, parameters, owner)\n }\n for (const name of Object.keys(overrides ?? {})) {\n if (!declared.has(name))\n throw new DocsError(\"DOCS_CONTENT_SLOT\", `Unknown slot ${name} in ${id}.`)\n }\n path.delete(id)\n }\n function emit(block: InstanceBlock, parameters: Arguments, origin: BlockOrigin) {\n if (block.type === \"include\") include(block, origin)\n else if (block.type === \"value\") {\n const value = resolveValue(block.ref, parameters, origin)\n if (typeof value === \"object\" && value !== null)\n throw new DocsError(\"DOCS_VALUE_TYPE\", \"Native text needs a scalar value.\", {\n source: view.id,\n })\n blocks.push({ type: \"paragraph\", children: [{ type: \"text\", value: String(value) }] })\n } else if (block.type === \"reference\") {\n const fact = target(block.target, block.factRevision)\n if (block.select !== undefined) {\n const value = selectFactValue(fact.data, block.target, block.select, view.id)\n blocks.push({ type: \"paragraph\", children: [{ type: \"text\", value }] })\n return\n }\n const url =\n view.links && Object.hasOwn(view.links, block.target)\n ? view.links[block.target]\n : block.target.startsWith(\"document:\") && record(fact.data)\n ? fact.data.route\n : undefined\n if (typeof url !== \"string\" || !url.trim())\n throw new DocsError(\n \"DOCS_CONTENT_PLACEMENT\",\n `Missing link for ${block.target} in ${view.id}.`,\n )\n blocks.push({\n type: \"paragraph\",\n children: [{ type: \"link\", url, children: [{ type: \"text\", value: block.label }] }],\n })\n } else if (block.type === \"custom\") {\n const extension = blockProjections?.get(block.name)\n if (!extension || (extension.allowsSource && !extension.allowsSource(origin))) {\n const source =\n origin.kind === \"entity\"\n ? (origin.provenance[0]?.source ?? origin.entity)\n : origin.placement\n if (extension && !block.fallbackText)\n throw new DocsError(\n \"DOCS_CONTENT_BLOCK_SOURCE\",\n `Projection for ${block.name} does not allow this source in ${view.id}.`,\n { source },\n )\n if (!block.fallbackText)\n throw new DocsError(\n \"DOCS_CONTENT_BLOCK\",\n `Missing projection for ${block.name} in ${view.id}.`,\n )\n const losses = ([\"web\", \"markdown\"] as const).map((target): ProjectionLoss => ({\n target,\n kind: \"custom-block\",\n severity: \"warning\",\n source,\n message: `Used the author's text alternative for ${block.name} in ${view.id}.`,\n }))\n blocks.push({\n type: \"paragraph\",\n children: [{ type: \"text\", value: block.fallbackText }],\n losses,\n })\n for (const child of block.children ?? []) emit(child, parameters, origin)\n return\n }\n if (!extension.schema && (block.version ?? 1) !== 1)\n throw new DocsError(\n \"DOCS_BLOCK_SCHEMA\",\n `No versioned schema registered for ${block.name}.`,\n )\n const input = resolveAttrs(block.attrs, parameters, origin)\n const attrs = extension.schema\n ? upgradeCustomBlock({ ...block, attrs: input }, extension.schema).attrs\n : input\n const start = blocks.length\n for (const child of block.children ?? []) emit(child, parameters, origin)\n const children = block.children?.length ? blocks.splice(start) : undefined\n const group = extension.renderer && { type: extension.renderer, props: attrs }\n for (const projected of extension.project(attrs, read, parameters, children)) {\n const output = append(projected, origin)\n if (group) (owners ??= new WeakMap()).set(output, [group, ...(owners.get(projected) ?? [])])\n }\n } else append(block, origin)\n }\n function append(block: LiteralBlock, origin: BlockOrigin) {\n const output = annotations ? materializeAnnotations(block, annotations, origin) : block\n blocks.push(output)\n return output\n }\n if (\"content\" in root) {\n if (!isContentTree(root.content))\n throw new DocsError(\"DOCS_CONTENT_INVALID\", \"Invalid structured content.\", {\n source: view.id,\n })\n const parameters = bindArguments(view.id, root.content.parameters)\n for (const block of root.content.blocks) {\n if (block.type === \"slot\")\n for (const child of block.fallback) emit(child, parameters, root.origin)\n else emit(block, parameters, root.origin)\n }\n } else include(root)\n const renderGroups: ContentRenderGroup[] = []\n let active: { owner: Group; span: ContentRenderGroup }[] = []\n if (owners)\n for (const [index, block] of blocks.entries()) {\n const path = owners.get(block) ?? []\n active = path.map((owner, depth) => {\n const existing = active[depth]\n if (existing?.owner === owner) {\n existing.span.end = index + 1\n return existing\n }\n const span = { ...owner, start: index, end: index + 1 }\n renderGroups.push(span)\n return { owner, span }\n })\n }\n const losses = blocks.flatMap(blockLosses)\n return {\n content: {\n schemaVersion: 1 as const,\n blocks,\n ...(renderGroups.length && { renderGroups }),\n ...(losses.length && { losses }),\n },\n dependencies: [...dependencies.values()],\n }\n}\n\n/** Re-resolve recorded reads to catch removed, changed, ambiguous and newly more-specific variants. */\nexport function affectedViews(previous: readonly ReturnType<typeof composeView>[], next: Reader) {\n return previous\n .filter(({ view, dependencies }) =>\n dependencies.some((dep) => {\n const result = next.resolve(dep.entity, view.context)\n return (\n result.status !== \"exact\" ||\n result.value.variantId !== dep.variant ||\n result.value.revision !== dep.revision ||\n result.value.provenanceRevision !== dep.provenanceRevision\n )\n }),\n )\n .map((result) => result.view.id)\n}\n\nexport function blockLosses(block: LiteralBlock): ProjectionLoss[] {\n const own = block.losses ?? []\n if (block.type === \"blockquote\") return [...own, ...block.blocks.flatMap(blockLosses)]\n if (block.type === \"list\")\n return [...own, ...block.items.flatMap((item) => item.blocks.flatMap(blockLosses))]\n return own\n}\n\nexport interface AnnotationProjection {\n renderer?: string\n schema: AttributeSchema\n /** Host policy. A restricted projection requires an origin and is checked before running the schema. */\n allowsSource?(origin: BlockOrigin): boolean\n /** Wrap the annotated children in a portable format. Core retains their text and nested formatting. */\n project(\n attrs: JsonValue,\n ):\n | { type: \"link\"; url: string; title?: string }\n | { type: \"strong\" | \"emphasis\" | \"strikethrough\" }\n}\n\nexport type { ContentTree, ContentBlock, LiteralBlock, FragmentInclude } from \"./content-schema.js\"\n\n/** A host-selected overlay supplies a semantic content entity for a named slot of a pinned upstream view. */\nexport interface SlotOverlay {\n owner: string\n entity: string\n slot: string\n priority: number\n upstreamFactRevision: string\n /** Exact applicability dimensions, such as the installed software version. */\n context?: Context\n /** Optional content pin for reproducible consumption. */\n factRevision?: string\n}\n\nexport interface OverlayReceipt {\n /** Resolved includes and facts read by projections, including their provenance revision. */\n dependencies: Omit<ViewDependency, \"provenance\">[]\n publications?: {\n package: string\n version: string\n inventoryRevision: string\n export: string\n entity: string\n }[]\n upstream: { entity: string; variant: string; revision: string; factRevision: string }\n slots: {\n slot: string\n owner: string\n entity: string\n variant: string\n revision: string\n priority: number\n selected: boolean\n }[]\n}\n\ntype OverlayDiagnostic = {\n slot?: string\n owner?: string\n entity: string\n reason: string\n expected?: string\n actual?: string\n}\n\n/** Resolve team overlays first, then feed the resulting includes to the ordinary view materializer. */\nexport function composeOverlays(\n view: DocumentView,\n overlays: readonly SlotOverlay[],\n reader: Reader,\n extensions: Projections = {},\n) {\n const upstream = reader.resolve(view.document, view.context)\n const diagnostics: OverlayDiagnostic[] = []\n if (\n upstream.status !== \"exact\" ||\n !upstream.value.factRevision ||\n !isContentTree(upstream.value.data)\n )\n return {\n status: \"blocked\" as const,\n diagnostics: [\n {\n entity: view.document,\n reason: upstream.status === \"exact\" ? \"unversioned-or-invalid-content\" : upstream.status,\n },\n ] as OverlayDiagnostic[],\n }\n const fact = upstream.value\n const slots = new Set(\n upstream.value.data.blocks.flatMap((block) => (block.type === \"slot\" ? [block.name] : [])),\n )\n const receipt: OverlayReceipt = {\n dependencies: [],\n upstream: {\n entity: view.document,\n variant: fact.variantId,\n revision: fact.revision,\n factRevision: upstream.value.factRevision,\n },\n slots: [],\n }\n const groups = new Map<string, OverlayReceipt[\"slots\"]>()\n // A copied declaration order must not choose a winner or perturb a lock.\n const compare = (a: string, b: string) => (a < b ? -1 : a > b ? 1 : 0)\n const ordered = [...overlays].sort(\n (a, b) =>\n compare(a.slot, b.slot) ||\n b.priority - a.priority ||\n compare(a.owner, b.owner) ||\n compare(a.entity, b.entity),\n )\n for (const overlay of ordered) {\n const { entity, owner, slot, priority } = overlay\n const report = (reason: string, expected?: string, actual?: string) =>\n diagnostics.push({\n entity,\n slot,\n owner,\n reason,\n ...(expected !== undefined && { expected }),\n ...(actual !== undefined && { actual }),\n })\n if (!owner.trim() || !Number.isSafeInteger(priority)) {\n report(\"invalid-declaration\")\n continue\n }\n if (overlay.upstreamFactRevision !== fact.factRevision) {\n report(\"stale-upstream\", overlay.upstreamFactRevision, fact.factRevision)\n continue\n }\n if (!slots.has(slot)) {\n report(\"missing-slot\")\n continue\n }\n if (Object.hasOwn(view.overrides ?? {}, slot)) {\n report(\"placement-conflict\")\n continue\n }\n const applicability = resolveContext([{ context: overlay.context ?? {} }], view.context)\n if (applicability.status !== \"exact\") {\n report(applicability.status)\n continue\n }\n const content = reader.resolve(entity, view.context)\n if (content.status !== \"exact\") {\n report(content.status)\n continue\n }\n if (!isContentTree(content.value.data)) {\n report(\"invalid-content\")\n continue\n }\n if (overlay.factRevision !== undefined && overlay.factRevision !== content.value.factRevision) {\n report(\"stale-overlay\", overlay.factRevision, content.value.factRevision)\n continue\n }\n const record = {\n slot,\n owner,\n entity,\n variant: content.value.variantId,\n revision: content.value.revision,\n priority,\n selected: false,\n }\n receipt.slots.push(record)\n const existing = groups.get(slot)\n if (existing) existing.push(record)\n else groups.set(slot, [record])\n }\n const overrides = Object.assign(Object.create(null), view.overrides) as NonNullable<\n DocumentView[\"overrides\"]\n >\n for (const [slot, group] of groups) {\n const winner = group[0]!\n const tied = group.filter((item) => item.priority === winner.priority)\n if (tied.length > 1) {\n for (const item of tied)\n diagnostics.push({ slot, owner: item.owner, entity: item.entity, reason: \"equal-priority\" })\n continue\n }\n winner.selected = true\n overrides[slot] = [{ type: \"include\", target: winner.entity }]\n }\n if (diagnostics.length) return { status: \"blocked\" as const, diagnostics }\n const composed = composeView({ ...view, overrides }, reader, extensions)\n receipt.dependencies = composed.dependencies.map(\n ({ entity, variant, revision, provenanceRevision }) => ({\n entity,\n variant,\n revision,\n ...(provenanceRevision && { provenanceRevision }),\n }),\n )\n return { status: \"ready\" as const, receipt, ...composed }\n}\n\ntype PublishedContent = Extract<ReadDocumentExport, { status: \"exact\" }>\ntype PublishedOverlay = Omit<SlotOverlay, \"entity\"> & { content: PublishedContent }\n\n/** Compose only public exports the host opened. Retain the exact upstream and team releases in the overlay lock. */\nexport function composePublishedOverlays(\n view: Omit<DocumentView, \"document\">,\n upstream: PublishedContent,\n overlays: readonly PublishedOverlay[],\n imports: readonly PublishedContent[] = [],\n extensions: Projections = {},\n) {\n const entities = new Map<string, SemanticEntity>()\n const owners = new Map<string, string>()\n const publications: NonNullable<OverlayReceipt[\"publications\"]> = []\n const published = new Set<string>()\n for (const content of [upstream, ...overlays.map((overlay) => overlay.content), ...imports]) {\n const { entity, software, inventoryRevision } = content\n const owner = JSON.stringify([software.name, inventoryRevision])\n if (owners.has(entity) && owners.get(entity) !== owner)\n return {\n status: \"blocked\" as const,\n diagnostics: [{ entity, reason: \"conflicting-publications\" }],\n }\n owners.set(entity, owner)\n const source = JSON.stringify([owner, content.export])\n if (!published.has(source)) {\n publications.push({\n package: software.name,\n version: software.version,\n inventoryRevision,\n export: content.export,\n entity,\n })\n published.add(source)\n }\n const variant: EntityVariant =\n content.kind === \"entity\"\n ? content.value\n : {\n context: content.identity.dimensions,\n variantId: variantId(entity, content.identity.dimensions),\n revision: content.contentSha256,\n factRevision: content.contentSha256,\n provenance: content.value.provenance,\n data: {\n schemaVersion: 1,\n blocks: [{ type: \"markdown\", value: content.value.markdown }],\n },\n }\n const entry = entities.get(entity) ?? { id: entity, type: entity.split(\":\")[0]!, variants: [] }\n const prior = entry.variants.find((item) => item.variantId === variant.variantId)\n if (prior && prior.revision !== variant.revision)\n return {\n status: \"blocked\" as const,\n diagnostics: [{ entity, reason: \"conflicting-exports\" }],\n }\n if (!prior) entry.variants.push(variant)\n entities.set(entity, entry)\n }\n const reader = createSemanticReader({\n schemaVersion: 1,\n entities: [...entities.values()],\n relations: [],\n })\n const result = composeOverlays(\n { ...view, document: upstream.entity },\n overlays.map(({ content, ...overlay }) => ({ ...overlay, entity: content.entity })),\n reader,\n extensions,\n )\n if (result.status === \"ready\") {\n const key = (p: (typeof publications)[number]) =>\n JSON.stringify([p.package, p.inventoryRevision, p.export])\n result.receipt.publications = publications.sort((a, b) =>\n key(a) < key(b) ? -1 : key(a) > key(b) ? 1 : 0,\n )\n }\n return result\n}\n"],"mappings":";;;;;;;;AAwFA,SAAgB,eAAe,MAAe,QAAgB,UAAkB,QAAgB;CAC9F,IAAI,QAAQ;CACZ,KAAK,MAAM,OAAO,SAAS,MAAM,GAAG,GAAG;EACrC,IAAI,CAAC,OAAO,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,OAAO,OAAO,GAAG,GACrD,MAAM,IAAI,UACR,yBACA,WAAW,SAAS,MAAM,OAAO,MAAM,OAAO,IAC9C,EAAE,OAAO,CACX;EACF,QAAQ,MAAM;CAChB;CACA,IAAI,OAAO,UAAU,YAAY,OAAO,UAAU,YAAY,OAAO,UAAU,WAC7E,MAAM,IAAI,UACR,yBACA,wBAAwB,OAAO,GAAG,SAAS,MAAM,OAAO,IACxD,EAAE,OAAO,CACX;CACF,OAAO;AACT;AAEA,SAAgB,gBAAgB,MAAe,QAAgB,UAAkB,QAAgB;CAC/F,OAAO,OAAO,eAAe,MAAM,QAAQ,UAAU,MAAM,CAAC;AAC9D;;AAGA,SAAgB,YAAY,MAAoB,QAAgB,aAA0B,CAAC,GAAG;CAC5F,OAAO;EACL;EACA,GAAG,YACD,MACA;GACE,MAAM;GACN,QAAQ,KAAK;GACb,cAAc,KAAK;GACnB,WAAW,KAAK;GAChB,WAAW,KAAK;EAClB,GACA,QACA,UACF;CACF;AACF;;AAGA,SAAgB,eACd,UACA,SACA,QACA,aAA0B,CAAC,GAC3B,OACA;CACA,MAAM,WAAW,YACf;EAAE,IAAI,SAAS;EAAQ;EAAS;CAAM,GACtC,UACA,QACA,UACF;CACA,OAAO;EACL,SAAS,gBAAgB,SAAS,OAAO;EACzC,SAAS,gBAAgB,SAAS,YAAY;CAChD;AACF;;AAGA,SAAgB,eACd,SACA,QACA,SACA,aAA0B,CA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;EACvC,SAAS,IAAI,QAAQ,KAAK;CAC5B;CACA,MAAM,SAAS,qBAAqB;EAClC,eAAe;EACf,UAAU,CAAC,GAAG,SAAS,OAAO,CAAC;EAC/B,WAAW,CAAC;CACd,CAAC;CACD,MAAM,SAAS,gBACb;EAAE,GAAG;EAAM,UAAU,SAAS;CAAO,GACrC,SAAS,KAAK,EAAE,SAAS,GAAG,eAAe;EAAE,GAAG;EAAS,QAAQ,QAAQ;CAAO,EAAE,GAClF,QACA,UACF;CACA,IAAI,OAAO,WAAW,SAAS;EAC7B,MAAM,OAAO,MACX,KAAK,UAAU;GAAC,EAAE;GAAS,EAAE;GAAmB,EAAE;EAAM,CAAC;EAC3D,OAAO,QAAQ,eAAe,aAAa,MAAM,GAAG,MAClD,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,CAC/C;CACF;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Context } from "./semantic.js";
|
|
2
|
+
type MatchValue<Value extends string = string> = Value | readonly Value[] | null;
|
|
3
|
+
export type ConditionMatch<Selection = Context> = {
|
|
4
|
+
readonly [Name in keyof Selection]?: MatchValue<Extract<Selection[Name], string>>;
|
|
5
|
+
};
|
|
6
|
+
export type Condition<Selection = Context> = ConditionMatch<Selection> | readonly ["all" | "any", ...Condition<Selection>[]] | readonly ["not", Condition<Selection>];
|
|
7
|
+
export declare function match<const Rules extends ConditionMatch>(rules: Rules): Rules;
|
|
8
|
+
export declare function all<const Rules extends readonly Condition[]>(...rules: Rules): readonly ["all", ...Rules];
|
|
9
|
+
export declare function any<const Rules extends readonly Condition[]>(...rules: Rules): readonly ["any", ...Rules];
|
|
10
|
+
export declare function not<const Rule extends Condition>(rule: Rule): readonly ["not", Rule];
|
|
11
|
+
export declare function matchesCondition(rule: Condition | undefined, context: Context): boolean;
|
|
12
|
+
export declare function conditionReferences(rule: Condition | undefined, fail: (message: string) => never, visit: (name: string, values: readonly string[]) => void): void;
|
|
13
|
+
/** A materialized projection records absent keys by omission across the candidate family. */
|
|
14
|
+
export declare function selectContextProjection<T extends {
|
|
15
|
+
context: Context;
|
|
16
|
+
}>(candidates: readonly T[], context: Context, baseline?: Context): T | undefined;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/condition.ts
|
|
2
|
+
function match(rules) {
|
|
3
|
+
return rules;
|
|
4
|
+
}
|
|
5
|
+
function all(...rules) {
|
|
6
|
+
return ["all", ...rules];
|
|
7
|
+
}
|
|
8
|
+
function any(...rules) {
|
|
9
|
+
return ["any", ...rules];
|
|
10
|
+
}
|
|
11
|
+
function not(rule) {
|
|
12
|
+
return ["not", rule];
|
|
13
|
+
}
|
|
14
|
+
function isConditionExpression(rule) {
|
|
15
|
+
return Array.isArray(rule);
|
|
16
|
+
}
|
|
17
|
+
function matchesCondition(rule, context) {
|
|
18
|
+
if (rule === void 0) return true;
|
|
19
|
+
if (isConditionExpression(rule)) {
|
|
20
|
+
const [operator, ...items] = rule;
|
|
21
|
+
switch (operator) {
|
|
22
|
+
case "all": return items.every((item) => matchesCondition(item, context));
|
|
23
|
+
case "any": return items.some((item) => matchesCondition(item, context));
|
|
24
|
+
case "not": return !matchesCondition(rule[1], context);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return Object.entries(rule).every(([name, expected]) => {
|
|
28
|
+
const value = Object.hasOwn(context, name) ? context[name] : void 0;
|
|
29
|
+
if (expected === null) return value === void 0;
|
|
30
|
+
if (typeof expected === "string") return expected === value;
|
|
31
|
+
return value !== void 0 && expected?.includes(value) === true;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function conditionReferences(rule, fail, visit) {
|
|
35
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
36
|
+
function walk(node) {
|
|
37
|
+
if (!node || typeof node !== "object" || visiting.has(node)) return fail("Expected an acyclic condition expression.");
|
|
38
|
+
visiting.add(node);
|
|
39
|
+
if (Array.isArray(node)) {
|
|
40
|
+
const [operator, ...items] = node;
|
|
41
|
+
if (operator === "not" && items.length !== 1 || operator !== "not" && operator !== "all" && operator !== "any") return fail("Expected all, any, or not with one operand.");
|
|
42
|
+
items.forEach(walk);
|
|
43
|
+
} else {
|
|
44
|
+
if (Object.getPrototypeOf(node) !== Object.prototype && Object.getPrototypeOf(node) !== null) return fail("Expected a condition object.");
|
|
45
|
+
for (const [name, value] of Object.entries(node)) if (value === null) visit(name, []);
|
|
46
|
+
else if (typeof value === "string") visit(name, [value]);
|
|
47
|
+
else if (Array.isArray(value) && value.length && Array.from(value).every((item) => typeof item === "string")) visit(name, value);
|
|
48
|
+
else return fail("Expected a value, a non-empty list of values, or null for " + name + ".");
|
|
49
|
+
}
|
|
50
|
+
visiting.delete(node);
|
|
51
|
+
}
|
|
52
|
+
if (rule !== void 0) walk(rule);
|
|
53
|
+
}
|
|
54
|
+
/** A materialized projection records absent keys by omission across the candidate family. */
|
|
55
|
+
function selectContextProjection(candidates, context, baseline) {
|
|
56
|
+
const keys = /* @__PURE__ */ new Set([...Object.keys(baseline ?? {}), ...candidates.flatMap((candidate) => Object.keys(candidate.context))]);
|
|
57
|
+
return candidates.find((candidate) => [...keys].every((name) => (Object.hasOwn(candidate.context, name) ? candidate.context[name] : void 0) === (Object.hasOwn(context, name) ? context[name] : void 0)));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { all, any, conditionReferences, match, matchesCondition, not, selectContextProjection };
|
|
61
|
+
//# sourceMappingURL=condition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition.js","names":["elements"],"sources":["../src/condition.ts"],"sourcesContent":["import type { Context } from \"./semantic.js\"\n\ntype MatchValue<Value extends string = string> = Value | readonly Value[] | null\n\nexport type ConditionMatch<Selection = Context> = {\n readonly [Name in keyof Selection]?: MatchValue<Extract<Selection[Name], string>>\n}\n\nexport type Condition<Selection = Context> =\n | ConditionMatch<Selection>\n | readonly [\"all\" | \"any\", ...Condition<Selection>[]]\n | readonly [\"not\", Condition<Selection>]\n\nexport function match<const Rules extends ConditionMatch>(rules: Rules): Rules {\n return rules\n}\n\nexport function all<const Rules extends readonly Condition[]>(...rules: Rules) {\n return [\"all\", ...rules] as const\n}\n\nexport function any<const Rules extends readonly Condition[]>(...rules: Rules) {\n return [\"any\", ...rules] as const\n}\n\nexport function not<const Rule extends Condition>(rule: Rule) {\n return [\"not\", rule] as const\n}\n\nfunction isConditionExpression(rule: Condition): rule is Exclude<Condition, ConditionMatch> {\n return Array.isArray(rule)\n}\n\nexport function matchesCondition(rule: Condition | undefined, context: Context): boolean {\n if (rule === undefined) return true\n if (isConditionExpression(rule)) {\n const [operator, ...items] = rule\n switch (operator) {\n case \"all\":\n return items.every((item) => matchesCondition(item, context))\n case \"any\":\n return items.some((item) => matchesCondition(item, context))\n case \"not\":\n return !matchesCondition(rule[1], context)\n }\n }\n return Object.entries(rule).every(([name, expected]) => {\n const value = Object.hasOwn(context, name) ? context[name] : undefined\n if (expected === null) return value === undefined\n if (typeof expected === \"string\") return expected === value\n return value !== undefined && expected?.includes(value) === true\n })\n}\n\nexport function conditionReferences(\n rule: Condition | undefined,\n fail: (message: string) => never,\n visit: (name: string, values: readonly string[]) => void,\n) {\n const visiting = new Set<object>()\n function walk(node: unknown) {\n if (!node || typeof node !== \"object\" || visiting.has(node))\n return fail(\"Expected an acyclic condition expression.\")\n visiting.add(node)\n if (Array.isArray(node)) {\n const elements: readonly unknown[] = node\n const [operator, ...items] = elements\n if (\n (operator === \"not\" && items.length !== 1) ||\n (operator !== \"not\" && operator !== \"all\" && operator !== \"any\")\n )\n return fail(\"Expected all, any, or not with one operand.\")\n items.forEach(walk)\n } else {\n if (Object.getPrototypeOf(node) !== Object.prototype && Object.getPrototypeOf(node) !== null)\n return fail(\"Expected a condition object.\")\n for (const [name, value] of Object.entries(node)) {\n if (value === null) visit(name, [])\n else if (typeof value === \"string\") visit(name, [value])\n else if (\n Array.isArray(value) &&\n value.length &&\n Array.from(value).every((item) => typeof item === \"string\")\n )\n visit(name, value)\n else return fail(\"Expected a value, a non-empty list of values, or null for \" + name + \".\")\n }\n }\n visiting.delete(node)\n }\n if (rule !== undefined) walk(rule)\n}\n\n/** A materialized projection records absent keys by omission across the candidate family. */\nexport function selectContextProjection<T extends { context: Context }>(\n candidates: readonly T[],\n context: Context,\n baseline?: Context,\n): T | undefined {\n const keys = new Set([\n ...Object.keys(baseline ?? {}),\n ...candidates.flatMap((candidate) => Object.keys(candidate.context)),\n ])\n return candidates.find((candidate) =>\n [...keys].every(\n (name) =>\n (Object.hasOwn(candidate.context, name) ? candidate.context[name] : undefined) ===\n (Object.hasOwn(context, name) ? context[name] : undefined),\n ),\n )\n}\n"],"mappings":";AAaA,SAAgB,MAA0C,OAAqB;CAC7E,OAAO;AACT;AAEA,SAAgB,IAA8C,GAAG,OAAc;CAC7E,OAAO,CAAC,OAAO,GAAG,KAAK;AACzB;AAEA,SAAgB,IAA8C,GAAG,OAAc;CAC7E,OAAO,CAAC,OAAO,GAAG,KAAK;AACzB;AAEA,SAAgB,IAAkC,MAAY;CAC5D,OAAO,CAAC,OAAO,IAAI;AACrB;AAEA,SAAS,sBAAsB,MAA6D;CAC1F,OAAO,MAAM,QAAQ,IAAI;AAC3B;AAEA,SAAgB,iBAAiB,MAA6B,SAA2B;CACvF,IAAI,SAAS,QAAW,OAAO;CAC/B,IAAI,sBAAsB,IAAI,GAAG;EAC/B,MAAM,CAAC,UAAU,GAAG,SAAS;EAC7B,QAAQ,UAAR;GACE,KAAK,OACH,OAAO,MAAM,OAAO,SAAS,iBAAiB,MAAM,OAAO,CAAC;GAC9D,KAAK,OACH,OAAO,MAAM,MAAM,SAAS,iBAAiB,MAAM,OAAO,CAAC;GAC7D,KAAK,OACH,OAAO,CAAC,iBAAiB,KAAK,IAAI,OAAO;EAC7C;CACF;CACA,OAAO,OAAO,QAAQ,IAAI,CAAC,CAAC,OAAO,CAAC,MAA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