@altertable/data-app 0.70.0 → 0.71.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 +7 -1
- package/CONTRIBUTING.md +59 -26
- package/README.md +22 -26
- package/REFERENCE.md +1900 -0
- package/dist/chunks/index-5a27erdg.js +54 -0
- package/dist/chunks/index-5a27erdg.js.map +10 -0
- package/dist/chunks/{index-58kks6a8.js → index-9yxr7nmm.js} +330 -21
- package/dist/chunks/index-9yxr7nmm.js.map +17 -0
- package/dist/chunks/{index-wjt6cavj.js → index-j5q5n3ra.js} +5 -5
- package/dist/chunks/index-j5q5n3ra.js.map +10 -0
- package/dist/chunks/{index-22d576sn.js → index-q75zm3a7.js} +3 -3
- package/dist/chunks/{index-22d576sn.js.map → index-q75zm3a7.js.map} +3 -3
- package/dist/chunks/{index-9zqbrv2z.js → index-vhaec7m5.js} +4 -6
- package/dist/chunks/index-vhaec7m5.js.map +10 -0
- package/dist/chunks/{index-q1w84fv9.js → index-zp78caex.js} +345 -84
- package/dist/chunks/index-zp78caex.js.map +19 -0
- package/dist/client/index.js +284 -16
- package/dist/client/index.js.map +7 -3
- package/dist/core/appearance.js +181 -11
- package/dist/core/appearance.js.map +4 -3
- package/dist/core/config.js +3 -3
- package/dist/core/contract.js +10 -12
- package/dist/core/contract.js.map +1 -1
- package/dist/core/format.js +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/internal.js +418 -0
- package/dist/internal.js.map +15 -0
- package/dist/server/index.js +102 -0
- package/dist/server/index.js.map +10 -0
- package/dist/types/client/annotations.d.ts +1 -1
- package/dist/types/client/iframe.d.ts +6 -6
- package/dist/types/client/index.d.ts +3 -4
- package/dist/types/client/location.d.ts +2 -2
- package/dist/types/client/logger.d.ts +1 -1
- package/dist/types/client/navigation.d.ts +1 -1
- package/dist/types/client/transport.d.ts +1 -1
- package/dist/types/core/bridge.d.ts +1 -1
- package/dist/types/core/filters.d.ts +1 -1
- package/dist/types/core/format.d.ts +1 -2
- package/dist/types/core/messages.d.ts +3 -3
- package/dist/types/core/operation-types.d.ts +1 -1
- package/dist/types/core/presentation.d.ts +1 -1
- package/dist/types/core/reading.d.ts +1 -1
- package/dist/types/internal.d.ts +22 -0
- package/dist/types/server/index.d.ts +1 -2
- package/docs/app-authoring.md +2 -1
- package/docs/contract.md +1 -1
- package/docs/data-context.md +3 -3
- package/docs/embed.md +4 -4
- package/docs/formatting-and-appearance.md +1 -1
- package/docs/hosted-apps.md +4 -0
- package/docs/react-embed.md +7 -6
- package/docs/react.md +5 -5
- package/docs/server-bun.md +5 -5
- package/docs/stories-and-export.md +3 -3
- package/docs/styling.md +2 -2
- package/docs/ui.md +6 -6
- package/docs/views.md +1 -1
- package/docs/widgets.md +4 -4
- package/docs/worker.md +4 -4
- package/examples/starter-data-app/index.tsx +1 -1
- package/examples/starter-local-data-app/AGENTS.md +1 -1
- package/examples/starter-local-data-app/README.md +12 -10
- package/examples/starter-local-data-app/package.json +3 -1
- package/examples/starter-local-data-app/src/App.tsx +1 -1
- package/examples/starter-local-data-app/src/data-context.ts +1 -1
- package/examples/starter-local-data-app/src/main.tsx +1 -1
- package/examples/starter-local-data-app/src/server.ts +1 -1
- package/package.json +16 -92
- package/THIRD_PARTY_NOTICES +0 -18
- package/dist/chunks/index-2ajhmsc4.js +0 -355
- package/dist/chunks/index-2ajhmsc4.js.map +0 -13
- package/dist/chunks/index-58kks6a8.js.map +0 -13
- package/dist/chunks/index-7q99hf1z.js +0 -87
- package/dist/chunks/index-7q99hf1z.js.map +0 -10
- package/dist/chunks/index-9zqbrv2z.js.map +0 -10
- package/dist/chunks/index-cv36cyna.js +0 -180
- package/dist/chunks/index-cv36cyna.js.map +0 -10
- package/dist/chunks/index-q1w84fv9.js.map +0 -15
- package/dist/chunks/index-rew95tbg.js +0 -272
- package/dist/chunks/index-rew95tbg.js.map +0 -13
- package/dist/chunks/index-vtpygsbq.js +0 -17270
- package/dist/chunks/index-vtpygsbq.js.map +0 -126
- package/dist/chunks/index-wjt6cavj.js.map +0 -10
- package/dist/chunks/index-wss3gd3h.js +0 -319
- package/dist/chunks/index-wss3gd3h.js.map +0 -13
- package/dist/chunks/index-xzb7sx6g.js +0 -221
- package/dist/chunks/index-xzb7sx6g.js.map +0 -12
- package/dist/embed/index.js +0 -138
- package/dist/embed/index.js.map +0 -12
- package/dist/local.js +0 -465
- package/dist/local.js.map +0 -16
- package/dist/preview.js +0 -1456
- package/dist/preview.js.map +0 -17
- package/dist/react/embed/index.js +0 -117
- package/dist/react/embed/index.js.map +0 -10
- package/dist/react/index.js +0 -2890
- package/dist/react/index.js.map +0 -23
- package/dist/react/ui/index.js +0 -3514
- package/dist/react/ui/index.js.map +0 -36
- package/dist/server.js +0 -334
- package/dist/server.js.map +0 -15
- package/dist/types/core/time-interval.d.ts +0 -96
- package/dist/types/embed/bootstrap.d.ts +0 -5
- package/dist/types/embed/bridge.d.ts +0 -12
- package/dist/types/embed/host.d.ts +0 -36
- package/dist/types/embed/index.d.ts +0 -14
- package/dist/types/embed/navigation.d.ts +0 -6
- package/dist/types/embed/runtime-html.d.ts +0 -2
- package/dist/types/embed/source.d.ts +0 -16
- package/dist/types/embed/sql.d.ts +0 -4
- package/dist/types/react/actions.d.ts +0 -53
- package/dist/types/react/annotations/AnnotationBar.d.ts +0 -30
- package/dist/types/react/annotations/AnnotationControls.d.ts +0 -10
- package/dist/types/react/annotations/AnnotationEditor.d.ts +0 -16
- package/dist/types/react/annotations/AnnotationMarkers.d.ts +0 -19
- package/dist/types/react/annotations/AnnotationSelectionLayer.d.ts +0 -12
- package/dist/types/react/annotations/AnnotationTarget.d.ts +0 -9
- package/dist/types/react/annotations/AnnotationTooltip.d.ts +0 -9
- package/dist/types/react/annotations/AnnotationTrigger.d.ts +0 -10
- package/dist/types/react/annotations/annotation-editor-state.d.ts +0 -58
- package/dist/types/react/annotations/annotation-screenshot.d.ts +0 -4
- package/dist/types/react/annotations/annotation-targets.d.ts +0 -34
- package/dist/types/react/annotations/getAnnotationProps.d.ts +0 -17
- package/dist/types/react/annotations/styles.d.ts +0 -3
- package/dist/types/react/annotations/useAnnotationGeometry.d.ts +0 -22
- package/dist/types/react/annotations/useDataAppAnnotations.d.ts +0 -22
- package/dist/types/react/app-context.d.ts +0 -3
- package/dist/types/react/bindings.d.ts +0 -169
- package/dist/types/react/content.d.ts +0 -36
- package/dist/types/react/date-formatting.d.ts +0 -12
- package/dist/types/react/details.d.ts +0 -46
- package/dist/types/react/embed/bridge.d.ts +0 -21
- package/dist/types/react/embed/index.d.ts +0 -7
- package/dist/types/react/exploration.d.ts +0 -44
- package/dist/types/react/hooks.d.ts +0 -113
- package/dist/types/react/index.d.ts +0 -78
- package/dist/types/react/injectStyles.d.ts +0 -7
- package/dist/types/react/mount.d.ts +0 -13
- package/dist/types/react/search-suggestions.d.ts +0 -8
- package/dist/types/react/source-owner.d.ts +0 -2
- package/dist/types/react/style-contract.d.ts +0 -88
- package/dist/types/react/style-validation.d.ts +0 -2
- package/dist/types/react/styles.d.ts +0 -8
- package/dist/types/react/ui/AboutData.d.ts +0 -73
- package/dist/types/react/ui/AltertableLogo.d.ts +0 -3
- package/dist/types/react/ui/AppFooter.d.ts +0 -6
- package/dist/types/react/ui/AppHeader.d.ts +0 -10
- package/dist/types/react/ui/AppLayout.d.ts +0 -10
- package/dist/types/react/ui/AppScope.d.ts +0 -7
- package/dist/types/react/ui/AppToolbar.d.ts +0 -30
- package/dist/types/react/ui/AreaChart.d.ts +0 -7
- package/dist/types/react/ui/BarChart.d.ts +0 -6
- package/dist/types/react/ui/Breakdown.d.ts +0 -13
- package/dist/types/react/ui/Button.d.ts +0 -12
- package/dist/types/react/ui/ChartLegend.d.ts +0 -32
- package/dist/types/react/ui/Checkbox.d.ts +0 -21
- package/dist/types/react/ui/CheckboxGroup.d.ts +0 -7
- package/dist/types/react/ui/ChoicePicker.d.ts +0 -39
- package/dist/types/react/ui/Comparison.d.ts +0 -14
- package/dist/types/react/ui/ComposedChart.d.ts +0 -41
- package/dist/types/react/ui/ComposedChartLegend.d.ts +0 -9
- package/dist/types/react/ui/ContentSkeleton.d.ts +0 -7
- package/dist/types/react/ui/DataApp.d.ts +0 -24
- package/dist/types/react/ui/DataAppFrame.d.ts +0 -52
- package/dist/types/react/ui/DataBoundary.d.ts +0 -14
- package/dist/types/react/ui/DataSection.d.ts +0 -14
- package/dist/types/react/ui/DataSectionBoundary.d.ts +0 -30
- package/dist/types/react/ui/DataTable.d.ts +0 -29
- package/dist/types/react/ui/DataValue.d.ts +0 -9
- package/dist/types/react/ui/DataViewToast.d.ts +0 -11
- package/dist/types/react/ui/DataWidget.d.ts +0 -37
- package/dist/types/react/ui/DateDisplay.d.ts +0 -9
- package/dist/types/react/ui/DateRangePicker.d.ts +0 -30
- package/dist/types/react/ui/DateTimeTooltip.d.ts +0 -10
- package/dist/types/react/ui/DimensionPicker.d.ts +0 -13
- package/dist/types/react/ui/EmptyState.d.ts +0 -6
- package/dist/types/react/ui/ExplorationActionControl.d.ts +0 -60
- package/dist/types/react/ui/ExportControl.d.ts +0 -4
- package/dist/types/react/ui/FilterActions.d.ts +0 -10
- package/dist/types/react/ui/FilterBar.d.ts +0 -3
- package/dist/types/react/ui/FunnelChart.d.ts +0 -20
- package/dist/types/react/ui/GettingStarted.d.ts +0 -6
- package/dist/types/react/ui/GlossaryDefinition.d.ts +0 -7
- package/dist/types/react/ui/GlossaryExplanation.d.ts +0 -16
- package/dist/types/react/ui/GradientScroll.d.ts +0 -23
- package/dist/types/react/ui/Grid.d.ts +0 -12
- package/dist/types/react/ui/GridItem.d.ts +0 -7
- package/dist/types/react/ui/HelpPopover.d.ts +0 -21
- package/dist/types/react/ui/IconButton.d.ts +0 -19
- package/dist/types/react/ui/InspectionContext.d.ts +0 -12
- package/dist/types/react/ui/InspectionProvider.d.ts +0 -29
- package/dist/types/react/ui/JourneyChart.d.ts +0 -10
- package/dist/types/react/ui/Kbd.d.ts +0 -7
- package/dist/types/react/ui/LineChart.d.ts +0 -7
- package/dist/types/react/ui/LiveControl.d.ts +0 -10
- package/dist/types/react/ui/Menu.d.ts +0 -13
- package/dist/types/react/ui/MetricWidget.d.ts +0 -51
- package/dist/types/react/ui/NumberField.d.ts +0 -27
- package/dist/types/react/ui/NumberFilterPicker.d.ts +0 -11
- package/dist/types/react/ui/PeriodSummary.d.ts +0 -17
- package/dist/types/react/ui/PickerField.d.ts +0 -23
- package/dist/types/react/ui/PieChart.d.ts +0 -11
- package/dist/types/react/ui/PopoverSurface.d.ts +0 -5
- package/dist/types/react/ui/PresentStory.d.ts +0 -30
- package/dist/types/react/ui/QueryList.d.ts +0 -14
- package/dist/types/react/ui/RadioGroup.d.ts +0 -18
- package/dist/types/react/ui/Ranking.d.ts +0 -13
- package/dist/types/react/ui/RefreshControl.d.ts +0 -9
- package/dist/types/react/ui/RequestHint.d.ts +0 -20
- package/dist/types/react/ui/RetentionChart.d.ts +0 -27
- package/dist/types/react/ui/ScatterChart.d.ts +0 -17
- package/dist/types/react/ui/SearchField.d.ts +0 -23
- package/dist/types/react/ui/SearchInput.d.ts +0 -10
- package/dist/types/react/ui/SearchMatch.d.ts +0 -6
- package/dist/types/react/ui/SearchTypeahead.d.ts +0 -15
- package/dist/types/react/ui/SectionHeading.d.ts +0 -8
- package/dist/types/react/ui/Select.d.ts +0 -22
- package/dist/types/react/ui/SelectionMark.d.ts +0 -5
- package/dist/types/react/ui/Sheet.d.ts +0 -21
- package/dist/types/react/ui/Skeleton.d.ts +0 -8
- package/dist/types/react/ui/Stack.d.ts +0 -7
- package/dist/types/react/ui/StaticDataApp.d.ts +0 -4
- package/dist/types/react/ui/StatusPanel.d.ts +0 -10
- package/dist/types/react/ui/TableWidget.d.ts +0 -67
- package/dist/types/react/ui/Tabs.d.ts +0 -10
- package/dist/types/react/ui/TextContent.d.ts +0 -4
- package/dist/types/react/ui/TextWidget.d.ts +0 -20
- package/dist/types/react/ui/ThemeSelector.d.ts +0 -12
- package/dist/types/react/ui/Toast.d.ts +0 -8
- package/dist/types/react/ui/Tooltip.d.ts +0 -23
- package/dist/types/react/ui/TooltipSurface.d.ts +0 -3
- package/dist/types/react/ui/TrendChart.d.ts +0 -5
- package/dist/types/react/ui/UpdatedAt.d.ts +0 -9
- package/dist/types/react/ui/VariableBar.d.ts +0 -6
- package/dist/types/react/ui/VisualizationWidget.d.ts +0 -43
- package/dist/types/react/ui/WidgetDisclosure.d.ts +0 -6
- package/dist/types/react/ui/WidgetEvidence.d.ts +0 -12
- package/dist/types/react/ui/WidgetViewTabs.d.ts +0 -16
- package/dist/types/react/ui/chart-data.d.ts +0 -36
- package/dist/types/react/ui/chart-date-axis.d.ts +0 -15
- package/dist/types/react/ui/chart-interaction.d.ts +0 -27
- package/dist/types/react/ui/chart-primitives.d.ts +0 -22
- package/dist/types/react/ui/chart-time.d.ts +0 -19
- package/dist/types/react/ui/chartColor.d.ts +0 -2
- package/dist/types/react/ui/classNames.d.ts +0 -1
- package/dist/types/react/ui/csv-export.d.ts +0 -19
- package/dist/types/react/ui/data-context.d.ts +0 -76
- package/dist/types/react/ui/data-identifiers.d.ts +0 -32
- package/dist/types/react/ui/icons.d.ts +0 -49
- package/dist/types/react/ui/index.d.ts +0 -111
- package/dist/types/react/ui/journey-flow.d.ts +0 -49
- package/dist/types/react/ui/keyboard.d.ts +0 -6
- package/dist/types/react/ui/metric-comparison.d.ts +0 -30
- package/dist/types/react/ui/metric.d.ts +0 -11
- package/dist/types/react/ui/presentation.d.ts +0 -25
- package/dist/types/react/ui/search.d.ts +0 -6
- package/dist/types/react/ui/searchItems.d.ts +0 -36
- package/dist/types/react/ui/shortcuts.d.ts +0 -45
- package/dist/types/react/ui/story.d.ts +0 -20
- package/dist/types/react/ui/use-chart-scroll-to-end.d.ts +0 -2
- package/dist/types/react/ui/useAppAppearance.d.ts +0 -3
- package/dist/types/react/ui/useDataAppPresentation.d.ts +0 -3
- package/dist/types/react/ui/useSvgId.d.ts +0 -2
- package/dist/types/react/ui/variables.d.ts +0 -38
- package/dist/types/react/ui/widget-views.d.ts +0 -3
- package/dist/types/react/view-control-bar.d.ts +0 -18
- package/dist/types/react/view-controls.d.ts +0 -20
- package/dist/types/react/view-runtime.d.ts +0 -34
- package/dist/types/react/view.d.ts +0 -87
- package/dist/types/react/widgets.d.ts +0 -90
- package/dist/types/server/local.d.ts +0 -19
- package/dist/types/server/preview/host.d.ts +0 -1
- package/dist/types/server/preview/index.d.ts +0 -16
- package/dist/types/server/reload-channel.d.ts +0 -6
- package/dist/worker.js +0 -106
|
@@ -1,34 +1,33 @@
|
|
|
1
1
|
import {
|
|
2
2
|
formatDateRange2
|
|
3
|
-
} from "./index-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
decodeQueryResult,
|
|
8
|
-
resolveQueryParameters,
|
|
9
|
-
defineMessageRoute2
|
|
10
|
-
} from "./index-rew95tbg.js";
|
|
3
|
+
} from "./index-q75zm3a7.js";
|
|
4
|
+
|
|
5
|
+
// packages/data-app/src/core/keys.ts
|
|
6
|
+
var KEY_SEPARATOR2 = ":";
|
|
11
7
|
|
|
12
|
-
// src/core/
|
|
13
|
-
|
|
8
|
+
// packages/data-app/src/core/invariant.ts
|
|
9
|
+
function invariant2(condition, message) {
|
|
10
|
+
if (!condition)
|
|
11
|
+
throw new Error(`Invariant failed: ${message}`);
|
|
12
|
+
}
|
|
14
13
|
|
|
15
|
-
// src/core/dimension.ts
|
|
14
|
+
// packages/data-app/src/core/dimension.ts
|
|
16
15
|
var allSelection = { kind: "all" };
|
|
17
|
-
function
|
|
18
|
-
return member.kind === "missing" ? "missing" : ["value", typeof member.value, member.value].join(
|
|
16
|
+
function dimensionMemberKey2(member) {
|
|
17
|
+
return member.kind === "missing" ? "missing" : ["value", typeof member.value, member.value].join(KEY_SEPARATOR2);
|
|
19
18
|
}
|
|
20
19
|
function dimensionFilter2(config) {
|
|
21
|
-
return { ...
|
|
20
|
+
return { ...createDimensionFilter2(config), optionsSource: "fixed" };
|
|
22
21
|
}
|
|
23
|
-
function
|
|
22
|
+
function createDimensionFilter2(config, dynamic = false) {
|
|
24
23
|
const { key, label, selectionMode, valueType } = config;
|
|
25
24
|
const options = config.options ?? [];
|
|
26
|
-
const optionKeys = options.map((option) =>
|
|
27
|
-
|
|
28
|
-
|
|
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.");
|
|
29
28
|
const allowed = new Set(optionKeys);
|
|
30
29
|
const maxSelected = config.maxSelected ?? (selectionMode === "single" ? 1 : 20);
|
|
31
|
-
|
|
30
|
+
invariant2(Number.isInteger(maxSelected) && maxSelected >= 1 && maxSelected <= 50 && (selectionMode !== "single" || maxSelected === 1), "Dimension selection limit is invalid.");
|
|
32
31
|
const allowMissing = config.allowMissing ?? false;
|
|
33
32
|
const defaultValue = allSelection;
|
|
34
33
|
function validMember(member) {
|
|
@@ -39,7 +38,7 @@ function createDimensionFilter(config, dynamic = false) {
|
|
|
39
38
|
if (member.kind !== "value" || typeof member.value !== valueType)
|
|
40
39
|
return false;
|
|
41
40
|
if (!dynamic)
|
|
42
|
-
return allowed.has(
|
|
41
|
+
return allowed.has(dimensionMemberKey2(member));
|
|
43
42
|
return typeof member.value === "number" ? Number.isFinite(member.value) : member.value.length <= 100;
|
|
44
43
|
}
|
|
45
44
|
function valid(value) {
|
|
@@ -51,7 +50,7 @@ function createDimensionFilter(config, dynamic = false) {
|
|
|
51
50
|
return false;
|
|
52
51
|
if (!value.members.every(validMember))
|
|
53
52
|
return false;
|
|
54
|
-
const ids = value.members.map(
|
|
53
|
+
const ids = value.members.map(dimensionMemberKey2);
|
|
55
54
|
return new Set(ids).size === ids.length;
|
|
56
55
|
}
|
|
57
56
|
function encode(value) {
|
|
@@ -110,42 +109,42 @@ function createDimensionFilter(config, dynamic = false) {
|
|
|
110
109
|
};
|
|
111
110
|
}
|
|
112
111
|
function parseDimensionSelection2(value, filter) {
|
|
113
|
-
|
|
112
|
+
invariant2(filter.valid(value), `Invalid ${filter.label} selection.`);
|
|
114
113
|
return value;
|
|
115
114
|
}
|
|
116
115
|
function parseFacetOptions2(value, filter) {
|
|
117
|
-
|
|
116
|
+
invariant2(Array.isArray(value) && value.length <= 200, "Facet options exceed their bound.");
|
|
118
117
|
const options = [];
|
|
119
118
|
const seen = new Set;
|
|
120
119
|
for (const item of value) {
|
|
121
|
-
|
|
120
|
+
invariant2(item && typeof item === "object", "Invalid facet option.");
|
|
122
121
|
const option = item;
|
|
123
|
-
|
|
122
|
+
invariant2(typeof option.value === filter.valueType && filter.valid({
|
|
124
123
|
kind: "include",
|
|
125
124
|
members: [{ kind: "value", value: option.value }]
|
|
126
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.");
|
|
127
|
-
const id =
|
|
128
|
-
|
|
126
|
+
const id = dimensionMemberKey2({ kind: "value", value: option.value });
|
|
127
|
+
invariant2(!seen.has(id), "Duplicate facet option.");
|
|
129
128
|
seen.add(id);
|
|
130
129
|
options.push(option);
|
|
131
130
|
}
|
|
132
131
|
return options;
|
|
133
132
|
}
|
|
134
133
|
function dimensionPredicate2(column, selection, allowedColumns) {
|
|
135
|
-
|
|
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.");
|
|
136
135
|
if (selection.kind === "all")
|
|
137
136
|
return "";
|
|
138
|
-
|
|
137
|
+
invariant2(selection.members.length > 0, "Empty dimension inclusion is invalid.");
|
|
139
138
|
const values = selection.members.filter((member) => member.kind === "value");
|
|
140
139
|
const missing = selection.members.some((member) => member.kind === "missing");
|
|
141
140
|
const literals = values.map(({ value }) => {
|
|
142
141
|
if (typeof value === "number") {
|
|
143
|
-
|
|
142
|
+
invariant2(Number.isFinite(value), "Invalid numeric dimension value.");
|
|
144
143
|
return String(value);
|
|
145
144
|
}
|
|
146
145
|
const text = value;
|
|
147
146
|
for (let index = 0;index < text.length; index++)
|
|
148
|
-
|
|
147
|
+
invariant2(text.charCodeAt(index) >= 32 && text.charCodeAt(index) !== 127, "Invalid control character in dimension value.");
|
|
149
148
|
return `'${text.replaceAll("'", "''")}'`;
|
|
150
149
|
});
|
|
151
150
|
const clauses = [
|
|
@@ -156,8 +155,114 @@ function dimensionPredicate2(column, selection, allowedColumns) {
|
|
|
156
155
|
return selection.kind === "exclude" ? missing ? `NOT ${predicate}` : `(${column} IS NULL OR NOT ${predicate})` : predicate;
|
|
157
156
|
}
|
|
158
157
|
|
|
159
|
-
// src/core/
|
|
160
|
-
var
|
|
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");
|
|
161
266
|
var sources = new WeakMap;
|
|
162
267
|
var parserVariables = new WeakMap;
|
|
163
268
|
var selectorsKey = Symbol.for("@altertable/data-app/dimension-selectors");
|
|
@@ -174,15 +279,15 @@ function variableInput2(parse, variables) {
|
|
|
174
279
|
const previous = parserVariables.get(parse) ?? {};
|
|
175
280
|
const definitions = { ...variables };
|
|
176
281
|
for (const [name, variable] of Object.entries(definitions))
|
|
177
|
-
|
|
282
|
+
invariant2(!previous[name] || previous[name] === variable, `Variable input ${name} is already declared.`);
|
|
178
283
|
function parser(value) {
|
|
179
|
-
|
|
284
|
+
invariant2(value && typeof value === "object" && !Array.isArray(value), "Expected variable input.");
|
|
180
285
|
const input = parse(value);
|
|
181
|
-
|
|
286
|
+
invariant2(input && typeof input === "object" && !Array.isArray(input), "Expected parsed input object.");
|
|
182
287
|
const values = {};
|
|
183
288
|
for (const [name, variable] of Object.entries(definitions)) {
|
|
184
289
|
const selected = value[name];
|
|
185
|
-
|
|
290
|
+
invariant2(variable.valid(selected), `Invalid ${variable.label ?? name}.`);
|
|
186
291
|
values[name] = selected;
|
|
187
292
|
}
|
|
188
293
|
return { ...input, ...values };
|
|
@@ -194,20 +299,20 @@ function variableInput2(parse, variables) {
|
|
|
194
299
|
return parser;
|
|
195
300
|
}
|
|
196
301
|
function bindDimensionSource(config, queries) {
|
|
197
|
-
|
|
302
|
+
invariant2(!config.allowMissing, "Source dimensions require concrete members.");
|
|
198
303
|
const query = queries[config.source.query];
|
|
199
|
-
|
|
304
|
+
invariant2(query && Object.hasOwn(query.params, "member"), "Dimension sources must declare member.");
|
|
200
305
|
const member = query.params.member;
|
|
201
306
|
const { value, label, count } = query.projections;
|
|
202
|
-
|
|
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.");
|
|
203
308
|
const operation = `__dimension:${config.key}`;
|
|
204
|
-
const variable = Object.assign(
|
|
309
|
+
const variable = Object.assign(createDimensionFilter2({
|
|
205
310
|
...config,
|
|
206
311
|
valueType: config.valueType,
|
|
207
312
|
options: []
|
|
208
313
|
}, true), {
|
|
209
314
|
optionsSource: "query",
|
|
210
|
-
[
|
|
315
|
+
[dimensionSource2]: Object.freeze({ operation })
|
|
211
316
|
});
|
|
212
317
|
sources.set(variable, { query: config.source.query, queries });
|
|
213
318
|
return variable;
|
|
@@ -216,7 +321,7 @@ async function loadOptions(variable, member, query) {
|
|
|
216
321
|
const source = sources.get(variable);
|
|
217
322
|
const result = await query(source.query, { member }, { limit: member === null ? 200 : 2 });
|
|
218
323
|
const names = result.columns.map((column) => column.name);
|
|
219
|
-
|
|
324
|
+
invariant2(new Set(names).size === names.length && names.includes("value") && names.includes("label"), "Dimension source must return value and label.");
|
|
220
325
|
const options = parseFacetOptions2(result.rows, variable);
|
|
221
326
|
if (member !== null && (options.length !== 1 || options[0].value !== member))
|
|
222
327
|
throw new DimensionMembershipError(`Invalid ${variable.label} member.`);
|
|
@@ -237,19 +342,19 @@ async function validateVariableInput(parser, input, query) {
|
|
|
237
342
|
function attachDimensionSelectors(operation, queries) {
|
|
238
343
|
const selectors = {};
|
|
239
344
|
for (const variable of Object.values(parserVariables.get(operation.input) ?? {})) {
|
|
240
|
-
if (variable.kind !== "dimension" || !(
|
|
345
|
+
if (variable.kind !== "dimension" || !(dimensionSource2 in variable))
|
|
241
346
|
continue;
|
|
242
347
|
const source = sources.get(variable);
|
|
243
348
|
if (!source)
|
|
244
349
|
continue;
|
|
245
|
-
|
|
246
|
-
const name = variable[
|
|
247
|
-
|
|
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.");
|
|
248
353
|
selectors[name] = {
|
|
249
354
|
input(value) {
|
|
250
|
-
|
|
355
|
+
invariant2(value && typeof value === "object", "Invalid dimension request.");
|
|
251
356
|
const member = value.member;
|
|
252
|
-
|
|
357
|
+
invariant2(member === null || variable.valid({
|
|
253
358
|
kind: "include",
|
|
254
359
|
members: [{ kind: "value", value: member }]
|
|
255
360
|
}), "Invalid requested member.");
|
|
@@ -283,16 +388,172 @@ function withDimensionSelectors(operations) {
|
|
|
283
388
|
const expanded = { ...operations };
|
|
284
389
|
for (const operation of Object.values(operations))
|
|
285
390
|
for (const [name, selector] of Object.entries(operation[selectorsKey] ?? {})) {
|
|
286
|
-
|
|
287
|
-
|
|
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.");
|
|
288
393
|
expanded[name] ??= selector;
|
|
289
394
|
}
|
|
290
395
|
return expanded;
|
|
291
396
|
}
|
|
292
397
|
|
|
293
|
-
// src/core/contract.ts
|
|
398
|
+
// packages/data-app/src/core/contract.ts
|
|
294
399
|
import { parseDate, today } from "@internationalized/date";
|
|
295
|
-
// src/core/
|
|
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
|
|
296
557
|
function object(value) {
|
|
297
558
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
298
559
|
throw new Error("Invalid annotation.");
|
|
@@ -478,9 +739,9 @@ function isAnnotationPresentation(value) {
|
|
|
478
739
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
|
|
479
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)));
|
|
480
741
|
}
|
|
481
|
-
// src/core/filters.ts
|
|
742
|
+
// packages/data-app/src/core/filters.ts
|
|
482
743
|
var all = { kind: "all" };
|
|
483
|
-
var
|
|
744
|
+
var numberOperatorLabels2 = {
|
|
484
745
|
eq: "Equals",
|
|
485
746
|
ne: "Does not equal",
|
|
486
747
|
gt: "Greater than",
|
|
@@ -497,8 +758,8 @@ function numberFilter2({
|
|
|
497
758
|
history = "push",
|
|
498
759
|
presentation
|
|
499
760
|
}) {
|
|
500
|
-
|
|
501
|
-
|
|
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.");
|
|
502
763
|
function validNumber(value) {
|
|
503
764
|
return typeof value === "number" && Number.isFinite(value) && (min === undefined || value >= min) && (max === undefined || value <= max);
|
|
504
765
|
}
|
|
@@ -508,7 +769,7 @@ function numberFilter2({
|
|
|
508
769
|
if (value.kind === "all")
|
|
509
770
|
return true;
|
|
510
771
|
if (value.kind === "comparison")
|
|
511
|
-
return typeof value.operator === "string" && Object.hasOwn(
|
|
772
|
+
return typeof value.operator === "string" && Object.hasOwn(numberOperatorLabels2, value.operator) && validNumber(value.value);
|
|
512
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);
|
|
513
774
|
}
|
|
514
775
|
function encode(value) {
|
|
@@ -518,7 +779,7 @@ function numberFilter2({
|
|
|
518
779
|
value: value.value
|
|
519
780
|
});
|
|
520
781
|
}
|
|
521
|
-
|
|
782
|
+
invariant2(valid(defaultValue), `Invalid default for ${label}.`);
|
|
522
783
|
return {
|
|
523
784
|
kind: "numberFilter",
|
|
524
785
|
presentation,
|
|
@@ -532,7 +793,7 @@ function numberFilter2({
|
|
|
532
793
|
valid,
|
|
533
794
|
same: (left, right) => encode(left) === encode(right),
|
|
534
795
|
describe(value) {
|
|
535
|
-
return value.kind === "all" ? "Any" : value.kind === "comparison" ? `${
|
|
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}`;
|
|
536
797
|
},
|
|
537
798
|
read(params) {
|
|
538
799
|
const raw = params.get(key);
|
|
@@ -561,14 +822,14 @@ function booleanFilter2({
|
|
|
561
822
|
history = "push",
|
|
562
823
|
presentation
|
|
563
824
|
}) {
|
|
564
|
-
|
|
825
|
+
invariant2(!!key.trim(), "Boolean filter requires a URL key.");
|
|
565
826
|
function valid(value) {
|
|
566
827
|
return !!value && typeof value === "object" && (value.kind === "all" || value.kind === "is" && typeof value.value === "boolean");
|
|
567
828
|
}
|
|
568
829
|
function encode(value) {
|
|
569
830
|
return value.kind === "all" ? "all" : String(value.value);
|
|
570
831
|
}
|
|
571
|
-
|
|
832
|
+
invariant2(valid(defaultValue), `Invalid default for ${label}.`);
|
|
572
833
|
return {
|
|
573
834
|
kind: "booleanFilter",
|
|
574
835
|
presentation,
|
|
@@ -592,21 +853,21 @@ function booleanFilter2({
|
|
|
592
853
|
};
|
|
593
854
|
}
|
|
594
855
|
function parseNumberSelection2(value, filter) {
|
|
595
|
-
|
|
856
|
+
invariant2(filter.valid(value), `Invalid ${filter.label} selection.`);
|
|
596
857
|
return value;
|
|
597
858
|
}
|
|
598
859
|
function parseBooleanSelection2(value, filter) {
|
|
599
|
-
|
|
860
|
+
invariant2(filter.valid(value), `Invalid ${filter.label} selection.`);
|
|
600
861
|
return value;
|
|
601
862
|
}
|
|
602
863
|
|
|
603
|
-
// src/core/contract.ts
|
|
864
|
+
// packages/data-app/src/core/contract.ts
|
|
604
865
|
function parseEmptyInput2(value) {
|
|
605
|
-
|
|
866
|
+
invariant2(typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length === 0, "This operation takes no inputs.");
|
|
606
867
|
return {};
|
|
607
868
|
}
|
|
608
869
|
function parseTrue2(value) {
|
|
609
|
-
|
|
870
|
+
invariant2(value === true, "Expected a successful check.");
|
|
610
871
|
return true;
|
|
611
872
|
}
|
|
612
873
|
function previousDateRange2({
|
|
@@ -616,7 +877,7 @@ function previousDateRange2({
|
|
|
616
877
|
const first = parseDate(start);
|
|
617
878
|
const last = parseDate(end);
|
|
618
879
|
const days = (last.toDate("UTC").getTime() - first.toDate("UTC").getTime()) / 86400000 + 1;
|
|
619
|
-
|
|
880
|
+
invariant2(days >= 1, "Date range must start before it ends.");
|
|
620
881
|
const previousEnd = first.subtract({ days: 1 });
|
|
621
882
|
return {
|
|
622
883
|
start: previousEnd.subtract({ days: days - 1 }).toString(),
|
|
@@ -624,7 +885,7 @@ function previousDateRange2({
|
|
|
624
885
|
};
|
|
625
886
|
}
|
|
626
887
|
function defineDateRangeContract2(options) {
|
|
627
|
-
|
|
888
|
+
invariant2(Number.isInteger(options.maxRangeDays) && options.maxRangeDays > 0, "Date range needs a positive maxRangeDays.");
|
|
628
889
|
if (options.minDate)
|
|
629
890
|
parseDate(options.minDate);
|
|
630
891
|
if (typeof options.maxDate === "string")
|
|
@@ -661,16 +922,16 @@ function defineDateRangeContract2(options) {
|
|
|
661
922
|
function request(value, compare = false) {
|
|
662
923
|
const range = parseDateRangeInput2(value, bounds());
|
|
663
924
|
const previous = compare ? comparison(range) : null;
|
|
664
|
-
|
|
925
|
+
invariant2(!compare || previous, "Comparison is outside available source coverage.");
|
|
665
926
|
return { range, comparison: previous };
|
|
666
927
|
}
|
|
667
928
|
function parseRequest(value) {
|
|
668
|
-
|
|
929
|
+
invariant2(value && typeof value === "object", "Choose a date range.");
|
|
669
930
|
const input = value;
|
|
670
931
|
const parsed = request(input.range, input.comparison != null);
|
|
671
932
|
if (input.comparison != null) {
|
|
672
933
|
const supplied = parseDateRangeInput2(input.comparison, bounds());
|
|
673
|
-
|
|
934
|
+
invariant2(supplied.start === parsed.comparison?.start && supplied.end === parsed.comparison?.end, "Comparison must be the preceding equal-length range.");
|
|
674
935
|
}
|
|
675
936
|
return parsed;
|
|
676
937
|
}
|
|
@@ -692,32 +953,32 @@ function parseDateRangeInput2(value, {
|
|
|
692
953
|
maxDate,
|
|
693
954
|
maxRangeDays
|
|
694
955
|
}) {
|
|
695
|
-
|
|
956
|
+
invariant2(value && typeof value === "object" && !Array.isArray(value), "Choose a date range.");
|
|
696
957
|
const { start, end } = value;
|
|
697
958
|
function day(input) {
|
|
698
|
-
|
|
959
|
+
invariant2(typeof input === "string" && /^\d{4}-\d{2}-\d{2}$/.test(input), "Dates must be YYYY-MM-DD.");
|
|
699
960
|
const timestamp = Date.parse(`${input}T00:00:00Z`);
|
|
700
|
-
|
|
961
|
+
invariant2(Number.isFinite(timestamp) && new Date(timestamp).toISOString().slice(0, 10) === input, "Choose valid calendar dates.");
|
|
701
962
|
return timestamp;
|
|
702
963
|
}
|
|
703
964
|
const first = day(start);
|
|
704
965
|
const last = day(end);
|
|
705
|
-
|
|
706
|
-
|
|
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.`);
|
|
707
968
|
return { start, end };
|
|
708
969
|
}
|
|
709
970
|
function parseCount2(value) {
|
|
710
971
|
const number = typeof value === "number" || typeof value === "string" ? Number(value) : NaN;
|
|
711
|
-
|
|
972
|
+
invariant2(Number.isSafeInteger(number) && number >= 0 && (typeof value !== "string" || !!value.trim()), "Invalid count in query result.");
|
|
712
973
|
return number;
|
|
713
974
|
}
|
|
714
975
|
function parseLabel2(value, maxLength = 100) {
|
|
715
|
-
|
|
976
|
+
invariant2(typeof value === "string" && !!value && value.length <= maxLength, "Invalid label in query result.");
|
|
716
977
|
return value;
|
|
717
978
|
}
|
|
718
979
|
function defineQueryNames2(names) {
|
|
719
980
|
const values = Object.values(names);
|
|
720
|
-
|
|
981
|
+
invariant2(values.every((name) => !!name.trim()) && new Set(values).size === values.length, "Query names must be nonempty and unique.");
|
|
721
982
|
return names;
|
|
722
983
|
}
|
|
723
984
|
var sourceErrorBrand = Symbol.for("@altertable/data-app/DataSourceError");
|
|
@@ -738,7 +999,7 @@ class DataSourceError2 extends Error {
|
|
|
738
999
|
}
|
|
739
1000
|
}
|
|
740
1001
|
function defineOperation2(operation) {
|
|
741
|
-
|
|
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.");
|
|
742
1003
|
const queries = snapshotQueries(operation.queries);
|
|
743
1004
|
const queryNames = Object.fromEntries(Object.keys(queries).map((name) => [name, name]));
|
|
744
1005
|
for (const input of operation.checks)
|
|
@@ -748,7 +1009,7 @@ function defineOperation2(operation) {
|
|
|
748
1009
|
queryNames,
|
|
749
1010
|
async run(context, input) {
|
|
750
1011
|
async function query(name, values = {}, options) {
|
|
751
|
-
|
|
1012
|
+
invariant2(Object.hasOwn(queries, name), `Unknown query name: ${name}.`);
|
|
752
1013
|
const definition = queries[name];
|
|
753
1014
|
const params = resolveQueryParameters(definition.params, values, context.queryParams ?? {});
|
|
754
1015
|
const result = await context.lakehouse.queryAll(definition.statement, {
|
|
@@ -781,6 +1042,6 @@ function connectionCheck2(queries) {
|
|
|
781
1042
|
});
|
|
782
1043
|
}
|
|
783
1044
|
|
|
784
|
-
export {
|
|
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 };
|
|
785
1046
|
|
|
786
|
-
//# debugId=
|
|
1047
|
+
//# debugId=0B494A6494D6A59764756E2164756E21
|