@altertable/data-app 0.69.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 +11 -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-2sbp9h2b.js → index-9yxr7nmm.js} +330 -21
- package/dist/chunks/index-9yxr7nmm.js.map +17 -0
- package/dist/chunks/{index-r7b1ftwy.js → index-j5q5n3ra.js} +8 -6
- 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-kwnqycjt.js → index-vhaec7m5.js} +8 -6
- package/dist/chunks/index-vhaec7m5.js.map +10 -0
- package/dist/chunks/index-zp78caex.js +1047 -0
- 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 +13 -15
- 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/data-client.d.ts +21 -10
- 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 +20 -17
- package/dist/types/core/contract.d.ts +23 -13
- package/dist/types/core/dimension-source.d.ts +64 -0
- package/dist/types/core/dimension.d.ts +31 -23
- package/dist/types/core/facets.d.ts +13 -0
- package/dist/types/core/filters.d.ts +1 -1
- package/dist/types/core/format.d.ts +1 -2
- package/dist/types/core/keys.d.ts +2 -0
- package/dist/types/core/messages.d.ts +3 -3
- package/dist/types/core/operation-types.d.ts +7 -6
- package/dist/types/core/presentation.d.ts +1 -1
- package/dist/types/core/queries.d.ts +75 -7
- package/dist/types/core/reading.d.ts +1 -1
- package/dist/types/core/variables.d.ts +38 -12
- package/dist/types/index.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 +12 -4
- package/docs/client.md +5 -6
- package/docs/composition.md +84 -0
- package/docs/contract.md +41 -21
- package/docs/data-context.md +5 -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/server.md +1 -1
- package/docs/stories-and-export.md +3 -3
- package/docs/styling.md +6 -2
- package/docs/ui.md +18 -7
- package/docs/variables.md +83 -11
- package/docs/views.md +57 -3
- package/docs/widgets.md +97 -4
- package/docs/worker.md +4 -4
- package/examples/starter-data-app/index.tsx +11 -23
- 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/app.ts +7 -1
- 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/examples/starter-local-data-app/tsconfig.json +7 -1
- package/package.json +16 -92
- package/THIRD_PARTY_NOTICES +0 -18
- package/dist/chunks/index-2sbp9h2b.js.map +0 -13
- package/dist/chunks/index-ap60vggk.js +0 -80
- package/dist/chunks/index-ap60vggk.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-k766wwwr.js +0 -643
- package/dist/chunks/index-k766wwwr.js.map +0 -13
- package/dist/chunks/index-kwnqycjt.js.map +0 -10
- package/dist/chunks/index-m0gbxtgp.js +0 -355
- package/dist/chunks/index-m0gbxtgp.js.map +0 -13
- package/dist/chunks/index-qhzdzca2.js +0 -15869
- package/dist/chunks/index-qhzdzca2.js.map +0 -118
- package/dist/chunks/index-r7b1ftwy.js.map +0 -10
- package/dist/chunks/index-sx488hvs.js +0 -221
- package/dist/chunks/index-sx488hvs.js.map +0 -12
- package/dist/chunks/index-wss3gd3h.js +0 -319
- package/dist/chunks/index-wss3gd3h.js.map +0 -13
- package/dist/chunks/index-zcqxfwdq.js +0 -197
- package/dist/chunks/index-zcqxfwdq.js.map +0 -13
- package/dist/embed/index.js +0 -138
- package/dist/embed/index.js.map +0 -12
- package/dist/local.js +0 -432
- package/dist/local.js.map +0 -14
- 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 -2948
- package/dist/react/index.js.map +0 -26
- package/dist/react/ui/index.js +0 -3142
- package/dist/react/ui/index.js.map +0 -35
- package/dist/server.js +0 -301
- package/dist/server.js.map +0 -13
- 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/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 -133
- package/dist/types/react/content.d.ts +0 -36
- package/dist/types/react/date-formatting.d.ts +0 -12
- package/dist/types/react/embed/bridge.d.ts +0 -21
- package/dist/types/react/embed/index.d.ts +0 -7
- package/dist/types/react/hooks.d.ts +0 -75
- package/dist/types/react/index.d.ts +0 -75
- 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 -68
- 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 -11
- 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 -8
- package/dist/types/react/ui/ContentSkeleton.d.ts +0 -7
- package/dist/types/react/ui/DataApp.d.ts +0 -21
- 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 -34
- 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/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 -12
- package/dist/types/react/ui/MetricWidget.d.ts +0 -49
- 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 -15
- 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 -18
- 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 -34
- package/dist/types/react/ui/chart-date-axis.d.ts +0 -15
- package/dist/types/react/ui/chart-interaction.d.ts +0 -21
- package/dist/types/react/ui/chart-primitives.d.ts +0 -22
- package/dist/types/react/ui/chart-time.d.ts +0 -16
- 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 -47
- package/dist/types/react/ui/index.d.ts +0 -109
- 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/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 -16
- package/dist/types/react/view-controls.d.ts +0 -20
- package/dist/types/react/view-runtime.d.ts +0 -31
- package/dist/types/react/view.d.ts +0 -78
- package/dist/types/react/widgets.d.ts +0 -79
- 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/dist/server.js
DELETED
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// src/server/request-body.ts
|
|
3
|
-
class RequestBodyTooLargeError extends Error {
|
|
4
|
-
}
|
|
5
|
-
async function readRequestBody(request, maxBytes) {
|
|
6
|
-
const body = request.body;
|
|
7
|
-
if (!body)
|
|
8
|
-
return "";
|
|
9
|
-
const reader = body.getReader();
|
|
10
|
-
const chunks = [];
|
|
11
|
-
let size = 0;
|
|
12
|
-
let abort;
|
|
13
|
-
function cancelReader() {
|
|
14
|
-
reader.cancel().catch(() => {});
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
request.signal.throwIfAborted();
|
|
18
|
-
const cancelled = new Promise((_, reject) => {
|
|
19
|
-
function rejectAborted() {
|
|
20
|
-
reject(new Error("Request aborted."));
|
|
21
|
-
cancelReader();
|
|
22
|
-
}
|
|
23
|
-
abort = rejectAborted;
|
|
24
|
-
request.signal.addEventListener("abort", rejectAborted, { once: true });
|
|
25
|
-
if (request.signal.aborted)
|
|
26
|
-
rejectAborted();
|
|
27
|
-
});
|
|
28
|
-
while (true) {
|
|
29
|
-
const { done, value } = await Promise.race([reader.read(), cancelled]);
|
|
30
|
-
if (done)
|
|
31
|
-
break;
|
|
32
|
-
size += value.byteLength;
|
|
33
|
-
if (size > maxBytes) {
|
|
34
|
-
cancelReader();
|
|
35
|
-
throw new RequestBodyTooLargeError;
|
|
36
|
-
}
|
|
37
|
-
chunks.push(value);
|
|
38
|
-
}
|
|
39
|
-
const bytes = new Uint8Array(size);
|
|
40
|
-
let offset = 0;
|
|
41
|
-
for (const chunk of chunks) {
|
|
42
|
-
bytes.set(chunk, offset);
|
|
43
|
-
offset += chunk.byteLength;
|
|
44
|
-
}
|
|
45
|
-
return new TextDecoder().decode(bytes);
|
|
46
|
-
} finally {
|
|
47
|
-
if (abort)
|
|
48
|
-
request.signal.removeEventListener("abort", abort);
|
|
49
|
-
reader.releaseLock();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// src/core/contract.ts
|
|
54
|
-
import { parseDate, today } from "@internationalized/date";
|
|
55
|
-
var sourceErrorBrand = Symbol.for("@altertable/data-app/DataSourceError");
|
|
56
|
-
|
|
57
|
-
class DataSourceError extends Error {
|
|
58
|
-
reason;
|
|
59
|
-
status;
|
|
60
|
-
[sourceErrorBrand] = true;
|
|
61
|
-
queryName;
|
|
62
|
-
static [Symbol.hasInstance](value) {
|
|
63
|
-
return value instanceof Error && value[sourceErrorBrand] === true;
|
|
64
|
-
}
|
|
65
|
-
constructor(reason, status, options) {
|
|
66
|
-
super(`Data source ${reason}${status ? ` (${status})` : ""}.`, options);
|
|
67
|
-
this.reason = reason;
|
|
68
|
-
this.status = status;
|
|
69
|
-
this.name = "DataSourceError";
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// src/core/operation.ts
|
|
74
|
-
async function executeDataOperation(operation, value, {
|
|
75
|
-
operationName,
|
|
76
|
-
lakehouse,
|
|
77
|
-
signal: requestSignal,
|
|
78
|
-
requestId,
|
|
79
|
-
queryParams
|
|
80
|
-
}) {
|
|
81
|
-
requestSignal.throwIfAborted();
|
|
82
|
-
let input;
|
|
83
|
-
try {
|
|
84
|
-
input = operation.input(value);
|
|
85
|
-
} catch {
|
|
86
|
-
throw new OperationInputError;
|
|
87
|
-
}
|
|
88
|
-
const signal = AbortSignal.any([
|
|
89
|
-
requestSignal,
|
|
90
|
-
AbortSignal.timeout(operation.policy.maxDurationMs)
|
|
91
|
-
]);
|
|
92
|
-
const execution = createOperationLakehouse(operation, lakehouse, signal, operationName);
|
|
93
|
-
try {
|
|
94
|
-
const output = await runOperation(operation, input, {
|
|
95
|
-
lakehouse: execution.lakehouse,
|
|
96
|
-
signal,
|
|
97
|
-
queryParams
|
|
98
|
-
});
|
|
99
|
-
const body = {
|
|
100
|
-
data: output,
|
|
101
|
-
requestId,
|
|
102
|
-
queriedAt: new Date().toISOString(),
|
|
103
|
-
queryIds: execution.queryIds,
|
|
104
|
-
queries: execution.queries
|
|
105
|
-
};
|
|
106
|
-
const serializedBody = JSON.stringify(body);
|
|
107
|
-
const responseBytes = new TextEncoder().encode(serializedBody).byteLength;
|
|
108
|
-
if (responseBytes > (operation.policy.maxResponseBytes ?? 1e6))
|
|
109
|
-
throw new Error("Response exceeds byte limit.");
|
|
110
|
-
return { body, serializedBody };
|
|
111
|
-
} catch (error) {
|
|
112
|
-
if (signal.aborted && !(error instanceof DataSourceError))
|
|
113
|
-
throw new OperationTimeoutError;
|
|
114
|
-
throw error;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
function createOperationLakehouse(operation, source, signal, operationName) {
|
|
118
|
-
const queryIds = [];
|
|
119
|
-
const queries = [];
|
|
120
|
-
const lakehouse = {
|
|
121
|
-
async queryAll(statement, options) {
|
|
122
|
-
if (!Number.isInteger(options.limit) || options.limit < 1)
|
|
123
|
-
throw new Error("Query needs a positive row limit.");
|
|
124
|
-
if (operation.queryNames && !Object.values(operation.queryNames).includes(options.name ?? ""))
|
|
125
|
-
throw new Error(`Query name is not registered for operation ${operationName}.`);
|
|
126
|
-
const query = {
|
|
127
|
-
name: options.name ?? `Query ${queries.length + 1}`,
|
|
128
|
-
statement,
|
|
129
|
-
...options.params === undefined ? {} : { params: options.params }
|
|
130
|
-
};
|
|
131
|
-
queries.push(query);
|
|
132
|
-
const limit = Math.min(options.limit, operation.policy.maxQueryRows);
|
|
133
|
-
let result;
|
|
134
|
-
try {
|
|
135
|
-
result = await source.queryAll(statement, {
|
|
136
|
-
limit,
|
|
137
|
-
...options.params === undefined ? {} : { params: options.params },
|
|
138
|
-
signal: AbortSignal.any([signal, options.signal])
|
|
139
|
-
});
|
|
140
|
-
} catch (error) {
|
|
141
|
-
if (error instanceof DataSourceError)
|
|
142
|
-
error.queryName = query.name;
|
|
143
|
-
throw error;
|
|
144
|
-
}
|
|
145
|
-
if (result.rows.length > limit)
|
|
146
|
-
throw new Error("Result exceeds row limit.");
|
|
147
|
-
if (result.queryId) {
|
|
148
|
-
query.queryId = result.queryId;
|
|
149
|
-
queryIds.push(result.queryId);
|
|
150
|
-
}
|
|
151
|
-
return result;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
return { lakehouse, queries, queryIds };
|
|
155
|
-
}
|
|
156
|
-
async function runOperation(operation, input, { lakehouse, signal, queryParams }) {
|
|
157
|
-
let abort;
|
|
158
|
-
try {
|
|
159
|
-
signal.throwIfAborted();
|
|
160
|
-
const cancelled = new Promise((_, reject) => {
|
|
161
|
-
function rejectAborted() {
|
|
162
|
-
reject(new Error("Request aborted."));
|
|
163
|
-
}
|
|
164
|
-
abort = rejectAborted;
|
|
165
|
-
signal.addEventListener("abort", rejectAborted, { once: true });
|
|
166
|
-
if (signal.aborted)
|
|
167
|
-
rejectAborted();
|
|
168
|
-
});
|
|
169
|
-
return await Promise.race([
|
|
170
|
-
cancelled,
|
|
171
|
-
Promise.resolve().then(() => {
|
|
172
|
-
signal.throwIfAborted();
|
|
173
|
-
return operation.run({ lakehouse, signal, queryParams }, input);
|
|
174
|
-
})
|
|
175
|
-
]);
|
|
176
|
-
} finally {
|
|
177
|
-
if (abort)
|
|
178
|
-
signal.removeEventListener("abort", abort);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
class OperationTimeoutError extends Error {
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
class OperationInputError extends Error {
|
|
186
|
-
}
|
|
187
|
-
var sourceErrorMessages = {
|
|
188
|
-
unauthorized: "This app could not authenticate its data connection. Contact the app owner.",
|
|
189
|
-
forbidden: "This app cannot access the requested data. Contact the app owner.",
|
|
190
|
-
rate_limited: "The lakehouse is busy. Wait a moment and retry.",
|
|
191
|
-
query_rejected: "A lakehouse query was rejected. Check the app's data operation.",
|
|
192
|
-
unavailable: "The lakehouse is unavailable. Check the connection and retry."
|
|
193
|
-
};
|
|
194
|
-
function toDataOperationFailure(error, aborted = false) {
|
|
195
|
-
if (error instanceof OperationInputError)
|
|
196
|
-
return {
|
|
197
|
-
status: 400,
|
|
198
|
-
code: "invalid_input",
|
|
199
|
-
message: "Check this operation's inputs."
|
|
200
|
-
};
|
|
201
|
-
if (error instanceof DataSourceError)
|
|
202
|
-
return {
|
|
203
|
-
status: error.reason === "rate_limited" ? 429 : 502,
|
|
204
|
-
code: `source_${error.reason}`,
|
|
205
|
-
message: sourceErrorMessages[error.reason]
|
|
206
|
-
};
|
|
207
|
-
const timedOut = aborted || error instanceof OperationTimeoutError;
|
|
208
|
-
return {
|
|
209
|
-
status: timedOut ? 504 : 502,
|
|
210
|
-
code: timedOut ? "timeout" : "query_failed",
|
|
211
|
-
message: timedOut ? "The data request timed out." : "The data request failed."
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// src/server/handler.ts
|
|
216
|
-
function createDataHandler(operations, authorize) {
|
|
217
|
-
async function handleDataRequest(request) {
|
|
218
|
-
const requestId = crypto.randomUUID();
|
|
219
|
-
const url = new URL(request.url);
|
|
220
|
-
if (!url.pathname.startsWith("/api/data/"))
|
|
221
|
-
return new Response("Not found", { status: 404 });
|
|
222
|
-
const encodedName = url.pathname.slice("/api/data/".length);
|
|
223
|
-
if (!encodedName || encodedName.includes("/"))
|
|
224
|
-
return problem(404, "not_found", "Unknown data operation.", requestId);
|
|
225
|
-
let name;
|
|
226
|
-
try {
|
|
227
|
-
name = decodeURIComponent(encodedName);
|
|
228
|
-
} catch {
|
|
229
|
-
return problem(404, "not_found", "Unknown data operation.", requestId);
|
|
230
|
-
}
|
|
231
|
-
if (!Object.hasOwn(operations, name))
|
|
232
|
-
return problem(404, "not_found", "Unknown data operation.", requestId);
|
|
233
|
-
if (request.method !== "POST")
|
|
234
|
-
return problem(405, "method_not_allowed", "Use POST.", requestId);
|
|
235
|
-
if (request.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase() !== "application/json")
|
|
236
|
-
return problem(415, "unsupported_media_type", "Use application/json.", requestId);
|
|
237
|
-
const origin = request.headers.get("origin");
|
|
238
|
-
const fetchSite = request.headers.get("sec-fetch-site");
|
|
239
|
-
const fetchMode = request.headers.get("sec-fetch-mode");
|
|
240
|
-
if (origin !== null && origin !== url.origin || fetchSite !== null && fetchSite !== "same-origin" || fetchSite !== null && origin === null || fetchMode !== null && fetchMode !== "cors" && fetchMode !== "same-origin")
|
|
241
|
-
return problem(403, "cross_origin_request", "The data request must come from this app.", requestId);
|
|
242
|
-
let access;
|
|
243
|
-
try {
|
|
244
|
-
access = await authorize(request, name);
|
|
245
|
-
} catch {
|
|
246
|
-
return problem(403, "forbidden", "You cannot run this data operation.", requestId);
|
|
247
|
-
}
|
|
248
|
-
const operation = operations[name];
|
|
249
|
-
let input;
|
|
250
|
-
if (request.signal.aborted)
|
|
251
|
-
return problem(504, "timeout", "The data request timed out.", requestId);
|
|
252
|
-
try {
|
|
253
|
-
const body = await readRequestBody(request, MAX_INPUT_BYTES);
|
|
254
|
-
input = JSON.parse(body);
|
|
255
|
-
} catch (error) {
|
|
256
|
-
if (error instanceof RequestBodyTooLargeError)
|
|
257
|
-
return problem(413, "input_too_large", "Input is too large.", requestId);
|
|
258
|
-
return problem(400, "invalid_input", "Check this operation's inputs.", requestId);
|
|
259
|
-
}
|
|
260
|
-
const signal = request.signal;
|
|
261
|
-
try {
|
|
262
|
-
const { serializedBody } = await executeDataOperation(operation, input, {
|
|
263
|
-
lakehouse: access.lakehouse,
|
|
264
|
-
signal,
|
|
265
|
-
requestId,
|
|
266
|
-
operationName: name,
|
|
267
|
-
queryParams: access.queryParams
|
|
268
|
-
});
|
|
269
|
-
return new Response(serializedBody, {
|
|
270
|
-
headers: {
|
|
271
|
-
"cache-control": "no-store",
|
|
272
|
-
"content-type": "application/json"
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
} catch (error) {
|
|
276
|
-
let detail = error instanceof Error ? error.name : "unknown";
|
|
277
|
-
if (error instanceof DataSourceError) {
|
|
278
|
-
detail = error.reason;
|
|
279
|
-
if (error.status)
|
|
280
|
-
detail += ` (${error.status})`;
|
|
281
|
-
if (error.queryName)
|
|
282
|
-
detail += ` in ${error.queryName}`;
|
|
283
|
-
if (error.cause instanceof Error && error.cause.message)
|
|
284
|
-
detail += `: ${error.cause.message}`;
|
|
285
|
-
}
|
|
286
|
-
console.error(`Data operation ${name} failed (${requestId}): ${detail}`);
|
|
287
|
-
const failure = toDataOperationFailure(error, signal.aborted);
|
|
288
|
-
return problem(failure.status, failure.code, failure.message, requestId);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
return handleDataRequest;
|
|
292
|
-
}
|
|
293
|
-
function problem(status, code, message, requestId) {
|
|
294
|
-
return Response.json({ error: { code, message, requestId } }, { status, headers: { "cache-control": "no-store" } });
|
|
295
|
-
}
|
|
296
|
-
var MAX_INPUT_BYTES = 16384;
|
|
297
|
-
export {
|
|
298
|
-
createDataHandler
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
//# debugId=7A13BF5389E0F62064756E2164756E21
|
package/dist/server.js.map
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/server/request-body.ts", "../src/core/contract.ts", "../src/core/operation.ts", "../src/server/handler.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"export class RequestBodyTooLargeError extends Error {}\n\n/** Count encoded bytes before retaining chunks; cancellation also interrupts waiting reads. */\nexport async function readRequestBody(\n request: Request,\n maxBytes: number\n): Promise<string> {\n const body = request.body;\n if (!body) return '';\n const reader = body.getReader();\n const chunks: Uint8Array[] = [];\n let size = 0;\n let abort: (() => void) | undefined;\n\n function cancelReader() {\n // The source's cancel algorithm may never settle; the handler must still respond.\n void reader.cancel().catch(() => {});\n }\n\n try {\n request.signal.throwIfAborted();\n const cancelled = new Promise<never>((_, reject) => {\n function rejectAborted() {\n reject(new Error('Request aborted.'));\n cancelReader();\n }\n abort = rejectAborted;\n request.signal.addEventListener('abort', rejectAborted, { once: true });\n if (request.signal.aborted) rejectAborted();\n });\n while (true) {\n const { done, value } = await Promise.race([reader.read(), cancelled]);\n if (done) break;\n size += value.byteLength;\n if (size > maxBytes) {\n cancelReader();\n throw new RequestBodyTooLargeError();\n }\n chunks.push(value);\n }\n const bytes = new Uint8Array(size);\n let offset = 0;\n for (const chunk of chunks) {\n bytes.set(chunk, offset);\n offset += chunk.byteLength;\n }\n\n return new TextDecoder().decode(bytes);\n } finally {\n if (abort) request.signal.removeEventListener('abort', abort);\n reader.releaseLock();\n }\n}\n",
|
|
6
|
-
"/**\n * Shared operation contracts and input validation for browser and server.\n * @module @altertable/data-app/contract\n * @see https://github.com/altertable-ai/data-app/blob/main/docs/contract.md\n */\nimport { parseDate, today } from '@internationalized/date';\nimport { formatDateRange } from '@/src/core/format';\nimport { invariant } from '@/src/core/invariant';\nimport {\n snapshotQueries,\n resolveQueryParameters,\n type QueryDefinitions,\n type QueryParameters,\n type QueryParameterValue,\n} from '@/src/core/queries';\nexport type {\n QueryDefinitions,\n QueryParameters,\n QueryParameterValue,\n} from '@/src/core/queries';\nimport type { DateRange as DateRangeInput } from '@/src/core/date-range';\nimport type {\n QueryResult,\n DataOperation,\n OperationContext,\n} from '@/src/core/operation-types';\nexport type {\n QueryResult,\n DisclosedQuery,\n Lakehouse,\n OperationContext,\n DataOperation,\n DataOperations,\n} from '@/src/core/operation-types';\n\nexport function parseEmptyInput(value: unknown): Record<string, never> {\n invariant(\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n Object.keys(value).length === 0,\n 'This operation takes no inputs.'\n );\n\n return {};\n}\n\nexport function parseTrue(value: unknown): true {\n invariant(value === true, 'Expected a successful check.');\n\n return true;\n}\n\nexport type { DateRange as DateRangeInput } from '@/src/core/date-range';\nexport type DateRangeRequest = {\n range: DateRangeInput;\n comparison: DateRangeInput | null;\n};\n\n/** The immediately preceding, equally long set of calendar days. */\nexport function previousDateRange({\n start,\n end,\n}: DateRangeInput): DateRangeInput {\n const first = parseDate(start);\n const last = parseDate(end);\n const days =\n (last.toDate('UTC').getTime() - first.toDate('UTC').getTime()) /\n 86_400_000 +\n 1;\n invariant(days >= 1, 'Date range must start before it ends.');\n const previousEnd = first.subtract({ days: 1 });\n\n return {\n start: previousEnd.subtract({ days: days - 1 }).toString(),\n end: previousEnd.toString(),\n };\n}\n\nexport type ReportingPeriod =\n | { kind: 'rolling'; amount: number; unit: 'hour' | 'day'; end: string }\n | { kind: 'calendar'; start: string; end: string; timeZone: string };\n\nexport type DateRangeContractOptions = {\n minDate?: string;\n maxDate?: string | (() => string);\n maxRangeDays: number;\n timeZone: string;\n completeDays?: boolean;\n};\n\n/** One source policy for the server parser, URL variable, and displayed reporting period. */\nexport function defineDateRangeContract(options: DateRangeContractOptions) {\n invariant(\n Number.isInteger(options.maxRangeDays) && options.maxRangeDays > 0,\n 'Date range needs a positive maxRangeDays.'\n );\n if (options.minDate) parseDate(options.minDate);\n if (typeof options.maxDate === 'string') parseDate(options.maxDate);\n today(options.timeZone);\n\n function bounds() {\n const latest = today(options.timeZone).subtract({\n days: options.completeDays === false ? 0 : 1,\n });\n const sourceMax =\n typeof options.maxDate === 'function'\n ? options.maxDate()\n : options.maxDate;\n const maxDate =\n sourceMax && parseDate(sourceMax).compare(latest) < 0\n ? parseDate(sourceMax).toString()\n : latest.toString();\n\n return {\n minDate: options.minDate,\n maxDate,\n maxRangeDays: options.maxRangeDays,\n timeZone: options.timeZone,\n };\n }\n\n function period({ start, end }: DateRangeInput): ReportingPeriod {\n return {\n kind: 'calendar',\n start,\n end,\n timeZone: options.timeZone,\n };\n }\n\n function describeInput(input: DateRangeInput) {\n return `${formatDateRange(input)} ${options.timeZone}`;\n }\n\n function comparison(input: DateRangeInput): DateRangeInput | null {\n const previous = previousDateRange(input);\n\n return options.minDate && previous.start < options.minDate\n ? null\n : previous;\n }\n\n function request(value: unknown, compare = false): DateRangeRequest {\n const range = parseDateRangeInput(value, bounds());\n const previous = compare ? comparison(range) : null;\n invariant(\n !compare || previous,\n 'Comparison is outside available source coverage.'\n );\n\n return { range, comparison: previous };\n }\n\n function parseRequest(value: unknown): DateRangeRequest {\n invariant(value && typeof value === 'object', 'Choose a date range.');\n const input = value as Record<string, unknown>;\n const parsed = request(input.range, input.comparison != null);\n if (input.comparison != null) {\n const supplied = parseDateRangeInput(input.comparison, bounds());\n invariant(\n supplied.start === parsed.comparison?.start &&\n supplied.end === parsed.comparison?.end,\n 'Comparison must be the preceding equal-length range.'\n );\n }\n\n return parsed;\n }\n\n return {\n request,\n parseRequest,\n bounds,\n parse(value: unknown) {\n return parseDateRangeInput(value, bounds());\n },\n period,\n comparison,\n describeInput,\n view: { period, describeInput },\n };\n}\n\nexport type DateRangeContract = ReturnType<typeof defineDateRangeContract>;\n\n/** Validate calendar dates and a bounded inclusive range on the server. */\nexport function parseDateRangeInput(\n value: unknown,\n {\n minDate,\n maxDate,\n maxRangeDays,\n }: { minDate?: string; maxDate?: string; maxRangeDays: number }\n): DateRangeInput {\n invariant(\n value && typeof value === 'object' && !Array.isArray(value),\n 'Choose a date range.'\n );\n const { start, end } = value as Record<string, unknown>;\n\n function day(input: unknown): number {\n invariant(\n typeof input === 'string' && /^\\d{4}-\\d{2}-\\d{2}$/.test(input),\n 'Dates must be YYYY-MM-DD.'\n );\n const timestamp = Date.parse(`${input}T00:00:00Z`);\n invariant(\n Number.isFinite(timestamp) &&\n new Date(timestamp).toISOString().slice(0, 10) === input,\n 'Choose valid calendar dates.'\n );\n\n return timestamp;\n }\n const first = day(start);\n const last = day(end);\n invariant(\n Number.isInteger(maxRangeDays) && maxRangeDays > 0,\n 'Maximum range days must be positive.'\n );\n invariant(\n first <= last &&\n (last - first) / 86_400_000 < maxRangeDays &&\n (minDate === undefined || first >= day(minDate)) &&\n (maxDate === undefined || last <= day(maxDate)),\n `Choose up to ${maxRangeDays} days within the available range.`\n );\n\n return { start: start as string, end: end as string };\n}\n\n/** Accepts numeric strings from DuckDB; rejects negative, fractional, and unsafe integers. */\nexport function parseCount(value: unknown): number {\n const number =\n typeof value === 'number' || typeof value === 'string'\n ? Number(value)\n : NaN;\n invariant(\n Number.isSafeInteger(number) &&\n number >= 0 &&\n (typeof value !== 'string' || !!value.trim()),\n 'Invalid count in query result.'\n );\n\n return number;\n}\n\nexport function parseLabel(value: unknown, maxLength = 100): string {\n invariant(\n typeof value === 'string' && !!value && value.length <= maxLength,\n 'Invalid label in query result.'\n );\n\n return value;\n}\n\n/** Rejects missing or duplicate columns and rows whose width differs from the column list. */\nexport function rowsAsRecords(\n result: QueryResult,\n requiredColumns: readonly string[]\n): Record<string, unknown>[] {\n const names = result.columns.map(column => column.name);\n invariant(\n new Set(names).size === names.length &&\n requiredColumns.every(name => names.includes(name)),\n 'Query result columns do not match the expected shape.'\n );\n\n return result.rows.map(row => {\n invariant(\n row.length === names.length,\n 'Query result row has the wrong width.'\n );\n\n return Object.fromEntries(names.map((name, index) => [name, row[index]]));\n });\n}\n\nexport function defineQueryNames<const Names extends Record<string, string>>(\n names: Names\n): Names {\n const values = Object.values(names);\n invariant(\n values.every(name => !!name.trim()) &&\n new Set(values).size === values.length,\n 'Query names must be nonempty and unique.'\n );\n\n return names;\n}\n\nconst sourceErrorBrand = Symbol.for('@altertable/data-app/DataSourceError');\n\nexport class DataSourceError extends Error {\n readonly [sourceErrorBrand] = true;\n queryName?: string;\n\n static [Symbol.hasInstance](value: unknown): boolean {\n return (\n value instanceof Error &&\n (value as { [sourceErrorBrand]?: unknown })[sourceErrorBrand] === true\n );\n }\n\n constructor(\n public readonly reason:\n | 'unauthorized'\n | 'forbidden'\n | 'rate_limited'\n | 'query_rejected'\n | 'unavailable',\n public readonly status?: number,\n /** `cause` stays on the server or host for logs; responses carry only the reason. */\n options?: ErrorOptions\n ) {\n super(`Data source ${reason}${status ? ` (${status})` : ''}.`, options);\n this.name = 'DataSourceError';\n }\n}\n\ntype RegisteredQueryParameters<\n Queries extends QueryDefinitions,\n Name extends keyof Queries,\n> = keyof Queries[Name]['params'] extends never\n ? Record<string, never>\n : Partial<Record<keyof Queries[Name]['params'], QueryParameterValue>>;\n\nexport type RegisteredQuery<Queries extends QueryDefinitions> = <\n Name extends keyof Queries & string,\n const Params extends object = {},\n>(\n name: Name,\n params?: Params &\n NoInfer<RegisteredQueryParameters<Queries, Name>> &\n NoInfer<\n Record<Exclude<keyof Params, keyof Queries[Name]['params']>, never>\n > &\n NoInfer<Params extends (...args: never[]) => unknown ? never : object>,\n options?: { limit?: number }\n) => Promise<QueryResult>;\n\nexport function defineOperation<\n Input,\n Output,\n const Queries extends QueryDefinitions,\n>(\n operation: Omit<DataOperation<Input, Output>, 'run' | 'queryNames'> & {\n queries: Queries;\n run: (\n context: Pick<OperationContext, 'signal'> & {\n query: RegisteredQuery<NoInfer<Queries>>;\n },\n input: Input\n ) => Promise<Output>;\n }\n): Omit<DataOperation<Input, Output>, 'queryNames'> & {\n queryNames: { readonly [Name in keyof Queries & string]: Name };\n} {\n invariant(\n Array.isArray(operation.checks) &&\n operation.checks.length > 0 &&\n Number.isInteger(operation.policy.maxQueryRows) &&\n operation.policy.maxQueryRows > 0 &&\n Number.isInteger(operation.policy.maxDurationMs) &&\n operation.policy.maxDurationMs > 0 &&\n (operation.policy.maxResponseBytes === undefined ||\n (Number.isInteger(operation.policy.maxResponseBytes) &&\n operation.policy.maxResponseBytes > 0)),\n 'Each data operation needs check inputs and positive row and duration limits.'\n );\n const queries = snapshotQueries(operation.queries);\n const queryNames = Object.fromEntries(\n Object.keys(queries).map(name => [name, name])\n ) as { readonly [Name in keyof Queries & string]: Name };\n for (const input of operation.checks) operation.input(input);\n\n return {\n ...operation,\n queryNames,\n run(context, input) {\n function query(\n name: keyof Queries & string,\n values: Partial<QueryParameters> = {},\n options?: { limit?: number }\n ) {\n invariant(Object.hasOwn(queries, name), `Unknown query name: ${name}.`);\n const definition = queries[name]!;\n const params = resolveQueryParameters(\n definition.params,\n values,\n context.queryParams ?? {}\n );\n return context.lakehouse.queryAll(definition.statement, {\n name,\n params,\n limit: options?.limit ?? operation.policy.maxQueryRows,\n signal: context.signal,\n });\n }\n return operation.run({ signal: context.signal, query }, input);\n },\n };\n}\n\n/** A connectivity probe uses the app's registered connection query. */\nexport function connectionCheck<\n const Queries extends QueryDefinitions & {\n connection: QueryDefinitions[string];\n },\n>(queries: Queries) {\n return defineOperation({\n queries,\n input: parseEmptyInput,\n checks: [{}],\n policy: { maxQueryRows: 1, maxDurationMs: 15_000 },\n async run({ query }): Promise<true> {\n await query('connection');\n return true;\n },\n });\n}\n\nexport {\n dimensionFilter,\n parseDimensionSelection,\n parseFacetOptions,\n dimensionPredicate,\n} from '@/src/core/dimension';\nexport type {\n DimensionSelection,\n DimensionMember,\n DimensionOption,\n DimensionVariable,\n DimensionFilterOptions,\n} from '@/src/core/dimension';\n\nexport {\n createMessageRouter,\n defineMessageRoute,\n defineDataQueryRoute,\n MessageRoutingError,\n dataAppRoutes,\n navigationUpdateRoute,\n sqlQueryRoute,\n} from '@/src/core/messages';\nexport type {\n MessageContext,\n RoutedMessage,\n MessageDispatcher,\n MessageTransport,\n MessageRoute,\n MessageRoutes,\n MessageInput,\n MessageHandlers,\n MessageOutput,\n OperationContracts,\n DataQueryInput,\n DataQueryBody,\n DataQueryRoute,\n NavigationUpdate,\n SqlQueryInput,\n} from '@/src/core/messages';\nexport type { TransportResponse } from '@/src/core/bridge';\n\nexport {\n annotationDraftRoute,\n annotationModeRoute,\n annotationEditorStateRoute,\n annotationSendRoute,\n annotationUpdateRoute,\n parseDataAppAnnotationDraft,\n} from '@/src/core/annotations';\nexport type {\n DataAppAnnotationDraft,\n DataAppAnnotationPresentation,\n} from '@/src/core/annotations';\n\nexport {\n numberFilter,\n booleanFilter,\n parseNumberSelection,\n parseBooleanSelection,\n} from '@/src/core/filters';\nexport type {\n NumberSelection,\n NumberOperator,\n NumberFilter,\n BooleanSelection,\n BooleanFilter,\n} from '@/src/core/filters';\n",
|
|
7
|
-
"import { DataSourceError } from '@/src/core/contract';\nimport type {\n DataOperations,\n DisclosedQuery,\n Lakehouse,\n OperationContext,\n DataQueryBody,\n} from '@/src/core/operation-types';\n\ntype Operation = DataOperations[string];\ntype OperationExecutionOptions = {\n operationName: string;\n lakehouse: Lakehouse;\n signal: AbortSignal;\n requestId: string;\n queryParams?: OperationContext['queryParams'];\n};\n\n/** Shared operation execution. Adapters own authorization, delivery, and public errors. */\nexport async function executeDataOperation(\n operation: Operation,\n value: unknown,\n {\n operationName,\n lakehouse,\n signal: requestSignal,\n requestId,\n queryParams,\n }: OperationExecutionOptions\n) {\n requestSignal.throwIfAborted();\n let input: unknown;\n try {\n input = operation.input(value);\n } catch {\n throw new OperationInputError();\n }\n\n const signal = AbortSignal.any([\n requestSignal,\n AbortSignal.timeout(operation.policy.maxDurationMs),\n ]);\n const execution = createOperationLakehouse(\n operation,\n lakehouse,\n signal,\n operationName\n );\n try {\n const output = await runOperation(operation, input, {\n lakehouse: execution.lakehouse,\n signal,\n queryParams,\n });\n const body: DataQueryBody<unknown> = {\n data: output,\n requestId,\n queriedAt: new Date().toISOString(),\n queryIds: execution.queryIds,\n queries: execution.queries,\n };\n const serializedBody = JSON.stringify(body);\n const responseBytes = new TextEncoder().encode(serializedBody).byteLength;\n if (responseBytes > (operation.policy.maxResponseBytes ?? 1_000_000))\n throw new Error('Response exceeds byte limit.');\n\n return { body, serializedBody };\n } catch (error) {\n if (signal.aborted && !(error instanceof DataSourceError))\n throw new OperationTimeoutError();\n throw error;\n }\n}\n\n/** Query evidence follows statement invocation order; query IDs retain completion order. */\nfunction createOperationLakehouse(\n operation: Operation,\n source: Lakehouse,\n signal: AbortSignal,\n operationName: string\n) {\n const queryIds: string[] = [];\n const queries: DisclosedQuery[] = [];\n const lakehouse: Lakehouse = {\n async queryAll(statement, options) {\n if (!Number.isInteger(options.limit) || options.limit < 1)\n throw new Error('Query needs a positive row limit.');\n if (\n operation.queryNames &&\n !Object.values(operation.queryNames).includes(options.name ?? '')\n )\n throw new Error(\n `Query name is not registered for operation ${operationName}.`\n );\n const query: DisclosedQuery = {\n name: options.name ?? `Query ${queries.length + 1}`,\n statement,\n ...(options.params === undefined ? {} : { params: options.params }),\n };\n queries.push(query);\n const limit = Math.min(options.limit, operation.policy.maxQueryRows);\n let result;\n try {\n result = await source.queryAll(statement, {\n limit,\n ...(options.params === undefined ? {} : { params: options.params }),\n signal: AbortSignal.any([signal, options.signal]),\n });\n } catch (error) {\n if (error instanceof DataSourceError) error.queryName = query.name;\n throw error;\n }\n if (result.rows.length > limit)\n throw new Error('Result exceeds row limit.');\n if (result.queryId) {\n query.queryId = result.queryId;\n queryIds.push(result.queryId);\n }\n\n return result;\n },\n };\n\n return { lakehouse, queries, queryIds };\n}\n\n/** Settle cancellation even when operation code or its lakehouse ignores the signal. */\nasync function runOperation(\n operation: Operation,\n input: unknown,\n { lakehouse, signal, queryParams }: OperationContext\n) {\n let abort: (() => void) | undefined;\n try {\n signal.throwIfAborted();\n const cancelled = new Promise<never>((_, reject) => {\n function rejectAborted() {\n reject(new Error('Request aborted.'));\n }\n abort = rejectAborted;\n signal.addEventListener('abort', rejectAborted, { once: true });\n if (signal.aborted) rejectAborted();\n });\n\n return await Promise.race([\n cancelled,\n Promise.resolve().then(() => {\n signal.throwIfAborted();\n\n return operation.run(\n { lakehouse, signal, queryParams },\n input as never\n );\n }),\n ]);\n } finally {\n if (abort) signal.removeEventListener('abort', abort);\n }\n}\n\nclass OperationTimeoutError extends Error {}\n\nclass OperationInputError extends Error {}\n\nconst sourceErrorMessages = {\n unauthorized:\n 'This app could not authenticate its data connection. Contact the app owner.',\n forbidden:\n 'This app cannot access the requested data. Contact the app owner.',\n rate_limited: 'The lakehouse is busy. Wait a moment and retry.',\n query_rejected:\n \"A lakehouse query was rejected. Check the app's data operation.\",\n unavailable: 'The lakehouse is unavailable. Check the connection and retry.',\n};\n\nexport function toDataOperationFailure(error: unknown, aborted = false) {\n if (error instanceof OperationInputError)\n return {\n status: 400,\n code: 'invalid_input',\n message: \"Check this operation's inputs.\",\n };\n if (error instanceof DataSourceError)\n return {\n status: error.reason === 'rate_limited' ? 429 : 502,\n code: `source_${error.reason}`,\n message: sourceErrorMessages[error.reason],\n };\n const timedOut = aborted || error instanceof OperationTimeoutError;\n return {\n status: timedOut ? 504 : 502,\n code: timedOut ? 'timeout' : 'query_failed',\n message: timedOut\n ? 'The data request timed out.'\n : 'The data request failed.',\n };\n}\n",
|
|
8
|
-
"import {\n readRequestBody,\n RequestBodyTooLargeError,\n} from '@/src/server/request-body';\nimport {\n executeDataOperation,\n toDataOperationFailure,\n} from '@/src/core/operation';\nimport {\n DataSourceError,\n type DataOperations,\n type Lakehouse,\n type QueryParameters,\n} from '@/src/core/contract';\n\n/** Authorization result for one viewer request. A hosted adapter must scope its lakehouse client. */\nexport type RequestAccess = {\n lakehouse: Lakehouse;\n /** Trusted values shared across queries; each query uses only its declared keys. */\n queryParams?: QueryParameters;\n};\n\n/**\n * Execute named operations on the server. The app supplies operations and viewer authorization.\n * JSON, Origin, and Fetch Metadata checks reject cross-site browser POSTs; they do not\n * authenticate another local process. Query evidence accompanies every result.\n */\nexport function createDataHandler(\n operations: DataOperations,\n authorize: (request: Request, operation: string) => Promise<RequestAccess>\n) {\n async function handleDataRequest(request: Request): Promise<Response> {\n const requestId = crypto.randomUUID();\n const url = new URL(request.url);\n if (!url.pathname.startsWith('/api/data/'))\n return new Response('Not found', { status: 404 });\n const encodedName = url.pathname.slice('/api/data/'.length);\n if (!encodedName || encodedName.includes('/'))\n return problem(404, 'not_found', 'Unknown data operation.', requestId);\n let name: string;\n try {\n name = decodeURIComponent(encodedName);\n } catch {\n return problem(404, 'not_found', 'Unknown data operation.', requestId);\n }\n if (!Object.hasOwn(operations, name))\n return problem(404, 'not_found', 'Unknown data operation.', requestId);\n if (request.method !== 'POST')\n return problem(405, 'method_not_allowed', 'Use POST.', requestId);\n if (\n request.headers\n .get('content-type')\n ?.split(';')[0]\n ?.trim()\n .toLowerCase() !== 'application/json'\n )\n return problem(\n 415,\n 'unsupported_media_type',\n 'Use application/json.',\n requestId\n );\n const origin = request.headers.get('origin');\n const fetchSite = request.headers.get('sec-fetch-site');\n const fetchMode = request.headers.get('sec-fetch-mode');\n if (\n (origin !== null && origin !== url.origin) ||\n (fetchSite !== null && fetchSite !== 'same-origin') ||\n (fetchSite !== null && origin === null) ||\n (fetchMode !== null &&\n fetchMode !== 'cors' &&\n fetchMode !== 'same-origin')\n )\n return problem(\n 403,\n 'cross_origin_request',\n 'The data request must come from this app.',\n requestId\n );\n let access: RequestAccess;\n try {\n access = await authorize(request, name);\n } catch {\n return problem(\n 403,\n 'forbidden',\n 'You cannot run this data operation.',\n requestId\n );\n }\n const operation = operations[name]!;\n let input: unknown;\n if (request.signal.aborted)\n return problem(504, 'timeout', 'The data request timed out.', requestId);\n try {\n const body = await readRequestBody(request, MAX_INPUT_BYTES);\n input = JSON.parse(body);\n } catch (error) {\n if (error instanceof RequestBodyTooLargeError)\n return problem(\n 413,\n 'input_too_large',\n 'Input is too large.',\n requestId\n );\n\n return problem(\n 400,\n 'invalid_input',\n \"Check this operation's inputs.\",\n requestId\n );\n }\n const signal = request.signal;\n try {\n const { serializedBody } = await executeDataOperation(operation, input, {\n lakehouse: access.lakehouse,\n signal,\n requestId,\n operationName: name,\n queryParams: access.queryParams,\n });\n return new Response(serializedBody, {\n headers: {\n 'cache-control': 'no-store',\n 'content-type': 'application/json',\n },\n });\n } catch (error) {\n let detail = error instanceof Error ? error.name : 'unknown';\n if (error instanceof DataSourceError) {\n detail = error.reason;\n if (error.status) detail += ` (${error.status})`;\n if (error.queryName) detail += ` in ${error.queryName}`;\n if (error.cause instanceof Error && error.cause.message)\n detail += `: ${error.cause.message}`;\n }\n console.error(`Data operation ${name} failed (${requestId}): ${detail}`);\n const failure = toDataOperationFailure(error, signal.aborted);\n\n return problem(failure.status, failure.code, failure.message, requestId);\n }\n }\n\n return handleDataRequest;\n}\n\nfunction problem(\n status: number,\n code: string,\n message: string,\n requestId: string\n): Response {\n return Response.json(\n { error: { code, message, requestId } },\n { status, headers: { 'cache-control': 'no-store' } }\n );\n}\n\nconst MAX_INPUT_BYTES = 16_384;\n"
|
|
9
|
-
],
|
|
10
|
-
"mappings": ";;AAAO,MAAM,iCAAiC,MAAM;AAAC;AAGrD,eAAsB,eAAe,CACnC,SACA,UACiB;AAAA,EACjB,MAAM,OAAO,QAAQ;AAAA,EACrB,IAAI,CAAC;AAAA,IAAM,OAAO;AAAA,EAClB,MAAM,SAAS,KAAK,UAAU;AAAA,EAC9B,MAAM,SAAuB,CAAC;AAAA,EAC9B,IAAI,OAAO;AAAA,EACX,IAAI;AAAA,EAEJ,SAAS,YAAY,GAAG;AAAA,IAEjB,OAAO,OAAO,EAAE,MAAM,MAAM,EAAE;AAAA;AAAA,EAGrC,IAAI;AAAA,IACF,QAAQ,OAAO,eAAe;AAAA,IAC9B,MAAM,YAAY,IAAI,QAAe,CAAC,GAAG,WAAW;AAAA,MAClD,SAAS,aAAa,GAAG;AAAA,QACvB,OAAO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MACvE,MAAM,UAAU,uBAAuB,OAAO,OAAO,OAAO;AAAA,MAE5D,OAAO,QAAQ,QAAQ,QAAQ,QAAQ,MAAM,QAAQ,SAAS,SAAS;AAAA;AAAA;AAAA,EAI3E,OAAO;AAAA;AAGT,SAAS,OAAO,CACd,QACA,MACA,SACA,WACU;AAAA,EACV,OAAO,SAAS,KACd,EAAE,OAAO,EAAE,MAAM,SAAS,UAAU,EAAE,GACtC,EAAE,QAAQ,SAAS,EAAE,iBAAiB,WAAW,EAAE,CACrD;AAAA;AAGF,IAAM,kBAAkB;",
|
|
11
|
-
"debugId": "7A13BF5389E0F62064756E2164756E21",
|
|
12
|
-
"names": []
|
|
13
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* TypeScript port of d3-time 3.1.0 (ISC), https://github.com/d3/d3-time/tree/v3.1.0
|
|
3
|
-
* Numeric tick-step helpers adapted from d3-array 3.2.4 (ISC).
|
|
4
|
-
*
|
|
5
|
-
* Copyright 2010-2022 Mike Bostock (d3-time)
|
|
6
|
-
* Copyright 2010-2023 Mike Bostock (d3-array tick-step helpers)
|
|
7
|
-
*
|
|
8
|
-
* Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
9
|
-
* with or without fee is hereby granted, provided that the above copyright notice
|
|
10
|
-
* and this permission notice appear in all copies.
|
|
11
|
-
*
|
|
12
|
-
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
-
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
14
|
-
* FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
-
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
16
|
-
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
17
|
-
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
18
|
-
* THIS SOFTWARE.
|
|
19
|
-
*/
|
|
20
|
-
type DateValue = Date | number;
|
|
21
|
-
type DateMutation = (date: Date) => void;
|
|
22
|
-
type DateOffset = (date: Date, step: number) => void;
|
|
23
|
-
type DateCount = (start: Date, end: Date) => number;
|
|
24
|
-
export interface TimeInterval {
|
|
25
|
-
(date?: DateValue): Date;
|
|
26
|
-
floor(this: void, date: DateValue): Date;
|
|
27
|
-
ceil(this: void, date: DateValue): Date;
|
|
28
|
-
round(this: void, date: DateValue): Date;
|
|
29
|
-
offset(this: void, date: DateValue, step?: number): Date;
|
|
30
|
-
range(this: void, start: DateValue, stop: DateValue, step?: number): Date[];
|
|
31
|
-
filter(this: void, test: (date: Date) => boolean): TimeInterval;
|
|
32
|
-
}
|
|
33
|
-
export interface CountableTimeInterval extends TimeInterval {
|
|
34
|
-
count(this: void, start: DateValue, end: DateValue): number;
|
|
35
|
-
every(this: void, step: number): TimeInterval | null;
|
|
36
|
-
}
|
|
37
|
-
export declare function timeInterval(floor: DateMutation, offset: DateOffset): TimeInterval;
|
|
38
|
-
export declare function timeInterval(floor: DateMutation, offset: DateOffset, count: DateCount, field?: (date: Date) => number): CountableTimeInterval;
|
|
39
|
-
declare const millisecond: CountableTimeInterval;
|
|
40
|
-
declare const milliseconds: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
41
|
-
declare const second: CountableTimeInterval;
|
|
42
|
-
declare const seconds: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
43
|
-
export declare const timeMinute: CountableTimeInterval;
|
|
44
|
-
export declare const timeMinutes: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
45
|
-
export declare const utcMinute: CountableTimeInterval;
|
|
46
|
-
export declare const utcMinutes: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
47
|
-
export declare const timeHour: CountableTimeInterval;
|
|
48
|
-
export declare const timeHours: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
49
|
-
export declare const utcHour: CountableTimeInterval;
|
|
50
|
-
export declare const utcHours: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
51
|
-
export declare const timeDay: CountableTimeInterval;
|
|
52
|
-
export declare const timeDays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
53
|
-
export declare const utcDay: CountableTimeInterval;
|
|
54
|
-
export declare const utcDays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
55
|
-
export declare const unixDay: CountableTimeInterval;
|
|
56
|
-
export declare const unixDays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
57
|
-
export declare const timeSunday: CountableTimeInterval;
|
|
58
|
-
export declare const timeMonday: CountableTimeInterval;
|
|
59
|
-
export declare const timeTuesday: CountableTimeInterval;
|
|
60
|
-
export declare const timeWednesday: CountableTimeInterval;
|
|
61
|
-
export declare const timeThursday: CountableTimeInterval;
|
|
62
|
-
export declare const timeFriday: CountableTimeInterval;
|
|
63
|
-
export declare const timeSaturday: CountableTimeInterval;
|
|
64
|
-
export declare const timeSundays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
65
|
-
export declare const timeMondays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
66
|
-
export declare const timeTuesdays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
67
|
-
export declare const timeWednesdays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
68
|
-
export declare const timeThursdays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
69
|
-
export declare const timeFridays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
70
|
-
export declare const timeSaturdays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
71
|
-
export declare const utcSunday: CountableTimeInterval;
|
|
72
|
-
export declare const utcMonday: CountableTimeInterval;
|
|
73
|
-
export declare const utcTuesday: CountableTimeInterval;
|
|
74
|
-
export declare const utcWednesday: CountableTimeInterval;
|
|
75
|
-
export declare const utcThursday: CountableTimeInterval;
|
|
76
|
-
export declare const utcFriday: CountableTimeInterval;
|
|
77
|
-
export declare const utcSaturday: CountableTimeInterval;
|
|
78
|
-
export declare const utcSundays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
79
|
-
export declare const utcMondays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
80
|
-
export declare const utcTuesdays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
81
|
-
export declare const utcWednesdays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
82
|
-
export declare const utcThursdays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
83
|
-
export declare const utcFridays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
84
|
-
export declare const utcSaturdays: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
85
|
-
export declare const timeMonth: CountableTimeInterval;
|
|
86
|
-
export declare const timeMonths: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
87
|
-
export declare const utcMonth: CountableTimeInterval;
|
|
88
|
-
export declare const utcMonths: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
89
|
-
export declare const timeYear: CountableTimeInterval;
|
|
90
|
-
export declare const timeYears: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
91
|
-
export declare const utcYear: CountableTimeInterval;
|
|
92
|
-
export declare const utcYears: (this: void, start: DateValue, stop: DateValue, step?: number) => Date[];
|
|
93
|
-
declare const utcTicks: (start: DateValue, stop: DateValue, count: number | TimeInterval) => Date[], utcTickInterval: (start: DateValue, stop: DateValue, count: number) => TimeInterval | null;
|
|
94
|
-
declare const timeTicks: (start: DateValue, stop: DateValue, count: number | TimeInterval) => Date[], timeTickInterval: (start: DateValue, stop: DateValue, count: number) => TimeInterval | null;
|
|
95
|
-
export { utcTicks, utcTickInterval, timeTicks, timeTickInterval };
|
|
96
|
-
export { millisecond as timeMillisecond, millisecond as utcMillisecond, milliseconds as timeMilliseconds, milliseconds as utcMilliseconds, second as timeSecond, second as utcSecond, seconds as timeSeconds, seconds as utcSeconds, timeSunday as timeWeek, timeSundays as timeWeeks, utcSunday as utcWeek, utcSundays as utcWeeks, };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type DataAppConnectionOptions } from './host.js';
|
|
2
|
-
import { type DataAppSourceOptions } from './source.js';
|
|
3
|
-
export type DataAppBridgeOptions = (DataAppSourceOptions & {
|
|
4
|
-
connection?: never;
|
|
5
|
-
window?: never;
|
|
6
|
-
javascript?: never;
|
|
7
|
-
}) | (DataAppConnectionOptions & {
|
|
8
|
-
source?: never;
|
|
9
|
-
startupTimeoutMs?: never;
|
|
10
|
-
});
|
|
11
|
-
/** Source mode configures and loads the iframe; connection mode attaches to a host-owned document. */
|
|
12
|
-
export declare function attachDataAppBridge(options: DataAppBridgeOptions): import("./host.js").DataAppHost;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { DataAppPresentation } from '../core/presentation.js';
|
|
2
|
-
import type { DataAppLogger } from '../core/logger.js';
|
|
3
|
-
import { type BridgeDiagnostic } from '../core/bridge.js';
|
|
4
|
-
import { type MessageDispatcher } from '../core/messages.js';
|
|
5
|
-
export type DataAppConnection = {
|
|
6
|
-
type: 'origin';
|
|
7
|
-
origin: string;
|
|
8
|
-
} | {
|
|
9
|
-
type: 'opaque';
|
|
10
|
-
token: string;
|
|
11
|
-
};
|
|
12
|
-
export type DataAppStatus = 'connecting' | 'connected' | 'ready' | 'failed' | 'disconnected';
|
|
13
|
-
/** Delivery metadata only; never tokens or payloads. `durationMs` measures host handling of a request, reported on its result or error. */
|
|
14
|
-
export type DataAppDiagnostic = BridgeDiagnostic & {
|
|
15
|
-
durationMs?: number;
|
|
16
|
-
};
|
|
17
|
-
export type DataAppHost = {
|
|
18
|
-
dispose: () => void;
|
|
19
|
-
setPresentation: (presentation?: DataAppPresentation) => void;
|
|
20
|
-
setLogger: (logger?: DataAppLogger) => void;
|
|
21
|
-
};
|
|
22
|
-
export type DataAppHostOptions = {
|
|
23
|
-
iframe: HTMLIFrameElement;
|
|
24
|
-
presentation?: DataAppPresentation;
|
|
25
|
-
logger?: DataAppLogger;
|
|
26
|
-
onStatusChange?: (status: DataAppStatus) => void;
|
|
27
|
-
onDiagnostic?: (event: DataAppDiagnostic) => void;
|
|
28
|
-
onMessage: MessageDispatcher;
|
|
29
|
-
};
|
|
30
|
-
export type DataAppConnectionOptions = DataAppHostOptions & {
|
|
31
|
-
connection: DataAppConnection;
|
|
32
|
-
javascript?: string;
|
|
33
|
-
window?: Window;
|
|
34
|
-
};
|
|
35
|
-
/** The bridge owns delivery and cancellation; the routed handler owns validation, authorization and execution. */
|
|
36
|
-
export declare function attachDataAppConnection({ iframe, connection, javascript, presentation, logger, onStatusChange, onDiagnostic, onMessage, window: host, }: DataAppConnectionOptions): DataAppHost;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Framework-neutral iframe hosting and sandboxed bundle initialization.
|
|
3
|
-
* @module @altertable/data-app/embed
|
|
4
|
-
* @see https://github.com/altertable-ai/data-app/blob/main/docs/embed.md
|
|
5
|
-
*/
|
|
6
|
-
export { attachDataAppBridge } from './bridge.js';
|
|
7
|
-
export type { DataAppBridgeOptions } from './bridge.js';
|
|
8
|
-
export type { DataAppHost, DataAppConnection, DataAppStatus, DataAppDiagnostic, } from './host.js';
|
|
9
|
-
export type { DataAppSource } from './source.js';
|
|
10
|
-
export { startDataAppBootstrap } from './bootstrap.js';
|
|
11
|
-
export { createNavigationHandler } from './navigation.js';
|
|
12
|
-
export { createSqlQueryHandler } from './sql.js';
|
|
13
|
-
export type { DataAppPresentation } from '../core/presentation.js';
|
|
14
|
-
export type { DataAppLogger } from '../core/logger.js';
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { NavigationUpdate } from '../core/messages.js';
|
|
2
|
-
/** Override this handler for framework routers. Reserved host parameters survive app navigation. */
|
|
3
|
-
export declare function createNavigationHandler({ window: host, reservedSearchParams, }?: {
|
|
4
|
-
window?: Window;
|
|
5
|
-
reservedSearchParams?: readonly string[];
|
|
6
|
-
}): (input: NavigationUpdate) => null;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type DataAppHost, type DataAppHostOptions } from './host.js';
|
|
2
|
-
export type DataAppSource = {
|
|
3
|
-
type: 'url';
|
|
4
|
-
url: string;
|
|
5
|
-
} | {
|
|
6
|
-
type: 'bundle';
|
|
7
|
-
/** Omit to use the packaged, network-isolated data document. */
|
|
8
|
-
bootstrapUrl?: string;
|
|
9
|
-
javascript: string;
|
|
10
|
-
};
|
|
11
|
-
export type DataAppSourceOptions = DataAppHostOptions & {
|
|
12
|
-
source: DataAppSource;
|
|
13
|
-
startupTimeoutMs?: number;
|
|
14
|
-
};
|
|
15
|
-
/** Owns loading and sandbox policy. Dispose before replacing the source or retrying. */
|
|
16
|
-
export declare function attachDataAppSource({ iframe, source, presentation, logger, onMessage, onStatusChange, onDiagnostic, startupTimeoutMs, }: DataAppSourceOptions): DataAppHost;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { Lakehouse } from '../core/contract.js';
|
|
2
|
-
import { type MessageContext, type SqlQueryInput } from '../core/messages.js';
|
|
3
|
-
/** Authorize every SQL request and supply a backend that independently enforces access and query limits. */
|
|
4
|
-
export declare function createSqlQueryHandler(authorize: (query: SqlQueryInput, context: MessageContext) => Promise<Lakehouse>): (input: SqlQueryInput, context: MessageContext) => Promise<import("../core/contract.js").QueryResult>;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { type Ref } from 'react';
|
|
2
|
-
import type { Theme } from '../../core/appearance.js';
|
|
3
|
-
import { type DataAppAnnotationDraft } from '../../core/annotations.js';
|
|
4
|
-
export type AnnotationBarHandle = {
|
|
5
|
-
/** Submit through the same guards, pending state, and retry feedback as the Send button. */
|
|
6
|
-
send: () => Promise<void>;
|
|
7
|
-
};
|
|
8
|
-
export type AnnotationBarProps = {
|
|
9
|
-
ref?: Ref<AnnotationBarHandle>;
|
|
10
|
-
annotations: readonly DataAppAnnotationDraft[];
|
|
11
|
-
active?: boolean;
|
|
12
|
-
theme?: Theme;
|
|
13
|
-
disabled?: boolean;
|
|
14
|
-
deletedAnnotationId?: string;
|
|
15
|
-
onUndoDelete?: (id: string) => void;
|
|
16
|
-
onDismissUndo?: () => void;
|
|
17
|
-
hasUnsavedChanges?: boolean;
|
|
18
|
-
pinsVisible: boolean;
|
|
19
|
-
onPinsVisibleChange: (visible: boolean) => void;
|
|
20
|
-
onSelect: (id: string) => void;
|
|
21
|
-
onDelete: (id: string) => void;
|
|
22
|
-
onClear: () => void;
|
|
23
|
-
/** Let host apps use their existing confirmation dialog. */
|
|
24
|
-
requestDiscard?: (discard: () => void) => void;
|
|
25
|
-
/** Resolve only after the outer application's agent API accepts this snapshot. */
|
|
26
|
-
onSend: (annotations: readonly DataAppAnnotationDraft[]) => Promise<void>;
|
|
27
|
-
onClose: () => void;
|
|
28
|
-
};
|
|
29
|
-
/** Host-owned batch controls. Collection changes and agent submission stay with the outer app. */
|
|
30
|
-
export declare function AnnotationBar({ ref, annotations, active, theme, disabled, deletedAnnotationId, onUndoDelete, onDismissUndo, hasUnsavedChanges, pinsVisible, onPinsVisibleChange, onSelect, onDelete, onClear, requestDiscard, onSend, onClose, }: AnnotationBarProps): import("react").JSX.Element | null;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type ComponentRef, type RefObject } from 'react';
|
|
2
|
-
import type { DataAppAnnotationPresentation } from '../../core/annotations.js';
|
|
3
|
-
type AnnotationControlsProps = {
|
|
4
|
-
rootRef: RefObject<ComponentRef<'div'> | null>;
|
|
5
|
-
presentation: DataAppAnnotationPresentation;
|
|
6
|
-
displayedInput?: unknown;
|
|
7
|
-
view?: string;
|
|
8
|
-
};
|
|
9
|
-
export declare function AnnotationControls({ rootRef, presentation, displayedInput, view, }: AnnotationControlsProps): import("react").JSX.Element;
|
|
10
|
-
export {};
|