@altertable/data-app 0.71.0 → 0.73.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.
Files changed (130) hide show
  1. package/AGENTS.md +5 -61
  2. package/CONTRIBUTING.md +93 -173
  3. package/README.md +3 -3
  4. package/REFERENCE.md +30 -341
  5. package/dist/chunks/contract-BeLPJwlO.js +558 -0
  6. package/dist/chunks/contract-BeLPJwlO.js.map +1 -0
  7. package/dist/chunks/contract-Di8SP74I.js +462 -0
  8. package/dist/chunks/contract-Di8SP74I.js.map +1 -0
  9. package/dist/chunks/format-BdFlv_xa.js +148 -0
  10. package/dist/chunks/format-BdFlv_xa.js.map +1 -0
  11. package/dist/chunks/iframe-C3uCZEXh.js +809 -0
  12. package/dist/chunks/iframe-C3uCZEXh.js.map +1 -0
  13. package/dist/chunks/operation-CBxhjNhK.js +131 -0
  14. package/dist/chunks/operation-CBxhjNhK.js.map +1 -0
  15. package/dist/chunks/request-body-H1qPmmTN.js +50 -0
  16. package/dist/chunks/request-body-H1qPmmTN.js.map +1 -0
  17. package/dist/client/index.js +253 -285
  18. package/dist/client/index.js.map +1 -13
  19. package/dist/core/appearance.js +171 -162
  20. package/dist/core/appearance.js.map +1 -10
  21. package/dist/core/config.js +49 -11
  22. package/dist/core/config.js.map +1 -9
  23. package/dist/core/contract.js +3 -73
  24. package/dist/core/format.js +1 -26
  25. package/dist/index.js +1 -12
  26. package/dist/internal.js +352 -397
  27. package/dist/internal.js.map +1 -15
  28. package/dist/server/index.js +85 -97
  29. package/dist/server/index.js.map +1 -10
  30. package/dist/types/chunks/appearance.d.ts +45 -0
  31. package/dist/types/chunks/contract.d.ts +720 -0
  32. package/dist/types/chunks/index.d.ts +189 -0
  33. package/dist/types/client/index.d.ts +3 -13
  34. package/dist/types/core/appearance.d.ts +2 -42
  35. package/dist/types/core/config.d.ts +44 -48
  36. package/dist/types/core/contract.d.ts +2 -114
  37. package/dist/types/core/format.d.ts +44 -17
  38. package/dist/types/index.d.ts +3 -3
  39. package/dist/types/internal.d.ts +312 -22
  40. package/dist/types/server/index.d.ts +15 -4
  41. package/docs/app-authoring.md +72 -112
  42. package/docs/client.md +29 -63
  43. package/docs/composition.md +44 -75
  44. package/docs/contract.md +60 -100
  45. package/docs/data-context.md +35 -61
  46. package/docs/embed.md +83 -55
  47. package/docs/formatting-and-appearance.md +17 -38
  48. package/docs/hosted-apps.md +12 -15
  49. package/docs/layout.md +30 -47
  50. package/docs/local-data-apps.md +7 -7
  51. package/docs/react-embed.md +20 -26
  52. package/docs/react.md +10 -27
  53. package/docs/server-bun.md +3 -28
  54. package/docs/server.md +6 -12
  55. package/docs/stories-and-export.md +38 -40
  56. package/docs/styling.md +14 -22
  57. package/docs/ui-quality.md +5 -5
  58. package/docs/ui.md +68 -70
  59. package/docs/variables.md +142 -254
  60. package/docs/views.md +85 -116
  61. package/docs/widgets.md +100 -153
  62. package/docs/worker.md +15 -27
  63. package/package.json +3 -3
  64. package/dist/chunks/index-5a27erdg.js +0 -54
  65. package/dist/chunks/index-5a27erdg.js.map +0 -10
  66. package/dist/chunks/index-9yxr7nmm.js +0 -742
  67. package/dist/chunks/index-9yxr7nmm.js.map +0 -17
  68. package/dist/chunks/index-j5q5n3ra.js +0 -151
  69. package/dist/chunks/index-j5q5n3ra.js.map +0 -10
  70. package/dist/chunks/index-q75zm3a7.js +0 -153
  71. package/dist/chunks/index-q75zm3a7.js.map +0 -11
  72. package/dist/chunks/index-vhaec7m5.js +0 -30
  73. package/dist/chunks/index-vhaec7m5.js.map +0 -10
  74. package/dist/chunks/index-zp78caex.js +0 -1047
  75. package/dist/chunks/index-zp78caex.js.map +0 -19
  76. package/dist/core/contract.js.map +0 -9
  77. package/dist/core/format.js.map +0 -9
  78. package/dist/index.js.map +0 -9
  79. package/dist/types/client/annotations.d.ts +0 -27
  80. package/dist/types/client/data-client.d.ts +0 -43
  81. package/dist/types/client/download.d.ts +0 -5
  82. package/dist/types/client/iframe.d.ts +0 -59
  83. package/dist/types/client/location.d.ts +0 -13
  84. package/dist/types/client/logger.d.ts +0 -14
  85. package/dist/types/client/messages.d.ts +0 -7
  86. package/dist/types/client/navigation.d.ts +0 -15
  87. package/dist/types/client/transport.d.ts +0 -15
  88. package/dist/types/core/annotations.d.ts +0 -99
  89. package/dist/types/core/bridge-endpoint.d.ts +0 -21
  90. package/dist/types/core/bridge.d.ts +0 -172
  91. package/dist/types/core/data-view.d.ts +0 -46
  92. package/dist/types/core/date-format.d.ts +0 -24
  93. package/dist/types/core/date-range.d.ts +0 -20
  94. package/dist/types/core/dimension-source.d.ts +0 -64
  95. package/dist/types/core/dimension.d.ts +0 -71
  96. package/dist/types/core/facets.d.ts +0 -13
  97. package/dist/types/core/filters.d.ts +0 -45
  98. package/dist/types/core/invariant.d.ts +0 -2
  99. package/dist/types/core/keys.d.ts +0 -2
  100. package/dist/types/core/logger.d.ts +0 -12
  101. package/dist/types/core/messages.d.ts +0 -62
  102. package/dist/types/core/navigation.d.ts +0 -11
  103. package/dist/types/core/operation-types.d.ts +0 -80
  104. package/dist/types/core/operation.d.ts +0 -20
  105. package/dist/types/core/presentation.d.ts +0 -9
  106. package/dist/types/core/queries.d.ts +0 -84
  107. package/dist/types/core/reading.d.ts +0 -17
  108. package/dist/types/core/uuid.d.ts +0 -2
  109. package/dist/types/core/variables.d.ts +0 -133
  110. package/dist/types/server/handler.d.ts +0 -13
  111. package/dist/types/server/request-body.d.ts +0 -4
  112. package/examples/starter-data-app/index.tsx +0 -193
  113. package/examples/starter-local-data-app/.bun-version +0 -1
  114. package/examples/starter-local-data-app/.node-version +0 -1
  115. package/examples/starter-local-data-app/.oxfmtrc.json +0 -4
  116. package/examples/starter-local-data-app/.oxlintrc.json +0 -33
  117. package/examples/starter-local-data-app/AGENTS.md +0 -22
  118. package/examples/starter-local-data-app/README.md +0 -56
  119. package/examples/starter-local-data-app/app.ts +0 -28
  120. package/examples/starter-local-data-app/bunfig.toml +0 -2
  121. package/examples/starter-local-data-app/package.json +0 -35
  122. package/examples/starter-local-data-app/src/App.tsx +0 -8
  123. package/examples/starter-local-data-app/src/assets.d.ts +0 -1
  124. package/examples/starter-local-data-app/src/data-context.ts +0 -21
  125. package/examples/starter-local-data-app/src/favicon.svg +0 -13
  126. package/examples/starter-local-data-app/src/index.html +0 -14
  127. package/examples/starter-local-data-app/src/main.tsx +0 -7
  128. package/examples/starter-local-data-app/src/operations.ts +0 -6
  129. package/examples/starter-local-data-app/src/server.ts +0 -6
  130. package/examples/starter-local-data-app/tsconfig.json +0 -21
package/dist/internal.js CHANGED
@@ -1,418 +1,373 @@
1
- import"./chunks/index-q75zm3a7.js";
2
- import {
3
- KEY_SEPARATOR2,
4
- invariant2,
5
- dimensionMemberKey2,
6
- createDimensionFilter2,
7
- dimensionSource2,
8
- isAnnotationPresentation,
9
- numberOperatorLabels2
10
- } from "./chunks/index-zp78caex.js";
11
- import {
12
- randomUuid2,
13
- PARENT_PARAM2,
14
- MAX_PENDING2,
15
- REQUEST_TIMEOUT_MS2,
16
- validId2,
17
- createBridgeEndpoint2,
18
- localFrameBridge2
19
- } from "./chunks/index-9yxr7nmm.js";
20
- import {
21
- RequestBodyTooLargeError2,
22
- readRequestBody2
23
- } from "./chunks/index-5a27erdg.js";
24
- import {
25
- toDataOperationFailure2
26
- } from "./chunks/index-j5q5n3ra.js";
27
-
28
- // packages/data-app/src/client/download.ts
29
- function downloadBlob({
30
- filename,
31
- blob
32
- }) {
33
- const url = URL.createObjectURL(blob);
34
- const link = document.createElement("a");
35
- link.href = url;
36
- link.download = filename;
37
- document.body.append(link);
38
- try {
39
- link.click();
40
- } finally {
41
- link.remove();
42
- setTimeout(() => URL.revokeObjectURL(url), 1000);
43
- }
1
+ import { T as invariant, b as dimensionMemberKey, p as dimensionSource, v as createDimensionFilter, w as KEY_SEPARATOR } from "./chunks/contract-BeLPJwlO.js";
2
+ import { y as numberOperatorLabels } from "./chunks/contract-Di8SP74I.js";
3
+ import { n as toDataOperationFailure } from "./chunks/operation-CBxhjNhK.js";
4
+ import { c as isDataAppPresentation, d as PARENT_PARAM, f as REQUEST_TIMEOUT_MS, i as localFrameBridge, l as createBridgeEndpoint, m as randomUuid, p as validId, u as MAX_PENDING } from "./chunks/iframe-C3uCZEXh.js";
5
+ import { n as readRequestBody, t as RequestBodyTooLargeError } from "./chunks/request-body-H1qPmmTN.js";
6
+ import { parseDate, today } from "@internationalized/date";
7
+ //#region src/client/download.ts
8
+ /** Start a browser download and release its temporary anchor and object URL. */
9
+ function downloadBlob({ filename, blob }) {
10
+ const url = URL.createObjectURL(blob);
11
+ const link = document.createElement("a");
12
+ link.href = url;
13
+ link.download = filename;
14
+ document.body.append(link);
15
+ try {
16
+ link.click();
17
+ } finally {
18
+ link.remove();
19
+ setTimeout(() => URL.revokeObjectURL(url), 1e3);
20
+ }
44
21
  }
45
- // packages/data-app/src/core/data-view.ts
22
+ //#endregion
23
+ //#region src/core/data-view.ts
24
+ /** The result currently shown to the reader, including the input that produced it. */
46
25
  function displayedSnapshot(view) {
47
- if (view.kind === "ready")
48
- return { data: view.data, input: view.input, state: view.kind };
49
- if (view.kind === "updating" || view.kind === "stale-error")
50
- return { data: view.data, input: view.displayedInput, state: view.kind };
51
- return;
26
+ if (view.kind === "ready") return {
27
+ data: view.data,
28
+ input: view.input,
29
+ state: view.kind
30
+ };
31
+ if (view.kind === "updating" || view.kind === "stale-error") return {
32
+ data: view.data,
33
+ input: view.displayedInput,
34
+ state: view.kind
35
+ };
52
36
  }
53
- function resolveDataView({
54
- requestedInput,
55
- current,
56
- previous,
57
- pending,
58
- error,
59
- sameInput,
60
- describe,
61
- isEmpty
62
- }) {
63
- const shown = current ?? previous;
64
- if (!shown)
65
- return error ? { kind: "error", error } : { kind: "loading" };
66
- const currentInput = sameInput(shown.input, requestedInput);
67
- if (error)
68
- return {
69
- kind: "stale-error",
70
- data: shown.data,
71
- displayedInput: shown.input,
72
- requestedInput,
73
- error,
74
- message: currentInput ? `Couldn’t refresh. Showing the last result for ${describe(shown.input)}.` : `Couldn’t refresh. Showing ${describe(shown.input)} while ${describe(requestedInput)} is unavailable.`
75
- };
76
- if (pending || !currentInput)
77
- return {
78
- kind: "updating",
79
- data: shown.data,
80
- displayedInput: shown.input,
81
- requestedInput,
82
- message: currentInput ? `Updating ${describe(requestedInput)}…` : `Showing ${describe(shown.input)} while loading ${describe(requestedInput)}…`
83
- };
84
- return isEmpty(shown.data) ? { kind: "empty", input: shown.input } : { kind: "ready", data: shown.data, input: shown.input };
37
+ /** Keep the requested input separate from the input that produced visible data. */
38
+ function resolveDataView({ requestedInput, current, previous, pending, error, sameInput, describe, isEmpty }) {
39
+ const shown = current ?? previous;
40
+ if (!shown) return error ? {
41
+ kind: "error",
42
+ error
43
+ } : { kind: "loading" };
44
+ const currentInput = sameInput(shown.input, requestedInput);
45
+ if (error) return {
46
+ kind: "stale-error",
47
+ data: shown.data,
48
+ displayedInput: shown.input,
49
+ requestedInput,
50
+ error,
51
+ message: currentInput ? `Couldn’t refresh. Showing the last result for ${describe(shown.input)}.` : `Couldn’t refresh. Showing ${describe(shown.input)} while ${describe(requestedInput)} is unavailable.`
52
+ };
53
+ if (pending || !currentInput) return {
54
+ kind: "updating",
55
+ data: shown.data,
56
+ displayedInput: shown.input,
57
+ requestedInput,
58
+ message: currentInput ? `Updating ${describe(requestedInput)}…` : `Showing ${describe(shown.input)} while loading ${describe(requestedInput)}…`
59
+ };
60
+ return isEmpty(shown.data) ? {
61
+ kind: "empty",
62
+ input: shown.input
63
+ } : {
64
+ kind: "ready",
65
+ data: shown.data,
66
+ input: shown.input
67
+ };
85
68
  }
86
- // packages/data-app/src/core/date-range.ts
87
- import { parseDate, today } from "@internationalized/date";
69
+ //#endregion
70
+ //#region src/core/date-range.ts
88
71
  function inclusiveDays(range) {
89
- return (parseDate(range.end).toDate("UTC").getTime() - parseDate(range.start).toDate("UTC").getTime()) / 86400000 + 1;
72
+ return (parseDate(range.end).toDate("UTC").getTime() - parseDate(range.start).toDate("UTC").getTime()) / 864e5 + 1;
90
73
  }
91
74
  function monday(date) {
92
- return date.subtract({ days: (date.toDate("UTC").getUTCDay() + 6) % 7 });
75
+ return date.subtract({ days: (date.toDate("UTC").getUTCDay() + 6) % 7 });
93
76
  }
94
77
  function withinBounds(range, minDate, maxDate, maxRangeDays) {
95
- try {
96
- const start = parseDate(range.start);
97
- const end = parseDate(range.end);
98
- const days = inclusiveDays(range);
99
- return days >= 1 && (!maxRangeDays || days <= maxRangeDays) && (!minDate || start.compare(parseDate(minDate)) >= 0) && (!maxDate || end.compare(parseDate(maxDate)) <= 0);
100
- } catch {
101
- return false;
102
- }
103
- }
104
- function availableDatePresets({
105
- minDate,
106
- maxDate,
107
- maxRangeDays,
108
- timeZone = "UTC"
109
- }) {
110
- const currentDay = today(timeZone);
111
- const latest = maxDate && parseDate(maxDate).compare(currentDay) < 0 ? parseDate(maxDate) : currentDay;
112
- const earliest = minDate ? parseDate(minDate) : null;
113
- const completeDays = latest.compare(currentDay.subtract({ days: 1 })) === 0;
114
- const historical = latest.compare(currentDay.subtract({ days: 1 })) < 0;
115
- const options = [];
116
- const seen = new Set;
117
- function add(id, label, start, end = latest) {
118
- const days = (end.toDate("UTC").getTime() - start.toDate("UTC").getTime()) / 86400000 + 1;
119
- const range = { start: start.toString(), end: end.toString() };
120
- const key = [range.start, range.end].join(KEY_SEPARATOR2);
121
- if (days < 1 || maxRangeDays && days > maxRangeDays || earliest && start.compare(earliest) < 0 || end.compare(latest) > 0 || seen.has(key))
122
- return;
123
- seen.add(key);
124
- options.push({ id, label, range });
125
- }
126
- add("day", historical ? "Latest available day" : completeDays ? "Yesterday" : "Today", latest);
127
- for (const days of [3, 7, 14, 30, 90]) {
128
- add(`last-${days}`, historical ? `Latest ${days} available days` : completeDays ? `Last ${days} complete days` : `Last ${days} days`, latest.subtract({ days: days - 1 }));
129
- }
130
- const weekStart = monday(currentDay);
131
- if (latest.compare(weekStart) >= 0)
132
- add("this-week", completeDays ? "This week through yesterday" : "This week", weekStart);
133
- add("previous-week", "Previous week", weekStart.subtract({ days: 7 }), weekStart.subtract({ days: 1 }));
134
- const monthStart = currentDay.set({ day: 1 });
135
- if (latest.compare(monthStart) >= 0)
136
- add("this-month", completeDays ? "This month through yesterday" : "This month", monthStart);
137
- const previousMonthEnd = monthStart.subtract({ days: 1 });
138
- add("previous-month", "Previous month", previousMonthEnd.set({ day: 1 }), previousMonthEnd);
139
- return options;
78
+ try {
79
+ const start = parseDate(range.start);
80
+ const end = parseDate(range.end);
81
+ const days = inclusiveDays(range);
82
+ return days >= 1 && (!maxRangeDays || days <= maxRangeDays) && (!minDate || start.compare(parseDate(minDate)) >= 0) && (!maxDate || end.compare(parseDate(maxDate)) <= 0);
83
+ } catch {
84
+ return false;
85
+ }
140
86
  }
141
- // packages/data-app/src/core/presentation.ts
142
- function isDataAppPresentation(value) {
143
- if (!value || typeof value !== "object")
144
- return false;
145
- const presentation = value;
146
- return (presentation.surface === "embedded" || presentation.surface === "standalone") && (presentation.theme === "light" || presentation.theme === "dark") && (presentation.annotations === undefined || isAnnotationPresentation(presentation.annotations));
87
+ /** Only offer ranges the app says it can query. Dates and range lengths are inclusive. */
88
+ function availableDatePresets({ minDate, maxDate, maxRangeDays, timeZone = "UTC" }) {
89
+ const currentDay = today(timeZone);
90
+ const latest = maxDate && parseDate(maxDate).compare(currentDay) < 0 ? parseDate(maxDate) : currentDay;
91
+ const earliest = minDate ? parseDate(minDate) : null;
92
+ const completeDays = latest.compare(currentDay.subtract({ days: 1 })) === 0;
93
+ const historical = latest.compare(currentDay.subtract({ days: 1 })) < 0;
94
+ const options = [];
95
+ const seen = /* @__PURE__ */ new Set();
96
+ function add(id, label, start, end = latest) {
97
+ const days = (end.toDate("UTC").getTime() - start.toDate("UTC").getTime()) / 864e5 + 1;
98
+ const range = {
99
+ start: start.toString(),
100
+ end: end.toString()
101
+ };
102
+ const key = [range.start, range.end].join(":");
103
+ if (days < 1 || maxRangeDays && days > maxRangeDays || earliest && start.compare(earliest) < 0 || end.compare(latest) > 0 || seen.has(key)) return;
104
+ seen.add(key);
105
+ options.push({
106
+ id,
107
+ label,
108
+ range
109
+ });
110
+ }
111
+ add("day", historical ? "Latest available day" : completeDays ? "Yesterday" : "Today", latest);
112
+ for (const days of [
113
+ 3,
114
+ 7,
115
+ 14,
116
+ 30,
117
+ 90
118
+ ]) add(`last-${days}`, historical ? `Latest ${days} available days` : completeDays ? `Last ${days} complete days` : `Last ${days} days`, latest.subtract({ days: days - 1 }));
119
+ const weekStart = monday(currentDay);
120
+ if (latest.compare(weekStart) >= 0) add("this-week", completeDays ? "This week through yesterday" : "This week", weekStart);
121
+ add("previous-week", "Previous week", weekStart.subtract({ days: 7 }), weekStart.subtract({ days: 1 }));
122
+ const monthStart = currentDay.set({ day: 1 });
123
+ if (latest.compare(monthStart) >= 0) add("this-month", completeDays ? "This month through yesterday" : "This month", monthStart);
124
+ const previousMonthEnd = monthStart.subtract({ days: 1 });
125
+ add("previous-month", "Previous month", previousMonthEnd.set({ day: 1 }), previousMonthEnd);
126
+ return options;
147
127
  }
148
- // packages/data-app/src/core/variables.ts
128
+ //#endregion
129
+ //#region src/core/variables.ts
130
+ /** Name variables once in the app. URL keys must be unique across its controls. */
149
131
  function defineAppVariables(variables) {
150
- const owners = new Map;
151
- for (const [name, variable] of Object.entries(variables)) {
152
- const presentation = variable.presentation;
153
- invariant2(presentation === undefined || presentation !== null && typeof presentation === "object" && !Array.isArray(presentation) && (presentation.control === undefined || presentation.control === "toolbar" || presentation.control === "widget") && (presentation.group === undefined || presentation.group === "scope" || presentation.group === "display") && (presentation.prominence === undefined || presentation.prominence === "primary" || presentation.prominence === "secondary"), `Variable ${name} has invalid presentation.`);
154
- for (const key of variable.urlKeys) {
155
- invariant2(!["view", "about", "tab", "present", "step", "details"].includes(key), `Variable ${name} uses reserved URL key: ${key}.`);
156
- invariant2(!!key && !owners.has(key), `Variable ${name} has an empty or duplicate URL key: ${key}.`);
157
- owners.set(key, name);
158
- }
159
- }
160
- return variables;
132
+ const owners = /* @__PURE__ */ new Map();
133
+ for (const [name, variable] of Object.entries(variables)) {
134
+ const presentation = variable.presentation;
135
+ invariant(presentation === void 0 || presentation !== null && typeof presentation === "object" && !Array.isArray(presentation) && (presentation.control === void 0 || presentation.control === "toolbar" || presentation.control === "widget") && (presentation.group === void 0 || presentation.group === "scope" || presentation.group === "display") && (presentation.prominence === void 0 || presentation.prominence === "primary" || presentation.prominence === "secondary"), `Variable ${name} has invalid presentation.`);
136
+ for (const key of variable.urlKeys) {
137
+ invariant(![
138
+ "view",
139
+ "about",
140
+ "tab",
141
+ "present",
142
+ "step",
143
+ "details"
144
+ ].includes(key), `Variable ${name} uses reserved URL key: ${key}.`);
145
+ invariant(!!key && !owners.has(key), `Variable ${name} has an empty or duplicate URL key: ${key}.`);
146
+ owners.set(key, name);
147
+ }
148
+ }
149
+ return variables;
161
150
  }
162
- function searchVariable({
163
- key,
164
- label,
165
- defaultValue = "",
166
- history = "replace"
167
- }) {
168
- return {
169
- kind: "search",
170
- label: label ?? key,
171
- urlKeys: [key],
172
- defaultValue,
173
- clearValue: "",
174
- describe: (value) => value,
175
- history,
176
- read(params) {
177
- return params.get(key) ?? defaultValue;
178
- },
179
- write(value) {
180
- return { [key]: value === defaultValue ? null : value };
181
- },
182
- valid(value) {
183
- return typeof value === "string";
184
- },
185
- same(left, right) {
186
- return left === right;
187
- }
188
- };
151
+ /** Search query state; typing replaces history by default. */
152
+ function searchVariable({ key, label, defaultValue = "", history = "replace" }) {
153
+ return {
154
+ kind: "search",
155
+ label: label ?? key,
156
+ urlKeys: [key],
157
+ defaultValue,
158
+ clearValue: "",
159
+ describe: (value) => value,
160
+ history,
161
+ read(params) {
162
+ return params.get(key) ?? defaultValue;
163
+ },
164
+ write(value) {
165
+ return { [key]: value === defaultValue ? null : value };
166
+ },
167
+ valid(value) {
168
+ return typeof value === "string";
169
+ },
170
+ same(left, right) {
171
+ return left === right;
172
+ }
173
+ };
189
174
  }
175
+ /** Validate labeled choices before controls or URL state consume them. */
190
176
  function validateChoiceOptions(options) {
191
- invariant2(options.length > 0 && options.every((option) => !!option.id.trim() && !!option.label.trim()) && new Set(options.map((option) => option.id)).size === options.length, "Choices require nonempty, unique IDs and labels.");
177
+ invariant(options.length > 0 && options.every((option) => !!option.id.trim() && !!option.label.trim()) && new Set(options.map((option) => option.id)).size === options.length, "Choices require nonempty, unique IDs and labels.");
192
178
  }
193
- function choiceVariable({
194
- key,
195
- label,
196
- defaultValue,
197
- options,
198
- history = "push",
199
- presentation
200
- }) {
201
- validateChoiceOptions(options);
202
- function valid(value) {
203
- return typeof value === "string" && options.some((option) => option.id === value);
204
- }
205
- invariant2(valid(defaultValue), `Choice variable ${key} must include its default value.`);
206
- return {
207
- kind: "choice",
208
- presentation,
209
- label: label ?? key,
210
- options,
211
- urlKeys: [key],
212
- defaultValue,
213
- history,
214
- describe: (value) => options.find((option) => option.id === value).label,
215
- read(params) {
216
- const value = params.get(key);
217
- return value !== null && valid(value) ? value : defaultValue;
218
- },
219
- write(value) {
220
- return { [key]: value === defaultValue ? null : value };
221
- },
222
- valid,
223
- same: (left, right) => left === right
224
- };
179
+ function choiceVariable({ key, label, defaultValue, options, history = "push", presentation }) {
180
+ validateChoiceOptions(options);
181
+ function valid(value) {
182
+ return typeof value === "string" && options.some((option) => option.id === value);
183
+ }
184
+ invariant(valid(defaultValue), `Choice variable ${key} must include its default value.`);
185
+ return {
186
+ kind: "choice",
187
+ presentation,
188
+ label: label ?? key,
189
+ options,
190
+ urlKeys: [key],
191
+ defaultValue,
192
+ history,
193
+ describe: (value) => options.find((option) => option.id === value).label,
194
+ read(params) {
195
+ const value = params.get(key);
196
+ return value !== null && valid(value) ? value : defaultValue;
197
+ },
198
+ write(value) {
199
+ return { [key]: value === defaultValue ? null : value };
200
+ },
201
+ valid,
202
+ same: (left, right) => left === right
203
+ };
225
204
  }
226
- function multiChoiceVariable({
227
- key,
228
- label,
229
- defaultValue = [],
230
- options,
231
- maxSelected = options.length,
232
- history = "push",
233
- presentation
234
- }) {
235
- validateChoiceOptions(options);
236
- invariant2(Number.isSafeInteger(maxSelected) && maxSelected >= 1 && maxSelected <= options.length, "Invalid choice selection limit.");
237
- function valid(value) {
238
- return Array.isArray(value) && value.length <= maxSelected && new Set(value).size === value.length && value.every((id) => options.some((option) => option.id === id));
239
- }
240
- function same(left, right) {
241
- return left.length === right.length && left.every((id) => right.includes(id));
242
- }
243
- invariant2(valid(defaultValue), `Invalid default choices for ${key}.`);
244
- return {
245
- kind: "multiChoice",
246
- presentation,
247
- label: label ?? key,
248
- options,
249
- maxSelected,
250
- urlKeys: [key],
251
- defaultValue,
252
- history,
253
- describe: (values) => values.map((id) => options.find((option) => option.id === id).label).join(", ") || "None",
254
- read(params) {
255
- const raw = params.get(key);
256
- if (raw === null || raw.length > 4096)
257
- return defaultValue;
258
- try {
259
- const values = JSON.parse(raw);
260
- return valid(values) ? values : defaultValue;
261
- } catch {
262
- return defaultValue;
263
- }
264
- },
265
- write(value) {
266
- return {
267
- [key]: same(value, defaultValue) ? null : JSON.stringify(options.filter((option) => value.includes(option.id)).map((option) => option.id))
268
- };
269
- },
270
- valid,
271
- same
272
- };
205
+ function multiChoiceVariable({ key, label, defaultValue = [], options, maxSelected = options.length, history = "push", presentation }) {
206
+ validateChoiceOptions(options);
207
+ invariant(Number.isSafeInteger(maxSelected) && maxSelected >= 1 && maxSelected <= options.length, "Invalid choice selection limit.");
208
+ function valid(value) {
209
+ return Array.isArray(value) && value.length <= maxSelected && new Set(value).size === value.length && value.every((id) => options.some((option) => option.id === id));
210
+ }
211
+ function same(left, right) {
212
+ return left.length === right.length && left.every((id) => right.includes(id));
213
+ }
214
+ invariant(valid(defaultValue), `Invalid default choices for ${key}.`);
215
+ return {
216
+ kind: "multiChoice",
217
+ presentation,
218
+ label: label ?? key,
219
+ options,
220
+ maxSelected,
221
+ urlKeys: [key],
222
+ defaultValue,
223
+ history,
224
+ describe: (values) => values.map((id) => options.find((option) => option.id === id).label).join(", ") || "None",
225
+ read(params) {
226
+ const raw = params.get(key);
227
+ if (raw === null || raw.length > 4096) return defaultValue;
228
+ try {
229
+ const values = JSON.parse(raw);
230
+ return valid(values) ? values : defaultValue;
231
+ } catch {
232
+ return defaultValue;
233
+ }
234
+ },
235
+ write(value) {
236
+ return { [key]: same(value, defaultValue) ? null : JSON.stringify(options.filter((option) => value.includes(option.id)).map((option) => option.id)) };
237
+ },
238
+ valid,
239
+ same
240
+ };
273
241
  }
274
- var PRESET_IDS = new Set([
275
- "day",
276
- "last-3",
277
- "last-7",
278
- "last-14",
279
- "last-30",
280
- "last-90",
281
- "this-week",
282
- "previous-week",
283
- "this-month",
284
- "previous-month"
242
+ const PRESET_IDS = /* @__PURE__ */ new Set([
243
+ "day",
244
+ "last-3",
245
+ "last-7",
246
+ "last-14",
247
+ "last-30",
248
+ "last-90",
249
+ "this-week",
250
+ "previous-week",
251
+ "this-month",
252
+ "previous-month"
285
253
  ]);
286
- function dateRangeVariable({
287
- key,
288
- label = "Date range",
289
- defaultValue,
290
- contract,
291
- history = "push",
292
- comparison = false,
293
- presentation
294
- }) {
295
- const startKey = key === "period" ? "start" : [key, "start"].join("-");
296
- const endKey = key === "period" ? "end" : [key, "end"].join("-");
297
- const comparisonKey = key === "period" ? "compare" : [key, "compare"].join("-");
298
- const bounds = contract.bounds;
299
- function resolve(selection) {
300
- const limits = bounds();
301
- if (selection.kind === "preset") {
302
- const preset = availableDatePresets(limits).find((item) => item.id === selection.id);
303
- if (preset)
304
- return preset.range;
305
- } else {
306
- try {
307
- return contract.parse(selection);
308
- } catch {}
309
- }
310
- invariant2(false, `Date variable ${key} is outside its available data range.`);
311
- }
312
- function same(left, right) {
313
- return left.kind === right.kind && left.comparison === right.comparison && (left.kind === "preset" && right.kind === "preset" ? left.id === right.id : left.kind === "dates" && right.kind === "dates" && left.start === right.start && left.end === right.end);
314
- }
315
- const variable = {
316
- kind: "dateRange",
317
- presentation,
318
- label,
319
- describe: (selection) => contract.describeInput(variable.input(selection).range),
320
- supportsComparison: comparison,
321
- input(selection) {
322
- return contract.request(resolve(selection), selection.comparison === "previous" && comparison);
323
- },
324
- describeInput(input) {
325
- return contract.describeInput(input.range);
326
- },
327
- urlKeys: comparison ? [key, startKey, endKey, comparisonKey] : [key, startKey, endKey],
328
- defaultValue,
329
- clearValue: defaultValue,
330
- history,
331
- bounds,
332
- resolve,
333
- previous(selection) {
334
- return comparison ? contract.comparison(resolve(selection)) : null;
335
- },
336
- comparisonRange(selection) {
337
- return selection.comparison === "previous" && comparison ? contract.comparison(resolve(selection)) : null;
338
- },
339
- same,
340
- valid(value) {
341
- try {
342
- const range = resolve(value);
343
- return value.comparison === undefined || value.comparison === "previous" && comparison && contract.comparison(range) !== null;
344
- } catch {
345
- return false;
346
- }
347
- },
348
- read(params) {
349
- function withComparison(selection) {
350
- if (!comparison || params.get(comparisonKey) !== "previous")
351
- return selection;
352
- const selected = { ...selection, comparison: "previous" };
353
- return variable.valid(selected) ? selected : selection;
354
- }
355
- const presetId = params.get(key);
356
- if (presetId && PRESET_IDS.has(presetId)) {
357
- const selection = {
358
- kind: "preset",
359
- id: presetId
360
- };
361
- if (variable.valid(selection))
362
- return withComparison(selection);
363
- }
364
- const start = params.get(startKey);
365
- const end = params.get(endKey);
366
- if (start && end) {
367
- const selection = { kind: "dates", start, end };
368
- if (variable.valid(selection))
369
- return withComparison(selection);
370
- }
371
- return withComparison(defaultValue);
372
- },
373
- write(value) {
374
- return {
375
- ...same(value, defaultValue) ? { [key]: null, [startKey]: null, [endKey]: null } : value.kind === "preset" ? { [key]: value.id, [startKey]: null, [endKey]: null } : { [key]: null, [startKey]: value.start, [endKey]: value.end },
376
- ...comparison ? { [comparisonKey]: value.comparison ?? null } : {}
377
- };
378
- }
379
- };
380
- invariant2(variable.valid(defaultValue), `Date variable ${key} has a default outside its available data range.`);
381
- return variable;
254
+ /** A date variable keeps relative presets relative and validates exact dates against source coverage. */
255
+ function dateRangeVariable({ key, label = "Date range", defaultValue, contract, history = "push", comparison = false, presentation }) {
256
+ const startKey = key === "period" ? "start" : [key, "start"].join("-");
257
+ const endKey = key === "period" ? "end" : [key, "end"].join("-");
258
+ const comparisonKey = key === "period" ? "compare" : [key, "compare"].join("-");
259
+ const bounds = contract.bounds;
260
+ function resolve(selection) {
261
+ const limits = bounds();
262
+ if (selection.kind === "preset") {
263
+ const preset = availableDatePresets(limits).find((item) => item.id === selection.id);
264
+ if (preset) return preset.range;
265
+ } else try {
266
+ return contract.parse(selection);
267
+ } catch {}
268
+ invariant(false, `Date variable ${key} is outside its available data range.`);
269
+ }
270
+ function same(left, right) {
271
+ return left.kind === right.kind && left.comparison === right.comparison && (left.kind === "preset" && right.kind === "preset" ? left.id === right.id : left.kind === "dates" && right.kind === "dates" && left.start === right.start && left.end === right.end);
272
+ }
273
+ const variable = {
274
+ kind: "dateRange",
275
+ presentation,
276
+ label,
277
+ describe: (selection) => contract.describeInput(variable.input(selection).range),
278
+ supportsComparison: comparison,
279
+ input(selection) {
280
+ return contract.request(resolve(selection), selection.comparison === "previous" && comparison);
281
+ },
282
+ describeInput(input) {
283
+ return contract.describeInput(input.range);
284
+ },
285
+ urlKeys: comparison ? [
286
+ key,
287
+ startKey,
288
+ endKey,
289
+ comparisonKey
290
+ ] : [
291
+ key,
292
+ startKey,
293
+ endKey
294
+ ],
295
+ defaultValue,
296
+ clearValue: defaultValue,
297
+ history,
298
+ bounds,
299
+ resolve,
300
+ previous(selection) {
301
+ return comparison ? contract.comparison(resolve(selection)) : null;
302
+ },
303
+ comparisonRange(selection) {
304
+ return selection.comparison === "previous" && comparison ? contract.comparison(resolve(selection)) : null;
305
+ },
306
+ same,
307
+ valid(value) {
308
+ try {
309
+ const range = resolve(value);
310
+ return value.comparison === void 0 || value.comparison === "previous" && comparison && contract.comparison(range) !== null;
311
+ } catch {
312
+ return false;
313
+ }
314
+ },
315
+ read(params) {
316
+ function withComparison(selection) {
317
+ if (!comparison || params.get(comparisonKey) !== "previous") return selection;
318
+ const selected = {
319
+ ...selection,
320
+ comparison: "previous"
321
+ };
322
+ return variable.valid(selected) ? selected : selection;
323
+ }
324
+ const presetId = params.get(key);
325
+ if (presetId && PRESET_IDS.has(presetId)) {
326
+ const selection = {
327
+ kind: "preset",
328
+ id: presetId
329
+ };
330
+ if (variable.valid(selection)) return withComparison(selection);
331
+ }
332
+ const start = params.get(startKey);
333
+ const end = params.get(endKey);
334
+ if (start && end) {
335
+ const selection = {
336
+ kind: "dates",
337
+ start,
338
+ end
339
+ };
340
+ if (variable.valid(selection)) return withComparison(selection);
341
+ }
342
+ return withComparison(defaultValue);
343
+ },
344
+ write(value) {
345
+ return {
346
+ ...same(value, defaultValue) ? {
347
+ [key]: null,
348
+ [startKey]: null,
349
+ [endKey]: null
350
+ } : value.kind === "preset" ? {
351
+ [key]: value.id,
352
+ [startKey]: null,
353
+ [endKey]: null
354
+ } : {
355
+ [key]: null,
356
+ [startKey]: value.start,
357
+ [endKey]: value.end
358
+ },
359
+ ...comparison ? { [comparisonKey]: value.comparison ?? null } : {}
360
+ };
361
+ }
362
+ };
363
+ invariant(variable.valid(defaultValue), `Date variable ${key} has a default outside its available data range.`);
364
+ return variable;
382
365
  }
383
- // packages/data-app/src/core/facets.ts
384
- var facetSource = Symbol("data-app.facetSource");
385
- export {
386
- KEY_SEPARATOR2 as KEY_SEPARATOR,
387
- MAX_PENDING2 as MAX_PENDING,
388
- PARENT_PARAM2 as PARENT_PARAM,
389
- REQUEST_TIMEOUT_MS2 as REQUEST_TIMEOUT_MS,
390
- RequestBodyTooLargeError2 as RequestBodyTooLargeError,
391
- availableDatePresets,
392
- choiceVariable,
393
- createBridgeEndpoint2 as createBridgeEndpoint,
394
- createDimensionFilter2 as createDimensionFilter,
395
- dateRangeVariable,
396
- defineAppVariables,
397
- dimensionMemberKey2 as dimensionMemberKey,
398
- dimensionSource2 as dimensionSource,
399
- displayedSnapshot,
400
- downloadBlob,
401
- facetSource,
402
- inclusiveDays,
403
- invariant2 as invariant,
404
- isDataAppPresentation,
405
- localFrameBridge2 as localFrameBridge,
406
- multiChoiceVariable,
407
- numberOperatorLabels2 as numberOperatorLabels,
408
- randomUuid2 as randomUuid,
409
- readRequestBody2 as readRequestBody,
410
- resolveDataView,
411
- searchVariable,
412
- toDataOperationFailure2 as toDataOperationFailure,
413
- validId2 as validId,
414
- validateChoiceOptions,
415
- withinBounds
416
- };
366
+ //#endregion
367
+ //#region src/core/facets.ts
368
+ /** Executable facet sources are attached only by the typed hooks factory. */
369
+ const facetSource = Symbol("data-app.facetSource");
370
+ //#endregion
371
+ export { KEY_SEPARATOR, MAX_PENDING, PARENT_PARAM, REQUEST_TIMEOUT_MS, RequestBodyTooLargeError, availableDatePresets, choiceVariable, createBridgeEndpoint, createDimensionFilter, dateRangeVariable, defineAppVariables, dimensionMemberKey, dimensionSource, displayedSnapshot, downloadBlob, facetSource, inclusiveDays, invariant, isDataAppPresentation, localFrameBridge, multiChoiceVariable, numberOperatorLabels, randomUuid, readRequestBody, resolveDataView, searchVariable, toDataOperationFailure, validId, validateChoiceOptions, withinBounds };
417
372
 
418
- //# debugId=B7F5F5B63A5F0E7D64756E2164756E21
373
+ //# sourceMappingURL=internal.js.map