@altertable/data-app 0.68.0 → 0.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/AGENTS.md +10 -0
  2. package/CONTRIBUTING.md +27 -1
  3. package/README.md +18 -21
  4. package/THIRD_PARTY_NOTICES +18 -0
  5. package/dist/chunks/index-22d576sn.js +153 -0
  6. package/dist/chunks/index-22d576sn.js.map +11 -0
  7. package/dist/chunks/index-2ajhmsc4.js +355 -0
  8. package/dist/chunks/index-2ajhmsc4.js.map +13 -0
  9. package/dist/chunks/{index-ktmvs916.js → index-58kks6a8.js} +37 -21
  10. package/dist/chunks/index-58kks6a8.js.map +13 -0
  11. package/dist/chunks/{index-23dktynd.js → index-7q99hf1z.js} +19 -12
  12. package/dist/chunks/index-7q99hf1z.js.map +10 -0
  13. package/dist/chunks/{index-mt93ff2b.js → index-9zqbrv2z.js} +7 -3
  14. package/dist/chunks/index-9zqbrv2z.js.map +10 -0
  15. package/dist/chunks/{index-m6n8ctfc.js → index-cv36cyna.js} +4 -4
  16. package/dist/chunks/index-cv36cyna.js.map +10 -0
  17. package/dist/chunks/{index-ag0cgnvq.js → index-q1w84fv9.js} +178 -31
  18. package/dist/chunks/index-q1w84fv9.js.map +15 -0
  19. package/dist/chunks/{index-qd5xgx6y.js → index-rew95tbg.js} +89 -21
  20. package/dist/chunks/index-rew95tbg.js.map +13 -0
  21. package/dist/chunks/{index-gvers8jw.js → index-vtpygsbq.js} +5651 -2711
  22. package/dist/chunks/index-vtpygsbq.js.map +126 -0
  23. package/dist/chunks/{index-x69p7cv7.js → index-wjt6cavj.js} +6 -4
  24. package/dist/chunks/index-wjt6cavj.js.map +10 -0
  25. package/dist/chunks/{index-f5cnbrjz.js → index-wss3gd3h.js} +39 -9
  26. package/dist/chunks/index-wss3gd3h.js.map +13 -0
  27. package/dist/chunks/{index-ev2b5aaf.js → index-xzb7sx6g.js} +4 -4
  28. package/dist/client/index.js +6 -6
  29. package/dist/core/appearance.js +1 -1
  30. package/dist/core/config.js +3 -3
  31. package/dist/core/contract.js +7 -7
  32. package/dist/core/contract.js.map +1 -1
  33. package/dist/core/format.js +10 -2
  34. package/dist/core/format.js.map +1 -1
  35. package/dist/embed/index.js +26 -25
  36. package/dist/embed/index.js.map +4 -4
  37. package/dist/index.js +3 -3
  38. package/dist/local.js +200 -145
  39. package/dist/local.js.map +10 -7
  40. package/dist/preview.js +1456 -0
  41. package/dist/preview.js.map +17 -0
  42. package/dist/react/embed/index.js +1 -1
  43. package/dist/react/index.js +500 -401
  44. package/dist/react/index.js.map +10 -13
  45. package/dist/react/ui/index.js +1851 -1476
  46. package/dist/react/ui/index.js.map +24 -21
  47. package/dist/server.js +102 -58
  48. package/dist/server.js.map +9 -6
  49. package/dist/types/client/data-client.d.ts +21 -10
  50. package/dist/types/client/download.d.ts +5 -0
  51. package/dist/types/client/iframe.d.ts +4 -2
  52. package/dist/types/client/logger.d.ts +10 -2
  53. package/dist/types/core/annotations.d.ts +5 -0
  54. package/dist/types/core/appearance.d.ts +2 -0
  55. package/dist/types/core/bridge-endpoint.d.ts +2 -2
  56. package/dist/types/core/bridge.d.ts +22 -0
  57. package/dist/types/core/config.d.ts +25 -17
  58. package/dist/types/core/contract.d.ts +26 -14
  59. package/dist/types/core/date-format.d.ts +24 -0
  60. package/dist/types/core/dimension-source.d.ts +64 -0
  61. package/dist/types/core/dimension.d.ts +33 -24
  62. package/dist/types/core/facets.d.ts +13 -0
  63. package/dist/types/core/filters.d.ts +4 -3
  64. package/dist/types/core/format.d.ts +5 -3
  65. package/dist/types/core/keys.d.ts +2 -0
  66. package/dist/types/core/messages.d.ts +3 -1
  67. package/dist/types/core/operation-types.d.ts +12 -11
  68. package/dist/types/core/queries.d.ts +75 -7
  69. package/dist/types/core/time-interval.d.ts +96 -0
  70. package/dist/types/core/variables.d.ts +49 -14
  71. package/dist/types/embed/host.d.ts +4 -4
  72. package/dist/types/embed/sql.d.ts +1 -1
  73. package/dist/types/index.d.ts +1 -1
  74. package/dist/types/react/actions.d.ts +53 -0
  75. package/dist/types/react/annotations/annotation-editor-state.d.ts +2 -0
  76. package/dist/types/react/annotations/annotation-targets.d.ts +1 -0
  77. package/dist/types/react/annotations/getAnnotationProps.d.ts +5 -3
  78. package/dist/types/react/annotations/useAnnotationGeometry.d.ts +2 -2
  79. package/dist/types/react/bindings.d.ts +62 -3
  80. package/dist/types/react/date-formatting.d.ts +12 -0
  81. package/dist/types/react/details.d.ts +46 -0
  82. package/dist/types/react/exploration.d.ts +44 -0
  83. package/dist/types/react/hooks.d.ts +82 -43
  84. package/dist/types/react/index.d.ts +10 -2
  85. package/dist/types/react/search-suggestions.d.ts +8 -0
  86. package/dist/types/react/style-contract.d.ts +1 -5
  87. package/dist/types/react/ui/AboutData.d.ts +9 -4
  88. package/dist/types/react/ui/AreaChart.d.ts +2 -2
  89. package/dist/types/react/ui/BarChart.d.ts +2 -2
  90. package/dist/types/react/ui/Button.d.ts +2 -1
  91. package/dist/types/react/ui/ChartLegend.d.ts +3 -2
  92. package/dist/types/react/ui/ChoicePicker.d.ts +2 -0
  93. package/dist/types/react/ui/ComposedChartLegend.d.ts +2 -1
  94. package/dist/types/react/ui/DataApp.d.ts +8 -4
  95. package/dist/types/react/ui/DataAppFrame.d.ts +14 -3
  96. package/dist/types/react/ui/DataTable.d.ts +6 -4
  97. package/dist/types/react/ui/DataWidget.d.ts +7 -0
  98. package/dist/types/react/ui/DateDisplay.d.ts +9 -0
  99. package/dist/types/react/ui/DateRangePicker.d.ts +3 -1
  100. package/dist/types/react/ui/DateTimeTooltip.d.ts +3 -2
  101. package/dist/types/react/ui/DimensionPicker.d.ts +5 -3
  102. package/dist/types/react/ui/EmptyState.d.ts +1 -1
  103. package/dist/types/react/ui/ExplorationActionControl.d.ts +60 -0
  104. package/dist/types/react/ui/GradientScroll.d.ts +8 -0
  105. package/dist/types/react/ui/Grid.d.ts +1 -1
  106. package/dist/types/react/ui/InspectionProvider.d.ts +2 -2
  107. package/dist/types/react/ui/LineChart.d.ts +2 -2
  108. package/dist/types/react/ui/Menu.d.ts +3 -2
  109. package/dist/types/react/ui/MetricWidget.d.ts +4 -0
  110. package/dist/types/react/ui/NumberFilterPicker.d.ts +3 -1
  111. package/dist/types/react/ui/PeriodSummary.d.ts +2 -1
  112. package/dist/types/react/ui/PickerField.d.ts +23 -0
  113. package/dist/types/react/ui/PieChart.d.ts +2 -2
  114. package/dist/types/react/ui/PopoverSurface.d.ts +5 -0
  115. package/dist/types/react/ui/RequestHint.d.ts +2 -2
  116. package/dist/types/react/ui/SearchField.d.ts +3 -1
  117. package/dist/types/react/ui/SearchTypeahead.d.ts +15 -0
  118. package/dist/types/react/ui/SectionHeading.d.ts +8 -0
  119. package/dist/types/react/ui/Select.d.ts +9 -1
  120. package/dist/types/react/ui/Sheet.d.ts +4 -2
  121. package/dist/types/react/ui/TableWidget.d.ts +8 -0
  122. package/dist/types/react/ui/Tabs.d.ts +4 -3
  123. package/dist/types/react/ui/TrendChart.d.ts +3 -3
  124. package/dist/types/react/ui/VariableBar.d.ts +1 -1
  125. package/dist/types/react/ui/VisualizationWidget.d.ts +1 -1
  126. package/dist/types/react/ui/chart-data.d.ts +8 -6
  127. package/dist/types/react/ui/chart-date-axis.d.ts +15 -0
  128. package/dist/types/react/ui/chart-interaction.d.ts +27 -0
  129. package/dist/types/react/ui/chart-primitives.d.ts +4 -4
  130. package/dist/types/react/ui/chart-time.d.ts +19 -0
  131. package/dist/types/react/ui/chartColor.d.ts +1 -1
  132. package/dist/types/react/ui/icons.d.ts +5 -1
  133. package/dist/types/react/ui/index.d.ts +10 -4
  134. package/dist/types/react/ui/metric-comparison.d.ts +2 -2
  135. package/dist/types/react/ui/metric.d.ts +2 -2
  136. package/dist/types/react/ui/presentation.d.ts +2 -0
  137. package/dist/types/react/ui/searchItems.d.ts +2 -0
  138. package/dist/types/react/ui/use-chart-scroll-to-end.d.ts +2 -0
  139. package/dist/types/react/ui/variables.d.ts +1 -1
  140. package/dist/types/react/view-control-bar.d.ts +18 -0
  141. package/dist/types/react/view-controls.d.ts +3 -2
  142. package/dist/types/react/view-runtime.d.ts +8 -3
  143. package/dist/types/react/view.d.ts +28 -7
  144. package/dist/types/react/widgets.d.ts +22 -11
  145. package/dist/types/server/local.d.ts +3 -1
  146. package/dist/types/server/preview/host.d.ts +1 -0
  147. package/dist/types/server/preview/index.d.ts +16 -0
  148. package/dist/types/server/reload-channel.d.ts +6 -0
  149. package/dist/types/server/request-body.d.ts +4 -0
  150. package/dist/worker.js +1 -1
  151. package/docs/app-authoring.md +27 -12
  152. package/docs/client.md +6 -7
  153. package/docs/composition.md +84 -0
  154. package/docs/contract.md +45 -26
  155. package/docs/data-context.md +2 -0
  156. package/docs/embed.md +11 -3
  157. package/docs/formatting-and-appearance.md +36 -5
  158. package/docs/layout.md +31 -8
  159. package/docs/react-embed.md +4 -4
  160. package/docs/react.md +1 -1
  161. package/docs/server-bun.md +25 -0
  162. package/docs/server.md +2 -2
  163. package/docs/styling.md +10 -27
  164. package/docs/ui.md +32 -18
  165. package/docs/variables.md +174 -25
  166. package/docs/views.md +60 -29
  167. package/docs/widgets.md +131 -26
  168. package/examples/starter-data-app/index.tsx +10 -23
  169. package/examples/starter-local-data-app/.bun-version +1 -0
  170. package/examples/starter-local-data-app/.node-version +1 -0
  171. package/examples/starter-local-data-app/.oxfmtrc.json +4 -0
  172. package/examples/starter-local-data-app/.oxlintrc.json +33 -0
  173. package/examples/starter-local-data-app/AGENTS.md +22 -0
  174. package/examples/starter-local-data-app/README.md +54 -0
  175. package/examples/starter-local-data-app/app.ts +28 -0
  176. package/examples/starter-local-data-app/bunfig.toml +2 -0
  177. package/examples/starter-local-data-app/package.json +33 -0
  178. package/examples/starter-local-data-app/src/App.tsx +8 -0
  179. package/examples/starter-local-data-app/src/assets.d.ts +1 -0
  180. package/examples/starter-local-data-app/src/data-context.ts +21 -0
  181. package/examples/starter-local-data-app/src/favicon.svg +13 -0
  182. package/examples/starter-local-data-app/src/index.html +14 -0
  183. package/examples/starter-local-data-app/src/main.tsx +7 -0
  184. package/examples/starter-local-data-app/src/operations.ts +6 -0
  185. package/examples/starter-local-data-app/src/server.ts +6 -0
  186. package/examples/starter-local-data-app/tsconfig.json +21 -0
  187. package/package.json +13 -3
  188. package/dist/chunks/index-23dktynd.js.map +0 -10
  189. package/dist/chunks/index-ag0cgnvq.js.map +0 -13
  190. package/dist/chunks/index-dq7b35fn.js +0 -307
  191. package/dist/chunks/index-dq7b35fn.js.map +0 -13
  192. package/dist/chunks/index-f5cnbrjz.js.map +0 -13
  193. package/dist/chunks/index-gvers8jw.js.map +0 -109
  194. package/dist/chunks/index-ktmvs916.js.map +0 -13
  195. package/dist/chunks/index-m6n8ctfc.js.map +0 -10
  196. package/dist/chunks/index-mev09s5v.js +0 -77
  197. package/dist/chunks/index-mev09s5v.js.map +0 -10
  198. package/dist/chunks/index-mt93ff2b.js.map +0 -10
  199. package/dist/chunks/index-qd5xgx6y.js.map +0 -13
  200. package/dist/chunks/index-x69p7cv7.js.map +0 -10
  201. package/dist/types/react/shellStyles.d.ts +0 -3
  202. package/dist/types/react/ui/DataAppSkeleton.d.ts +0 -7
  203. /package/dist/chunks/{index-ev2b5aaf.js.map → index-xzb7sx6g.js.map} +0 -0
@@ -1,11 +1,12 @@
1
+ import { type DimensionSourceConfig, type DimensionSourceQueryName, type SourceDimensionVariable } from './dimension-source.js';
1
2
  /**
2
3
  * App configuration shared by browser and server.
3
4
  * @module @altertable/data-app
4
5
  */
5
- import { defineOperation } from './contract.js';
6
+ import { defineOperation, type OperationDefinition } from './contract.js';
6
7
  import type { AppearanceOptions } from './appearance.js';
7
- import { type QueryDefinitions } from './queries.js';
8
- export type { QueryDefinitions, QueryParameterValue } from './queries.js';
8
+ import { type QueryDefinitions, type CheckedQueries, type QuerySnapshot } from './queries.js';
9
+ export type { QueryDefinitions, QueryParameterValue, QueryParameter, QueryValueType, QueryField, QueryProjections, QueryRow, } from './queries.js';
9
10
  export type DataAppConfig<Queries extends QueryDefinitions = QueryDefinitions> = {
10
11
  title: string;
11
12
  /** Display labels; scope does not grant data access. */
@@ -17,21 +18,26 @@ export type DataAppConfig<Queries extends QueryDefinitions = QueryDefinitions> =
17
18
  description: string;
18
19
  /** Omit to use the standard appearance. */
19
20
  appearance?: AppearanceOptions;
20
- /** Named SQL statements and parameter defaults used by app operations. */
21
- queries: Queries;
22
- };
23
- type ImmutableQueries<Queries extends QueryDefinitions> = {
24
- readonly [Name in keyof Queries]: {
25
- readonly statement: Queries[Name]['statement'];
26
- readonly params: {
27
- readonly [Param in keyof Queries[Name]['params']]: Readonly<Queries[Name]['params'][Param]>;
28
- };
21
+ /** Shared date display defaults. Reporting views and individual fields may override the time zone. */
22
+ dateFormatting?: {
23
+ locale?: string;
24
+ timeZone?: string;
29
25
  };
26
+ /** Named SQL statements with typed parameters and result projections. */
27
+ queries: Queries;
30
28
  };
31
29
  /** An app declaration with operations bound to its query registry. */
32
30
  export type DataAppDefinition<Queries extends QueryDefinitions = QueryDefinitions> = Readonly<Omit<DataAppConfig<Queries>, 'queries'>> & {
33
- readonly queries: ImmutableQueries<Queries>;
34
- defineOperation<Input, Output>(operation: Omit<Parameters<typeof defineOperation<Input, Output, Queries>>[0], 'queries'>): ReturnType<typeof defineOperation<Input, Output, Queries>>;
31
+ readonly queries: QuerySnapshot<Queries>;
32
+ defineDimension<const Type extends 'string' | 'number'>(config: DimensionSourceConfig<Type> & {
33
+ source: {
34
+ query: DimensionSourceQueryName<Queries, NoInfer<Type>>;
35
+ };
36
+ }): SourceDimensionVariable<{
37
+ string: string;
38
+ number: number;
39
+ }[Type]>;
40
+ defineOperation<Input, Output>(operation: OperationDefinition<Input, Output, Queries>): ReturnType<typeof defineOperation<Input, Output, Queries>>;
35
41
  };
36
42
  /**
37
43
  * Define the app's query source of truth while preserving exact query and parameter names.
@@ -51,9 +57,11 @@ export type DataAppDefinition<Queries extends QueryDefinitions = QueryDefinition
51
57
  * TypeScript checks the shape, not AST syntax. Keep executable composition outside the call.
52
58
  *
53
59
  * SQL passes unchanged to the backend, which interprets placeholders such as `$orgId`.
54
- * Declare every parameter with `{ defaultValue: value }` or `{}` for a required value.
60
+ * Declare each parameter's type and optional defaultValue.
55
61
  * Values are finite numbers, strings, booleans, or null, never SQL fragments or identifiers.
56
- * Caller values override defaults; trusted server `queryParams` cannot be overridden.
62
+ * Host queryParams supply protected values; callers cannot override them.
57
63
  */
58
- export declare function defineDataApp<const Queries extends QueryDefinitions>(config: DataAppConfig<Queries>): DataAppDefinition<Queries>;
64
+ export declare function defineDataApp<const Queries extends QueryDefinitions>(config: DataAppConfig<Queries> & {
65
+ queries: CheckedQueries<Queries>;
66
+ }): DataAppDefinition<Queries>;
59
67
  export declare function dataAppTitle(config: Pick<DataAppConfig, 'title' | 'scope'>): string;
@@ -1,5 +1,5 @@
1
- import { type QueryDefinitions, type QueryParameterValue } from './queries.js';
2
- export type { QueryDefinitions, QueryParameters, QueryParameterValue, } from './queries.js';
1
+ import { type QueryDefinitions, type CheckedQueries, type QueryInputParameters, type QueryRow, type IsUnion } from './queries.js';
2
+ export type { QueryDefinitions, QueryParameters, QueryParameterValue, QueryParameter, QueryValueType, QueryField, QueryProjections, QueryRow, } from './queries.js';
3
3
  import type { DateRange as DateRangeInput } from './date-range.js';
4
4
  import type { QueryResult, DataOperation, OperationContext } from './operation-types.js';
5
5
  export type { QueryResult, DisclosedQuery, Lakehouse, OperationContext, DataOperation, DataOperations, } from './operation-types.js';
@@ -59,8 +59,6 @@ export declare function parseDateRangeInput(value: unknown, { minDate, maxDate,
59
59
  /** Accepts numeric strings from DuckDB; rejects negative, fractional, and unsafe integers. */
60
60
  export declare function parseCount(value: unknown): number;
61
61
  export declare function parseLabel(value: unknown, maxLength?: number): string;
62
- /** Rejects missing or duplicate columns and rows whose width differs from the column list. */
63
- export declare function rowsAsRecords(result: QueryResult, requiredColumns: readonly string[]): Record<string, unknown>[];
64
62
  export declare function defineQueryNames<const Names extends Record<string, string>>(names: Names): Names;
65
63
  declare const sourceErrorBrand: unique symbol;
66
64
  export declare class DataSourceError extends Error {
@@ -69,28 +67,41 @@ export declare class DataSourceError extends Error {
69
67
  readonly [sourceErrorBrand] = true;
70
68
  queryName?: string;
71
69
  static [Symbol.hasInstance](value: unknown): boolean;
72
- constructor(reason: 'unauthorized' | 'forbidden' | 'rate_limited' | 'query_rejected' | 'unavailable', status?: number | undefined);
70
+ constructor(reason: 'unauthorized' | 'forbidden' | 'rate_limited' | 'query_rejected' | 'unavailable', status?: number | undefined,
71
+ /** `cause` stays on the server or host for logs; responses carry only the reason. */
72
+ options?: ErrorOptions);
73
73
  }
74
- type RegisteredQueryParameters<Queries extends QueryDefinitions, Name extends keyof Queries> = keyof Queries[Name]['params'] extends never ? Record<string, never> : Partial<Record<keyof Queries[Name]['params'], QueryParameterValue>>;
75
- export type RegisteredQuery<Queries extends QueryDefinitions> = <Name extends keyof Queries & string, const Params extends object = {}>(name: Name, params?: Params & NoInfer<RegisteredQueryParameters<Queries, Name>> & NoInfer<Record<Exclude<keyof Params, keyof Queries[Name]['params']>, never>> & NoInfer<Params extends (...args: never[]) => unknown ? never : object>, options?: {
76
- limit?: number;
77
- }) => Promise<QueryResult>;
78
- export declare function defineOperation<Input, Output, const Queries extends QueryDefinitions>(operation: Omit<DataOperation<Input, Output>, 'run' | 'queryNames'> & {
79
- queries: Queries;
74
+ type RegisteredQueryParameters<Queries extends QueryDefinitions, Name extends keyof Queries> = QueryInputParameters<Queries[Name]['params']>;
75
+ type ExactQueryParameters<Expected, Params extends object> = Params & Expected & Record<Exclude<keyof Params, keyof Expected>, never> & (Params extends (...args: never[]) => unknown ? never : object);
76
+ type ParameterNames<Queries extends QueryDefinitions, Name extends keyof Queries> = Name extends keyof Queries ? keyof RegisteredQueryParameters<Queries, Name> : never;
77
+ /** Dynamic limits are checked at execution; known limits must be positive integers. */
78
+ type QueryLimit<Limit extends number> = number extends Limit ? number : `${Limit}` extends '0' | `-${string}` ? never : `${Limit}` extends `${bigint}` ? Limit : never;
79
+ export type RegisteredQuery<Queries extends QueryDefinitions> = <Name extends keyof Queries & string, const Params extends object = {}, const Limit extends number = number>(name: Name & (true extends IsUnion<NoInfer<Name>> ? [ParameterNames<Queries, Name>] extends [never] ? unknown : never : unknown), params?: ExactQueryParameters<RegisteredQueryParameters<Queries, NoInfer<Name>>, Params>, options?: {
80
+ limit?: Limit & QueryLimit<NoInfer<Limit>>;
81
+ }) => Promise<QueryResult<QueryRow<Queries[Name]['projections']>>>;
82
+ /** Infer operation data from run(). */
83
+ export type OperationDefinition<Input, Output, Queries extends QueryDefinitions> = Omit<DataOperation<Input, Output>, 'run' | 'queryNames'> & {
80
84
  run: (context: Pick<OperationContext, 'signal'> & {
81
85
  query: RegisteredQuery<NoInfer<Queries>>;
82
86
  }, input: Input) => Promise<Output>;
87
+ };
88
+ export declare function defineOperation<Input, Output, const Queries extends QueryDefinitions>(operation: OperationDefinition<Input, Output, Queries> & {
89
+ queries: CheckedQueries<Queries>;
83
90
  }): Omit<DataOperation<Input, Output>, 'queryNames'> & {
84
91
  queryNames: {
85
92
  readonly [Name in keyof Queries & string]: Name;
86
93
  };
87
94
  };
95
+ /** The built-in connection operation shares one contract with setup clients. */
96
+ export type ConnectionOperation = Omit<DataOperation<Record<string, never>, true>, 'queryNames'> & {
97
+ queryNames: {
98
+ readonly connection: 'connection';
99
+ };
100
+ };
88
101
  /** A connectivity probe uses the app's registered connection query. */
89
102
  export declare function connectionCheck<const Queries extends QueryDefinitions & {
90
103
  connection: QueryDefinitions[string];
91
- }>(queries: Queries): Omit<DataOperation<Record<string, never>, true>, "queryNames"> & {
92
- queryNames: { readonly [Name in keyof Queries & string]: Name; };
93
- };
104
+ }>(queries: CheckedQueries<Queries>): ConnectionOperation;
94
105
  export { dimensionFilter, parseDimensionSelection, parseFacetOptions, dimensionPredicate, } from './dimension.js';
95
106
  export type { DimensionSelection, DimensionMember, DimensionOption, DimensionVariable, DimensionFilterOptions, } from './dimension.js';
96
107
  export { createMessageRouter, defineMessageRoute, defineDataQueryRoute, MessageRoutingError, dataAppRoutes, navigationUpdateRoute, sqlQueryRoute, } from './messages.js';
@@ -100,3 +111,4 @@ export { annotationDraftRoute, annotationModeRoute, annotationEditorStateRoute,
100
111
  export type { DataAppAnnotationDraft, DataAppAnnotationPresentation, } from './annotations.js';
101
112
  export { numberFilter, booleanFilter, parseNumberSelection, parseBooleanSelection, } from './filters.js';
102
113
  export type { NumberSelection, NumberOperator, NumberFilter, BooleanSelection, BooleanFilter, } from './filters.js';
114
+ export { variableInput } from './dimension-source.js';
@@ -0,0 +1,24 @@
1
+ /** Formatting for calendar dates and instants without implicit time-zone parsing. */
2
+ export type DateFormatOptions = {
3
+ locale?: string;
4
+ missing?: string;
5
+ };
6
+ export type DateTimeFormatOptions = DateFormatOptions & {
7
+ timeZone?: string;
8
+ precision?: 'minute' | 'second';
9
+ };
10
+ export type DateFormat = ({
11
+ kind: 'date';
12
+ } & DateFormatOptions) | ({
13
+ kind: 'dateTime';
14
+ } & DateTimeFormatOptions);
15
+ type DateTimeValue = string | Date | number | null | undefined;
16
+ /** Format an ISO calendar date as a date, never as a browser-local instant. */
17
+ export declare function formatDate(value: string | null | undefined, options?: DateFormatOptions): string;
18
+ /** Parse only unambiguous instants. String values must include `Z` or an explicit offset. */
19
+ export declare function parseDateTime(value: DateTimeValue): Date | null;
20
+ /** Format an instant in an explicit reporting zone. Defaults use UTC and 24-hour minutes. */
21
+ export declare function formatDateTime(value: DateTimeValue, options?: DateTimeFormatOptions): string;
22
+ /** Format an instant's time for intraday chart axes using the same zone and precision policy. */
23
+ export declare function formatTime(value: DateTimeValue, options?: DateTimeFormatOptions): string;
24
+ export {};
@@ -0,0 +1,64 @@
1
+ import { type DimensionSettings, type DimensionSelectionVariable, type DimensionValue } from './dimension.js';
2
+ import type { AppVariableValues, VariableCollection } from './variables.js';
3
+ import { type QueryDefinitions, type QueryParameters } from './queries.js';
4
+ import type { DataOperation, DataOperations, QueryResult } from './operation-types.js';
5
+ export declare const dimensionSource: unique symbol;
6
+ export type SourceDimensionVariable<Value extends DimensionValue> = DimensionSelectionVariable<Value> & {
7
+ readonly optionsSource: 'query';
8
+ readonly [dimensionSource]: {
9
+ readonly operation: string;
10
+ };
11
+ };
12
+ declare const invalidMemberKey: unique symbol;
13
+ export declare class DimensionMembershipError extends Error {
14
+ readonly [invalidMemberKey] = true;
15
+ static [Symbol.hasInstance](value: unknown): boolean;
16
+ }
17
+ /** Validate named variable values at the operation boundary. Date inputs belong to the base parser. */
18
+ export declare function variableInput<Input extends object, const Variables extends VariableCollection>(parse: (value: unknown) => Input, variables: Variables & {
19
+ [Key in keyof Variables]: Variables[Key] extends {
20
+ kind: 'dateRange';
21
+ } ? never : Variables[Key];
22
+ }): (value: unknown) => Input & AppVariableValues<Variables>;
23
+ export type DimensionSourceConfig<Type extends 'string' | 'number'> = DimensionSettings & {
24
+ allowMissing?: false;
25
+ valueType: Type;
26
+ source: {
27
+ query: string;
28
+ };
29
+ };
30
+ export type DimensionSourceQueryName<Queries extends QueryDefinitions, Type extends 'string' | 'number'> = {
31
+ [Name in keyof Queries & string]: Queries[Name] extends {
32
+ params: {
33
+ member: {
34
+ type: Type;
35
+ nullable: true;
36
+ };
37
+ };
38
+ projections: {
39
+ value: {
40
+ type: Type;
41
+ nullable?: false;
42
+ };
43
+ label: {
44
+ type: 'string';
45
+ nullable?: false;
46
+ };
47
+ };
48
+ } ? 'count' extends keyof Queries[Name]['projections'] ? Queries[Name]['projections']['count'] extends {
49
+ type: 'number';
50
+ nullable?: false;
51
+ } ? Name : never : Name : never;
52
+ }[keyof Queries & string];
53
+ /** A query supplies independent options and exact member lookup; it declares a nullable `member` parameter. */
54
+ export declare function bindDimensionSource<const Type extends 'string' | 'number'>(config: DimensionSourceConfig<Type>, queries: QueryDefinitions): SourceDimensionVariable<{
55
+ string: string;
56
+ number: number;
57
+ }[Type]>;
58
+ type Query = (name: string, params: QueryParameters, options: {
59
+ limit: number;
60
+ }) => Promise<QueryResult<Record<string, unknown>>>;
61
+ export declare function validateVariableInput(parser: Function, input: unknown, query: Query): Promise<void>;
62
+ export declare function attachDimensionSelectors(operation: DataOperation<any, any>, queries: QueryDefinitions): void;
63
+ export declare function withDimensionSelectors<Operations extends DataOperations>(operations: Operations): Operations;
64
+ export {};
@@ -1,4 +1,5 @@
1
- import type { AppVariable, HistoryMode } from './variables.js';
1
+ import { facetSource } from './facets.js';
2
+ import type { AppVariable, HistoryMode, VariablePresentation } from './variables.js';
2
3
  export type DimensionValue = string | number;
3
4
  export type DimensionMember<T extends DimensionValue = DimensionValue> = {
4
5
  kind: 'value';
@@ -17,46 +18,54 @@ export type DimensionOption<T extends DimensionValue = DimensionValue> = {
17
18
  label: string;
18
19
  count?: number;
19
20
  };
20
- export type DimensionVariable<T extends DimensionValue = DimensionValue> = AppVariable<DimensionSelection<T>, 'dimension'> & {
21
+ export type DimensionSelectionVariable<T extends DimensionValue = DimensionValue> = AppVariable<DimensionSelection<T>, 'dimension'> & {
22
+ readonly optionsSource: 'fixed' | 'query';
21
23
  label: string;
22
24
  selectionMode: 'single' | 'multiple';
23
- valueType: 'string' | 'number';
25
+ readonly valueType: T extends number ? 'number' : 'string';
24
26
  allowMissing: boolean;
25
27
  allowExclusion: boolean;
26
28
  maxSelected: number;
27
29
  options: readonly DimensionOption<T>[];
28
- facet?: {
29
- operation: string;
30
- input: (values: Record<string, unknown>) => unknown;
31
- };
32
- describe: (selection: DimensionSelection<T>) => string;
30
+ describe: (selection: DimensionSelection<T>, options?: readonly DimensionOption<T>[]) => string;
31
+ };
32
+ /** A fixed-option dimension retains its distinction from query-backed facets. */
33
+ export type DimensionVariable<T extends DimensionValue = DimensionValue> = DimensionSelectionVariable<T> & {
34
+ readonly optionsSource: 'fixed';
35
+ readonly [facetSource]?: never;
33
36
  };
34
37
  export declare function dimensionMemberKey(member: DimensionMember): string;
35
- export type DimensionFilterOptions<T extends DimensionValue> = {
38
+ export type DimensionSettings = {
36
39
  key: string;
37
40
  label: string;
38
- valueType: T extends number ? 'number' : 'string';
39
- selectionMode: 'single' | 'multiple';
40
41
  allowMissing?: boolean;
41
42
  allowExclusion?: boolean;
42
- maxSelected?: number;
43
43
  history?: HistoryMode;
44
+ presentation?: VariablePresentation;
44
45
  } & ({
45
- options: readonly DimensionOption<T>[];
46
- facet?: never;
46
+ selectionMode: 'single';
47
+ maxSelected?: 1;
47
48
  } | {
48
- /** A bounded operation supplies options and counts; input chooses other filters affecting counts. */
49
- facet: {
50
- operation: string;
51
- input: (values: Record<string, unknown>) => unknown;
52
- };
53
- options?: never;
49
+ selectionMode: 'multiple';
50
+ maxSelected?: number;
54
51
  });
55
- /** A bounded categorical filter. URL tags distinguish missing from literal "null". */
56
- export declare function dimensionFilter<const T extends DimensionValue>(config: DimensionFilterOptions<T>): DimensionVariable<T>;
52
+ export type DimensionFilterSettings<T extends DimensionValue> = DimensionSettings & {
53
+ valueType: T extends number ? 'number' : 'string';
54
+ };
55
+ export type DimensionFilterOptions<T extends DimensionValue> = DimensionFilterSettings<T> & {
56
+ options: readonly DimensionOption<T>[];
57
+ facet?: never;
58
+ };
59
+ /** A bounded categorical filter with app-owned fixed options. */
60
+ export declare function dimensionFilter<const T extends string>(config: DimensionFilterOptions<T>): DimensionVariable<T>;
61
+ export declare function dimensionFilter<const T extends number>(config: DimensionFilterOptions<T>): DimensionVariable<T>;
62
+ /** Shared fixed-option and query-backed selection behavior. */
63
+ export declare function createDimensionFilter<const T extends DimensionValue>(config: DimensionFilterSettings<T> & {
64
+ options: readonly DimensionOption<T>[];
65
+ }, dynamic?: boolean): DimensionSelectionVariable<T>;
57
66
  /** Server-side parser; call from the operation input parser before building SQL. */
58
- export declare function parseDimensionSelection<T extends DimensionValue>(value: unknown, filter: DimensionVariable<T>): DimensionSelection<T>;
67
+ export declare function parseDimensionSelection<T extends DimensionValue>(value: unknown, filter: DimensionSelectionVariable<T>): DimensionSelection<T>;
59
68
  /** Validate bounded facet results before showing them in a picker. */
60
- export declare function parseFacetOptions<T extends DimensionValue>(value: unknown, filter: DimensionVariable<T>): DimensionOption<T>[];
69
+ export declare function parseFacetOptions<T extends DimensionValue>(value: unknown, filter: DimensionSelectionVariable<T>): DimensionOption<T>[];
61
70
  /** Central SQL literal encoding for transports without bound parameters. Column is an allowlisted identifier. */
62
71
  export declare function dimensionPredicate<T extends DimensionValue, const Columns extends readonly string[]>(column: Columns[number], selection: DimensionSelection<T>, allowedColumns: Columns): string;
@@ -0,0 +1,13 @@
1
+ import type { VariableCollection } from './variables.js';
2
+ import type { DimensionSelectionVariable, DimensionValue } from './dimension.js';
3
+ /** Executable facet sources are attached only by the typed hooks factory. */
4
+ export declare const facetSource: unique symbol;
5
+ export type FacetSourceDefinition<Context extends VariableCollection = VariableCollection, Name extends string = string, Input = unknown> = {
6
+ readonly context: Context;
7
+ readonly operation: Name;
8
+ readonly input: (values: Record<string, unknown>) => Input;
9
+ };
10
+ export type FacetVariable<Value extends DimensionValue, Context extends VariableCollection, Name extends string, Input> = DimensionSelectionVariable<Value> & {
11
+ readonly optionsSource: 'query';
12
+ readonly [facetSource]: FacetSourceDefinition<Context, Name, Input>;
13
+ };
@@ -1,4 +1,4 @@
1
- import type { AppVariable, HistoryMode } from './variables.js';
1
+ import type { AppVariable, HistoryMode, VariablePresentation } from './variables.js';
2
2
  export type NumberOperator = 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte';
3
3
  export type NumberSelection = {
4
4
  kind: 'all';
@@ -30,15 +30,16 @@ type FilterOptions<Value> = {
30
30
  label: string;
31
31
  defaultValue?: Value;
32
32
  history?: HistoryMode;
33
+ presentation?: VariablePresentation;
33
34
  };
34
35
  export declare const numberOperatorLabels: Record<NumberOperator, string>;
35
36
  /** Exact numeric predicates; range bounds are inclusive and may be open-ended. */
36
- export declare function numberFilter({ key, label, min, max, defaultValue, history, }: FilterOptions<NumberSelection> & {
37
+ export declare function numberFilter({ key, label, min, max, defaultValue, history, presentation, }: FilterOptions<NumberSelection> & {
37
38
  min?: number;
38
39
  max?: number;
39
40
  }): NumberFilter;
40
41
  /** Boolean predicate with a distinct unrestricted state. */
41
- export declare function booleanFilter({ key, label, defaultValue, history, }: FilterOptions<BooleanSelection>): BooleanFilter;
42
+ export declare function booleanFilter({ key, label, defaultValue, history, presentation, }: FilterOptions<BooleanSelection>): BooleanFilter;
42
43
  export declare function parseNumberSelection(value: unknown, filter: NumberFilter): NumberSelection;
43
44
  export declare function parseBooleanSelection(value: unknown, filter: BooleanFilter): BooleanSelection;
44
45
  export {};
@@ -1,3 +1,6 @@
1
+ import { type DateFormatOptions } from './date-format.js';
2
+ export { formatDate, formatDateTime, formatTime, parseDateTime, } from './date-format.js';
3
+ export type { DateFormat, DateFormatOptions, DateTimeFormatOptions, } from './date-format.js';
1
4
  /**
2
5
  * Date and number formatting with explicit units and missing-value behavior.
3
6
  * @module @altertable/data-app/format
@@ -7,10 +10,10 @@ type CommonOptions = {
7
10
  missing?: string;
8
11
  };
9
12
  /** Compact, unambiguous calendar dates for labels and request status. */
10
- export declare function formatDateRange({ start, end, }: {
13
+ export declare function formatDateRange({ start, end }: {
11
14
  start: string;
12
15
  end: string;
13
- }): string;
16
+ }, options?: DateFormatOptions): string;
14
17
  export type MetricFormat = {
15
18
  kind: 'count';
16
19
  compact?: boolean;
@@ -36,4 +39,3 @@ export declare function pluralize(count: number, singular: string, plural?: stri
36
39
  export declare function formatPercent(ratio: number | null | undefined, options?: CommonOptions & {
37
40
  maximumFractionDigits?: number;
38
41
  }): string;
39
- export {};
@@ -0,0 +1,2 @@
1
+ /** Separator for opaque composite keys, independent of URL and DOM ID formats. */
2
+ export declare const KEY_SEPARATOR = ":";
@@ -31,7 +31,9 @@ export declare class MessageRoutingError extends Error {
31
31
  readonly requestId?: string | undefined;
32
32
  readonly [errorBrand] = true;
33
33
  static [Symbol.hasInstance](value: unknown): boolean;
34
- constructor(code: string, message: string, requestId?: string | undefined);
34
+ constructor(code: string, message: string, requestId?: string | undefined,
35
+ /** `cause` stays with the host for logs; the bridge sends only code, message, and request ID. */
36
+ options?: ErrorOptions);
35
37
  }
36
38
  export declare function defineMessageRoute<Input, Output>(route: MessageRoute<Input, Output>): MessageRoute<Input, Output>;
37
39
  /** Contracts are shared; handlers are supplied by the host and never belong in the app bundle. */
@@ -2,20 +2,21 @@
2
2
  import type { QueryParameters } from './queries.js';
3
3
  export type OperationContracts = Record<string, {
4
4
  input: (value: unknown) => unknown;
5
- output: (value: unknown) => unknown;
6
5
  }>;
7
6
  export type InputOf<T> = T extends {
8
7
  input: (value: unknown) => infer Input;
9
8
  } ? Input : never;
9
+ /** An operation's data is what its `run` resolves to. */
10
10
  export type OutputOf<T> = T extends {
11
- output: (value: unknown) => infer Output;
12
- } ? Output : never;
13
- export type QueryResult = {
11
+ run: (...args: never[]) => Promise<infer Output>;
12
+ } ? Output : unknown;
13
+ /** Lakehouse results contain positional unknown cells; registered queries supply decoded records. */
14
+ export type QueryResult<Row = unknown[]> = {
14
15
  columns: {
15
16
  name: string;
16
17
  type?: string;
17
18
  }[];
18
- rows: unknown[][];
19
+ rows: Row[];
19
20
  queryId?: string;
20
21
  };
21
22
  /** One registered statement an operation ran, with its parameter values. */
@@ -40,14 +41,14 @@ export type OperationContext = {
40
41
  queryParams?: QueryParameters;
41
42
  };
42
43
  /**
43
- * Parsers run in the operation executor's runtime: server for HTTP apps, browser for bundle apps.
44
- * Browser validation does not replace backend authorization or query limits.
44
+ * The input parser runs in the operation executor's runtime: server for HTTP apps, browser for
45
+ * bundle apps. Browser validation does not replace backend authorization or query limits.
46
+ * Registered queries decode rows from their declared projections; `run` derives the operation's data.
45
47
  */
46
48
  export type DataOperation<Input, Output> = {
47
49
  input: (value: unknown) => Input;
48
- output: (value: unknown) => Output;
49
50
  run: (context: OperationContext, input: Input) => Promise<Output>;
50
- checks: readonly Input[];
51
+ checks: readonly [Input, ...Input[]];
51
52
  queryNames?: Readonly<Record<string, string>>;
52
53
  policy: {
53
54
  maxQueryRows: number;
@@ -56,8 +57,8 @@ export type DataOperation<Input, Output> = {
56
57
  };
57
58
  };
58
59
  /** Heterogeneous registry: inputs vary per operation, so checks retain unknown values. */
59
- export type DataOperations = Record<string, OperationContracts[string] & Omit<DataOperation<never, unknown>, 'input' | 'output' | 'checks'> & {
60
- checks: readonly unknown[];
60
+ export type DataOperations = Record<string, OperationContracts[string] & Omit<DataOperation<never, unknown>, 'input' | 'checks'> & {
61
+ checks: readonly [unknown, ...unknown[]];
61
62
  }>;
62
63
  export type DataQueryInput<Operations extends OperationContracts> = {
63
64
  [Name in keyof Operations & string]: {
@@ -1,16 +1,84 @@
1
+ import type { QueryResult } from './operation-types.js';
2
+ type QueryValues = {
3
+ string: string;
4
+ number: number;
5
+ boolean: boolean;
6
+ null: null;
7
+ };
8
+ /** Primitive values after decoding, independent of SQL storage types. */
9
+ export type QueryValueType = keyof QueryValues;
10
+ export type QueryField = {
11
+ type: QueryValueType;
12
+ nullable?: boolean;
13
+ };
14
+ export type QueryProjections = Readonly<Record<string, QueryField>>;
15
+ type QueryValue<Field extends QueryField> = QueryValues[Field['type']] | (Field extends {
16
+ nullable: true;
17
+ } ? null : never);
18
+ export type QueryRow<Projections extends QueryProjections> = {
19
+ -readonly [Name in keyof Projections]: QueryValue<Projections[Name]>;
20
+ };
1
21
  export type QueryParameterValue = string | number | boolean | null;
22
+ /** Typed scalar parameters with optional fallback values. */
23
+ export type QueryParameter = {
24
+ [Type in QueryValueType]: {
25
+ type: Type;
26
+ nullable?: false;
27
+ defaultValue?: QueryValues[Type];
28
+ } | {
29
+ type: Type;
30
+ nullable: true;
31
+ defaultValue?: QueryValues[Type] | null;
32
+ };
33
+ }[QueryValueType];
34
+ /** Callers may omit values supplied by host context or declaration defaults. */
35
+ export type QueryInputParameters<Params extends Readonly<Record<string, QueryParameter>>> = {
36
+ [Name in keyof Params]?: QueryValue<Params[Name]>;
37
+ };
2
38
  type QueryDefinition = {
3
39
  statement: string;
4
- params: Readonly<Record<string, {
5
- defaultValue?: QueryParameterValue;
6
- }>>;
40
+ params: Readonly<Record<string, QueryParameter>>;
41
+ projections: QueryProjections;
7
42
  };
8
43
  export type QueryDefinitions = Readonly<Record<string, QueryDefinition>>;
44
+ export type IsUnion<Value, Whole = Value> = Value extends Whole ? [Whole] extends [Value] ? false : true : never;
45
+ export type KnownRecord<RecordType> = '__proto__' extends keyof RecordType ? never : string extends keyof RecordType ? never : Exclude<keyof RecordType, string> extends never ? true extends IsUnion<RecordType> ? never : RecordType : never;
46
+ type CheckedField<Field extends QueryField> = true extends IsUnion<Field> ? never : true extends IsUnion<Field['type']> ? never : 'nullable' extends keyof Field ? Field extends {
47
+ nullable: infer Nullable;
48
+ } ? boolean extends Nullable ? never : Field : never : Field;
49
+ type CheckedParameters<Params extends Readonly<Record<string, QueryParameter>>> = KnownRecord<Params> & {
50
+ [Name in keyof Params]: CheckedField<Params[Name]> & ('defaultValue' extends keyof Params[Name] ? undefined extends Params[Name]['defaultValue'] ? never : Params[Name] : Params[Name]);
51
+ };
52
+ type CheckedProjections<Projections extends QueryProjections> = KnownRecord<Projections> & (keyof Projections extends never ? never : '' extends keyof Projections ? never : {
53
+ [Name in keyof Projections]: CheckedField<Projections[Name]>;
54
+ });
55
+ /** Author declarations preserve finite names, fixed types, and one parameter map. */
56
+ export type CheckedQueries<Queries extends QueryDefinitions> = KnownRecord<Queries> & ('' extends keyof Queries ? never : unknown) & {
57
+ [Name in keyof Queries]: KnownRecord<Queries[Name]> & {
58
+ statement: Queries[Name]['statement'] extends '' ? never : Queries[Name]['statement'];
59
+ params: CheckedParameters<Queries[Name]['params']>;
60
+ projections: CheckedProjections<Queries[Name]['projections']>;
61
+ };
62
+ };
63
+ type FrozenField<Field extends QueryField> = Field extends unknown ? Readonly<Field> : never;
64
+ export type QuerySnapshot<Queries extends QueryDefinitions> = {
65
+ readonly [Name in keyof Queries]: {
66
+ readonly statement: Queries[Name]['statement'];
67
+ readonly params: {
68
+ readonly [Param in keyof Queries[Name]['params']]: FrozenField<Queries[Name]['params'][Param]>;
69
+ };
70
+ readonly projections: {
71
+ readonly [Field in keyof Queries[Name]['projections']]: FrozenField<Queries[Name]['projections'][Field]>;
72
+ };
73
+ };
74
+ };
9
75
  /** Parameters are scalar SQL values, never identifiers or SQL fragments. */
10
76
  export type QueryParameters = Readonly<Record<string, QueryParameterValue>>;
11
77
  export declare function isQueryParameters(value: unknown): value is QueryParameters;
12
- /** Retain authored statements and defaults, rejecting empty SQL and invalid scalar defaults. */
13
- export declare function snapshotQueries(definitions: QueryDefinitions): QueryDefinitions;
14
- /** Context owns protected values; callers supply filters; defaults fill remaining declarations. */
15
- export declare function resolveQueryParameters(declarations: QueryDefinition['params'], values: Partial<QueryParameters>, context: QueryParameters): QueryParameters;
78
+ /** Snapshot the query's SQL, parameter defaults, and decoded result contract. */
79
+ export declare function snapshotQueries<const Queries extends QueryDefinitions>(definitions: Queries): QuerySnapshot<Queries>;
80
+ /** Decode each returned cell once, matching aliases independently of result order. */
81
+ export declare function decodeQueryResult<Projections extends QueryProjections>(result: QueryResult, projections: Projections): QueryResult<QueryRow<Projections>>;
82
+ /** Host context supplies protected values; callers and defaults fill the remaining parameters. */
83
+ export declare function resolveQueryParameters(declarations: Readonly<Record<string, QueryParameter>>, values: Partial<QueryParameters>, context: QueryParameters): QueryParameters;
16
84
  export {};