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.
- package/dist/analytics-protocol/index.cjs +1 -1
- package/dist/analytics-protocol/index.js +2 -2
- package/dist/brand-studio/index.cjs +1 -1
- package/dist/brand-studio/index.js +2 -2
- package/dist/chunks/analyze-result-contract-BUgK3759.js +1833 -0
- package/dist/chunks/analyze-result-contract-S8u7CcPL.js +1 -0
- package/dist/chunks/{calendar-preferences-dialog-DwLeBLy2.js → calendar-preferences-dialog-Ci3rHHgA.js} +1 -1
- package/dist/chunks/{calendar-preferences-dialog-49fcEPXS.js → calendar-preferences-dialog-i3-jBIYS.js} +3 -3
- package/dist/chunks/{dashboard-briefing-launcher-cgPKz1yX.js → dashboard-briefing-launcher-BpwjeJsQ.js} +4 -4
- package/dist/chunks/{dashboard-briefing-launcher-CgkSKkZR.js → dashboard-briefing-launcher-DiEpMS9E.js} +1 -1
- package/dist/chunks/{dashboard-controls-D12ZSUP_.js → dashboard-controls-BaUUrvSI.js} +1 -1
- package/dist/chunks/{dashboard-controls-VMFm3OP4.js → dashboard-controls-Bkjpgr3d.js} +5 -5
- package/dist/chunks/{dashboard-json-CvK0oI24.js → dashboard-json-CxNyExRm.js} +1 -1
- package/dist/chunks/{dashboard-json-C-GG5yC7.js → dashboard-json-DvULhhN2.js} +3 -3
- package/dist/chunks/{edit-dashboard-visual-B5KB7dx4.js → edit-dashboard-visual-DBrsgEtL.js} +4 -4
- package/dist/chunks/{edit-dashboard-visual-ql99faTz.js → edit-dashboard-visual-DJRPiKdY.js} +1 -1
- package/dist/chunks/{index-DXCBPLDu.js → index-BepF6hoa.js} +2 -2
- package/dist/chunks/{index-CQmKDEbe.js → index-Drz04wqE.js} +5 -5
- package/dist/chunks/{switch-B79Hn4Qh.js → switch-D2oOmorN.js} +1 -1
- package/dist/chunks/{switch-BXQAlSuW.js → switch-qUw8u-gU.js} +1 -1
- package/dist/chunks/update-policy-BmtOqvbf.js +3 -0
- package/dist/chunks/update-policy-KImUg4Od.js +831 -0
- package/dist/chunks/{use-create-flow-overlay-state-Bw5LRkf9.js → use-create-flow-overlay-state-CFJIHt5D.js} +3 -3
- package/dist/chunks/{use-create-flow-overlay-state-7MFN3PWX.js → use-create-flow-overlay-state-DrkYiyQz.js} +1 -1
- package/dist/chunks/{validators-4EGCWWga.js → validators-B1Mgdr3T.js} +279 -242
- package/dist/chunks/{validators-CPtkrola.js → validators-DFOX0tYY.js} +1 -1
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/dashboard-authoring/index.cjs +1 -1
- package/dist/dashboard-authoring/index.js +2 -2
- package/dist/data-app-builder/index.cjs +1 -1
- package/dist/data-app-builder/index.js +2 -2
- package/dist/data-app-codegen/index.cjs +1 -0
- package/dist/data-app-codegen/index.js +22 -0
- package/dist/data-app-codegen-node/index.cjs +462 -0
- package/dist/data-app-codegen-node/index.js +1424 -0
- package/dist/data-app-sdk/index.cjs +2 -2
- package/dist/data-app-sdk/index.js +3 -2
- package/dist/data-app-sdk-adapters/index.cjs +1 -1
- package/dist/data-app-sdk-adapters/index.js +20 -12
- package/dist/data-app-sdk-validation/index.cjs +1 -1
- package/dist/data-app-sdk-validation/index.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +7 -7
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/analytics-protocol.d.ts +101 -2
- package/dist/types/dashboard-assistant.d.ts +14 -0
- package/dist/types/dashboard-authoring.d.ts +6 -0
- package/dist/types/data-app-builder.d.ts +6 -0
- package/dist/types/data-app-codegen-node.d.ts +1165 -0
- package/dist/types/data-app-codegen.d.ts +1137 -0
- package/dist/types/data-app-sdk-adapters.d.ts +7 -0
- package/dist/types/data-app-sdk-validation.d.ts +15 -0
- package/dist/types/data-app-sdk.d.ts +18 -0
- package/dist/types/main.d.ts +6 -0
- package/package.json +9 -1
- package/dist/chunks/analyze-result-contract-C9Gv2_qW.js +0 -1585
- package/dist/chunks/analyze-result-contract-Zgg-Bbpj.js +0 -1
|
@@ -0,0 +1,1424 @@
|
|
|
1
|
+
import { S as ln, a as cn, i as mn, v as fn } from "../chunks/analyze-result-contract-BUgK3759.js";
|
|
2
|
+
import { c as Ie, G as ce, a as $e, b as Fe } from "../chunks/update-policy-KImUg4Od.js";
|
|
3
|
+
import { C as hn, e as gn, R as Sn, f as wn, g as In, h as $n, i as Fn, j as bn, v as Vn, d as Rn } from "../chunks/update-policy-KImUg4Od.js";
|
|
4
|
+
import { createHash as me } from "node:crypto";
|
|
5
|
+
const an = "src/semaphor/generated", q = `// Generated by Semaphor Agent Plugin. Do not hand-edit analytics wiring here.
|
|
6
|
+
// Regenerate from the accepted semaphor_plan_data_app codegenSummary when the plan changes.
|
|
7
|
+
`;
|
|
8
|
+
function un(e, n = {}) {
|
|
9
|
+
Ie(e);
|
|
10
|
+
const r = be(e);
|
|
11
|
+
if (r.views.length === 0 && !n.allowEmpty)
|
|
12
|
+
throw new Error(
|
|
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
|
+
);
|
|
15
|
+
const o = Re(r), t = Ce({
|
|
16
|
+
contract: r,
|
|
17
|
+
files: o,
|
|
18
|
+
generatorName: n.generatorName || "react-semaphor/data-app-codegen/node",
|
|
19
|
+
generatorVersion: n.generatorVersion || "unknown"
|
|
20
|
+
}), i = {
|
|
21
|
+
...o,
|
|
22
|
+
"contract.manifest.json": `${JSON.stringify(t, null, 2)}
|
|
23
|
+
`
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
schemaVersion: ce,
|
|
27
|
+
files: i,
|
|
28
|
+
manifest: t,
|
|
29
|
+
contentHash: String(t.generatedContentHash || ""),
|
|
30
|
+
usageExample: Ne(r),
|
|
31
|
+
warnings: r.warnings,
|
|
32
|
+
stats: {
|
|
33
|
+
inputCount: r.inputs.length,
|
|
34
|
+
executableViewCount: r.views.length,
|
|
35
|
+
presentationViewCount: r.presentationViews.length,
|
|
36
|
+
queryCount: r.views.length,
|
|
37
|
+
optionQueryCount: r.optionQueries.length
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function be(e) {
|
|
42
|
+
var V, d, c, g, f, $, R, F, k, G, w, C;
|
|
43
|
+
const n = [], r = [];
|
|
44
|
+
for (const s of e.inputs) {
|
|
45
|
+
y(r, s.fieldRef);
|
|
46
|
+
for (const h of s.bindings || [])
|
|
47
|
+
y(r, h.fieldRef);
|
|
48
|
+
y(r, (V = s.optionQuery) == null ? void 0 : V.valueFieldRef), y(r, (d = s.optionQuery) == null ? void 0 : d.labelFieldRef), y(r, (c = s.optionQuery) == null ? void 0 : c.filterFieldRef), Q(r, (g = s.optionQuery) == null ? void 0 : g.spec);
|
|
49
|
+
}
|
|
50
|
+
for (const s of e.filterContracts) {
|
|
51
|
+
y(r, s.fieldRef), y(r, (f = s.optionQuery) == null ? void 0 : f.valueFieldRef), y(r, ($ = s.optionQuery) == null ? void 0 : $.labelFieldRef), y(r, (R = s.optionQuery) == null ? void 0 : R.filterFieldRef), Q(r, (F = s.optionQuery) == null ? void 0 : F.spec);
|
|
52
|
+
for (const h of s.bindings || [])
|
|
53
|
+
y(r, h.fieldRef);
|
|
54
|
+
}
|
|
55
|
+
for (const s of e.views) {
|
|
56
|
+
for (const h of s.fields || [])
|
|
57
|
+
y(r, h);
|
|
58
|
+
Q(r, (k = s.sdkSpec) == null ? void 0 : k.spec), Q(r, s.visualSpec);
|
|
59
|
+
}
|
|
60
|
+
const o = e.implementationChecklist || {};
|
|
61
|
+
for (const s of Object.values(o.bindingsByView || {}))
|
|
62
|
+
for (const h of Array.isArray(s) ? s : [])
|
|
63
|
+
y(r, h.fieldRef), y(r, h.optionValueField), y(r, h.optionLabelField);
|
|
64
|
+
for (const s of o.requiredInputOptions || [])
|
|
65
|
+
y(r, s.visibleLabelField), y(r, s.optionValueField), y(r, s.runtimeFilterField);
|
|
66
|
+
const t = We(
|
|
67
|
+
[
|
|
68
|
+
...e.sources.map((s) => ({
|
|
69
|
+
raw: s,
|
|
70
|
+
key: he(s),
|
|
71
|
+
aliases: ge(s),
|
|
72
|
+
name: ""
|
|
73
|
+
})),
|
|
74
|
+
...r.map((s) => ze(s)).filter(A)
|
|
75
|
+
]
|
|
76
|
+
);
|
|
77
|
+
v(t, (s) => {
|
|
78
|
+
const h = S(s.raw);
|
|
79
|
+
return K(
|
|
80
|
+
s.raw.label || (h == null ? void 0 : h.datasetName) || (h == null ? void 0 : h.datasetId) || (h == null ? void 0 : h.name) || s.raw.kind || "source"
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
const i = Xe(t), u = ue(
|
|
84
|
+
r.filter((s) => s.name).map((s) => ({
|
|
85
|
+
raw: s,
|
|
86
|
+
key: ie(s),
|
|
87
|
+
name: ""
|
|
88
|
+
})),
|
|
89
|
+
(s) => s.key
|
|
90
|
+
);
|
|
91
|
+
v(
|
|
92
|
+
u,
|
|
93
|
+
(s) => K([
|
|
94
|
+
s.raw.sourceKey ? tn(s.raw.sourceKey) : "",
|
|
95
|
+
s.raw.aggregate ? s.raw.aggregate.toLowerCase() : "",
|
|
96
|
+
s.raw.name
|
|
97
|
+
].filter(Boolean).join("_"))
|
|
98
|
+
);
|
|
99
|
+
const l = new Map(u.map((s) => [s.key, s.name])), p = e.inputs.map((s) => ({
|
|
100
|
+
raw: s,
|
|
101
|
+
name: K(s.id || s.label || "input")
|
|
102
|
+
}));
|
|
103
|
+
v(p, (s) => s.name);
|
|
104
|
+
const m = p.filter((s) => !!s.raw.optionQuery).map((s) => ({
|
|
105
|
+
input: s,
|
|
106
|
+
name: `${s.name}Options`,
|
|
107
|
+
raw: s.raw.optionQuery
|
|
108
|
+
}));
|
|
109
|
+
v(m, (s) => s.name);
|
|
110
|
+
for (const s of m)
|
|
111
|
+
Ye(s.raw.labelFieldRef, s.raw.valueFieldRef) && Ze(s.raw.valueFieldRef) && n.push(
|
|
112
|
+
`Input option query ${((G = s.raw.spec) == null ? void 0 : G.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
|
+
);
|
|
114
|
+
const a = e.views.filter(
|
|
115
|
+
(s) => {
|
|
116
|
+
var h, T;
|
|
117
|
+
return !!((h = s.sdkSpec) != null && h.builder && ((T = s.sdkSpec) != null && T.spec));
|
|
118
|
+
}
|
|
119
|
+
).map((s) => ({
|
|
120
|
+
raw: s,
|
|
121
|
+
name: K(s.id || s.title || "query")
|
|
122
|
+
}));
|
|
123
|
+
v(a, (s) => s.name);
|
|
124
|
+
const I = e.views.filter((s) => le(s) && !("sdkSpec" in s)).map((s) => Le(s));
|
|
125
|
+
for (const s of e.views)
|
|
126
|
+
(!("sdkSpec" in s) || !((w = s.sdkSpec) != null && w.builder) || !((C = s.sdkSpec) != null && C.spec)) && !le(s) && n.push(`Skipped view ${s.id || s.title || "unknown"} because it has no sdkSpec.`);
|
|
127
|
+
return Ve({
|
|
128
|
+
inputs: p,
|
|
129
|
+
views: a,
|
|
130
|
+
filterContracts: e.filterContracts
|
|
131
|
+
}), {
|
|
132
|
+
summary: e,
|
|
133
|
+
title: e.title || "Semaphor Data App",
|
|
134
|
+
sources: t,
|
|
135
|
+
fields: u,
|
|
136
|
+
inputs: p,
|
|
137
|
+
optionQueries: m,
|
|
138
|
+
views: a,
|
|
139
|
+
presentationViews: I,
|
|
140
|
+
filterContracts: e.filterContracts,
|
|
141
|
+
checklist: o,
|
|
142
|
+
sourceNameByKey: i,
|
|
143
|
+
fieldNameByKey: l,
|
|
144
|
+
warnings: n
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function Ve({
|
|
148
|
+
inputs: e,
|
|
149
|
+
views: n,
|
|
150
|
+
filterContracts: r
|
|
151
|
+
}) {
|
|
152
|
+
const o = new Set(e.map((i) => i.raw.id).filter(Boolean)), t = new Set(n.map((i) => i.raw.id).filter(Boolean));
|
|
153
|
+
for (const [i, u] of r.entries()) {
|
|
154
|
+
if (!o.has(u.inputId))
|
|
155
|
+
throw new Error(`filterContracts.${i}.inputId must reference a generated input.`);
|
|
156
|
+
const l = new Set(u.appliesToViewIds || []), p = new Set(u.notAppliedToViewIds || []);
|
|
157
|
+
for (const [m, a] of (u.appliesToViewIds || []).entries())
|
|
158
|
+
if (!t.has(a))
|
|
159
|
+
throw new Error(
|
|
160
|
+
`filterContracts.${i}.appliesToViewIds.${m} must reference an executable generated view.`
|
|
161
|
+
);
|
|
162
|
+
for (const [m, a] of (u.notAppliedToViewIds || []).entries())
|
|
163
|
+
if (!t.has(a))
|
|
164
|
+
throw new Error(
|
|
165
|
+
`filterContracts.${i}.notAppliedToViewIds.${m} must reference an executable generated view.`
|
|
166
|
+
);
|
|
167
|
+
for (const [m, a] of (u.bindings || []).entries()) {
|
|
168
|
+
if (!t.has(a.viewId))
|
|
169
|
+
throw new Error(
|
|
170
|
+
`filterContracts.${i}.bindings.${m}.viewId must reference an executable generated view.`
|
|
171
|
+
);
|
|
172
|
+
if (!l.has(a.viewId))
|
|
173
|
+
throw new Error(
|
|
174
|
+
`filterContracts.${i}.bindings.${m}.viewId must be included in appliesToViewIds.`
|
|
175
|
+
);
|
|
176
|
+
if (p.has(a.viewId))
|
|
177
|
+
throw new Error(
|
|
178
|
+
`filterContracts.${i}.bindings.${m}.viewId must not be listed in notAppliedToViewIds.`
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function Re(e) {
|
|
184
|
+
return {
|
|
185
|
+
"sources.ts": Ge(e),
|
|
186
|
+
"fields.ts": He(e),
|
|
187
|
+
"inputs.ts": qe(e),
|
|
188
|
+
"queries.ts": Te(e),
|
|
189
|
+
"bindings.ts": Ke(e),
|
|
190
|
+
"accessors.ts": Be(e),
|
|
191
|
+
"metadata.ts": De(e),
|
|
192
|
+
"index.ts": Ue()
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function Ce({
|
|
196
|
+
contract: e,
|
|
197
|
+
files: n,
|
|
198
|
+
generatorName: r,
|
|
199
|
+
generatorVersion: o
|
|
200
|
+
}) {
|
|
201
|
+
return {
|
|
202
|
+
schemaVersion: Fe,
|
|
203
|
+
generatedContractSchemaVersion: ce,
|
|
204
|
+
generator: {
|
|
205
|
+
name: r,
|
|
206
|
+
version: o
|
|
207
|
+
},
|
|
208
|
+
generatedContentHash: Oe(n),
|
|
209
|
+
codegenSummaryValidatorVersion: $e,
|
|
210
|
+
codegenSummaryHash: ke(e.summary),
|
|
211
|
+
codegenSummary: e.summary
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function Oe(e) {
|
|
215
|
+
const n = me("sha256");
|
|
216
|
+
for (const r of Object.keys(e).sort())
|
|
217
|
+
n.update(r), n.update("\0"), n.update(e[r]), n.update("\0");
|
|
218
|
+
return `sha256:${n.digest("hex")}`;
|
|
219
|
+
}
|
|
220
|
+
function ke(e) {
|
|
221
|
+
return `sha256:${me("sha256").update(te(e)).digest("hex")}`;
|
|
222
|
+
}
|
|
223
|
+
function te(e) {
|
|
224
|
+
if (e === null || typeof e != "object")
|
|
225
|
+
return JSON.stringify(e);
|
|
226
|
+
if (Array.isArray(e))
|
|
227
|
+
return `[${e.map((o) => te(o)).join(",")}]`;
|
|
228
|
+
const n = e;
|
|
229
|
+
return `{${Object.keys(n).sort().filter((o) => n[o] !== void 0).map((o) => `${JSON.stringify(o)}:${te(n[o])}`).join(",")}}`;
|
|
230
|
+
}
|
|
231
|
+
function Ne(e) {
|
|
232
|
+
const n = e.views.find(
|
|
233
|
+
(p) => E(p) && H(p)
|
|
234
|
+
);
|
|
235
|
+
if (n)
|
|
236
|
+
return [
|
|
237
|
+
'import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, recordsSortOptionsForView, rowValuesForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',
|
|
238
|
+
"const handles = useSemaphorInputs(appInputSpecs);",
|
|
239
|
+
"const inputHandles = createInputHandleMap(handles);",
|
|
240
|
+
`const sortOption = recordsSortOptionsForView.${n.name}[0];`,
|
|
241
|
+
'const sort = sortOption ? { key: sortOption.key, direction: "asc" as const } : undefined;',
|
|
242
|
+
`const query = queries.${n.name}({ page, pageSize, sort });`,
|
|
243
|
+
`const result = useSemaphorQuery(query, queryOptionsForView.${n.name}(inputHandles));`,
|
|
244
|
+
`const rows = result.records.map((row) => rowValuesForView.${n.name}(row, result.columns));`,
|
|
245
|
+
"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"
|
|
246
|
+
].join(`
|
|
247
|
+
`);
|
|
248
|
+
const r = e.views.find(
|
|
249
|
+
(p) => E(p)
|
|
250
|
+
);
|
|
251
|
+
if (r)
|
|
252
|
+
return [
|
|
253
|
+
'import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, recordsSortOptionsForView, rowValuesForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',
|
|
254
|
+
"const handles = useSemaphorInputs(appInputSpecs);",
|
|
255
|
+
"const inputHandles = createInputHandleMap(handles);",
|
|
256
|
+
`const sortOption = recordsSortOptionsForView.${r.name}[0];`,
|
|
257
|
+
'const sort = sortOption ? { key: sortOption.key, direction: "asc" as const } : undefined;',
|
|
258
|
+
`const query = queries.${r.name}({ sort });`,
|
|
259
|
+
`const result = useSemaphorQuery(query, queryOptionsForView.${r.name}(inputHandles));`,
|
|
260
|
+
`const rows = result.records.map((row) => rowValuesForView.${r.name}(row, result.columns));`,
|
|
261
|
+
"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"
|
|
262
|
+
].join(`
|
|
263
|
+
`);
|
|
264
|
+
const o = e.views.find(
|
|
265
|
+
(p) => L(p) && H(p)
|
|
266
|
+
);
|
|
267
|
+
if (o)
|
|
268
|
+
return [
|
|
269
|
+
'import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, rowValuesForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',
|
|
270
|
+
"const handles = useSemaphorInputs(appInputSpecs);",
|
|
271
|
+
"const inputHandles = createInputHandleMap(handles);",
|
|
272
|
+
`const query = queries.${o.name}({ page, pageSize });`,
|
|
273
|
+
`const result = useSemaphorQuery(query, queryOptionsForView.${o.name}(inputHandles));`,
|
|
274
|
+
`const rows = result.records.map((row) => rowValuesForView.${o.name}(row, result.columns));`,
|
|
275
|
+
"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"
|
|
276
|
+
].join(`
|
|
277
|
+
`);
|
|
278
|
+
const t = e.views.find(
|
|
279
|
+
(p) => se(p) && H(p)
|
|
280
|
+
);
|
|
281
|
+
if (t)
|
|
282
|
+
return [
|
|
283
|
+
'import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, rowValuesForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',
|
|
284
|
+
"const handles = useSemaphorInputs(appInputSpecs);",
|
|
285
|
+
"const inputHandles = createInputHandleMap(handles);",
|
|
286
|
+
`const query = queries.${t.name}({ page, pageSize });`,
|
|
287
|
+
`const result = useSemaphorQuery(query, queryOptionsForView.${t.name}(inputHandles));`,
|
|
288
|
+
`const rows = result.records.map((row) => rowValuesForView.${t.name}(row, result.columns));`,
|
|
289
|
+
"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"
|
|
290
|
+
].join(`
|
|
291
|
+
`);
|
|
292
|
+
const i = e.views.find((p) => {
|
|
293
|
+
var m;
|
|
294
|
+
return nn((m = p.raw.sdkSpec) == null ? void 0 : m.builder);
|
|
295
|
+
});
|
|
296
|
+
if (i)
|
|
297
|
+
return [
|
|
298
|
+
'import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, rowValuesForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',
|
|
299
|
+
"const handles = useSemaphorInputs(appInputSpecs);",
|
|
300
|
+
"const inputHandles = createInputHandleMap(handles);",
|
|
301
|
+
`const result = useSemaphorQuery(queries.${i.name}(), queryOptionsForView.${i.name}(inputHandles));`,
|
|
302
|
+
`const rows = result.records.map((row) => rowValuesForView.${i.name}(row, result.columns));`,
|
|
303
|
+
"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"
|
|
304
|
+
].join(`
|
|
305
|
+
`);
|
|
306
|
+
const u = e.views[0];
|
|
307
|
+
return [
|
|
308
|
+
'import { appInputSpecs, createInputHandleMap, queries, queryOptionsForView, semaphorGeneratedContractMetadata } from "./semaphor/generated";',
|
|
309
|
+
"const handles = useSemaphorInputs(appInputSpecs);",
|
|
310
|
+
"const inputHandles = createInputHandleMap(handles);",
|
|
311
|
+
u ? `const result = useSemaphorQuery(queries.${u.name}(), queryOptionsForView.${u.name}(inputHandles));` : "const result = undefined;",
|
|
312
|
+
"const presentationViews = semaphorGeneratedContractMetadata.presentationViews;"
|
|
313
|
+
].join(`
|
|
314
|
+
`);
|
|
315
|
+
}
|
|
316
|
+
function L(e) {
|
|
317
|
+
var n;
|
|
318
|
+
return B((n = e.raw.sdkSpec) == null ? void 0 : n.builder) === "records";
|
|
319
|
+
}
|
|
320
|
+
function E(e) {
|
|
321
|
+
var n, r, o;
|
|
322
|
+
return L(e) && ((o = (r = (n = e.raw.visualSpec) == null ? void 0 : n.tableBehavior) == null ? void 0 : r.sorting) == null ? void 0 : o.mode) === "server";
|
|
323
|
+
}
|
|
324
|
+
function se(e) {
|
|
325
|
+
var n;
|
|
326
|
+
return B((n = e.raw.sdkSpec) == null ? void 0 : n.builder) === "sql";
|
|
327
|
+
}
|
|
328
|
+
function H(e) {
|
|
329
|
+
var n, r, o;
|
|
330
|
+
return ((o = (r = (n = e.raw.visualSpec) == null ? void 0 : n.tableBehavior) == null ? void 0 : r.pagination) == null ? void 0 : o.mode) === "server";
|
|
331
|
+
}
|
|
332
|
+
function xe(e) {
|
|
333
|
+
return L(e) && (H(e) || E(e)) || se(e) && H(e);
|
|
334
|
+
}
|
|
335
|
+
function Ge(e) {
|
|
336
|
+
const n = e.sources.map(({ name: o, raw: t }) => {
|
|
337
|
+
const i = Ee(t);
|
|
338
|
+
return ` ${o}: ${i},`;
|
|
339
|
+
}).join(`
|
|
340
|
+
`), r = e.sources.some((o) => o.raw.kind === "semantic") ? `import { semaphor } from "react-semaphor/data-app-sdk";
|
|
341
|
+
|
|
342
|
+
` : "";
|
|
343
|
+
return `${q}
|
|
344
|
+
${r}export const sources = {
|
|
345
|
+
${n}
|
|
346
|
+
} as const;
|
|
347
|
+
`;
|
|
348
|
+
}
|
|
349
|
+
function Ee(e) {
|
|
350
|
+
if (e.kind === "semantic") {
|
|
351
|
+
const n = {
|
|
352
|
+
domainId: e.domainId,
|
|
353
|
+
datasetId: e.datasetId,
|
|
354
|
+
datasetName: e.datasetName,
|
|
355
|
+
label: e.label
|
|
356
|
+
};
|
|
357
|
+
return `semaphor.source.semantic(${b(M(n))})`;
|
|
358
|
+
}
|
|
359
|
+
return `${b(M({ ...e, sourceKey: void 0 }))} as const`;
|
|
360
|
+
}
|
|
361
|
+
function He(e) {
|
|
362
|
+
const n = e.fields.map(({ name: o, raw: t }) => {
|
|
363
|
+
const i = Ae(t, e);
|
|
364
|
+
return ` ${o}: ${i},`;
|
|
365
|
+
}).join(`
|
|
366
|
+
`), r = n.includes("sources.") ? `import { sources } from "./sources";
|
|
367
|
+
|
|
368
|
+
` : "";
|
|
369
|
+
return `${q}
|
|
370
|
+
${r}export const fields = {
|
|
371
|
+
${n}
|
|
372
|
+
} as const;
|
|
373
|
+
`;
|
|
374
|
+
}
|
|
375
|
+
function Ae(e, n) {
|
|
376
|
+
const r = {
|
|
377
|
+
name: e.name,
|
|
378
|
+
label: e.label,
|
|
379
|
+
role: e.role,
|
|
380
|
+
dataType: e.dataType,
|
|
381
|
+
aggregate: e.aggregate
|
|
382
|
+
}, o = en(e), t = o ? n.sourceNameByKey.get(o) : void 0;
|
|
383
|
+
if (o && !t)
|
|
384
|
+
throw new Error(
|
|
385
|
+
`Field ${e.name} references source ${o}, but that source is not renderable. Include the source in codegenSummary.sources or provide field.source.`
|
|
386
|
+
);
|
|
387
|
+
const i = Object.entries(M(r)).map(([u, l]) => `${JSON.stringify(u)}: ${x(l, n)}`);
|
|
388
|
+
return t && i.push(`"source": sources.${t}`), `{ ${i.join(", ")} }`;
|
|
389
|
+
}
|
|
390
|
+
function qe(e) {
|
|
391
|
+
const n = e.inputs.map((c) => {
|
|
392
|
+
const g = O(c.raw.fieldRef, e), f = [
|
|
393
|
+
`id: ${JSON.stringify(c.raw.id)}`,
|
|
394
|
+
`label: ${JSON.stringify(c.raw.label || c.raw.id)}`,
|
|
395
|
+
`operator: ${JSON.stringify(rn(c.raw))}`
|
|
396
|
+
];
|
|
397
|
+
if (g && f.push(`field: fields.${g}`), c.raw.relationshipHint && f.push(`relationshipHint: ${b(c.raw.relationshipHint)}`), !g)
|
|
398
|
+
throw new Error(`Input ${c.raw.id || c.name} is missing a generated field reference.`);
|
|
399
|
+
return ` ${c.name}: semaphor.filter({ ${f.join(", ")} }),`;
|
|
400
|
+
}).join(`
|
|
401
|
+
`), r = e.inputs.map((c) => `filterSpecs.${c.name}`).join(", "), o = e.inputs.map((c) => JSON.stringify(c.raw.id)).join(", "), t = e.optionQueries.map((c) => {
|
|
402
|
+
const g = c.input.raw, f = c.raw, $ = S(f.spec) || {}, {
|
|
403
|
+
id: R,
|
|
404
|
+
inputId: F,
|
|
405
|
+
source: k,
|
|
406
|
+
sourceKey: G,
|
|
407
|
+
valueField: w,
|
|
408
|
+
labelField: C,
|
|
409
|
+
population: s,
|
|
410
|
+
dependencies: h,
|
|
411
|
+
limit: T,
|
|
412
|
+
...Z
|
|
413
|
+
} = $, P = f.sourceKey ? { sourceKey: f.sourceKey } : f.source || k || (typeof G == "string" ? { sourceKey: G } : void 0), W = ye(P, e), X = O(f.valueFieldRef, e), ee = O(f.labelFieldRef, e), ne = {
|
|
414
|
+
...Z,
|
|
415
|
+
id: f.id || $.id || `${g.id}-options`,
|
|
416
|
+
inputId: g.id,
|
|
417
|
+
source: P,
|
|
418
|
+
valueField: f.valueFieldRef,
|
|
419
|
+
labelField: f.labelFieldRef,
|
|
420
|
+
population: f.population || s,
|
|
421
|
+
dependencies: f.dependencies || h,
|
|
422
|
+
limit: f.limit || T || 100
|
|
423
|
+
};
|
|
424
|
+
if (!W || !X || !ee)
|
|
425
|
+
throw new Error(`Input option query ${f.id || `${g.id}-options`} is missing source, valueField, or labelField.`);
|
|
426
|
+
const re = Object.entries(M(ne)).map(([Se, we]) => `${JSON.stringify(Se)}: ${x(we, e)}`);
|
|
427
|
+
return ` ${c.name}: semaphor.inputOptions({ ${re.join(", ")} }),`;
|
|
428
|
+
}).join(`
|
|
429
|
+
`), i = e.optionQueries.map((c) => {
|
|
430
|
+
const f = Me(e, c).map(($) => {
|
|
431
|
+
const R = O($.raw.fieldRef, e);
|
|
432
|
+
if (!R)
|
|
433
|
+
throw new Error(
|
|
434
|
+
`Input option query ${c.raw.id || `${c.input.raw.id}-options`} references input ${$.raw.id} without a generated field reference.`
|
|
435
|
+
);
|
|
436
|
+
const F = `inputHandles[${JSON.stringify($.raw.id)}]`;
|
|
437
|
+
return ` if (${F}) {
|
|
438
|
+
inputs.push(semaphor.bindInput(${F}, { field: fields.${R} }));
|
|
439
|
+
}`;
|
|
440
|
+
}).join(`
|
|
441
|
+
`);
|
|
442
|
+
return ` ${c.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorInputReference[] {
|
|
443
|
+
const inputs: SemaphorInputReference[] = [];
|
|
444
|
+
${f}
|
|
445
|
+
return inputs;
|
|
446
|
+
},`;
|
|
447
|
+
}).join(`
|
|
448
|
+
|
|
449
|
+
`), u = e.optionQueries.map((c) => ` ${c.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorQueryRuntimeOptions {
|
|
450
|
+
return {
|
|
451
|
+
inputs: inputsForInputOptionQuery.${c.name}(inputHandles),
|
|
452
|
+
};
|
|
453
|
+
},`).join(`
|
|
454
|
+
|
|
455
|
+
`), l = e.optionQueries.map((c) => ` case ${JSON.stringify(c.raw.id || `${c.input.raw.id}-options`)}:
|
|
456
|
+
return queryOptionsForInputOptionQuery.${c.name}(inputHandles);`).join(`
|
|
457
|
+
`), p = e.inputs.length > 0, m = e.optionQueries.length > 0, a = m ? "inputOptionQueryId" : "_inputOptionQueryId", I = m ? "inputHandles" : "_inputHandles", V = [
|
|
458
|
+
"SemaphorInputHandle",
|
|
459
|
+
m ? "SemaphorInputReference" : void 0,
|
|
460
|
+
"SemaphorQueryRuntimeOptions"
|
|
461
|
+
].filter(A).join(", "), d = [
|
|
462
|
+
p || m ? 'import { semaphor } from "react-semaphor/data-app-sdk";' : void 0,
|
|
463
|
+
`import type { ${V} } from "react-semaphor/data-app-sdk";`,
|
|
464
|
+
p || m ? 'import { fields } from "./fields";' : void 0,
|
|
465
|
+
m ? 'import { sources } from "./sources";' : void 0,
|
|
466
|
+
'import type { SemaphorGeneratedInputId, SemaphorGeneratedInputOptionQueryId } from "./metadata";'
|
|
467
|
+
].filter(A).join(`
|
|
468
|
+
`);
|
|
469
|
+
return `${q}
|
|
470
|
+
${d}
|
|
471
|
+
|
|
472
|
+
export const filterSpecs = {
|
|
473
|
+
${n}
|
|
474
|
+
} as const;
|
|
475
|
+
|
|
476
|
+
export const appInputSpecs = [${r}] as const;
|
|
477
|
+
export const appInputIds = [${o}] as const;
|
|
478
|
+
|
|
479
|
+
export type SemaphorGeneratedInputHandleMap = Partial<Record<SemaphorGeneratedInputId, SemaphorInputHandle>>;
|
|
480
|
+
|
|
481
|
+
export function createInputHandleMap(handles: readonly SemaphorInputHandle[]): SemaphorGeneratedInputHandleMap {
|
|
482
|
+
return Object.fromEntries(appInputIds.map((id, index) => [id, handles[index]])) as SemaphorGeneratedInputHandleMap;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export const inputOptionQueries = {
|
|
486
|
+
${t}
|
|
487
|
+
} as const;
|
|
488
|
+
|
|
489
|
+
export const inputsForInputOptionQuery = {
|
|
490
|
+
${i}
|
|
491
|
+
} as const;
|
|
492
|
+
|
|
493
|
+
export const queryOptionsForInputOptionQuery = {
|
|
494
|
+
${u}
|
|
495
|
+
} as const;
|
|
496
|
+
|
|
497
|
+
export function queryOptionsForInputOptionQueryId(
|
|
498
|
+
${a}: SemaphorGeneratedInputOptionQueryId,
|
|
499
|
+
${I}: SemaphorGeneratedInputHandleMap,
|
|
500
|
+
): SemaphorQueryRuntimeOptions {
|
|
501
|
+
switch (${a}) {
|
|
502
|
+
${l}
|
|
503
|
+
}
|
|
504
|
+
throw new Error(\`Unknown generated Semaphor input option query id: \${${a}}\`);
|
|
505
|
+
}
|
|
506
|
+
`;
|
|
507
|
+
}
|
|
508
|
+
function Me(e, n) {
|
|
509
|
+
const r = n.raw.dependencies;
|
|
510
|
+
if ((r == null ? void 0 : r.mode) === "independent")
|
|
511
|
+
return [];
|
|
512
|
+
const o = /* @__PURE__ */ new Set([
|
|
513
|
+
n.input.raw.id,
|
|
514
|
+
...(r == null ? void 0 : r.excludeInputIds) || []
|
|
515
|
+
]), t = (r == null ? void 0 : r.mode) === "explicit" ? new Set(r.includeInputIds || []) : void 0;
|
|
516
|
+
return e.inputs.filter((i) => o.has(i.raw.id) ? !1 : t ? t.has(i.raw.id) : !!i.raw.fieldRef);
|
|
517
|
+
}
|
|
518
|
+
function Te(e) {
|
|
519
|
+
const n = e.views.map((d) => {
|
|
520
|
+
var f, $, R, F, k, G;
|
|
521
|
+
const c = B(d.raw.sdkSpec.builder), g = ve(d);
|
|
522
|
+
if (L(d) && xe(d)) {
|
|
523
|
+
const w = (f = d.raw.visualSpec) == null ? void 0 : f.tableBehavior, C = S(g.pagination), s = H(d), h = E(d), T = (($ = w == null ? void 0 : w.pagination) == null ? void 0 : $.pageSize) || D(C == null ? void 0 : C.pageSize) || D(g.limit) || 100, Z = h ? U(d, e) : [], P = h ? je({
|
|
524
|
+
view: d,
|
|
525
|
+
contract: e,
|
|
526
|
+
sortFields: Z,
|
|
527
|
+
defaultField: (R = w == null ? void 0 : w.sorting) == null ? void 0 : R.defaultField
|
|
528
|
+
}) : void 0, W = h ? (F = w == null ? void 0 : w.sorting) == null ? void 0 : F.defaultDirection : void 0, X = Qe({
|
|
529
|
+
viewName: d.name,
|
|
530
|
+
supportsPagination: s,
|
|
531
|
+
supportsSort: h
|
|
532
|
+
}), ee = h ? ` const orderBy = resolveRecordsOrderBy(
|
|
533
|
+
recordsSortFieldsForView.${d.name},
|
|
534
|
+
params.sort,
|
|
535
|
+
${x(P, e)},
|
|
536
|
+
${x(W, e)},
|
|
537
|
+
);
|
|
538
|
+
` : "", ne = h ? ` ...(orderBy ? { orderBy } : {}),
|
|
539
|
+
` : "", re = s ? ` pagination: resolveServerTablePagination(params, ${JSON.stringify(T)}),
|
|
540
|
+
` : "";
|
|
541
|
+
return ` ${d.name}(
|
|
542
|
+
params: ${X} = {},
|
|
543
|
+
) {
|
|
544
|
+
${ee} return semaphor.${c}({
|
|
545
|
+
...${x(g, e)},
|
|
546
|
+
${ne}${re} });
|
|
547
|
+
},`;
|
|
548
|
+
}
|
|
549
|
+
if (se(d) && H(d)) {
|
|
550
|
+
const w = (k = d.raw.visualSpec) == null ? void 0 : k.tableBehavior, C = S(g.pagination), s = ((G = w == null ? void 0 : w.pagination) == null ? void 0 : G.pageSize) || D(C == null ? void 0 : C.pageSize) || D(g.limit) || 100;
|
|
551
|
+
return ` ${d.name}(
|
|
552
|
+
params: SemaphorGeneratedServerPaginationParams = {},
|
|
553
|
+
) {
|
|
554
|
+
return semaphor.${c}({
|
|
555
|
+
...${x(g, e)},
|
|
556
|
+
pagination: resolveServerTablePagination(params, ${JSON.stringify(s)}),
|
|
557
|
+
});
|
|
558
|
+
},`;
|
|
559
|
+
}
|
|
560
|
+
return ` ${d.name}: () => semaphor.${c}(${x(g, e)}),`;
|
|
561
|
+
}).join(`
|
|
562
|
+
`), r = e.views.filter((d) => E(d)).map((d) => {
|
|
563
|
+
const g = U(d, e).map((f) => ` ${JSON.stringify(f.key)}: fields.${f.fieldName},`).join(`
|
|
564
|
+
`);
|
|
565
|
+
return ` ${d.name}: {
|
|
566
|
+
${g}
|
|
567
|
+
},`;
|
|
568
|
+
}).join(`
|
|
569
|
+
`), o = e.views.filter((d) => E(d)).map((d) => {
|
|
570
|
+
const g = U(d, e).map((f) => ` { key: ${JSON.stringify(f.key)}, label: ${JSON.stringify(f.label)}, field: fields.${f.fieldName} },`).join(`
|
|
571
|
+
`);
|
|
572
|
+
return ` ${d.name}: [
|
|
573
|
+
${g}
|
|
574
|
+
],`;
|
|
575
|
+
}).join(`
|
|
576
|
+
`), t = e.views.some((d) => E(d)), i = e.views.some((d) => H(d)), u = [n, r, o].join(`
|
|
577
|
+
`), l = [
|
|
578
|
+
n ? 'import { semaphor } from "react-semaphor/data-app-sdk";' : void 0,
|
|
579
|
+
t ? 'import type { SemaphorFieldRef } from "react-semaphor/data-app-sdk";' : void 0,
|
|
580
|
+
u.includes("fields.") ? 'import { fields } from "./fields";' : void 0,
|
|
581
|
+
u.includes("sources.") ? 'import { sources } from "./sources";' : void 0
|
|
582
|
+
].filter(A).join(`
|
|
583
|
+
`);
|
|
584
|
+
return `${q}
|
|
585
|
+
${l}
|
|
586
|
+
${t ? `export type SemaphorGeneratedRecordsSortDirection = "asc" | "desc";
|
|
587
|
+
|
|
588
|
+
export type SemaphorGeneratedRecordsSort<TSortKey extends string = string> = {
|
|
589
|
+
key: TSortKey;
|
|
590
|
+
direction: SemaphorGeneratedRecordsSortDirection;
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
export type SemaphorGeneratedRecordsSortParams<TSortKey extends string = string> = {
|
|
594
|
+
sort?: SemaphorGeneratedRecordsSort<TSortKey> | null;
|
|
595
|
+
};
|
|
596
|
+
` : ""}${i ? `export type SemaphorGeneratedServerPaginationParams = {
|
|
597
|
+
page?: number;
|
|
598
|
+
pageSize?: number;
|
|
599
|
+
};
|
|
600
|
+
` : ""}${t && i ? `export type SemaphorGeneratedRecordsQueryParams<TSortKey extends string = string> =
|
|
601
|
+
SemaphorGeneratedServerPaginationParams &
|
|
602
|
+
SemaphorGeneratedRecordsSortParams<TSortKey>;
|
|
603
|
+
` : ""}
|
|
604
|
+
|
|
605
|
+
export const recordsSortFieldsForView = {
|
|
606
|
+
${r}
|
|
607
|
+
} as const;
|
|
608
|
+
|
|
609
|
+
export const recordsSortOptionsForView = {
|
|
610
|
+
${o}
|
|
611
|
+
} as const;
|
|
612
|
+
|
|
613
|
+
export const queries = {
|
|
614
|
+
${n}
|
|
615
|
+
} as const;
|
|
616
|
+
|
|
617
|
+
${t ? `function resolveRecordsOrderBy<TSortKey extends string>(
|
|
618
|
+
sortFields: Record<TSortKey, SemaphorFieldRef>,
|
|
619
|
+
sort: SemaphorGeneratedRecordsSort<TSortKey> | null | undefined,
|
|
620
|
+
defaultKey: TSortKey | undefined,
|
|
621
|
+
defaultDirection: SemaphorGeneratedRecordsSortDirection | undefined,
|
|
622
|
+
) {
|
|
623
|
+
const key = sort?.key ?? defaultKey;
|
|
624
|
+
if (!key) {
|
|
625
|
+
return undefined;
|
|
626
|
+
}
|
|
627
|
+
const field = sortFields[key];
|
|
628
|
+
if (!field) {
|
|
629
|
+
return undefined;
|
|
630
|
+
}
|
|
631
|
+
return {
|
|
632
|
+
field,
|
|
633
|
+
direction: sort?.direction ?? defaultDirection ?? "asc",
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
` : ""}
|
|
637
|
+
${i ? `function resolveServerTablePagination(
|
|
638
|
+
params: SemaphorGeneratedServerPaginationParams,
|
|
639
|
+
defaultPageSize: number,
|
|
640
|
+
) {
|
|
641
|
+
return {
|
|
642
|
+
page: params.page ?? 1,
|
|
643
|
+
pageSize: params.pageSize ?? defaultPageSize,
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
` : ""}
|
|
647
|
+
`;
|
|
648
|
+
}
|
|
649
|
+
function ve(e) {
|
|
650
|
+
var i, u;
|
|
651
|
+
const n = S((i = e.raw.sdkSpec) == null ? void 0 : i.spec) || {}, { kind: r, id: o, ...t } = n;
|
|
652
|
+
return {
|
|
653
|
+
...t,
|
|
654
|
+
id: e.raw.id,
|
|
655
|
+
label: ((u = e.raw.visualSpec) == null ? void 0 : u.title) || e.raw.title || t.label
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
function U(e, n) {
|
|
659
|
+
var i, u;
|
|
660
|
+
const r = [], o = S((i = e.raw.sdkSpec) == null ? void 0 : i.spec) || {};
|
|
661
|
+
for (const l of j(o.fields)) y(r, l);
|
|
662
|
+
y(r, o.dateField), y(r, (u = S(o.orderBy)) == null ? void 0 : u.field);
|
|
663
|
+
for (const l of e.raw.fields || []) y(r, l);
|
|
664
|
+
return ue(
|
|
665
|
+
r.map((l) => {
|
|
666
|
+
const p = O(l, n);
|
|
667
|
+
if (!(!l.name || !p))
|
|
668
|
+
return {
|
|
669
|
+
key: p,
|
|
670
|
+
fieldName: p,
|
|
671
|
+
rawName: l.name,
|
|
672
|
+
label: l.label || l.name
|
|
673
|
+
};
|
|
674
|
+
}).filter(A),
|
|
675
|
+
(l) => l.key
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
function je({
|
|
679
|
+
view: e,
|
|
680
|
+
contract: n,
|
|
681
|
+
sortFields: r,
|
|
682
|
+
defaultField: o
|
|
683
|
+
}) {
|
|
684
|
+
var p, m;
|
|
685
|
+
const t = new Set(r.map((a) => a.key));
|
|
686
|
+
if (o && t.has(o))
|
|
687
|
+
return o;
|
|
688
|
+
const i = r.filter((a) => a.rawName === o);
|
|
689
|
+
if (i.length === 1)
|
|
690
|
+
return i[0].key;
|
|
691
|
+
const u = S((p = e.raw.sdkSpec) == null ? void 0 : p.spec), l = O((m = S(u == null ? void 0 : u.orderBy)) == null ? void 0 : m.field, n);
|
|
692
|
+
return l && t.has(l) ? l : void 0;
|
|
693
|
+
}
|
|
694
|
+
function Qe({
|
|
695
|
+
viewName: e,
|
|
696
|
+
supportsPagination: n,
|
|
697
|
+
supportsSort: r
|
|
698
|
+
}) {
|
|
699
|
+
return n && r ? `SemaphorGeneratedRecordsQueryParams<Extract<keyof typeof recordsSortFieldsForView.${e}, string>>` : r ? `SemaphorGeneratedRecordsSortParams<Extract<keyof typeof recordsSortFieldsForView.${e}, string>>` : "SemaphorGeneratedServerPaginationParams";
|
|
700
|
+
}
|
|
701
|
+
function Ke(e) {
|
|
702
|
+
const n = e.views.map((a) => {
|
|
703
|
+
const V = _e(e, a.raw.id).map((d) => {
|
|
704
|
+
const c = d.inputId, g = O(d.fieldRef, e);
|
|
705
|
+
if (!c || !g)
|
|
706
|
+
return "";
|
|
707
|
+
const f = [`field: fields.${g}`];
|
|
708
|
+
if (d.relationshipHint)
|
|
709
|
+
f.push(`relationshipHint: ${b(d.relationshipHint)}`);
|
|
710
|
+
else if (Array.isArray(d.relationshipsUsed) && d.relationshipsUsed.length > 0) {
|
|
711
|
+
const R = d.relationshipsUsed.map((F) => {
|
|
712
|
+
var k;
|
|
713
|
+
return (k = S(F)) == null ? void 0 : k.id;
|
|
714
|
+
}).filter((F) => typeof F == "string" && F.length > 0);
|
|
715
|
+
R.length > 0 && f.push(`relationshipHint: ${b({ relationshipIds: R })}`);
|
|
716
|
+
}
|
|
717
|
+
const $ = `inputHandles[${JSON.stringify(c)}]`;
|
|
718
|
+
return ` if (${$}) {
|
|
719
|
+
inputs.push(semaphor.bindInput(${$}, { ${f.join(", ")} }));
|
|
720
|
+
}`;
|
|
721
|
+
}).filter(Boolean).join(`
|
|
722
|
+
`);
|
|
723
|
+
return { view: a, renderedBindings: V };
|
|
724
|
+
}), r = n.some((a) => a.renderedBindings.length > 0), o = n.map(({ view: a, renderedBindings: I }) => {
|
|
725
|
+
const V = I ? "inputHandles" : "_inputHandles";
|
|
726
|
+
return ` ${a.name}(${V}: SemaphorGeneratedInputHandleMap): SemaphorInputReference[] {
|
|
727
|
+
const inputs: SemaphorInputReference[] = [];
|
|
728
|
+
${I}
|
|
729
|
+
return inputs;
|
|
730
|
+
},`;
|
|
731
|
+
}).join(`
|
|
732
|
+
|
|
733
|
+
`), t = e.views.map((a) => ` ${a.name}(inputHandles: SemaphorGeneratedInputHandleMap): SemaphorQueryRuntimeOptions {
|
|
734
|
+
return {
|
|
735
|
+
inputs: inputsForView.${a.name}(inputHandles),
|
|
736
|
+
debug: queryDebugForView.${a.name},
|
|
737
|
+
};
|
|
738
|
+
},`).join(`
|
|
739
|
+
|
|
740
|
+
`), i = e.views.map((a) => ` case ${JSON.stringify(a.raw.id)}:
|
|
741
|
+
return inputsForView.${a.name}(inputHandles);`).join(`
|
|
742
|
+
`), u = e.views.map((a) => ` case ${JSON.stringify(a.raw.id)}:
|
|
743
|
+
return queryOptionsForView.${a.name}(inputHandles);`).join(`
|
|
744
|
+
`), l = e.views.length > 0, p = l ? "inputHandles" : "_inputHandles", m = [
|
|
745
|
+
r ? 'import { semaphor } from "react-semaphor/data-app-sdk";' : void 0,
|
|
746
|
+
'import type { SemaphorInputReference, SemaphorQueryRuntimeOptions } from "react-semaphor/data-app-sdk";',
|
|
747
|
+
r ? 'import { fields } from "./fields";' : void 0,
|
|
748
|
+
'import type { SemaphorGeneratedInputHandleMap } from "./inputs";',
|
|
749
|
+
l ? 'import { queryDebugForView } from "./metadata";' : void 0,
|
|
750
|
+
'import type { SemaphorGeneratedQueryViewId } from "./metadata";'
|
|
751
|
+
].filter(A).join(`
|
|
752
|
+
`);
|
|
753
|
+
return `${q}
|
|
754
|
+
${m}
|
|
755
|
+
|
|
756
|
+
export const inputsForView = {
|
|
757
|
+
${o}
|
|
758
|
+
} as const;
|
|
759
|
+
|
|
760
|
+
export const queryOptionsForView = {
|
|
761
|
+
${t}
|
|
762
|
+
} as const;
|
|
763
|
+
|
|
764
|
+
export function inputsForViewId(
|
|
765
|
+
viewId: SemaphorGeneratedQueryViewId,
|
|
766
|
+
${p}: SemaphorGeneratedInputHandleMap,
|
|
767
|
+
): SemaphorInputReference[] {
|
|
768
|
+
switch (viewId) {
|
|
769
|
+
${i}
|
|
770
|
+
}
|
|
771
|
+
throw new Error(\`Unknown generated Semaphor view id: \${viewId}\`);
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
export function queryOptionsForViewId(
|
|
775
|
+
viewId: SemaphorGeneratedQueryViewId,
|
|
776
|
+
${p}: SemaphorGeneratedInputHandleMap,
|
|
777
|
+
): SemaphorQueryRuntimeOptions {
|
|
778
|
+
switch (viewId) {
|
|
779
|
+
${u}
|
|
780
|
+
}
|
|
781
|
+
throw new Error(\`Unknown generated Semaphor view id: \${viewId}\`);
|
|
782
|
+
}
|
|
783
|
+
`;
|
|
784
|
+
}
|
|
785
|
+
function _e(e, n) {
|
|
786
|
+
return e.filterContracts.flatMap(
|
|
787
|
+
(r) => (r.bindings || []).filter((o) => o.viewId === n).map((o) => ({
|
|
788
|
+
inputId: r.inputId,
|
|
789
|
+
fieldRef: o.fieldRef,
|
|
790
|
+
relationshipHint: o.relationshipHint,
|
|
791
|
+
relationshipsUsed: o.relationshipsUsed
|
|
792
|
+
}))
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
function Be(e) {
|
|
796
|
+
const n = e.views.map((u) => {
|
|
797
|
+
const p = J(u, e).map((m) => {
|
|
798
|
+
const a = O(m.raw, e);
|
|
799
|
+
return a ? ` ${m.name}: fields.${a},` : "";
|
|
800
|
+
}).filter(Boolean).join(`
|
|
801
|
+
`);
|
|
802
|
+
return ` ${u.name}: {
|
|
803
|
+
${p}
|
|
804
|
+
},`;
|
|
805
|
+
}).join(`
|
|
806
|
+
`), r = e.views.map((u) => {
|
|
807
|
+
const l = Pe(u, e);
|
|
808
|
+
return ` ${u.name}: ${b(l)},`;
|
|
809
|
+
}).join(`
|
|
810
|
+
`), o = e.views.map((u) => {
|
|
811
|
+
const p = J(u, e).map((m) => ` ${m.name}: resolveColumnKey(columns, fieldsForView.${u.name}.${m.name}),`).join(`
|
|
812
|
+
`);
|
|
813
|
+
return ` ${u.name}(columns: SemaphorGeneratedColumns): Record<keyof typeof fieldsForView.${u.name}, string | undefined> {
|
|
814
|
+
return {
|
|
815
|
+
${p}
|
|
816
|
+
};
|
|
817
|
+
},`;
|
|
818
|
+
}).join(`
|
|
819
|
+
|
|
820
|
+
`), t = e.views.map((u) => {
|
|
821
|
+
const p = J(u, e).map((m) => ` ${m.name}: readCell(row, columns, fieldsForView.${u.name}.${m.name}),`).join(`
|
|
822
|
+
`);
|
|
823
|
+
return ` ${u.name}(row: SemaphorGeneratedRow, columns: SemaphorGeneratedColumns): Record<keyof typeof fieldsForView.${u.name}, unknown> {
|
|
824
|
+
return {
|
|
825
|
+
${p}
|
|
826
|
+
};
|
|
827
|
+
},`;
|
|
828
|
+
}).join(`
|
|
829
|
+
|
|
830
|
+
`), i = [
|
|
831
|
+
'import type { SemaphorFieldRef, SemaphorResultColumn } from "react-semaphor/data-app-sdk";',
|
|
832
|
+
n.includes("fields.") ? 'import { fields } from "./fields";' : void 0
|
|
833
|
+
].filter(A).join(`
|
|
834
|
+
`);
|
|
835
|
+
return `${q}
|
|
836
|
+
${i}
|
|
837
|
+
|
|
838
|
+
export type SemaphorGeneratedRow = Record<string, unknown>;
|
|
839
|
+
export type SemaphorGeneratedColumns = readonly SemaphorResultColumn[] | null | undefined;
|
|
840
|
+
export type SemaphorGeneratedTableColumn = {
|
|
841
|
+
readonly key: string;
|
|
842
|
+
readonly label: string;
|
|
843
|
+
readonly dataType?: string;
|
|
844
|
+
readonly sortable?: boolean;
|
|
845
|
+
readonly sortKey?: string;
|
|
846
|
+
};
|
|
847
|
+
|
|
848
|
+
export const fieldsForView = {
|
|
849
|
+
${n}
|
|
850
|
+
} as const;
|
|
851
|
+
|
|
852
|
+
export const tableColumnsForView = {
|
|
853
|
+
${r}
|
|
854
|
+
} as const;
|
|
855
|
+
|
|
856
|
+
export const columnKeysForView = {
|
|
857
|
+
${o}
|
|
858
|
+
} as const;
|
|
859
|
+
|
|
860
|
+
export const rowValuesForView = {
|
|
861
|
+
${t}
|
|
862
|
+
} as const;
|
|
863
|
+
|
|
864
|
+
export function resolveColumnKey(
|
|
865
|
+
columns: SemaphorGeneratedColumns,
|
|
866
|
+
field: SemaphorFieldRef,
|
|
867
|
+
): string | undefined {
|
|
868
|
+
return resolveColumn(columns, field)?.key;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
export function readCell(
|
|
872
|
+
row: SemaphorGeneratedRow,
|
|
873
|
+
columns: SemaphorGeneratedColumns,
|
|
874
|
+
field: SemaphorFieldRef,
|
|
875
|
+
): unknown {
|
|
876
|
+
const key = resolveColumnKey(columns, field);
|
|
877
|
+
return key ? row[key] : undefined;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
export function readNumberCell(
|
|
881
|
+
row: SemaphorGeneratedRow,
|
|
882
|
+
columns: SemaphorGeneratedColumns,
|
|
883
|
+
field: SemaphorFieldRef,
|
|
884
|
+
): number | null {
|
|
885
|
+
const value = readCell(row, columns, field);
|
|
886
|
+
if (typeof value === "number") {
|
|
887
|
+
return Number.isFinite(value) ? value : null;
|
|
888
|
+
}
|
|
889
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
890
|
+
const parsed = Number(value);
|
|
891
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
892
|
+
}
|
|
893
|
+
return null;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
export function readStringCell(
|
|
897
|
+
row: SemaphorGeneratedRow,
|
|
898
|
+
columns: SemaphorGeneratedColumns,
|
|
899
|
+
field: SemaphorFieldRef,
|
|
900
|
+
): string {
|
|
901
|
+
const value = readCell(row, columns, field);
|
|
902
|
+
return value === null || value === undefined ? "" : String(value);
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
function resolveColumn(
|
|
906
|
+
columns: SemaphorGeneratedColumns,
|
|
907
|
+
field: SemaphorFieldRef,
|
|
908
|
+
): SemaphorResultColumn | undefined {
|
|
909
|
+
if (!columns || columns.length === 0) {
|
|
910
|
+
return undefined;
|
|
911
|
+
}
|
|
912
|
+
return (
|
|
913
|
+
findUniqueColumn(columns, (column) => column.name === field.name && columnMatchesField(column, field, true, false)) ||
|
|
914
|
+
findUniqueColumn(columns, (column) => column.name === field.name && columnMatchesField(column, field, false, false)) ||
|
|
915
|
+
findUniqueColumn(columns, (column) => columnLabelMatchesField(column, field) && columnMatchesField(column, field, true, false)) ||
|
|
916
|
+
findUniqueColumn(columns, (column) => columnLabelMatchesField(column, field) && columnMatchesField(column, field, false, false)) ||
|
|
917
|
+
findUniqueColumn(columns, (column) => column.name === field.name && columnMatchesField(column, field, true, true)) ||
|
|
918
|
+
findUniqueColumn(columns, (column) => column.name === field.name && columnMatchesField(column, field, false, true)) ||
|
|
919
|
+
findUniqueColumn(columns, (column) => columnLabelMatchesField(column, field) && columnMatchesField(column, field, true, true)) ||
|
|
920
|
+
findUniqueColumn(columns, (column) => columnLabelMatchesField(column, field) && columnMatchesField(column, field, false, true))
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
function findUniqueColumn(
|
|
925
|
+
columns: readonly SemaphorResultColumn[],
|
|
926
|
+
predicate: (column: SemaphorResultColumn) => boolean,
|
|
927
|
+
): SemaphorResultColumn | undefined {
|
|
928
|
+
const matches = columns.filter(predicate);
|
|
929
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
function columnLabelMatchesField(
|
|
933
|
+
column: SemaphorResultColumn,
|
|
934
|
+
field: SemaphorFieldRef,
|
|
935
|
+
): boolean {
|
|
936
|
+
return Boolean(field.label && column.label === field.label);
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
function columnMatchesField(
|
|
940
|
+
column: SemaphorResultColumn,
|
|
941
|
+
field: SemaphorFieldRef,
|
|
942
|
+
requireComparableSource: boolean,
|
|
943
|
+
allowImplicitAggregate: boolean,
|
|
944
|
+
): boolean {
|
|
945
|
+
if (field.aggregate && column.aggregate && normalizeAggregate(field.aggregate) !== normalizeAggregate(column.aggregate)) {
|
|
946
|
+
return false;
|
|
947
|
+
}
|
|
948
|
+
if (
|
|
949
|
+
!field.aggregate &&
|
|
950
|
+
column.aggregate &&
|
|
951
|
+
(!allowImplicitAggregate || field.role !== "measure")
|
|
952
|
+
) {
|
|
953
|
+
return false;
|
|
954
|
+
}
|
|
955
|
+
if (requireComparableSource && !column.source) {
|
|
956
|
+
return false;
|
|
957
|
+
}
|
|
958
|
+
return sourcesReferToSameDataset(column.source, field.source);
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
function normalizeAggregate(aggregate: string): string {
|
|
962
|
+
return aggregate.trim().toLowerCase();
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
function sourcesReferToSameDataset(
|
|
966
|
+
left: SemaphorFieldRef["source"] | undefined,
|
|
967
|
+
right: SemaphorFieldRef["source"] | undefined,
|
|
968
|
+
): boolean {
|
|
969
|
+
if (!left || !right) {
|
|
970
|
+
return true;
|
|
971
|
+
}
|
|
972
|
+
if (left.kind !== right.kind) {
|
|
973
|
+
return false;
|
|
974
|
+
}
|
|
975
|
+
if (left.kind === "physical" && right.kind === "physical") {
|
|
976
|
+
if (left.connectionId && right.connectionId && left.connectionId !== right.connectionId) {
|
|
977
|
+
return false;
|
|
978
|
+
}
|
|
979
|
+
if (left.databaseName && right.databaseName && left.databaseName !== right.databaseName) {
|
|
980
|
+
return false;
|
|
981
|
+
}
|
|
982
|
+
if (left.schemaName && right.schemaName && left.schemaName !== right.schemaName) {
|
|
983
|
+
return false;
|
|
984
|
+
}
|
|
985
|
+
if (left.tableName && right.tableName && left.tableName !== right.tableName) {
|
|
986
|
+
return false;
|
|
987
|
+
}
|
|
988
|
+
return true;
|
|
989
|
+
}
|
|
990
|
+
if (left.kind === "sql" && right.kind === "sql") {
|
|
991
|
+
return !left.connectionId || !right.connectionId || left.connectionId === right.connectionId;
|
|
992
|
+
}
|
|
993
|
+
if (left.kind === "semantic" && right.kind === "semantic") {
|
|
994
|
+
if (left.domainId && right.domainId && left.domainId !== right.domainId) {
|
|
995
|
+
return false;
|
|
996
|
+
}
|
|
997
|
+
if (left.datasetId && right.datasetId) {
|
|
998
|
+
return left.datasetId === right.datasetId;
|
|
999
|
+
}
|
|
1000
|
+
if (left.datasetName && right.datasetName) {
|
|
1001
|
+
return left.datasetName === right.datasetName;
|
|
1002
|
+
}
|
|
1003
|
+
return true;
|
|
1004
|
+
}
|
|
1005
|
+
return false;
|
|
1006
|
+
}
|
|
1007
|
+
`;
|
|
1008
|
+
}
|
|
1009
|
+
function Pe(e, n) {
|
|
1010
|
+
const r = J(e, n), o = new Map(
|
|
1011
|
+
(E(e) ? U(e, n) : []).map((t) => [t.fieldName, t.key])
|
|
1012
|
+
);
|
|
1013
|
+
return r.map((t) => {
|
|
1014
|
+
const i = O(t.raw, n), u = i ? o.get(i) : void 0;
|
|
1015
|
+
return M({
|
|
1016
|
+
key: t.name,
|
|
1017
|
+
label: t.raw.label || t.raw.name,
|
|
1018
|
+
dataType: t.raw.dataType,
|
|
1019
|
+
sortable: !!u,
|
|
1020
|
+
sortKey: u
|
|
1021
|
+
});
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
function De(e) {
|
|
1025
|
+
const n = e.checklist.filterScopeByInput || [], r = e.checklist.requiredDevtools || {}, o = e.summary.views.map((a) => a.id).filter(Boolean), t = e.views.map((a) => a.raw.id).filter(Boolean), i = e.inputs.map((a) => a.raw.id).filter(Boolean), u = e.optionQueries.map((a) => a.raw.id || `${a.input.raw.id}-options`).filter(Boolean), l = Object.fromEntries(t.map((a) => [
|
|
1026
|
+
a,
|
|
1027
|
+
e.filterContracts.filter(
|
|
1028
|
+
(I) => Array.isArray(I.appliesToViewIds) && I.appliesToViewIds.includes(a)
|
|
1029
|
+
).map((I) => I.inputId)
|
|
1030
|
+
])), p = Object.fromEntries(e.views.map((a) => [
|
|
1031
|
+
a.raw.id,
|
|
1032
|
+
{
|
|
1033
|
+
title: a.raw.title,
|
|
1034
|
+
visual: a.raw.visual,
|
|
1035
|
+
visualSpec: a.raw.visualSpec,
|
|
1036
|
+
queryKind: a.raw.queryKind,
|
|
1037
|
+
sdkBuilder: a.raw.sdkBuilder
|
|
1038
|
+
}
|
|
1039
|
+
])), m = Object.fromEntries(e.views.map((a) => {
|
|
1040
|
+
var I, V, d;
|
|
1041
|
+
return [
|
|
1042
|
+
a.name,
|
|
1043
|
+
M({
|
|
1044
|
+
viewId: a.raw.id,
|
|
1045
|
+
viewTitle: ((I = a.raw.visualSpec) == null ? void 0 : I.title) || a.raw.title,
|
|
1046
|
+
visualType: (V = a.raw.visualSpec) == null ? void 0 : V.visualType,
|
|
1047
|
+
title: ((d = a.raw.visualSpec) == null ? void 0 : d.title) || a.raw.title
|
|
1048
|
+
})
|
|
1049
|
+
];
|
|
1050
|
+
}));
|
|
1051
|
+
return `${q}
|
|
1052
|
+
export const generatedViewIds = ${b(o)} as const;
|
|
1053
|
+
export const generatedQueryViewIds = ${b(t)} as const;
|
|
1054
|
+
export const generatedInputIds = ${b(i)} as const;
|
|
1055
|
+
export const generatedInputOptionQueryIds = ${b(u)} as const;
|
|
1056
|
+
|
|
1057
|
+
export type SemaphorGeneratedViewId = typeof generatedViewIds[number];
|
|
1058
|
+
export type SemaphorGeneratedQueryViewId = typeof generatedQueryViewIds[number];
|
|
1059
|
+
export type SemaphorGeneratedInputId = typeof generatedInputIds[number];
|
|
1060
|
+
export type SemaphorGeneratedInputOptionQueryId = typeof generatedInputOptionQueryIds[number];
|
|
1061
|
+
export type SemaphorGeneratedFilterContract = {
|
|
1062
|
+
readonly inputId: string;
|
|
1063
|
+
readonly appliesToViewIds: readonly SemaphorGeneratedQueryViewId[];
|
|
1064
|
+
readonly notAppliedToViewIds: readonly SemaphorGeneratedQueryViewId[];
|
|
1065
|
+
readonly bindings: readonly {
|
|
1066
|
+
readonly viewId: SemaphorGeneratedQueryViewId;
|
|
1067
|
+
readonly fieldRef: Record<string, unknown>;
|
|
1068
|
+
readonly relationshipHint?: Record<string, unknown>;
|
|
1069
|
+
readonly relationshipsUsed?: readonly Record<string, unknown>[];
|
|
1070
|
+
}[];
|
|
1071
|
+
readonly [key: string]: unknown;
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
export const generatedInputIdsForView = ${b(l)} as const;
|
|
1075
|
+
export const generatedFilterContracts: readonly SemaphorGeneratedFilterContract[] = ${b(e.filterContracts)} as const;
|
|
1076
|
+
|
|
1077
|
+
export function filterContractsForView(viewId: SemaphorGeneratedQueryViewId) {
|
|
1078
|
+
return generatedFilterContracts.filter((filterContract) =>
|
|
1079
|
+
filterContract.appliesToViewIds.includes(viewId)
|
|
1080
|
+
);
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
export const queryDebugForView = ${b(m)} as const;
|
|
1084
|
+
|
|
1085
|
+
export const semaphorGeneratedContractMetadata = ${b({
|
|
1086
|
+
schemaVersion: "semaphor-generated-data-app-contract/v1",
|
|
1087
|
+
title: e.title,
|
|
1088
|
+
requiredDevtools: r,
|
|
1089
|
+
filterContracts: e.filterContracts,
|
|
1090
|
+
filterScopeByInput: n,
|
|
1091
|
+
generatedViewIds: o,
|
|
1092
|
+
generatedQueryViewIds: t,
|
|
1093
|
+
generatedInputIds: i,
|
|
1094
|
+
generatedInputOptionQueryIds: u,
|
|
1095
|
+
generatedInputIdsForView: l,
|
|
1096
|
+
visualSpecs: p,
|
|
1097
|
+
presentationViews: e.presentationViews
|
|
1098
|
+
})} as const;
|
|
1099
|
+
`;
|
|
1100
|
+
}
|
|
1101
|
+
function Ue() {
|
|
1102
|
+
return `${q}
|
|
1103
|
+
export * from "./sources";
|
|
1104
|
+
export * from "./fields";
|
|
1105
|
+
export * from "./inputs";
|
|
1106
|
+
export * from "./queries";
|
|
1107
|
+
export * from "./bindings";
|
|
1108
|
+
export * from "./accessors";
|
|
1109
|
+
export * from "./metadata";
|
|
1110
|
+
`;
|
|
1111
|
+
}
|
|
1112
|
+
function Q(e, n) {
|
|
1113
|
+
if (!(!n || typeof n != "object")) {
|
|
1114
|
+
if (Array.isArray(n)) {
|
|
1115
|
+
for (const r of n) Q(e, r);
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1118
|
+
N(n) && y(e, z(n));
|
|
1119
|
+
for (const r of Object.values(n))
|
|
1120
|
+
Q(e, r);
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
function J(e, n) {
|
|
1124
|
+
const r = [];
|
|
1125
|
+
if (Je(r, e.raw.sdkSpec), r.length === 0)
|
|
1126
|
+
for (const t of e.raw.fields || [])
|
|
1127
|
+
y(r, t);
|
|
1128
|
+
const o = ue(
|
|
1129
|
+
r.filter((t) => t.name && O(t, n)).map((t) => ({ raw: t, key: ie(t), name: "" })),
|
|
1130
|
+
(t) => t.key
|
|
1131
|
+
);
|
|
1132
|
+
return v(
|
|
1133
|
+
o,
|
|
1134
|
+
(t) => K(t.raw.label || t.raw.name || "field")
|
|
1135
|
+
), o;
|
|
1136
|
+
}
|
|
1137
|
+
function Je(e, n) {
|
|
1138
|
+
const r = S(n.spec);
|
|
1139
|
+
if (!r)
|
|
1140
|
+
return;
|
|
1141
|
+
const o = B(n.builder);
|
|
1142
|
+
if (o === "records") {
|
|
1143
|
+
for (const t of j(r.fields)) y(e, t);
|
|
1144
|
+
return;
|
|
1145
|
+
}
|
|
1146
|
+
if (o === "sql") {
|
|
1147
|
+
for (const t of j(r.fields)) y(e, t);
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
if (o === "analysis" || o === "metric") {
|
|
1151
|
+
y(e, r.primaryMeasure);
|
|
1152
|
+
for (const t of j(r.measures)) y(e, t);
|
|
1153
|
+
for (const t of j(r.dimensions)) y(e, t);
|
|
1154
|
+
y(e, r.dateField);
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
if (o === "matrix") {
|
|
1158
|
+
const t = pe(r.rows), i = pe(r.columns), u = j(r.values);
|
|
1159
|
+
for (const l of t) de(e, l);
|
|
1160
|
+
for (const l of i) de(e, l);
|
|
1161
|
+
for (const l of u) {
|
|
1162
|
+
const p = S(l);
|
|
1163
|
+
y(e, p == null ? void 0 : p.field), y(e, p == null ? void 0 : p.measure);
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
function pe(e) {
|
|
1168
|
+
if (Array.isArray(e))
|
|
1169
|
+
return e;
|
|
1170
|
+
const n = S(e);
|
|
1171
|
+
return Array.isArray(n == null ? void 0 : n.levels) ? n.levels : [];
|
|
1172
|
+
}
|
|
1173
|
+
function de(e, n) {
|
|
1174
|
+
var r;
|
|
1175
|
+
if (N(n)) {
|
|
1176
|
+
y(e, n);
|
|
1177
|
+
return;
|
|
1178
|
+
}
|
|
1179
|
+
y(e, (r = S(n)) == null ? void 0 : r.field);
|
|
1180
|
+
}
|
|
1181
|
+
function le(e) {
|
|
1182
|
+
var n, r, o, t;
|
|
1183
|
+
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" || ((o = e == null ? void 0 : e.computation) == null ? void 0 : o.kind) === "unsupported" || (e == null ? void 0 : e.visual) === "text_block" || ((t = e == null ? void 0 : e.visualSpec) == null ? void 0 : t.visualType) === "text_block";
|
|
1184
|
+
}
|
|
1185
|
+
function Le(e) {
|
|
1186
|
+
const n = S(e) || {};
|
|
1187
|
+
return M({
|
|
1188
|
+
id: e.id,
|
|
1189
|
+
title: e.title,
|
|
1190
|
+
purpose: e.purpose,
|
|
1191
|
+
visual: e.visual,
|
|
1192
|
+
visualSpec: e.visualSpec,
|
|
1193
|
+
computation: e.computation,
|
|
1194
|
+
uxExpectations: e.uxExpectations,
|
|
1195
|
+
validation: e.validation,
|
|
1196
|
+
sourceViewIds: n.sourceViewIds,
|
|
1197
|
+
content: n.content,
|
|
1198
|
+
description: n.description
|
|
1199
|
+
});
|
|
1200
|
+
}
|
|
1201
|
+
function y(e, n) {
|
|
1202
|
+
N(n) && e.push(z(n));
|
|
1203
|
+
}
|
|
1204
|
+
function z(e) {
|
|
1205
|
+
return {
|
|
1206
|
+
name: e.name,
|
|
1207
|
+
label: e.label,
|
|
1208
|
+
role: e.role,
|
|
1209
|
+
dataType: e.dataType,
|
|
1210
|
+
aggregate: e.aggregate,
|
|
1211
|
+
sourceKey: e.sourceKey || (e.source ? ae(e.source) : void 0),
|
|
1212
|
+
...e.source ? { source: e.source } : {}
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
function ze(e) {
|
|
1216
|
+
if (!e.source)
|
|
1217
|
+
return;
|
|
1218
|
+
const n = {
|
|
1219
|
+
...e.source,
|
|
1220
|
+
...e.sourceKey ? { sourceKey: e.sourceKey } : {}
|
|
1221
|
+
}, r = he(n);
|
|
1222
|
+
if (r)
|
|
1223
|
+
return {
|
|
1224
|
+
raw: n,
|
|
1225
|
+
key: r,
|
|
1226
|
+
aliases: ge(n),
|
|
1227
|
+
name: ""
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
1230
|
+
function N(e) {
|
|
1231
|
+
const n = S(e);
|
|
1232
|
+
return !!(n && typeof n.name == "string" && (typeof n.role == "string" || typeof n.dataType == "string" || typeof n.aggregate == "string" || n.source || n.sourceKey));
|
|
1233
|
+
}
|
|
1234
|
+
function fe(e) {
|
|
1235
|
+
const n = S(e);
|
|
1236
|
+
return !!(n && (typeof n.sourceKey == "string" || n.kind === "semantic" || typeof n.datasetName == "string" && typeof n.domainId == "string"));
|
|
1237
|
+
}
|
|
1238
|
+
function x(e, n) {
|
|
1239
|
+
if (e === void 0)
|
|
1240
|
+
return "undefined";
|
|
1241
|
+
if (e === null || typeof e == "number" || typeof e == "boolean" || typeof e == "string")
|
|
1242
|
+
return JSON.stringify(e);
|
|
1243
|
+
if (Array.isArray(e))
|
|
1244
|
+
return `[${e.map((t) => x(t, n)).join(", ")}]`;
|
|
1245
|
+
if (N(e)) {
|
|
1246
|
+
const t = O(z(e), n);
|
|
1247
|
+
if (t) return `fields.${t}`;
|
|
1248
|
+
}
|
|
1249
|
+
if (fe(e)) {
|
|
1250
|
+
const t = ye(e, n);
|
|
1251
|
+
if (t) return `sources.${t}`;
|
|
1252
|
+
}
|
|
1253
|
+
const r = S(e);
|
|
1254
|
+
return r ? `{ ${Object.entries(r).filter(([, t]) => t !== void 0).map(([t, i]) => `${JSON.stringify(t)}: ${x(i, n)}`).join(", ")} }` : JSON.stringify(e);
|
|
1255
|
+
}
|
|
1256
|
+
function b(e) {
|
|
1257
|
+
return JSON.stringify(e, null, 2);
|
|
1258
|
+
}
|
|
1259
|
+
function O(e, n) {
|
|
1260
|
+
if (N(e))
|
|
1261
|
+
return n.fieldNameByKey.get(ie(z(e)));
|
|
1262
|
+
}
|
|
1263
|
+
function ye(e, n) {
|
|
1264
|
+
if (fe(e))
|
|
1265
|
+
for (const r of Y(e)) {
|
|
1266
|
+
const o = n.sourceNameByKey.get(r);
|
|
1267
|
+
if (o)
|
|
1268
|
+
return o;
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
function ie(e) {
|
|
1272
|
+
return [
|
|
1273
|
+
e.sourceKey || "",
|
|
1274
|
+
e.name || "",
|
|
1275
|
+
e.role || "",
|
|
1276
|
+
e.aggregate || ""
|
|
1277
|
+
].join("|");
|
|
1278
|
+
}
|
|
1279
|
+
function Ye(e, n) {
|
|
1280
|
+
return !N(e) || !N(n) || e.name !== n.name ? !1 : oe(e).some(
|
|
1281
|
+
(r) => oe(n).includes(r)
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1284
|
+
function Ze(e) {
|
|
1285
|
+
return N(e) && e.role === "id";
|
|
1286
|
+
}
|
|
1287
|
+
function We(e) {
|
|
1288
|
+
const n = [], r = /* @__PURE__ */ new Map();
|
|
1289
|
+
for (const o of e) {
|
|
1290
|
+
const t = _(o.aliases.length ? o.aliases : [o.key]), i = t.map((u) => r.get(u)).find(A);
|
|
1291
|
+
if (i) {
|
|
1292
|
+
i.aliases = _([...i.aliases, ...t]);
|
|
1293
|
+
continue;
|
|
1294
|
+
}
|
|
1295
|
+
o.aliases = t, n.push(o);
|
|
1296
|
+
for (const u of t)
|
|
1297
|
+
r.set(u, o);
|
|
1298
|
+
}
|
|
1299
|
+
return n;
|
|
1300
|
+
}
|
|
1301
|
+
function Xe(e) {
|
|
1302
|
+
const n = /* @__PURE__ */ new Map();
|
|
1303
|
+
for (const r of e)
|
|
1304
|
+
for (const o of _([r.key, ...r.aliases])) {
|
|
1305
|
+
const t = n.get(o);
|
|
1306
|
+
if (t && t !== r.name)
|
|
1307
|
+
throw new Error(`Source identity ${o} resolves to multiple generated sources.`);
|
|
1308
|
+
n.set(o, r.name);
|
|
1309
|
+
}
|
|
1310
|
+
return n;
|
|
1311
|
+
}
|
|
1312
|
+
function _(e) {
|
|
1313
|
+
return Array.from(new Set(e.filter(Boolean)));
|
|
1314
|
+
}
|
|
1315
|
+
function he(e) {
|
|
1316
|
+
return Y(e)[0] || ae(e);
|
|
1317
|
+
}
|
|
1318
|
+
function Y(e) {
|
|
1319
|
+
const n = S(e);
|
|
1320
|
+
if (!n)
|
|
1321
|
+
return [];
|
|
1322
|
+
const r = [];
|
|
1323
|
+
if (typeof n.sourceKey == "string" && r.push(n.sourceKey), n.kind === "semantic" || n.datasetName) {
|
|
1324
|
+
const o = typeof n.domainId == "string" ? n.domainId : "";
|
|
1325
|
+
o && typeof n.datasetId == "string" && r.push(`semantic:${o}:datasetId:${n.datasetId}`), o && typeof n.datasetName == "string" && r.push(`semantic:${o}:datasetName:${n.datasetName}`);
|
|
1326
|
+
}
|
|
1327
|
+
return r.length === 0 && r.push(ae(e)), _(r);
|
|
1328
|
+
}
|
|
1329
|
+
function ge(e) {
|
|
1330
|
+
return Y(e);
|
|
1331
|
+
}
|
|
1332
|
+
function ae(e) {
|
|
1333
|
+
const n = S(e);
|
|
1334
|
+
return n ? typeof n.sourceKey == "string" ? n.sourceKey : JSON.stringify(n) : "";
|
|
1335
|
+
}
|
|
1336
|
+
function en(e) {
|
|
1337
|
+
return N(e) && oe(e)[0] || "";
|
|
1338
|
+
}
|
|
1339
|
+
function oe(e) {
|
|
1340
|
+
return N(e) ? _([
|
|
1341
|
+
...typeof e.sourceKey == "string" ? [e.sourceKey] : [],
|
|
1342
|
+
...e.source ? Y(e.source) : []
|
|
1343
|
+
]) : [];
|
|
1344
|
+
}
|
|
1345
|
+
function B(e) {
|
|
1346
|
+
const n = String(e || "").replace(/^semaphor\./, "");
|
|
1347
|
+
if (!["metric", "records", "analysis", "matrix", "sql"].includes(n))
|
|
1348
|
+
throw new Error(`Unsupported sdkSpec builder: ${e}`);
|
|
1349
|
+
return n;
|
|
1350
|
+
}
|
|
1351
|
+
function nn(e) {
|
|
1352
|
+
const n = B(e);
|
|
1353
|
+
return n === "records" || n === "sql";
|
|
1354
|
+
}
|
|
1355
|
+
function rn(e) {
|
|
1356
|
+
const n = S(e);
|
|
1357
|
+
return typeof (n == null ? void 0 : n.operator) == "string" ? n.operator : e.type === "date_range" ? "between" : e.type === "multi_select" || e.type === "select" ? "in" : "=";
|
|
1358
|
+
}
|
|
1359
|
+
function v(e, n) {
|
|
1360
|
+
const r = /* @__PURE__ */ new Map();
|
|
1361
|
+
for (const o of e) {
|
|
1362
|
+
const t = n(o) || "item", i = r.get(t) || 0;
|
|
1363
|
+
r.set(t, i + 1), o.name = i === 0 ? t : `${t}${i + 1}`;
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
function ue(e, n) {
|
|
1367
|
+
const r = /* @__PURE__ */ new Set(), o = [];
|
|
1368
|
+
for (const t of e) {
|
|
1369
|
+
const i = n(t);
|
|
1370
|
+
!i || r.has(i) || (r.add(i), o.push(t));
|
|
1371
|
+
}
|
|
1372
|
+
return o;
|
|
1373
|
+
}
|
|
1374
|
+
function K(e) {
|
|
1375
|
+
const n = String(e || "").replace(/[^A-Za-z0-9]+/g, " ").trim().split(/\s+/).filter(Boolean);
|
|
1376
|
+
if (n.length === 0)
|
|
1377
|
+
return "item";
|
|
1378
|
+
const [r, ...o] = n, t = [
|
|
1379
|
+
r.toLowerCase(),
|
|
1380
|
+
...o.map((i) => i.charAt(0).toUpperCase() + i.slice(1).toLowerCase())
|
|
1381
|
+
].join("");
|
|
1382
|
+
return /^[A-Za-z_$]/.test(t) ? t : `item${t}`;
|
|
1383
|
+
}
|
|
1384
|
+
function tn(e) {
|
|
1385
|
+
const n = String(e).split(":");
|
|
1386
|
+
return n[n.length - 1] || String(e);
|
|
1387
|
+
}
|
|
1388
|
+
function M(e) {
|
|
1389
|
+
return Object.fromEntries(Object.entries(e).filter(([, n]) => n !== void 0));
|
|
1390
|
+
}
|
|
1391
|
+
function S(e) {
|
|
1392
|
+
return e && typeof e == "object" && !Array.isArray(e) ? e : void 0;
|
|
1393
|
+
}
|
|
1394
|
+
function j(e) {
|
|
1395
|
+
return Array.isArray(e) ? e : [];
|
|
1396
|
+
}
|
|
1397
|
+
function D(e) {
|
|
1398
|
+
return typeof e == "number" && Number.isFinite(e) ? e : void 0;
|
|
1399
|
+
}
|
|
1400
|
+
function A(e) {
|
|
1401
|
+
return e !== void 0;
|
|
1402
|
+
}
|
|
1403
|
+
export {
|
|
1404
|
+
hn as CODEGEN_SUMMARY_SCHEMA_VERSION,
|
|
1405
|
+
$e as CODEGEN_SUMMARY_VALIDATOR_VERSION,
|
|
1406
|
+
Fe as CONTRACT_MANIFEST_SCHEMA_VERSION,
|
|
1407
|
+
an as DEFAULT_GENERATED_CONTRACT_OUTPUT_DIR,
|
|
1408
|
+
ce as GENERATED_CONTRACT_SCHEMA_VERSION,
|
|
1409
|
+
gn as GENERATED_CONTRACT_TYPESCRIPT_FILES,
|
|
1410
|
+
Sn as REQUIRED_GENERATED_CONTRACT_FILES,
|
|
1411
|
+
ln as SEMAPHOR_DATA_APP_CODEGEN_SUMMARY_SCHEMA_VERSION,
|
|
1412
|
+
cn as SEMAPHOR_DATA_APP_CODEGEN_SUMMARY_VALIDATOR_VERSION,
|
|
1413
|
+
Ie as assertValidCodegenSummary,
|
|
1414
|
+
wn as buildSemaphorGeneratedActiveInput,
|
|
1415
|
+
In as buildSemaphorGeneratedInputOptionIntent,
|
|
1416
|
+
$n as buildSemaphorGeneratedViewExecutionRequest,
|
|
1417
|
+
Fn as buildSemaphorGeneratedViewExecutionRequests,
|
|
1418
|
+
bn as evaluateSemaphorDataAppContractUpdatePolicy,
|
|
1419
|
+
un as generateSemaphorDataAppContract,
|
|
1420
|
+
mn as isSemaphorDataAppCodegenSummary,
|
|
1421
|
+
Vn as validateCodegenSummary,
|
|
1422
|
+
fn as validateSemaphorDataAppCodegenSummary,
|
|
1423
|
+
Rn as validateSemaphorGeneratedContract
|
|
1424
|
+
};
|