@altertable/data-app 0.72.0 → 0.74.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +5 -61
- package/CONTRIBUTING.md +130 -181
- package/README.md +3 -4
- package/REFERENCE.md +35 -345
- package/dist/chunks/contract-BeLPJwlO.js +558 -0
- package/dist/chunks/contract-BeLPJwlO.js.map +1 -0
- package/dist/chunks/contract-Di8SP74I.js +462 -0
- package/dist/chunks/contract-Di8SP74I.js.map +1 -0
- package/dist/chunks/diagnostics-BTZSlNtW.js +967 -0
- package/dist/chunks/diagnostics-BTZSlNtW.js.map +1 -0
- package/dist/chunks/format-BdFlv_xa.js +148 -0
- package/dist/chunks/format-BdFlv_xa.js.map +1 -0
- package/dist/chunks/operation-CSM9UmO3.js +134 -0
- package/dist/chunks/operation-CSM9UmO3.js.map +1 -0
- package/dist/chunks/request-body-H1qPmmTN.js +50 -0
- package/dist/chunks/request-body-H1qPmmTN.js.map +1 -0
- package/dist/client/index.js +273 -285
- package/dist/client/index.js.map +1 -13
- package/dist/core/appearance.js +171 -162
- package/dist/core/appearance.js.map +1 -10
- package/dist/core/config.js +49 -11
- package/dist/core/config.js.map +1 -9
- package/dist/core/contract.js +3 -73
- package/dist/core/format.js +1 -26
- package/dist/index.js +1 -12
- package/dist/internal.js +352 -397
- package/dist/internal.js.map +1 -15
- package/dist/server/index.js +85 -97
- package/dist/server/index.js.map +1 -10
- package/dist/types/chunks/appearance.d.ts +45 -0
- package/dist/types/chunks/contract.d.ts +720 -0
- package/dist/types/chunks/index.d.ts +240 -0
- package/dist/types/client/index.d.ts +3 -13
- package/dist/types/core/appearance.d.ts +2 -42
- package/dist/types/core/config.d.ts +36 -39
- package/dist/types/core/contract.d.ts +2 -114
- package/dist/types/core/format.d.ts +44 -17
- package/dist/types/index.d.ts +3 -3
- package/dist/types/internal.d.ts +312 -22
- package/dist/types/server/index.d.ts +15 -4
- package/docs/app-authoring.md +77 -128
- package/docs/client.md +29 -63
- package/docs/composition.md +44 -75
- package/docs/contract.md +60 -100
- package/docs/data-context.md +35 -61
- package/docs/diagnostics.md +45 -0
- package/docs/embed.md +86 -55
- package/docs/formatting-and-appearance.md +17 -38
- package/docs/hosted-apps.md +7 -14
- package/docs/layout.md +30 -47
- package/docs/local-data-apps.md +7 -7
- package/docs/react-embed.md +20 -26
- package/docs/react.md +10 -27
- package/docs/server-bun.md +2 -27
- package/docs/server.md +6 -12
- package/docs/stories-and-export.md +38 -40
- package/docs/styling.md +14 -22
- package/docs/ui-quality.md +5 -5
- package/docs/ui.md +93 -70
- package/docs/variables.md +142 -254
- package/docs/views.md +85 -116
- package/docs/widgets.md +100 -153
- package/docs/worker.md +15 -27
- package/package.json +3 -2
- package/dist/chunks/index-5a27erdg.js +0 -54
- package/dist/chunks/index-5a27erdg.js.map +0 -10
- package/dist/chunks/index-9yxr7nmm.js +0 -742
- package/dist/chunks/index-9yxr7nmm.js.map +0 -17
- package/dist/chunks/index-j5q5n3ra.js +0 -151
- package/dist/chunks/index-j5q5n3ra.js.map +0 -10
- package/dist/chunks/index-q75zm3a7.js +0 -153
- package/dist/chunks/index-q75zm3a7.js.map +0 -11
- package/dist/chunks/index-vhaec7m5.js +0 -30
- package/dist/chunks/index-vhaec7m5.js.map +0 -10
- package/dist/chunks/index-zp78caex.js +0 -1047
- package/dist/chunks/index-zp78caex.js.map +0 -19
- package/dist/core/contract.js.map +0 -9
- package/dist/core/format.js.map +0 -9
- package/dist/index.js.map +0 -9
- package/dist/types/client/annotations.d.ts +0 -27
- package/dist/types/client/data-client.d.ts +0 -43
- package/dist/types/client/download.d.ts +0 -5
- package/dist/types/client/iframe.d.ts +0 -59
- package/dist/types/client/location.d.ts +0 -13
- package/dist/types/client/logger.d.ts +0 -14
- package/dist/types/client/messages.d.ts +0 -7
- package/dist/types/client/navigation.d.ts +0 -15
- package/dist/types/client/transport.d.ts +0 -15
- package/dist/types/core/annotations.d.ts +0 -99
- package/dist/types/core/bridge-endpoint.d.ts +0 -21
- package/dist/types/core/bridge.d.ts +0 -172
- package/dist/types/core/data-view.d.ts +0 -46
- package/dist/types/core/date-format.d.ts +0 -24
- package/dist/types/core/date-range.d.ts +0 -20
- package/dist/types/core/dimension-source.d.ts +0 -64
- package/dist/types/core/dimension.d.ts +0 -71
- package/dist/types/core/facets.d.ts +0 -13
- package/dist/types/core/filters.d.ts +0 -45
- package/dist/types/core/invariant.d.ts +0 -2
- package/dist/types/core/keys.d.ts +0 -2
- package/dist/types/core/logger.d.ts +0 -12
- package/dist/types/core/messages.d.ts +0 -62
- package/dist/types/core/navigation.d.ts +0 -11
- package/dist/types/core/operation-types.d.ts +0 -80
- package/dist/types/core/operation.d.ts +0 -20
- package/dist/types/core/presentation.d.ts +0 -9
- package/dist/types/core/queries.d.ts +0 -84
- package/dist/types/core/reading.d.ts +0 -17
- package/dist/types/core/uuid.d.ts +0 -2
- package/dist/types/core/variables.d.ts +0 -133
- package/dist/types/server/handler.d.ts +0 -13
- package/dist/types/server/request-body.d.ts +0 -4
|
@@ -1,1047 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatDateRange2
|
|
3
|
-
} from "./index-q75zm3a7.js";
|
|
4
|
-
|
|
5
|
-
// packages/data-app/src/core/keys.ts
|
|
6
|
-
var KEY_SEPARATOR2 = ":";
|
|
7
|
-
|
|
8
|
-
// packages/data-app/src/core/invariant.ts
|
|
9
|
-
function invariant2(condition, message) {
|
|
10
|
-
if (!condition)
|
|
11
|
-
throw new Error(`Invariant failed: ${message}`);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// packages/data-app/src/core/dimension.ts
|
|
15
|
-
var allSelection = { kind: "all" };
|
|
16
|
-
function dimensionMemberKey2(member) {
|
|
17
|
-
return member.kind === "missing" ? "missing" : ["value", typeof member.value, member.value].join(KEY_SEPARATOR2);
|
|
18
|
-
}
|
|
19
|
-
function dimensionFilter2(config) {
|
|
20
|
-
return { ...createDimensionFilter2(config), optionsSource: "fixed" };
|
|
21
|
-
}
|
|
22
|
-
function createDimensionFilter2(config, dynamic = false) {
|
|
23
|
-
const { key, label, selectionMode, valueType } = config;
|
|
24
|
-
const options = config.options ?? [];
|
|
25
|
-
const optionKeys = options.map((option) => dimensionMemberKey2({ kind: "value", value: option.value }));
|
|
26
|
-
invariant2(!!key && options.length <= 200 && new Set(optionKeys).size === options.length, "Dimension options need a key, at most 200 distinct values.");
|
|
27
|
-
invariant2(options.every((option) => typeof option.value === valueType && !!option.label.trim() && (option.count === undefined || Number.isSafeInteger(option.count) && option.count >= 0)), "Dimension options need typed values, labels, and nonnegative counts.");
|
|
28
|
-
const allowed = new Set(optionKeys);
|
|
29
|
-
const maxSelected = config.maxSelected ?? (selectionMode === "single" ? 1 : 20);
|
|
30
|
-
invariant2(Number.isInteger(maxSelected) && maxSelected >= 1 && maxSelected <= 50 && (selectionMode !== "single" || maxSelected === 1), "Dimension selection limit is invalid.");
|
|
31
|
-
const allowMissing = config.allowMissing ?? false;
|
|
32
|
-
const defaultValue = allSelection;
|
|
33
|
-
function validMember(member) {
|
|
34
|
-
if (!member || typeof member !== "object")
|
|
35
|
-
return false;
|
|
36
|
-
if (member.kind === "missing")
|
|
37
|
-
return allowMissing;
|
|
38
|
-
if (member.kind !== "value" || typeof member.value !== valueType)
|
|
39
|
-
return false;
|
|
40
|
-
if (!dynamic)
|
|
41
|
-
return allowed.has(dimensionMemberKey2(member));
|
|
42
|
-
return typeof member.value === "number" ? Number.isFinite(member.value) : member.value.length <= 100;
|
|
43
|
-
}
|
|
44
|
-
function valid(value) {
|
|
45
|
-
if (!value || typeof value !== "object")
|
|
46
|
-
return false;
|
|
47
|
-
if (value.kind === "all")
|
|
48
|
-
return true;
|
|
49
|
-
if (value.kind !== "include" && !(config.allowExclusion && value.kind === "exclude") || !Array.isArray(value.members) || !value.members.length || value.members.length > maxSelected)
|
|
50
|
-
return false;
|
|
51
|
-
if (!value.members.every(validMember))
|
|
52
|
-
return false;
|
|
53
|
-
const ids = value.members.map(dimensionMemberKey2);
|
|
54
|
-
return new Set(ids).size === ids.length;
|
|
55
|
-
}
|
|
56
|
-
function encode(value) {
|
|
57
|
-
return value.kind === "all" ? null : JSON.stringify({
|
|
58
|
-
kind: value.kind,
|
|
59
|
-
members: value.members.map((member) => member.kind === "missing" ? ["m"] : ["v", member.value])
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
function parse(raw) {
|
|
63
|
-
if (raw === null)
|
|
64
|
-
return defaultValue;
|
|
65
|
-
if (raw.length > 4096)
|
|
66
|
-
return defaultValue;
|
|
67
|
-
try {
|
|
68
|
-
const parsed = JSON.parse(raw);
|
|
69
|
-
const tokens = Array.isArray(parsed) ? { kind: "include", members: parsed } : parsed;
|
|
70
|
-
if (!tokens || !Array.isArray(tokens.members))
|
|
71
|
-
return defaultValue;
|
|
72
|
-
const value = {
|
|
73
|
-
kind: tokens.kind,
|
|
74
|
-
members: tokens.members.map((token) => Array.isArray(token) && token.length === 1 && token[0] === "m" ? { kind: "missing" } : Array.isArray(token) && token.length === 2 && token[0] === "v" ? { kind: "value", value: token[1] } : { kind: "invalid" })
|
|
75
|
-
};
|
|
76
|
-
return valid(value) ? value : defaultValue;
|
|
77
|
-
} catch {
|
|
78
|
-
return defaultValue;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
kind: "dimension",
|
|
83
|
-
optionsSource: dynamic ? "query" : "fixed",
|
|
84
|
-
presentation: config.presentation,
|
|
85
|
-
label,
|
|
86
|
-
valueType,
|
|
87
|
-
selectionMode,
|
|
88
|
-
options,
|
|
89
|
-
allowMissing,
|
|
90
|
-
allowExclusion: config.allowExclusion ?? false,
|
|
91
|
-
maxSelected,
|
|
92
|
-
urlKeys: [key],
|
|
93
|
-
defaultValue,
|
|
94
|
-
clearValue: allSelection,
|
|
95
|
-
history: config.history ?? "push",
|
|
96
|
-
valid,
|
|
97
|
-
same(left, right) {
|
|
98
|
-
return encode(left) === encode(right);
|
|
99
|
-
},
|
|
100
|
-
read(params) {
|
|
101
|
-
return parse(params.get(key));
|
|
102
|
-
},
|
|
103
|
-
write(value) {
|
|
104
|
-
return { [key]: encode(value) };
|
|
105
|
-
},
|
|
106
|
-
describe(value, suppliedOptions = options) {
|
|
107
|
-
return value.kind === "all" ? `All ${label.toLocaleLowerCase()}` : `${value.kind === "exclude" ? "Exclude: " : ""}${value.members.map((member) => member.kind === "missing" ? "Missing" : suppliedOptions.find((option) => option.value === member.value)?.label ?? String(member.value)).join(", ")}`;
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
function parseDimensionSelection2(value, filter) {
|
|
112
|
-
invariant2(filter.valid(value), `Invalid ${filter.label} selection.`);
|
|
113
|
-
return value;
|
|
114
|
-
}
|
|
115
|
-
function parseFacetOptions2(value, filter) {
|
|
116
|
-
invariant2(Array.isArray(value) && value.length <= 200, "Facet options exceed their bound.");
|
|
117
|
-
const options = [];
|
|
118
|
-
const seen = new Set;
|
|
119
|
-
for (const item of value) {
|
|
120
|
-
invariant2(item && typeof item === "object", "Invalid facet option.");
|
|
121
|
-
const option = item;
|
|
122
|
-
invariant2(typeof option.value === filter.valueType && filter.valid({
|
|
123
|
-
kind: "include",
|
|
124
|
-
members: [{ kind: "value", value: option.value }]
|
|
125
|
-
}) && typeof option.label === "string" && !!option.label.trim() && option.label.length <= 100 && (option.count === undefined || Number.isSafeInteger(option.count) && option.count >= 0), "Invalid facet option.");
|
|
126
|
-
const id = dimensionMemberKey2({ kind: "value", value: option.value });
|
|
127
|
-
invariant2(!seen.has(id), "Duplicate facet option.");
|
|
128
|
-
seen.add(id);
|
|
129
|
-
options.push(option);
|
|
130
|
-
}
|
|
131
|
-
return options;
|
|
132
|
-
}
|
|
133
|
-
function dimensionPredicate2(column, selection, allowedColumns) {
|
|
134
|
-
invariant2(allowedColumns.includes(column) && /^[A-Za-z_][A-Za-z_0-9]*(?:\.[A-Za-z_][A-Za-z_0-9]*)*$/.test(column), "Invalid dimension column.");
|
|
135
|
-
if (selection.kind === "all")
|
|
136
|
-
return "";
|
|
137
|
-
invariant2(selection.members.length > 0, "Empty dimension inclusion is invalid.");
|
|
138
|
-
const values = selection.members.filter((member) => member.kind === "value");
|
|
139
|
-
const missing = selection.members.some((member) => member.kind === "missing");
|
|
140
|
-
const literals = values.map(({ value }) => {
|
|
141
|
-
if (typeof value === "number") {
|
|
142
|
-
invariant2(Number.isFinite(value), "Invalid numeric dimension value.");
|
|
143
|
-
return String(value);
|
|
144
|
-
}
|
|
145
|
-
const text = value;
|
|
146
|
-
for (let index = 0;index < text.length; index++)
|
|
147
|
-
invariant2(text.charCodeAt(index) >= 32 && text.charCodeAt(index) !== 127, "Invalid control character in dimension value.");
|
|
148
|
-
return `'${text.replaceAll("'", "''")}'`;
|
|
149
|
-
});
|
|
150
|
-
const clauses = [
|
|
151
|
-
...literals.length ? [`${column} IN (${literals.join(", ")})`] : [],
|
|
152
|
-
...missing ? [`${column} IS NULL`] : []
|
|
153
|
-
];
|
|
154
|
-
const predicate = `(${clauses.join(" OR ")})`;
|
|
155
|
-
return selection.kind === "exclude" ? missing ? `NOT ${predicate}` : `(${column} IS NULL OR NOT ${predicate})` : predicate;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// packages/data-app/src/core/queries.ts
|
|
159
|
-
var QUERY_CAST_ERROR = "##ERROR##";
|
|
160
|
-
function isQueryParameterValue(value) {
|
|
161
|
-
return value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value);
|
|
162
|
-
}
|
|
163
|
-
function isQueryParameters(value) {
|
|
164
|
-
return !!value && typeof value === "object" && !Array.isArray(value) && Object.values(value).every(isQueryParameterValue);
|
|
165
|
-
}
|
|
166
|
-
function snapshotField(field) {
|
|
167
|
-
invariant2(field && typeof field === "object" && !Array.isArray(field) && (field.type === "string" || field.type === "number" || field.type === "boolean" || field.type === "null") && (field.nullable === undefined || typeof field.nullable === "boolean"), "Query fields need a supported type and a boolean nullable flag.");
|
|
168
|
-
return Object.freeze({ ...field });
|
|
169
|
-
}
|
|
170
|
-
function snapshotQueries(definitions) {
|
|
171
|
-
return Object.freeze(Object.fromEntries(Object.entries(definitions).map(([name, query]) => {
|
|
172
|
-
invariant2(!!name.trim() && !!query.statement.trim(), "Queries need a name and SQL statement.");
|
|
173
|
-
const params = Object.freeze(Object.fromEntries(Object.entries(query.params).map(([key, declaration]) => {
|
|
174
|
-
invariant2(!Object.hasOwn(declaration, "defaultValue") || isQueryParameterValue(declaration.defaultValue), `Invalid default for parameter ${key} in query ${name}.`);
|
|
175
|
-
return [key, snapshotField(declaration)];
|
|
176
|
-
})));
|
|
177
|
-
const projectionEntries = Object.entries(query.projections);
|
|
178
|
-
invariant2(projectionEntries.length > 0 && projectionEntries.every(([alias]) => !!alias.trim()), "Queries need at least one named projection.");
|
|
179
|
-
return [
|
|
180
|
-
name,
|
|
181
|
-
Object.freeze({
|
|
182
|
-
statement: query.statement,
|
|
183
|
-
params,
|
|
184
|
-
projections: Object.freeze(Object.fromEntries(projectionEntries.map(([alias, field]) => [
|
|
185
|
-
alias,
|
|
186
|
-
snapshotField(field)
|
|
187
|
-
])))
|
|
188
|
-
})
|
|
189
|
-
];
|
|
190
|
-
})));
|
|
191
|
-
}
|
|
192
|
-
function decodeQueryResult(result, projections) {
|
|
193
|
-
if (!result || !Array.isArray(result.columns) || !Array.isArray(result.rows) || result.queryId !== undefined && typeof result.queryId !== "string") {
|
|
194
|
-
throw new Error("Query result must contain columns and rows.");
|
|
195
|
-
}
|
|
196
|
-
const returnedColumns = Array.from(result.columns, (column) => {
|
|
197
|
-
if (!column || typeof column !== "object" || Array.isArray(column) || typeof column.name !== "string" || column.type !== undefined && typeof column.type !== "string") {
|
|
198
|
-
throw new Error("Query result columns must have names and optional type strings.");
|
|
199
|
-
}
|
|
200
|
-
return {
|
|
201
|
-
name: column.name,
|
|
202
|
-
...column.type === undefined ? {} : { type: column.type }
|
|
203
|
-
};
|
|
204
|
-
});
|
|
205
|
-
const names = returnedColumns.map((column) => column.name);
|
|
206
|
-
const rows = Array.from(result.rows, (row) => {
|
|
207
|
-
if (!Array.isArray(row) || row.length !== names.length) {
|
|
208
|
-
throw new Error("Query result row has the wrong width.");
|
|
209
|
-
}
|
|
210
|
-
return Object.fromEntries(names.map((name, index) => [
|
|
211
|
-
name,
|
|
212
|
-
castQueryCell(row[index], projections[name])
|
|
213
|
-
]));
|
|
214
|
-
});
|
|
215
|
-
return {
|
|
216
|
-
columns: returnedColumns,
|
|
217
|
-
rows,
|
|
218
|
-
...result.queryId === undefined ? {} : { queryId: result.queryId }
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
function castQueryCell(value, field) {
|
|
222
|
-
if (field === undefined) {
|
|
223
|
-
if (typeof value === "string" || typeof value === "boolean" || typeof value === "number")
|
|
224
|
-
return value;
|
|
225
|
-
if (value === null)
|
|
226
|
-
return null;
|
|
227
|
-
return JSON.stringify(value);
|
|
228
|
-
}
|
|
229
|
-
if (value === null && field.nullable !== false)
|
|
230
|
-
return null;
|
|
231
|
-
switch (field.type) {
|
|
232
|
-
case "string":
|
|
233
|
-
return String(value);
|
|
234
|
-
case "number": {
|
|
235
|
-
const number = Number(value);
|
|
236
|
-
return Number.isFinite(number) ? number : QUERY_CAST_ERROR;
|
|
237
|
-
}
|
|
238
|
-
case "boolean":
|
|
239
|
-
return Boolean(value);
|
|
240
|
-
case "null":
|
|
241
|
-
return null;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
function resolveQueryParameters(declarations, values, context) {
|
|
245
|
-
if (!values || typeof values !== "object" || Array.isArray(values))
|
|
246
|
-
throw new Error("Supply query parameter values as an object.");
|
|
247
|
-
for (const key of Object.keys(values)) {
|
|
248
|
-
if (!Object.hasOwn(declarations, key))
|
|
249
|
-
throw new Error(`Unknown parameter ${key}.`);
|
|
250
|
-
if (Object.hasOwn(context, key))
|
|
251
|
-
throw new Error(`Cannot override context parameter ${key}.`);
|
|
252
|
-
}
|
|
253
|
-
return Object.fromEntries(Object.entries(declarations).map(([key, declaration]) => {
|
|
254
|
-
const value = Object.hasOwn(context, key) ? context[key] : Object.hasOwn(values, key) && values[key] !== undefined ? values[key] : declaration.defaultValue;
|
|
255
|
-
if (value === undefined)
|
|
256
|
-
throw new Error(`Missing parameter ${key}.`);
|
|
257
|
-
const nullable = declaration.type === "null" || declaration.nullable === true;
|
|
258
|
-
if (!(value === null ? nullable : typeof value === declaration.type && isQueryParameterValue(value)))
|
|
259
|
-
throw new Error(`Parameter ${key} does not match ${declaration.type}.`);
|
|
260
|
-
return [key, value];
|
|
261
|
-
}));
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// packages/data-app/src/core/dimension-source.ts
|
|
265
|
-
var dimensionSource2 = Symbol("data-app.dimensionSource");
|
|
266
|
-
var sources = new WeakMap;
|
|
267
|
-
var parserVariables = new WeakMap;
|
|
268
|
-
var selectorsKey = Symbol.for("@altertable/data-app/dimension-selectors");
|
|
269
|
-
var ownerKey = Symbol.for("@altertable/data-app/dimension-selector-owner");
|
|
270
|
-
var invalidMemberKey = Symbol.for("@altertable/data-app/dimension-member-error");
|
|
271
|
-
|
|
272
|
-
class DimensionMembershipError extends Error {
|
|
273
|
-
[invalidMemberKey] = true;
|
|
274
|
-
static [Symbol.hasInstance](value) {
|
|
275
|
-
return value instanceof Error && value[invalidMemberKey] === true;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
function variableInput2(parse, variables) {
|
|
279
|
-
const previous = parserVariables.get(parse) ?? {};
|
|
280
|
-
const definitions = { ...variables };
|
|
281
|
-
for (const [name, variable] of Object.entries(definitions))
|
|
282
|
-
invariant2(!previous[name] || previous[name] === variable, `Variable input ${name} is already declared.`);
|
|
283
|
-
function parser(value) {
|
|
284
|
-
invariant2(value && typeof value === "object" && !Array.isArray(value), "Expected variable input.");
|
|
285
|
-
const input = parse(value);
|
|
286
|
-
invariant2(input && typeof input === "object" && !Array.isArray(input), "Expected parsed input object.");
|
|
287
|
-
const values = {};
|
|
288
|
-
for (const [name, variable] of Object.entries(definitions)) {
|
|
289
|
-
const selected = value[name];
|
|
290
|
-
invariant2(variable.valid(selected), `Invalid ${variable.label ?? name}.`);
|
|
291
|
-
values[name] = selected;
|
|
292
|
-
}
|
|
293
|
-
return { ...input, ...values };
|
|
294
|
-
}
|
|
295
|
-
parserVariables.set(parser, {
|
|
296
|
-
...previous,
|
|
297
|
-
...definitions
|
|
298
|
-
});
|
|
299
|
-
return parser;
|
|
300
|
-
}
|
|
301
|
-
function bindDimensionSource(config, queries) {
|
|
302
|
-
invariant2(!config.allowMissing, "Source dimensions require concrete members.");
|
|
303
|
-
const query = queries[config.source.query];
|
|
304
|
-
invariant2(query && Object.hasOwn(query.params, "member"), "Dimension sources must declare member.");
|
|
305
|
-
const member = query.params.member;
|
|
306
|
-
const { value, label, count } = query.projections;
|
|
307
|
-
invariant2(member.type === config.valueType && member.nullable === true && value?.type === config.valueType && value.nullable !== true && label?.type === "string" && label.nullable !== true && (!count || count.type === "number" && count.nullable !== true), "Dimension sources require a matching nullable member and concrete value, label, and count projections.");
|
|
308
|
-
const operation = `__dimension:${config.key}`;
|
|
309
|
-
const variable = Object.assign(createDimensionFilter2({
|
|
310
|
-
...config,
|
|
311
|
-
valueType: config.valueType,
|
|
312
|
-
options: []
|
|
313
|
-
}, true), {
|
|
314
|
-
optionsSource: "query",
|
|
315
|
-
[dimensionSource2]: Object.freeze({ operation })
|
|
316
|
-
});
|
|
317
|
-
sources.set(variable, { query: config.source.query, queries });
|
|
318
|
-
return variable;
|
|
319
|
-
}
|
|
320
|
-
async function loadOptions(variable, member, query) {
|
|
321
|
-
const source = sources.get(variable);
|
|
322
|
-
const result = await query(source.query, { member }, { limit: member === null ? 200 : 2 });
|
|
323
|
-
const names = result.columns.map((column) => column.name);
|
|
324
|
-
invariant2(new Set(names).size === names.length && names.includes("value") && names.includes("label"), "Dimension source must return value and label.");
|
|
325
|
-
const options = parseFacetOptions2(result.rows, variable);
|
|
326
|
-
if (member !== null && (options.length !== 1 || options[0].value !== member))
|
|
327
|
-
throw new DimensionMembershipError(`Invalid ${variable.label} member.`);
|
|
328
|
-
return options;
|
|
329
|
-
}
|
|
330
|
-
async function validateVariableInput(parser, input, query) {
|
|
331
|
-
for (const [name, variable] of Object.entries(parserVariables.get(parser) ?? {})) {
|
|
332
|
-
if (variable.kind !== "dimension" || !sources.has(variable))
|
|
333
|
-
continue;
|
|
334
|
-
const selection = input[name];
|
|
335
|
-
if (selection.kind === "all")
|
|
336
|
-
continue;
|
|
337
|
-
for (const member of selection.members)
|
|
338
|
-
if (member.kind === "value")
|
|
339
|
-
await loadOptions(variable, member.value, query);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
function attachDimensionSelectors(operation, queries) {
|
|
343
|
-
const selectors = {};
|
|
344
|
-
for (const variable of Object.values(parserVariables.get(operation.input) ?? {})) {
|
|
345
|
-
if (variable.kind !== "dimension" || !(dimensionSource2 in variable))
|
|
346
|
-
continue;
|
|
347
|
-
const source = sources.get(variable);
|
|
348
|
-
if (!source)
|
|
349
|
-
continue;
|
|
350
|
-
invariant2(JSON.stringify(source.queries[source.query]) === JSON.stringify(queries[source.query]), "Dimension sources must belong to the operation query registry.");
|
|
351
|
-
const name = variable[dimensionSource2].operation;
|
|
352
|
-
invariant2(!selectors[name] || selectors[name][ownerKey] === variable, "Dimension source keys must be unique across the app.");
|
|
353
|
-
selectors[name] = {
|
|
354
|
-
input(value) {
|
|
355
|
-
invariant2(value && typeof value === "object", "Invalid dimension request.");
|
|
356
|
-
const member = value.member;
|
|
357
|
-
invariant2(member === null || variable.valid({
|
|
358
|
-
kind: "include",
|
|
359
|
-
members: [{ kind: "value", value: member }]
|
|
360
|
-
}), "Invalid requested member.");
|
|
361
|
-
return { member };
|
|
362
|
-
},
|
|
363
|
-
checks: [{ member: null }],
|
|
364
|
-
policy: {
|
|
365
|
-
maxDurationMs: 15000,
|
|
366
|
-
maxQueryRows: 200,
|
|
367
|
-
maxResponseBytes: 1e6
|
|
368
|
-
},
|
|
369
|
-
queryNames: { [source.query]: source.query },
|
|
370
|
-
async run(context, input) {
|
|
371
|
-
return loadOptions(variable, input.member, async (name, params, options) => {
|
|
372
|
-
const definition = queries[name];
|
|
373
|
-
const result = await context.lakehouse.queryAll(definition.statement, {
|
|
374
|
-
name,
|
|
375
|
-
params: resolveQueryParameters(definition.params, params, context.queryParams ?? {}),
|
|
376
|
-
limit: options.limit,
|
|
377
|
-
signal: context.signal
|
|
378
|
-
});
|
|
379
|
-
return decodeQueryResult(result, definition.projections);
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
Object.defineProperty(selectors[name], ownerKey, { value: variable });
|
|
384
|
-
}
|
|
385
|
-
Object.defineProperty(operation, selectorsKey, { value: selectors });
|
|
386
|
-
}
|
|
387
|
-
function withDimensionSelectors(operations) {
|
|
388
|
-
const expanded = { ...operations };
|
|
389
|
-
for (const operation of Object.values(operations))
|
|
390
|
-
for (const [name, selector] of Object.entries(operation[selectorsKey] ?? {})) {
|
|
391
|
-
invariant2(!Object.hasOwn(operations, name), "Reserved dimension operation name.");
|
|
392
|
-
invariant2(!expanded[name] || expanded[name][ownerKey] === selector[ownerKey], "Dimension source keys must be unique across the app.");
|
|
393
|
-
expanded[name] ??= selector;
|
|
394
|
-
}
|
|
395
|
-
return expanded;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
// packages/data-app/src/core/contract.ts
|
|
399
|
-
import { parseDate, today } from "@internationalized/date";
|
|
400
|
-
// packages/data-app/src/core/navigation.ts
|
|
401
|
-
function validLocation(value) {
|
|
402
|
-
if (!value || typeof value !== "object")
|
|
403
|
-
return false;
|
|
404
|
-
const message = value;
|
|
405
|
-
return typeof message.search === "string" && message.search.length <= 16384 && (message.search === "" || message.search.startsWith("?")) && typeof message.hash === "string" && message.hash.length <= 4096 && (message.hash === "" || message.hash.startsWith("#"));
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
// packages/data-app/src/core/messages.ts
|
|
409
|
-
var errorBrand = Symbol.for("@altertable/data-app/MessageRoutingError");
|
|
410
|
-
|
|
411
|
-
class MessageRoutingError2 extends Error {
|
|
412
|
-
code;
|
|
413
|
-
requestId;
|
|
414
|
-
[errorBrand] = true;
|
|
415
|
-
static [Symbol.hasInstance](value) {
|
|
416
|
-
return value instanceof Error && value[errorBrand] === true;
|
|
417
|
-
}
|
|
418
|
-
constructor(code, message, requestId, options) {
|
|
419
|
-
super(message, options);
|
|
420
|
-
this.code = code;
|
|
421
|
-
this.requestId = requestId;
|
|
422
|
-
this.name = "MessageRoutingError";
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
function defineMessageRoute2(route) {
|
|
426
|
-
return route;
|
|
427
|
-
}
|
|
428
|
-
function createMessageRouter2(routes, handlers) {
|
|
429
|
-
const registered = new Map(Object.entries(routes).map(([name, contract]) => {
|
|
430
|
-
const handler = handlers[name];
|
|
431
|
-
if (!name || name.length > 256 || typeof handler !== "function")
|
|
432
|
-
throw new Error("Each message route requires a handler and a bounded name.");
|
|
433
|
-
return [name, { contract, handler }];
|
|
434
|
-
}));
|
|
435
|
-
async function dispatch(value, context) {
|
|
436
|
-
if (!value || typeof value !== "object" || typeof value.route !== "string")
|
|
437
|
-
throw new MessageRoutingError2("invalid_message", "Invalid routed message.");
|
|
438
|
-
const message = value;
|
|
439
|
-
const entry = registered.get(message.route);
|
|
440
|
-
if (!entry)
|
|
441
|
-
throw new MessageRoutingError2("unknown_route", "Unknown message route.");
|
|
442
|
-
let payload;
|
|
443
|
-
try {
|
|
444
|
-
payload = entry.contract.input(message.payload);
|
|
445
|
-
} catch {
|
|
446
|
-
throw new MessageRoutingError2("invalid_payload", "Invalid message payload.");
|
|
447
|
-
}
|
|
448
|
-
context.signal.throwIfAborted();
|
|
449
|
-
let result;
|
|
450
|
-
try {
|
|
451
|
-
result = await entry.handler(payload, context);
|
|
452
|
-
} catch (error) {
|
|
453
|
-
if (context.signal.aborted)
|
|
454
|
-
throw context.signal.reason;
|
|
455
|
-
if (error instanceof MessageRoutingError2)
|
|
456
|
-
throw error;
|
|
457
|
-
throw new MessageRoutingError2("request_failed", "The message request failed. Retry the request.");
|
|
458
|
-
}
|
|
459
|
-
context.signal.throwIfAborted();
|
|
460
|
-
try {
|
|
461
|
-
return entry.contract.output(result, payload);
|
|
462
|
-
} catch (error) {
|
|
463
|
-
if (error instanceof MessageRoutingError2)
|
|
464
|
-
throw error;
|
|
465
|
-
throw new MessageRoutingError2("invalid_response", "Invalid message response.");
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
return { dispatch };
|
|
469
|
-
}
|
|
470
|
-
function defineDataQueryRoute2(operations) {
|
|
471
|
-
return {
|
|
472
|
-
operations,
|
|
473
|
-
input(value) {
|
|
474
|
-
if (!value || typeof value !== "object")
|
|
475
|
-
throw new Error("Invalid query.");
|
|
476
|
-
const request = value;
|
|
477
|
-
if (typeof request.operation !== "string" || !request.operation || request.operation.length > 256 || request.operation.includes("/"))
|
|
478
|
-
throw new Error("Invalid operation.");
|
|
479
|
-
const operation = operations && Object.hasOwn(operations, request.operation) ? operations[request.operation] : undefined;
|
|
480
|
-
if (operations && !operation)
|
|
481
|
-
throw new Error("Unknown operation.");
|
|
482
|
-
return {
|
|
483
|
-
operation: request.operation,
|
|
484
|
-
input: operation ? operation.input(request.input) : request.input
|
|
485
|
-
};
|
|
486
|
-
},
|
|
487
|
-
output(value) {
|
|
488
|
-
if (!value || typeof value !== "object")
|
|
489
|
-
throw new Error("Invalid data response.");
|
|
490
|
-
const response = value;
|
|
491
|
-
if (!Number.isInteger(response.status) || response.status < 100 || response.status > 599 || !response.body || typeof response.body !== "object" || Array.isArray(response.body))
|
|
492
|
-
throw new Error("Invalid data response.");
|
|
493
|
-
const body = response.body;
|
|
494
|
-
if (response.status < 200 || response.status >= 300) {
|
|
495
|
-
const failure = body.error;
|
|
496
|
-
throw new MessageRoutingError2(typeof failure?.code === "string" ? failure.code : "request_failed", typeof failure?.message === "string" ? failure.message : "Could not load data.", typeof failure?.requestId === "string" ? failure.requestId : undefined);
|
|
497
|
-
}
|
|
498
|
-
if (!("data" in body) || typeof body.requestId !== "string" || typeof body.queriedAt !== "string" || !Array.isArray(body.queryIds) || !body.queryIds.every((id) => typeof id === "string"))
|
|
499
|
-
throw new Error("Invalid data envelope.");
|
|
500
|
-
if (body.queries !== undefined && (!Array.isArray(body.queries) || !body.queries.every((query) => query && typeof query === "object" && typeof query.name === "string" && typeof query.statement === "string" && (query.params === undefined || isQueryParameters(query.params)) && (query.queryId === undefined || typeof query.queryId === "string"))))
|
|
501
|
-
throw new Error("Invalid query evidence.");
|
|
502
|
-
return { status: response.status, body };
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
var navigationUpdateRoute2 = /* @__PURE__ */ defineMessageRoute2({
|
|
507
|
-
input(value) {
|
|
508
|
-
if (!value || typeof value !== "object")
|
|
509
|
-
throw new Error("Invalid navigation.");
|
|
510
|
-
const input = value;
|
|
511
|
-
if (!validLocation(input) || input.mode !== "push" && input.mode !== "replace" || input.title !== undefined && (typeof input.title !== "string" || input.title.length > 512))
|
|
512
|
-
throw new Error("Invalid navigation.");
|
|
513
|
-
return {
|
|
514
|
-
search: input.search,
|
|
515
|
-
hash: input.hash,
|
|
516
|
-
mode: input.mode,
|
|
517
|
-
...input.title === undefined ? {} : { title: input.title }
|
|
518
|
-
};
|
|
519
|
-
},
|
|
520
|
-
output(value) {
|
|
521
|
-
if (value !== null)
|
|
522
|
-
throw new Error("Invalid navigation response.");
|
|
523
|
-
return null;
|
|
524
|
-
}
|
|
525
|
-
});
|
|
526
|
-
var sqlQueryRoute2 = defineMessageRoute2({
|
|
527
|
-
input(value) {
|
|
528
|
-
if (!value || typeof value !== "object")
|
|
529
|
-
throw new Error("Invalid SQL query.");
|
|
530
|
-
const query = value;
|
|
531
|
-
if (typeof query.statement !== "string" || !query.statement.trim() || typeof query.limit !== "number" || !Number.isSafeInteger(query.limit) || query.limit < 1 || query.params !== undefined && !isQueryParameters(query.params))
|
|
532
|
-
throw new Error("Invalid SQL query.");
|
|
533
|
-
return {
|
|
534
|
-
statement: query.statement,
|
|
535
|
-
limit: query.limit,
|
|
536
|
-
...query.params === undefined ? {} : { params: query.params }
|
|
537
|
-
};
|
|
538
|
-
},
|
|
539
|
-
output(value, input) {
|
|
540
|
-
if (!value || typeof value !== "object")
|
|
541
|
-
throw new Error("Invalid query result.");
|
|
542
|
-
const result = value;
|
|
543
|
-
if (!Array.isArray(result.columns) || !result.columns.every((column) => column && typeof column.name === "string" && (column.type === undefined || typeof column.type === "string")) || !Array.isArray(result.rows) || result.rows.length > input.limit || !result.rows.every((row) => Array.isArray(row) && row.length === result.columns.length) || result.queryId !== undefined && typeof result.queryId !== "string")
|
|
544
|
-
throw new Error("Invalid query result.");
|
|
545
|
-
return {
|
|
546
|
-
columns: result.columns,
|
|
547
|
-
rows: result.rows,
|
|
548
|
-
...result.queryId === undefined ? {} : { queryId: result.queryId }
|
|
549
|
-
};
|
|
550
|
-
}
|
|
551
|
-
});
|
|
552
|
-
var dataAppRoutes2 = {
|
|
553
|
-
"data:query": /* @__PURE__ */ defineDataQueryRoute2(),
|
|
554
|
-
"navigation:update": navigationUpdateRoute2
|
|
555
|
-
};
|
|
556
|
-
// packages/data-app/src/core/annotations.ts
|
|
557
|
-
function object(value) {
|
|
558
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
559
|
-
throw new Error("Invalid annotation.");
|
|
560
|
-
return value;
|
|
561
|
-
}
|
|
562
|
-
function text(value, limit, required = false) {
|
|
563
|
-
if (typeof value !== "string" || value.length > limit || required && !value.trim())
|
|
564
|
-
throw new Error("Invalid annotation text.");
|
|
565
|
-
return value;
|
|
566
|
-
}
|
|
567
|
-
function names(value) {
|
|
568
|
-
if (!Array.isArray(value) || value.length > 20)
|
|
569
|
-
throw new Error("Invalid annotation references.");
|
|
570
|
-
return value.map((name) => text(name, 128, true));
|
|
571
|
-
}
|
|
572
|
-
function number(value, positive = false) {
|
|
573
|
-
if (typeof value !== "number" || !Number.isFinite(value) || Math.abs(value) > 1e6 || positive && value < 0)
|
|
574
|
-
throw new Error("Invalid annotation geometry.");
|
|
575
|
-
return value;
|
|
576
|
-
}
|
|
577
|
-
function parseDataAppAnnotationDraft2(value) {
|
|
578
|
-
const input = object(value);
|
|
579
|
-
const target = object(input.target);
|
|
580
|
-
const context = object(input.context);
|
|
581
|
-
const viewport = object(context.viewport);
|
|
582
|
-
const rect = object(context.rect);
|
|
583
|
-
if (target.kind !== "widget" && target.kind !== "element" && target.kind !== "app")
|
|
584
|
-
throw new Error("Invalid annotation target.");
|
|
585
|
-
let screenshot;
|
|
586
|
-
if (context.screenshot !== undefined) {
|
|
587
|
-
const image = object(context.screenshot);
|
|
588
|
-
const dataUrl = text(image.dataUrl, 350000, true);
|
|
589
|
-
if (image.mimeType !== "image/png" || !/^data:image\/png;base64,iVBORw0KGgo[A-Za-z0-9+/]*={0,2}$/.test(dataUrl))
|
|
590
|
-
throw new Error("Invalid annotation screenshot.");
|
|
591
|
-
const width = number(image.width, true);
|
|
592
|
-
const height = number(image.height, true);
|
|
593
|
-
if (!Number.isInteger(width) || !Number.isInteger(height) || width < 1 || height < 1 || width > 1024 || height > 1024)
|
|
594
|
-
throw new Error("Invalid screenshot dimensions.");
|
|
595
|
-
const encoded = dataUrl.slice("data:image/png;base64,".length);
|
|
596
|
-
if (encoded.length % 4 !== 0 || encoded.length / 4 * 3 - (encoded.endsWith("==") ? 2 : encoded.endsWith("=") ? 1 : 0) > 262144)
|
|
597
|
-
throw new Error("Screenshot is too large.");
|
|
598
|
-
const header = atob(encoded.slice(0, 44));
|
|
599
|
-
if (header.length < 24 || header.slice(12, 16) !== "IHDR")
|
|
600
|
-
throw new Error("Invalid PNG header.");
|
|
601
|
-
const bytes = Uint8Array.from(header, (character) => character.charCodeAt(0));
|
|
602
|
-
const dimensions = new DataView(bytes.buffer);
|
|
603
|
-
if (dimensions.getUint32(16) !== width || dimensions.getUint32(20) !== height)
|
|
604
|
-
throw new Error("Screenshot dimensions do not match the image.");
|
|
605
|
-
screenshot = { mimeType: "image/png", dataUrl, width, height };
|
|
606
|
-
}
|
|
607
|
-
let anchor;
|
|
608
|
-
if (context.anchor !== undefined) {
|
|
609
|
-
const point = object(context.anchor);
|
|
610
|
-
const x = number(point.x, true);
|
|
611
|
-
const y = number(point.y, true);
|
|
612
|
-
if (x > 1 || y > 1)
|
|
613
|
-
throw new Error("Invalid annotation anchor.");
|
|
614
|
-
anchor = { x, y };
|
|
615
|
-
}
|
|
616
|
-
let cursor;
|
|
617
|
-
if (context.cursor !== undefined) {
|
|
618
|
-
const point = object(context.cursor);
|
|
619
|
-
cursor = { x: number(point.x), y: number(point.y) };
|
|
620
|
-
}
|
|
621
|
-
let region;
|
|
622
|
-
if (context.region !== undefined) {
|
|
623
|
-
const area = object(context.region);
|
|
624
|
-
region = {
|
|
625
|
-
x: number(area.x, true),
|
|
626
|
-
y: number(area.y, true),
|
|
627
|
-
width: number(area.width, true),
|
|
628
|
-
height: number(area.height, true)
|
|
629
|
-
};
|
|
630
|
-
if (target.kind !== "app" || region.width <= 0 || region.height <= 0 || region.x + region.width > 1.000001 || region.y + region.height > 1.000001)
|
|
631
|
-
throw new Error("Invalid annotation selection.");
|
|
632
|
-
}
|
|
633
|
-
const draft = {
|
|
634
|
-
id: text(input.id, 128, true),
|
|
635
|
-
target: {
|
|
636
|
-
id: text(target.id, 128, true),
|
|
637
|
-
label: text(target.label, 256, true),
|
|
638
|
-
kind: target.kind,
|
|
639
|
-
text: text(target.text, 1024),
|
|
640
|
-
queryNames: names(target.queryNames),
|
|
641
|
-
glossaryIds: names(target.glossaryIds)
|
|
642
|
-
},
|
|
643
|
-
context: {
|
|
644
|
-
...anchor ? { anchor } : {},
|
|
645
|
-
...region ? { region } : {},
|
|
646
|
-
...cursor ? { cursor } : {},
|
|
647
|
-
...screenshot ? { screenshot } : {},
|
|
648
|
-
search: text(context.search, 2048),
|
|
649
|
-
hash: text(context.hash, 1024),
|
|
650
|
-
viewport: {
|
|
651
|
-
width: number(viewport.width, true),
|
|
652
|
-
height: number(viewport.height, true)
|
|
653
|
-
},
|
|
654
|
-
rect: {
|
|
655
|
-
x: number(rect.x),
|
|
656
|
-
y: number(rect.y),
|
|
657
|
-
width: number(rect.width, true),
|
|
658
|
-
height: number(rect.height, true)
|
|
659
|
-
},
|
|
660
|
-
...context.view === undefined ? {} : { view: text(context.view, 128) },
|
|
661
|
-
...context.displayedInput === undefined ? {} : { displayedInput: context.displayedInput }
|
|
662
|
-
},
|
|
663
|
-
comment: text(input.comment, 2000, true).trim()
|
|
664
|
-
};
|
|
665
|
-
const json = JSON.stringify({
|
|
666
|
-
...draft,
|
|
667
|
-
context: { ...draft.context, screenshot: undefined }
|
|
668
|
-
});
|
|
669
|
-
if (new TextEncoder().encode(json).byteLength > 12000)
|
|
670
|
-
throw new Error("Annotation is too large.");
|
|
671
|
-
return JSON.parse(JSON.stringify(draft));
|
|
672
|
-
}
|
|
673
|
-
var annotationDraftRoute2 = /* @__PURE__ */ defineMessageRoute2({
|
|
674
|
-
input: parseDataAppAnnotationDraft2,
|
|
675
|
-
output(value) {
|
|
676
|
-
if (value !== null)
|
|
677
|
-
throw new Error("Invalid annotation response.");
|
|
678
|
-
return null;
|
|
679
|
-
}
|
|
680
|
-
});
|
|
681
|
-
var annotationEditorStateRoute2 = /* @__PURE__ */ defineMessageRoute2({
|
|
682
|
-
input(value) {
|
|
683
|
-
const input = object(value);
|
|
684
|
-
if (typeof input.hasUnsavedChanges !== "boolean")
|
|
685
|
-
throw new Error("Invalid annotation editor state.");
|
|
686
|
-
return { hasUnsavedChanges: input.hasUnsavedChanges };
|
|
687
|
-
},
|
|
688
|
-
output(value) {
|
|
689
|
-
if (value !== null)
|
|
690
|
-
throw new Error("Invalid annotation response.");
|
|
691
|
-
return null;
|
|
692
|
-
}
|
|
693
|
-
});
|
|
694
|
-
var annotationSendRoute2 = /* @__PURE__ */ defineMessageRoute2({
|
|
695
|
-
input(value) {
|
|
696
|
-
if (value !== null)
|
|
697
|
-
throw new Error("Invalid annotation send request.");
|
|
698
|
-
return null;
|
|
699
|
-
},
|
|
700
|
-
output(value) {
|
|
701
|
-
if (value !== null)
|
|
702
|
-
throw new Error("Invalid annotation response.");
|
|
703
|
-
return null;
|
|
704
|
-
}
|
|
705
|
-
});
|
|
706
|
-
var annotationUpdateRoute2 = /* @__PURE__ */ defineMessageRoute2({
|
|
707
|
-
input(value) {
|
|
708
|
-
const input = object(value);
|
|
709
|
-
return {
|
|
710
|
-
id: text(input.id, 128, true),
|
|
711
|
-
comment: text(input.comment, 2000, true).trim()
|
|
712
|
-
};
|
|
713
|
-
},
|
|
714
|
-
output(value) {
|
|
715
|
-
if (value !== null)
|
|
716
|
-
throw new Error("Invalid annotation response.");
|
|
717
|
-
return null;
|
|
718
|
-
}
|
|
719
|
-
});
|
|
720
|
-
var annotationModeRoute2 = /* @__PURE__ */ defineMessageRoute2({
|
|
721
|
-
input(value) {
|
|
722
|
-
const input = object(value);
|
|
723
|
-
if (typeof input.active !== "boolean")
|
|
724
|
-
throw new Error("Invalid annotation mode.");
|
|
725
|
-
return { active: input.active };
|
|
726
|
-
},
|
|
727
|
-
output(value) {
|
|
728
|
-
if (value !== null)
|
|
729
|
-
throw new Error("Invalid annotation response.");
|
|
730
|
-
return null;
|
|
731
|
-
}
|
|
732
|
-
});
|
|
733
|
-
function isAnnotationPresentation(value) {
|
|
734
|
-
if (!value || typeof value !== "object")
|
|
735
|
-
return false;
|
|
736
|
-
const input = value;
|
|
737
|
-
return typeof input.enabled === "boolean" && (input.active === undefined || typeof input.active === "boolean") && (input.pinsVisible === undefined || typeof input.pinsVisible === "boolean") && (input.showHint === undefined || typeof input.showHint === "boolean") && (input.readOnly === undefined || typeof input.readOnly === "boolean") && (input.selectedAnnotationId === undefined || typeof input.selectedAnnotationId === "string" && input.selectedAnnotationId.length <= 128) && (input.dismissal === undefined || input.dismissal !== null && typeof input.dismissal === "object" && typeof input.dismissal.id === "string" && input.dismissal.id.length <= 128 && typeof input.dismissal.occurredAt === "number" && Number.isFinite(input.dismissal.occurredAt)) && (input.selectionId === undefined || typeof input.selectionId === "string" && input.selectionId.length <= 128) && (input.selectedTargetId === undefined || typeof input.selectedTargetId === "string" && input.selectedTargetId.length <= 128) && (input.targets === undefined || Array.isArray(input.targets) && input.targets.length <= 50 && input.targets.every((target) => target && typeof target.id === "string" && target.id.length <= 128 && typeof target.targetId === "string" && target.targetId.length <= 128 && Number.isSafeInteger(target.number) && target.number > 0 && (target.anchor === undefined || typeof target.anchor.x === "number" && Number.isFinite(target.anchor.x) && target.anchor.x >= 0 && target.anchor.x <= 1 && typeof target.anchor.y === "number" && Number.isFinite(target.anchor.y) && target.anchor.y >= 0 && target.anchor.y <= 1) && (target.region === undefined || typeof target.region === "object" && target.region !== null && ["x", "y", "width", "height"].every((key) => {
|
|
738
|
-
const value = target.region[key];
|
|
739
|
-
return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
|
|
740
|
-
}) && target.region.width > 0 && target.region.height > 0 && target.region.x + target.region.width <= 1.000001 && target.region.y + target.region.height <= 1.000001) && (target.comment === undefined || typeof target.comment === "string" && target.comment.length <= 2000)));
|
|
741
|
-
}
|
|
742
|
-
// packages/data-app/src/core/filters.ts
|
|
743
|
-
var all = { kind: "all" };
|
|
744
|
-
var numberOperatorLabels2 = {
|
|
745
|
-
eq: "Equals",
|
|
746
|
-
ne: "Does not equal",
|
|
747
|
-
gt: "Greater than",
|
|
748
|
-
gte: "At least",
|
|
749
|
-
lt: "Less than",
|
|
750
|
-
lte: "At most"
|
|
751
|
-
};
|
|
752
|
-
function numberFilter2({
|
|
753
|
-
key,
|
|
754
|
-
label,
|
|
755
|
-
min,
|
|
756
|
-
max,
|
|
757
|
-
defaultValue = all,
|
|
758
|
-
history = "push",
|
|
759
|
-
presentation
|
|
760
|
-
}) {
|
|
761
|
-
invariant2(!!key.trim(), "Numeric filter requires a URL key.");
|
|
762
|
-
invariant2((min === undefined || Number.isFinite(min)) && (max === undefined || Number.isFinite(max)) && (min === undefined || max === undefined || min <= max), "Invalid numeric filter bounds.");
|
|
763
|
-
function validNumber(value) {
|
|
764
|
-
return typeof value === "number" && Number.isFinite(value) && (min === undefined || value >= min) && (max === undefined || value <= max);
|
|
765
|
-
}
|
|
766
|
-
function valid(value) {
|
|
767
|
-
if (!value || typeof value !== "object")
|
|
768
|
-
return false;
|
|
769
|
-
if (value.kind === "all")
|
|
770
|
-
return true;
|
|
771
|
-
if (value.kind === "comparison")
|
|
772
|
-
return typeof value.operator === "string" && Object.hasOwn(numberOperatorLabels2, value.operator) && validNumber(value.value);
|
|
773
|
-
return value.kind === "range" && (value.min !== undefined || value.max !== undefined) && (value.min === undefined || validNumber(value.min)) && (value.max === undefined || validNumber(value.max)) && (value.min === undefined || value.max === undefined || value.min <= value.max);
|
|
774
|
-
}
|
|
775
|
-
function encode(value) {
|
|
776
|
-
return value.kind === "all" ? null : value.kind === "range" ? JSON.stringify({ kind: "range", min: value.min, max: value.max }) : JSON.stringify({
|
|
777
|
-
kind: "comparison",
|
|
778
|
-
operator: value.operator,
|
|
779
|
-
value: value.value
|
|
780
|
-
});
|
|
781
|
-
}
|
|
782
|
-
invariant2(valid(defaultValue), `Invalid default for ${label}.`);
|
|
783
|
-
return {
|
|
784
|
-
kind: "numberFilter",
|
|
785
|
-
presentation,
|
|
786
|
-
label,
|
|
787
|
-
min,
|
|
788
|
-
max,
|
|
789
|
-
defaultValue,
|
|
790
|
-
clearValue: all,
|
|
791
|
-
urlKeys: [key],
|
|
792
|
-
history,
|
|
793
|
-
valid,
|
|
794
|
-
same: (left, right) => encode(left) === encode(right),
|
|
795
|
-
describe(value) {
|
|
796
|
-
return value.kind === "all" ? "Any" : value.kind === "comparison" ? `${numberOperatorLabels2[value.operator]} ${value.value}` : value.min === undefined ? `At most ${value.max}` : value.max === undefined ? `At least ${value.min}` : `${value.min}–${value.max}`;
|
|
797
|
-
},
|
|
798
|
-
read(params) {
|
|
799
|
-
const raw = params.get(key);
|
|
800
|
-
if (raw === null)
|
|
801
|
-
return defaultValue;
|
|
802
|
-
if (raw.length > 512)
|
|
803
|
-
return defaultValue;
|
|
804
|
-
try {
|
|
805
|
-
const value = raw === "all" ? all : JSON.parse(raw);
|
|
806
|
-
return valid(value) ? value : defaultValue;
|
|
807
|
-
} catch {
|
|
808
|
-
return defaultValue;
|
|
809
|
-
}
|
|
810
|
-
},
|
|
811
|
-
write(value) {
|
|
812
|
-
return {
|
|
813
|
-
[key]: encode(value) === encode(defaultValue) ? null : value.kind === "all" ? "all" : encode(value)
|
|
814
|
-
};
|
|
815
|
-
}
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
function booleanFilter2({
|
|
819
|
-
key,
|
|
820
|
-
label,
|
|
821
|
-
defaultValue = all,
|
|
822
|
-
history = "push",
|
|
823
|
-
presentation
|
|
824
|
-
}) {
|
|
825
|
-
invariant2(!!key.trim(), "Boolean filter requires a URL key.");
|
|
826
|
-
function valid(value) {
|
|
827
|
-
return !!value && typeof value === "object" && (value.kind === "all" || value.kind === "is" && typeof value.value === "boolean");
|
|
828
|
-
}
|
|
829
|
-
function encode(value) {
|
|
830
|
-
return value.kind === "all" ? "all" : String(value.value);
|
|
831
|
-
}
|
|
832
|
-
invariant2(valid(defaultValue), `Invalid default for ${label}.`);
|
|
833
|
-
return {
|
|
834
|
-
kind: "booleanFilter",
|
|
835
|
-
presentation,
|
|
836
|
-
label,
|
|
837
|
-
defaultValue,
|
|
838
|
-
clearValue: all,
|
|
839
|
-
urlKeys: [key],
|
|
840
|
-
history,
|
|
841
|
-
valid,
|
|
842
|
-
describe: (value) => value.kind === "all" ? "Any" : value.value ? "Yes" : "No",
|
|
843
|
-
same: (left, right) => encode(left) === encode(right),
|
|
844
|
-
read(params) {
|
|
845
|
-
const raw = params.get(key);
|
|
846
|
-
return raw === "all" ? all : raw === "true" || raw === "false" ? { kind: "is", value: raw === "true" } : defaultValue;
|
|
847
|
-
},
|
|
848
|
-
write(value) {
|
|
849
|
-
return {
|
|
850
|
-
[key]: encode(value) === encode(defaultValue) ? null : encode(value)
|
|
851
|
-
};
|
|
852
|
-
}
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
function parseNumberSelection2(value, filter) {
|
|
856
|
-
invariant2(filter.valid(value), `Invalid ${filter.label} selection.`);
|
|
857
|
-
return value;
|
|
858
|
-
}
|
|
859
|
-
function parseBooleanSelection2(value, filter) {
|
|
860
|
-
invariant2(filter.valid(value), `Invalid ${filter.label} selection.`);
|
|
861
|
-
return value;
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
// packages/data-app/src/core/contract.ts
|
|
865
|
-
function parseEmptyInput2(value) {
|
|
866
|
-
invariant2(typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length === 0, "This operation takes no inputs.");
|
|
867
|
-
return {};
|
|
868
|
-
}
|
|
869
|
-
function parseTrue2(value) {
|
|
870
|
-
invariant2(value === true, "Expected a successful check.");
|
|
871
|
-
return true;
|
|
872
|
-
}
|
|
873
|
-
function previousDateRange2({
|
|
874
|
-
start,
|
|
875
|
-
end
|
|
876
|
-
}) {
|
|
877
|
-
const first = parseDate(start);
|
|
878
|
-
const last = parseDate(end);
|
|
879
|
-
const days = (last.toDate("UTC").getTime() - first.toDate("UTC").getTime()) / 86400000 + 1;
|
|
880
|
-
invariant2(days >= 1, "Date range must start before it ends.");
|
|
881
|
-
const previousEnd = first.subtract({ days: 1 });
|
|
882
|
-
return {
|
|
883
|
-
start: previousEnd.subtract({ days: days - 1 }).toString(),
|
|
884
|
-
end: previousEnd.toString()
|
|
885
|
-
};
|
|
886
|
-
}
|
|
887
|
-
function defineDateRangeContract2(options) {
|
|
888
|
-
invariant2(Number.isInteger(options.maxRangeDays) && options.maxRangeDays > 0, "Date range needs a positive maxRangeDays.");
|
|
889
|
-
if (options.minDate)
|
|
890
|
-
parseDate(options.minDate);
|
|
891
|
-
if (typeof options.maxDate === "string")
|
|
892
|
-
parseDate(options.maxDate);
|
|
893
|
-
today(options.timeZone);
|
|
894
|
-
function bounds() {
|
|
895
|
-
const latest = today(options.timeZone).subtract({
|
|
896
|
-
days: options.completeDays === false ? 0 : 1
|
|
897
|
-
});
|
|
898
|
-
const sourceMax = typeof options.maxDate === "function" ? options.maxDate() : options.maxDate;
|
|
899
|
-
const maxDate = sourceMax && parseDate(sourceMax).compare(latest) < 0 ? parseDate(sourceMax).toString() : latest.toString();
|
|
900
|
-
return {
|
|
901
|
-
minDate: options.minDate,
|
|
902
|
-
maxDate,
|
|
903
|
-
maxRangeDays: options.maxRangeDays,
|
|
904
|
-
timeZone: options.timeZone
|
|
905
|
-
};
|
|
906
|
-
}
|
|
907
|
-
function period({ start, end }) {
|
|
908
|
-
return {
|
|
909
|
-
kind: "calendar",
|
|
910
|
-
start,
|
|
911
|
-
end,
|
|
912
|
-
timeZone: options.timeZone
|
|
913
|
-
};
|
|
914
|
-
}
|
|
915
|
-
function describeInput(input) {
|
|
916
|
-
return `${formatDateRange2(input)} ${options.timeZone}`;
|
|
917
|
-
}
|
|
918
|
-
function comparison(input) {
|
|
919
|
-
const previous = previousDateRange2(input);
|
|
920
|
-
return options.minDate && previous.start < options.minDate ? null : previous;
|
|
921
|
-
}
|
|
922
|
-
function request(value, compare = false) {
|
|
923
|
-
const range = parseDateRangeInput2(value, bounds());
|
|
924
|
-
const previous = compare ? comparison(range) : null;
|
|
925
|
-
invariant2(!compare || previous, "Comparison is outside available source coverage.");
|
|
926
|
-
return { range, comparison: previous };
|
|
927
|
-
}
|
|
928
|
-
function parseRequest(value) {
|
|
929
|
-
invariant2(value && typeof value === "object", "Choose a date range.");
|
|
930
|
-
const input = value;
|
|
931
|
-
const parsed = request(input.range, input.comparison != null);
|
|
932
|
-
if (input.comparison != null) {
|
|
933
|
-
const supplied = parseDateRangeInput2(input.comparison, bounds());
|
|
934
|
-
invariant2(supplied.start === parsed.comparison?.start && supplied.end === parsed.comparison?.end, "Comparison must be the preceding equal-length range.");
|
|
935
|
-
}
|
|
936
|
-
return parsed;
|
|
937
|
-
}
|
|
938
|
-
return {
|
|
939
|
-
request,
|
|
940
|
-
parseRequest,
|
|
941
|
-
bounds,
|
|
942
|
-
parse(value) {
|
|
943
|
-
return parseDateRangeInput2(value, bounds());
|
|
944
|
-
},
|
|
945
|
-
period,
|
|
946
|
-
comparison,
|
|
947
|
-
describeInput,
|
|
948
|
-
view: { period, describeInput }
|
|
949
|
-
};
|
|
950
|
-
}
|
|
951
|
-
function parseDateRangeInput2(value, {
|
|
952
|
-
minDate,
|
|
953
|
-
maxDate,
|
|
954
|
-
maxRangeDays
|
|
955
|
-
}) {
|
|
956
|
-
invariant2(value && typeof value === "object" && !Array.isArray(value), "Choose a date range.");
|
|
957
|
-
const { start, end } = value;
|
|
958
|
-
function day(input) {
|
|
959
|
-
invariant2(typeof input === "string" && /^\d{4}-\d{2}-\d{2}$/.test(input), "Dates must be YYYY-MM-DD.");
|
|
960
|
-
const timestamp = Date.parse(`${input}T00:00:00Z`);
|
|
961
|
-
invariant2(Number.isFinite(timestamp) && new Date(timestamp).toISOString().slice(0, 10) === input, "Choose valid calendar dates.");
|
|
962
|
-
return timestamp;
|
|
963
|
-
}
|
|
964
|
-
const first = day(start);
|
|
965
|
-
const last = day(end);
|
|
966
|
-
invariant2(Number.isInteger(maxRangeDays) && maxRangeDays > 0, "Maximum range days must be positive.");
|
|
967
|
-
invariant2(first <= last && (last - first) / 86400000 < maxRangeDays && (minDate === undefined || first >= day(minDate)) && (maxDate === undefined || last <= day(maxDate)), `Choose up to ${maxRangeDays} days within the available range.`);
|
|
968
|
-
return { start, end };
|
|
969
|
-
}
|
|
970
|
-
function parseCount2(value) {
|
|
971
|
-
const number = typeof value === "number" || typeof value === "string" ? Number(value) : NaN;
|
|
972
|
-
invariant2(Number.isSafeInteger(number) && number >= 0 && (typeof value !== "string" || !!value.trim()), "Invalid count in query result.");
|
|
973
|
-
return number;
|
|
974
|
-
}
|
|
975
|
-
function parseLabel2(value, maxLength = 100) {
|
|
976
|
-
invariant2(typeof value === "string" && !!value && value.length <= maxLength, "Invalid label in query result.");
|
|
977
|
-
return value;
|
|
978
|
-
}
|
|
979
|
-
function defineQueryNames2(names) {
|
|
980
|
-
const values = Object.values(names);
|
|
981
|
-
invariant2(values.every((name) => !!name.trim()) && new Set(values).size === values.length, "Query names must be nonempty and unique.");
|
|
982
|
-
return names;
|
|
983
|
-
}
|
|
984
|
-
var sourceErrorBrand = Symbol.for("@altertable/data-app/DataSourceError");
|
|
985
|
-
|
|
986
|
-
class DataSourceError2 extends Error {
|
|
987
|
-
reason;
|
|
988
|
-
status;
|
|
989
|
-
[sourceErrorBrand] = true;
|
|
990
|
-
queryName;
|
|
991
|
-
static [Symbol.hasInstance](value) {
|
|
992
|
-
return value instanceof Error && value[sourceErrorBrand] === true;
|
|
993
|
-
}
|
|
994
|
-
constructor(reason, status, options) {
|
|
995
|
-
super(`Data source ${reason}${status ? ` (${status})` : ""}.`, options);
|
|
996
|
-
this.reason = reason;
|
|
997
|
-
this.status = status;
|
|
998
|
-
this.name = "DataSourceError";
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
function defineOperation2(operation) {
|
|
1002
|
-
invariant2(Array.isArray(operation.checks) && operation.checks.length > 0 && Number.isInteger(operation.policy.maxQueryRows) && operation.policy.maxQueryRows > 0 && Number.isInteger(operation.policy.maxDurationMs) && operation.policy.maxDurationMs > 0 && (operation.policy.maxResponseBytes === undefined || Number.isInteger(operation.policy.maxResponseBytes) && operation.policy.maxResponseBytes > 0), "Each data operation needs check inputs and positive row and duration limits.");
|
|
1003
|
-
const queries = snapshotQueries(operation.queries);
|
|
1004
|
-
const queryNames = Object.fromEntries(Object.keys(queries).map((name) => [name, name]));
|
|
1005
|
-
for (const input of operation.checks)
|
|
1006
|
-
operation.input(input);
|
|
1007
|
-
const defined = {
|
|
1008
|
-
...operation,
|
|
1009
|
-
queryNames,
|
|
1010
|
-
async run(context, input) {
|
|
1011
|
-
async function query(name, values = {}, options) {
|
|
1012
|
-
invariant2(Object.hasOwn(queries, name), `Unknown query name: ${name}.`);
|
|
1013
|
-
const definition = queries[name];
|
|
1014
|
-
const params = resolveQueryParameters(definition.params, values, context.queryParams ?? {});
|
|
1015
|
-
const result = await context.lakehouse.queryAll(definition.statement, {
|
|
1016
|
-
name,
|
|
1017
|
-
params,
|
|
1018
|
-
limit: options?.limit ?? operation.policy.maxQueryRows,
|
|
1019
|
-
signal: context.signal
|
|
1020
|
-
});
|
|
1021
|
-
return decodeQueryResult(result, definition.projections);
|
|
1022
|
-
}
|
|
1023
|
-
await validateVariableInput(operation.input, input, query);
|
|
1024
|
-
context.signal.throwIfAborted();
|
|
1025
|
-
return operation.run({ signal: context.signal, query }, input);
|
|
1026
|
-
}
|
|
1027
|
-
};
|
|
1028
|
-
attachDimensionSelectors(defined, queries);
|
|
1029
|
-
return defined;
|
|
1030
|
-
}
|
|
1031
|
-
function connectionCheck2(queries) {
|
|
1032
|
-
const connection = queries.connection;
|
|
1033
|
-
return defineOperation2({
|
|
1034
|
-
queries: { connection },
|
|
1035
|
-
input: parseEmptyInput2,
|
|
1036
|
-
checks: [{}],
|
|
1037
|
-
policy: { maxQueryRows: 1, maxDurationMs: 15000 },
|
|
1038
|
-
async run({ query }) {
|
|
1039
|
-
await query("connection");
|
|
1040
|
-
return true;
|
|
1041
|
-
}
|
|
1042
|
-
});
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
export { KEY_SEPARATOR2, invariant2, dimensionMemberKey2, dimensionFilter2, createDimensionFilter2, parseDimensionSelection2, parseFacetOptions2, dimensionPredicate2, snapshotQueries, dimensionSource2, DimensionMembershipError, variableInput2, bindDimensionSource, withDimensionSelectors, validLocation, MessageRoutingError2, defineMessageRoute2, createMessageRouter2, defineDataQueryRoute2, navigationUpdateRoute2, sqlQueryRoute2, dataAppRoutes2, parseDataAppAnnotationDraft2, annotationDraftRoute2, annotationEditorStateRoute2, annotationSendRoute2, annotationUpdateRoute2, annotationModeRoute2, isAnnotationPresentation, numberOperatorLabels2, numberFilter2, booleanFilter2, parseNumberSelection2, parseBooleanSelection2, parseEmptyInput2, parseTrue2, previousDateRange2, defineDateRangeContract2, parseDateRangeInput2, parseCount2, parseLabel2, defineQueryNames2, DataSourceError2, defineOperation2, connectionCheck2 };
|
|
1046
|
-
|
|
1047
|
-
//# debugId=0B494A6494D6A59764756E2164756E21
|