@altertable/data-app 0.70.0 → 0.72.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 +73 -33
- package/README.md +23 -26
- package/REFERENCE.md +1904 -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/config.d.ts +8 -9
- 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 +18 -1
- package/docs/client.md +1 -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 +16 -8
- package/docs/local-data-apps.md +1 -1
- package/docs/react-embed.md +7 -6
- package/docs/react.md +6 -6
- package/docs/server-bun.md +6 -6
- package/docs/stories-and-export.md +3 -3
- package/docs/styling.md +2 -2
- package/docs/ui.md +6 -6
- package/docs/views.md +2 -2
- package/docs/widgets.md +4 -4
- package/docs/worker.md +4 -4
- package/package.json +15 -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
- package/examples/starter-data-app/index.tsx +0 -193
- package/examples/starter-local-data-app/.bun-version +0 -1
- package/examples/starter-local-data-app/.node-version +0 -1
- package/examples/starter-local-data-app/.oxfmtrc.json +0 -4
- package/examples/starter-local-data-app/.oxlintrc.json +0 -33
- package/examples/starter-local-data-app/AGENTS.md +0 -22
- package/examples/starter-local-data-app/README.md +0 -54
- package/examples/starter-local-data-app/app.ts +0 -28
- package/examples/starter-local-data-app/bunfig.toml +0 -2
- package/examples/starter-local-data-app/package.json +0 -33
- package/examples/starter-local-data-app/src/App.tsx +0 -8
- package/examples/starter-local-data-app/src/assets.d.ts +0 -1
- package/examples/starter-local-data-app/src/data-context.ts +0 -21
- package/examples/starter-local-data-app/src/favicon.svg +0 -13
- package/examples/starter-local-data-app/src/index.html +0 -14
- package/examples/starter-local-data-app/src/main.tsx +0 -7
- package/examples/starter-local-data-app/src/operations.ts +0 -6
- package/examples/starter-local-data-app/src/server.ts +0 -6
- package/examples/starter-local-data-app/tsconfig.json +0 -21
package/dist/embed/index.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import"../chunks/index-22d576sn.js";
|
|
2
|
-
import"../chunks/index-q1w84fv9.js";
|
|
3
|
-
import {
|
|
4
|
-
attachDataAppBridge2
|
|
5
|
-
} from "../chunks/index-2ajhmsc4.js";
|
|
6
|
-
import {
|
|
7
|
-
toDataOperationFailure
|
|
8
|
-
} from "../chunks/index-wjt6cavj.js";
|
|
9
|
-
import {
|
|
10
|
-
createIframeTransport2,
|
|
11
|
-
installDataAppTransport2
|
|
12
|
-
} from "../chunks/index-58kks6a8.js";
|
|
13
|
-
import {
|
|
14
|
-
randomUuid,
|
|
15
|
-
PARENT_PARAM
|
|
16
|
-
} from "../chunks/index-wss3gd3h.js";
|
|
17
|
-
import {
|
|
18
|
-
MessageRoutingError2
|
|
19
|
-
} from "../chunks/index-rew95tbg.js";
|
|
20
|
-
// src/embed/bootstrap.ts
|
|
21
|
-
function startDataAppBootstrap({
|
|
22
|
-
parentOrigin,
|
|
23
|
-
window: frame = window
|
|
24
|
-
}) {
|
|
25
|
-
let loaded;
|
|
26
|
-
let failure;
|
|
27
|
-
const bundleSource = `altertable-data-app-${randomUuid()}.js`;
|
|
28
|
-
const bridge = createIframeTransport2({
|
|
29
|
-
parentOrigin,
|
|
30
|
-
window: frame,
|
|
31
|
-
mode: "bundle",
|
|
32
|
-
loadScript(javascript) {
|
|
33
|
-
if (loaded !== undefined) {
|
|
34
|
-
if (javascript !== loaded)
|
|
35
|
-
bridge.fail(new Error("This frame already evaluated a different app script."));
|
|
36
|
-
else if (failure)
|
|
37
|
-
bridge.fail(failure.cause);
|
|
38
|
-
else
|
|
39
|
-
bridge.ready();
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
loaded = javascript;
|
|
43
|
-
try {
|
|
44
|
-
const script = frame.document.createElement("script");
|
|
45
|
-
script.textContent = `${javascript}
|
|
46
|
-
//# sourceURL=${bundleSource}`;
|
|
47
|
-
frame.document.body.append(script);
|
|
48
|
-
if (!failure)
|
|
49
|
-
bridge.ready();
|
|
50
|
-
} catch (error) {
|
|
51
|
-
reportError(error);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
function reportError(error) {
|
|
56
|
-
failure = { cause: error };
|
|
57
|
-
bridge.fail(error);
|
|
58
|
-
}
|
|
59
|
-
function reportBundleError(event) {
|
|
60
|
-
if (event.filename === bundleSource)
|
|
61
|
-
reportError(event.error ?? event.message);
|
|
62
|
-
}
|
|
63
|
-
function reportBundleRejection(event) {
|
|
64
|
-
if (event.reason instanceof Error && event.reason.stack?.includes(bundleSource))
|
|
65
|
-
reportError(event.reason);
|
|
66
|
-
}
|
|
67
|
-
frame.addEventListener("error", reportBundleError);
|
|
68
|
-
frame.addEventListener("unhandledrejection", reportBundleRejection);
|
|
69
|
-
const uninstall = installDataAppTransport2(bridge, frame);
|
|
70
|
-
return () => {
|
|
71
|
-
frame.removeEventListener("error", reportBundleError);
|
|
72
|
-
frame.removeEventListener("unhandledrejection", reportBundleRejection);
|
|
73
|
-
uninstall();
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
// src/embed/navigation.ts
|
|
77
|
-
function createNavigationHandler({
|
|
78
|
-
window: host = window,
|
|
79
|
-
reservedSearchParams = []
|
|
80
|
-
} = {}) {
|
|
81
|
-
function navigate(input) {
|
|
82
|
-
const previous = new URL(host.location.href);
|
|
83
|
-
const url = new URL(previous);
|
|
84
|
-
url.search = input.search;
|
|
85
|
-
url.searchParams.delete(PARENT_PARAM);
|
|
86
|
-
for (const name of reservedSearchParams) {
|
|
87
|
-
url.searchParams.delete(name);
|
|
88
|
-
for (const value of previous.searchParams.getAll(name))
|
|
89
|
-
url.searchParams.append(name, value);
|
|
90
|
-
}
|
|
91
|
-
url.hash = input.hash;
|
|
92
|
-
if (url.href !== host.location.href)
|
|
93
|
-
host.history[input.mode === "push" ? "pushState" : "replaceState"](null, "", url);
|
|
94
|
-
if (input.title !== undefined)
|
|
95
|
-
host.document.title = input.title;
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
return navigate;
|
|
99
|
-
}
|
|
100
|
-
// src/embed/sql.ts
|
|
101
|
-
function createSqlQueryHandler(authorize) {
|
|
102
|
-
async function handleSqlQuery(input, context) {
|
|
103
|
-
const requestId = randomUuid();
|
|
104
|
-
context.signal.throwIfAborted();
|
|
105
|
-
let lakehouse;
|
|
106
|
-
try {
|
|
107
|
-
lakehouse = await authorize(input, context);
|
|
108
|
-
} catch {
|
|
109
|
-
context.signal.throwIfAborted();
|
|
110
|
-
throw new MessageRoutingError2("forbidden", "You cannot run this query.", requestId);
|
|
111
|
-
}
|
|
112
|
-
context.signal.throwIfAborted();
|
|
113
|
-
try {
|
|
114
|
-
return await lakehouse.queryAll(input.statement, {
|
|
115
|
-
limit: input.limit,
|
|
116
|
-
...input.params === undefined ? {} : { params: input.params },
|
|
117
|
-
signal: context.signal
|
|
118
|
-
});
|
|
119
|
-
} catch (error) {
|
|
120
|
-
context.signal.throwIfAborted();
|
|
121
|
-
if (error instanceof MessageRoutingError2)
|
|
122
|
-
throw error;
|
|
123
|
-
const failure = toDataOperationFailure(error);
|
|
124
|
-
throw new MessageRoutingError2(failure.code, failure.message, requestId, {
|
|
125
|
-
cause: error
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return handleSqlQuery;
|
|
130
|
-
}
|
|
131
|
-
export {
|
|
132
|
-
attachDataAppBridge2 as attachDataAppBridge,
|
|
133
|
-
createNavigationHandler,
|
|
134
|
-
createSqlQueryHandler,
|
|
135
|
-
startDataAppBootstrap
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
//# debugId=F133D372B55FA32864756E2164756E21
|
package/dist/embed/index.js.map
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/embed/bootstrap.ts", "../src/embed/navigation.ts", "../src/embed/sql.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { randomUuid } from '@/src/core/uuid';\nimport {\n createIframeTransport,\n installDataAppTransport,\n} from '@/src/client/iframe';\n\n/** Run from a trusted bootstrap page in an allow-scripts-only iframe. CSP can prohibit network access. */\nexport function startDataAppBootstrap({\n parentOrigin,\n window: frame = window,\n}: {\n parentOrigin: string;\n window?: Window;\n}) {\n let loaded: string | undefined;\n let failure: { cause: unknown } | undefined;\n const bundleSource = `altertable-data-app-${randomUuid()}.js`;\n const bridge = createIframeTransport({\n parentOrigin,\n window: frame,\n mode: 'bundle',\n loadScript(javascript) {\n if (loaded !== undefined) {\n if (javascript !== loaded)\n bridge.fail(\n new Error('This frame already evaluated a different app script.')\n );\n else if (failure) bridge.fail(failure.cause);\n else bridge.ready();\n\n return;\n }\n loaded = javascript;\n try {\n const script = frame.document.createElement('script');\n script.textContent = `${javascript}\\n//# sourceURL=${bundleSource}`;\n frame.document.body.append(script);\n if (!failure) bridge.ready();\n } catch (error) {\n reportError(error);\n }\n },\n });\n\n function reportError(error: unknown) {\n failure = { cause: error };\n bridge.fail(error);\n }\n\n function reportBundleError(event: ErrorEvent) {\n if (event.filename === bundleSource)\n reportError(event.error ?? event.message);\n }\n\n function reportBundleRejection(event: PromiseRejectionEvent) {\n if (\n event.reason instanceof Error &&\n event.reason.stack?.includes(bundleSource)\n )\n reportError(event.reason);\n }\n\n frame.addEventListener('error', reportBundleError);\n frame.addEventListener('unhandledrejection', reportBundleRejection);\n const uninstall = installDataAppTransport(bridge, frame);\n\n return () => {\n frame.removeEventListener('error', reportBundleError);\n frame.removeEventListener('unhandledrejection', reportBundleRejection);\n uninstall();\n };\n}\n",
|
|
6
|
-
"import { PARENT_PARAM } from '@/src/core/bridge';\nimport type { NavigationUpdate } from '@/src/core/messages';\n\n/** Override this handler for framework routers. Reserved host parameters survive app navigation. */\nexport function createNavigationHandler({\n window: host = window,\n reservedSearchParams = [],\n}: {\n window?: Window;\n reservedSearchParams?: readonly string[];\n} = {}) {\n function navigate(input: NavigationUpdate): null {\n const previous = new URL(host.location.href);\n const url = new URL(previous);\n url.search = input.search;\n url.searchParams.delete(PARENT_PARAM);\n for (const name of reservedSearchParams) {\n url.searchParams.delete(name);\n for (const value of previous.searchParams.getAll(name))\n url.searchParams.append(name, value);\n }\n url.hash = input.hash;\n if (url.href !== host.location.href)\n host.history[input.mode === 'push' ? 'pushState' : 'replaceState'](\n null,\n '',\n url\n );\n if (input.title !== undefined) host.document.title = input.title;\n\n return null;\n }\n\n return navigate;\n}\n",
|
|
7
|
-
"import { randomUuid } from '@/src/core/uuid';\nimport type { Lakehouse } from '@/src/core/contract';\nimport { toDataOperationFailure } from '@/src/core/operation';\nimport {\n MessageRoutingError,\n type MessageContext,\n type SqlQueryInput,\n} from '@/src/core/messages';\n\n/** Authorize every SQL request and supply a backend that independently enforces access and query limits. */\nexport function createSqlQueryHandler(\n authorize: (\n query: SqlQueryInput,\n context: MessageContext\n ) => Promise<Lakehouse>\n) {\n async function handleSqlQuery(input: SqlQueryInput, context: MessageContext) {\n const requestId = randomUuid();\n context.signal.throwIfAborted();\n let lakehouse: Lakehouse;\n try {\n lakehouse = await authorize(input, context);\n } catch {\n context.signal.throwIfAborted();\n throw new MessageRoutingError(\n 'forbidden',\n 'You cannot run this query.',\n requestId\n );\n }\n context.signal.throwIfAborted();\n try {\n return await lakehouse.queryAll(input.statement, {\n limit: input.limit,\n ...(input.params === undefined ? {} : { params: input.params }),\n signal: context.signal,\n });\n } catch (error) {\n context.signal.throwIfAborted();\n if (error instanceof MessageRoutingError) throw error;\n const failure = toDataOperationFailure(error);\n throw new MessageRoutingError(failure.code, failure.message, requestId, {\n cause: error,\n });\n }\n }\n\n return handleSqlQuery;\n}\n"
|
|
8
|
-
],
|
|
9
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAOO,SAAS,qBAAqB;AAAA,EACnC;AAAA,EACA,QAAQ,QAAQ;AAAA,GAIf;AAAA,EACD,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,MAAM,eAAe,uBAAuB,WAAW;AAAA,EACvD,MAAM,SAAS,uBAAsB;AAAA,IACnC;AAAA,IACA,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,UAAU,CAAC,YAAY;AAAA,MACrB,IAAI,WAAW,WAAW;AAAA,QACxB,IAAI,eAAe;AAAA,UACjB,OAAO,KACL,IAAI,MAAM,sDAAsD,CAClE;AAAA,QACG,SAAI;AAAA,UAAS,OAAO,KAAK,QAAQ,KAAK;AAAA,QACtC;AAAA,iBAAO,MAAM;AAAA,QAElB;AAAA,MACF;AAAA,MACA,SAAS;AAAA,MACT,IAAI;AAAA,QACF,MAAM,SAAS,MAAM,SAAS,cAAc,QAAQ;AAAA,QACpD,OAAO,cAAc,GAAG;AAAA,gBAA6B;AAAA,QACrD,MAAM,SAAS,KAAK,OAAO,MAAM;AAAA,QACjC,IAAI,CAAC;AAAA,UAAS,OAAO,MAAM;AAAA,QAC3B,OAAO,OAAO;AAAA,QACd,YAAY,KAAK;AAAA;AAAA;AAAA,EAGvB,CAAC;AAAA,EAED,SAAS,WAAW,CAAC,OAAgB;AAAA,IACnC,UAAU,EAAE,OAAO,MAAM;AAAA,IACzB,OAAO,KAAK,KAAK;AAAA;AAAA,EAGnB,SAAS,iBAAiB,CAAC,OAAmB;AAAA,IAC5C,IAAI,MAAM,aAAa;AAAA,MACrB,YAAY,MAAM,SAAS,MAAM,OAAO;AAAA;AAAA,EAG5C,SAAS,qBAAqB,CAAC,OAA8B;AAAA,IAC3D,IACE,MAAM,kBAAkB,SACxB,MAAM,OAAO,OAAO,SAAS,YAAY;AAAA,MAEzC,YAAY,MAAM,MAAM;AAAA;AAAA,EAG5B,MAAM,iBAAiB,SAAS,iBAAiB;AAAA,EACjD,MAAM,iBAAiB,sBAAsB,qBAAqB;AAAA,EAClE,MAAM,YAAY,yBAAwB,QAAQ,KAAK;AAAA,EAEvD,OAAO,MAAM;AAAA,IACX,MAAM,oBAAoB,SAAS,iBAAiB;AAAA,IACpD,MAAM,oBAAoB,sBAAsB,qBAAqB;AAAA,IACrE,UAAU;AAAA;AAAA;;ACjEP,SAAS,uBAAuB;AAAA,EACrC,QAAQ,OAAO;AAAA,EACf,uBAAuB,CAAC;AAAA,IAItB,CAAC,GAAG;AAAA,EACN,SAAS,QAAQ,CAAC,OAA+B;AAAA,IAC/C,MAAM,WAAW,IAAI,IAAI,KAAK,SAAS,IAAI;AAAA,IAC3C,MAAM,MAAM,IAAI,IAAI,QAAQ;AAAA,IAC5B,IAAI,SAAS,MAAM;AAAA,IACnB,IAAI,aAAa,OAAO,YAAY;AAAA,IACpC,WAAW,QAAQ,sBAAsB;AAAA,MACvC,IAAI,aAAa,OAAO,IAAI;AAAA,MAC5B,WAAW,SAAS,SAAS,aAAa,OAAO,IAAI;AAAA,QACnD,IAAI,aAAa,OAAO,MAAM,KAAK;AAAA,IACvC;AAAA,IACA,IAAI,OAAO,MAAM;AAAA,IACjB,IAAI,IAAI,SAAS,KAAK,SAAS;AAAA,MAC7B,KAAK,QAAQ,MAAM,SAAS,SAAS,cAAc,gBACjD,MACA,IACA,GACF;AAAA,IACF,IAAI,MAAM,UAAU;AAAA,MAAW,KAAK,SAAS,QAAQ,MAAM;AAAA,IAE3D,OAAO;AAAA;AAAA,EAGT,OAAO;AAAA;;ACvBF,SAAS,qBAAqB,CACnC,WAIA;AAAA,EACA,eAAe,cAAc,CAAC,OAAsB,SAAyB;AAAA,IAC3E,MAAM,YAAY,WAAW;AAAA,IAC7B,QAAQ,OAAO,eAAe;AAAA,IAC9B,IAAI;AAAA,IACJ,IAAI;AAAA,MACF,YAAY,MAAM,UAAU,OAAO,OAAO;AAAA,MAC1C,MAAM;AAAA,MACN,QAAQ,OAAO,eAAe;AAAA,MAC9B,MAAM,IAAI,qBACR,aACA,8BACA,SACF;AAAA;AAAA,IAEF,QAAQ,OAAO,eAAe;AAAA,IAC9B,IAAI;AAAA,MACF,OAAO,MAAM,UAAU,SAAS,MAAM,WAAW;AAAA,QAC/C,OAAO,MAAM;AAAA,WACT,MAAM,WAAW,YAAY,CAAC,IAAI,EAAE,QAAQ,MAAM,OAAO;AAAA,QAC7D,QAAQ,QAAQ;AAAA,MAClB,CAAC;AAAA,MACD,OAAO,OAAO;AAAA,MACd,QAAQ,OAAO,eAAe;AAAA,MAC9B,IAAI,iBAAiB;AAAA,QAAqB,MAAM;AAAA,MAChD,MAAM,UAAU,uBAAuB,KAAK;AAAA,MAC5C,MAAM,IAAI,qBAAoB,QAAQ,MAAM,QAAQ,SAAS,WAAW;AAAA,QACtE,OAAO;AAAA,MACT,CAAC;AAAA;AAAA;AAAA,EAIL,OAAO;AAAA;",
|
|
10
|
-
"debugId": "F133D372B55FA32864756E2164756E21",
|
|
11
|
-
"names": []
|
|
12
|
-
}
|
package/dist/local.js
DELETED
|
@@ -1,465 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// src/core/invariant.ts
|
|
3
|
-
function invariant(condition, message) {
|
|
4
|
-
if (!condition)
|
|
5
|
-
throw new Error(`Invariant failed: ${message}`);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// src/core/dimension-source.ts
|
|
9
|
-
var dimensionSource = Symbol("data-app.dimensionSource");
|
|
10
|
-
var sources = new WeakMap;
|
|
11
|
-
var parserVariables = new WeakMap;
|
|
12
|
-
var selectorsKey = Symbol.for("@altertable/data-app/dimension-selectors");
|
|
13
|
-
var ownerKey = Symbol.for("@altertable/data-app/dimension-selector-owner");
|
|
14
|
-
var invalidMemberKey = Symbol.for("@altertable/data-app/dimension-member-error");
|
|
15
|
-
|
|
16
|
-
class DimensionMembershipError extends Error {
|
|
17
|
-
[invalidMemberKey] = true;
|
|
18
|
-
static [Symbol.hasInstance](value) {
|
|
19
|
-
return value instanceof Error && value[invalidMemberKey] === true;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function withDimensionSelectors(operations) {
|
|
23
|
-
const expanded = { ...operations };
|
|
24
|
-
for (const operation of Object.values(operations))
|
|
25
|
-
for (const [name, selector] of Object.entries(operation[selectorsKey] ?? {})) {
|
|
26
|
-
invariant(!Object.hasOwn(operations, name), "Reserved dimension operation name.");
|
|
27
|
-
invariant(!expanded[name] || expanded[name][ownerKey] === selector[ownerKey], "Dimension source keys must be unique across the app.");
|
|
28
|
-
expanded[name] ??= selector;
|
|
29
|
-
}
|
|
30
|
-
return expanded;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// src/core/contract.ts
|
|
34
|
-
import { parseDate, today } from "@internationalized/date";
|
|
35
|
-
var sourceErrorBrand = Symbol.for("@altertable/data-app/DataSourceError");
|
|
36
|
-
|
|
37
|
-
class DataSourceError extends Error {
|
|
38
|
-
reason;
|
|
39
|
-
status;
|
|
40
|
-
[sourceErrorBrand] = true;
|
|
41
|
-
queryName;
|
|
42
|
-
static [Symbol.hasInstance](value) {
|
|
43
|
-
return value instanceof Error && value[sourceErrorBrand] === true;
|
|
44
|
-
}
|
|
45
|
-
constructor(reason, status, options) {
|
|
46
|
-
super(`Data source ${reason}${status ? ` (${status})` : ""}.`, options);
|
|
47
|
-
this.reason = reason;
|
|
48
|
-
this.status = status;
|
|
49
|
-
this.name = "DataSourceError";
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// src/server/local.ts
|
|
54
|
-
import {
|
|
55
|
-
AltertableLakehouseClient,
|
|
56
|
-
AltertableLakehouseError,
|
|
57
|
-
NetworkError,
|
|
58
|
-
TimeoutError,
|
|
59
|
-
QueryError
|
|
60
|
-
} from "@altertable/lakehouse";
|
|
61
|
-
|
|
62
|
-
// src/server/request-body.ts
|
|
63
|
-
class RequestBodyTooLargeError extends Error {
|
|
64
|
-
}
|
|
65
|
-
async function readRequestBody(request, maxBytes) {
|
|
66
|
-
const body = request.body;
|
|
67
|
-
if (!body)
|
|
68
|
-
return "";
|
|
69
|
-
const reader = body.getReader();
|
|
70
|
-
const chunks = [];
|
|
71
|
-
let size = 0;
|
|
72
|
-
let abort;
|
|
73
|
-
function cancelReader() {
|
|
74
|
-
reader.cancel().catch(() => {});
|
|
75
|
-
}
|
|
76
|
-
try {
|
|
77
|
-
request.signal.throwIfAborted();
|
|
78
|
-
const cancelled = new Promise((_, reject) => {
|
|
79
|
-
function rejectAborted() {
|
|
80
|
-
reject(new Error("Request aborted."));
|
|
81
|
-
cancelReader();
|
|
82
|
-
}
|
|
83
|
-
abort = rejectAborted;
|
|
84
|
-
request.signal.addEventListener("abort", rejectAborted, { once: true });
|
|
85
|
-
if (request.signal.aborted)
|
|
86
|
-
rejectAborted();
|
|
87
|
-
});
|
|
88
|
-
while (true) {
|
|
89
|
-
const { done, value } = await Promise.race([reader.read(), cancelled]);
|
|
90
|
-
if (done)
|
|
91
|
-
break;
|
|
92
|
-
size += value.byteLength;
|
|
93
|
-
if (size > maxBytes) {
|
|
94
|
-
cancelReader();
|
|
95
|
-
throw new RequestBodyTooLargeError;
|
|
96
|
-
}
|
|
97
|
-
chunks.push(value);
|
|
98
|
-
}
|
|
99
|
-
const bytes = new Uint8Array(size);
|
|
100
|
-
let offset = 0;
|
|
101
|
-
for (const chunk of chunks) {
|
|
102
|
-
bytes.set(chunk, offset);
|
|
103
|
-
offset += chunk.byteLength;
|
|
104
|
-
}
|
|
105
|
-
return new TextDecoder().decode(bytes);
|
|
106
|
-
} finally {
|
|
107
|
-
if (abort)
|
|
108
|
-
request.signal.removeEventListener("abort", abort);
|
|
109
|
-
reader.releaseLock();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// src/core/operation.ts
|
|
114
|
-
async function executeDataOperation(operation, value, {
|
|
115
|
-
operationName,
|
|
116
|
-
lakehouse,
|
|
117
|
-
signal: requestSignal,
|
|
118
|
-
requestId,
|
|
119
|
-
queryParams
|
|
120
|
-
}) {
|
|
121
|
-
requestSignal.throwIfAborted();
|
|
122
|
-
let input;
|
|
123
|
-
try {
|
|
124
|
-
input = operation.input(value);
|
|
125
|
-
} catch {
|
|
126
|
-
throw new OperationInputError;
|
|
127
|
-
}
|
|
128
|
-
const signal = AbortSignal.any([
|
|
129
|
-
requestSignal,
|
|
130
|
-
AbortSignal.timeout(operation.policy.maxDurationMs)
|
|
131
|
-
]);
|
|
132
|
-
const execution = createOperationLakehouse(operation, lakehouse, signal, operationName);
|
|
133
|
-
try {
|
|
134
|
-
const output = await runOperation(operation, input, {
|
|
135
|
-
lakehouse: execution.lakehouse,
|
|
136
|
-
signal,
|
|
137
|
-
queryParams
|
|
138
|
-
});
|
|
139
|
-
const body = {
|
|
140
|
-
data: output,
|
|
141
|
-
requestId,
|
|
142
|
-
queriedAt: new Date().toISOString(),
|
|
143
|
-
queryIds: execution.queryIds,
|
|
144
|
-
queries: execution.queries
|
|
145
|
-
};
|
|
146
|
-
const serializedBody = JSON.stringify(body);
|
|
147
|
-
const responseBytes = new TextEncoder().encode(serializedBody).byteLength;
|
|
148
|
-
if (responseBytes > (operation.policy.maxResponseBytes ?? 1e6))
|
|
149
|
-
throw new Error("Response exceeds byte limit.");
|
|
150
|
-
return { body, serializedBody };
|
|
151
|
-
} catch (error) {
|
|
152
|
-
if (signal.aborted && !(error instanceof DataSourceError))
|
|
153
|
-
throw new OperationTimeoutError;
|
|
154
|
-
throw error;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
function createOperationLakehouse(operation, source, signal, operationName) {
|
|
158
|
-
const queryIds = [];
|
|
159
|
-
const queries = [];
|
|
160
|
-
const lakehouse = {
|
|
161
|
-
async queryAll(statement, options) {
|
|
162
|
-
signal.throwIfAborted();
|
|
163
|
-
if (!Number.isInteger(options.limit) || options.limit < 1)
|
|
164
|
-
throw new Error("Query needs a positive row limit.");
|
|
165
|
-
if (operation.queryNames && !Object.values(operation.queryNames).includes(options.name ?? ""))
|
|
166
|
-
throw new Error(`Query name is not registered for operation ${operationName}.`);
|
|
167
|
-
const query = {
|
|
168
|
-
name: options.name ?? `Query ${queries.length + 1}`,
|
|
169
|
-
statement,
|
|
170
|
-
...options.params === undefined ? {} : { params: options.params }
|
|
171
|
-
};
|
|
172
|
-
queries.push(query);
|
|
173
|
-
const limit = Math.min(options.limit, operation.policy.maxQueryRows);
|
|
174
|
-
let result;
|
|
175
|
-
try {
|
|
176
|
-
result = await source.queryAll(statement, {
|
|
177
|
-
limit,
|
|
178
|
-
...options.params === undefined ? {} : { params: options.params },
|
|
179
|
-
signal: AbortSignal.any([signal, options.signal])
|
|
180
|
-
});
|
|
181
|
-
} catch (error) {
|
|
182
|
-
if (error instanceof DataSourceError)
|
|
183
|
-
error.queryName = query.name;
|
|
184
|
-
throw error;
|
|
185
|
-
}
|
|
186
|
-
if (result.rows.length > limit)
|
|
187
|
-
throw new Error("Result exceeds row limit.");
|
|
188
|
-
if (result.queryId) {
|
|
189
|
-
query.queryId = result.queryId;
|
|
190
|
-
queryIds.push(result.queryId);
|
|
191
|
-
}
|
|
192
|
-
return result;
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
return { lakehouse, queries, queryIds };
|
|
196
|
-
}
|
|
197
|
-
async function runOperation(operation, input, { lakehouse, signal, queryParams }) {
|
|
198
|
-
let abort;
|
|
199
|
-
try {
|
|
200
|
-
signal.throwIfAborted();
|
|
201
|
-
const cancelled = new Promise((_, reject) => {
|
|
202
|
-
function rejectAborted() {
|
|
203
|
-
reject(new Error("Request aborted."));
|
|
204
|
-
}
|
|
205
|
-
abort = rejectAborted;
|
|
206
|
-
signal.addEventListener("abort", rejectAborted, { once: true });
|
|
207
|
-
if (signal.aborted)
|
|
208
|
-
rejectAborted();
|
|
209
|
-
});
|
|
210
|
-
return await Promise.race([
|
|
211
|
-
cancelled,
|
|
212
|
-
Promise.resolve().then(() => {
|
|
213
|
-
signal.throwIfAborted();
|
|
214
|
-
return operation.run({ lakehouse, signal, queryParams }, input);
|
|
215
|
-
})
|
|
216
|
-
]);
|
|
217
|
-
} finally {
|
|
218
|
-
if (abort)
|
|
219
|
-
signal.removeEventListener("abort", abort);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
class OperationTimeoutError extends Error {
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
class OperationInputError extends Error {
|
|
227
|
-
}
|
|
228
|
-
var sourceErrorMessages = {
|
|
229
|
-
unauthorized: "This app could not authenticate its data connection. Contact the app owner.",
|
|
230
|
-
forbidden: "This app cannot access the requested data. Contact the app owner.",
|
|
231
|
-
rate_limited: "The lakehouse is busy. Wait a moment and retry.",
|
|
232
|
-
query_rejected: "A lakehouse query was rejected. Check the app's data operation.",
|
|
233
|
-
unavailable: "The lakehouse is unavailable. Check the connection and retry."
|
|
234
|
-
};
|
|
235
|
-
function toDataOperationFailure(error, aborted = false) {
|
|
236
|
-
if (error instanceof OperationInputError || error instanceof DimensionMembershipError)
|
|
237
|
-
return {
|
|
238
|
-
status: 400,
|
|
239
|
-
code: "invalid_input",
|
|
240
|
-
message: "Check this operation's inputs."
|
|
241
|
-
};
|
|
242
|
-
if (error instanceof DataSourceError)
|
|
243
|
-
return {
|
|
244
|
-
status: error.reason === "rate_limited" ? 429 : 502,
|
|
245
|
-
code: `source_${error.reason}`,
|
|
246
|
-
message: sourceErrorMessages[error.reason]
|
|
247
|
-
};
|
|
248
|
-
const timedOut = aborted || error instanceof OperationTimeoutError;
|
|
249
|
-
return {
|
|
250
|
-
status: timedOut ? 504 : 502,
|
|
251
|
-
code: timedOut ? "timeout" : "query_failed",
|
|
252
|
-
message: timedOut ? "The data request timed out." : "The data request failed."
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// src/server/handler.ts
|
|
257
|
-
function createDataHandler(operations, authorize) {
|
|
258
|
-
operations = withDimensionSelectors(operations);
|
|
259
|
-
async function handleDataRequest(request) {
|
|
260
|
-
const requestId = crypto.randomUUID();
|
|
261
|
-
const url = new URL(request.url);
|
|
262
|
-
if (!url.pathname.startsWith("/api/data/"))
|
|
263
|
-
return new Response("Not found", { status: 404 });
|
|
264
|
-
const encodedName = url.pathname.slice("/api/data/".length);
|
|
265
|
-
if (!encodedName || encodedName.includes("/"))
|
|
266
|
-
return problem(404, "not_found", "Unknown data operation.", requestId);
|
|
267
|
-
let name;
|
|
268
|
-
try {
|
|
269
|
-
name = decodeURIComponent(encodedName);
|
|
270
|
-
} catch {
|
|
271
|
-
return problem(404, "not_found", "Unknown data operation.", requestId);
|
|
272
|
-
}
|
|
273
|
-
if (!Object.hasOwn(operations, name))
|
|
274
|
-
return problem(404, "not_found", "Unknown data operation.", requestId);
|
|
275
|
-
if (request.method !== "POST")
|
|
276
|
-
return problem(405, "method_not_allowed", "Use POST.", requestId);
|
|
277
|
-
if (request.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase() !== "application/json")
|
|
278
|
-
return problem(415, "unsupported_media_type", "Use application/json.", requestId);
|
|
279
|
-
const origin = request.headers.get("origin");
|
|
280
|
-
const fetchSite = request.headers.get("sec-fetch-site");
|
|
281
|
-
const fetchMode = request.headers.get("sec-fetch-mode");
|
|
282
|
-
if (origin !== null && origin !== url.origin || fetchSite !== null && fetchSite !== "same-origin" || fetchSite !== null && origin === null || fetchMode !== null && fetchMode !== "cors" && fetchMode !== "same-origin")
|
|
283
|
-
return problem(403, "cross_origin_request", "The data request must come from this app.", requestId);
|
|
284
|
-
let access;
|
|
285
|
-
try {
|
|
286
|
-
access = await authorize(request, name);
|
|
287
|
-
} catch {
|
|
288
|
-
return problem(403, "forbidden", "You cannot run this data operation.", requestId);
|
|
289
|
-
}
|
|
290
|
-
const operation = operations[name];
|
|
291
|
-
let input;
|
|
292
|
-
if (request.signal.aborted)
|
|
293
|
-
return problem(504, "timeout", "The data request timed out.", requestId);
|
|
294
|
-
try {
|
|
295
|
-
const body = await readRequestBody(request, MAX_INPUT_BYTES);
|
|
296
|
-
input = JSON.parse(body);
|
|
297
|
-
} catch (error) {
|
|
298
|
-
if (error instanceof RequestBodyTooLargeError)
|
|
299
|
-
return problem(413, "input_too_large", "Input is too large.", requestId);
|
|
300
|
-
return problem(400, "invalid_input", "Check this operation's inputs.", requestId);
|
|
301
|
-
}
|
|
302
|
-
const signal = request.signal;
|
|
303
|
-
try {
|
|
304
|
-
const { serializedBody } = await executeDataOperation(operation, input, {
|
|
305
|
-
lakehouse: access.lakehouse,
|
|
306
|
-
signal,
|
|
307
|
-
requestId,
|
|
308
|
-
operationName: name,
|
|
309
|
-
queryParams: access.queryParams
|
|
310
|
-
});
|
|
311
|
-
return new Response(serializedBody, {
|
|
312
|
-
headers: {
|
|
313
|
-
"cache-control": "no-store",
|
|
314
|
-
"content-type": "application/json"
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
} catch (error) {
|
|
318
|
-
let detail = error instanceof Error ? error.name : "unknown";
|
|
319
|
-
if (error instanceof DataSourceError) {
|
|
320
|
-
detail = error.reason;
|
|
321
|
-
if (error.status)
|
|
322
|
-
detail += ` (${error.status})`;
|
|
323
|
-
if (error.queryName)
|
|
324
|
-
detail += ` in ${error.queryName}`;
|
|
325
|
-
if (error.cause instanceof Error && error.cause.message)
|
|
326
|
-
detail += `: ${error.cause.message}`;
|
|
327
|
-
}
|
|
328
|
-
console.error(`Data operation ${name} failed (${requestId}): ${detail}`);
|
|
329
|
-
const failure = toDataOperationFailure(error, signal.aborted);
|
|
330
|
-
return problem(failure.status, failure.code, failure.message, requestId);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
return handleDataRequest;
|
|
334
|
-
}
|
|
335
|
-
function problem(status, code, message, requestId) {
|
|
336
|
-
return Response.json({ error: { code, message, requestId } }, { status, headers: { "cache-control": "no-store" } });
|
|
337
|
-
}
|
|
338
|
-
var MAX_INPUT_BYTES = 16384;
|
|
339
|
-
|
|
340
|
-
// src/server/local.ts
|
|
341
|
-
function serveLocalApp({
|
|
342
|
-
page,
|
|
343
|
-
operations,
|
|
344
|
-
title,
|
|
345
|
-
port = Number(process.env.PORT ?? 25837)
|
|
346
|
-
}) {
|
|
347
|
-
const lakehouse = localLakehouse();
|
|
348
|
-
const server = Bun.serve({
|
|
349
|
-
hostname: "127.0.0.1",
|
|
350
|
-
port,
|
|
351
|
-
development: true,
|
|
352
|
-
idleTimeout: 60,
|
|
353
|
-
routes: { "/": page },
|
|
354
|
-
fetch: createDataHandler(operations, async () => ({
|
|
355
|
-
lakehouse
|
|
356
|
-
}))
|
|
357
|
-
});
|
|
358
|
-
console.log(`${title} running at ${server.url}`);
|
|
359
|
-
return server;
|
|
360
|
-
}
|
|
361
|
-
function validateLakehouseCredentials(environment = process.env) {
|
|
362
|
-
const proxyUrl = environment.ALTERTABLE_DATA_PROXY_URL;
|
|
363
|
-
const proxyToken = environment.ALTERTABLE_DATA_PROXY_TOKEN;
|
|
364
|
-
const username = environment.ALTERTABLE_LAKEHOUSE_USERNAME;
|
|
365
|
-
const password = environment.ALTERTABLE_LAKEHOUSE_PASSWORD;
|
|
366
|
-
if (proxyUrl && !proxyToken)
|
|
367
|
-
throw new Error("Missing ALTERTABLE_DATA_PROXY_TOKEN. Set it when ALTERTABLE_DATA_PROXY_URL is configured.");
|
|
368
|
-
if (!proxyUrl && (!username || !password))
|
|
369
|
-
throw new Error("Missing lakehouse credentials. Set both ALTERTABLE_LAKEHOUSE_USERNAME and ALTERTABLE_LAKEHOUSE_PASSWORD, or use the CLI lakehouse proxy.");
|
|
370
|
-
}
|
|
371
|
-
function localLakehouse(environment = process.env, request = fetch) {
|
|
372
|
-
validateLakehouseCredentials(environment);
|
|
373
|
-
const proxyUrl = environment.ALTERTABLE_DATA_PROXY_URL;
|
|
374
|
-
const proxyToken = environment.ALTERTABLE_DATA_PROXY_TOKEN;
|
|
375
|
-
const username = environment.ALTERTABLE_LAKEHOUSE_USERNAME;
|
|
376
|
-
const password = environment.ALTERTABLE_LAKEHOUSE_PASSWORD;
|
|
377
|
-
return {
|
|
378
|
-
async queryAll(statement, { limit, signal, params }) {
|
|
379
|
-
signal.throwIfAborted();
|
|
380
|
-
const cancellation = new AbortController;
|
|
381
|
-
const client = new AltertableLakehouseClient({
|
|
382
|
-
baseUrl: proxyUrl || environment.ALTERTABLE_API_BASE || undefined,
|
|
383
|
-
username,
|
|
384
|
-
password,
|
|
385
|
-
basicAuthToken: proxyUrl ? proxyToken : undefined,
|
|
386
|
-
retryPolicy: { maxAttempts: 1 },
|
|
387
|
-
fetch: Object.assign(async (url, options) => {
|
|
388
|
-
const headers = new Headers(options?.headers);
|
|
389
|
-
if (proxyUrl)
|
|
390
|
-
headers.set("authorization", `Bearer ${proxyToken}`);
|
|
391
|
-
const requestSignal = AbortSignal.any([
|
|
392
|
-
signal,
|
|
393
|
-
cancellation.signal,
|
|
394
|
-
...options?.signal ? [options.signal] : []
|
|
395
|
-
]);
|
|
396
|
-
const response = await request(url, {
|
|
397
|
-
...options,
|
|
398
|
-
headers,
|
|
399
|
-
signal: requestSignal
|
|
400
|
-
});
|
|
401
|
-
return boundedQueryResponse(response, requestSignal);
|
|
402
|
-
}, { preconnect() {} })
|
|
403
|
-
});
|
|
404
|
-
try {
|
|
405
|
-
const result = await client.query({ statement, limit, params });
|
|
406
|
-
const { columns, metadata } = result;
|
|
407
|
-
if (!metadata || typeof metadata !== "object" || Array.isArray(metadata) || metadata.query_id !== undefined && typeof metadata.query_id !== "string")
|
|
408
|
-
throw new Error("Invalid query metadata.");
|
|
409
|
-
if (new Set(columns.map((column) => column.name)).size !== columns.length)
|
|
410
|
-
throw new Error("Query columns must have unique names.");
|
|
411
|
-
const rows = [];
|
|
412
|
-
for await (const row of result.rows) {
|
|
413
|
-
signal.throwIfAborted();
|
|
414
|
-
if (rows.length >= limit)
|
|
415
|
-
throw new Error("Lakehouse returned more rows than requested.");
|
|
416
|
-
const values = columns.map((column) => Object.hasOwn(row, column.name) ? row[column.name] : undefined);
|
|
417
|
-
if (values.some((value) => value === undefined))
|
|
418
|
-
throw new Error("Query row is missing a column.");
|
|
419
|
-
rows.push(values);
|
|
420
|
-
}
|
|
421
|
-
return { columns, rows, queryId: metadata.query_id };
|
|
422
|
-
} catch (error) {
|
|
423
|
-
signal.throwIfAborted();
|
|
424
|
-
if (error instanceof QueryError)
|
|
425
|
-
throw new DataSourceError("query_rejected", undefined, {
|
|
426
|
-
cause: error
|
|
427
|
-
});
|
|
428
|
-
if (error instanceof NetworkError || error instanceof TimeoutError)
|
|
429
|
-
throw new DataSourceError("unavailable", undefined, { cause: error });
|
|
430
|
-
if (error instanceof AltertableLakehouseError && error.statusCode !== undefined) {
|
|
431
|
-
const status = error.statusCode;
|
|
432
|
-
const reason = status === 401 ? "unauthorized" : status === 403 ? "forbidden" : status === 429 ? "rate_limited" : status === 400 || status === 422 ? "query_rejected" : "unavailable";
|
|
433
|
-
throw new DataSourceError(reason, status, { cause: error });
|
|
434
|
-
}
|
|
435
|
-
throw error;
|
|
436
|
-
} finally {
|
|
437
|
-
cancellation.abort();
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
function boundedQueryResponse(response, signal) {
|
|
443
|
-
if (!response.body)
|
|
444
|
-
return response;
|
|
445
|
-
let bytes = 0;
|
|
446
|
-
const body = response.body.pipeThrough(new TransformStream({
|
|
447
|
-
transform(chunk, controller) {
|
|
448
|
-
bytes += chunk.byteLength;
|
|
449
|
-
if (bytes > 5000000)
|
|
450
|
-
throw new Error("Query response is too large.");
|
|
451
|
-
controller.enqueue(chunk);
|
|
452
|
-
}
|
|
453
|
-
}), { signal });
|
|
454
|
-
return new Response(body, {
|
|
455
|
-
status: response.status,
|
|
456
|
-
headers: response.headers
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
export {
|
|
460
|
-
localLakehouse,
|
|
461
|
-
serveLocalApp,
|
|
462
|
-
validateLakehouseCredentials
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
//# debugId=6A4E2C19477DE8E064756E2164756E21
|