@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
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { DatePresetId, DateRange } from '../../core/date-range.js';
|
|
2
|
-
import { type AppVariableValues, type DateRangeSelection, type DateRangeVariable, type HistoryMode, type VariableCollection } from '../../core/variables.js';
|
|
3
|
-
export { defineAppVariables, searchVariable, choiceVariable, multiChoiceVariable, dateRangeVariable, } from '../../core/variables.js';
|
|
4
|
-
export type { VariablePresentation, AppVariable, AppVariableValues, ChoiceOption, ChoiceVariable, MultiChoiceVariable, SearchVariable, DateRangeSelection, DateRangeVariable, DateRangeVariableOptions, VariableCollection, } from '../../core/variables.js';
|
|
5
|
-
/** Adapt one date variable to the controlled picker without giving the picker URL ownership. */
|
|
6
|
-
export declare function dateRangeControl(variable: DateRangeVariable, selection: DateRangeSelection, onChange: (selection: DateRangeSelection) => void): {
|
|
7
|
-
minDate?: string;
|
|
8
|
-
maxDate: string;
|
|
9
|
-
maxRangeDays: number;
|
|
10
|
-
timeZone: string;
|
|
11
|
-
value: DateRange;
|
|
12
|
-
label: string | undefined;
|
|
13
|
-
onChange(range: DateRange | null): void;
|
|
14
|
-
onPresetChange(id: DatePresetId): void;
|
|
15
|
-
selectedPresetId: DatePresetId | null;
|
|
16
|
-
onReset(): void;
|
|
17
|
-
isDefault: boolean;
|
|
18
|
-
resetValue: DateRange;
|
|
19
|
-
comparison?: {
|
|
20
|
-
enabled: boolean;
|
|
21
|
-
range: DateRange | null;
|
|
22
|
-
onChange(enabled: boolean): void;
|
|
23
|
-
} | undefined;
|
|
24
|
-
};
|
|
25
|
-
/** URL is the source of truth for app variables; one update can change dependent values atomically. */
|
|
26
|
-
export declare function useAppVariables<const Variables extends VariableCollection>(definitions: Variables): {
|
|
27
|
-
values: AppVariableValues<Variables>;
|
|
28
|
-
set: <Key extends keyof Variables & string>(name: Key, value: AppVariableValues<Variables>[Key]) => void;
|
|
29
|
-
reset: <Key extends keyof Variables & string>(name: Key) => void;
|
|
30
|
-
resetAll: () => void;
|
|
31
|
-
clearAll: () => void;
|
|
32
|
-
update: (next: Partial<AppVariableValues<Variables>>, history?: HistoryMode) => void;
|
|
33
|
-
bind: <Key extends keyof Variables & string>(name: Key) => {
|
|
34
|
-
value: AppVariableValues<Variables>[Key];
|
|
35
|
-
onChange(value: AppVariableValues<Variables>[Key]): void;
|
|
36
|
-
resetValue: AppVariableValues<Variables>[Key];
|
|
37
|
-
};
|
|
38
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type ReactNode } from 'react';
|
|
2
|
-
export type ActiveFilterControl = {
|
|
3
|
-
id: string;
|
|
4
|
-
label: string;
|
|
5
|
-
renderControl: (onDeactivate: () => void) => ReactNode;
|
|
6
|
-
onClear?: () => void;
|
|
7
|
-
};
|
|
8
|
-
export declare function ViewControlBar({ primaryFilters, activeSecondaryFilters, allFilters, activeFilterCount, displayOptions, changedDisplayOptionCount, onClear, }: {
|
|
9
|
-
primaryFilters: ReactNode[];
|
|
10
|
-
allFilters: ReactNode[];
|
|
11
|
-
activeSecondaryFilters: ActiveFilterControl[];
|
|
12
|
-
activeFilterCount: number;
|
|
13
|
-
displayOptions: ReactNode[];
|
|
14
|
-
changedDisplayOptionCount: number;
|
|
15
|
-
onClear?: () => void;
|
|
16
|
-
}): import("react").JSX.Element;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type ReactNode } from 'react';
|
|
2
|
-
import { type AppVariableValues, type VariableCollection } from './ui/variables.js';
|
|
3
|
-
import type { ResolvedVariables } from './view.js';
|
|
4
|
-
/** URL values resolve before facets; facet keys include their dependent inputs for cached, bounded loading. */
|
|
5
|
-
export declare function useViewVariables<Variables extends VariableCollection>(definitions: Variables, clientScope: string, loadFacet: (operation: string, input: unknown, signal: AbortSignal) => Promise<unknown>): {
|
|
6
|
-
values: AppVariableValues<Variables>;
|
|
7
|
-
set: <Key extends keyof Variables & string>(name: Key, value: AppVariableValues<Variables>[Key]) => void;
|
|
8
|
-
reset: <Key extends keyof Variables & string>(name: Key) => void;
|
|
9
|
-
resetAll: () => void;
|
|
10
|
-
clearAll: () => void;
|
|
11
|
-
update: (next: Partial<AppVariableValues<Variables>>, history?: import("../core/variables.js").HistoryMode) => void;
|
|
12
|
-
bind: <Key extends keyof Variables & string>(name: Key) => {
|
|
13
|
-
value: AppVariableValues<Variables>[Key];
|
|
14
|
-
onChange(value: AppVariableValues<Variables>[Key]): void;
|
|
15
|
-
resetValue: AppVariableValues<Variables>[Key];
|
|
16
|
-
};
|
|
17
|
-
resolved: ResolvedVariables<Variables>;
|
|
18
|
-
searchControls: ReactNode[] | null;
|
|
19
|
-
filterControls: import("react").JSX.Element | null;
|
|
20
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { DataContext } from './ui/data-context.js';
|
|
2
|
-
import type { ReactNode } from 'react';
|
|
3
|
-
import type { DataView, DisplayedSnapshot } from '../core/data-view.js';
|
|
4
|
-
import type { DisclosedQuery } from '../core/contract.js';
|
|
5
|
-
import type { EmptyContent } from './ui/presentation.js';
|
|
6
|
-
export type ViewResult<Data, Input> = {
|
|
7
|
-
dataContext: DataContext;
|
|
8
|
-
timeZone?: string;
|
|
9
|
-
view: DataView<Data, Input>;
|
|
10
|
-
snapshot?: DisplayedSnapshot<Data, Input>;
|
|
11
|
-
refetch: () => unknown;
|
|
12
|
-
cancel: () => unknown;
|
|
13
|
-
refreshing: boolean;
|
|
14
|
-
queries?: DisclosedQuery[];
|
|
15
|
-
searchControls?: ReactNode;
|
|
16
|
-
filterControls?: ReactNode;
|
|
17
|
-
emptyFallback: EmptyContent;
|
|
18
|
-
};
|
|
19
|
-
/** The executor is private; declarations expose data composition, not subscription hooks. */
|
|
20
|
-
export declare class DeclaredView<Data, Input, Definition = unknown> {
|
|
21
|
-
#private;
|
|
22
|
-
constructor(useResult: () => ViewResult<Data, Input>, definition?: Definition);
|
|
23
|
-
static definition<Data, Input, Definition>(view: DeclaredView<Data, Input, Definition>): Definition;
|
|
24
|
-
static useResult<Data, Input>(view: DeclaredView<Data, Input>): ViewResult<Data, Input>;
|
|
25
|
-
}
|
|
26
|
-
export declare function useDeclaredResult<Data, Input>(view: DeclaredView<Data, Input>): ViewResult<Data, Input>;
|
|
27
|
-
export declare const PrimaryViewContext: import("react").Context<{
|
|
28
|
-
declaration: object;
|
|
29
|
-
result: ViewResult<unknown, unknown>;
|
|
30
|
-
} | null>;
|
|
31
|
-
export declare function getViewDefinition<Data, Input, Definition>(view: DeclaredView<Data, Input, Definition>): Definition;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import type { DataContext } from './ui/data-context.js';
|
|
2
|
-
import type { EmptyContent } from './ui/presentation.js';
|
|
3
|
-
import type { AppVariableValues, DateRangeVariable, VariableCollection } from '../core/variables.js';
|
|
4
|
-
import type { DateRangeRequest } from '../core/contract.js';
|
|
5
|
-
export type ResolvedVariables<Variables extends VariableCollection> = {
|
|
6
|
-
[Key in keyof Variables]: Variables[Key] extends DateRangeVariable ? DateRangeRequest : AppVariableValues<Variables>[Key];
|
|
7
|
-
};
|
|
8
|
-
type DateVariableKey<Variables extends VariableCollection> = {
|
|
9
|
-
[Key in keyof Variables]: Variables[Key] extends DateRangeVariable ? Key : never;
|
|
10
|
-
}[keyof Variables] & string;
|
|
11
|
-
export type ViewDate<Variables extends VariableCollection, Input> = {
|
|
12
|
-
variable: DateVariableKey<Variables>;
|
|
13
|
-
/** Extract the selected range and comparison unchanged, including from nested inputs. */
|
|
14
|
-
input: (input: Input) => DateRangeRequest;
|
|
15
|
-
};
|
|
16
|
-
/** Read variable values from a custom operation input; omitted keys use top-level fields. */
|
|
17
|
-
export type ViewBindings<Variables extends VariableCollection, Input> = Partial<{
|
|
18
|
-
[Key in keyof Variables]: (input: Input) => ResolvedVariables<Variables>[Key];
|
|
19
|
-
}>;
|
|
20
|
-
type RequiredFilterBindingKeys<Variables extends VariableCollection, Input> = {
|
|
21
|
-
[Key in keyof Variables]: Extract<Variables[Key]['kind'], 'dimension' | 'numberFilter' | 'booleanFilter'> extends never ? never : [Input] extends [Record<Key, ResolvedVariables<Variables>[Key]>] ? [ResolvedVariables<Variables>[Key]] extends [Input[Key]] ? never : Key : Key;
|
|
22
|
-
}[keyof Variables];
|
|
23
|
-
/** Derive compatible top-level filter bindings; require readers for other input shapes. */
|
|
24
|
-
export type ViewBindingOptions<Variables extends VariableCollection, Input, AdditionalRequired extends keyof Variables = never> = [RequiredFilterBindingKeys<Variables, Input> | AdditionalRequired] extends [
|
|
25
|
-
never
|
|
26
|
-
] ? {
|
|
27
|
-
bindings?: ViewBindings<Variables, Input>;
|
|
28
|
-
} : {
|
|
29
|
-
bindings: ViewBindings<Variables, Input> & {
|
|
30
|
-
[Key in RequiredFilterBindingKeys<Variables, Input> | AdditionalRequired]-?: (input: Input) => ResolvedVariables<Variables>[Key];
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
type SameViewInput<Variables extends VariableCollection, Input> = [
|
|
34
|
-
ResolvedVariables<Variables>
|
|
35
|
-
] extends [Input] ? [Input] extends [ResolvedVariables<Variables>] ? [Input] extends [Record<string, never>] ? true : [keyof Input] extends [keyof Variables] ? true : false : false : false;
|
|
36
|
-
type ViewInputMapping<Variables extends VariableCollection, Input> = SameViewInput<Variables, Input> extends true ? {
|
|
37
|
-
input?: (values: ResolvedVariables<Variables>) => Input;
|
|
38
|
-
} : {
|
|
39
|
-
input: (values: ResolvedVariables<Variables>) => Input;
|
|
40
|
-
};
|
|
41
|
-
export type DataViewDefinition<Name extends string, Variables extends VariableCollection, Input, Data> = {
|
|
42
|
-
operation: Name;
|
|
43
|
-
dataContext: DataContext;
|
|
44
|
-
/** App-owned semantics: measured zero need not mean an empty result. */
|
|
45
|
-
isEmpty: (data: Data) => boolean;
|
|
46
|
-
/** Inherited by DataSection unless it supplies its own copy. */
|
|
47
|
-
emptyFallback: EmptyContent;
|
|
48
|
-
} & (keyof Variables extends never ? {
|
|
49
|
-
variables?: Variables;
|
|
50
|
-
} : {
|
|
51
|
-
variables: Variables;
|
|
52
|
-
}) & ViewInputMapping<NoInfer<Variables>, Input> & ViewBindingOptions<NoInfer<Variables>, Input> & ({
|
|
53
|
-
date: ViewDate<Variables, Input>;
|
|
54
|
-
describeInput?: (input: Input) => string;
|
|
55
|
-
} | {
|
|
56
|
-
date?: never;
|
|
57
|
-
describeInput: (input: Input) => string;
|
|
58
|
-
});
|
|
59
|
-
export type ResolvedDataViewDefinition<Name extends string, Variables extends VariableCollection, Input, Data> = Omit<DataViewDefinition<Name, Variables, Input, Data>, 'variables' | 'input'> & {
|
|
60
|
-
variables: Variables;
|
|
61
|
-
input: (values: ResolvedVariables<Variables>) => Input;
|
|
62
|
-
};
|
|
63
|
-
export declare function describeViewInput<Input>(definition: {
|
|
64
|
-
variables: VariableCollection;
|
|
65
|
-
bindings?: Partial<Record<string, (input: Input) => unknown>>;
|
|
66
|
-
date?: {
|
|
67
|
-
variable: string;
|
|
68
|
-
input: (input: Input) => DateRangeRequest;
|
|
69
|
-
};
|
|
70
|
-
describeInput?: (input: Input) => string;
|
|
71
|
-
}): (input: Input) => string;
|
|
72
|
-
export declare function resolveViewInput<Variables extends VariableCollection, Input>(definition: {
|
|
73
|
-
input: (values: ResolvedVariables<Variables>) => Input;
|
|
74
|
-
date?: ViewDate<Variables, Input>;
|
|
75
|
-
variables: Variables;
|
|
76
|
-
bindings?: ViewBindings<Variables, Input>;
|
|
77
|
-
}, values: ResolvedVariables<Variables>): Input;
|
|
78
|
-
export {};
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { type Dataset, type Metric, type ViewSource } from './bindings.js';
|
|
2
|
-
import { type MetricWidgetProps as DisplayMetricProps } from './ui/MetricWidget.js';
|
|
3
|
-
import { type TableWidgetProps as DisplayTableProps, type TableDisplayMode } from './ui/TableWidget.js';
|
|
4
|
-
import { type VisualizationWidgetProps as DisplayVisualProps, type VisualizationWidgetView as DisplayVisualizationView } from './ui/VisualizationWidget.js';
|
|
5
|
-
import { type TextWidgetProps as DisplayTextProps } from './ui/TextWidget.js';
|
|
6
|
-
import { type DataValueProps as DisplayValueProps } from './ui/DataValue.js';
|
|
7
|
-
import type { MetricValues } from '../core/reading.js';
|
|
8
|
-
import type { MetricDefinition } from './ui/metric.js';
|
|
9
|
-
import type { ReactNode } from 'react';
|
|
10
|
-
import type { DataReading } from '../core/reading.js';
|
|
11
|
-
export type MetricWidgetProps<Data = unknown, Input = unknown> = Omit<Extract<DisplayMetricProps, {
|
|
12
|
-
metric: MetricDefinition;
|
|
13
|
-
}>, 'metric' | 'reading'> & {
|
|
14
|
-
metric: Metric<Data, Input>;
|
|
15
|
-
source: ViewSource<Data, Input>;
|
|
16
|
-
};
|
|
17
|
-
export declare function MetricWidget<Data, Input>({ metric, source, ...presentation }: MetricWidgetProps<Data, Input>): import("react").JSX.Element;
|
|
18
|
-
type BoundTableProps<Row> = Extract<DisplayTableProps<Row>, {
|
|
19
|
-
reading: DataReading<readonly Row[]>;
|
|
20
|
-
}>;
|
|
21
|
-
type TablePresentation<Row> = Pick<BoundTableProps<Row>, 'title' | 'columns' | 'rowKey' | 'reading' | 'evidence' | 'emptyFallback'>;
|
|
22
|
-
export type TableWidgetProps<Row, Data = unknown, Input = unknown> = Omit<BoundTableProps<Row>, keyof TablePresentation<Row> | 'limit' | 'pagination'> & TableDisplayMode & {
|
|
23
|
-
dataset: Dataset<Data, Input, Row>;
|
|
24
|
-
source: ViewSource<Data, Input>;
|
|
25
|
-
title?: ReactNode;
|
|
26
|
-
};
|
|
27
|
-
export declare function TableWidget<Row, Data, Input>({ dataset, source, title, ...presentation }: TableWidgetProps<Row, Data, Input>): import("react").JSX.Element;
|
|
28
|
-
type BoundVisual<Row> = Extract<DisplayVisualProps<readonly Row[]>, {
|
|
29
|
-
reading: DataReading<readonly Row[]>;
|
|
30
|
-
}>;
|
|
31
|
-
export type VisualizationWidgetView<Row> = DisplayVisualizationView<readonly Row[]>;
|
|
32
|
-
type VisualContent<Row> = {
|
|
33
|
-
children: (rows: readonly Row[]) => ReactNode;
|
|
34
|
-
views?: never;
|
|
35
|
-
viewLabel?: never;
|
|
36
|
-
initialView?: never;
|
|
37
|
-
} | {
|
|
38
|
-
children?: never;
|
|
39
|
-
views: readonly VisualizationWidgetView<Row>[];
|
|
40
|
-
viewLabel: string;
|
|
41
|
-
initialView?: string;
|
|
42
|
-
};
|
|
43
|
-
export type VisualizationWidgetProps<Row, Data = unknown, Input = unknown> = Omit<BoundVisual<Row>, 'reading' | 'isEmpty' | 'emptyFallback' | 'evidence' | 'title' | 'children' | 'views' | 'viewLabel' | 'initialView'> & VisualContent<Row> & {
|
|
44
|
-
dataset: Dataset<Data, Input, Row>;
|
|
45
|
-
source: ViewSource<Data, Input>;
|
|
46
|
-
title?: ReactNode;
|
|
47
|
-
};
|
|
48
|
-
export declare function VisualizationWidget<Row, Data, Input>({ dataset, source, title, ...presentation }: VisualizationWidgetProps<Row, Data, Input>): import("react").JSX.Element;
|
|
49
|
-
type NarrativeBinding<Data, Input, Row> = {
|
|
50
|
-
metric: Metric<Data, Input>;
|
|
51
|
-
dataset?: never;
|
|
52
|
-
source: ViewSource<Data, Input>;
|
|
53
|
-
children?: (values: MetricValues) => ReactNode;
|
|
54
|
-
} | {
|
|
55
|
-
metric?: never;
|
|
56
|
-
dataset: Dataset<Data, Input, Row>;
|
|
57
|
-
source: ViewSource<Data, Input>;
|
|
58
|
-
children: (rows: readonly Row[]) => ReactNode;
|
|
59
|
-
};
|
|
60
|
-
export type TextWidgetProps<Data = unknown, Input = unknown, Row = never> = Omit<Extract<DisplayTextProps<unknown>, {
|
|
61
|
-
reading: DataReading<unknown>;
|
|
62
|
-
}>, 'reading' | 'evidence' | 'children' | 'title' | 'emptyFallback'> & NarrativeBinding<Data, Input, Row> & {
|
|
63
|
-
title?: ReactNode;
|
|
64
|
-
};
|
|
65
|
-
export declare function TextWidget<Data, Input, Row>(props: TextWidgetProps<Data, Input, Row>): import("react").JSX.Element;
|
|
66
|
-
type InlinePresentation = Omit<DisplayValueProps<unknown>, 'reading' | 'children' | 'loadingFallback'> & {
|
|
67
|
-
loadingFallback?: ReactNode;
|
|
68
|
-
};
|
|
69
|
-
export type DataValueProps<Data = unknown, Input = unknown, Row = never> = InlinePresentation & ((NarrativeBinding<Data, Input, Row> & {
|
|
70
|
-
scope?: never;
|
|
71
|
-
}) | {
|
|
72
|
-
metric?: never;
|
|
73
|
-
dataset?: never;
|
|
74
|
-
source?: never;
|
|
75
|
-
scope: DataReading<string>;
|
|
76
|
-
children?: (scope: string) => ReactNode;
|
|
77
|
-
});
|
|
78
|
-
export declare function DataValue<Data, Input, Row>(props: DataValueProps<Data, Input, Row>): import("react").JSX.Element;
|
|
79
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bun local-development serving and server-only lakehouse access.
|
|
3
|
-
* @module @altertable/data-app/server/bun
|
|
4
|
-
* @see https://github.com/altertable-ai/data-app/blob/main/docs/server-bun.md
|
|
5
|
-
*/
|
|
6
|
-
import { type Lakehouse } from '../core/contract.js';
|
|
7
|
-
import type { DataOperations } from '../core/contract.js';
|
|
8
|
-
/** Serve one app on localhost through the CLI's lakehouse proxy during development.
|
|
9
|
-
* Hosted servers must authorize every viewer and must use `createDataHandler` directly. */
|
|
10
|
-
export declare function serveLocalApp({ page, operations, title, port, }: {
|
|
11
|
-
page: Bun.HTMLBundle;
|
|
12
|
-
operations: DataOperations;
|
|
13
|
-
title: string;
|
|
14
|
-
port?: number;
|
|
15
|
-
}): Bun.Server<undefined>;
|
|
16
|
-
/** Throw an actionable startup error when the selected lakehouse credentials are missing. */
|
|
17
|
-
export declare function validateLakehouseCredentials(environment?: Record<string, string | undefined>): void;
|
|
18
|
-
/** Server-only SDK adapter. Local development uses the selected CLI profile's proxy. */
|
|
19
|
-
export declare function localLakehouse(environment?: Record<string, string | undefined>, request?: typeof fetch): Lakehouse;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type Lakehouse } from '../../core/contract.js';
|
|
2
|
-
export type AppFilePreviewOptions = {
|
|
3
|
-
/** Absolute path to the app source. */
|
|
4
|
-
file: string;
|
|
5
|
-
/** Localhost port. Use 0 to select an available port. Defaults to 25837. */
|
|
6
|
-
port?: number;
|
|
7
|
-
/** Server-only query backend; the caller owns credentials and profile selection. */
|
|
8
|
-
lakehouse: Lakehouse;
|
|
9
|
-
};
|
|
10
|
-
export type AppFilePreview = {
|
|
11
|
-
url: URL;
|
|
12
|
-
/** Stop serving, close reload connections, and release all file watchers. */
|
|
13
|
-
stop(): Promise<void>;
|
|
14
|
-
};
|
|
15
|
-
/** Preview a single-file app in the hosted sandbox. Requires the Bun runtime. */
|
|
16
|
-
export declare function serveAppFile({ file: appFile, port, lakehouse, }: AppFilePreviewOptions): Promise<AppFilePreview>;
|
package/dist/worker.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
// src/embed/runtime-html.ts
|
|
2
|
-
var PAGE_CSP = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data: blob:; connect-src 'none'; form-action 'none'; base-uri 'none'";
|
|
3
|
-
var inlineBootstrap = '(()=>{function D(){if(typeof crypto.randomUUID==="function")return crypto.randomUUID();let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=Array.from(e,(n)=>n.toString(16).padStart(2,"0"));return[t.slice(0,4),t.slice(4,6),t.slice(6,8),t.slice(8,10),t.slice(10)].map((n)=>n.join("")).join("-")}function Z(e){if(!e||typeof e!=="object")return!1;let t=e;return(t.method==="log"||t.method==="info"||t.method==="warn"||t.method==="error")&&Array.isArray(t.args)&&t.args.length<=128}var F="altertable:data-app";var Y=128,ee=60000;function P(e){return typeof e==="string"&&/^[a-zA-Z0-9_-]{1,128}$/.test(e)}function w({wire:e,from:t,session:n,parse:r}){return{wire:e,from:t,session:n,parse:r}}function L(e){if(!P(e.id))throw Error("Invalid request ID.");return e.id}function S(e,t){let n=e[t];if(typeof n!=="string")throw Error(`Invalid ${t}.`);return n}function j(){return{}}var h={channel:F,version:1,events:{connect:w({wire:"bridge:connect",from:"host",session:"none",parse:j}),ready:w({wire:"bridge:ready",from:"app",session:"none",parse:j}),initialize:w({wire:"bridge:initialize",from:"host",session:"establish",parse:(e)=>({state:e.state})}),request:w({wire:"bridge:request",from:"app",session:"current",parse:(e)=>{let t=S(e,"route");if(!t||t.length>256)throw Error("Invalid message route.");return{id:L(e),route:t,payload:e.payload}}}),result:w({wire:"bridge:result",from:"host",session:"current",parse:(e)=>{if(!Object.hasOwn(e,"response"))throw Error("Missing response.");return{id:L(e),response:e.response}}}),error:w({wire:"bridge:error",from:"host",session:"current",parse:(e)=>{if(e.requestId!==void 0&&typeof e.requestId!=="string")throw Error("Invalid requestId.");return{id:L(e),code:S(e,"code"),message:S(e,"message"),...e.requestId===void 0?{}:{requestId:e.requestId}}}}),cancel:w({wire:"bridge:cancel",from:"app",session:"current",parse:(e)=>({id:L(e)})}),disconnect:w({wire:"bridge:disconnect",from:"app",session:"current",parse:j}),scriptLoad:w({wire:"script:load",from:"host",session:"current",parse:(e)=>({javascript:S(e,"javascript")})}),stateUpdate:w({wire:"state:update",from:"host",session:"current",parse:(e)=>({state:e.state})}),runtimeLog:w({wire:"runtime:log",from:"app",session:"current",parse:(e)=>{if(!Z(e.payload))throw Error("Invalid log entry.");return{payload:e.payload}}}),runtimeReady:w({wire:"runtime:ready",from:"app",session:"current",parse:j}),runtimeError:w({wire:"runtime:error",from:"app",session:"current",parse:j})}};function W(e){let t={type:e.type};if("id"in e)t.id=e.id;if(e.type==="bridge:request"){t.route=e.route;let n=e.payload;if(e.route==="data:query"&&n&&typeof n==="object"&&"operation"in n&&typeof n.operation==="string")t.operation=n.operation.slice(0,256)}if(e.type==="bridge:error")t.error={code:e.code,message:e.message,...e.requestId===void 0?{}:{requestId:e.requestId}};return t}var C=new Map;for(let e of Object.keys(h.events)){let t=h.events[e].wire;if(C.has(t))throw Error(`Duplicate bridge event: ${t}`);C.set(t,e)}function z(e){return C.get(e)}function V(e){if(!e||typeof e!=="object")return;let t=e;if(t.channel!==F||t.version!==h.version||typeof t.type!=="string"||typeof t.documentId!=="string"||!t.documentId||t.documentId.length>128||t.sessionId!==void 0&&!P(t.sessionId)||t.token!==void 0&&typeof t.token!=="string")return;return t}function H(e,t){try{return{channel:F,version:h.version,documentId:e.documentId,...e.sessionId===void 0?{}:{sessionId:e.sessionId},...e.token===void 0?{}:{token:e.token},type:t.wire,...t.parse(e)}}catch{return}}function te(e){let t=V(e);if(!t)return;let n=z(t.type);if(!n)return;let r=h.events[n];if(r.session!=="none"&&t.sessionId===void 0)return;return H(t,r)}function ne({role:e,origin:t,source:n,opaque:r,context:o,post:a,diagnostic:l,invalidRequest:u,handlers:f}){let c=!1;function i(y,p){l?.({direction:"drop",reason:y,...typeof p==="string"?{type:p.slice(0,64)}:{}})}function v(y,p){if(c)throw Error("The bridge endpoint has closed.");let d=h.events[y],g=o(),x=te({...p,channel:h.channel,version:h.version,type:d.wire,documentId:y==="connect"?"host":g.documentId,sessionId:g.sessionId,token:r?g.token:void 0});if(!x||r&&!P(g.token))throw Error("The bridge is not ready to send this event.");if(l?.({direction:"send",...W(x)}),c)return;a(x)}function B(y){let p=n();if(c||!p||y.origin!==t||y.source!==p)return;let d=V(y.data);if(!d){let k=y.data;if(k&&typeof k==="object"&&"channel"in k&&k.channel===h.channel)i("invalid_envelope","type"in k?k.type:void 0);return}let g=o(),x=e==="app"&&d.type===h.events.connect.wire;if(r&&(x?!P(d.token):!g.token||d.token!==g.token))return i("token_mismatch",d.type);let M=z(d.type);if(!M)return i("unexpected_type",d.type);let T=h.events[M];if(T.from===e)return i("unexpected_type",d.type);if(T.session==="establish"){if(d.documentId!==g.documentId||d.sessionId===void 0)return i("session_mismatch",d.type)}else if(T.session==="current"){if(!g.sessionId||d.sessionId!==g.sessionId||d.documentId!==g.documentId)return i("session_mismatch",d.type)}let q=H(d,T);if(!q){if(i("invalid_payload",d.type),e==="host"&&M==="request"&&P(d.id))u?.(d.id);return}if(l?.({direction:"receive",...W(q)}),c)return;let Q=f[M];Q(q)}return{send:v,receive:B,dispose(){c=!0}}}function we(e){return e===null||typeof e==="string"||typeof e==="boolean"||typeof e==="number"&&Number.isFinite(e)}function G(e){return!!e&&typeof e==="object"&&!Array.isArray(e)&&Object.values(e).every(we)}var re=Symbol.for("@altertable/data-app/MessageRoutingError");class I extends Error{code;requestId;[re]=!0;static[Symbol.hasInstance](e){return e instanceof Error&&e[re]===!0}constructor(e,t,n,r){super(t,r);this.code=e;this.requestId=n;this.name="MessageRoutingError"}}function he(e){return e}function oe(e){return{operations:e,input(t){if(!t||typeof t!=="object")throw Error("Invalid query.");let n=t;if(typeof n.operation!=="string"||!n.operation||n.operation.length>256||n.operation.includes("/"))throw Error("Invalid operation.");let r=e&&Object.hasOwn(e,n.operation)?e[n.operation]:void 0;if(e&&!r)throw Error("Unknown operation.");return{operation:n.operation,input:r?r.input(n.input):n.input}},output(t){if(!t||typeof t!=="object")throw Error("Invalid data response.");let n=t;if(!Number.isInteger(n.status)||n.status<100||n.status>599||!n.body||typeof n.body!=="object"||Array.isArray(n.body))throw Error("Invalid data response.");let r=n.body;if(n.status<200||n.status>=300){let o=r.error;throw new I(typeof o?.code==="string"?o.code:"request_failed",typeof o?.message==="string"?o.message:"Could not load data.",typeof o?.requestId==="string"?o.requestId:void 0)}if(!("data"in r)||typeof r.requestId!=="string"||typeof r.queriedAt!=="string"||!Array.isArray(r.queryIds)||!r.queryIds.every((o)=>typeof o==="string"))throw Error("Invalid data envelope.");if(r.queries!==void 0&&(!Array.isArray(r.queries)||!r.queries.every((o)=>o&&typeof o==="object"&&typeof o.name==="string"&&typeof o.statement==="string"&&(o.params===void 0||G(o.params))&&(o.queryId===void 0||typeof o.queryId==="string"))))throw Error("Invalid query evidence.");return{status:n.status,body:r}}}}var se=he({input(e){if(!e||typeof e!=="object")throw Error("Invalid SQL query.");let t=e;if(typeof t.statement!=="string"||!t.statement.trim()||typeof t.limit!=="number"||!Number.isSafeInteger(t.limit)||t.limit<1||t.params!==void 0&&!G(t.params))throw Error("Invalid SQL query.");return{statement:t.statement,limit:t.limit,...t.params===void 0?{}:{params:t.params}}},output(e,t){if(!e||typeof e!=="object")throw Error("Invalid query result.");let n=e;if(!Array.isArray(n.columns)||!n.columns.every((r)=>r&&typeof r.name==="string"&&(r.type===void 0||typeof r.type==="string"))||!Array.isArray(n.rows)||n.rows.length>t.limit||!n.rows.every((r)=>Array.isArray(r)&&r.length===n.columns.length)||n.queryId!==void 0&&typeof n.queryId!=="string")throw Error("Invalid query result.");return{columns:n.columns,rows:n.rows,...n.queryId===void 0?{}:{queryId:n.queryId}}}});function ie(e,t){return{async request(n,r,{signal:o}={}){if(o?.throwIfAborted(),!Object.hasOwn(e,n))throw new I("unknown_route","Unknown message route.");let a=e[n],l;try{l=a.input(r)}catch{throw new I("invalid_payload","Invalid message payload.")}let u=await t({route:n,payload:l},o);o?.throwIfAborted();try{return a.output(u,l)}catch(f){if(f instanceof I)throw f;throw new I("invalid_response","Invalid message response.")}}}}var ae=Symbol.for("@altertable/data-app/DataAppError");class R extends Error{code;requestId;[ae]=!0;static[Symbol.hasInstance](e){return e instanceof Error&&e[ae]===!0}constructor(e,t,n){super(e);this.code=t;this.requestId=n;this.name="DataAppError"}}function de(e,t){function n(o){if(o.length===1&&typeof o[0]==="function"){let a=o[0]();return Array.isArray(a)?a:[a]}return o.map((a)=>typeof a==="function"?a():a)}function r(o,a){if(!e())return;try{t({method:o,args:n(a)})}catch{}}return{log:(...o)=>r("log",o),info:(...o)=>r("info",o),warn:(...o)=>r("warn",o),error:(...o)=>r("error",o)}}var ve={send:"Sending message to parent",receive:"Received message from parent",drop:"Ignored message from parent"};function ue(e,{direction:t,...n}){if(n.type==="runtime:log")return;e.log(ve[t],n)}function pe(e){if(e instanceof Error)return{name:e.name,message:e.message,...e.stack?{stack:e.stack}:{}};return{message:String(e)}}function ce(e){if(e instanceof I)throw new R(e.message,e.code,e.requestId);throw e}function le({parentOrigin:e,window:t=window,timeoutMs:n=ee,mode:r="url",loadScript:o}){if(new URL(e).origin!==e)throw Error("Expected an exact parent origin.");let a=D(),l,u,f=!1,c=new Map,i,v=new Set,B=de(()=>!f&&!!u&&!!i&&typeof i==="object"&&("logging"in i)&&i.logging===!0,(s)=>p("runtimeLog",{payload:s})),y=ne({role:"app",origin:e,source:()=>t.parent,opaque:r==="bundle",context:()=>({documentId:a,sessionId:u,token:l}),post(s){t.parent.postMessage(s,e)},diagnostic:(s)=>ue(B,s),handlers:{connect(s){if(r==="bundle")l=s.token;p("ready",{})},initialize(s){if(u&&u!==s.sessionId){if(c.size)B.warn("Preview reconnected; rejecting pending requests",{count:c.size});for(let E of c.values())E.reject(new R("The preview reconnected. Retry the request.","bridge_reset"))}let m=!u;if(u=s.sessionId,g(s.state),m)for(let E of c.values())E.start();if(f)return;if(r==="url")p("runtimeReady",{})},stateUpdate(s){g(s.state)},scriptLoad(s){if(r==="bundle")o?.(s.javascript)},result(s){c.get(s.id)?.resolve(s.response)},error(s){c.get(s.id)?.reject(new I(s.code,s.message,s.requestId))}}}),{send:p,receive:d}=y;function g(s){i=s;for(let m of v)m(s)}t.addEventListener("message",d);function x(s,m){return new Promise((E,b)=>{if(f)return b(new R("The preview has closed.","bridge_closed"));if(m?.aborted)return b(m.reason);if(c.size>=Y)return b(new R("Too many pending data requests.","bridge_busy"));let O=D(),A=!1;function N(){clearTimeout(me),m?.removeEventListener("abort",X),c.delete(O)}function X(){if(A)p("cancel",{id:O});N(),b(m?.reason)}let me=setTimeout(()=>{if(B.warn("Message request timed out",{id:O,route:s.route,timeoutMs:n,sent:A}),A)p("cancel",{id:O});N(),b(new R(u?"The data request timed out.":"The preview shell is unavailable. Reload the preview.",u?"timeout":"bridge_unavailable"))},n),J={start(){if(A)return;try{p("request",{id:O,route:s.route,payload:s.payload}),A=!0}catch{N(),b(new R("The message payload could not be sent.","invalid_payload"))}},resolve(U){N(),E(U)},reject(U){N(),b(U)}};if(c.set(O,J),m?.addEventListener("abort",X,{once:!0}),u)J.start();else if(r==="url"||l)p("ready",{})})}let M=ie({"data:query":oe(),"data:sql":se},x);function T(s,m,E){return M.request("data:query",{operation:s,input:m},{signal:E}).catch(ce)}function q(){if(u)p("disconnect",{});u=void 0;for(let s of c.values())s.reject(new R("The preview has closed.","bridge_closed"))}function Q(s){if(s.persisted&&(r==="url"||l))p("ready",{})}function k(){if(f)return;q(),f=!0,y.dispose(),t.removeEventListener("message",d),t.removeEventListener("pagehide",q),t.removeEventListener("pageshow",Q),v.clear()}if(t.addEventListener("pagehide",q),t.addEventListener("pageshow",Q),r==="url")p("ready",{});return{logger:B,request:x,transport:T,lakehouse:{queryAll(s,{limit:m,signal:E,params:b}){return M.request("data:sql",{statement:s,limit:m,...b===void 0?{}:{params:b}},{signal:E}).catch(ce)}},dispose:k,mode:r,snapshot(){return i},subscribe(s){return v.add(s),()=>{v.delete(s)}},ready(){if(!f&&u)p("runtimeReady",{})},fail(s){if(f||!u)return;if(s!==void 0)B.error(()=>["Data app failed",pe(s)]);p("runtimeError",{})}}}var K=Symbol.for("altertable.localFrameBridge"),_=Symbol.for("altertable.installedTransport");function fe(e,t=window){let n=t;if(n[_])throw Error("A data app transport is already installed.");return n[K]=e,n[_]=e,()=>{if(n[K]===e)delete n[K];if(n[_]===e)delete n[_];e.dispose()}}function ge({parentOrigin:e,window:t=window}){let n,r,o=`altertable-data-app-${D()}.js`,a=le({parentOrigin:e,window:t,mode:"bundle",loadScript(i){if(n!==void 0){if(i!==n)a.fail(Error("This frame already evaluated a different app script."));else if(r)a.fail(r.cause);else a.ready();return}n=i;try{let v=t.document.createElement("script");if(v.textContent=`${i}\n//# sourceURL=${o}`,t.document.body.append(v),!r)a.ready()}catch(v){l(v)}}});function l(i){r={cause:i},a.fail(i)}function u(i){if(i.filename===o)l(i.error??i.message)}function f(i){if(i.reason instanceof Error&&i.reason.stack?.includes(o))l(i.reason)}t.addEventListener("error",u),t.addEventListener("unhandledrejection",f);let c=fe(a,t);return()=>{t.removeEventListener("error",u),t.removeEventListener("unhandledrejection",f),c()}}var ye=document.currentScript?.dataset.parentOrigin;if(!ye)throw Error("Missing trusted parent origin.");ge({parentOrigin:ye});})();\n'.replace(/<\/script/gi, (match) => `<\\${match.slice(1)}`);
|
|
4
|
-
function runtimeHtml(parentOrigin) {
|
|
5
|
-
const attribute = parentOrigin.replaceAll("&", "&").replaceAll('"', """).replaceAll("<", "<").replaceAll(">", ">").replaceAll("'", "'");
|
|
6
|
-
return `<!doctype html>
|
|
7
|
-
<html>
|
|
8
|
-
<head>
|
|
9
|
-
<meta charset="utf-8">
|
|
10
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
11
|
-
<meta http-equiv="Content-Security-Policy" content="${PAGE_CSP}">
|
|
12
|
-
</head>
|
|
13
|
-
<body>
|
|
14
|
-
<div id="root"></div>
|
|
15
|
-
<script data-parent-origin="${attribute}">${inlineBootstrap}</script>
|
|
16
|
-
</body>
|
|
17
|
-
</html>
|
|
18
|
-
`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// src/worker/trusted-parent.ts
|
|
22
|
-
function exactOrigin(value) {
|
|
23
|
-
const url = new URL(value);
|
|
24
|
-
if (!/^https?:$/.test(url.protocol) || url.origin !== value) {
|
|
25
|
-
throw new Error("Expected an exact HTTP(S) parent origin.");
|
|
26
|
-
}
|
|
27
|
-
return url;
|
|
28
|
-
}
|
|
29
|
-
function trustedParent(config, searchParams) {
|
|
30
|
-
if (typeof config !== "string" || !config.trim()) {
|
|
31
|
-
throw new Error("Missing trusted parent origins.");
|
|
32
|
-
}
|
|
33
|
-
const allowed = config.trim().split(/\s+/).map((value) => {
|
|
34
|
-
const wildcard = value.startsWith("https://*.");
|
|
35
|
-
const url = exactOrigin(wildcard ? value.replace("*.", "") : value);
|
|
36
|
-
if (url.hostname.includes("*") || wildcard && url.port) {
|
|
37
|
-
throw new Error("Invalid parent origin pattern.");
|
|
38
|
-
}
|
|
39
|
-
return { value, url, wildcard };
|
|
40
|
-
});
|
|
41
|
-
const requested = searchParams.getAll("__altertable_parent");
|
|
42
|
-
if (!requested.length) {
|
|
43
|
-
const fallback = allowed.find((origin) => !origin.wildcard);
|
|
44
|
-
if (!fallback)
|
|
45
|
-
throw new Error("An exact default parent origin is required.");
|
|
46
|
-
return fallback.value;
|
|
47
|
-
}
|
|
48
|
-
if (requested.length !== 1)
|
|
49
|
-
return null;
|
|
50
|
-
let url;
|
|
51
|
-
try {
|
|
52
|
-
url = exactOrigin(requested[0]);
|
|
53
|
-
} catch {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
const permitted = allowed.some((origin) => {
|
|
57
|
-
if (!origin.wildcard)
|
|
58
|
-
return origin.value === requested[0];
|
|
59
|
-
if (url.protocol !== "https:" || url.port)
|
|
60
|
-
return false;
|
|
61
|
-
const suffix = `.${origin.url.hostname}`;
|
|
62
|
-
return url.hostname.endsWith(suffix) && /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(url.hostname.slice(0, -suffix.length));
|
|
63
|
-
});
|
|
64
|
-
return permitted ? requested[0] : null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// src/worker/index.ts
|
|
68
|
-
var TOKEN_RE = /^(?=.{1,63}$)[a-z0-9]+(?:-+[a-z0-9]+)+$/;
|
|
69
|
-
function isPreviewHost(hostname, domainName) {
|
|
70
|
-
const suffix = `.${domainName}`;
|
|
71
|
-
return hostname.endsWith(suffix) && TOKEN_RE.test(hostname.slice(0, -suffix.length));
|
|
72
|
-
}
|
|
73
|
-
var worker_default = {
|
|
74
|
-
runtimeHtml,
|
|
75
|
-
fetch(request, env) {
|
|
76
|
-
const url = new URL(request.url);
|
|
77
|
-
if (!isPreviewHost(url.hostname, env.DOMAIN_NAME) || url.pathname !== "/") {
|
|
78
|
-
return new Response(null, { status: 404 });
|
|
79
|
-
}
|
|
80
|
-
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
81
|
-
return new Response(null, {
|
|
82
|
-
status: 405,
|
|
83
|
-
headers: { Allow: "GET, HEAD" }
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
let parent;
|
|
87
|
-
try {
|
|
88
|
-
parent = trustedParent(env.PARENT_ORIGINS, url.searchParams);
|
|
89
|
-
} catch {
|
|
90
|
-
return new Response(null, { status: 503 });
|
|
91
|
-
}
|
|
92
|
-
if (!parent)
|
|
93
|
-
return new Response(null, { status: 403 });
|
|
94
|
-
return new Response(request.method === "HEAD" ? null : runtimeHtml(parent), {
|
|
95
|
-
headers: {
|
|
96
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
97
|
-
"Content-Security-Policy": `${PAGE_CSP}; frame-ancestors ${env.PARENT_ORIGINS.trim().split(/\s+/).join(" ")}`,
|
|
98
|
-
"X-Content-Type-Options": "nosniff",
|
|
99
|
-
"Referrer-Policy": "no-referrer"
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
export {
|
|
105
|
-
worker_default as default
|
|
106
|
-
};
|