react-semaphor 0.1.420 → 0.1.422

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 (58) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +28 -27
  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-D7pjjYPy.js +2069 -0
  6. package/dist/chunks/analyze-result-contract-DpDcImgk.js +1 -0
  7. package/dist/chunks/{calendar-preferences-dialog-f0Z7Kf-U.js → calendar-preferences-dialog-C2fBRNZh.js} +1 -1
  8. package/dist/chunks/{calendar-preferences-dialog-DIfAbE_y.js → calendar-preferences-dialog-Cbavs2EK.js} +3 -3
  9. package/dist/chunks/{dashboard-briefing-launcher-anh-Jy5v.js → dashboard-briefing-launcher-C0_ZbBK3.js} +4 -4
  10. package/dist/chunks/{dashboard-briefing-launcher-C3tNkGFG.js → dashboard-briefing-launcher-CGfEFUnX.js} +1 -1
  11. package/dist/chunks/{dashboard-controls-DQxlOxzy.js → dashboard-controls-BUuS-BGl.js} +1 -1
  12. package/dist/chunks/{dashboard-controls-8dCQaPaq.js → dashboard-controls-ae5t32xV.js} +5 -5
  13. package/dist/chunks/{dashboard-json-B309EInF.js → dashboard-json-DTL_kYhz.js} +1 -1
  14. package/dist/chunks/{dashboard-json-i7Ae9KGD.js → dashboard-json-Db3rkY_a.js} +3 -3
  15. package/dist/chunks/{edit-dashboard-visual-z3IqzYnj.js → edit-dashboard-visual-CW7mv_si.js} +7030 -6963
  16. package/dist/chunks/{edit-dashboard-visual-4HycwBHR.js → edit-dashboard-visual-Ciqdu58a.js} +38 -38
  17. package/dist/chunks/{index-yxKWKFdr.js → index-8y8XX7sX.js} +121 -121
  18. package/dist/chunks/{index-B6DLEXRX.js → index-OD6mLD7U.js} +257 -256
  19. package/dist/chunks/{switch-COWQU8aK.js → switch-CWcWwwDJ.js} +1 -1
  20. package/dist/chunks/{switch-D6Ygf3wA.js → switch-DRNqX0v0.js} +1 -1
  21. package/dist/chunks/{update-policy-BzT2k4n6.js → update-policy-BCJc0oI5.js} +211 -187
  22. package/dist/chunks/update-policy-C1pmhLz9.js +3 -0
  23. package/dist/chunks/{use-create-flow-overlay-state-DENfd7sW.js → use-create-flow-overlay-state-C0Uhmlpd.js} +1 -1
  24. package/dist/chunks/{use-create-flow-overlay-state-CX0D-6HM.js → use-create-flow-overlay-state-CkMmXhI-.js} +3 -3
  25. package/dist/chunks/validators-DMlVbd1p.js +1 -0
  26. package/dist/chunks/{validators-Cxr9qbrR.js → validators-PXkij33j.js} +93 -93
  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 +14 -14
  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 -1
  34. package/dist/data-app-codegen/index.js +2 -2
  35. package/dist/data-app-codegen-node/index.cjs +188 -251
  36. package/dist/data-app-codegen-node/index.js +631 -673
  37. package/dist/data-app-sdk/index.cjs +2 -2
  38. package/dist/data-app-sdk/index.js +678 -638
  39. package/dist/data-app-sdk-adapters/index.cjs +1 -1
  40. package/dist/data-app-sdk-adapters/index.js +51 -51
  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/style.css +1 -1
  46. package/dist/surfboard/index.cjs +1 -1
  47. package/dist/surfboard/index.js +2 -2
  48. package/dist/types/analytics-protocol.d.ts +12 -9
  49. package/dist/types/dashboard-assistant.d.ts +0 -6
  50. package/dist/types/data-app-codegen-node.d.ts +12 -2
  51. package/dist/types/data-app-codegen.d.ts +12 -2
  52. package/dist/types/data-app-sdk-validation.d.ts +0 -6
  53. package/dist/types/data-app-sdk.d.ts +17 -7
  54. package/package.json +1 -1
  55. package/dist/chunks/analyze-result-contract-DdhEt99q.js +0 -2004
  56. package/dist/chunks/analyze-result-contract-DwRzl7yJ.js +0 -1
  57. package/dist/chunks/update-policy-VloD-0YM.js +0 -3
  58. package/dist/chunks/validators-BMQo93Y0.js +0 -1
@@ -1,18 +1,18 @@
1
- import { S as In, a as Fn, i as bn, v as Vn } from "../chunks/analyze-result-contract-DdhEt99q.js";
2
- import { c as ke, G as fe, a as Re, b as Me } from "../chunks/update-policy-BzT2k4n6.js";
3
- import { C as Rn, e as Mn, R as xn, f as Nn, g as Cn, h as On, i as Gn, j as Kn, v as En, d as An } from "../chunks/update-policy-BzT2k4n6.js";
1
+ import { S as Vn, a as Fn, i as bn, v as kn } from "../chunks/analyze-result-contract-D7pjjYPy.js";
2
+ import { c as ke, G as fe, a as Re, b as Me } from "../chunks/update-policy-BCJc0oI5.js";
3
+ import { C as Mn, e as Cn, R as On, f as xn, g as Gn, h as Nn, i as En, j as An, v as jn, d as vn } from "../chunks/update-policy-BCJc0oI5.js";
4
4
  import { createHash as ye } from "node:crypto";
5
- const hn = "src/semaphor/generated", H = `// Generated by Semaphor Agent Plugin. Do not hand-edit analytics wiring here.
5
+ const wn = "src/semaphor/generated", v = `// Generated by Semaphor Agent Plugin. Do not hand-edit analytics wiring here.
6
6
  // Regenerate from the accepted semaphor_plan_data_app codegenSummary when the plan changes.
7
7
  `;
8
- function wn(e, n = {}) {
8
+ function Sn(e, n = {}) {
9
9
  ke(e);
10
- const r = xe(e);
10
+ const r = Ce(e);
11
11
  if (r.views.length === 0 && !n.allowEmpty)
12
12
  throw new Error(
13
13
  "Contract generation produced zero executable views. Stop and ask for a different domain/goal or semantic model improvement; pass --allow-empty only for an explicit model-gap report."
14
14
  );
15
- const t = Ce(r), o = Oe({
15
+ const t = xe(r), o = Ge({
16
16
  contract: r,
17
17
  files: t,
18
18
  generatorName: n.generatorName || "react-semaphor/data-app-codegen/node",
@@ -27,7 +27,7 @@ function wn(e, n = {}) {
27
27
  files: a,
28
28
  manifest: o,
29
29
  contentHash: String(o.generatedContentHash || ""),
30
- usageExample: Ee(r),
30
+ usageExample: je(r),
31
31
  warnings: r.warnings,
32
32
  stats: {
33
33
  inputCount: r.inputs.length,
@@ -38,32 +38,32 @@ function wn(e, n = {}) {
38
38
  }
39
39
  };
40
40
  }
41
- function xe(e) {
42
- var u, d, c, i, p, S, g, $, F, R, b, M;
41
+ function Ce(e) {
42
+ var d, p, m, i, l, g, h, I, $, M, b, C;
43
43
  const n = [], r = [];
44
44
  for (const s of e.inputs) {
45
- h(r, s.fieldRef);
46
- for (const I of s.bindings || [])
47
- h(r, I.fieldRef);
48
- h(r, (u = s.optionQuery) == null ? void 0 : u.valueFieldRef), h(r, (d = s.optionQuery) == null ? void 0 : d.labelFieldRef), h(r, (c = s.optionQuery) == null ? void 0 : c.filterFieldRef), Q(r, (i = s.optionQuery) == null ? void 0 : i.spec);
45
+ w(r, s.fieldRef);
46
+ for (const V of s.bindings || [])
47
+ w(r, V.fieldRef);
48
+ w(r, (d = s.optionQuery) == null ? void 0 : d.valueFieldRef), w(r, (p = s.optionQuery) == null ? void 0 : p.labelFieldRef), w(r, (m = s.optionQuery) == null ? void 0 : m.filterFieldRef), B(r, (i = s.optionQuery) == null ? void 0 : i.spec);
49
49
  }
50
50
  for (const s of e.filterContracts) {
51
- h(r, s.fieldRef), h(r, (p = s.optionQuery) == null ? void 0 : p.valueFieldRef), h(r, (S = s.optionQuery) == null ? void 0 : S.labelFieldRef), h(r, (g = s.optionQuery) == null ? void 0 : g.filterFieldRef), Q(r, ($ = s.optionQuery) == null ? void 0 : $.spec);
52
- for (const I of s.bindings || [])
53
- h(r, I.fieldRef);
51
+ w(r, s.fieldRef), w(r, (l = s.optionQuery) == null ? void 0 : l.valueFieldRef), w(r, (g = s.optionQuery) == null ? void 0 : g.labelFieldRef), w(r, (h = s.optionQuery) == null ? void 0 : h.filterFieldRef), B(r, (I = s.optionQuery) == null ? void 0 : I.spec);
52
+ for (const V of s.bindings || [])
53
+ w(r, V.fieldRef);
54
54
  }
55
55
  for (const s of e.views) {
56
- for (const I of s.fields || [])
57
- h(r, I);
58
- Q(r, (F = s.sdkSpec) == null ? void 0 : F.spec), Q(r, s.visualSpec);
56
+ for (const V of s.fields || [])
57
+ w(r, V);
58
+ B(r, ($ = s.sdkSpec) == null ? void 0 : $.spec), B(r, s.visualSpec);
59
59
  }
60
60
  const t = e.implementationChecklist || {};
61
61
  for (const s of Object.values(t.bindingsByView || {}))
62
- for (const I of Array.isArray(s) ? s : [])
63
- h(r, I.fieldRef), h(r, I.optionValueField), h(r, I.optionLabelField);
62
+ for (const V of Array.isArray(s) ? s : [])
63
+ w(r, V.fieldRef), w(r, V.optionValueField), w(r, V.optionLabelField);
64
64
  for (const s of t.requiredInputOptions || [])
65
- h(r, s.visibleLabelField), h(r, s.optionValueField), h(r, s.runtimeFilterField);
66
- const o = dn(
65
+ w(r, s.visibleLabelField), w(r, s.optionValueField), w(r, s.runtimeFilterField);
66
+ const o = pn(
67
67
  [
68
68
  ...e.sources.map((s) => ({
69
69
  raw: s,
@@ -71,128 +71,129 @@ function xe(e) {
71
71
  aliases: Ie(s),
72
72
  name: ""
73
73
  })),
74
- ...r.map((s) => sn(s)).filter(K)
74
+ ...r.map((s) => an(s)).filter(E)
75
75
  ]
76
76
  );
77
- v(o, (s) => {
78
- const I = V(s.raw);
79
- return q(
80
- s.raw.label || (I == null ? void 0 : I.datasetName) || (I == null ? void 0 : I.datasetId) || (I == null ? void 0 : I.name) || s.raw.kind || "source"
77
+ P(o, (s) => {
78
+ const V = F(s.raw);
79
+ return K(
80
+ s.raw.label || (V == null ? void 0 : V.datasetName) || (V == null ? void 0 : V.datasetId) || (V == null ? void 0 : V.name) || s.raw.kind || "source"
81
81
  );
82
82
  });
83
- const a = pn(o), l = X(
83
+ const a = ln(o), u = X(
84
84
  r.filter((s) => s.name).map((s) => ({
85
85
  raw: s,
86
- key: L(s),
86
+ key: Z(s),
87
87
  name: ""
88
88
  })),
89
89
  (s) => s.key
90
90
  );
91
- v(
92
- l,
93
- (s) => q([
94
- s.raw.sourceKey ? fn(s.raw.sourceKey) : "",
91
+ P(
92
+ u,
93
+ (s) => K([
94
+ s.raw.sourceKey ? yn(s.raw.sourceKey) : "",
95
95
  s.raw.aggregate ? s.raw.aggregate.toLowerCase() : "",
96
96
  s.raw.name
97
97
  ].filter(Boolean).join("_"))
98
98
  );
99
- const y = new Map(l.map((s) => [s.key, s.name])), w = e.inputs.map((s) => ({
99
+ const c = new Map(u.map((s) => [s.key, s.name])), S = e.inputs.map((s) => ({
100
100
  raw: s,
101
- name: q(s.id || s.label || "input")
101
+ name: K(s.id || s.label || "input")
102
102
  }));
103
- v(w, (s) => s.name);
104
- const f = w.filter((s) => !!s.raw.optionQuery).map((s) => ({
103
+ P(S, (s) => s.name);
104
+ const f = S.filter((s) => !!s.raw.optionQuery).map((s) => ({
105
105
  input: s,
106
106
  name: `${s.name}Options`,
107
107
  raw: s.raw.optionQuery
108
108
  }));
109
- v(f, (s) => s.name);
109
+ P(f, (s) => s.name);
110
110
  for (const s of f)
111
- an(s.raw.labelFieldRef, s.raw.valueFieldRef) && un(s.raw.valueFieldRef) && n.push(
112
- `Input option query ${((R = s.raw.spec) == null ? void 0 : R.inputId) || s.input.raw.id || s.name} uses identifier field ${s.raw.valueFieldRef.name} as both label and value. It can execute, but the UI will show key values unless the semantic model exposes a human-readable label through a modeled relationship.`
111
+ un(s.raw.labelFieldRef, s.raw.valueFieldRef) && dn(s.raw.valueFieldRef) && n.push(
112
+ `Input option query ${((M = s.raw.spec) == null ? void 0 : M.inputId) || s.input.raw.id || s.name} uses identifier field ${s.raw.valueFieldRef.name} as both label and value. It can execute, but the UI will show key values unless the semantic model exposes a human-readable label through a modeled relationship.`
113
113
  );
114
- const m = e.views.filter(
114
+ const y = e.views.filter(
115
115
  (s) => {
116
- var I, T;
117
- return !!((I = s.sdkSpec) != null && I.builder && ((T = s.sdkSpec) != null && T.spec));
116
+ var V, T;
117
+ return !!((V = s.sdkSpec) != null && V.builder && ((T = s.sdkSpec) != null && T.spec));
118
118
  }
119
119
  ).map((s) => ({
120
120
  raw: s,
121
- name: q(s.id || s.title || "query")
121
+ name: K(s.id || s.title || "query")
122
122
  }));
123
- v(m, (s) => s.name);
124
- const N = e.views.filter((s) => ce(s) && !("sdkSpec" in s)).map((s) => on(s));
123
+ P(y, (s) => s.name);
124
+ const O = e.views.filter((s) => ce(s) && !("sdkSpec" in s)).map((s) => sn(s));
125
125
  for (const s of e.views)
126
- (!("sdkSpec" in s) || !((b = s.sdkSpec) != null && b.builder) || !((M = s.sdkSpec) != null && M.spec)) && !ce(s) && n.push(`Skipped view ${s.id || s.title || "unknown"} because it has no sdkSpec.`);
127
- return Ne({
128
- inputs: w,
129
- views: m,
126
+ (!("sdkSpec" in s) || !((b = s.sdkSpec) != null && b.builder) || !((C = s.sdkSpec) != null && C.spec)) && !ce(s) && n.push(`Skipped view ${s.id || s.title || "unknown"} because it has no sdkSpec.`);
127
+ return Oe({
128
+ inputs: S,
129
+ views: y,
130
130
  filterContracts: e.filterContracts
131
131
  }), {
132
132
  summary: e,
133
133
  title: e.title || "Semaphor Data App",
134
134
  sources: o,
135
- fields: l,
136
- inputs: w,
135
+ fields: u,
136
+ inputs: S,
137
137
  optionQueries: f,
138
- views: m,
139
- presentationViews: N,
138
+ views: y,
139
+ presentationViews: O,
140
140
  filterContracts: e.filterContracts,
141
141
  checklist: t,
142
142
  sourceNameByKey: a,
143
- fieldNameByKey: y,
143
+ fieldNameByKey: c,
144
144
  warnings: n
145
145
  };
146
146
  }
147
- function Ne({
147
+ function Oe({
148
148
  inputs: e,
149
149
  views: n,
150
150
  filterContracts: r
151
151
  }) {
152
152
  const t = new Set(e.map((a) => a.raw.id).filter(Boolean)), o = new Set(n.map((a) => a.raw.id).filter(Boolean));
153
- for (const [a, l] of r.entries()) {
154
- if (!t.has(l.inputId))
153
+ for (const [a, u] of r.entries()) {
154
+ if (!t.has(u.inputId))
155
155
  throw new Error(`filterContracts.${a}.inputId must reference a generated input.`);
156
- const y = new Set(l.appliesToViewIds || []), w = new Set(l.notAppliedToViewIds || []);
157
- for (const [f, m] of (l.appliesToViewIds || []).entries())
158
- if (!o.has(m))
156
+ const c = new Set(u.appliesToViewIds || []), S = new Set(u.notAppliedToViewIds || []);
157
+ for (const [f, y] of (u.appliesToViewIds || []).entries())
158
+ if (!o.has(y))
159
159
  throw new Error(
160
160
  `filterContracts.${a}.appliesToViewIds.${f} must reference an executable generated view.`
161
161
  );
162
- for (const [f, m] of (l.notAppliedToViewIds || []).entries())
163
- if (!o.has(m))
162
+ for (const [f, y] of (u.notAppliedToViewIds || []).entries())
163
+ if (!o.has(y))
164
164
  throw new Error(
165
165
  `filterContracts.${a}.notAppliedToViewIds.${f} must reference an executable generated view.`
166
166
  );
167
- for (const [f, m] of (l.bindings || []).entries()) {
168
- if (!o.has(m.viewId))
167
+ for (const [f, y] of (u.bindings || []).entries()) {
168
+ if (!o.has(y.viewId))
169
169
  throw new Error(
170
170
  `filterContracts.${a}.bindings.${f}.viewId must reference an executable generated view.`
171
171
  );
172
- if (!y.has(m.viewId))
172
+ if (!c.has(y.viewId))
173
173
  throw new Error(
174
174
  `filterContracts.${a}.bindings.${f}.viewId must be included in appliesToViewIds.`
175
175
  );
176
- if (w.has(m.viewId))
176
+ if (S.has(y.viewId))
177
177
  throw new Error(
178
178
  `filterContracts.${a}.bindings.${f}.viewId must not be listed in notAppliedToViewIds.`
179
179
  );
180
180
  }
181
181
  }
182
182
  }
183
- function Ce(e) {
183
+ function xe(e) {
184
184
  return {
185
- "sources.ts": ve(e),
186
- "fields.ts": qe(e),
187
- "inputs.ts": Te(e),
188
- "queries.ts": _e(e),
185
+ "sources.ts": Ke(e),
186
+ "fields.ts": Te(e),
187
+ "inputs.ts": Qe(e),
188
+ "queries.ts": De(e),
189
189
  "bindings.ts": Le(e),
190
- "accessors.ts": ze(e),
190
+ "accessors.ts": Ye(e),
191
191
  "metadata.ts": We(e),
192
- "index.ts": Ze()
192
+ "index.ts": Xe(),
193
+ "USAGE.md": Ee(e)
193
194
  };
194
195
  }
195
- function Oe({
196
+ function Ge({
196
197
  contract: e,
197
198
  files: n,
198
199
  generatorName: r,
@@ -205,19 +206,51 @@ function Oe({
205
206
  name: r,
206
207
  version: t
207
208
  },
208
- generatedContentHash: Ge(n),
209
+ generatedContentHash: Ne(n),
209
210
  codegenSummaryValidatorVersion: Re,
210
- codegenSummaryHash: Ke(e.summary),
211
+ codegenSummaryHash: Ae(e.summary),
211
212
  codegenSummary: e.summary
212
213
  };
213
214
  }
214
- function Ge(e) {
215
+ function Ne(e) {
215
216
  const n = ye("sha256");
216
- for (const r of Object.keys(e).sort())
217
+ for (const r of Object.keys(e).filter(
218
+ (t) => t.endsWith(".ts")
219
+ ).sort())
217
220
  n.update(r), n.update("\0"), n.update(e[r]), n.update("\0");
218
221
  return `sha256:${n.digest("hex")}`;
219
222
  }
220
- function Ke(e) {
223
+ function Ee(e) {
224
+ const n = [
225
+ "# Semaphor Generated Data App Contract",
226
+ "",
227
+ "Generated files in this directory are governed Semaphor analytics wiring. Do not hand-edit them.",
228
+ "",
229
+ "Use the app-facing exports from `index.ts`:",
230
+ "",
231
+ "- `queries`: generated governed query factories.",
232
+ "- `queryOptionsForView`: active-input wiring for each generated view.",
233
+ "- `rowsForView`: table/records row readers.",
234
+ "- `rowValuesForView`: friendly row object readers for chart/table views.",
235
+ "- `metricValuesForView`: friendly metric-value readers.",
236
+ "- `kpiPropsForView`: KPI component props derived from runtime metric results.",
237
+ "- `roleValuesForView`: canonical dimension/measure/date/id role readers.",
238
+ "- `appInputSpecs`: generated input/filter specs.",
239
+ "- `inputOptionQueries`: option-list query factories for generated inputs.",
240
+ "- `semaphorGeneratedContractMetadata`: generated view/input metadata and presentation-only views.",
241
+ "",
242
+ "Start with these exports before opening large generated internals such as `metadata.ts`.",
243
+ ""
244
+ ];
245
+ return e.views.length > 0 && (n.push("Generated executable views:"), e.views.forEach((r) => {
246
+ n.push(`- \`${r.raw.id}\`: ${r.raw.title || r.name}`);
247
+ }), n.push("")), e.inputs.length > 0 && (n.push("Generated inputs:"), e.inputs.forEach((r) => {
248
+ n.push(`- \`${r.raw.id}\`: ${r.raw.label || r.name}`);
249
+ }), n.push("")), `${n.join(`
250
+ `)}
251
+ `;
252
+ }
253
+ function Ae(e) {
221
254
  return `sha256:${ye("sha256").update(ae(e)).digest("hex")}`;
222
255
  }
223
256
  function ae(e) {
@@ -228,9 +261,9 @@ function ae(e) {
228
261
  const n = e;
229
262
  return `{${Object.keys(n).sort().filter((t) => n[t] !== void 0).map((t) => `${JSON.stringify(t)}:${ae(n[t])}`).join(",")}}`;
230
263
  }
231
- function Ee(e) {
264
+ function je(e) {
232
265
  const n = e.views.find(
233
- (f) => E(f) && A(f)
266
+ (f) => A(f) && j(f)
234
267
  );
235
268
  if (n)
236
269
  return [
@@ -246,7 +279,7 @@ function Ee(e) {
246
279
  ].join(`
247
280
  `);
248
281
  const r = e.views.find(
249
- (f) => E(f)
282
+ (f) => A(f)
250
283
  );
251
284
  if (r)
252
285
  return [
@@ -262,7 +295,7 @@ function Ee(e) {
262
295
  ].join(`
263
296
  `);
264
297
  const t = e.views.find(
265
- (f) => W(f) && A(f)
298
+ (f) => z(f) && j(f)
266
299
  );
267
300
  if (t)
268
301
  return [
@@ -276,7 +309,7 @@ function Ee(e) {
276
309
  ].join(`
277
310
  `);
278
311
  const o = e.views.find(
279
- (f) => ue(f) && A(f)
312
+ (f) => ue(f) && j(f)
280
313
  );
281
314
  if (o)
282
315
  return [
@@ -290,8 +323,8 @@ function Ee(e) {
290
323
  ].join(`
291
324
  `);
292
325
  const a = e.views.find((f) => {
293
- var m;
294
- return cn((m = f.raw.sdkSpec) == null ? void 0 : m.builder);
326
+ var y;
327
+ return mn((y = f.raw.sdkSpec) == null ? void 0 : y.builder);
295
328
  });
296
329
  if (a)
297
330
  return [
@@ -303,65 +336,65 @@ function Ee(e) {
303
336
  "const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"
304
337
  ].join(`
305
338
  `);
306
- const l = e.views.find((f) => Ae(f));
307
- if (l)
339
+ const u = e.views.find((f) => ve(f));
340
+ if (u)
308
341
  return [
309
- 'import { appInputSpecs, createInputHandleMap, metricValuesForView, queries, queryOptionsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',
342
+ 'import { appInputSpecs, createInputHandleMap, kpiPropsForView, queries, queryOptionsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',
310
343
  "const handles = useSemaphorInputs(appInputSpecs);",
311
344
  "const inputHandles = createInputHandleMap(handles);",
312
- `const result = useSemaphorQuery(queries.${l.name}(), queryOptionsForView.${l.name}(inputHandles));`,
313
- `const metrics = metricValuesForView.${l.name}(result);`,
345
+ `const result = useSemaphorQuery(queries.${u.name}(), queryOptionsForView.${u.name}(inputHandles));`,
346
+ `const kpiProps = kpiPropsForView.${u.name}(result);`,
314
347
  "const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"
315
348
  ].join(`
316
349
  `);
317
- const y = e.views[0];
350
+ const c = e.views[0];
318
351
  return [
319
352
  'import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',
320
353
  "const handles = useSemaphorInputs(appInputSpecs);",
321
354
  "const inputHandles = createInputHandleMap(handles);",
322
- y ? `const result = useSemaphorQuery(queries.${y.name}(), queryOptionsForView.${y.name}(inputHandles));` : "const result = undefined;",
355
+ c ? `const result = useSemaphorQuery(queries.${c.name}(), queryOptionsForView.${c.name}(inputHandles));` : "const result = undefined;",
323
356
  "const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"
324
357
  ].join(`
325
358
  `);
326
359
  }
327
- function W(e) {
360
+ function z(e) {
328
361
  var n;
329
- return B((n = e.raw.sdkSpec) == null ? void 0 : n.builder) === "records";
362
+ return q((n = e.raw.sdkSpec) == null ? void 0 : n.builder) === "records";
330
363
  }
331
- function Ae(e) {
364
+ function ve(e) {
332
365
  var n;
333
- return B((n = e.raw.sdkSpec) == null ? void 0 : n.builder) === "metric";
366
+ return q((n = e.raw.sdkSpec) == null ? void 0 : n.builder) === "metric";
334
367
  }
335
- function E(e) {
368
+ function A(e) {
336
369
  var n, r, t;
337
- return W(e) && ((t = (r = (n = e.raw.visualSpec) == null ? void 0 : n.tableBehavior) == null ? void 0 : r.sorting) == null ? void 0 : t.mode) === "server";
370
+ return z(e) && ((t = (r = (n = e.raw.visualSpec) == null ? void 0 : n.tableBehavior) == null ? void 0 : r.sorting) == null ? void 0 : t.mode) === "server";
338
371
  }
339
372
  function ue(e) {
340
373
  var n;
341
- return B((n = e.raw.sdkSpec) == null ? void 0 : n.builder) === "sql";
374
+ return q((n = e.raw.sdkSpec) == null ? void 0 : n.builder) === "sql";
342
375
  }
343
- function A(e) {
376
+ function j(e) {
344
377
  var n, r, t;
345
378
  return ((t = (r = (n = e.raw.visualSpec) == null ? void 0 : n.tableBehavior) == null ? void 0 : r.pagination) == null ? void 0 : t.mode) === "server";
346
379
  }
347
380
  function He(e) {
348
- return W(e) && (A(e) || E(e)) || ue(e) && A(e);
381
+ return z(e) && (j(e) || A(e)) || ue(e) && j(e);
349
382
  }
350
- function ve(e) {
383
+ function Ke(e) {
351
384
  const n = e.sources.map(({ name: t, raw: o }) => {
352
- const a = je(o);
385
+ const a = qe(o);
353
386
  return ` ${t}: ${a},`;
354
387
  }).join(`
355
388
  `), r = e.sources.some((t) => t.raw.kind === "semantic") ? `import { semaphor } from "react-semaphor/data-app-sdk";
356
389
 
357
390
  ` : "";
358
- return `${H}
391
+ return `${v}
359
392
  ${r}export const sources = {
360
393
  ${n}
361
394
  } as const;
362
395
  `;
363
396
  }
364
- function je(e) {
397
+ function qe(e) {
365
398
  if (e.kind === "semantic") {
366
399
  const n = {
367
400
  domainId: e.domainId,
@@ -369,11 +402,11 @@ function je(e) {
369
402
  datasetName: e.datasetName,
370
403
  label: e.label
371
404
  };
372
- return `semaphor.source.semantic(${k(G(n))})`;
405
+ return `semaphor.source.semantic(${k(N(n))})`;
373
406
  }
374
- return `${k(G({ ...e, sourceKey: void 0 }))} as const`;
407
+ return `${k(N({ ...e, sourceKey: void 0 }))} as const`;
375
408
  }
376
- function qe(e) {
409
+ function Te(e) {
377
410
  const n = e.fields.map(({ name: t, raw: o }) => {
378
411
  const a = Be(o, e);
379
412
  return ` ${t}: ${a},`;
@@ -381,7 +414,7 @@ function qe(e) {
381
414
  `), r = n.includes("sources.") ? `import { sources } from "./sources";
382
415
 
383
416
  ` : "";
384
- return `${H}
417
+ return `${v}
385
418
  ${r}export const fields = {
386
419
  ${n}
387
420
  } as const;
@@ -394,95 +427,95 @@ function Be(e, n) {
394
427
  role: e.role,
395
428
  dataType: e.dataType,
396
429
  aggregate: e.aggregate
397
- }, t = ln(e), o = t ? n.sourceNameByKey.get(t) : void 0;
430
+ }, t = cn(e), o = t ? n.sourceNameByKey.get(t) : void 0;
398
431
  if (t && !o)
399
432
  throw new Error(
400
433
  `Field ${e.name} references source ${t}, but that source is not renderable. Include the source in codegenSummary.sources or provide field.source.`
401
434
  );
402
- const a = Object.entries(G(r)).map(([l, y]) => `${JSON.stringify(l)}: ${O(y, n)}`);
435
+ const a = Object.entries(N(r)).map(([u, c]) => `${JSON.stringify(u)}: ${G(c, n)}`);
403
436
  return o && a.push(`"source": sources.${o}`), `{ ${a.join(", ")} }`;
404
437
  }
405
- function Te(e) {
406
- const n = e.inputs.map((c) => {
407
- const i = x(c.raw.fieldRef, e), p = [
408
- `id: ${JSON.stringify(c.raw.id)}`,
409
- `label: ${JSON.stringify(c.raw.label || c.raw.id)}`,
410
- `operator: ${JSON.stringify(mn(c.raw))}`
438
+ function Qe(e) {
439
+ const n = e.inputs.map((m) => {
440
+ const i = R(m.raw.fieldRef, e), l = [
441
+ `id: ${JSON.stringify(m.raw.id)}`,
442
+ `label: ${JSON.stringify(m.raw.label || m.raw.id)}`,
443
+ `operator: ${JSON.stringify(fn(m.raw))}`
411
444
  ];
412
- if (i && p.push(`field: fields.${i}`), c.raw.relationshipHint && p.push(`relationshipHint: ${k(c.raw.relationshipHint)}`), !i)
413
- throw new Error(`Input ${c.raw.id || c.name} is missing a generated field reference.`);
414
- return ` ${c.name}: semaphor.filter({ ${p.join(", ")} }),`;
445
+ if (i && l.push(`field: fields.${i}`), m.raw.relationshipHint && l.push(`relationshipHint: ${k(m.raw.relationshipHint)}`), !i)
446
+ throw new Error(`Input ${m.raw.id || m.name} is missing a generated field reference.`);
447
+ return ` ${m.name}: semaphor.filter({ ${l.join(", ")} }),`;
415
448
  }).join(`
416
- `), r = e.inputs.map((c) => `filterSpecs.${c.name}`).join(", "), t = e.inputs.map((c) => JSON.stringify(c.raw.id)).join(", "), o = e.optionQueries.map((c) => {
417
- const i = c.input.raw, p = c.raw, S = V(p.spec) || {}, {
418
- id: g,
419
- inputId: $,
420
- source: F,
421
- sourceKey: R,
449
+ `), r = e.inputs.map((m) => `filterSpecs.${m.name}`).join(", "), t = e.inputs.map((m) => JSON.stringify(m.raw.id)).join(", "), o = e.optionQueries.map((m) => {
450
+ const i = m.input.raw, l = m.raw, g = F(l.spec) || {}, {
451
+ id: h,
452
+ inputId: I,
453
+ source: $,
454
+ sourceKey: M,
422
455
  valueField: b,
423
- labelField: M,
456
+ labelField: C,
424
457
  population: s,
425
- dependencies: I,
458
+ dependencies: V,
426
459
  limit: T,
427
460
  ...ee
428
- } = S, J = p.sourceKey ? { sourceKey: p.sourceKey } : p.source || F || (typeof R == "string" ? { sourceKey: R } : void 0), ne = Se(J, e), re = x(p.valueFieldRef, e), te = x(p.labelFieldRef, e), oe = ge(c), se = {
461
+ } = g, U = l.sourceKey ? { sourceKey: l.sourceKey } : l.source || $ || (typeof M == "string" ? { sourceKey: M } : void 0), ne = Se(U, e), re = R(l.valueFieldRef, e), te = R(l.labelFieldRef, e), oe = he(m), se = {
429
462
  ...ee,
430
- id: p.id || S.id || `${i.id}-options`,
463
+ id: l.id || g.id || `${i.id}-options`,
431
464
  inputId: i.id,
432
- source: J,
433
- valueField: p.valueFieldRef,
434
- labelField: p.labelFieldRef,
435
- population: p.population || s,
465
+ source: U,
466
+ valueField: l.valueFieldRef,
467
+ labelField: l.labelFieldRef,
468
+ population: l.population || s,
436
469
  dependencies: oe,
437
- limit: p.limit || T || 100
470
+ limit: l.limit || T || 100
438
471
  };
439
472
  if (!ne || !re || !te)
440
- throw new Error(`Input option query ${p.id || `${i.id}-options`} is missing source, valueField, or labelField.`);
441
- const Fe = Object.entries(G(se)).map(([be, Ve]) => `${JSON.stringify(be)}: ${O(Ve, e)}`);
442
- return ` ${c.name}: semaphor.inputOptions({ ${Fe.join(", ")} }),`;
473
+ throw new Error(`Input option query ${l.id || `${i.id}-options`} is missing source, valueField, or labelField.`);
474
+ const Ve = Object.entries(N(se)).map(([Fe, be]) => `${JSON.stringify(Fe)}: ${G(be, e)}`);
475
+ return ` ${m.name}: semaphor.inputOptions({ ${Ve.join(", ")} }),`;
443
476
  }).join(`
444
- `), a = e.optionQueries.map((c) => {
445
- const i = Qe(e, c), p = i.length > 0 ? "inputHandles" : "_inputHandles", S = i.map((g) => {
446
- const $ = x(g.raw.fieldRef, e);
447
- if (!$)
477
+ `), a = e.optionQueries.map((m) => {
478
+ const i = Pe(e, m), l = i.length > 0 ? "inputHandles" : "_inputHandles", g = i.map((h) => {
479
+ const I = R(h.raw.fieldRef, e);
480
+ if (!I)
448
481
  throw new Error(
449
- `Input option query ${c.raw.id || `${c.input.raw.id}-options`} references input ${g.raw.id} without a generated field reference.`
482
+ `Input option query ${m.raw.id || `${m.input.raw.id}-options`} references input ${h.raw.id} without a generated field reference.`
450
483
  );
451
- const F = `inputHandles[${JSON.stringify(g.raw.id)}]`;
452
- return ` if (${F}) {
453
- inputs.push(semaphor.bindInput(${F}, { field: fields.${$} }));
484
+ const $ = `inputHandles[${JSON.stringify(h.raw.id)}]`;
485
+ return ` if (${$}) {
486
+ inputs.push(semaphor.bindInput(${$}, { field: fields.${I} }));
454
487
  }`;
455
488
  }).join(`
456
489
  `);
457
- return ` ${c.name}(${p}: SemaphorGeneratedInputHandleMap): SemaphorInputReference[] {
490
+ return ` ${m.name}(${l}: SemaphorGeneratedInputHandleMap): SemaphorInputReference[] {
458
491
  const inputs: SemaphorInputReference[] = [];
459
- ${S}
492
+ ${g}
460
493
  return inputs;
461
494
  },`;
462
495
  }).join(`
463
496
 
464
- `), l = e.optionQueries.map((c) => ` ${c.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorQueryRuntimeOptions {
497
+ `), u = e.optionQueries.map((m) => ` ${m.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorQueryRuntimeOptions {
465
498
  return {
466
- inputs: inputsForInputOptionQuery.${c.name}(inputHandles),
499
+ inputs: inputsForInputOptionQuery.${m.name}(inputHandles),
467
500
  };
468
501
  },`).join(`
469
502
 
470
- `), y = e.optionQueries.map((c) => ` case ${JSON.stringify(c.raw.id || `${c.input.raw.id}-options`)}:
471
- return queryOptionsForInputOptionQuery.${c.name}(inputHandles);`).join(`
472
- `), w = e.inputs.length > 0, f = e.optionQueries.length > 0, m = f ? "inputOptionQueryId" : "_inputOptionQueryId", N = f ? "inputHandles" : "_inputHandles", u = [
503
+ `), c = e.optionQueries.map((m) => ` case ${JSON.stringify(m.raw.id || `${m.input.raw.id}-options`)}:
504
+ return queryOptionsForInputOptionQuery.${m.name}(inputHandles);`).join(`
505
+ `), S = e.inputs.length > 0, f = e.optionQueries.length > 0, y = f ? "inputOptionQueryId" : "_inputOptionQueryId", O = f ? "inputHandles" : "_inputHandles", d = [
473
506
  "SemaphorInputHandle",
474
507
  f ? "SemaphorInputReference" : void 0,
475
508
  "SemaphorQueryRuntimeOptions"
476
- ].filter(K).join(", "), d = [
477
- w || f ? 'import { semaphor } from "react-semaphor/data-app-sdk";' : void 0,
478
- `import type { ${u} } from "react-semaphor/data-app-sdk";`,
479
- w || f ? 'import { fields } from "./fields";' : void 0,
509
+ ].filter(E).join(", "), p = [
510
+ S || f ? 'import { semaphor } from "react-semaphor/data-app-sdk";' : void 0,
511
+ `import type { ${d} } from "react-semaphor/data-app-sdk";`,
512
+ S || f ? 'import { fields } from "./fields";' : void 0,
480
513
  f ? 'import { sources } from "./sources";' : void 0,
481
514
  'import type { SemaphorGeneratedInputId, SemaphorGeneratedInputOptionQueryId } from "./metadata";'
482
- ].filter(K).join(`
515
+ ].filter(E).join(`
483
516
  `);
484
- return `${H}
485
- ${d}
517
+ return `${v}
518
+ ${p}
486
519
 
487
520
  export const filterSpecs = {
488
521
  ${n}
@@ -506,22 +539,22 @@ ${a}
506
539
  } as const;
507
540
 
508
541
  export const queryOptionsForInputOptionQuery = {
509
- ${l}
542
+ ${u}
510
543
  } as const;
511
544
 
512
545
  export function queryOptionsForInputOptionQueryId(
513
- ${m}: SemaphorGeneratedInputOptionQueryId,
514
- ${N}: SemaphorGeneratedInputHandleMap,
546
+ ${y}: SemaphorGeneratedInputOptionQueryId,
547
+ ${O}: SemaphorGeneratedInputHandleMap,
515
548
  ): SemaphorQueryRuntimeOptions {
516
- switch (${m}) {
517
- ${y}
549
+ switch (${y}) {
550
+ ${c}
518
551
  }
519
- throw new Error(\`Unknown generated Semaphor input option query id: \${${m}}\`);
552
+ throw new Error(\`Unknown generated Semaphor input option query id: \${${y}}\`);
520
553
  }
521
554
  `;
522
555
  }
523
- function Qe(e, n) {
524
- const r = ge(n);
556
+ function Pe(e, n) {
557
+ const r = he(n);
525
558
  if (!r || r.mode === "independent")
526
559
  return [];
527
560
  if (r.mode !== "explicit")
@@ -532,78 +565,78 @@ function Qe(e, n) {
532
565
  ]);
533
566
  return e.inputs.filter((a) => o.has(a.raw.id) ? !1 : t.has(a.raw.id));
534
567
  }
535
- function ge(e) {
568
+ function he(e) {
536
569
  var n;
537
570
  return e.raw.dependencies || ((n = e.raw.spec) == null ? void 0 : n.dependencies);
538
571
  }
539
- function _e(e) {
540
- const n = e.views.map((d) => {
541
- var p, S, g, $, F, R;
542
- const c = B(d.raw.sdkSpec.builder), i = Pe(d);
543
- if (W(d) && He(d)) {
544
- const b = (p = d.raw.visualSpec) == null ? void 0 : p.tableBehavior, M = V(i.pagination), s = A(d), I = E(d), T = ((S = b == null ? void 0 : b.pagination) == null ? void 0 : S.pageSize) || z(M == null ? void 0 : M.pageSize) || z(i.limit) || 100, ee = I ? Y(d, e) : [], J = I ? De({
545
- view: d,
572
+ function De(e) {
573
+ const n = e.views.map((p) => {
574
+ var l, g, h, I, $, M;
575
+ const m = q(p.raw.sdkSpec.builder), i = _e(p);
576
+ if (z(p) && He(p)) {
577
+ const b = (l = p.raw.visualSpec) == null ? void 0 : l.tableBehavior, C = F(i.pagination), s = j(p), V = A(p), T = ((g = b == null ? void 0 : b.pagination) == null ? void 0 : g.pageSize) || J(C == null ? void 0 : C.pageSize) || J(i.limit) || 100, ee = V ? L(p, e) : [], U = V ? Ue({
578
+ view: p,
546
579
  contract: e,
547
580
  sortFields: ee,
548
- defaultField: (g = b == null ? void 0 : b.sorting) == null ? void 0 : g.defaultField
549
- }) : void 0, ne = I ? ($ = b == null ? void 0 : b.sorting) == null ? void 0 : $.defaultDirection : void 0, re = Ue({
550
- viewName: d.name,
581
+ defaultField: (h = b == null ? void 0 : b.sorting) == null ? void 0 : h.defaultField
582
+ }) : void 0, ne = V ? (I = b == null ? void 0 : b.sorting) == null ? void 0 : I.defaultDirection : void 0, re = Je({
583
+ viewName: p.name,
551
584
  supportsPagination: s,
552
- supportsSort: I
553
- }), te = I ? ` const orderBy = resolveRecordsOrderBy(
554
- recordsSortFieldsForView.${d.name},
585
+ supportsSort: V
586
+ }), te = V ? ` const orderBy = resolveRecordsOrderBy(
587
+ recordsSortFieldsForView.${p.name},
555
588
  params.sort,
556
- ${O(J, e)},
557
- ${O(ne, e)},
589
+ ${G(U, e)},
590
+ ${G(ne, e)},
558
591
  );
559
- ` : "", oe = I ? ` ...(orderBy ? { orderBy } : {}),
592
+ ` : "", oe = V ? ` ...(orderBy ? { orderBy } : {}),
560
593
  ` : "", se = s ? ` pagination: resolveServerTablePagination(params, ${JSON.stringify(T)}),
561
594
  ` : "";
562
- return ` ${d.name}(
595
+ return ` ${p.name}(
563
596
  params: ${re} = {},
564
597
  ) {
565
- ${te} return semaphor.${c}({
566
- ...${O(i, e)},
598
+ ${te} return semaphor.${m}({
599
+ ...${G(i, e)},
567
600
  ${oe}${se} });
568
601
  },`;
569
602
  }
570
- if (ue(d) && A(d)) {
571
- const b = (F = d.raw.visualSpec) == null ? void 0 : F.tableBehavior, M = V(i.pagination), s = ((R = b == null ? void 0 : b.pagination) == null ? void 0 : R.pageSize) || z(M == null ? void 0 : M.pageSize) || z(i.limit) || 100;
572
- return ` ${d.name}(
603
+ if (ue(p) && j(p)) {
604
+ const b = ($ = p.raw.visualSpec) == null ? void 0 : $.tableBehavior, C = F(i.pagination), s = ((M = b == null ? void 0 : b.pagination) == null ? void 0 : M.pageSize) || J(C == null ? void 0 : C.pageSize) || J(i.limit) || 100;
605
+ return ` ${p.name}(
573
606
  params: SemaphorGeneratedServerPaginationParams = {},
574
607
  ) {
575
- return semaphor.${c}({
576
- ...${O(i, e)},
608
+ return semaphor.${m}({
609
+ ...${G(i, e)},
577
610
  pagination: resolveServerTablePagination(params, ${JSON.stringify(s)}),
578
611
  });
579
612
  },`;
580
613
  }
581
- return ` ${d.name}: () => semaphor.${c}(${O(i, e)}),`;
614
+ return ` ${p.name}: () => semaphor.${m}(${G(i, e)}),`;
582
615
  }).join(`
583
- `), r = e.views.filter((d) => E(d)).map((d) => {
584
- const i = Y(d, e).map((p) => ` ${JSON.stringify(p.key)}: fields.${p.fieldName},`).join(`
616
+ `), r = e.views.filter((p) => A(p)).map((p) => {
617
+ const i = L(p, e).map((l) => ` ${JSON.stringify(l.key)}: fields.${l.fieldName},`).join(`
585
618
  `);
586
- return ` ${d.name}: {
619
+ return ` ${p.name}: {
587
620
  ${i}
588
621
  },`;
589
622
  }).join(`
590
- `), t = e.views.filter((d) => E(d)).map((d) => {
591
- const i = Y(d, e).map((p) => ` { key: ${JSON.stringify(p.key)}, label: ${JSON.stringify(p.label)}, field: fields.${p.fieldName} },`).join(`
623
+ `), t = e.views.filter((p) => A(p)).map((p) => {
624
+ const i = L(p, e).map((l) => ` { key: ${JSON.stringify(l.key)}, label: ${JSON.stringify(l.label)}, field: fields.${l.fieldName} },`).join(`
592
625
  `);
593
- return ` ${d.name}: [
626
+ return ` ${p.name}: [
594
627
  ${i}
595
628
  ],`;
596
629
  }).join(`
597
- `), o = e.views.some((d) => E(d)), a = e.views.some((d) => A(d)), l = [n, r, t].join(`
598
- `), y = [
630
+ `), o = e.views.some((p) => A(p)), a = e.views.some((p) => j(p)), u = [n, r, t].join(`
631
+ `), c = [
599
632
  n ? 'import { semaphor } from "react-semaphor/data-app-sdk";' : void 0,
600
633
  o ? 'import type { SemaphorFieldRef } from "react-semaphor/data-app-sdk";' : void 0,
601
- l.includes("fields.") ? 'import { fields } from "./fields";' : void 0,
602
- l.includes("sources.") ? 'import { sources } from "./sources";' : void 0
603
- ].filter(K).join(`
634
+ u.includes("fields.") ? 'import { fields } from "./fields";' : void 0,
635
+ u.includes("sources.") ? 'import { sources } from "./sources";' : void 0
636
+ ].filter(E).join(`
604
637
  `);
605
- return `${H}
606
- ${y}
638
+ return `${v}
639
+ ${c}
607
640
  ${o ? `export type SemaphorGeneratedRecordsSortDirection = "asc" | "desc";
608
641
 
609
642
  export type SemaphorGeneratedRecordsSort<TSortKey extends string = string> = {
@@ -667,52 +700,52 @@ ${a ? `function resolveServerTablePagination(
667
700
  ` : ""}
668
701
  `;
669
702
  }
670
- function Pe(e) {
671
- var a, l;
672
- const n = V((a = e.raw.sdkSpec) == null ? void 0 : a.spec) || {}, { kind: r, id: t, ...o } = n;
703
+ function _e(e) {
704
+ var a, u;
705
+ const n = F((a = e.raw.sdkSpec) == null ? void 0 : a.spec) || {}, { kind: r, id: t, ...o } = n;
673
706
  return {
674
707
  ...o,
675
708
  id: e.raw.id,
676
- label: ((l = e.raw.visualSpec) == null ? void 0 : l.title) || e.raw.title || o.label
709
+ label: ((u = e.raw.visualSpec) == null ? void 0 : u.title) || e.raw.title || o.label
677
710
  };
678
711
  }
679
- function Y(e, n) {
680
- var a, l;
681
- const r = [], t = V((a = e.raw.sdkSpec) == null ? void 0 : a.spec) || {};
682
- for (const y of j(t.fields)) h(r, y);
683
- h(r, t.dateField), h(r, (l = V(t.orderBy)) == null ? void 0 : l.field);
684
- for (const y of e.raw.fields || []) h(r, y);
712
+ function L(e, n) {
713
+ var a, u;
714
+ const r = [], t = F((a = e.raw.sdkSpec) == null ? void 0 : a.spec) || {};
715
+ for (const c of H(t.fields)) w(r, c);
716
+ w(r, t.dateField), w(r, (u = F(t.orderBy)) == null ? void 0 : u.field);
717
+ for (const c of e.raw.fields || []) w(r, c);
685
718
  return X(
686
- r.map((y) => {
687
- const w = x(y, n);
688
- if (!(!y.name || !w))
719
+ r.map((c) => {
720
+ const S = R(c, n);
721
+ if (!(!c.name || !S))
689
722
  return {
690
- key: w,
691
- fieldName: w,
692
- rawName: y.name,
693
- label: y.label || y.name
723
+ key: S,
724
+ fieldName: S,
725
+ rawName: c.name,
726
+ label: c.label || c.name
694
727
  };
695
- }).filter(K),
696
- (y) => y.key
728
+ }).filter(E),
729
+ (c) => c.key
697
730
  );
698
731
  }
699
- function De({
732
+ function Ue({
700
733
  view: e,
701
734
  contract: n,
702
735
  sortFields: r,
703
736
  defaultField: t
704
737
  }) {
705
- var w, f;
706
- const o = new Set(r.map((m) => m.key));
738
+ var S, f;
739
+ const o = new Set(r.map((y) => y.key));
707
740
  if (t && o.has(t))
708
741
  return t;
709
- const a = r.filter((m) => m.rawName === t);
742
+ const a = r.filter((y) => y.rawName === t);
710
743
  if (a.length === 1)
711
744
  return a[0].key;
712
- const l = V((w = e.raw.sdkSpec) == null ? void 0 : w.spec), y = x((f = V(l == null ? void 0 : l.orderBy)) == null ? void 0 : f.field, n);
713
- return y && o.has(y) ? y : void 0;
745
+ const u = F((S = e.raw.sdkSpec) == null ? void 0 : S.spec), c = R((f = F(u == null ? void 0 : u.orderBy)) == null ? void 0 : f.field, n);
746
+ return c && o.has(c) ? c : void 0;
714
747
  }
715
- function Ue({
748
+ function Je({
716
749
  viewName: e,
717
750
  supportsPagination: n,
718
751
  supportsSort: r
@@ -720,58 +753,58 @@ function Ue({
720
753
  return n && r ? `SemaphorGeneratedRecordsQueryParams<Extract<keyof typeof recordsSortFieldsForView.${e}, string>>` : r ? `SemaphorGeneratedRecordsSortParams<Extract<keyof typeof recordsSortFieldsForView.${e}, string>>` : "SemaphorGeneratedServerPaginationParams";
721
754
  }
722
755
  function Le(e) {
723
- const n = e.views.map((m) => {
724
- const u = Je(e, m.raw.id).map((d) => {
725
- const c = d.inputId, i = x(d.fieldRef, e);
726
- if (!c || !i)
756
+ const n = e.views.map((y) => {
757
+ const d = ze(e, y.raw.id).map((p) => {
758
+ const m = p.inputId, i = R(p.fieldRef, e);
759
+ if (!m || !i)
727
760
  return "";
728
- const p = [`field: fields.${i}`];
729
- if (d.relationshipHint)
730
- p.push(`relationshipHint: ${k(d.relationshipHint)}`);
731
- else if (Array.isArray(d.relationshipsUsed) && d.relationshipsUsed.length > 0) {
732
- const g = d.relationshipsUsed.map(($) => {
733
- var F;
734
- return (F = V($)) == null ? void 0 : F.id;
735
- }).filter(($) => typeof $ == "string" && $.length > 0);
736
- g.length > 0 && p.push(`relationshipHint: ${k({ relationshipIds: g })}`);
761
+ const l = [`field: fields.${i}`];
762
+ if (p.relationshipHint)
763
+ l.push(`relationshipHint: ${k(p.relationshipHint)}`);
764
+ else if (Array.isArray(p.relationshipsUsed) && p.relationshipsUsed.length > 0) {
765
+ const h = p.relationshipsUsed.map((I) => {
766
+ var $;
767
+ return ($ = F(I)) == null ? void 0 : $.id;
768
+ }).filter((I) => typeof I == "string" && I.length > 0);
769
+ h.length > 0 && l.push(`relationshipHint: ${k({ relationshipIds: h })}`);
737
770
  }
738
- const S = `inputHandles[${JSON.stringify(c)}]`;
739
- return ` if (${S}) {
740
- inputs.push(semaphor.bindInput(${S}, { ${p.join(", ")} }));
771
+ const g = `inputHandles[${JSON.stringify(m)}]`;
772
+ return ` if (${g}) {
773
+ inputs.push(semaphor.bindInput(${g}, { ${l.join(", ")} }));
741
774
  }`;
742
775
  }).filter(Boolean).join(`
743
776
  `);
744
- return { view: m, renderedBindings: u };
745
- }), r = n.some((m) => m.renderedBindings.length > 0), t = n.map(({ view: m, renderedBindings: N }) => {
746
- const u = N ? "inputHandles" : "_inputHandles";
747
- return ` ${m.name}(${u}: SemaphorGeneratedInputHandleMap): SemaphorInputReference[] {
777
+ return { view: y, renderedBindings: d };
778
+ }), r = n.some((y) => y.renderedBindings.length > 0), t = n.map(({ view: y, renderedBindings: O }) => {
779
+ const d = O ? "inputHandles" : "_inputHandles";
780
+ return ` ${y.name}(${d}: SemaphorGeneratedInputHandleMap): SemaphorInputReference[] {
748
781
  const inputs: SemaphorInputReference[] = [];
749
- ${N}
782
+ ${O}
750
783
  return inputs;
751
784
  },`;
752
785
  }).join(`
753
786
 
754
- `), o = e.views.map((m) => ` ${m.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorQueryRuntimeOptions {
787
+ `), o = e.views.map((y) => ` ${y.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorQueryRuntimeOptions {
755
788
  return {
756
- inputs: inputsForView.${m.name}(inputHandles),
757
- debug: queryDebugForView.${m.name},
789
+ inputs: inputsForView.${y.name}(inputHandles),
790
+ debug: queryDebugForView.${y.name},
758
791
  };
759
792
  },`).join(`
760
793
 
761
- `), a = e.views.map((m) => ` case ${JSON.stringify(m.raw.id)}:
762
- return inputsForView.${m.name}(inputHandles);`).join(`
763
- `), l = e.views.map((m) => ` case ${JSON.stringify(m.raw.id)}:
764
- return queryOptionsForView.${m.name}(inputHandles);`).join(`
765
- `), y = e.views.length > 0, w = y ? "inputHandles" : "_inputHandles", f = [
794
+ `), a = e.views.map((y) => ` case ${JSON.stringify(y.raw.id)}:
795
+ return inputsForView.${y.name}(inputHandles);`).join(`
796
+ `), u = e.views.map((y) => ` case ${JSON.stringify(y.raw.id)}:
797
+ return queryOptionsForView.${y.name}(inputHandles);`).join(`
798
+ `), c = e.views.length > 0, S = c ? "inputHandles" : "_inputHandles", f = [
766
799
  r ? 'import { semaphor } from "react-semaphor/data-app-sdk";' : void 0,
767
800
  'import type { SemaphorInputReference, SemaphorQueryRuntimeOptions } from "react-semaphor/data-app-sdk";',
768
801
  r ? 'import { fields } from "./fields";' : void 0,
769
802
  'import type { SemaphorGeneratedInputHandleMap } from "./inputs";',
770
- y ? 'import { queryDebugForView } from "./metadata";' : void 0,
803
+ c ? 'import { queryDebugForView } from "./metadata";' : void 0,
771
804
  'import type { SemaphorGeneratedQueryViewId } from "./metadata";'
772
- ].filter(K).join(`
805
+ ].filter(E).join(`
773
806
  `);
774
- return `${H}
807
+ return `${v}
775
808
  ${f}
776
809
 
777
810
  export const inputsForView = {
@@ -784,7 +817,7 @@ ${o}
784
817
 
785
818
  export function inputsForViewId(
786
819
  viewId: SemaphorGeneratedQueryViewId,
787
- ${w}: SemaphorGeneratedInputHandleMap,
820
+ ${S}: SemaphorGeneratedInputHandleMap,
788
821
  ): SemaphorInputReference[] {
789
822
  switch (viewId) {
790
823
  ${a}
@@ -794,16 +827,16 @@ ${a}
794
827
 
795
828
  export function queryOptionsForViewId(
796
829
  viewId: SemaphorGeneratedQueryViewId,
797
- ${w}: SemaphorGeneratedInputHandleMap,
830
+ ${S}: SemaphorGeneratedInputHandleMap,
798
831
  ): SemaphorQueryRuntimeOptions {
799
832
  switch (viewId) {
800
- ${l}
833
+ ${u}
801
834
  }
802
835
  throw new Error(\`Unknown generated Semaphor view id: \${viewId}\`);
803
836
  }
804
837
  `;
805
838
  }
806
- function Je(e, n) {
839
+ function ze(e, n) {
807
840
  return e.filterContracts.flatMap(
808
841
  (r) => (r.bindings || []).filter((t) => t.viewId === n).map((t) => ({
809
842
  inputId: r.inputId,
@@ -813,140 +846,160 @@ function Je(e, n) {
813
846
  }))
814
847
  );
815
848
  }
816
- function ze(e) {
849
+ function Ye(e) {
817
850
  const n = e.views.map((i) => {
818
- const S = D(i, e).map((g) => {
819
- const $ = x(g.raw, e);
820
- return $ ? ` ${g.name}: fields.${$},` : "";
851
+ const g = D(i, e).map((h) => {
852
+ const I = R(h.raw, e);
853
+ return I ? ` ${h.name}: fields.${I},` : "";
821
854
  }).filter(Boolean).join(`
822
855
  `);
823
856
  return ` ${i.name}: {
824
- ${S}
857
+ ${g}
825
858
  },`;
826
859
  }).join(`
827
860
  `), r = e.views.map((i) => {
828
- const S = P(i, e).map((g) => {
829
- const $ = x(g.raw, e);
830
- return $ ? ` ${g.name}: fields.${$},` : "";
861
+ const g = Q(i, e).map((h) => {
862
+ const I = R(h.raw, e);
863
+ return I ? ` ${h.name}: fields.${I},` : "";
831
864
  }).filter(Boolean).join(`
832
865
  `);
833
866
  return ` ${i.name}: {
834
- ${S}
867
+ ${g}
835
868
  },`;
836
869
  }).join(`
837
870
  `), t = e.views.map((i) => {
838
- const p = P(i, e), S = rn(p), g = nn(p), $ = p.map((F) => {
839
- const R = Array.from(
840
- new Set(
841
- he(F.raw).filter((b) => g.has(b))
842
- )
843
- );
844
- return ` ${F.name}: metricKeysForField(metricFieldsForView.${i.name}.${F.name}, { allowNameFallback: ${S.has(F.raw.name) ? "false" : "true"}, excludedKeys: ${k(R)} }),`;
845
- }).join(`
871
+ const g = Q(i, e).map((h, I) => ` ${h.name}: ${JSON.stringify(en(i, h, I))},`).join(`
846
872
  `);
847
873
  return ` ${i.name}: {
848
- ${$}
874
+ ${g}
849
875
  },`;
850
876
  }).join(`
851
877
  `), o = e.views.map((i) => {
852
- const S = P(i, e).map((g, $) => ` ${g.name}: ${JSON.stringify(Xe(i, g, $))},`).join(`
853
- `);
854
- return ` ${i.name}: {
855
- ${S}
856
- },`;
857
- }).join(`
858
- `), a = e.views.map((i) => {
859
- const p = P(i, e);
860
- if (p.length === 0)
878
+ const l = Q(i, e);
879
+ if (l.length === 0)
861
880
  return ` ${i.name}(): Record<keyof typeof metricFieldsForView.${i.name}, unknown> {
862
881
  return {};
863
882
  },`;
864
- const S = en(i, p), g = p.map(($) => {
865
- const F = `metricMeasureKeysForView.${i.name}.${$.name}`, R = `metricMeasureBindingKeysForView.${i.name}.${$.name}`, b = S.has($.name) ? `readMetricValueByBindingWithFallback(measures, measureBindings, ${R}, ${F}, primaryValue)` : `readMetricValueByBinding(measures, measureBindings, ${R}, ${F})`;
866
- return ` ${$.name}: ${b},`;
883
+ const g = l.map((h) => {
884
+ const $ = `readMetricValueByBinding(measures, measureBindings, ${`metricMeasureBindingKeysForView.${i.name}.${h.name}`})`;
885
+ return ` ${h.name}: ${$},`;
867
886
  }).join(`
868
887
  `);
869
888
  return ` ${i.name}(result: SemaphorGeneratedMetricResult): Record<keyof typeof metricFieldsForView.${i.name}, unknown> {
870
889
  const measures = result?.measures;
871
890
  const measureBindings = result?.measureBindings;
872
- const primaryValue = result?.primaryValue;
873
891
  return {
874
892
  ${g}
875
893
  };
876
894
  },`;
877
895
  }).join(`
878
896
 
879
- `), l = e.views.map((i) => {
880
- const p = P(i, e);
881
- if (p.length === 0)
897
+ `), a = e.views.map((i) => {
898
+ const l = Q(i, e);
899
+ if (l.length === 0)
882
900
  return ` ${i.name}(): Array<keyof typeof metricFieldsForView.${i.name}> {
883
901
  return [];
884
902
  },`;
885
- const S = p.map((g) => ` ...(missing.has(metricMeasureBindingKeysForView.${i.name}.${g.name}) ? [${JSON.stringify(g.name)} as keyof typeof metricFieldsForView.${i.name}] : []),`).join(`
903
+ const g = l.map((h, I) => {
904
+ const $ = `metricMeasureBindingKeysForView.${i.name}.${h.name}`, M = I === 0 ? `readMetricValueByBinding(measures, measureBindings, ${$}) === undefined && !hasOwnPrimaryMetricValue(result)` : `readMetricValueByBinding(measures, measureBindings, ${$}) === undefined`;
905
+ return ` ...(missing.has(${$}) || (${M}) ? [${JSON.stringify(h.name)} as keyof typeof metricFieldsForView.${i.name}] : []),`;
906
+ }).join(`
886
907
  `);
887
908
  return ` ${i.name}(result: SemaphorGeneratedMetricResult): Array<keyof typeof metricFieldsForView.${i.name}> {
888
909
  const missing = new Set(result?.missingMeasures || []);
910
+ const measures = result?.measures;
911
+ const measureBindings = result?.measureBindings;
889
912
  return [
890
- ${S}
913
+ ${g}
891
914
  ];
892
915
  },`;
893
916
  }).join(`
894
917
 
895
- `), y = e.views.map((i) => {
896
- const p = Ye(i, e);
897
- return ` ${i.name}: ${k(p)},`;
918
+ `), u = e.views.map((i) => {
919
+ const l = Q(i, e);
920
+ if (l.length === 0)
921
+ return "";
922
+ const g = l[0], h = l.map(($) => `{ key: ${JSON.stringify($.name)}, label: ${JSON.stringify($.raw.label || $.raw.name)} }`).join(", "), I = l.filter(($) => $.name !== g.name).map(($) => ` if (missing.includes(${JSON.stringify($.name)})) delete values.${$.name};`).join(`
923
+ `);
924
+ return ` ${i.name}(result: SemaphorGeneratedMetricResult): SemaphorGeneratedKpiProps {
925
+ const values = mapMetricDisplayValues(metricValuesForView.${i.name}(result));
926
+ const missing = missingMetricMeasuresForView.${i.name}(result).map((key) => String(key));
927
+ const primaryMissing = missing.includes(${JSON.stringify(g.name)});
928
+ const boundPrimaryValue = values.${g.name};
929
+ const primaryValue = primaryMissing || boundPrimaryValue === undefined ? result?.primaryValue : boundPrimaryValue;
930
+ if (primaryMissing) values.${g.name} = metricDisplayValue(result?.primaryValue);
931
+ ${I}
932
+ return {
933
+ result: {
934
+ ...(result || {}),
935
+ primaryValue: metricDisplayValue(result?.primaryValue),
936
+ comparisonValue: metricDisplayValue(result?.comparisonValue),
937
+ measures: values,
938
+ },
939
+ title: ${JSON.stringify(i.raw.title || i.raw.id)},
940
+ label: ${JSON.stringify(g.raw.label || g.raw.name)},
941
+ value: metricDisplayValue(primaryValue),
942
+ measures: [${h}],
943
+ missingMeasures: missing,
944
+ showComparison: Boolean(result?.comparisonKind),
945
+ };
946
+ },`;
947
+ }).filter(Boolean).join(`
948
+
949
+ `), c = e.views.map((i) => {
950
+ const l = Ze(i, e);
951
+ return ` ${i.name}: ${k(l)},`;
898
952
  }).join(`
899
- `), w = e.views.map((i) => {
900
- const S = D(i, e).map((g) => ` ${g.name}: resolveColumnKey(columns, fieldsForView.${i.name}.${g.name}),`).join(`
953
+ `), S = e.views.map((i) => {
954
+ const g = D(i, e).map((h) => ` ${h.name}: resolveColumnKey(columns, fieldsForView.${i.name}.${h.name}),`).join(`
901
955
  `);
902
956
  return ` ${i.name}(columns: SemaphorGeneratedColumns): Record<keyof typeof fieldsForView.${i.name}, string | undefined> {
903
957
  return {
904
- ${S}
958
+ ${g}
905
959
  };
906
960
  },`;
907
961
  }).join(`
908
962
 
909
963
  `), f = e.views.map((i) => {
910
- const S = D(i, e).map((g) => ` ${g.name}: readCell(row, columns, fieldsForView.${i.name}.${g.name}),`).join(`
964
+ const g = D(i, e).map((h) => ` ${h.name}: readCell(row, columns, fieldsForView.${i.name}.${h.name}),`).join(`
911
965
  `);
912
966
  return ` ${i.name}(row: SemaphorGeneratedRow, columns: SemaphorGeneratedColumns): Record<keyof typeof fieldsForView.${i.name}, unknown> {
913
967
  return {
914
- ${S}
968
+ ${g}
915
969
  };
916
970
  },`;
917
971
  }).join(`
918
972
 
919
- `), m = e.views.map((i) => ` ${i.name}(result: SemaphorGeneratedRecordsResult): Array<Record<keyof typeof fieldsForView.${i.name}, unknown>> {
973
+ `), y = e.views.map((i) => ` ${i.name}(result: SemaphorGeneratedRecordsResult): Array<Record<keyof typeof fieldsForView.${i.name}, unknown>> {
920
974
  return (result?.records || []).map((row) => rowValuesForView.${i.name}(row, result?.columns));
921
975
  },`).join(`
922
976
 
923
- `), N = e.views.map((i) => {
924
- const p = D(i, e), S = p.filter((s) => s.raw.role === "dimension"), g = p.filter((s) => s.raw.role === "measure"), $ = S[0], F = S[1], R = g[0], b = g[1], M = [
925
- $ ? ` primaryDimension: values.${$.name},` : " primaryDimension: undefined,",
926
- F ? ` secondaryDimension: values.${F.name},` : " secondaryDimension: undefined,",
927
- R ? ` primaryMeasure: values.${R.name},` : " primaryMeasure: undefined,",
977
+ `), O = e.views.map((i) => {
978
+ const l = D(i, e), g = l.filter((s) => s.raw.role === "dimension"), h = l.filter((s) => s.raw.role === "measure"), I = g[0], $ = g[1], M = h[0], b = h[1], C = [
979
+ I ? ` primaryDimension: values.${I.name},` : " primaryDimension: undefined,",
980
+ $ ? ` secondaryDimension: values.${$.name},` : " secondaryDimension: undefined,",
981
+ M ? ` primaryMeasure: values.${M.name},` : " primaryMeasure: undefined,",
928
982
  b ? ` secondaryMeasure: values.${b.name},` : " secondaryMeasure: undefined,"
929
983
  ].join(`
930
984
  `);
931
985
  return ` ${i.name}(row: SemaphorGeneratedRow, columns: SemaphorGeneratedColumns): SemaphorGeneratedRoleValues {
932
986
  const values = rowValuesForView.${i.name}(row, columns);
933
987
  return {
934
- ${M}
988
+ ${C}
935
989
  };
936
990
  },`;
937
991
  }).join(`
938
992
 
939
- `), u = n.includes("fields.") || r.includes("fields."), c = [
993
+ `), d = n.includes("fields.") || r.includes("fields."), m = [
940
994
  `import { ${[
941
995
  "type SemaphorFieldRef",
942
- "type SemaphorResultColumn",
943
- "semaphorMetricMeasureBindingKey"
944
- ].filter(K).join(", ")} } from "react-semaphor/data-app-sdk";`,
945
- u ? 'import { fields } from "./fields";' : void 0
946
- ].filter(K).join(`
996
+ "type SemaphorResultColumn"
997
+ ].filter(E).join(", ")} } from "react-semaphor/data-app-sdk";`,
998
+ d ? 'import { fields } from "./fields";' : void 0
999
+ ].filter(E).join(`
947
1000
  `);
948
- return `${H}
949
- ${c}
1001
+ return `${v}
1002
+ ${m}
950
1003
 
951
1004
  export type SemaphorGeneratedRow = Record<string, unknown>;
952
1005
  export type SemaphorGeneratedColumns = readonly SemaphorResultColumn[] | null | undefined;
@@ -956,12 +1009,16 @@ export type SemaphorGeneratedRecordsResult = {
956
1009
  } | null | undefined;
957
1010
  export type SemaphorGeneratedMetricMeasures = Record<string, unknown> | null | undefined;
958
1011
  export type SemaphorGeneratedMetricMeasureBindings = Record<string, string> | null | undefined;
1012
+ export type SemaphorGeneratedMetricValue = number | string | null;
959
1013
  export type SemaphorGeneratedMetricResult = {
960
1014
  readonly measures?: SemaphorGeneratedMetricMeasures;
961
1015
  readonly measureBindings?: SemaphorGeneratedMetricMeasureBindings;
962
1016
  readonly missingMeasures?: readonly string[];
963
1017
  readonly primaryValue: unknown;
964
- readonly value?: unknown;
1018
+ readonly comparisonKind?: string;
1019
+ readonly comparisonValue?: unknown;
1020
+ readonly delta?: number | null;
1021
+ readonly deltaPercent?: number | null;
965
1022
  } | null | undefined;
966
1023
  export type SemaphorGeneratedRoleValues = {
967
1024
  readonly primaryDimension: unknown;
@@ -976,6 +1033,28 @@ export type SemaphorGeneratedTableColumn = {
976
1033
  readonly sortable?: boolean;
977
1034
  readonly sortKey?: string;
978
1035
  };
1036
+ export type SemaphorGeneratedKpiResult<TValues extends Record<string, SemaphorGeneratedMetricValue> = Record<string, SemaphorGeneratedMetricValue>> =
1037
+ Record<string, unknown> & {
1038
+ readonly primaryValue?: SemaphorGeneratedMetricValue;
1039
+ readonly comparisonValue?: SemaphorGeneratedMetricValue;
1040
+ readonly comparisonKind?: string;
1041
+ readonly delta?: number | null;
1042
+ readonly deltaPercent?: number | null;
1043
+ readonly measures: TValues;
1044
+ };
1045
+ export type SemaphorGeneratedKpiMeasureConfig = {
1046
+ key: string;
1047
+ label: string;
1048
+ };
1049
+ export type SemaphorGeneratedKpiProps = {
1050
+ readonly result: SemaphorGeneratedKpiResult;
1051
+ readonly title: string;
1052
+ readonly label: string;
1053
+ readonly value: SemaphorGeneratedMetricValue;
1054
+ readonly measures: SemaphorGeneratedKpiMeasureConfig[];
1055
+ readonly missingMeasures: readonly string[];
1056
+ readonly showComparison: boolean;
1057
+ };
979
1058
 
980
1059
  export const fieldsForView = {
981
1060
  ${n}
@@ -985,20 +1064,16 @@ export const metricFieldsForView = {
985
1064
  ${r}
986
1065
  } as const;
987
1066
 
988
- export const metricMeasureKeysForView = {
989
- ${t}
990
- } as const;
991
-
992
1067
  export const metricMeasureBindingKeysForView = {
993
- ${o}
1068
+ ${t}
994
1069
  } as const;
995
1070
 
996
1071
  export const tableColumnsForView = {
997
- ${y}
1072
+ ${c}
998
1073
  } as const;
999
1074
 
1000
1075
  export const columnKeysForView = {
1001
- ${w}
1076
+ ${S}
1002
1077
  } as const;
1003
1078
 
1004
1079
  export const rowValuesForView = {
@@ -1006,19 +1081,23 @@ ${f}
1006
1081
  } as const;
1007
1082
 
1008
1083
  export const rowsForView = {
1009
- ${m}
1084
+ ${y}
1010
1085
  } as const;
1011
1086
 
1012
1087
  export const roleValuesForView = {
1013
- ${N}
1088
+ ${O}
1014
1089
  } as const;
1015
1090
 
1016
1091
  export const metricValuesForView = {
1017
- ${a}
1092
+ ${o}
1018
1093
  } as const;
1019
1094
 
1020
1095
  export const missingMetricMeasuresForView = {
1021
- ${l}
1096
+ ${a}
1097
+ } as const;
1098
+
1099
+ export const kpiPropsForView = {
1100
+ ${u}
1022
1101
  } as const;
1023
1102
 
1024
1103
  export function resolveColumnKey(
@@ -1062,155 +1141,42 @@ export function readStringCell(
1062
1141
  return value === null || value === undefined ? "" : String(value);
1063
1142
  }
1064
1143
 
1065
- export function readMetricValue(
1066
- measures: SemaphorGeneratedMetricMeasures,
1067
- field: SemaphorFieldRef,
1068
- ): unknown {
1069
- return readMetricValueByKeys(measures, metricKeysForField(field));
1070
- }
1071
-
1072
- export function readMetricValueByKeys(
1073
- measures: SemaphorGeneratedMetricMeasures,
1074
- keys: readonly string[],
1075
- ): unknown {
1076
- if (!measures) {
1077
- return undefined;
1078
- }
1079
- for (const key of keys) {
1080
- if (Object.prototype.hasOwnProperty.call(measures, key)) {
1081
- return measures[key];
1082
- }
1083
- }
1084
- return undefined;
1085
- }
1086
-
1087
1144
  export function readMetricValueByBinding(
1088
1145
  measures: SemaphorGeneratedMetricMeasures,
1089
1146
  measureBindings: SemaphorGeneratedMetricMeasureBindings,
1090
1147
  bindingKey: string,
1091
- fallbackKeys: readonly string[],
1092
1148
  ): unknown {
1093
1149
  const resultKey = measureBindings?.[bindingKey];
1094
1150
  if (resultKey && measures && Object.prototype.hasOwnProperty.call(measures, resultKey)) {
1095
1151
  return measures[resultKey];
1096
1152
  }
1097
- return readMetricValueByKeys(measures, fallbackKeys);
1098
- }
1099
-
1100
- export function readMetricValueByKeysWithFallback(
1101
- measures: SemaphorGeneratedMetricMeasures,
1102
- keys: readonly string[],
1103
- fallbackValue: unknown,
1104
- ): unknown {
1105
- const value = readMetricValueByKeys(measures, keys);
1106
- return value === undefined ? fallbackValue : value;
1107
- }
1108
-
1109
- export function readMetricValueByBindingWithFallback(
1110
- measures: SemaphorGeneratedMetricMeasures,
1111
- measureBindings: SemaphorGeneratedMetricMeasureBindings,
1112
- bindingKey: string,
1113
- fallbackKeys: readonly string[],
1114
- fallbackValue: unknown,
1115
- ): unknown {
1116
- const value = readMetricValueByBinding(measures, measureBindings, bindingKey, fallbackKeys);
1117
- return value === undefined ? fallbackValue : value;
1153
+ return undefined;
1118
1154
  }
1119
1155
 
1120
- export function readNumberMetricValue(
1121
- measures: SemaphorGeneratedMetricMeasures,
1122
- field: SemaphorFieldRef,
1123
- ): number | null {
1124
- const value = readMetricValue(measures, field);
1125
- if (typeof value === "number") {
1126
- return Number.isFinite(value) ? value : null;
1127
- }
1128
- if (typeof value === "string" && value.trim().length > 0) {
1129
- const parsed = Number(value);
1130
- return Number.isFinite(parsed) ? parsed : null;
1131
- }
1132
- return null;
1156
+ export function hasOwnPrimaryMetricValue(
1157
+ result: SemaphorGeneratedMetricResult,
1158
+ ): boolean {
1159
+ return Boolean(result && Object.prototype.hasOwnProperty.call(result, "primaryValue"));
1133
1160
  }
1134
1161
 
1135
- export function readStringMetricValue(
1136
- measures: SemaphorGeneratedMetricMeasures,
1137
- field: SemaphorFieldRef,
1138
- ): string {
1139
- const value = readMetricValue(measures, field);
1140
- return value === null || value === undefined ? "" : String(value);
1162
+ export function mapMetricDisplayValues(
1163
+ values: Record<string, unknown>,
1164
+ ): Record<string, SemaphorGeneratedMetricValue> {
1165
+ return Object.fromEntries(
1166
+ Object.entries(values)
1167
+ .map(([key, value]) => [key, metricDisplayValue(value)] as const)
1168
+ .filter(([key]) => values[key] !== undefined),
1169
+ );
1141
1170
  }
1142
1171
 
1143
- export function metricKeysForField(
1144
- field: SemaphorFieldRef,
1145
- options: { allowNameFallback?: boolean; excludedKeys?: readonly string[] } = {},
1146
- ): string[] {
1147
- const prefixes = metricKeyPrefixesForSource(field.source);
1148
- const aggregate = metricAggregateForField(field);
1149
- const excludedKeys = new Set(options.excludedKeys || []);
1150
- return uniqueStrings([
1151
- metricQualifiedKeyForField(field),
1152
- ...prefixes.map((prefix) => \`\${prefix}.\${field.name}\`),
1153
- \`\${aggregate.toLowerCase()}_\${field.name}\`,
1154
- \`\${aggregate}_\${field.name}\`,
1155
- \`\${field.name}_\${aggregate.toLowerCase()}\`,
1156
- \`\${field.name}_\${aggregate}\`,
1157
- ...(options.allowNameFallback === false ? [] : [field.name]),
1158
- ]).filter((key) => !excludedKeys.has(key));
1159
- }
1160
-
1161
- function metricQualifiedKeyForField(field: SemaphorFieldRef): string {
1162
- return semaphorMetricMeasureBindingKey(field);
1163
- }
1164
-
1165
- function metricAggregateForField(field: SemaphorFieldRef): string {
1166
- return stringProperty(field as Record<string, unknown>, "aggregate")?.toUpperCase() || "SUM";
1167
- }
1168
-
1169
- function metricKeyPrefixesForSource(
1170
- source: SemaphorFieldRef["source"] | undefined,
1171
- ): string[] {
1172
- if (!source) {
1173
- return [];
1172
+ export function metricDisplayValue(value: unknown): SemaphorGeneratedMetricValue {
1173
+ if (value === null || value === undefined) {
1174
+ return null;
1174
1175
  }
1175
- const sourceRecord = source as Record<string, unknown>;
1176
- if (source.kind === "semantic") {
1177
- const prefixes: string[] = [];
1178
- const datasetName = stringProperty(sourceRecord, "datasetName");
1179
- const datasetId = stringProperty(sourceRecord, "datasetId");
1180
- if (datasetName) {
1181
- prefixes.push(datasetName);
1182
- }
1183
- if (datasetId) {
1184
- prefixes.push(datasetId);
1185
- }
1186
- return uniqueStrings(prefixes);
1176
+ if (typeof value === "number" || typeof value === "string") {
1177
+ return value;
1187
1178
  }
1188
- if (source.kind === "physical") {
1189
- const prefixes: string[] = [];
1190
- const databaseName = stringProperty(sourceRecord, "databaseName");
1191
- const schemaName = stringProperty(sourceRecord, "schemaName");
1192
- const tableName = stringProperty(sourceRecord, "tableName");
1193
- if (tableName) {
1194
- prefixes.push(tableName);
1195
- }
1196
- if (schemaName && tableName) {
1197
- prefixes.push(\`\${schemaName}.\${tableName}\`);
1198
- }
1199
- if (databaseName && schemaName && tableName) {
1200
- prefixes.push(\`\${databaseName}.\${schemaName}.\${tableName}\`);
1201
- }
1202
- return uniqueStrings(prefixes);
1203
- }
1204
- return [];
1205
- }
1206
-
1207
- function stringProperty(record: Record<string, unknown>, key: string): string | undefined {
1208
- const value = record[key];
1209
- return typeof value === "string" && value.length > 0 ? value : undefined;
1210
- }
1211
-
1212
- function uniqueStrings(values: string[]): string[] {
1213
- return Array.from(new Set(values.filter((value) => value.length > 0)));
1179
+ return String(value);
1214
1180
  }
1215
1181
 
1216
1182
  function resolveColumn(
@@ -1317,87 +1283,87 @@ function sourcesReferToSameDataset(
1317
1283
  }
1318
1284
  `;
1319
1285
  }
1320
- function Ye(e, n) {
1286
+ function Ze(e, n) {
1321
1287
  const r = D(e, n), t = new Map(
1322
- (E(e) ? Y(e, n) : []).map((o) => [o.fieldName, o.key])
1288
+ (A(e) ? L(e, n) : []).map((o) => [o.fieldName, o.key])
1323
1289
  );
1324
1290
  return r.map((o) => {
1325
- const a = x(o.raw, n), l = a ? t.get(a) : void 0;
1326
- return G({
1291
+ const a = R(o.raw, n), u = a ? t.get(a) : void 0;
1292
+ return N({
1327
1293
  key: o.name,
1328
1294
  label: o.raw.label || o.raw.name,
1329
1295
  dataType: o.raw.dataType,
1330
- sortable: !!l,
1331
- sortKey: l
1296
+ sortable: !!u,
1297
+ sortKey: u
1332
1298
  });
1333
1299
  });
1334
1300
  }
1335
1301
  function We(e) {
1336
- const n = e.checklist.filterScopeByInput || [], r = e.checklist.requiredDevtools || {}, t = e.summary.views.map((u) => u.id).filter(Boolean), o = e.views.map((u) => u.raw.id).filter(Boolean), a = e.inputs.map((u) => u.raw.id).filter(Boolean), l = e.optionQueries.map((u) => u.raw.id || `${u.input.raw.id}-options`).filter(Boolean), y = Object.fromEntries(o.map((u) => [
1337
- u,
1302
+ const n = e.checklist.filterScopeByInput || [], r = e.checklist.requiredDevtools || {}, t = e.summary.views.map((d) => d.id).filter(Boolean), o = e.views.map((d) => d.raw.id).filter(Boolean), a = e.inputs.map((d) => d.raw.id).filter(Boolean), u = e.optionQueries.map((d) => d.raw.id || `${d.input.raw.id}-options`).filter(Boolean), c = Object.fromEntries(o.map((d) => [
1303
+ d,
1338
1304
  e.filterContracts.filter(
1339
- (d) => Array.isArray(d.appliesToViewIds) && d.appliesToViewIds.includes(u)
1340
- ).map((d) => d.inputId)
1341
- ])), w = Object.fromEntries(e.views.map((u) => [
1342
- u.raw.id,
1305
+ (p) => Array.isArray(p.appliesToViewIds) && p.appliesToViewIds.includes(d)
1306
+ ).map((p) => p.inputId)
1307
+ ])), S = Object.fromEntries(e.views.map((d) => [
1308
+ d.raw.id,
1343
1309
  {
1344
- title: u.raw.title,
1345
- visual: u.raw.visual,
1346
- visualSpec: u.raw.visualSpec,
1347
- queryKind: u.raw.queryKind,
1348
- sdkBuilder: u.raw.sdkBuilder
1310
+ title: d.raw.title,
1311
+ visual: d.raw.visual,
1312
+ visualSpec: d.raw.visualSpec,
1313
+ queryKind: d.raw.queryKind,
1314
+ sdkBuilder: d.raw.sdkBuilder
1349
1315
  }
1350
- ])), f = Object.fromEntries(e.views.map((u) => {
1351
- var d;
1316
+ ])), f = Object.fromEntries(e.views.map((d) => {
1317
+ var p;
1352
1318
  return [
1353
- u.raw.id,
1354
- G({
1355
- viewId: u.raw.id,
1356
- queryId: u.name,
1357
- title: u.raw.title,
1358
- visualType: ((d = u.raw.visualSpec) == null ? void 0 : d.visualType) || u.raw.visual,
1359
- suggestedComponentName: me(u.raw.title || u.raw.id || u.name),
1319
+ d.raw.id,
1320
+ N({
1321
+ viewId: d.raw.id,
1322
+ queryId: d.name,
1323
+ title: d.raw.title,
1324
+ visualType: ((p = d.raw.visualSpec) == null ? void 0 : p.visualType) || d.raw.visual,
1325
+ suggestedComponentName: me(d.raw.title || d.raw.id || d.name),
1360
1326
  marker: {
1361
1327
  attribute: "data-semaphor-view-id",
1362
- value: u.raw.id
1328
+ value: d.raw.id
1363
1329
  }
1364
1330
  })
1365
1331
  ];
1366
- })), m = Object.fromEntries(e.inputs.map((u) => {
1367
- var d;
1332
+ })), y = Object.fromEntries(e.inputs.map((d) => {
1333
+ var p;
1368
1334
  return [
1369
- u.raw.id,
1370
- G({
1371
- inputId: u.raw.id,
1372
- label: u.raw.label,
1373
- type: u.raw.type,
1374
- optionQueryId: ((d = u.raw.optionQuery) == null ? void 0 : d.id) || (u.raw.optionQuery ? `${u.raw.id}-options` : void 0),
1375
- suggestedComponentName: me(u.raw.label || u.raw.id || u.name),
1335
+ d.raw.id,
1336
+ N({
1337
+ inputId: d.raw.id,
1338
+ label: d.raw.label,
1339
+ type: d.raw.type,
1340
+ optionQueryId: ((p = d.raw.optionQuery) == null ? void 0 : p.id) || (d.raw.optionQuery ? `${d.raw.id}-options` : void 0),
1341
+ suggestedComponentName: me(d.raw.label || d.raw.id || d.name),
1376
1342
  marker: {
1377
1343
  attribute: "data-semaphor-input-id",
1378
- value: u.raw.id
1344
+ value: d.raw.id
1379
1345
  }
1380
1346
  })
1381
1347
  ];
1382
- })), N = Object.fromEntries(e.views.map((u) => {
1383
- var d, c, i;
1348
+ })), O = Object.fromEntries(e.views.map((d) => {
1349
+ var p, m, i;
1384
1350
  return [
1385
- u.name,
1386
- G({
1387
- viewId: u.raw.id,
1388
- viewTitle: ((d = u.raw.visualSpec) == null ? void 0 : d.title) || u.raw.title,
1389
- visualType: (c = u.raw.visualSpec) == null ? void 0 : c.visualType,
1390
- title: ((i = u.raw.visualSpec) == null ? void 0 : i.title) || u.raw.title
1351
+ d.name,
1352
+ N({
1353
+ viewId: d.raw.id,
1354
+ viewTitle: ((p = d.raw.visualSpec) == null ? void 0 : p.title) || d.raw.title,
1355
+ visualType: (m = d.raw.visualSpec) == null ? void 0 : m.visualType,
1356
+ title: ((i = d.raw.visualSpec) == null ? void 0 : i.title) || d.raw.title
1391
1357
  })
1392
1358
  ];
1393
1359
  }));
1394
- return `${H}
1360
+ return `${v}
1395
1361
  export const generatedViewIds = ${k(t)} as const;
1396
1362
  export const generatedQueryViewIds = ${k(o)} as const;
1397
1363
  export const generatedInputIds = ${k(a)} as const;
1398
- export const generatedInputOptionQueryIds = ${k(l)} as const;
1364
+ export const generatedInputOptionQueryIds = ${k(u)} as const;
1399
1365
  export const generatedViewAuthoring = ${k(f)} as const;
1400
- export const generatedInputAuthoring = ${k(m)} as const;
1366
+ export const generatedInputAuthoring = ${k(y)} as const;
1401
1367
 
1402
1368
  export type SemaphorGeneratedViewId = typeof generatedViewIds[number];
1403
1369
  export type SemaphorGeneratedQueryViewId = typeof generatedQueryViewIds[number];
@@ -1416,7 +1382,7 @@ export type SemaphorGeneratedFilterContract = {
1416
1382
  readonly [key: string]: unknown;
1417
1383
  };
1418
1384
 
1419
- export const generatedInputIdsForView = ${k(y)} as const;
1385
+ export const generatedInputIdsForView = ${k(c)} as const;
1420
1386
  export const generatedFilterContracts: readonly SemaphorGeneratedFilterContract[] = ${k(e.filterContracts)} as const;
1421
1387
 
1422
1388
  export function semaphorViewMarkerProps(viewId: SemaphorGeneratedViewId) {
@@ -1437,7 +1403,7 @@ export function filterContractsForView(viewId: SemaphorGeneratedQueryViewId) {
1437
1403
  );
1438
1404
  }
1439
1405
 
1440
- export const queryDebugForView = ${k(N)} as const;
1406
+ export const queryDebugForView = ${k(O)} as const;
1441
1407
 
1442
1408
  export const semaphorGeneratedContractMetadata = ${k({
1443
1409
  schemaVersion: "semaphor-generated-data-app-contract/v1",
@@ -1448,17 +1414,17 @@ export const semaphorGeneratedContractMetadata = ${k({
1448
1414
  generatedViewIds: t,
1449
1415
  generatedQueryViewIds: o,
1450
1416
  generatedInputIds: a,
1451
- generatedInputOptionQueryIds: l,
1452
- generatedInputIdsForView: y,
1417
+ generatedInputOptionQueryIds: u,
1418
+ generatedInputIdsForView: c,
1453
1419
  generatedViewAuthoring: f,
1454
- generatedInputAuthoring: m,
1455
- visualSpecs: w,
1420
+ generatedInputAuthoring: y,
1421
+ visualSpecs: S,
1456
1422
  presentationViews: e.presentationViews
1457
1423
  })} as const;
1458
1424
  `;
1459
1425
  }
1460
- function Ze() {
1461
- return `${H}
1426
+ function Xe() {
1427
+ return `${v}
1462
1428
  export * from "./sources";
1463
1429
  export * from "./fields";
1464
1430
  export * from "./inputs";
@@ -1468,48 +1434,42 @@ export * from "./accessors";
1468
1434
  export * from "./metadata";
1469
1435
  `;
1470
1436
  }
1471
- function Q(e, n) {
1437
+ function B(e, n) {
1472
1438
  if (!(!n || typeof n != "object")) {
1473
1439
  if (Array.isArray(n)) {
1474
- for (const r of n) Q(e, r);
1440
+ for (const r of n) B(e, r);
1475
1441
  return;
1476
1442
  }
1477
- C(n) && h(e, U(n));
1443
+ x(n) && w(e, Y(n));
1478
1444
  for (const r of Object.values(n))
1479
- Q(e, r);
1445
+ B(e, r);
1480
1446
  }
1481
1447
  }
1482
1448
  function D(e, n) {
1483
1449
  const r = [];
1484
- if (tn(r, e.raw.sdkSpec), r.length === 0)
1450
+ if (on(r, e.raw.sdkSpec), r.length === 0)
1485
1451
  for (const o of e.raw.fields || [])
1486
- h(r, o);
1452
+ w(r, o);
1487
1453
  const t = X(
1488
- r.filter((o) => o.name && x(o, n)).map((o) => ({ raw: o, key: L(o), name: "" })),
1454
+ r.filter((o) => o.name && R(o, n)).map((o) => ({ raw: o, key: Z(o), name: "" })),
1489
1455
  (o) => o.key
1490
1456
  );
1491
- return v(
1492
- t,
1493
- (o) => q(o.raw.label || o.raw.name || "field")
1494
- ), t;
1457
+ return ge(t, n, "field"), t;
1495
1458
  }
1496
- function P(e, n) {
1497
- if (B(e.raw.sdkSpec.builder) !== "metric")
1459
+ function Q(e, n) {
1460
+ if (q(e.raw.sdkSpec.builder) !== "metric")
1498
1461
  return [];
1499
- const r = V(e.raw.sdkSpec.spec), t = [];
1500
- h(t, r == null ? void 0 : r.primaryMeasure);
1501
- for (const a of j(r == null ? void 0 : r.measures))
1502
- h(t, a);
1462
+ const r = F(e.raw.sdkSpec.spec), t = [];
1463
+ w(t, r == null ? void 0 : r.primaryMeasure);
1464
+ for (const a of H(r == null ? void 0 : r.measures))
1465
+ w(t, a);
1503
1466
  const o = X(
1504
- t.filter((a) => a.name && x(a, n)).map((a) => ({ raw: a, key: L(a), name: "" })),
1467
+ t.filter((a) => a.name && R(a, n)).map((a) => ({ raw: a, key: Z(a), name: "" })),
1505
1468
  (a) => a.key
1506
1469
  );
1507
- return v(
1508
- o,
1509
- (a) => q(a.raw.label || a.raw.name || "metric")
1510
- ), o;
1470
+ return ge(o, n, "metric"), o;
1511
1471
  }
1512
- function Xe(e, n, r) {
1472
+ function en(e, n, r) {
1513
1473
  var o;
1514
1474
  const t = (o = e.raw.metricBindingKeys) == null ? void 0 : o[r];
1515
1475
  if (typeof t == "string" && t.trim())
@@ -1518,93 +1478,91 @@ function Xe(e, n, r) {
1518
1478
  `views.${e.raw.id}.metricBindingKeys must include a binding key for metric field ${n.raw.name}.`
1519
1479
  );
1520
1480
  }
1521
- function en(e, n) {
1522
- if (n.length === 1)
1523
- return /* @__PURE__ */ new Set([n[0].name]);
1524
- const r = V(e.raw.sdkSpec.spec);
1525
- if (!C(r == null ? void 0 : r.primaryMeasure))
1526
- return /* @__PURE__ */ new Set();
1527
- const t = L(U(r.primaryMeasure)), o = n.find((a) => a.key === t);
1528
- return o ? /* @__PURE__ */ new Set([o.name]) : /* @__PURE__ */ new Set();
1529
- }
1530
- function nn(e) {
1531
- const n = /* @__PURE__ */ new Map();
1532
- for (const r of e)
1533
- for (const t of new Set(he(r.raw)))
1534
- n.set(t, (n.get(t) || 0) + 1);
1535
- return new Set(
1536
- Array.from(n.entries()).filter(([, r]) => r > 1).map(([r]) => r)
1537
- );
1481
+ function ge(e, n, r) {
1482
+ const t = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
1483
+ for (const u of e) {
1484
+ const c = K(u.raw.name || u.raw.label || r) || r;
1485
+ t.set(u.key, c), o.set(c, (o.get(c) || 0) + 1);
1486
+ }
1487
+ const a = /* @__PURE__ */ new Set();
1488
+ for (const u of e) {
1489
+ const c = t.get(u.key) || r, S = R(u.raw, n) || c, f = o.get(c) === 1 ? c : S;
1490
+ u.name = nn(f, u.key, a);
1491
+ }
1538
1492
  }
1539
- function he(e) {
1540
- const n = (e.aggregate || "SUM").toUpperCase();
1541
- return _([
1542
- `${n.toLowerCase()}_${e.name}`,
1543
- `${n}_${e.name}`,
1544
- `${e.name}_${n.toLowerCase()}`,
1545
- `${e.name}_${n}`,
1546
- e.name
1547
- ]);
1493
+ function nn(e, n, r) {
1494
+ const t = tn(e) ? e : K(e || "field") || "field";
1495
+ if (!r.has(t))
1496
+ return r.add(t), t;
1497
+ const o = rn(n), a = `${t}${o}`;
1498
+ if (!r.has(a))
1499
+ return r.add(a), a;
1500
+ let u = 2;
1501
+ for (; r.has(`${a}${u}`); )
1502
+ u += 1;
1503
+ const c = `${a}${u}`;
1504
+ return r.add(c), c;
1548
1505
  }
1549
1506
  function rn(e) {
1550
- const n = /* @__PURE__ */ new Map();
1551
- for (const r of e)
1552
- n.set(r.raw.name, (n.get(r.raw.name) || 0) + 1);
1553
- return new Set(
1554
- Array.from(n.entries()).filter(([, r]) => r > 1).map(([r]) => r)
1555
- );
1507
+ let n = 0;
1508
+ for (let r = 0; r < e.length; r += 1)
1509
+ n = n * 31 + e.charCodeAt(r) >>> 0;
1510
+ return n.toString(36).slice(0, 6).replace(/^[0-9]/, "x$&");
1556
1511
  }
1557
- function tn(e, n) {
1558
- const r = V(n.spec);
1512
+ function tn(e) {
1513
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e);
1514
+ }
1515
+ function on(e, n) {
1516
+ const r = F(n.spec);
1559
1517
  if (!r)
1560
1518
  return;
1561
- const t = B(n.builder);
1519
+ const t = q(n.builder);
1562
1520
  if (t === "records") {
1563
- for (const o of j(r.fields)) h(e, o);
1521
+ for (const o of H(r.fields)) w(e, o);
1564
1522
  return;
1565
1523
  }
1566
1524
  if (t === "sql") {
1567
- for (const o of j(r.fields)) h(e, o);
1525
+ for (const o of H(r.fields)) w(e, o);
1568
1526
  return;
1569
1527
  }
1570
1528
  if (t === "analysis" || t === "metric") {
1571
- h(e, r.primaryMeasure);
1572
- for (const o of j(r.measures)) h(e, o);
1573
- for (const o of j(r.dimensions)) h(e, o);
1574
- h(e, r.dateField);
1529
+ w(e, r.primaryMeasure);
1530
+ for (const o of H(r.measures)) w(e, o);
1531
+ for (const o of H(r.dimensions)) w(e, o);
1532
+ w(e, r.dateField);
1575
1533
  return;
1576
1534
  }
1577
1535
  if (t === "matrix") {
1578
- const o = pe(r.rows), a = pe(r.columns), l = j(r.values);
1579
- for (const y of o) le(e, y);
1580
- for (const y of a) le(e, y);
1581
- for (const y of l) {
1582
- const w = V(y);
1583
- h(e, w == null ? void 0 : w.field), h(e, w == null ? void 0 : w.measure);
1536
+ const o = pe(r.rows), a = pe(r.columns), u = H(r.values);
1537
+ for (const c of o) le(e, c);
1538
+ for (const c of a) le(e, c);
1539
+ for (const c of u) {
1540
+ const S = F(c);
1541
+ w(e, S == null ? void 0 : S.field), w(e, S == null ? void 0 : S.measure);
1584
1542
  }
1585
1543
  }
1586
1544
  }
1587
1545
  function pe(e) {
1588
1546
  if (Array.isArray(e))
1589
1547
  return e;
1590
- const n = V(e);
1548
+ const n = F(e);
1591
1549
  return Array.isArray(n == null ? void 0 : n.levels) ? n.levels : [];
1592
1550
  }
1593
1551
  function le(e, n) {
1594
1552
  var r;
1595
- if (C(n)) {
1596
- h(e, n);
1553
+ if (x(n)) {
1554
+ w(e, n);
1597
1555
  return;
1598
1556
  }
1599
- h(e, (r = V(n)) == null ? void 0 : r.field);
1557
+ w(e, (r = F(n)) == null ? void 0 : r.field);
1600
1558
  }
1601
1559
  function ce(e) {
1602
1560
  var n, r, t, o;
1603
1561
  return ((n = e == null ? void 0 : e.computation) == null ? void 0 : n.kind) === "presentation_only" || ((r = e == null ? void 0 : e.computation) == null ? void 0 : r.kind) === "derived" || ((t = e == null ? void 0 : e.computation) == null ? void 0 : t.kind) === "unsupported" || (e == null ? void 0 : e.visual) === "text_block" || ((o = e == null ? void 0 : e.visualSpec) == null ? void 0 : o.visualType) === "text_block";
1604
1562
  }
1605
- function on(e) {
1606
- const n = V(e) || {};
1607
- return G({
1563
+ function sn(e) {
1564
+ const n = F(e) || {};
1565
+ return N({
1608
1566
  id: e.id,
1609
1567
  title: e.title,
1610
1568
  purpose: e.purpose,
@@ -1618,10 +1576,10 @@ function on(e) {
1618
1576
  description: n.description
1619
1577
  });
1620
1578
  }
1621
- function h(e, n) {
1622
- C(n) && e.push(U(n));
1579
+ function w(e, n) {
1580
+ x(n) && e.push(Y(n));
1623
1581
  }
1624
- function U(e) {
1582
+ function Y(e) {
1625
1583
  return {
1626
1584
  name: e.name,
1627
1585
  label: e.label,
@@ -1632,7 +1590,7 @@ function U(e) {
1632
1590
  ...e.source ? { source: e.source } : {}
1633
1591
  };
1634
1592
  }
1635
- function sn(e) {
1593
+ function an(e) {
1636
1594
  if (!e.source)
1637
1595
  return;
1638
1596
  const n = {
@@ -1647,48 +1605,48 @@ function sn(e) {
1647
1605
  name: ""
1648
1606
  };
1649
1607
  }
1650
- function C(e) {
1651
- const n = V(e);
1608
+ function x(e) {
1609
+ const n = F(e);
1652
1610
  return !!(n && typeof n.name == "string" && (typeof n.role == "string" || typeof n.dataType == "string" || typeof n.aggregate == "string" || n.source || n.sourceKey));
1653
1611
  }
1654
1612
  function we(e) {
1655
- const n = V(e);
1613
+ const n = F(e);
1656
1614
  return !!(n && (typeof n.sourceKey == "string" || n.kind === "semantic" || typeof n.datasetName == "string" && typeof n.domainId == "string"));
1657
1615
  }
1658
- function O(e, n) {
1616
+ function G(e, n) {
1659
1617
  if (e === void 0)
1660
1618
  return "undefined";
1661
1619
  if (e === null || typeof e == "number" || typeof e == "boolean" || typeof e == "string")
1662
1620
  return JSON.stringify(e);
1663
1621
  if (Array.isArray(e))
1664
- return `[${e.map((o) => O(o, n)).join(", ")}]`;
1665
- if (C(e)) {
1666
- const o = x(U(e), n);
1622
+ return `[${e.map((o) => G(o, n)).join(", ")}]`;
1623
+ if (x(e)) {
1624
+ const o = R(Y(e), n);
1667
1625
  if (o) return `fields.${o}`;
1668
1626
  }
1669
1627
  if (we(e)) {
1670
1628
  const o = Se(e, n);
1671
1629
  if (o) return `sources.${o}`;
1672
1630
  }
1673
- const r = V(e);
1674
- return r ? `{ ${Object.entries(r).filter(([, o]) => o !== void 0).map(([o, a]) => `${JSON.stringify(o)}: ${O(a, n)}`).join(", ")} }` : JSON.stringify(e);
1631
+ const r = F(e);
1632
+ return r ? `{ ${Object.entries(r).filter(([, o]) => o !== void 0).map(([o, a]) => `${JSON.stringify(o)}: ${G(a, n)}`).join(", ")} }` : JSON.stringify(e);
1675
1633
  }
1676
1634
  function k(e) {
1677
1635
  return JSON.stringify(e, null, 2);
1678
1636
  }
1679
- function x(e, n) {
1680
- if (C(e))
1681
- return n.fieldNameByKey.get(L(U(e)));
1637
+ function R(e, n) {
1638
+ if (x(e))
1639
+ return n.fieldNameByKey.get(Z(Y(e)));
1682
1640
  }
1683
1641
  function Se(e, n) {
1684
1642
  if (we(e))
1685
- for (const r of Z(e)) {
1643
+ for (const r of W(e)) {
1686
1644
  const t = n.sourceNameByKey.get(r);
1687
1645
  if (t)
1688
1646
  return t;
1689
1647
  }
1690
1648
  }
1691
- function L(e) {
1649
+ function Z(e) {
1692
1650
  return [
1693
1651
  e.sourceKey || "",
1694
1652
  e.name || "",
@@ -1696,29 +1654,29 @@ function L(e) {
1696
1654
  e.aggregate || ""
1697
1655
  ].join("|");
1698
1656
  }
1699
- function an(e, n) {
1700
- return !C(e) || !C(n) || e.name !== n.name ? !1 : ie(e).some(
1657
+ function un(e, n) {
1658
+ return !x(e) || !x(n) || e.name !== n.name ? !1 : ie(e).some(
1701
1659
  (r) => ie(n).includes(r)
1702
1660
  );
1703
1661
  }
1704
- function un(e) {
1705
- return C(e) && e.role === "id";
1706
- }
1707
1662
  function dn(e) {
1663
+ return x(e) && e.role === "id";
1664
+ }
1665
+ function pn(e) {
1708
1666
  const n = [], r = /* @__PURE__ */ new Map();
1709
1667
  for (const t of e) {
1710
- const o = _(t.aliases.length ? t.aliases : [t.key]), a = o.map((l) => r.get(l)).find(K);
1668
+ const o = _(t.aliases.length ? t.aliases : [t.key]), a = o.map((u) => r.get(u)).find(E);
1711
1669
  if (a) {
1712
1670
  a.aliases = _([...a.aliases, ...o]);
1713
1671
  continue;
1714
1672
  }
1715
1673
  t.aliases = o, n.push(t);
1716
- for (const l of o)
1717
- r.set(l, t);
1674
+ for (const u of o)
1675
+ r.set(u, t);
1718
1676
  }
1719
1677
  return n;
1720
1678
  }
1721
- function pn(e) {
1679
+ function ln(e) {
1722
1680
  const n = /* @__PURE__ */ new Map();
1723
1681
  for (const r of e)
1724
1682
  for (const t of _([r.key, ...r.aliases])) {
@@ -1733,10 +1691,10 @@ function _(e) {
1733
1691
  return Array.from(new Set(e.filter(Boolean)));
1734
1692
  }
1735
1693
  function $e(e) {
1736
- return Z(e)[0] || de(e);
1694
+ return W(e)[0] || de(e);
1737
1695
  }
1738
- function Z(e) {
1739
- const n = V(e);
1696
+ function W(e) {
1697
+ const n = F(e);
1740
1698
  if (!n)
1741
1699
  return [];
1742
1700
  const r = [];
@@ -1747,36 +1705,36 @@ function Z(e) {
1747
1705
  return r.length === 0 && r.push(de(e)), _(r);
1748
1706
  }
1749
1707
  function Ie(e) {
1750
- return Z(e);
1708
+ return W(e);
1751
1709
  }
1752
1710
  function de(e) {
1753
- const n = V(e);
1711
+ const n = F(e);
1754
1712
  return n ? typeof n.sourceKey == "string" ? n.sourceKey : JSON.stringify(n) : "";
1755
1713
  }
1756
- function ln(e) {
1757
- return C(e) && ie(e)[0] || "";
1714
+ function cn(e) {
1715
+ return x(e) && ie(e)[0] || "";
1758
1716
  }
1759
1717
  function ie(e) {
1760
- return C(e) ? _([
1718
+ return x(e) ? _([
1761
1719
  ...typeof e.sourceKey == "string" ? [e.sourceKey] : [],
1762
- ...e.source ? Z(e.source) : []
1720
+ ...e.source ? W(e.source) : []
1763
1721
  ]) : [];
1764
1722
  }
1765
- function B(e) {
1723
+ function q(e) {
1766
1724
  const n = String(e || "").replace(/^semaphor\./, "");
1767
1725
  if (!["metric", "records", "analysis", "matrix", "sql"].includes(n))
1768
1726
  throw new Error(`Unsupported sdkSpec builder: ${e}`);
1769
1727
  return n;
1770
1728
  }
1771
- function cn(e) {
1772
- const n = B(e);
1729
+ function mn(e) {
1730
+ const n = q(e);
1773
1731
  return n === "records" || n === "sql";
1774
1732
  }
1775
- function mn(e) {
1776
- const n = V(e);
1733
+ function fn(e) {
1734
+ const n = F(e);
1777
1735
  return typeof (n == null ? void 0 : n.operator) == "string" ? n.operator : e.type === "date_range" ? "between" : e.type === "multi_select" || e.type === "select" ? "in" : "=";
1778
1736
  }
1779
- function v(e, n) {
1737
+ function P(e, n) {
1780
1738
  const r = /* @__PURE__ */ new Map();
1781
1739
  for (const t of e) {
1782
1740
  const o = n(t) || "item", a = r.get(o) || 0;
@@ -1791,7 +1749,7 @@ function X(e, n) {
1791
1749
  }
1792
1750
  return t;
1793
1751
  }
1794
- function q(e) {
1752
+ function K(e) {
1795
1753
  const n = String(e || "").replace(/[^A-Za-z0-9]+/g, " ").trim().split(/\s+/).filter(Boolean);
1796
1754
  if (n.length === 0)
1797
1755
  return "item";
@@ -1802,47 +1760,47 @@ function q(e) {
1802
1760
  return /^[A-Za-z_$]/.test(o) ? o : `item${o}`;
1803
1761
  }
1804
1762
  function me(e) {
1805
- const n = q(e);
1763
+ const n = K(e);
1806
1764
  return n.charAt(0).toUpperCase() + n.slice(1);
1807
1765
  }
1808
- function fn(e) {
1766
+ function yn(e) {
1809
1767
  const n = String(e).split(":");
1810
1768
  return n[n.length - 1] || String(e);
1811
1769
  }
1812
- function G(e) {
1770
+ function N(e) {
1813
1771
  return Object.fromEntries(Object.entries(e).filter(([, n]) => n !== void 0));
1814
1772
  }
1815
- function V(e) {
1773
+ function F(e) {
1816
1774
  return e && typeof e == "object" && !Array.isArray(e) ? e : void 0;
1817
1775
  }
1818
- function j(e) {
1776
+ function H(e) {
1819
1777
  return Array.isArray(e) ? e : [];
1820
1778
  }
1821
- function z(e) {
1779
+ function J(e) {
1822
1780
  return typeof e == "number" && Number.isFinite(e) ? e : void 0;
1823
1781
  }
1824
- function K(e) {
1782
+ function E(e) {
1825
1783
  return e !== void 0;
1826
1784
  }
1827
1785
  export {
1828
- Rn as CODEGEN_SUMMARY_SCHEMA_VERSION,
1786
+ Mn as CODEGEN_SUMMARY_SCHEMA_VERSION,
1829
1787
  Re as CODEGEN_SUMMARY_VALIDATOR_VERSION,
1830
1788
  Me as CONTRACT_MANIFEST_SCHEMA_VERSION,
1831
- hn as DEFAULT_GENERATED_CONTRACT_OUTPUT_DIR,
1789
+ wn as DEFAULT_GENERATED_CONTRACT_OUTPUT_DIR,
1832
1790
  fe as GENERATED_CONTRACT_SCHEMA_VERSION,
1833
- Mn as GENERATED_CONTRACT_TYPESCRIPT_FILES,
1834
- xn as REQUIRED_GENERATED_CONTRACT_FILES,
1835
- In as SEMAPHOR_DATA_APP_CODEGEN_SUMMARY_SCHEMA_VERSION,
1791
+ Cn as GENERATED_CONTRACT_TYPESCRIPT_FILES,
1792
+ On as REQUIRED_GENERATED_CONTRACT_FILES,
1793
+ Vn as SEMAPHOR_DATA_APP_CODEGEN_SUMMARY_SCHEMA_VERSION,
1836
1794
  Fn as SEMAPHOR_DATA_APP_CODEGEN_SUMMARY_VALIDATOR_VERSION,
1837
1795
  ke as assertValidCodegenSummary,
1838
- Nn as buildSemaphorGeneratedActiveInput,
1839
- Cn as buildSemaphorGeneratedInputOptionIntent,
1840
- On as buildSemaphorGeneratedViewExecutionRequest,
1841
- Gn as buildSemaphorGeneratedViewExecutionRequests,
1842
- Kn as evaluateSemaphorDataAppContractUpdatePolicy,
1843
- wn as generateSemaphorDataAppContract,
1796
+ xn as buildSemaphorGeneratedActiveInput,
1797
+ Gn as buildSemaphorGeneratedInputOptionIntent,
1798
+ Nn as buildSemaphorGeneratedViewExecutionRequest,
1799
+ En as buildSemaphorGeneratedViewExecutionRequests,
1800
+ An as evaluateSemaphorDataAppContractUpdatePolicy,
1801
+ Sn as generateSemaphorDataAppContract,
1844
1802
  bn as isSemaphorDataAppCodegenSummary,
1845
- En as validateCodegenSummary,
1846
- Vn as validateSemaphorDataAppCodegenSummary,
1847
- An as validateSemaphorGeneratedContract
1803
+ jn as validateCodegenSummary,
1804
+ kn as validateSemaphorDataAppCodegenSummary,
1805
+ vn as validateSemaphorGeneratedContract
1848
1806
  };