@ai-matrx/alchemy 0.8.13 → 0.8.17
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/CHANGELOG.md +32 -1
- package/dist/actions.cjs +1 -373
- package/dist/actions.cjs.map +1 -1
- package/dist/actions.js +1 -350
- package/dist/actions.js.map +1 -1
- package/dist/checks.cjs +9 -314
- package/dist/checks.cjs.map +1 -1
- package/dist/checks.js +8 -290
- package/dist/checks.js.map +1 -1
- package/dist/core.cjs +9 -1728
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +2 -0
- package/dist/core.d.ts +2 -0
- package/dist/core.js +9 -1702
- package/dist/core.js.map +1 -1
- package/dist/declare-host.cjs +1 -18
- package/dist/declare-host.cjs.map +1 -1
- package/dist/declare.cjs +1 -638
- package/dist/declare.cjs.map +1 -1
- package/dist/declare.js +1 -615
- package/dist/declare.js.map +1 -1
- package/dist/index.cjs +9 -1728
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -1702
- package/dist/index.js.map +1 -1
- package/dist/menu.cjs +1 -529
- package/dist/menu.cjs.map +1 -1
- package/dist/menu.js +1 -506
- package/dist/menu.js.map +1 -1
- package/dist/operate-document.cjs +4 -162
- package/dist/operate-document.cjs.map +1 -1
- package/dist/operate-document.js +4 -129
- package/dist/operate-document.js.map +1 -1
- package/dist/operate-rich-html.cjs +1 -128
- package/dist/operate-rich-html.cjs.map +1 -1
- package/dist/operate-rich-html.js +1 -95
- package/dist/operate-rich-html.js.map +1 -1
- package/dist/operate-server.cjs +1 -156
- package/dist/operate-server.cjs.map +1 -1
- package/dist/operate-server.js +1 -133
- package/dist/operate-server.js.map +1 -1
- package/dist/operate-xlsx.cjs +143 -34230
- package/dist/operate-xlsx.cjs.map +1 -1
- package/dist/operate-xlsx.js +143 -34214
- package/dist/operate-xlsx.js.map +1 -1
- package/dist/operate.cjs +9 -1726
- package/dist/operate.cjs.map +1 -1
- package/dist/operate.d.cts +2 -0
- package/dist/operate.d.ts +2 -0
- package/dist/operate.js +9 -1702
- package/dist/operate.js.map +1 -1
- package/dist/ports.cjs +1 -18
- package/dist/ports.cjs.map +1 -1
- package/dist/react-bar.cjs +2 -795
- package/dist/react-bar.cjs.map +1 -1
- package/dist/react-bar.js +2 -774
- package/dist/react-bar.js.map +1 -1
- package/dist/react-host.cjs +1 -299
- package/dist/react-host.cjs.map +1 -1
- package/dist/react-host.js +1 -267
- package/dist/react-host.js.map +1 -1
- package/dist/react-menu.cjs +2 -848
- package/dist/react-menu.cjs.map +1 -1
- package/dist/react-menu.js +2 -835
- package/dist/react-menu.js.map +1 -1
- package/dist/react-overflow.cjs +2 -695
- package/dist/react-overflow.cjs.map +1 -1
- package/dist/react-overflow.js +2 -674
- package/dist/react-overflow.js.map +1 -1
- package/dist/react-palette.cjs +2 -586
- package/dist/react-palette.cjs.map +1 -1
- package/dist/react-palette.js +2 -554
- package/dist/react-palette.js.map +1 -1
- package/dist/react-selection.cjs +2 -726
- package/dist/react-selection.cjs.map +1 -1
- package/dist/react-selection.js +2 -705
- package/dist/react-selection.js.map +1 -1
- package/dist/react-sheet.cjs +2 -734
- package/dist/react-sheet.cjs.map +1 -1
- package/dist/react-sheet.js +2 -713
- package/dist/react-sheet.js.map +1 -1
- package/dist/react.cjs +1 -29
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +1 -8
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/declare.js
CHANGED
|
@@ -1,616 +1,2 @@
|
|
|
1
|
-
// src/declare/keys.ts
|
|
2
|
-
var DECLARATION_NAME_RE = /^[a-z][a-z0-9_]*$/;
|
|
3
|
-
var SURFACE_NAME_RE = /^[a-z][a-z0-9-]*\/[a-z0-9-/]+$/;
|
|
4
|
-
var QUALIFIED_VALUE_KEY_RE = /^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)?$/;
|
|
5
|
-
function parseQualifiedValueKey(key) {
|
|
6
|
-
if (!QUALIFIED_VALUE_KEY_RE.test(key)) return null;
|
|
7
|
-
const dot = key.indexOf(".");
|
|
8
|
-
if (dot === -1) return { itemType: "", name: key };
|
|
9
|
-
return { itemType: key.slice(0, dot), name: key.slice(dot + 1) };
|
|
10
|
-
}
|
|
11
|
-
function qualifyValueKey(itemType, name) {
|
|
12
|
-
return itemType ? `${itemType}.${name}` : name;
|
|
13
|
-
}
|
|
14
|
-
function surfaceClientOf(surfaceName) {
|
|
15
|
-
return surfaceName.split("/")[0] ?? "";
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// src/declare/hash.ts
|
|
19
|
-
function canonicalJson(value) {
|
|
20
|
-
if (value === void 0) return "null";
|
|
21
|
-
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
22
|
-
if (Array.isArray(value)) return `[${value.map((entry) => canonicalJson(entry)).join(",")}]`;
|
|
23
|
-
const record = value;
|
|
24
|
-
return `{${Object.keys(record).filter((key) => record[key] !== void 0).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(record[key])}`).join(",")}}`;
|
|
25
|
-
}
|
|
26
|
-
var K = new Uint32Array([
|
|
27
|
-
1116352408,
|
|
28
|
-
1899447441,
|
|
29
|
-
3049323471,
|
|
30
|
-
3921009573,
|
|
31
|
-
961987163,
|
|
32
|
-
1508970993,
|
|
33
|
-
2453635748,
|
|
34
|
-
2870763221,
|
|
35
|
-
3624381080,
|
|
36
|
-
310598401,
|
|
37
|
-
607225278,
|
|
38
|
-
1426881987,
|
|
39
|
-
1925078388,
|
|
40
|
-
2162078206,
|
|
41
|
-
2614888103,
|
|
42
|
-
3248222580,
|
|
43
|
-
3835390401,
|
|
44
|
-
4022224774,
|
|
45
|
-
264347078,
|
|
46
|
-
604807628,
|
|
47
|
-
770255983,
|
|
48
|
-
1249150122,
|
|
49
|
-
1555081692,
|
|
50
|
-
1996064986,
|
|
51
|
-
2554220882,
|
|
52
|
-
2821834349,
|
|
53
|
-
2952996808,
|
|
54
|
-
3210313671,
|
|
55
|
-
3336571891,
|
|
56
|
-
3584528711,
|
|
57
|
-
113926993,
|
|
58
|
-
338241895,
|
|
59
|
-
666307205,
|
|
60
|
-
773529912,
|
|
61
|
-
1294757372,
|
|
62
|
-
1396182291,
|
|
63
|
-
1695183700,
|
|
64
|
-
1986661051,
|
|
65
|
-
2177026350,
|
|
66
|
-
2456956037,
|
|
67
|
-
2730485921,
|
|
68
|
-
2820302411,
|
|
69
|
-
3259730800,
|
|
70
|
-
3345764771,
|
|
71
|
-
3516065817,
|
|
72
|
-
3600352804,
|
|
73
|
-
4094571909,
|
|
74
|
-
275423344,
|
|
75
|
-
430227734,
|
|
76
|
-
506948616,
|
|
77
|
-
659060556,
|
|
78
|
-
883997877,
|
|
79
|
-
958139571,
|
|
80
|
-
1322822218,
|
|
81
|
-
1537002063,
|
|
82
|
-
1747873779,
|
|
83
|
-
1955562222,
|
|
84
|
-
2024104815,
|
|
85
|
-
2227730452,
|
|
86
|
-
2361852424,
|
|
87
|
-
2428436474,
|
|
88
|
-
2756734187,
|
|
89
|
-
3204031479,
|
|
90
|
-
3329325298
|
|
91
|
-
]);
|
|
92
|
-
function sha256Hex(input) {
|
|
93
|
-
const bytes = new TextEncoder().encode(input);
|
|
94
|
-
const bitLength = bytes.length * 8;
|
|
95
|
-
const padded = new Uint8Array(bytes.length + 9 + 63 >> 6 << 6);
|
|
96
|
-
padded.set(bytes);
|
|
97
|
-
padded[bytes.length] = 128;
|
|
98
|
-
const view = new DataView(padded.buffer);
|
|
99
|
-
view.setUint32(padded.length - 8, Math.floor(bitLength / 4294967296));
|
|
100
|
-
view.setUint32(padded.length - 4, bitLength >>> 0);
|
|
101
|
-
const h = new Uint32Array([
|
|
102
|
-
1779033703,
|
|
103
|
-
3144134277,
|
|
104
|
-
1013904242,
|
|
105
|
-
2773480762,
|
|
106
|
-
1359893119,
|
|
107
|
-
2600822924,
|
|
108
|
-
528734635,
|
|
109
|
-
1541459225
|
|
110
|
-
]);
|
|
111
|
-
const w = new Uint32Array(64);
|
|
112
|
-
for (let offset = 0; offset < padded.length; offset += 64) {
|
|
113
|
-
for (let i = 0; i < 16; i += 1) w[i] = view.getUint32(offset + i * 4);
|
|
114
|
-
for (let i = 16; i < 64; i += 1) {
|
|
115
|
-
const a2 = w[i - 15];
|
|
116
|
-
const b2 = w[i - 2];
|
|
117
|
-
const s0 = (a2 >>> 7 | a2 << 25) ^ (a2 >>> 18 | a2 << 14) ^ a2 >>> 3;
|
|
118
|
-
const s1 = (b2 >>> 17 | b2 << 15) ^ (b2 >>> 19 | b2 << 13) ^ b2 >>> 10;
|
|
119
|
-
w[i] = w[i - 16] + s0 + w[i - 7] + s1 >>> 0;
|
|
120
|
-
}
|
|
121
|
-
let a = h[0], b = h[1], c = h[2], d = h[3], e = h[4], f = h[5], g = h[6], hh = h[7];
|
|
122
|
-
for (let i = 0; i < 64; i += 1) {
|
|
123
|
-
const S1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7);
|
|
124
|
-
const ch = e & f ^ ~e & g;
|
|
125
|
-
const t1 = hh + S1 + ch + K[i] + w[i] >>> 0;
|
|
126
|
-
const S0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10);
|
|
127
|
-
const maj = a & b ^ a & c ^ b & c;
|
|
128
|
-
const t2 = S0 + maj >>> 0;
|
|
129
|
-
hh = g;
|
|
130
|
-
g = f;
|
|
131
|
-
f = e;
|
|
132
|
-
e = d + t1 >>> 0;
|
|
133
|
-
d = c;
|
|
134
|
-
c = b;
|
|
135
|
-
b = a;
|
|
136
|
-
a = t1 + t2 >>> 0;
|
|
137
|
-
}
|
|
138
|
-
h[0] = h[0] + a >>> 0;
|
|
139
|
-
h[1] = h[1] + b >>> 0;
|
|
140
|
-
h[2] = h[2] + c >>> 0;
|
|
141
|
-
h[3] = h[3] + d >>> 0;
|
|
142
|
-
h[4] = h[4] + e >>> 0;
|
|
143
|
-
h[5] = h[5] + f >>> 0;
|
|
144
|
-
h[6] = h[6] + g >>> 0;
|
|
145
|
-
h[7] = h[7] + hh >>> 0;
|
|
146
|
-
}
|
|
147
|
-
return Array.from(h, (word) => word.toString(16).padStart(8, "0")).join("");
|
|
148
|
-
}
|
|
149
|
-
function declarationHash(declaration) {
|
|
150
|
-
return sha256Hex(canonicalJson(declaration));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// src/declare/validate.ts
|
|
154
|
-
var VALUE_TYPES = ["string", "number", "boolean", "object", "array", "document"];
|
|
155
|
-
var WRITE_MODES = ["draft", "entity", "ui", "stream"];
|
|
156
|
-
var APPLY_POLICIES = ["manual", "ask", "auto", "queued"];
|
|
157
|
-
var STREAM_OPS = ["replace", "insert_before", "insert_after", "prepend", "append", "patch"];
|
|
158
|
-
var EXECUTION_MODES = ["python-stream", "nextjs-stream", "browser-realtime", "local-runtime"];
|
|
159
|
-
var READINESS = ["verified", "partial", "stub"];
|
|
160
|
-
var LIVE_SLOTS = ["selection", "on-demand", "errors", "requests"];
|
|
161
|
-
var CLASSIFICATIONS = ["ordinary", "secret", "credential"];
|
|
162
|
-
var STRUCTURED = /* @__PURE__ */ new Set(["object", "array"]);
|
|
163
|
-
function has(list, value) {
|
|
164
|
-
return typeof value === "string" && list.includes(value);
|
|
165
|
-
}
|
|
166
|
-
function validateDeclarations(declarations, options = {}) {
|
|
167
|
-
const issues = [];
|
|
168
|
-
const seenSurfaces = /* @__PURE__ */ new Set();
|
|
169
|
-
const labelsByClient = /* @__PURE__ */ new Map();
|
|
170
|
-
for (const d of declarations) {
|
|
171
|
-
const s = d.surfaceName;
|
|
172
|
-
const push = (path, sentence, remedy, severity) => issues.push({ surfaceName: s, path, sentence, remedy, ...severity ? { severity } : {} });
|
|
173
|
-
if (seenSurfaces.has(s)) {
|
|
174
|
-
push("surfaceName", `Duplicate manifest surfaceName: "${s}" appears more than once.`, "Keep one declaration per surface.");
|
|
175
|
-
}
|
|
176
|
-
seenSurfaces.add(s);
|
|
177
|
-
if (!SURFACE_NAME_RE.test(s)) {
|
|
178
|
-
push("surfaceName", `Surface "${s}" doesn't match the "<client>/<local>" convention.`, "Rename it to <client>/<local>.");
|
|
179
|
-
}
|
|
180
|
-
const prefix = surfaceClientOf(s);
|
|
181
|
-
if (d.client !== prefix) {
|
|
182
|
-
push("client", `Surface "${s}" declares client "${String(d.client)}" but its name prefix is "${prefix}" \u2014 they must match.`, `Set client: "${prefix}".`);
|
|
183
|
-
}
|
|
184
|
-
if (!has(EXECUTION_MODES, d.executionMode)) {
|
|
185
|
-
push("executionMode", `Surface "${s}" has invalid executionMode "${String(d.executionMode)}".`, `Use one of ${EXECUTION_MODES.join(" | ")}.`);
|
|
186
|
-
}
|
|
187
|
-
if (typeof d.description !== "string") {
|
|
188
|
-
push("description", `Surface "${s}" has no description.`, 'Add one sentence on what the surface is ("" only where the live row is empty).');
|
|
189
|
-
}
|
|
190
|
-
const label = d.label?.trim();
|
|
191
|
-
if (!label) {
|
|
192
|
-
push("label", `Surface "${s}" has no canonical label \u2014 label is required.`, "Add the ONE canonical human display name.");
|
|
193
|
-
} else {
|
|
194
|
-
const clientLabels = labelsByClient.get(prefix) ?? /* @__PURE__ */ new Map();
|
|
195
|
-
const clash = clientLabels.get(label.toLowerCase());
|
|
196
|
-
if (clash && clash !== s) {
|
|
197
|
-
push("label", `Canonical label "${label}" is used by both "${clash}" and "${s}" \u2014 labels must be unique per client.`, "Give one of them a distinct label.");
|
|
198
|
-
}
|
|
199
|
-
clientLabels.set(label.toLowerCase(), s);
|
|
200
|
-
labelsByClient.set(prefix, clientLabels);
|
|
201
|
-
}
|
|
202
|
-
if (!has(READINESS, d.readiness)) {
|
|
203
|
-
push("readiness", `Surface "${s}" has invalid readiness "${String(d.readiness)}" (expected verified | partial | stub).`, "Set a valid readiness.");
|
|
204
|
-
} else if (d.readiness !== "verified" && !d.readinessNote?.trim()) {
|
|
205
|
-
push("readinessNote", `Surface "${s}" is readiness "${d.readiness}" but has no readinessNote \u2014 say what's missing.`, "Add a one-line readinessNote.");
|
|
206
|
-
}
|
|
207
|
-
const groupKeys = /* @__PURE__ */ new Set();
|
|
208
|
-
for (const g of d.groups ?? []) {
|
|
209
|
-
groupKeys.add(g.key);
|
|
210
|
-
const reserved = g.key === "general" || g.key === "baseline" || g.key.startsWith("inherited:");
|
|
211
|
-
if (reserved) continue;
|
|
212
|
-
if (!DECLARATION_NAME_RE.test(g.key)) push(`groups/${g.key}`, `Surface "${s}" group "${g.key}" doesn't match /^[a-z][a-z0-9_]*$/.`, "Rename the group key to lower_snake_case.");
|
|
213
|
-
if (g.sortOrder < 0 || g.sortOrder > 899) push(`groups/${g.key}/sortOrder`, `Surface "${s}" group "${g.key}" sortOrder ${g.sortOrder} is outside the curated band 0\u2013899.`, "Use a sortOrder between 0 and 899.");
|
|
214
|
-
if (!g.label?.trim()) push(`groups/${g.key}/label`, `Surface "${s}" group "${g.key}" has no canonical label.`, "Add a label.");
|
|
215
|
-
}
|
|
216
|
-
const seenNamespaces = /* @__PURE__ */ new Set();
|
|
217
|
-
for (const ns of d.configNamespaces ?? []) {
|
|
218
|
-
if (seenNamespaces.has(ns.namespace)) push(`configNamespaces/${ns.namespace}`, `Surface "${s}" declares duplicate config namespace "${ns.namespace}".`, "Remove the duplicate.");
|
|
219
|
-
seenNamespaces.add(ns.namespace);
|
|
220
|
-
if (options.knownNamespaces && !options.knownNamespaces.has(ns.namespace)) {
|
|
221
|
-
push(`configNamespaces/${ns.namespace}`, `Surface "${s}" references config namespace "${ns.namespace}" which is not registered.`, "Register the namespace first, or remove the reference.");
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
if (d.values.length === 0) {
|
|
225
|
-
push("values", `Surface "${s}" declares no values.`, "Declare at least one value.");
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
const seenValues = /* @__PURE__ */ new Set();
|
|
229
|
-
for (const v of d.values) {
|
|
230
|
-
const at = `values/${v.name}`;
|
|
231
|
-
if (seenValues.has(v.name)) push(at, `Surface "${s}" declares duplicate value "${v.name}".`, "Remove the duplicate.");
|
|
232
|
-
seenValues.add(v.name);
|
|
233
|
-
if (!DECLARATION_NAME_RE.test(v.name)) push(at, `Surface "${s}" value "${v.name}" doesn't match /^[a-z][a-z0-9_]*$/ \u2014 the DB CHECK constraint will reject this.`, "Rename it to lower_snake_case.");
|
|
234
|
-
if (!has(VALUE_TYPES, v.valueType)) push(`${at}/valueType`, `Surface "${s}" value "${v.name}" has invalid valueType "${String(v.valueType)}".`, `Use one of ${VALUE_TYPES.join(" | ")}.`);
|
|
235
|
-
if (typeof v.typicalCharCount !== "number" || v.typicalCharCount < 0) push(`${at}/typicalCharCount`, `Surface "${s}" value "${v.name}" has invalid typicalCharCount.`, "Use a non-negative number.");
|
|
236
|
-
if (v.sortOrder !== void 0 && (typeof v.sortOrder !== "number" || v.sortOrder < 0)) push(`${at}/sortOrder`, `Surface "${s}" value "${v.name}" has invalid sortOrder.`, "Use a non-negative number.");
|
|
237
|
-
if (v.groupKey && !groupKeys.has(v.groupKey)) push(`${at}/group`, `Surface "${s}" value "${v.name}" resolved to groupKey "${v.groupKey}" which is missing from the resolved groups list \u2014 registry group synthesis is broken.`, "Fix the registry resolution.");
|
|
238
|
-
if (v.liveSlot !== void 0 && !has(LIVE_SLOTS, v.liveSlot)) push(`${at}/liveSlot`, `Surface "${s}" value "${v.name}" has invalid liveSlot "${String(v.liveSlot)}".`, `Use one of ${LIVE_SLOTS.join(" | ")}.`);
|
|
239
|
-
if (v.role !== void 0 && v.role !== "data" && v.role !== "request") push(`${at}/role`, `Surface "${s}" value "${v.name}" has invalid role "${String(v.role)}".`, "Use data | request.");
|
|
240
|
-
if (v.sensitivity?.classification !== void 0 && !has(CLASSIFICATIONS, v.sensitivity.classification)) push(`${at}/sensitivity/classification`, `Surface "${s}" value "${v.name}" has invalid classification "${String(v.sensitivity.classification)}".`, `Use one of ${CLASSIFICATIONS.join(" | ")}.`);
|
|
241
|
-
}
|
|
242
|
-
for (const slot of d.liveSlots ?? []) {
|
|
243
|
-
if (!has(LIVE_SLOTS, slot)) push("liveSlots", `Surface "${s}" declares unknown live slot "${String(slot)}".`, `Use one of ${LIVE_SLOTS.join(" | ")}.`);
|
|
244
|
-
}
|
|
245
|
-
const itemTypeNames = /* @__PURE__ */ new Set();
|
|
246
|
-
for (const item of d.itemTypes ?? []) {
|
|
247
|
-
const at = `itemTypes/${item.name}`;
|
|
248
|
-
if (itemTypeNames.has(item.name)) push(at, `Surface "${s}" declares duplicate item type "${item.name}".`, "Remove the duplicate.");
|
|
249
|
-
itemTypeNames.add(item.name);
|
|
250
|
-
if (!DECLARATION_NAME_RE.test(item.name)) push(at, `Surface "${s}" item type "${item.name}" doesn't match /^[a-z][a-z0-9_]*$/.`, "Rename it to lower_snake_case.");
|
|
251
|
-
if (!item.label?.trim() || !item.description?.trim()) push(at, `Surface "${s}" item type "${item.name}" needs a label and a description.`, "Add both.");
|
|
252
|
-
const itemValues = new Set(item.values.map((v) => v.name));
|
|
253
|
-
if (item.identity.length === 0) push(`${at}/identity`, `Surface "${s}" item type "${item.name}" has an empty identity.`, "Name the value(s) that identify one item.");
|
|
254
|
-
for (const key of item.identity) {
|
|
255
|
-
if (!itemValues.has(key)) push(`${at}/identity`, `Surface "${s}" item type "${item.name}" identity names "${key}", which is not one of its values.`, "Declare it as an item value.");
|
|
256
|
-
}
|
|
257
|
-
for (const t of item.writeTargets ?? []) {
|
|
258
|
-
if (t.updatesValue && !itemValues.has(t.updatesValue)) push(`${at}/writeTargets/${t.name}`, `Surface "${s}" item type "${item.name}" write target "${t.name}" updatesValue "${t.updatesValue}" which is not an item value.`, "Point it at a declared item value.");
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
const seenTargets = /* @__PURE__ */ new Set();
|
|
262
|
-
const structuredWithoutKind = [];
|
|
263
|
-
for (const w of d.writeTargets ?? []) {
|
|
264
|
-
const at = `writeTargets/${w.name}`;
|
|
265
|
-
if (seenTargets.has(w.name)) push(at, `Surface "${s}" declares duplicate write target "${w.name}".`, "Remove the duplicate.");
|
|
266
|
-
seenTargets.add(w.name);
|
|
267
|
-
if (!DECLARATION_NAME_RE.test(w.name)) push(at, `Surface "${s}" write target "${w.name}" doesn't match /^[a-z][a-z0-9_]*$/.`, "Rename it to lower_snake_case.");
|
|
268
|
-
if (!w.label?.trim() || !w.description?.trim()) push(at, `Surface "${s}" write target "${w.name}" needs a label and a description.`, "Add both.");
|
|
269
|
-
if (!has(VALUE_TYPES, w.valueType)) push(`${at}/valueType`, `Surface "${s}" write target "${w.name}" has invalid valueType "${String(w.valueType)}".`, `Use one of ${VALUE_TYPES.join(" | ")}.`);
|
|
270
|
-
if (!has(WRITE_MODES, w.mode)) push(`${at}/mode`, `Surface "${s}" write target "${w.name}" has invalid mode "${String(w.mode)}".`, `Use one of ${WRITE_MODES.join(" | ")}.`);
|
|
271
|
-
if (w.applyPolicy !== void 0 && !has(APPLY_POLICIES, w.applyPolicy)) push(`${at}/applyPolicy`, `Surface "${s}" write target "${w.name}" has invalid applyPolicy "${String(w.applyPolicy)}".`, `Use one of ${APPLY_POLICIES.join(" | ")}.`);
|
|
272
|
-
if (w.itemType !== void 0 && !itemTypeNames.has(w.itemType)) push(`${at}/itemType`, `Surface "${s}" write target "${w.name}" names item type "${w.itemType}", which the surface does not declare.`, "Declare the item type or drop itemType.");
|
|
273
|
-
const readTwinDeclared = w.updatesValue ? seenValues.has(w.updatesValue) : false;
|
|
274
|
-
if (w.updatesValue && !w.itemType && !readTwinDeclared) push(`${at}/updatesValue`, `Surface "${s}" write target "${w.name}" updatesValue "${w.updatesValue}" which is not a declared value.`, "Point updatesValue at a declared value.");
|
|
275
|
-
if (w.patchable && !w.updatesValue) push(`${at}/patchable`, `Surface "${s}" write target "${w.name}" is patchable but declares no updatesValue \u2014 an anchored edit has nothing to read.`, "Declare the read twin in updatesValue.");
|
|
276
|
-
if (w.patchable && w.valueType !== "string" && w.valueType !== "document") push(`${at}/patchable`, `Surface "${s}" write target "${w.name}" is patchable but valueType is "${w.valueType}" (patching is for "string" | "document").`, "Drop patchable or change the value type.");
|
|
277
|
-
if (w.mode === "stream") {
|
|
278
|
-
if (!w.streamOps || w.streamOps.length === 0) push(`${at}/streamOps`, `Surface "${s}" write target "${w.name}" is a stream target with no streamOps.`, "List the ops it services.");
|
|
279
|
-
if (!w.updatesValue) push(`${at}/updatesValue`, `Surface "${s}" write target "${w.name}" is a stream target with no read twin.`, "Declare updatesValue.");
|
|
280
|
-
} else if (w.streamOps !== void 0) {
|
|
281
|
-
push(`${at}/streamOps`, `Surface "${s}" write target "${w.name}" lists streamOps but its mode is "${w.mode}".`, 'streamOps belong only to mode "stream".');
|
|
282
|
-
}
|
|
283
|
-
for (const op of w.streamOps ?? []) {
|
|
284
|
-
if (!has(STREAM_OPS, op)) push(`${at}/streamOps`, `Surface "${s}" write target "${w.name}" lists unknown stream op "${String(op)}".`, `Use ${STREAM_OPS.join(" | ")}.`);
|
|
285
|
-
}
|
|
286
|
-
if (w.group && !groupKeys.has(w.group)) push(`${at}/group`, `Surface "${s}" write target "${w.name}" references undeclared group "${w.group}".`, "Declare the group or drop it.");
|
|
287
|
-
if (w.valueKind !== void 0) {
|
|
288
|
-
if (typeof w.valueKind !== "string" || !w.valueKind.trim()) {
|
|
289
|
-
push(`${at}/valueKind`, `Surface "${s}" write target "${w.name}" has an empty valueKind.`, "Name a registered kind slug or omit the field.");
|
|
290
|
-
} else if (options.isKnownKind && !options.isKnownKind(w.valueKind)) {
|
|
291
|
-
push(`${at}/valueKind`, `Surface "${s}" write target "${w.name}" declares valueKind "${w.valueKind}", which is not a registered active kind.`, "Name a registered kind slug, or register the kind first; never inline a JSON schema.");
|
|
292
|
-
}
|
|
293
|
-
} else if (STRUCTURED.has(w.valueType)) {
|
|
294
|
-
structuredWithoutKind.push(w.name);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
for (const name of structuredWithoutKind) {
|
|
298
|
-
push(`writeTargets/${name}/valueKind`, `Surface "${s}" structured write target "${name}" declares no valueKind.`, "Name a registered kind slug (the value contract ratchet).", "advisory");
|
|
299
|
-
}
|
|
300
|
-
if (!d.skipBaselineValues && options.baselineNames) {
|
|
301
|
-
const missing = options.baselineNames.filter((name) => !seenValues.has(name));
|
|
302
|
-
if (missing.length > 0) {
|
|
303
|
-
push("values", `Surface "${s}" is missing baseline value(s): ${missing.join(", ")}.`, "The registry injects baselines automatically; opt out only with skipBaselineValues.");
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
for (const extension of options.extensions ?? []) {
|
|
308
|
-
if (!extension.validate) continue;
|
|
309
|
-
for (const d of declarations) issues.push(...extension.validate(d, { all: declarations }));
|
|
310
|
-
}
|
|
311
|
-
return issues;
|
|
312
|
-
}
|
|
313
|
-
function validateLoadedValues(declaration, loaded, options = {}) {
|
|
314
|
-
const declared = new Set(declaration.values.map((v) => v.name));
|
|
315
|
-
const ignore = new Set(options.ignore ?? []);
|
|
316
|
-
const issues = [];
|
|
317
|
-
for (const key of Object.keys(loaded)) {
|
|
318
|
-
if (key === "__item" || declared.has(key) || ignore.has(key)) continue;
|
|
319
|
-
issues.push({
|
|
320
|
-
surfaceName: declaration.surfaceName,
|
|
321
|
-
path: `values/${key}`,
|
|
322
|
-
sentence: `Surface "${declaration.surfaceName}" loaded a value "${key}" it never declared.`,
|
|
323
|
-
remedy: `Declare "${key}" in the surface's values, or stop emitting it.`
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
const item = loaded.__item;
|
|
327
|
-
if (item && typeof item === "object") {
|
|
328
|
-
const type = declaration.itemTypes?.find((t) => t.name === item.itemType);
|
|
329
|
-
if (!type) {
|
|
330
|
-
issues.push({
|
|
331
|
-
surfaceName: declaration.surfaceName,
|
|
332
|
-
path: "__item/itemType",
|
|
333
|
-
sentence: `Surface "${declaration.surfaceName}" loaded an item of type "${String(item.itemType)}" it never declared.`,
|
|
334
|
-
remedy: "Declare the item type, or stop emitting the item."
|
|
335
|
-
});
|
|
336
|
-
} else if (item.values && typeof item.values === "object") {
|
|
337
|
-
const itemDeclared = new Set(type.values.map((v) => v.name));
|
|
338
|
-
for (const key of Object.keys(item.values)) {
|
|
339
|
-
if (itemDeclared.has(key)) continue;
|
|
340
|
-
issues.push({
|
|
341
|
-
surfaceName: declaration.surfaceName,
|
|
342
|
-
path: `__item/${type.name}.${key}`,
|
|
343
|
-
sentence: `Surface "${declaration.surfaceName}" loaded item value "${type.name}.${key}" it never declared.`,
|
|
344
|
-
remedy: `Declare "${key}" on item type "${type.name}".`
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
return issues;
|
|
350
|
-
}
|
|
351
|
-
function findOrphanRows(rowNames, declaredNames, retired = []) {
|
|
352
|
-
const owned = new Set(declaredNames);
|
|
353
|
-
const archived = new Set(retired);
|
|
354
|
-
return rowNames.filter((name) => !owned.has(name) && !archived.has(name)).sort();
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// src/declare/sensitivity.ts
|
|
358
|
-
var DEFAULT_SENSITIVITY = Object.freeze({
|
|
359
|
-
exportable: true,
|
|
360
|
-
classification: "ordinary",
|
|
361
|
-
includedByDefault: true
|
|
362
|
-
});
|
|
363
|
-
function resolveSensitivity(value) {
|
|
364
|
-
return {
|
|
365
|
-
exportable: value.sensitivity?.exportable ?? DEFAULT_SENSITIVITY.exportable,
|
|
366
|
-
classification: value.sensitivity?.classification ?? DEFAULT_SENSITIVITY.classification,
|
|
367
|
-
includedByDefault: value.sensitivity?.includedByDefault ?? DEFAULT_SENSITIVITY.includedByDefault
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
// src/declare/registry.ts
|
|
372
|
-
var RESERVED_GROUP_KEYS = {
|
|
373
|
-
general: "general",
|
|
374
|
-
baseline: "baseline",
|
|
375
|
-
inheritedPrefix: "inherited:"
|
|
376
|
-
};
|
|
377
|
-
var GENERAL_GROUP_ORDER = 850;
|
|
378
|
-
var INHERITED_GROUP_ORDER_BASE = 9e3;
|
|
379
|
-
var BASELINE_GROUP_ORDER = 9900;
|
|
380
|
-
var DEFAULT_MAX_INHERITANCE_DEPTH = 3;
|
|
381
|
-
function createDeclarationRegistry(options = {}) {
|
|
382
|
-
const baselineValues = options.baselineValues ?? [];
|
|
383
|
-
const baselineNames = new Set(baselineValues.map((v) => v.name));
|
|
384
|
-
const reservedValues = new Set(options.reservedValueNames ?? []);
|
|
385
|
-
const reservedTargets = new Set(options.reservedWriteTargetNames ?? []);
|
|
386
|
-
const maxDepth = options.maxInheritanceDepth ?? DEFAULT_MAX_INHERITANCE_DEPTH;
|
|
387
|
-
const declarations = [];
|
|
388
|
-
const index = /* @__PURE__ */ new Map();
|
|
389
|
-
const extensionList = [];
|
|
390
|
-
let resolvedCache = null;
|
|
391
|
-
let resolvedIndex = /* @__PURE__ */ new Map();
|
|
392
|
-
function ancestry(surfaceName) {
|
|
393
|
-
const chain = [];
|
|
394
|
-
const seen = /* @__PURE__ */ new Set([surfaceName]);
|
|
395
|
-
let current = index.get(surfaceName)?.inheritsFrom;
|
|
396
|
-
while (current) {
|
|
397
|
-
if (seen.has(current)) {
|
|
398
|
-
throw new Error(
|
|
399
|
-
`[surfaces] inheritsFrom CYCLE detected at "${current}" (from "${surfaceName}"). Fix the manifest chain: ${[...seen].join(" \u2192 ")} \u2192 ${current}`
|
|
400
|
-
);
|
|
401
|
-
}
|
|
402
|
-
const parent = index.get(current);
|
|
403
|
-
if (!parent) {
|
|
404
|
-
throw new Error(
|
|
405
|
-
`[surfaces] "${surfaceName}" inheritsFrom unknown surface "${current}" \u2014 the parent must be a registered declaration`
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
seen.add(current);
|
|
409
|
-
chain.unshift(current);
|
|
410
|
-
if (chain.length > maxDepth) {
|
|
411
|
-
throw new Error(
|
|
412
|
-
`[surfaces] inheritance chain for "${surfaceName}" exceeds depth ${maxDepth}: ` + chain.join(" \u2192 ")
|
|
413
|
-
);
|
|
414
|
-
}
|
|
415
|
-
current = parent.inheritsFrom;
|
|
416
|
-
}
|
|
417
|
-
return chain;
|
|
418
|
-
}
|
|
419
|
-
function groupKeyFor(value, provenance) {
|
|
420
|
-
if (provenance.kind === "own" && value.group) return value.group;
|
|
421
|
-
if (baselineNames.has(value.name)) return RESERVED_GROUP_KEYS.baseline;
|
|
422
|
-
if (provenance.kind === "inherited") return `${RESERVED_GROUP_KEYS.inheritedPrefix}${provenance.from}`;
|
|
423
|
-
if (provenance.kind === "baseline") return RESERVED_GROUP_KEYS.baseline;
|
|
424
|
-
return RESERVED_GROUP_KEYS.general;
|
|
425
|
-
}
|
|
426
|
-
function resolve(declaration) {
|
|
427
|
-
const chain = ancestry(declaration.surfaceName);
|
|
428
|
-
const lineage = [
|
|
429
|
-
...chain.map((name) => {
|
|
430
|
-
const layer = index.get(name);
|
|
431
|
-
if (!layer) throw new Error(`[surfaces] missing inherited declaration "${name}"`);
|
|
432
|
-
return { layer, from: name };
|
|
433
|
-
}),
|
|
434
|
-
{ layer: declaration, from: null }
|
|
435
|
-
];
|
|
436
|
-
const curatedKeys = /* @__PURE__ */ new Set();
|
|
437
|
-
for (const group of declaration.groups ?? []) {
|
|
438
|
-
if (group.key === RESERVED_GROUP_KEYS.general || group.key === RESERVED_GROUP_KEYS.baseline || group.key.startsWith(RESERVED_GROUP_KEYS.inheritedPrefix)) {
|
|
439
|
-
throw new Error(
|
|
440
|
-
`[surfaces] "${declaration.surfaceName}" declares reserved group key "${group.key}" \u2014 general/baseline/inherited:* are synthesized by the registry`
|
|
441
|
-
);
|
|
442
|
-
}
|
|
443
|
-
if (curatedKeys.has(group.key)) {
|
|
444
|
-
throw new Error(`[surfaces] "${declaration.surfaceName}" declares duplicate group key "${group.key}"`);
|
|
445
|
-
}
|
|
446
|
-
curatedKeys.add(group.key);
|
|
447
|
-
}
|
|
448
|
-
for (const value of declaration.values) {
|
|
449
|
-
if (reservedValues.has(value.name)) {
|
|
450
|
-
throw new Error(
|
|
451
|
-
`[surfaces] "${declaration.surfaceName}" declares value "${value.name}" \u2014 that name is written by the platform; choose another name`
|
|
452
|
-
);
|
|
453
|
-
}
|
|
454
|
-
if (value.group && !curatedKeys.has(value.group)) {
|
|
455
|
-
throw new Error(
|
|
456
|
-
`[surfaces] "${declaration.surfaceName}" value "${value.name}" references undeclared group "${value.group}" \u2014 declare it in the manifest's \`groups\``
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
for (const target of declaration.writeTargets ?? []) {
|
|
461
|
-
if (reservedTargets.has(target.name)) {
|
|
462
|
-
throw new Error(
|
|
463
|
-
`[surfaces] "${declaration.surfaceName}" declares write target "${target.name}" \u2014 that name is written by the platform; choose another name`
|
|
464
|
-
);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
const valuesByName = /* @__PURE__ */ new Map();
|
|
468
|
-
const inheritedLists = /* @__PURE__ */ new Map();
|
|
469
|
-
const coreLists = [
|
|
470
|
-
{ field: "configNamespaces", identity: (entry) => entry.namespace },
|
|
471
|
-
{
|
|
472
|
-
field: "evidenceSources",
|
|
473
|
-
identity: (entry) => `${entry.kind}:${entry.idValue}`
|
|
474
|
-
}
|
|
475
|
-
];
|
|
476
|
-
const lists = [...coreLists, ...extensionList.flatMap((extension) => extension.inheritedLists ?? [])];
|
|
477
|
-
for (const { layer, from } of lineage) {
|
|
478
|
-
for (const value of layer.values) {
|
|
479
|
-
const provenance = from ? { kind: "inherited", from } : { kind: "own" };
|
|
480
|
-
valuesByName.set(value.name, {
|
|
481
|
-
...value,
|
|
482
|
-
provenance,
|
|
483
|
-
groupKey: groupKeyFor(value, provenance),
|
|
484
|
-
resolvedSensitivity: resolveSensitivity(value)
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
for (const list of lists) {
|
|
488
|
-
const entries = layer[list.field];
|
|
489
|
-
if (!Array.isArray(entries)) continue;
|
|
490
|
-
const byIdentity = inheritedLists.get(list.field) ?? /* @__PURE__ */ new Map();
|
|
491
|
-
for (const entry of entries) byIdentity.set(list.identity(entry), entry);
|
|
492
|
-
inheritedLists.set(list.field, byIdentity);
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
if (!declaration.skipBaselineValues) {
|
|
496
|
-
for (const baseline of baselineValues) {
|
|
497
|
-
if (valuesByName.has(baseline.name)) continue;
|
|
498
|
-
valuesByName.set(baseline.name, {
|
|
499
|
-
...baseline,
|
|
500
|
-
provenance: { kind: "baseline" },
|
|
501
|
-
groupKey: RESERVED_GROUP_KEYS.baseline,
|
|
502
|
-
resolvedSensitivity: resolveSensitivity(baseline)
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
const usedGroupKeys = new Set(Array.from(valuesByName.values(), (value) => value.groupKey));
|
|
507
|
-
const groups = [...declaration.groups ?? []];
|
|
508
|
-
if (usedGroupKeys.has(RESERVED_GROUP_KEYS.general)) {
|
|
509
|
-
groups.push({ key: RESERVED_GROUP_KEYS.general, label: "General", sortOrder: GENERAL_GROUP_ORDER });
|
|
510
|
-
}
|
|
511
|
-
for (let i = chain.length - 1, distance = 0; i >= 0; i -= 1, distance += 1) {
|
|
512
|
-
const parentName = chain[i];
|
|
513
|
-
const key = `${RESERVED_GROUP_KEYS.inheritedPrefix}${parentName}`;
|
|
514
|
-
if (!usedGroupKeys.has(key)) continue;
|
|
515
|
-
const parentLabel = index.get(parentName)?.label ?? parentName;
|
|
516
|
-
groups.push({
|
|
517
|
-
key,
|
|
518
|
-
label: `Inherited from ${parentLabel}`,
|
|
519
|
-
sortOrder: INHERITED_GROUP_ORDER_BASE + distance * 10
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
if (usedGroupKeys.has(RESERVED_GROUP_KEYS.baseline)) {
|
|
523
|
-
groups.push({ key: RESERVED_GROUP_KEYS.baseline, label: "Generic baselines", sortOrder: BASELINE_GROUP_ORDER });
|
|
524
|
-
}
|
|
525
|
-
groups.sort((a, b) => a.sortOrder - b.sortOrder);
|
|
526
|
-
const groupOrder = new Map(groups.map((group) => [group.key, group.sortOrder]));
|
|
527
|
-
const values = Array.from(valuesByName.values()).sort((a, b) => {
|
|
528
|
-
const ga = groupOrder.get(a.groupKey) ?? GENERAL_GROUP_ORDER;
|
|
529
|
-
const gb = groupOrder.get(b.groupKey) ?? GENERAL_GROUP_ORDER;
|
|
530
|
-
if (ga !== gb) return ga - gb;
|
|
531
|
-
return (a.sortOrder ?? 1e3) - (b.sortOrder ?? 1e3);
|
|
532
|
-
});
|
|
533
|
-
const merged = {};
|
|
534
|
-
for (const [field, byIdentity] of inheritedLists) {
|
|
535
|
-
if (byIdentity.size > 0) merged[field] = Array.from(byIdentity.values());
|
|
536
|
-
}
|
|
537
|
-
return {
|
|
538
|
-
...declaration,
|
|
539
|
-
values,
|
|
540
|
-
groups,
|
|
541
|
-
...merged,
|
|
542
|
-
contentHash: declarationHash(declaration)
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
function resolvedAll() {
|
|
546
|
-
if (!resolvedCache) {
|
|
547
|
-
resolvedCache = declarations.map(resolve);
|
|
548
|
-
resolvedIndex = new Map(resolvedCache.map((entry) => [entry.surfaceName, entry]));
|
|
549
|
-
}
|
|
550
|
-
return resolvedCache;
|
|
551
|
-
}
|
|
552
|
-
const registry = {
|
|
553
|
-
register(declaration) {
|
|
554
|
-
if (index.has(declaration.surfaceName)) {
|
|
555
|
-
throw new Error(`[surfaces] "${declaration.surfaceName}" is declared twice \u2014 one surface, one declaration`);
|
|
556
|
-
}
|
|
557
|
-
declarations.push(declaration);
|
|
558
|
-
index.set(declaration.surfaceName, declaration);
|
|
559
|
-
resolvedCache = null;
|
|
560
|
-
},
|
|
561
|
-
registerExtension(extension) {
|
|
562
|
-
if (extensionList.some((existing) => existing.key === extension.key)) {
|
|
563
|
-
throw new Error(`[surfaces] declaration extension "${extension.key}" is registered twice`);
|
|
564
|
-
}
|
|
565
|
-
extensionList.push(extension);
|
|
566
|
-
resolvedCache = null;
|
|
567
|
-
},
|
|
568
|
-
extensions: () => extensionList,
|
|
569
|
-
raw: () => declarations,
|
|
570
|
-
getRaw: (surfaceName) => index.get(surfaceName),
|
|
571
|
-
ancestry,
|
|
572
|
-
children: (surfaceName) => declarations.filter((d) => d.inheritsFrom === surfaceName).map((d) => d.surfaceName),
|
|
573
|
-
all: () => resolvedAll(),
|
|
574
|
-
get(surfaceName) {
|
|
575
|
-
resolvedAll();
|
|
576
|
-
return resolvedIndex.get(surfaceName);
|
|
577
|
-
},
|
|
578
|
-
validate: (validateOptions) => validateDeclarations(resolvedAll(), {
|
|
579
|
-
...validateOptions,
|
|
580
|
-
extensions: [...validateOptions?.extensions ?? [], ...extensionList],
|
|
581
|
-
baselineNames: validateOptions?.baselineNames ?? [...baselineNames]
|
|
582
|
-
})
|
|
583
|
-
};
|
|
584
|
-
return registry;
|
|
585
|
-
}
|
|
586
|
-
export {
|
|
587
|
-
APPLY_POLICIES,
|
|
588
|
-
BASELINE_GROUP_ORDER,
|
|
589
|
-
CLASSIFICATIONS,
|
|
590
|
-
DECLARATION_NAME_RE,
|
|
591
|
-
DEFAULT_MAX_INHERITANCE_DEPTH,
|
|
592
|
-
DEFAULT_SENSITIVITY,
|
|
593
|
-
EXECUTION_MODES,
|
|
594
|
-
GENERAL_GROUP_ORDER,
|
|
595
|
-
INHERITED_GROUP_ORDER_BASE,
|
|
596
|
-
LIVE_SLOTS,
|
|
597
|
-
QUALIFIED_VALUE_KEY_RE,
|
|
598
|
-
READINESS,
|
|
599
|
-
RESERVED_GROUP_KEYS,
|
|
600
|
-
STREAM_OPS,
|
|
601
|
-
SURFACE_NAME_RE,
|
|
602
|
-
VALUE_TYPES,
|
|
603
|
-
WRITE_MODES,
|
|
604
|
-
canonicalJson,
|
|
605
|
-
createDeclarationRegistry,
|
|
606
|
-
declarationHash,
|
|
607
|
-
findOrphanRows,
|
|
608
|
-
parseQualifiedValueKey,
|
|
609
|
-
qualifyValueKey,
|
|
610
|
-
resolveSensitivity,
|
|
611
|
-
sha256Hex,
|
|
612
|
-
surfaceClientOf,
|
|
613
|
-
validateDeclarations,
|
|
614
|
-
validateLoadedValues
|
|
615
|
-
};
|
|
1
|
+
var DECLARATION_NAME_RE=/^[a-z][a-z0-9_]*$/,SURFACE_NAME_RE=/^[a-z][a-z0-9-]*\/[a-z0-9-/]+$/,QUALIFIED_VALUE_KEY_RE=/^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)?$/;function parseQualifiedValueKey(key){if(!QUALIFIED_VALUE_KEY_RE.test(key))return null;let dot=key.indexOf(".");return dot===-1?{itemType:"",name:key}:{itemType:key.slice(0,dot),name:key.slice(dot+1)}}function qualifyValueKey(itemType,name){return itemType?`${itemType}.${name}`:name}function surfaceClientOf(surfaceName){return surfaceName.split("/")[0]??""}function canonicalJson(value){if(value===void 0)return"null";if(value===null||typeof value!="object")return JSON.stringify(value);if(Array.isArray(value))return`[${value.map(entry=>canonicalJson(entry)).join(",")}]`;let record=value;return`{${Object.keys(record).filter(key=>record[key]!==void 0).sort().map(key=>`${JSON.stringify(key)}:${canonicalJson(record[key])}`).join(",")}}`}var K=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function sha256Hex(input){let bytes=new TextEncoder().encode(input),bitLength=bytes.length*8,padded=new Uint8Array(bytes.length+9+63>>6<<6);padded.set(bytes),padded[bytes.length]=128;let view=new DataView(padded.buffer);view.setUint32(padded.length-8,Math.floor(bitLength/4294967296)),view.setUint32(padded.length-4,bitLength>>>0);let h=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),w=new Uint32Array(64);for(let offset=0;offset<padded.length;offset+=64){for(let i=0;i<16;i+=1)w[i]=view.getUint32(offset+i*4);for(let i=16;i<64;i+=1){let a2=w[i-15],b2=w[i-2],s0=(a2>>>7|a2<<25)^(a2>>>18|a2<<14)^a2>>>3,s1=(b2>>>17|b2<<15)^(b2>>>19|b2<<13)^b2>>>10;w[i]=w[i-16]+s0+w[i-7]+s1>>>0}let a=h[0],b=h[1],c=h[2],d=h[3],e=h[4],f=h[5],g=h[6],hh=h[7];for(let i=0;i<64;i+=1){let S1=(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7),ch=e&f^~e&g,t1=hh+S1+ch+K[i]+w[i]>>>0,S0=(a>>>2|a<<30)^(a>>>13|a<<19)^(a>>>22|a<<10),maj=a&b^a&c^b&c,t2=S0+maj>>>0;hh=g,g=f,f=e,e=d+t1>>>0,d=c,c=b,b=a,a=t1+t2>>>0}h[0]=h[0]+a>>>0,h[1]=h[1]+b>>>0,h[2]=h[2]+c>>>0,h[3]=h[3]+d>>>0,h[4]=h[4]+e>>>0,h[5]=h[5]+f>>>0,h[6]=h[6]+g>>>0,h[7]=h[7]+hh>>>0}return Array.from(h,word=>word.toString(16).padStart(8,"0")).join("")}function declarationHash(declaration){return sha256Hex(canonicalJson(declaration))}var VALUE_TYPES=["string","number","boolean","object","array","document"],WRITE_MODES=["draft","entity","ui","stream"],APPLY_POLICIES=["manual","ask","auto","queued"],STREAM_OPS=["replace","insert_before","insert_after","prepend","append","patch"],EXECUTION_MODES=["python-stream","nextjs-stream","browser-realtime","local-runtime"],READINESS=["verified","partial","stub"],LIVE_SLOTS=["selection","on-demand","errors","requests"],CLASSIFICATIONS=["ordinary","secret","credential"],STRUCTURED=new Set(["object","array"]);function has(list,value){return typeof value=="string"&&list.includes(value)}function validateDeclarations(declarations,options={}){let issues=[],seenSurfaces=new Set,labelsByClient=new Map;for(let d of declarations){let s=d.surfaceName,push=(path,sentence,remedy,severity)=>issues.push({surfaceName:s,path,sentence,remedy,...severity?{severity}:{}});seenSurfaces.has(s)&&push("surfaceName",`Duplicate manifest surfaceName: "${s}" appears more than once.`,"Keep one declaration per surface."),seenSurfaces.add(s),SURFACE_NAME_RE.test(s)||push("surfaceName",`Surface "${s}" doesn't match the "<client>/<local>" convention.`,"Rename it to <client>/<local>.");let prefix=surfaceClientOf(s);d.client!==prefix&&push("client",`Surface "${s}" declares client "${String(d.client)}" but its name prefix is "${prefix}" \u2014 they must match.`,`Set client: "${prefix}".`),has(EXECUTION_MODES,d.executionMode)||push("executionMode",`Surface "${s}" has invalid executionMode "${String(d.executionMode)}".`,`Use one of ${EXECUTION_MODES.join(" | ")}.`),typeof d.description!="string"&&push("description",`Surface "${s}" has no description.`,'Add one sentence on what the surface is ("" only where the live row is empty).');let label=d.label?.trim();if(!label)push("label",`Surface "${s}" has no canonical label \u2014 label is required.`,"Add the ONE canonical human display name.");else{let clientLabels=labelsByClient.get(prefix)??new Map,clash=clientLabels.get(label.toLowerCase());clash&&clash!==s&&push("label",`Canonical label "${label}" is used by both "${clash}" and "${s}" \u2014 labels must be unique per client.`,"Give one of them a distinct label."),clientLabels.set(label.toLowerCase(),s),labelsByClient.set(prefix,clientLabels)}has(READINESS,d.readiness)?d.readiness!=="verified"&&!d.readinessNote?.trim()&&push("readinessNote",`Surface "${s}" is readiness "${d.readiness}" but has no readinessNote \u2014 say what's missing.`,"Add a one-line readinessNote."):push("readiness",`Surface "${s}" has invalid readiness "${String(d.readiness)}" (expected verified | partial | stub).`,"Set a valid readiness.");let groupKeys=new Set;for(let g of d.groups??[])groupKeys.add(g.key),!(g.key==="general"||g.key==="baseline"||g.key.startsWith("inherited:"))&&(DECLARATION_NAME_RE.test(g.key)||push(`groups/${g.key}`,`Surface "${s}" group "${g.key}" doesn't match /^[a-z][a-z0-9_]*$/.`,"Rename the group key to lower_snake_case."),(g.sortOrder<0||g.sortOrder>899)&&push(`groups/${g.key}/sortOrder`,`Surface "${s}" group "${g.key}" sortOrder ${g.sortOrder} is outside the curated band 0\u2013899.`,"Use a sortOrder between 0 and 899."),g.label?.trim()||push(`groups/${g.key}/label`,`Surface "${s}" group "${g.key}" has no canonical label.`,"Add a label."));let seenNamespaces=new Set;for(let ns of d.configNamespaces??[])seenNamespaces.has(ns.namespace)&&push(`configNamespaces/${ns.namespace}`,`Surface "${s}" declares duplicate config namespace "${ns.namespace}".`,"Remove the duplicate."),seenNamespaces.add(ns.namespace),options.knownNamespaces&&!options.knownNamespaces.has(ns.namespace)&&push(`configNamespaces/${ns.namespace}`,`Surface "${s}" references config namespace "${ns.namespace}" which is not registered.`,"Register the namespace first, or remove the reference.");if(d.values.length===0){push("values",`Surface "${s}" declares no values.`,"Declare at least one value.");continue}let seenValues=new Set;for(let v of d.values){let at=`values/${v.name}`;seenValues.has(v.name)&&push(at,`Surface "${s}" declares duplicate value "${v.name}".`,"Remove the duplicate."),seenValues.add(v.name),DECLARATION_NAME_RE.test(v.name)||push(at,`Surface "${s}" value "${v.name}" doesn't match /^[a-z][a-z0-9_]*$/ \u2014 the DB CHECK constraint will reject this.`,"Rename it to lower_snake_case."),has(VALUE_TYPES,v.valueType)||push(`${at}/valueType`,`Surface "${s}" value "${v.name}" has invalid valueType "${String(v.valueType)}".`,`Use one of ${VALUE_TYPES.join(" | ")}.`),(typeof v.typicalCharCount!="number"||v.typicalCharCount<0)&&push(`${at}/typicalCharCount`,`Surface "${s}" value "${v.name}" has invalid typicalCharCount.`,"Use a non-negative number."),v.sortOrder!==void 0&&(typeof v.sortOrder!="number"||v.sortOrder<0)&&push(`${at}/sortOrder`,`Surface "${s}" value "${v.name}" has invalid sortOrder.`,"Use a non-negative number."),v.groupKey&&!groupKeys.has(v.groupKey)&&push(`${at}/group`,`Surface "${s}" value "${v.name}" resolved to groupKey "${v.groupKey}" which is missing from the resolved groups list \u2014 registry group synthesis is broken.`,"Fix the registry resolution."),v.liveSlot!==void 0&&!has(LIVE_SLOTS,v.liveSlot)&&push(`${at}/liveSlot`,`Surface "${s}" value "${v.name}" has invalid liveSlot "${String(v.liveSlot)}".`,`Use one of ${LIVE_SLOTS.join(" | ")}.`),v.role!==void 0&&v.role!=="data"&&v.role!=="request"&&push(`${at}/role`,`Surface "${s}" value "${v.name}" has invalid role "${String(v.role)}".`,"Use data | request."),v.sensitivity?.classification!==void 0&&!has(CLASSIFICATIONS,v.sensitivity.classification)&&push(`${at}/sensitivity/classification`,`Surface "${s}" value "${v.name}" has invalid classification "${String(v.sensitivity.classification)}".`,`Use one of ${CLASSIFICATIONS.join(" | ")}.`)}for(let slot of d.liveSlots??[])has(LIVE_SLOTS,slot)||push("liveSlots",`Surface "${s}" declares unknown live slot "${String(slot)}".`,`Use one of ${LIVE_SLOTS.join(" | ")}.`);let itemTypeNames=new Set;for(let item of d.itemTypes??[]){let at=`itemTypes/${item.name}`;itemTypeNames.has(item.name)&&push(at,`Surface "${s}" declares duplicate item type "${item.name}".`,"Remove the duplicate."),itemTypeNames.add(item.name),DECLARATION_NAME_RE.test(item.name)||push(at,`Surface "${s}" item type "${item.name}" doesn't match /^[a-z][a-z0-9_]*$/.`,"Rename it to lower_snake_case."),(!item.label?.trim()||!item.description?.trim())&&push(at,`Surface "${s}" item type "${item.name}" needs a label and a description.`,"Add both.");let itemValues=new Set(item.values.map(v=>v.name));item.identity.length===0&&push(`${at}/identity`,`Surface "${s}" item type "${item.name}" has an empty identity.`,"Name the value(s) that identify one item.");for(let key of item.identity)itemValues.has(key)||push(`${at}/identity`,`Surface "${s}" item type "${item.name}" identity names "${key}", which is not one of its values.`,"Declare it as an item value.");for(let t of item.writeTargets??[])t.updatesValue&&!itemValues.has(t.updatesValue)&&push(`${at}/writeTargets/${t.name}`,`Surface "${s}" item type "${item.name}" write target "${t.name}" updatesValue "${t.updatesValue}" which is not an item value.`,"Point it at a declared item value.")}let seenTargets=new Set,structuredWithoutKind=[];for(let w of d.writeTargets??[]){let at=`writeTargets/${w.name}`;seenTargets.has(w.name)&&push(at,`Surface "${s}" declares duplicate write target "${w.name}".`,"Remove the duplicate."),seenTargets.add(w.name),DECLARATION_NAME_RE.test(w.name)||push(at,`Surface "${s}" write target "${w.name}" doesn't match /^[a-z][a-z0-9_]*$/.`,"Rename it to lower_snake_case."),(!w.label?.trim()||!w.description?.trim())&&push(at,`Surface "${s}" write target "${w.name}" needs a label and a description.`,"Add both."),has(VALUE_TYPES,w.valueType)||push(`${at}/valueType`,`Surface "${s}" write target "${w.name}" has invalid valueType "${String(w.valueType)}".`,`Use one of ${VALUE_TYPES.join(" | ")}.`),has(WRITE_MODES,w.mode)||push(`${at}/mode`,`Surface "${s}" write target "${w.name}" has invalid mode "${String(w.mode)}".`,`Use one of ${WRITE_MODES.join(" | ")}.`),w.applyPolicy!==void 0&&!has(APPLY_POLICIES,w.applyPolicy)&&push(`${at}/applyPolicy`,`Surface "${s}" write target "${w.name}" has invalid applyPolicy "${String(w.applyPolicy)}".`,`Use one of ${APPLY_POLICIES.join(" | ")}.`),w.itemType!==void 0&&!itemTypeNames.has(w.itemType)&&push(`${at}/itemType`,`Surface "${s}" write target "${w.name}" names item type "${w.itemType}", which the surface does not declare.`,"Declare the item type or drop itemType.");let readTwinDeclared=w.updatesValue?seenValues.has(w.updatesValue):!1;w.updatesValue&&!w.itemType&&!readTwinDeclared&&push(`${at}/updatesValue`,`Surface "${s}" write target "${w.name}" updatesValue "${w.updatesValue}" which is not a declared value.`,"Point updatesValue at a declared value."),w.patchable&&!w.updatesValue&&push(`${at}/patchable`,`Surface "${s}" write target "${w.name}" is patchable but declares no updatesValue \u2014 an anchored edit has nothing to read.`,"Declare the read twin in updatesValue."),w.patchable&&w.valueType!=="string"&&w.valueType!=="document"&&push(`${at}/patchable`,`Surface "${s}" write target "${w.name}" is patchable but valueType is "${w.valueType}" (patching is for "string" | "document").`,"Drop patchable or change the value type."),w.mode==="stream"?((!w.streamOps||w.streamOps.length===0)&&push(`${at}/streamOps`,`Surface "${s}" write target "${w.name}" is a stream target with no streamOps.`,"List the ops it services."),w.updatesValue||push(`${at}/updatesValue`,`Surface "${s}" write target "${w.name}" is a stream target with no read twin.`,"Declare updatesValue.")):w.streamOps!==void 0&&push(`${at}/streamOps`,`Surface "${s}" write target "${w.name}" lists streamOps but its mode is "${w.mode}".`,'streamOps belong only to mode "stream".');for(let op of w.streamOps??[])has(STREAM_OPS,op)||push(`${at}/streamOps`,`Surface "${s}" write target "${w.name}" lists unknown stream op "${String(op)}".`,`Use ${STREAM_OPS.join(" | ")}.`);w.group&&!groupKeys.has(w.group)&&push(`${at}/group`,`Surface "${s}" write target "${w.name}" references undeclared group "${w.group}".`,"Declare the group or drop it."),w.valueKind!==void 0?typeof w.valueKind!="string"||!w.valueKind.trim()?push(`${at}/valueKind`,`Surface "${s}" write target "${w.name}" has an empty valueKind.`,"Name a registered kind slug or omit the field."):options.isKnownKind&&!options.isKnownKind(w.valueKind)&&push(`${at}/valueKind`,`Surface "${s}" write target "${w.name}" declares valueKind "${w.valueKind}", which is not a registered active kind.`,"Name a registered kind slug, or register the kind first; never inline a JSON schema."):STRUCTURED.has(w.valueType)&&structuredWithoutKind.push(w.name)}for(let name of structuredWithoutKind)push(`writeTargets/${name}/valueKind`,`Surface "${s}" structured write target "${name}" declares no valueKind.`,"Name a registered kind slug (the value contract ratchet).","advisory");if(!d.skipBaselineValues&&options.baselineNames){let missing=options.baselineNames.filter(name=>!seenValues.has(name));missing.length>0&&push("values",`Surface "${s}" is missing baseline value(s): ${missing.join(", ")}.`,"The registry injects baselines automatically; opt out only with skipBaselineValues.")}}for(let extension of options.extensions??[])if(extension.validate)for(let d of declarations)issues.push(...extension.validate(d,{all:declarations}));return issues}function validateLoadedValues(declaration,loaded,options={}){let declared=new Set(declaration.values.map(v=>v.name)),ignore=new Set(options.ignore??[]),issues=[];for(let key of Object.keys(loaded))key==="__item"||declared.has(key)||ignore.has(key)||issues.push({surfaceName:declaration.surfaceName,path:`values/${key}`,sentence:`Surface "${declaration.surfaceName}" loaded a value "${key}" it never declared.`,remedy:`Declare "${key}" in the surface's values, or stop emitting it.`});let item=loaded.__item;if(item&&typeof item=="object"){let type=declaration.itemTypes?.find(t=>t.name===item.itemType);if(!type)issues.push({surfaceName:declaration.surfaceName,path:"__item/itemType",sentence:`Surface "${declaration.surfaceName}" loaded an item of type "${String(item.itemType)}" it never declared.`,remedy:"Declare the item type, or stop emitting the item."});else if(item.values&&typeof item.values=="object"){let itemDeclared=new Set(type.values.map(v=>v.name));for(let key of Object.keys(item.values))itemDeclared.has(key)||issues.push({surfaceName:declaration.surfaceName,path:`__item/${type.name}.${key}`,sentence:`Surface "${declaration.surfaceName}" loaded item value "${type.name}.${key}" it never declared.`,remedy:`Declare "${key}" on item type "${type.name}".`})}}return issues}function findOrphanRows(rowNames,declaredNames,retired=[]){let owned=new Set(declaredNames),archived=new Set(retired);return rowNames.filter(name=>!owned.has(name)&&!archived.has(name)).sort()}var DEFAULT_SENSITIVITY=Object.freeze({exportable:!0,classification:"ordinary",includedByDefault:!0});function resolveSensitivity(value){return{exportable:value.sensitivity?.exportable??DEFAULT_SENSITIVITY.exportable,classification:value.sensitivity?.classification??DEFAULT_SENSITIVITY.classification,includedByDefault:value.sensitivity?.includedByDefault??DEFAULT_SENSITIVITY.includedByDefault}}var RESERVED_GROUP_KEYS={general:"general",baseline:"baseline",inheritedPrefix:"inherited:"},GENERAL_GROUP_ORDER=850,INHERITED_GROUP_ORDER_BASE=9e3,BASELINE_GROUP_ORDER=9900,DEFAULT_MAX_INHERITANCE_DEPTH=3;function createDeclarationRegistry(options={}){let baselineValues=options.baselineValues??[],baselineNames=new Set(baselineValues.map(v=>v.name)),reservedValues=new Set(options.reservedValueNames??[]),reservedTargets=new Set(options.reservedWriteTargetNames??[]),maxDepth=options.maxInheritanceDepth??DEFAULT_MAX_INHERITANCE_DEPTH,declarations=[],index=new Map,extensionList=[],resolvedCache=null,resolvedIndex=new Map;function ancestry(surfaceName){let chain=[],seen=new Set([surfaceName]),current=index.get(surfaceName)?.inheritsFrom;for(;current;){if(seen.has(current))throw new Error(`[surfaces] inheritsFrom CYCLE detected at "${current}" (from "${surfaceName}"). Fix the manifest chain: ${[...seen].join(" \u2192 ")} \u2192 ${current}`);let parent=index.get(current);if(!parent)throw new Error(`[surfaces] "${surfaceName}" inheritsFrom unknown surface "${current}" \u2014 the parent must be a registered declaration`);if(seen.add(current),chain.unshift(current),chain.length>maxDepth)throw new Error(`[surfaces] inheritance chain for "${surfaceName}" exceeds depth ${maxDepth}: `+chain.join(" \u2192 "));current=parent.inheritsFrom}return chain}function groupKeyFor(value,provenance){return provenance.kind==="own"&&value.group?value.group:baselineNames.has(value.name)?RESERVED_GROUP_KEYS.baseline:provenance.kind==="inherited"?`${RESERVED_GROUP_KEYS.inheritedPrefix}${provenance.from}`:provenance.kind==="baseline"?RESERVED_GROUP_KEYS.baseline:RESERVED_GROUP_KEYS.general}function resolve(declaration){let chain=ancestry(declaration.surfaceName),lineage=[...chain.map(name=>{let layer=index.get(name);if(!layer)throw new Error(`[surfaces] missing inherited declaration "${name}"`);return{layer,from:name}}),{layer:declaration,from:null}],curatedKeys=new Set;for(let group of declaration.groups??[]){if(group.key===RESERVED_GROUP_KEYS.general||group.key===RESERVED_GROUP_KEYS.baseline||group.key.startsWith(RESERVED_GROUP_KEYS.inheritedPrefix))throw new Error(`[surfaces] "${declaration.surfaceName}" declares reserved group key "${group.key}" \u2014 general/baseline/inherited:* are synthesized by the registry`);if(curatedKeys.has(group.key))throw new Error(`[surfaces] "${declaration.surfaceName}" declares duplicate group key "${group.key}"`);curatedKeys.add(group.key)}for(let value of declaration.values){if(reservedValues.has(value.name))throw new Error(`[surfaces] "${declaration.surfaceName}" declares value "${value.name}" \u2014 that name is written by the platform; choose another name`);if(value.group&&!curatedKeys.has(value.group))throw new Error(`[surfaces] "${declaration.surfaceName}" value "${value.name}" references undeclared group "${value.group}" \u2014 declare it in the manifest's \`groups\``)}for(let target of declaration.writeTargets??[])if(reservedTargets.has(target.name))throw new Error(`[surfaces] "${declaration.surfaceName}" declares write target "${target.name}" \u2014 that name is written by the platform; choose another name`);let valuesByName=new Map,inheritedLists=new Map,lists=[...[{field:"configNamespaces",identity:entry=>entry.namespace},{field:"evidenceSources",identity:entry=>`${entry.kind}:${entry.idValue}`}],...extensionList.flatMap(extension=>extension.inheritedLists??[])];for(let{layer,from}of lineage){for(let value of layer.values){let provenance=from?{kind:"inherited",from}:{kind:"own"};valuesByName.set(value.name,{...value,provenance,groupKey:groupKeyFor(value,provenance),resolvedSensitivity:resolveSensitivity(value)})}for(let list of lists){let entries=layer[list.field];if(!Array.isArray(entries))continue;let byIdentity=inheritedLists.get(list.field)??new Map;for(let entry of entries)byIdentity.set(list.identity(entry),entry);inheritedLists.set(list.field,byIdentity)}}if(!declaration.skipBaselineValues)for(let baseline of baselineValues)valuesByName.has(baseline.name)||valuesByName.set(baseline.name,{...baseline,provenance:{kind:"baseline"},groupKey:RESERVED_GROUP_KEYS.baseline,resolvedSensitivity:resolveSensitivity(baseline)});let usedGroupKeys=new Set(Array.from(valuesByName.values(),value=>value.groupKey)),groups=[...declaration.groups??[]];usedGroupKeys.has(RESERVED_GROUP_KEYS.general)&&groups.push({key:RESERVED_GROUP_KEYS.general,label:"General",sortOrder:GENERAL_GROUP_ORDER});for(let i=chain.length-1,distance=0;i>=0;i-=1,distance+=1){let parentName=chain[i],key=`${RESERVED_GROUP_KEYS.inheritedPrefix}${parentName}`;if(!usedGroupKeys.has(key))continue;let parentLabel=index.get(parentName)?.label??parentName;groups.push({key,label:`Inherited from ${parentLabel}`,sortOrder:INHERITED_GROUP_ORDER_BASE+distance*10})}usedGroupKeys.has(RESERVED_GROUP_KEYS.baseline)&&groups.push({key:RESERVED_GROUP_KEYS.baseline,label:"Generic baselines",sortOrder:BASELINE_GROUP_ORDER}),groups.sort((a,b)=>a.sortOrder-b.sortOrder);let groupOrder=new Map(groups.map(group=>[group.key,group.sortOrder])),values=Array.from(valuesByName.values()).sort((a,b)=>{let ga=groupOrder.get(a.groupKey)??GENERAL_GROUP_ORDER,gb=groupOrder.get(b.groupKey)??GENERAL_GROUP_ORDER;return ga!==gb?ga-gb:(a.sortOrder??1e3)-(b.sortOrder??1e3)}),merged={};for(let[field,byIdentity]of inheritedLists)byIdentity.size>0&&(merged[field]=Array.from(byIdentity.values()));return{...declaration,values,groups,...merged,contentHash:declarationHash(declaration)}}function resolvedAll(){return resolvedCache||(resolvedCache=declarations.map(resolve),resolvedIndex=new Map(resolvedCache.map(entry=>[entry.surfaceName,entry]))),resolvedCache}return{register(declaration){if(index.has(declaration.surfaceName))throw new Error(`[surfaces] "${declaration.surfaceName}" is declared twice \u2014 one surface, one declaration`);declarations.push(declaration),index.set(declaration.surfaceName,declaration),resolvedCache=null},registerExtension(extension){if(extensionList.some(existing=>existing.key===extension.key))throw new Error(`[surfaces] declaration extension "${extension.key}" is registered twice`);extensionList.push(extension),resolvedCache=null},extensions:()=>extensionList,raw:()=>declarations,getRaw:surfaceName=>index.get(surfaceName),ancestry,children:surfaceName=>declarations.filter(d=>d.inheritsFrom===surfaceName).map(d=>d.surfaceName),all:()=>resolvedAll(),get(surfaceName){return resolvedAll(),resolvedIndex.get(surfaceName)},validate:validateOptions=>validateDeclarations(resolvedAll(),{...validateOptions,extensions:[...validateOptions?.extensions??[],...extensionList],baselineNames:validateOptions?.baselineNames??[...baselineNames]})}}export{APPLY_POLICIES,BASELINE_GROUP_ORDER,CLASSIFICATIONS,DECLARATION_NAME_RE,DEFAULT_MAX_INHERITANCE_DEPTH,DEFAULT_SENSITIVITY,EXECUTION_MODES,GENERAL_GROUP_ORDER,INHERITED_GROUP_ORDER_BASE,LIVE_SLOTS,QUALIFIED_VALUE_KEY_RE,READINESS,RESERVED_GROUP_KEYS,STREAM_OPS,SURFACE_NAME_RE,VALUE_TYPES,WRITE_MODES,canonicalJson,createDeclarationRegistry,declarationHash,findOrphanRows,parseQualifiedValueKey,qualifyValueKey,resolveSensitivity,sha256Hex,surfaceClientOf,validateDeclarations,validateLoadedValues};
|
|
616
2
|
//# sourceMappingURL=declare.js.map
|