react-semaphor 0.1.398 → 0.1.400

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +2 -2
  3. package/dist/brand-studio/index.cjs +1 -1
  4. package/dist/brand-studio/index.js +2 -2
  5. package/dist/chunks/analyze-result-contract-BUgK3759.js +1833 -0
  6. package/dist/chunks/analyze-result-contract-S8u7CcPL.js +1 -0
  7. package/dist/chunks/{calendar-preferences-dialog-DwLeBLy2.js → calendar-preferences-dialog-Ci3rHHgA.js} +1 -1
  8. package/dist/chunks/{calendar-preferences-dialog-49fcEPXS.js → calendar-preferences-dialog-i3-jBIYS.js} +3 -3
  9. package/dist/chunks/{dashboard-briefing-launcher-cgPKz1yX.js → dashboard-briefing-launcher-BpwjeJsQ.js} +4 -4
  10. package/dist/chunks/{dashboard-briefing-launcher-CgkSKkZR.js → dashboard-briefing-launcher-DiEpMS9E.js} +1 -1
  11. package/dist/chunks/{dashboard-controls-D12ZSUP_.js → dashboard-controls-BaUUrvSI.js} +1 -1
  12. package/dist/chunks/{dashboard-controls-VMFm3OP4.js → dashboard-controls-Bkjpgr3d.js} +5 -5
  13. package/dist/chunks/{dashboard-json-CvK0oI24.js → dashboard-json-CxNyExRm.js} +1 -1
  14. package/dist/chunks/{dashboard-json-C-GG5yC7.js → dashboard-json-DvULhhN2.js} +3 -3
  15. package/dist/chunks/{edit-dashboard-visual-B5KB7dx4.js → edit-dashboard-visual-DBrsgEtL.js} +4 -4
  16. package/dist/chunks/{edit-dashboard-visual-ql99faTz.js → edit-dashboard-visual-DJRPiKdY.js} +1 -1
  17. package/dist/chunks/{index-DXCBPLDu.js → index-BepF6hoa.js} +2 -2
  18. package/dist/chunks/{index-CQmKDEbe.js → index-Drz04wqE.js} +5 -5
  19. package/dist/chunks/{switch-B79Hn4Qh.js → switch-D2oOmorN.js} +1 -1
  20. package/dist/chunks/{switch-BXQAlSuW.js → switch-qUw8u-gU.js} +1 -1
  21. package/dist/chunks/update-policy-BmtOqvbf.js +3 -0
  22. package/dist/chunks/update-policy-KImUg4Od.js +831 -0
  23. package/dist/chunks/{use-create-flow-overlay-state-Bw5LRkf9.js → use-create-flow-overlay-state-CFJIHt5D.js} +3 -3
  24. package/dist/chunks/{use-create-flow-overlay-state-7MFN3PWX.js → use-create-flow-overlay-state-DrkYiyQz.js} +1 -1
  25. package/dist/chunks/{validators-4EGCWWga.js → validators-B1Mgdr3T.js} +279 -242
  26. package/dist/chunks/{validators-CPtkrola.js → validators-DFOX0tYY.js} +1 -1
  27. package/dist/dashboard/index.cjs +1 -1
  28. package/dist/dashboard/index.js +1 -1
  29. package/dist/dashboard-authoring/index.cjs +1 -1
  30. package/dist/dashboard-authoring/index.js +2 -2
  31. package/dist/data-app-builder/index.cjs +1 -1
  32. package/dist/data-app-builder/index.js +2 -2
  33. package/dist/data-app-codegen/index.cjs +1 -0
  34. package/dist/data-app-codegen/index.js +22 -0
  35. package/dist/data-app-codegen-node/index.cjs +462 -0
  36. package/dist/data-app-codegen-node/index.js +1424 -0
  37. package/dist/data-app-sdk/index.cjs +2 -2
  38. package/dist/data-app-sdk/index.js +3 -2
  39. package/dist/data-app-sdk-adapters/index.cjs +1 -1
  40. package/dist/data-app-sdk-adapters/index.js +20 -12
  41. package/dist/data-app-sdk-validation/index.cjs +1 -1
  42. package/dist/data-app-sdk-validation/index.js +2 -2
  43. package/dist/index.cjs +1 -1
  44. package/dist/index.js +7 -7
  45. package/dist/surfboard/index.cjs +1 -1
  46. package/dist/surfboard/index.js +2 -2
  47. package/dist/types/analytics-protocol.d.ts +101 -2
  48. package/dist/types/dashboard-assistant.d.ts +14 -0
  49. package/dist/types/dashboard-authoring.d.ts +6 -0
  50. package/dist/types/data-app-builder.d.ts +6 -0
  51. package/dist/types/data-app-codegen-node.d.ts +1165 -0
  52. package/dist/types/data-app-codegen.d.ts +1137 -0
  53. package/dist/types/data-app-sdk-adapters.d.ts +7 -0
  54. package/dist/types/data-app-sdk-validation.d.ts +15 -0
  55. package/dist/types/data-app-sdk.d.ts +18 -0
  56. package/dist/types/main.d.ts +6 -0
  57. package/package.json +9 -1
  58. package/dist/chunks/analyze-result-contract-C9Gv2_qW.js +0 -1585
  59. package/dist/chunks/analyze-result-contract-Zgg-Bbpj.js +0 -1
@@ -0,0 +1,831 @@
1
+ import { S as W, a as Q, v as X } from "./analyze-result-contract-BUgK3759.js";
2
+ import { toSemaphorInputOptionsIntent as Z, toSemaphorAnalysisQueryOptions as ee, toSemaphorAnalysisIntent as te, toSemaphorMetricIntent as re, toSemaphorRecordsIntent as ne, toSemaphorMatrixIntent as ae, toSemaphorSqlIntent as se } from "../data-app-sdk-adapters/index.js";
3
+ const Be = W, K = Q, M = "semaphor-generated-data-app-contract/v1", x = "semaphor-generated-data-app-contract-manifest/v1";
4
+ function L(e) {
5
+ return _(e) ? [
6
+ ...X(e).issues,
7
+ ...ie(e)
8
+ ] : ["Plan artifact must be a Semaphor codegenSummary object."];
9
+ }
10
+ function Le(e) {
11
+ const t = L(e);
12
+ if (t.length > 0)
13
+ throw new Error(`Invalid Semaphor codegenSummary:
14
+ - ${t.join(`
15
+ - `)}`);
16
+ }
17
+ function ie(e) {
18
+ var r;
19
+ const t = _(e);
20
+ if (!t)
21
+ return [];
22
+ const n = [];
23
+ return ((r = _(t.validation)) == null ? void 0 : r.status) === "blocked" && n.push(
24
+ "validation.status blocked cannot be generated. Resolve blocked semantic model gaps and replan before generating contract files."
25
+ ), Array.isArray(t.unsupportedInsights) && t.unsupportedInsights.forEach((s, a) => {
26
+ var i;
27
+ ((i = _(s)) == null ? void 0 : i.reason) === "missing_relationship" && n.push(
28
+ `unsupportedInsights.${a}.reason missing_relationship blocks contract generation. Call semaphor_propose_semantic_model_change, apply an approved semantic model patch, and replan before generating contract files.`
29
+ );
30
+ }), Array.isArray(t.views) && t.views.forEach((s, a) => {
31
+ var o;
32
+ const i = _((o = _(s)) == null ? void 0 : o.computation);
33
+ (i == null ? void 0 : i.kind) === "unsupported" && i.reason === "missing_relationship" && n.push(
34
+ `views.${a}.computation.reason missing_relationship blocks contract generation. Call semaphor_propose_semantic_model_change, apply an approved semantic model patch, and replan before generating contract files.`
35
+ );
36
+ }), n;
37
+ }
38
+ function _(e) {
39
+ return e && typeof e == "object" && !Array.isArray(e) ? e : void 0;
40
+ }
41
+ async function Pe({
42
+ manifest: e,
43
+ generatedFiles: t
44
+ }) {
45
+ const n = [], r = y(e);
46
+ if (!r)
47
+ return {
48
+ issues: [
49
+ {
50
+ message: "Generated contract manifest must be an object.",
51
+ repairHint: "Regenerate the generated contract instead of hand-editing the manifest."
52
+ }
53
+ ]
54
+ };
55
+ r.schemaVersion !== x && n.push({
56
+ path: "schemaVersion",
57
+ message: `schemaVersion must be ${x}. Regenerate the contract with semaphor_create_data_app_contract.`,
58
+ repairHint: "Regenerate the contract with semaphor_create_data_app_contract."
59
+ }), r.generatedContractSchemaVersion !== M && n.push({
60
+ path: "generatedContractSchemaVersion",
61
+ message: `generatedContractSchemaVersion must be ${M}. Regenerate the contract with semaphor_generate_data_app_contract.`,
62
+ repairHint: "Regenerate the contract with semaphor_generate_data_app_contract."
63
+ });
64
+ const s = y(r.generator);
65
+ S(s == null ? void 0 : s.name) || n.push({
66
+ path: "generator.name",
67
+ message: "generator.name is required.",
68
+ repairHint: "Regenerate the generated contract so manifest generator metadata is written deterministically."
69
+ }), S(s == null ? void 0 : s.version) || n.push({
70
+ path: "generator.version",
71
+ message: "generator.version is required.",
72
+ repairHint: "Regenerate the generated contract so manifest generator metadata is written deterministically."
73
+ });
74
+ for (const a of L(r.codegenSummary))
75
+ n.push({
76
+ path: `codegenSummary.${a}`,
77
+ message: `codegenSummary.${a}`,
78
+ repairHint: "Regenerate the generated contract from a valid Data App codegenSummary."
79
+ });
80
+ if (r.codegenSummaryValidatorVersion !== K && n.push({
81
+ path: "codegenSummaryValidatorVersion",
82
+ message: `codegenSummaryValidatorVersion must be ${K}. Regenerate the contract with semaphor_generate_data_app_contract.`,
83
+ repairHint: "Regenerate the contract with semaphor_generate_data_app_contract."
84
+ }), typeof r.codegenSummaryHash != "string")
85
+ n.push({
86
+ path: "codegenSummaryHash",
87
+ message: "codegenSummaryHash is required.",
88
+ repairHint: "Regenerate the generated contract so manifest hashes are written deterministically."
89
+ });
90
+ else if (y(r.codegenSummary)) {
91
+ const a = await de(
92
+ r.codegenSummary
93
+ );
94
+ r.codegenSummaryHash !== a && n.push({
95
+ path: "codegenSummaryHash",
96
+ message: "codegenSummaryHash does not match codegenSummary. Regenerate the contract instead of editing the manifest.",
97
+ repairHint: "Regenerate the generated contract instead of editing the manifest."
98
+ });
99
+ }
100
+ if (n.push(...oe(r.codegenSummary)), typeof r.generatedContentHash != "string")
101
+ n.push({
102
+ path: "generatedContentHash",
103
+ message: "generatedContentHash is required.",
104
+ repairHint: "Regenerate the generated contract so manifest hashes are written deterministically."
105
+ });
106
+ else if (t) {
107
+ const a = await ce(t);
108
+ r.generatedContentHash !== a && n.push({
109
+ path: "generatedContentHash",
110
+ message: "generatedContentHash does not match generated TypeScript files. Regenerate the contract instead of hand-editing generated files.",
111
+ repairHint: "Regenerate the contract instead of hand-editing generated files."
112
+ });
113
+ }
114
+ return { issues: n };
115
+ }
116
+ function oe(e) {
117
+ const t = y(e);
118
+ if (!t)
119
+ return [];
120
+ const n = [], r = new Set(
121
+ E(t.inputs).map((a) => {
122
+ var i;
123
+ return (i = y(a)) == null ? void 0 : i.id;
124
+ }).filter(S)
125
+ ), s = new Set(
126
+ E(t.views).map((a) => {
127
+ var i;
128
+ return (i = y(a)) == null ? void 0 : i.id;
129
+ }).filter(S)
130
+ );
131
+ return E(t.filterContracts).forEach((a, i) => {
132
+ const o = y(a), c = o == null ? void 0 : o.inputId;
133
+ (!S(c) || !r.has(c)) && n.push({
134
+ path: `codegenSummary.filterContracts.${i}.inputId`,
135
+ message: `codegenSummary.filterContracts.${i}.inputId must reference a generated input.`,
136
+ repairHint: "Regenerate the generated contract from a valid planner output."
137
+ }), Array.isArray(o == null ? void 0 : o.bindings) && o.bindings.forEach((u, f) => {
138
+ const g = y(u), l = g == null ? void 0 : g.viewId;
139
+ (!S(l) || !s.has(l)) && n.push({
140
+ path: `codegenSummary.filterContracts.${i}.bindings.${f}.viewId`,
141
+ message: `codegenSummary.filterContracts.${i}.bindings.${f}.viewId must reference a generated view.`,
142
+ repairHint: "Regenerate the generated contract from a valid planner output."
143
+ });
144
+ const h = y(g == null ? void 0 : g.fieldRef);
145
+ S(h == null ? void 0 : h.name) || n.push({
146
+ path: `codegenSummary.filterContracts.${i}.bindings.${f}.fieldRef`,
147
+ message: `codegenSummary.filterContracts.${i}.bindings.${f}.fieldRef is required.`,
148
+ repairHint: "Regenerate the generated contract from a valid planner output."
149
+ });
150
+ });
151
+ }), n;
152
+ }
153
+ async function ce(e) {
154
+ const t = Object.keys(e).filter((r) => r.endsWith(".ts")).sort();
155
+ let n = "";
156
+ for (const r of t)
157
+ n += `${r}\0${e[r]}\0`;
158
+ return `sha256:${await P(n)}`;
159
+ }
160
+ async function de(e) {
161
+ return `sha256:${await P(N(e))}`;
162
+ }
163
+ function N(e) {
164
+ if (e === null || typeof e != "object")
165
+ return JSON.stringify(e);
166
+ if (Array.isArray(e))
167
+ return `[${e.map((r) => N(r)).join(",")}]`;
168
+ const t = e;
169
+ return `{${Object.keys(t).sort().filter((r) => t[r] !== void 0).map((r) => `${JSON.stringify(r)}:${N(t[r])}`).join(",")}}`;
170
+ }
171
+ async function P(e) {
172
+ var r;
173
+ if (!((r = globalThis.crypto) != null && r.subtle))
174
+ throw new Error("SHA-256 digest support is required for generated contract validation.");
175
+ const t = new TextEncoder().encode(e), n = await globalThis.crypto.subtle.digest("SHA-256", t);
176
+ return Array.from(new Uint8Array(n)).map((s) => s.toString(16).padStart(2, "0")).join("");
177
+ }
178
+ function y(e) {
179
+ return e && typeof e == "object" && !Array.isArray(e) ? e : void 0;
180
+ }
181
+ function E(e) {
182
+ return Array.isArray(e) ? e : [];
183
+ }
184
+ function S(e) {
185
+ return typeof e == "string" && e.length > 0;
186
+ }
187
+ const ue = [
188
+ "sources.ts",
189
+ "fields.ts",
190
+ "inputs.ts",
191
+ "queries.ts",
192
+ "bindings.ts",
193
+ "accessors.ts",
194
+ "metadata.ts",
195
+ "index.ts"
196
+ ], ze = [
197
+ ...ue,
198
+ "contract.manifest.json"
199
+ ];
200
+ function Je(e) {
201
+ const t = d(e), n = C(t), r = [], s = [];
202
+ return R(t == null ? void 0 : t.views).filter((a) => {
203
+ var o;
204
+ const i = d((o = d(a)) == null ? void 0 : o.sdkSpec);
205
+ return !!(i != null && i.builder && (i != null && i.spec));
206
+ }).forEach((a, i) => {
207
+ var u;
208
+ const o = String(((u = d(a)) == null ? void 0 : u.id) || `view_${i}`), c = fe(
209
+ a,
210
+ n
211
+ );
212
+ if (c) {
213
+ r.push({ viewId: o, ...c });
214
+ return;
215
+ }
216
+ s.push({
217
+ viewId: o,
218
+ path: `views.${o}.sdkSpec`,
219
+ message: `Generated view execution validation could not build intent for "${o}".`
220
+ });
221
+ }), { requests: r, issues: s };
222
+ }
223
+ function fe(e, t) {
224
+ const n = d(e), r = d(n == null ? void 0 : n.sdkSpec), s = d(r == null ? void 0 : r.spec);
225
+ if (!n || !(r != null && r.builder) || !s)
226
+ return null;
227
+ const a = ge(t) ? t : C(d(t)), i = Ee(r.builder), o = d(A(s, a)) || {}, c = me({
228
+ view: n,
229
+ builder: i,
230
+ rawSpec: s,
231
+ spec: {
232
+ ...o,
233
+ id: n.id,
234
+ label: Ve(n, s)
235
+ },
236
+ context: a
237
+ });
238
+ try {
239
+ if (i === "analysis") {
240
+ const u = c;
241
+ return {
242
+ intent: te(u),
243
+ resultShape: "analysis",
244
+ analysisOptions: ee(u)
245
+ };
246
+ }
247
+ if (i === "metric")
248
+ return {
249
+ intent: re(c),
250
+ resultShape: "metric"
251
+ };
252
+ if (i === "records")
253
+ return {
254
+ intent: ne(c),
255
+ resultShape: "records"
256
+ };
257
+ if (i === "matrix")
258
+ return {
259
+ intent: ae(c),
260
+ resultShape: "matrix"
261
+ };
262
+ if (i === "sql")
263
+ return {
264
+ intent: se(c),
265
+ resultShape: "sql"
266
+ };
267
+ } catch {
268
+ return null;
269
+ }
270
+ return null;
271
+ }
272
+ function Ue({
273
+ input: e,
274
+ filterContract: t,
275
+ codegenSummary: n
276
+ }) {
277
+ const r = d(e), s = d(t), a = d(r == null ? void 0 : r.optionQuery) || d(s == null ? void 0 : s.optionQuery);
278
+ if (!r || !a)
279
+ return null;
280
+ const i = C(d(n)), o = d(a.spec), c = pe(a, o, i), u = a.valueFieldRef || a.valueField || (o == null ? void 0 : o.valueField), f = a.labelFieldRef || a.labelField || (o == null ? void 0 : o.labelField);
281
+ if (!c || !u || !f)
282
+ return null;
283
+ const l = {
284
+ ...d(
285
+ A(o || {}, i)
286
+ ) || {},
287
+ id: a.id || (o == null ? void 0 : o.id) || `${r.id}-options`,
288
+ inputId: r.id,
289
+ source: c,
290
+ valueField: u,
291
+ labelField: f,
292
+ population: a.population || (o == null ? void 0 : o.population),
293
+ dependencies: a.dependencies || (o == null ? void 0 : o.dependencies),
294
+ limit: a.limit || (o == null ? void 0 : o.limit) || 100
295
+ };
296
+ try {
297
+ return Z(
298
+ A(l, i)
299
+ );
300
+ } catch {
301
+ return null;
302
+ }
303
+ }
304
+ function Ye({
305
+ input: e,
306
+ filterContract: t,
307
+ binding: n,
308
+ option: r,
309
+ codegenSummary: s
310
+ }) {
311
+ const a = C(d(s)), i = d(e), o = d(t), c = d(n), u = A(
312
+ (c == null ? void 0 : c.fieldRef) || (o == null ? void 0 : o.fieldRef) || (i == null ? void 0 : i.fieldRef),
313
+ a
314
+ ), f = String(
315
+ (o == null ? void 0 : o.operator) || (i == null ? void 0 : i.operator) || "in"
316
+ ), g = Oe(c);
317
+ return {
318
+ inputId: String((o == null ? void 0 : o.inputId) || (i == null ? void 0 : i.id) || ""),
319
+ kind: "filter",
320
+ operator: f,
321
+ value: be(f, r.value),
322
+ isActive: !0,
323
+ ...u ? { field: u } : {},
324
+ ...g ? { relationshipHint: g } : {}
325
+ };
326
+ }
327
+ function C(e) {
328
+ return {
329
+ sourcesByKey: new Map(
330
+ R(e == null ? void 0 : e.sources).map(d).filter(Fe).filter((t) => typeof t.sourceKey == "string").map((t) => [String(t.sourceKey), J(t)])
331
+ )
332
+ };
333
+ }
334
+ function ge(e) {
335
+ var t;
336
+ return e instanceof Object && ((t = d(e)) == null ? void 0 : t.sourcesByKey) instanceof Map;
337
+ }
338
+ function pe(e, t, n) {
339
+ if (typeof e.sourceKey == "string")
340
+ return n.sourcesByKey.get(e.sourceKey) || { sourceKey: e.sourceKey };
341
+ if (e.source)
342
+ return e.source;
343
+ if (t != null && t.source)
344
+ return t.source;
345
+ if (typeof (t == null ? void 0 : t.sourceKey) == "string")
346
+ return n.sourcesByKey.get(t.sourceKey) || { sourceKey: t.sourceKey };
347
+ }
348
+ function me({
349
+ view: e,
350
+ builder: t,
351
+ rawSpec: n,
352
+ spec: r,
353
+ context: s
354
+ }) {
355
+ var o;
356
+ if (t !== "records" && t !== "sql")
357
+ return r;
358
+ const a = d((o = d(e.visualSpec)) == null ? void 0 : o.tableBehavior);
359
+ if (!a)
360
+ return r;
361
+ const i = { ...r };
362
+ if (ve(a) === "server" && (i.pagination = {
363
+ page: 1,
364
+ pageSize: le({ tableBehavior: a, spec: r })
365
+ }), t === "records" && Ce(a) === "server") {
366
+ const c = he({
367
+ view: e,
368
+ rawSpec: n,
369
+ tableBehavior: a,
370
+ context: s
371
+ });
372
+ c && (i.orderBy = c);
373
+ }
374
+ return i;
375
+ }
376
+ function le({
377
+ tableBehavior: e,
378
+ spec: t
379
+ }) {
380
+ const n = d(e.pagination), r = d(t.pagination);
381
+ return O(n == null ? void 0 : n.pageSize) || O(r == null ? void 0 : r.pageSize) || O(t.limit) || 100;
382
+ }
383
+ function he({
384
+ view: e,
385
+ rawSpec: t,
386
+ tableBehavior: n,
387
+ context: r
388
+ }) {
389
+ const s = d(n.sorting), a = p(s == null ? void 0 : s.defaultField);
390
+ if (!a)
391
+ return;
392
+ const o = ye({
393
+ view: e,
394
+ rawSpec: t,
395
+ context: r
396
+ }).filter(
397
+ (c) => Se(c.lookup).includes(a)
398
+ );
399
+ if (o.length === 1)
400
+ return {
401
+ field: o[0].field,
402
+ direction: (s == null ? void 0 : s.defaultDirection) === "desc" ? "desc" : "asc"
403
+ };
404
+ }
405
+ function ye({
406
+ view: e,
407
+ rawSpec: t,
408
+ context: n
409
+ }) {
410
+ var s;
411
+ const r = [];
412
+ for (const a of R(t.fields)) I(r, a, n);
413
+ I(r, t.dateField, n), I(r, (s = d(t.orderBy)) == null ? void 0 : s.field, n);
414
+ for (const a of R(e.fields))
415
+ I(r, a, n);
416
+ return Ne(
417
+ r,
418
+ (a) => we(a.lookup)
419
+ );
420
+ }
421
+ function I(e, t, n) {
422
+ const r = d(t);
423
+ if (typeof (r == null ? void 0 : r.name) != "string" || r.name.length === 0)
424
+ return;
425
+ const s = d(A(r, n)) || r;
426
+ e.push({
427
+ lookup: r,
428
+ field: s
429
+ });
430
+ }
431
+ function Se(e) {
432
+ return He([
433
+ p(e.name),
434
+ z(e),
435
+ _e(e)
436
+ ]);
437
+ }
438
+ function we(e) {
439
+ return [
440
+ z(e),
441
+ p(e.name),
442
+ p(e.role),
443
+ p(e.aggregate)
444
+ ].join("|");
445
+ }
446
+ function z(e) {
447
+ return [
448
+ p(e.sourceKey) || Ae(e.source),
449
+ p(e.name),
450
+ p(e.aggregate)
451
+ ].filter(Boolean).join(":");
452
+ }
453
+ function Ae(e) {
454
+ const t = d(e);
455
+ if (!t)
456
+ return "";
457
+ if (typeof t.kind == "string" && typeof t.domainId == "string") {
458
+ if (typeof t.datasetId == "string")
459
+ return `${t.kind}:${t.domainId}:datasetId:${t.datasetId}`;
460
+ if (typeof t.datasetName == "string")
461
+ return `${t.kind}:${t.domainId}:datasetName:${t.datasetName}`;
462
+ }
463
+ return JSON.stringify(t);
464
+ }
465
+ function _e(e) {
466
+ return ke([
467
+ $e(e),
468
+ p(e.aggregate).toLowerCase(),
469
+ p(e.label) || p(e.name)
470
+ ].filter(Boolean));
471
+ }
472
+ function $e(e) {
473
+ return typeof e.sourceKey == "string" ? Ie(e.sourceKey) : Re(e.source);
474
+ }
475
+ function Re(e) {
476
+ const t = d(e);
477
+ return t ? p(t.datasetName) || p(t.datasetId) || p(t.name) || p(t.kind) : "";
478
+ }
479
+ function Ie(e) {
480
+ const t = String(e).split(":");
481
+ return t[t.length - 1] || String(e);
482
+ }
483
+ function ve(e) {
484
+ var t;
485
+ return p((t = d(e.pagination)) == null ? void 0 : t.mode);
486
+ }
487
+ function Ce(e) {
488
+ var t;
489
+ return p((t = d(e.sorting)) == null ? void 0 : t.mode);
490
+ }
491
+ function A(e, t) {
492
+ if (!e || typeof e != "object")
493
+ return e;
494
+ if (Array.isArray(e))
495
+ return e.map((s) => A(s, t));
496
+ const n = e;
497
+ if (typeof n.sourceKey == "string" && typeof n.kind == "string" && (typeof n.datasetName == "string" || typeof n.datasetId == "string"))
498
+ return J(n);
499
+ const r = {};
500
+ for (const [s, a] of Object.entries(n))
501
+ s !== "sourceKey" && (r[s] = A(a, t));
502
+ if (typeof n.sourceKey == "string") {
503
+ const s = t.sourcesByKey.get(n.sourceKey);
504
+ s && !r.source && (r.source = s);
505
+ }
506
+ return r;
507
+ }
508
+ function J(e) {
509
+ const { sourceKey: t, ...n } = e;
510
+ return n;
511
+ }
512
+ function Ve(e, t) {
513
+ const n = d(e.visualSpec);
514
+ return (n == null ? void 0 : n.title) || e.title || t.label;
515
+ }
516
+ function Ee(e) {
517
+ const t = String(e || "").replace(/^semaphor\./, "");
518
+ return ["metric", "records", "analysis", "matrix", "sql"].includes(t) ? t : "";
519
+ }
520
+ function Oe(e) {
521
+ if (e != null && e.relationshipHint)
522
+ return e.relationshipHint;
523
+ const t = R(e == null ? void 0 : e.relationshipsUsed).map((n) => {
524
+ var r;
525
+ return (r = d(n)) == null ? void 0 : r.id;
526
+ }).filter((n) => typeof n == "string" && n.length > 0);
527
+ return t.length > 0 ? { relationshipIds: t } : void 0;
528
+ }
529
+ function be(e, t) {
530
+ return e === "in" || e === "not_in" ? [t] : e === "between" ? Array.isArray(t) ? t : [t, t] : t;
531
+ }
532
+ function O(e) {
533
+ return typeof e == "number" && Number.isFinite(e) ? e : void 0;
534
+ }
535
+ function p(e) {
536
+ return typeof e == "string" ? e : "";
537
+ }
538
+ function Ne(e, t) {
539
+ const n = /* @__PURE__ */ new Set(), r = [];
540
+ for (const s of e) {
541
+ const a = t(s);
542
+ !a || n.has(a) || (n.add(a), r.push(s));
543
+ }
544
+ return r;
545
+ }
546
+ function He(e) {
547
+ return Array.from(new Set(e.filter(Boolean)));
548
+ }
549
+ function ke(e) {
550
+ return (Array.isArray(e) ? e.join(" ") : e).replace(/[^a-zA-Z0-9]+/g, " ").trim().split(/\s+/).filter(Boolean).map((n, r) => {
551
+ const s = n.toLowerCase();
552
+ return r === 0 ? s : s.charAt(0).toUpperCase() + s.slice(1);
553
+ }).join("");
554
+ }
555
+ function d(e) {
556
+ return e && typeof e == "object" && !Array.isArray(e) ? e : void 0;
557
+ }
558
+ function R(e) {
559
+ return Array.isArray(e) ? e : [];
560
+ }
561
+ function Fe(e) {
562
+ return e !== void 0;
563
+ }
564
+ const je = /* @__PURE__ */ new Set([
565
+ "diagnostic_fix",
566
+ "fix_diagnostics",
567
+ "fix_inspector_warnings",
568
+ "fix_runtime_warnings",
569
+ "fix_warnings"
570
+ ]), T = /* @__PURE__ */ new Set([
571
+ "fields",
572
+ "sdkSpec"
573
+ ]);
574
+ function We({
575
+ beforeSummary: e,
576
+ afterSummary: t,
577
+ migrationReport: n,
578
+ operationIntent: r,
579
+ preferences: s
580
+ }) {
581
+ const a = m(r), i = typeof (a == null ? void 0 : a.kind) == "string" ? a.kind.trim() : "add";
582
+ return Ke(s) ? {
583
+ ok: !1,
584
+ policy: {
585
+ kind: i,
586
+ mode: "invalid_update_preferences",
587
+ reason: "Metric aggregate override updates must use operationIntent.measureAggregateOverrides so deterministic update policy can guard the targeted edit."
588
+ },
589
+ violations: [
590
+ {
591
+ path: "preferences.measureAggregateOverrides",
592
+ reason: "Move measureAggregateOverrides to operationIntent.measureAggregateOverrides for update calls."
593
+ }
594
+ ]
595
+ } : je.has(i) ? D({
596
+ beforeSummary: e,
597
+ afterSummary: t,
598
+ migrationReport: n,
599
+ operationIntent: a,
600
+ mode: "diagnostic_warning_fix",
601
+ allowedViewChangeReasons: T,
602
+ label: "Diagnostic warning fixes",
603
+ reason: "Diagnostic warning fixes are preserve-by-default and may not add/remove views, inputs, or filter contracts."
604
+ }) : i === "edit" && Array.isArray(a == null ? void 0 : a.measureAggregateOverrides) && a.measureAggregateOverrides.length > 0 ? D({
605
+ beforeSummary: e,
606
+ afterSummary: t,
607
+ migrationReport: n,
608
+ operationIntent: a,
609
+ mode: "metric_aggregate_override_edit",
610
+ allowedViewChangeReasons: T,
611
+ label: "Metric aggregate override edits",
612
+ reason: "Metric aggregate override edits are preserve-by-default and may only adjust fields/sdkSpec on targeted views."
613
+ }) : {
614
+ ok: !0,
615
+ policy: {
616
+ kind: i,
617
+ mode: "general_iterative_update",
618
+ reason: "General generated-contract edits are allowed to change the requested contract shape. Review the migration report for expected UI work."
619
+ },
620
+ violations: []
621
+ };
622
+ }
623
+ function Ke(e) {
624
+ var t;
625
+ return Array.isArray((t = m(e)) == null ? void 0 : t.measureAggregateOverrides);
626
+ }
627
+ function D({
628
+ beforeSummary: e,
629
+ afterSummary: t,
630
+ migrationReport: n,
631
+ operationIntent: r,
632
+ mode: s,
633
+ allowedViewChangeReasons: a,
634
+ label: i,
635
+ reason: o
636
+ }) {
637
+ const c = [], u = xe(r == null ? void 0 : r.targetViewIds), f = m(n) || {};
638
+ u.size === 0 && c.push({
639
+ path: "operationIntent.targetViewIds",
640
+ reason: `${i} must declare targetViewIds so the update cannot broaden to unrelated views.`
641
+ }), b({
642
+ bucket: m(f.views),
643
+ label: "views",
644
+ operationLabel: i,
645
+ violations: c
646
+ }), b({
647
+ bucket: m(f.inputs),
648
+ label: "inputs",
649
+ operationLabel: i,
650
+ violations: c
651
+ }), q({
652
+ bucket: m(f.inputs),
653
+ label: "inputs",
654
+ operationLabel: i,
655
+ violations: c
656
+ }), b({
657
+ bucket: m(f.filterContracts),
658
+ label: "filterContracts",
659
+ operationLabel: i,
660
+ violations: c
661
+ }), q({
662
+ bucket: m(f.filterContracts),
663
+ label: "filterContracts",
664
+ operationLabel: i,
665
+ violations: c
666
+ });
667
+ for (const l of U(m(f.views))) {
668
+ u.size > 0 && !u.has(w(l.id)) && c.push({
669
+ path: `views.${w(l.id) || "<unknown>"}`,
670
+ reason: `${i} may only change explicitly targeted views.`
671
+ });
672
+ const h = Array.isArray(l.reasons) ? l.reasons.filter(
673
+ ($) => typeof $ != "string" || !a.has($)
674
+ ) : [];
675
+ h.length > 0 && c.push({
676
+ path: `views.${w(l.id) || "<unknown>"}`,
677
+ reason: `${i} may only adjust fields/sdkSpec; changed ${h.join(", ")}.`
678
+ });
679
+ }
680
+ const g = Me({
681
+ beforeSummary: e,
682
+ afterSummary: t,
683
+ targetViewIds: u,
684
+ label: i
685
+ });
686
+ return g && c.push(g), {
687
+ ok: c.length === 0,
688
+ policy: {
689
+ kind: w(r == null ? void 0 : r.kind) || "diagnostic_fix",
690
+ mode: s,
691
+ allowedViewChangeReasons: Array.from(a).sort(),
692
+ targetViewIds: Array.from(u).sort(),
693
+ reason: o
694
+ },
695
+ violations: c
696
+ };
697
+ }
698
+ function Me({
699
+ beforeSummary: e,
700
+ afterSummary: t,
701
+ targetViewIds: n,
702
+ label: r
703
+ }) {
704
+ const s = m(e), a = m(t);
705
+ if (!s || !a)
706
+ return {
707
+ path: "codegenSummary",
708
+ reason: `${r} require before/after codegen summaries for full-scope verification.`
709
+ };
710
+ const i = G(s), o = G(a), c = B(s.views), u = B(a.views), f = Array.isArray(i.views) ? i.views : [];
711
+ i.views = f;
712
+ for (const g of n) {
713
+ const l = c.get(g), h = u.get(g);
714
+ if (!l || !h)
715
+ continue;
716
+ const $ = f.find(
717
+ (Y) => {
718
+ var j;
719
+ return ((j = m(Y)) == null ? void 0 : j.id) === g;
720
+ }
721
+ ), V = m(h);
722
+ if (!$ || !V)
723
+ continue;
724
+ const F = $;
725
+ F.fields = k(V.fields), F.sdkSpec = k(V.sdkSpec);
726
+ }
727
+ return v(i) === v(o) ? null : {
728
+ path: "codegenSummary",
729
+ reason: `${r} may only change fields/sdkSpec on targetViewIds; another generated contract section changed.`
730
+ };
731
+ }
732
+ function G(e) {
733
+ const t = k(e);
734
+ for (const n of [
735
+ "implementationChecklist",
736
+ "assumptions",
737
+ "nextStep",
738
+ "nextRequiredTool",
739
+ "validation"
740
+ ])
741
+ delete t[n];
742
+ return De(t.unsupportedInsights) && delete t.unsupportedInsights, t;
743
+ }
744
+ function b({
745
+ bucket: e,
746
+ label: t,
747
+ operationLabel: n,
748
+ violations: r
749
+ }) {
750
+ for (const s of H(e == null ? void 0 : e.added))
751
+ r.push({
752
+ path: `${t}.${w(s.id) || "<unknown>"}`,
753
+ reason: `${n} may not add ${t}.`
754
+ });
755
+ for (const s of H(e == null ? void 0 : e.removed))
756
+ r.push({
757
+ path: `${t}.${w(s.id) || "<unknown>"}`,
758
+ reason: `${n} may not remove ${t}.`
759
+ });
760
+ }
761
+ function q({
762
+ bucket: e,
763
+ label: t,
764
+ operationLabel: n,
765
+ violations: r
766
+ }) {
767
+ for (const s of U(e))
768
+ r.push({
769
+ path: `${t}.${w(s.id) || "<unknown>"}`,
770
+ reason: `${n} may not change ${t}.`
771
+ });
772
+ }
773
+ function U(e) {
774
+ return H(e == null ? void 0 : e.changed);
775
+ }
776
+ function H(e) {
777
+ return Array.isArray(e) ? e.map(m).filter(Te) : [];
778
+ }
779
+ function xe(e) {
780
+ return Array.isArray(e) ? new Set(
781
+ e.filter((t) => typeof t == "string" && t.trim().length > 0).map((t) => t.trim())
782
+ ) : /* @__PURE__ */ new Set();
783
+ }
784
+ function B(e) {
785
+ var n;
786
+ const t = /* @__PURE__ */ new Map();
787
+ for (const r of Array.isArray(e) ? e : []) {
788
+ const s = (n = m(r)) == null ? void 0 : n.id;
789
+ typeof s == "string" && s.trim() && t.set(s, r);
790
+ }
791
+ return t;
792
+ }
793
+ function k(e) {
794
+ return e === void 0 ? e : JSON.parse(JSON.stringify(e));
795
+ }
796
+ function v(e) {
797
+ if (e === null || typeof e != "object")
798
+ return JSON.stringify(e);
799
+ if (Array.isArray(e))
800
+ return `[${e.map((n) => v(n)).join(",")}]`;
801
+ const t = e;
802
+ return `{${Object.keys(t).sort().filter((n) => t[n] !== void 0).map((n) => `${JSON.stringify(n)}:${v(t[n])}`).join(",")}}`;
803
+ }
804
+ function m(e) {
805
+ return e && typeof e == "object" && !Array.isArray(e) ? e : void 0;
806
+ }
807
+ function Te(e) {
808
+ return e !== void 0;
809
+ }
810
+ function De(e) {
811
+ return Array.isArray(e) && e.length === 0;
812
+ }
813
+ function w(e) {
814
+ return typeof e == "string" ? e : "";
815
+ }
816
+ export {
817
+ Be as C,
818
+ M as G,
819
+ ze as R,
820
+ K as a,
821
+ x as b,
822
+ Le as c,
823
+ Pe as d,
824
+ ue as e,
825
+ Ye as f,
826
+ Ue as g,
827
+ fe as h,
828
+ Je as i,
829
+ We as j,
830
+ L as v
831
+ };