@altertable/data-app 0.72.0 → 0.73.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 (111) hide show
  1. package/AGENTS.md +5 -61
  2. package/CONTRIBUTING.md +93 -180
  3. package/README.md +3 -4
  4. package/REFERENCE.md +30 -345
  5. package/dist/chunks/contract-BeLPJwlO.js +558 -0
  6. package/dist/chunks/contract-BeLPJwlO.js.map +1 -0
  7. package/dist/chunks/contract-Di8SP74I.js +462 -0
  8. package/dist/chunks/contract-Di8SP74I.js.map +1 -0
  9. package/dist/chunks/format-BdFlv_xa.js +148 -0
  10. package/dist/chunks/format-BdFlv_xa.js.map +1 -0
  11. package/dist/chunks/iframe-C3uCZEXh.js +809 -0
  12. package/dist/chunks/iframe-C3uCZEXh.js.map +1 -0
  13. package/dist/chunks/operation-CBxhjNhK.js +131 -0
  14. package/dist/chunks/operation-CBxhjNhK.js.map +1 -0
  15. package/dist/chunks/request-body-H1qPmmTN.js +50 -0
  16. package/dist/chunks/request-body-H1qPmmTN.js.map +1 -0
  17. package/dist/client/index.js +253 -285
  18. package/dist/client/index.js.map +1 -13
  19. package/dist/core/appearance.js +171 -162
  20. package/dist/core/appearance.js.map +1 -10
  21. package/dist/core/config.js +49 -11
  22. package/dist/core/config.js.map +1 -9
  23. package/dist/core/contract.js +3 -73
  24. package/dist/core/format.js +1 -26
  25. package/dist/index.js +1 -12
  26. package/dist/internal.js +352 -397
  27. package/dist/internal.js.map +1 -15
  28. package/dist/server/index.js +85 -97
  29. package/dist/server/index.js.map +1 -10
  30. package/dist/types/chunks/appearance.d.ts +45 -0
  31. package/dist/types/chunks/contract.d.ts +720 -0
  32. package/dist/types/chunks/index.d.ts +189 -0
  33. package/dist/types/client/index.d.ts +3 -13
  34. package/dist/types/core/appearance.d.ts +2 -42
  35. package/dist/types/core/config.d.ts +36 -39
  36. package/dist/types/core/contract.d.ts +2 -114
  37. package/dist/types/core/format.d.ts +44 -17
  38. package/dist/types/index.d.ts +3 -3
  39. package/dist/types/internal.d.ts +312 -22
  40. package/dist/types/server/index.d.ts +15 -4
  41. package/docs/app-authoring.md +72 -128
  42. package/docs/client.md +29 -63
  43. package/docs/composition.md +44 -75
  44. package/docs/contract.md +60 -100
  45. package/docs/data-context.md +35 -61
  46. package/docs/embed.md +83 -55
  47. package/docs/formatting-and-appearance.md +17 -38
  48. package/docs/hosted-apps.md +7 -14
  49. package/docs/layout.md +30 -47
  50. package/docs/local-data-apps.md +7 -7
  51. package/docs/react-embed.md +20 -26
  52. package/docs/react.md +10 -27
  53. package/docs/server-bun.md +2 -27
  54. package/docs/server.md +6 -12
  55. package/docs/stories-and-export.md +38 -40
  56. package/docs/styling.md +14 -22
  57. package/docs/ui-quality.md +5 -5
  58. package/docs/ui.md +68 -70
  59. package/docs/variables.md +142 -254
  60. package/docs/views.md +85 -116
  61. package/docs/widgets.md +100 -153
  62. package/docs/worker.md +15 -27
  63. package/package.json +3 -2
  64. package/dist/chunks/index-5a27erdg.js +0 -54
  65. package/dist/chunks/index-5a27erdg.js.map +0 -10
  66. package/dist/chunks/index-9yxr7nmm.js +0 -742
  67. package/dist/chunks/index-9yxr7nmm.js.map +0 -17
  68. package/dist/chunks/index-j5q5n3ra.js +0 -151
  69. package/dist/chunks/index-j5q5n3ra.js.map +0 -10
  70. package/dist/chunks/index-q75zm3a7.js +0 -153
  71. package/dist/chunks/index-q75zm3a7.js.map +0 -11
  72. package/dist/chunks/index-vhaec7m5.js +0 -30
  73. package/dist/chunks/index-vhaec7m5.js.map +0 -10
  74. package/dist/chunks/index-zp78caex.js +0 -1047
  75. package/dist/chunks/index-zp78caex.js.map +0 -19
  76. package/dist/core/contract.js.map +0 -9
  77. package/dist/core/format.js.map +0 -9
  78. package/dist/index.js.map +0 -9
  79. package/dist/types/client/annotations.d.ts +0 -27
  80. package/dist/types/client/data-client.d.ts +0 -43
  81. package/dist/types/client/download.d.ts +0 -5
  82. package/dist/types/client/iframe.d.ts +0 -59
  83. package/dist/types/client/location.d.ts +0 -13
  84. package/dist/types/client/logger.d.ts +0 -14
  85. package/dist/types/client/messages.d.ts +0 -7
  86. package/dist/types/client/navigation.d.ts +0 -15
  87. package/dist/types/client/transport.d.ts +0 -15
  88. package/dist/types/core/annotations.d.ts +0 -99
  89. package/dist/types/core/bridge-endpoint.d.ts +0 -21
  90. package/dist/types/core/bridge.d.ts +0 -172
  91. package/dist/types/core/data-view.d.ts +0 -46
  92. package/dist/types/core/date-format.d.ts +0 -24
  93. package/dist/types/core/date-range.d.ts +0 -20
  94. package/dist/types/core/dimension-source.d.ts +0 -64
  95. package/dist/types/core/dimension.d.ts +0 -71
  96. package/dist/types/core/facets.d.ts +0 -13
  97. package/dist/types/core/filters.d.ts +0 -45
  98. package/dist/types/core/invariant.d.ts +0 -2
  99. package/dist/types/core/keys.d.ts +0 -2
  100. package/dist/types/core/logger.d.ts +0 -12
  101. package/dist/types/core/messages.d.ts +0 -62
  102. package/dist/types/core/navigation.d.ts +0 -11
  103. package/dist/types/core/operation-types.d.ts +0 -80
  104. package/dist/types/core/operation.d.ts +0 -20
  105. package/dist/types/core/presentation.d.ts +0 -9
  106. package/dist/types/core/queries.d.ts +0 -84
  107. package/dist/types/core/reading.d.ts +0 -17
  108. package/dist/types/core/uuid.d.ts +0 -2
  109. package/dist/types/core/variables.d.ts +0 -133
  110. package/dist/types/server/handler.d.ts +0 -13
  111. package/dist/types/server/request-body.d.ts +0 -4
@@ -0,0 +1,720 @@
1
+ //#region src/core/operation-types.d.ts
2
+ type OperationContracts = Record<string, {
3
+ input: (value: unknown) => unknown;
4
+ }>;
5
+ type InputOf<T> = T extends {
6
+ input: (value: unknown) => infer Input;
7
+ } ? Input : never;
8
+ /** An operation's data is what its `run` resolves to. */
9
+ type OutputOf<T> = T extends {
10
+ run: (...args: never[]) => Promise<infer Output>;
11
+ } ? Output : unknown;
12
+ /** Lakehouse results contain positional unknown cells; registered queries supply decoded records. */
13
+ type QueryResult<Row = unknown[]> = {
14
+ columns: {
15
+ name: string;
16
+ type?: string;
17
+ }[];
18
+ rows: Row[];
19
+ queryId?: string;
20
+ };
21
+ /** One registered statement an operation ran, with its parameter values. */
22
+ type DisclosedQuery = {
23
+ name: string;
24
+ statement: string;
25
+ params?: QueryParameters;
26
+ queryId?: string;
27
+ };
28
+ /** Query interface supplied by a server adapter or an authorized iframe bridge. */
29
+ type Lakehouse = {
30
+ queryAll(statement: string, options: {
31
+ limit: number;
32
+ signal: AbortSignal;
33
+ name?: string;
34
+ params?: QueryParameters;
35
+ }): Promise<QueryResult>;
36
+ };
37
+ type OperationContext = {
38
+ lakehouse: Lakehouse;
39
+ signal: AbortSignal;
40
+ queryParams?: QueryParameters;
41
+ };
42
+ /**
43
+ * The input parser runs in the operation executor's runtime: server for HTTP apps, browser for
44
+ * bundle apps. Browser validation does not replace backend authorization or query limits.
45
+ * Registered queries decode rows from their declared projections; `run` derives the operation's data.
46
+ */
47
+ type DataOperation<Input, Output> = {
48
+ input: (value: unknown) => Input;
49
+ run: (context: OperationContext, input: Input) => Promise<Output>;
50
+ checks: readonly [Input, ...Input[]];
51
+ queryNames?: Readonly<Record<string, string>>;
52
+ policy: {
53
+ maxQueryRows: number;
54
+ maxDurationMs: number;
55
+ maxResponseBytes?: number;
56
+ };
57
+ };
58
+ /** Heterogeneous registry: inputs vary per operation, so checks retain unknown values. */
59
+ type DataOperations = Record<string, OperationContracts[string] & Omit<DataOperation<never, unknown>, 'input' | 'checks'> & {
60
+ checks: readonly [unknown, ...unknown[]];
61
+ }>;
62
+ type DataQueryInput<Operations extends OperationContracts> = { [Name in keyof Operations & string]: {
63
+ operation: Name;
64
+ input: InputOf<Operations[Name]>;
65
+ }; }[keyof Operations & string];
66
+ type DataQueryBody<Output> = {
67
+ data: Output;
68
+ requestId: string;
69
+ queriedAt: string;
70
+ queryIds: string[];
71
+ queries?: DisclosedQuery[];
72
+ };
73
+ /** Delivery envelope shared by HTTP and iframe transports. */
74
+ type TransportResponse<Body = unknown> = {
75
+ status: number;
76
+ body: Body;
77
+ };
78
+ //#endregion
79
+ //#region src/core/queries.d.ts
80
+ type QueryValues = {
81
+ string: string;
82
+ number: number;
83
+ boolean: boolean;
84
+ null: null;
85
+ };
86
+ /** Primitive values after decoding, independent of SQL storage types. */
87
+ type QueryValueType = keyof QueryValues;
88
+ type QueryField = {
89
+ type: QueryValueType;
90
+ nullable?: boolean;
91
+ };
92
+ type QueryProjections = Readonly<Record<string, QueryField>>;
93
+ type QueryValue<Field extends QueryField> = QueryValues[Field['type']] | (Field extends {
94
+ nullable: true;
95
+ } ? null : never);
96
+ type QueryRow<Projections extends QueryProjections> = { -readonly [Name in keyof Projections]: QueryValue<Projections[Name]>; };
97
+ type QueryParameterValue = string | number | boolean | null;
98
+ /** Typed scalar parameters with optional fallback values. */
99
+ type QueryParameter = { [Type in QueryValueType]: {
100
+ type: Type;
101
+ nullable?: false;
102
+ defaultValue?: QueryValues[Type];
103
+ } | {
104
+ type: Type;
105
+ nullable: true;
106
+ defaultValue?: QueryValues[Type] | null;
107
+ }; }[QueryValueType];
108
+ /** Callers may omit values supplied by host context or declaration defaults. */
109
+ type QueryInputParameters<Params extends Readonly<Record<string, QueryParameter>>> = { [Name in keyof Params]?: QueryValue<Params[Name]>; };
110
+ type QueryDefinition = {
111
+ statement: string;
112
+ params: Readonly<Record<string, QueryParameter>>;
113
+ projections: QueryProjections;
114
+ };
115
+ type QueryDefinitions = Readonly<Record<string, QueryDefinition>>;
116
+ type IsUnion<Value, Whole = Value> = Value extends Whole ? [Whole] extends [Value] ? false : true : never;
117
+ 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;
118
+ type CheckedField<Field extends QueryField> = true extends IsUnion<Field> ? never : true extends IsUnion<Field['type']> ? never : 'nullable' extends keyof Field ? Field extends {
119
+ nullable: infer Nullable;
120
+ } ? boolean extends Nullable ? never : Field : never : Field;
121
+ type CheckedParameters<Params extends Readonly<Record<string, QueryParameter>>> = KnownRecord<Params> & { [Name in keyof Params]: CheckedField<Params[Name]> & ('defaultValue' extends keyof Params[Name] ? undefined extends Params[Name]['defaultValue'] ? never : Params[Name] : Params[Name]); };
122
+ type CheckedProjections<Projections extends QueryProjections> = KnownRecord<Projections> & (keyof Projections extends never ? never : '' extends keyof Projections ? never : { [Name in keyof Projections]: CheckedField<Projections[Name]>; });
123
+ /** Author declarations preserve finite names, fixed types, and one parameter map. */
124
+ type CheckedQueries<Queries extends QueryDefinitions> = KnownRecord<Queries> & ('' extends keyof Queries ? never : unknown) & { [Name in keyof Queries]: KnownRecord<Queries[Name]> & {
125
+ statement: Queries[Name]['statement'] extends '' ? never : Queries[Name]['statement'];
126
+ params: CheckedParameters<Queries[Name]['params']>;
127
+ projections: CheckedProjections<Queries[Name]['projections']>;
128
+ }; };
129
+ type FrozenField<Field extends QueryField> = Field extends unknown ? Readonly<Field> : never;
130
+ type QuerySnapshot<Queries extends QueryDefinitions> = { readonly [Name in keyof Queries]: {
131
+ readonly statement: Queries[Name]['statement'];
132
+ readonly params: { readonly [Param in keyof Queries[Name]['params']]: FrozenField<Queries[Name]['params'][Param]>; };
133
+ readonly projections: { readonly [Field in keyof Queries[Name]['projections']]: FrozenField<Queries[Name]['projections'][Field]>; };
134
+ }; };
135
+ /** Parameters are scalar SQL values, never identifiers or SQL fragments. */
136
+ type QueryParameters = Readonly<Record<string, QueryParameterValue>>;
137
+ //#endregion
138
+ //#region src/core/date-range.d.ts
139
+ /** ISO calendar dates; the app operation defines timezone and inclusive bounds. */
140
+ type DateRange = {
141
+ start: string;
142
+ end: string;
143
+ };
144
+ type DatePresetId = 'day' | 'last-3' | 'last-7' | 'last-14' | 'last-30' | 'last-90' | 'this-week' | 'previous-week' | 'this-month' | 'previous-month';
145
+ type DatePreset = {
146
+ id: DatePresetId;
147
+ label: string;
148
+ range: DateRange;
149
+ };
150
+ declare function inclusiveDays(range: DateRange): number;
151
+ declare function withinBounds(range: DateRange, minDate?: string, maxDate?: string, maxRangeDays?: number): boolean;
152
+ /** Only offer ranges the app says it can query. Dates and range lengths are inclusive. */
153
+ declare function availableDatePresets({ minDate, maxDate, maxRangeDays, timeZone }: {
154
+ minDate?: string;
155
+ maxDate?: string;
156
+ maxRangeDays?: number;
157
+ timeZone?: string;
158
+ }): DatePreset[];
159
+ //#endregion
160
+ //#region src/core/dimension-source.d.ts
161
+ declare const dimensionSource: unique symbol;
162
+ type SourceDimensionVariable<Value extends DimensionValue> = DimensionSelectionVariable<Value> & {
163
+ readonly optionsSource: 'query';
164
+ readonly [dimensionSource]: {
165
+ readonly operation: string;
166
+ };
167
+ };
168
+ /** Validate named variable values at the operation boundary. Date inputs belong to the base parser. */
169
+ declare function variableInput<Input extends object, const Variables extends VariableCollection>(parse: (value: unknown) => Input, variables: Variables & { [Key in keyof Variables]: Variables[Key] extends {
170
+ kind: 'dateRange';
171
+ } ? never : Variables[Key]; }): (value: unknown) => Input & AppVariableValues<Variables>;
172
+ type DimensionSourceConfig<Type extends 'string' | 'number'> = DimensionSettings & {
173
+ allowMissing?: false;
174
+ valueType: Type;
175
+ source: {
176
+ query: string;
177
+ };
178
+ };
179
+ type DimensionSourceQueryName<Queries extends QueryDefinitions, Type extends 'string' | 'number'> = { [Name in keyof Queries & string]: Queries[Name] extends {
180
+ params: {
181
+ member: {
182
+ type: Type;
183
+ nullable: true;
184
+ };
185
+ };
186
+ projections: {
187
+ value: {
188
+ type: Type;
189
+ nullable?: false;
190
+ };
191
+ label: {
192
+ type: 'string';
193
+ nullable?: false;
194
+ };
195
+ };
196
+ } ? 'count' extends keyof Queries[Name]['projections'] ? Queries[Name]['projections']['count'] extends {
197
+ type: 'number';
198
+ nullable?: false;
199
+ } ? Name : never : Name : never; }[keyof Queries & string];
200
+ //#endregion
201
+ //#region src/core/filters.d.ts
202
+ type NumberOperator = 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte';
203
+ type NumberSelection = {
204
+ kind: 'all';
205
+ } | {
206
+ kind: 'comparison';
207
+ operator: NumberOperator;
208
+ value: number;
209
+ } | {
210
+ kind: 'range';
211
+ min?: number;
212
+ max?: number;
213
+ };
214
+ type BooleanSelection = {
215
+ kind: 'all';
216
+ } | {
217
+ kind: 'is';
218
+ value: boolean;
219
+ };
220
+ type NumberFilter = AppVariable<NumberSelection, 'numberFilter'> & {
221
+ label: string;
222
+ min?: number;
223
+ max?: number;
224
+ };
225
+ type BooleanFilter = AppVariable<BooleanSelection, 'booleanFilter'> & {
226
+ label: string;
227
+ };
228
+ type FilterOptions<Value> = {
229
+ key: string;
230
+ label: string;
231
+ defaultValue?: Value;
232
+ history?: HistoryMode;
233
+ presentation?: VariablePresentation;
234
+ };
235
+ declare const numberOperatorLabels: Record<NumberOperator, string>;
236
+ /** Exact numeric predicates; range bounds are inclusive and may be open-ended. */
237
+ declare function numberFilter({ key, label, min, max, defaultValue, history, presentation }: FilterOptions<NumberSelection> & {
238
+ min?: number;
239
+ max?: number;
240
+ }): NumberFilter;
241
+ /** Boolean predicate with a distinct unrestricted state. */
242
+ declare function booleanFilter({ key, label, defaultValue, history, presentation }: FilterOptions<BooleanSelection>): BooleanFilter;
243
+ declare function parseNumberSelection(value: unknown, filter: NumberFilter): NumberSelection;
244
+ declare function parseBooleanSelection(value: unknown, filter: BooleanFilter): BooleanSelection;
245
+ //#endregion
246
+ //#region src/core/navigation.d.ts
247
+ /** App-owned URL state shared by controls, frame adapters, and host navigation. */
248
+ type AppLocation = {
249
+ search: string;
250
+ hash: string;
251
+ };
252
+ type HistoryMode = 'push' | 'replace';
253
+ type NavigationUpdate = AppLocation & {
254
+ mode: HistoryMode;
255
+ title?: string;
256
+ };
257
+ //#endregion
258
+ //#region src/core/variables.d.ts
259
+ type VariablePresentation = {
260
+ /** Scope changes the included data; display changes its presentation. Defaults to scope. */
261
+ group?: 'scope' | 'display';
262
+ /** Widget controls render beside their visualization instead of in the toolbar.
263
+ * Scope filters remain available in the Filters sheet and active summaries. */
264
+ control?: 'toolbar' | 'widget';
265
+ /** Secondary scope controls live in the Filters sheet with compact pickers when active; secondary display options follow primary options. Defaults to primary. */
266
+ prominence?: 'primary' | 'secondary';
267
+ };
268
+ /** An app-owned value with one URL representation. Controls never parse or write routes. */
269
+ type AppVariable<Value, Kind extends string = string> = {
270
+ kind: Kind;
271
+ label?: string;
272
+ presentation?: VariablePresentation;
273
+ urlKeys: readonly string[];
274
+ defaultValue: Value;
275
+ /** Unrestricted value, when this variable represents a filter. */
276
+ clearValue?: Value;
277
+ describe?: (value: Value) => string;
278
+ history: HistoryMode;
279
+ read: (params: URLSearchParams) => Value;
280
+ write: (value: Value) => Record<string, string | null>;
281
+ valid: (value: Value) => boolean;
282
+ same: (left: Value, right: Value) => boolean;
283
+ };
284
+ type VariableCollection = Record<string, SearchVariable | ChoiceVariable<any> | MultiChoiceVariable | DateRangeVariable | DimensionVariable<any> | FacetVariable<any, any, string, unknown> | SourceDimensionVariable<any> | NumberFilter | BooleanFilter>;
285
+ type AppVariableValues<Variables> = { [Key in keyof Variables]: Variables[Key] extends DimensionSelectionVariable<infer Value> ? DimensionSelection<Value> : Variables[Key] extends AppVariable<infer Value, string> ? Value : never; };
286
+ /** Keep conditional declarations narrowed so every dependency has one contract. */
287
+ type CheckedVariableDeclarations<Variables extends VariableCollection> = true extends IsUnion<Variables> ? never : string extends keyof Variables ? Variables : '__proto__' extends keyof Variables ? never : { [Name in keyof Variables]: true extends IsUnion<Variables[Name]> ? never : Variables[Name]; };
288
+ /** Every facet dependency must be present with a compatible variable declaration. */
289
+ type CheckedFacetContexts<Variables extends VariableCollection> = CheckedVariableDeclarations<Variables> & (string extends keyof Variables ? Extract<Variables[keyof Variables], {
290
+ [facetSource]: unknown;
291
+ }> extends never ? Variables : never : { [Name in keyof Variables]: Variables[Name] extends {
292
+ [facetSource]: {
293
+ context: infer Context;
294
+ };
295
+ } ? string extends keyof Context ? never : Variables extends Context ? Variables[Name] : never : Variables[Name]; });
296
+ /** Name variables once in the app. URL keys must be unique across its controls. */
297
+ declare function defineAppVariables<const Variables extends VariableCollection>(variables: Variables): Variables;
298
+ type ScalarVariableOptions = {
299
+ label?: string;
300
+ key: string;
301
+ defaultValue?: string;
302
+ history?: HistoryMode;
303
+ presentation?: VariablePresentation;
304
+ };
305
+ type SearchVariable = AppVariable<string, 'search'>;
306
+ type ChoiceOption = {
307
+ id: string;
308
+ label: string;
309
+ description?: string;
310
+ };
311
+ type ChoiceVariable<Value extends string = string> = AppVariable<Value, 'choice'> & {
312
+ options: readonly ChoiceOption[];
313
+ };
314
+ type MultiChoiceVariable = AppVariable<readonly string[], 'multiChoice'> & {
315
+ options: readonly ChoiceOption[];
316
+ maxSelected: number;
317
+ };
318
+ /** Search query state; typing replaces history by default. */
319
+ declare function searchVariable({ key, label, defaultValue, history }: Omit<ScalarVariableOptions, 'presentation'>): SearchVariable;
320
+ /** Validate labeled choices before controls or URL state consume them. */
321
+ declare function validateChoiceOptions(options: readonly ChoiceOption[]): void;
322
+ declare function choiceVariable<const Options extends readonly ChoiceOption[], const Presentation extends VariablePresentation | undefined = undefined>({ key, label, defaultValue, options, history, presentation }: Omit<ScalarVariableOptions, 'presentation'> & {
323
+ presentation?: Presentation;
324
+ defaultValue: NoInfer<Options[number]['id']>;
325
+ options: Options & (Options extends readonly [] ? never : unknown);
326
+ }): ChoiceVariable<Options[number]['id']> & {
327
+ presentation?: Presentation;
328
+ };
329
+ declare function multiChoiceVariable<const Options extends readonly ChoiceOption[], const Presentation extends VariablePresentation | undefined = undefined>({ key, label, defaultValue, options, maxSelected, history, presentation }: Omit<ScalarVariableOptions, 'defaultValue' | 'presentation'> & {
330
+ presentation?: Presentation;
331
+ defaultValue?: readonly NoInfer<Options[number]['id']>[];
332
+ options: Options & (Options extends readonly [] ? never : unknown);
333
+ maxSelected?: number;
334
+ }): MultiChoiceVariable & {
335
+ presentation?: Presentation;
336
+ };
337
+ type DateRangeSelection = {
338
+ kind: 'preset';
339
+ id: DatePresetId;
340
+ comparison?: 'previous';
341
+ } | {
342
+ kind: 'dates';
343
+ start: string;
344
+ end: string;
345
+ comparison?: 'previous';
346
+ };
347
+ type DateRangeVariableOptions = {
348
+ label?: string;
349
+ /** URL key for a relative preset; explicit dates use start/end for period, otherwise key-prefixed fields. */
350
+ key: string;
351
+ defaultValue: DateRangeSelection & {
352
+ comparison?: never;
353
+ };
354
+ contract: DateRangeContract;
355
+ history?: HistoryMode;
356
+ /** Opt into a URL-backed comparison with the preceding equal-length range. */
357
+ comparison?: boolean;
358
+ presentation?: VariablePresentation;
359
+ };
360
+ type DateRangeVariable = AppVariable<DateRangeSelection, 'dateRange'> & {
361
+ kind: 'dateRange';
362
+ supportsComparison: boolean;
363
+ input: (selection: DateRangeSelection) => DateRangeRequest;
364
+ describeInput: (input: DateRangeRequest) => string;
365
+ bounds: () => {
366
+ minDate?: string;
367
+ maxDate: string;
368
+ maxRangeDays: number;
369
+ timeZone: string;
370
+ };
371
+ resolve: (selection: DateRangeSelection) => DateRange;
372
+ previous: (selection: DateRangeSelection) => DateRange | null;
373
+ comparisonRange: (selection: DateRangeSelection) => DateRange | null;
374
+ };
375
+ /** A date variable keeps relative presets relative and validates exact dates against source coverage. */
376
+ declare function dateRangeVariable({ key, label, defaultValue, contract, history, comparison, presentation }: DateRangeVariableOptions): DateRangeVariable;
377
+ //#endregion
378
+ //#region src/core/facets.d.ts
379
+ /** Executable facet sources are attached only by the typed hooks factory. */
380
+ declare const facetSource: unique symbol;
381
+ type FacetSourceDefinition<Context extends VariableCollection = VariableCollection, Name extends string = string, Input = unknown> = {
382
+ readonly context: Context;
383
+ readonly operation: Name;
384
+ readonly input: (values: Record<string, unknown>) => Input;
385
+ };
386
+ type FacetVariable<Value extends DimensionValue, Context extends VariableCollection, Name extends string, Input> = DimensionSelectionVariable<Value> & {
387
+ readonly optionsSource: 'query';
388
+ readonly [facetSource]: FacetSourceDefinition<Context, Name, Input>;
389
+ };
390
+ //#endregion
391
+ //#region src/core/dimension.d.ts
392
+ type DimensionValue = string | number;
393
+ type DimensionMember<T extends DimensionValue = DimensionValue> = {
394
+ kind: 'value';
395
+ value: T;
396
+ } | {
397
+ kind: 'missing';
398
+ };
399
+ type DimensionSelection<T extends DimensionValue = DimensionValue> = {
400
+ kind: 'all';
401
+ } | {
402
+ kind: 'include' | 'exclude';
403
+ members: readonly DimensionMember<T>[];
404
+ };
405
+ type DimensionOption<T extends DimensionValue = DimensionValue> = {
406
+ value: T;
407
+ label: string;
408
+ count?: number;
409
+ };
410
+ type DimensionSelectionVariable<T extends DimensionValue = DimensionValue> = AppVariable<DimensionSelection<T>, 'dimension'> & {
411
+ readonly optionsSource: 'fixed' | 'query';
412
+ label: string;
413
+ selectionMode: 'single' | 'multiple';
414
+ readonly valueType: T extends number ? 'number' : 'string';
415
+ allowMissing: boolean;
416
+ allowExclusion: boolean;
417
+ maxSelected: number;
418
+ options: readonly DimensionOption<T>[];
419
+ describe: (selection: DimensionSelection<T>, options?: readonly DimensionOption<T>[]) => string;
420
+ };
421
+ /** A fixed-option dimension retains its distinction from query-backed facets. */
422
+ type DimensionVariable<T extends DimensionValue = DimensionValue> = DimensionSelectionVariable<T> & {
423
+ readonly optionsSource: 'fixed';
424
+ readonly [facetSource]?: never;
425
+ };
426
+ declare function dimensionMemberKey(member: DimensionMember): string;
427
+ type DimensionSettings = {
428
+ key: string;
429
+ label: string;
430
+ allowMissing?: boolean;
431
+ allowExclusion?: boolean;
432
+ history?: HistoryMode;
433
+ presentation?: VariablePresentation;
434
+ } & ({
435
+ selectionMode: 'single';
436
+ maxSelected?: 1;
437
+ } | {
438
+ selectionMode: 'multiple';
439
+ maxSelected?: number;
440
+ });
441
+ type DimensionFilterSettings<T extends DimensionValue> = DimensionSettings & {
442
+ valueType: T extends number ? 'number' : 'string';
443
+ };
444
+ type DimensionFilterOptions<T extends DimensionValue> = DimensionFilterSettings<T> & {
445
+ options: readonly DimensionOption<T>[];
446
+ facet?: never;
447
+ };
448
+ /** A bounded categorical filter with app-owned fixed options. */
449
+ declare function dimensionFilter<const T extends string>(config: DimensionFilterOptions<T>): DimensionVariable<T>;
450
+ declare function dimensionFilter<const T extends number>(config: DimensionFilterOptions<T>): DimensionVariable<T>;
451
+ /** Shared fixed-option and query-backed selection behavior. */
452
+ declare function createDimensionFilter<const T extends DimensionValue>(config: DimensionFilterSettings<T> & {
453
+ options: readonly DimensionOption<T>[];
454
+ }, dynamic?: boolean): DimensionSelectionVariable<T>;
455
+ /** Server-side parser; call from the operation input parser before building SQL. */
456
+ declare function parseDimensionSelection<T extends DimensionValue>(value: unknown, filter: DimensionSelectionVariable<T>): DimensionSelection<T>;
457
+ /** Validate bounded facet results before showing them in a picker. */
458
+ declare function parseFacetOptions<T extends DimensionValue>(value: unknown, filter: DimensionSelectionVariable<T>): DimensionOption<T>[];
459
+ /** Central SQL literal encoding for transports without bound parameters. Column is an allowlisted identifier. */
460
+ declare function dimensionPredicate<T extends DimensionValue, const Columns extends readonly string[]>(column: Columns[number], selection: DimensionSelection<T>, allowedColumns: Columns): string;
461
+ //#endregion
462
+ //#region src/authoring/contract.d.ts
463
+ declare function parseEmptyInput(value: unknown): Record<string, never>;
464
+ declare function parseTrue(value: unknown): true;
465
+ type DateRangeRequest = {
466
+ range: DateRange;
467
+ comparison: DateRange | null;
468
+ };
469
+ /** The immediately preceding, equally long set of calendar days. */
470
+ declare function previousDateRange({ start, end }: DateRange): DateRange;
471
+ type ReportingPeriod = {
472
+ kind: 'rolling';
473
+ amount: number;
474
+ unit: 'hour' | 'day';
475
+ end: string;
476
+ } | {
477
+ kind: 'calendar';
478
+ start: string;
479
+ end: string;
480
+ timeZone: string;
481
+ };
482
+ type DateRangeContractOptions = {
483
+ minDate?: string;
484
+ maxDate?: string | (() => string);
485
+ maxRangeDays: number;
486
+ timeZone: string;
487
+ completeDays?: boolean;
488
+ };
489
+ /** One source policy for the server parser, URL variable, and displayed reporting period. */
490
+ declare function defineDateRangeContract(options: DateRangeContractOptions): {
491
+ request: (value: unknown, compare?: boolean) => DateRangeRequest;
492
+ parseRequest: (value: unknown) => DateRangeRequest;
493
+ bounds: () => {
494
+ minDate: string | undefined;
495
+ maxDate: string;
496
+ maxRangeDays: number;
497
+ timeZone: string;
498
+ };
499
+ parse(value: unknown): DateRange;
500
+ period: ({ start, end }: DateRange) => ReportingPeriod;
501
+ comparison: (input: DateRange) => DateRange | null;
502
+ describeInput: (input: DateRange) => string;
503
+ view: {
504
+ period: ({ start, end }: DateRange) => ReportingPeriod;
505
+ describeInput: (input: DateRange) => string;
506
+ };
507
+ };
508
+ type DateRangeContract = ReturnType<typeof defineDateRangeContract>;
509
+ /** Validate calendar dates and a bounded inclusive range on the server. */
510
+ declare function parseDateRangeInput(value: unknown, { minDate, maxDate, maxRangeDays }: {
511
+ minDate?: string;
512
+ maxDate?: string;
513
+ maxRangeDays: number;
514
+ }): DateRange;
515
+ /** Accepts numeric strings from DuckDB; rejects negative, fractional, and unsafe integers. */
516
+ declare function parseCount(value: unknown): number;
517
+ declare function parseLabel(value: unknown, maxLength?: number): string;
518
+ declare function defineQueryNames<const Names extends Record<string, string>>(names: Names): Names;
519
+ type RegisteredQueryParameters<Queries extends QueryDefinitions, Name extends keyof Queries> = QueryInputParameters<Queries[Name]['params']>;
520
+ type ExactQueryParameters<Expected, Params extends object> = Params & Expected & Record<Exclude<keyof Params, keyof Expected>, never> & (Params extends ((...args: never[]) => unknown) ? never : object);
521
+ type ParameterNames<Queries extends QueryDefinitions, Name extends keyof Queries> = Name extends keyof Queries ? keyof RegisteredQueryParameters<Queries, Name> : never;
522
+ /** Dynamic limits are checked at execution; known limits must be positive integers. */
523
+ type QueryLimit<Limit extends number> = number extends Limit ? number : `${Limit}` extends '0' | `-${string}` ? never : `${Limit}` extends `${bigint}` ? Limit : never;
524
+ 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?: {
525
+ limit?: Limit & QueryLimit<NoInfer<Limit>>;
526
+ }) => Promise<QueryResult<QueryRow<Queries[Name]['projections']>>>;
527
+ /** Infer operation data from run(). */
528
+ type OperationDefinition<Input, Output, Queries extends QueryDefinitions> = Omit<DataOperation<Input, Output>, 'run' | 'queryNames'> & {
529
+ run: (context: Pick<OperationContext, 'signal'> & {
530
+ query: RegisteredQuery<NoInfer<Queries>>;
531
+ }, input: Input) => Promise<Output>;
532
+ };
533
+ declare function defineOperation<Input, Output, const Queries extends QueryDefinitions>(operation: OperationDefinition<Input, Output, Queries> & {
534
+ queries: CheckedQueries<Queries>;
535
+ }): Omit<DataOperation<Input, Output>, 'queryNames'> & {
536
+ queryNames: { readonly [Name in keyof Queries & string]: Name; };
537
+ };
538
+ /** The built-in connection operation shares one contract with setup clients. */
539
+ type ConnectionOperation = Omit<DataOperation<Record<string, never>, true>, 'queryNames'> & {
540
+ queryNames: {
541
+ readonly connection: 'connection';
542
+ };
543
+ };
544
+ /** A connectivity probe uses the app's registered connection query. */
545
+ declare function connectionCheck<const Queries extends QueryDefinitions & {
546
+ connection: QueryDefinitions[string];
547
+ }>(queries: CheckedQueries<Queries>): ConnectionOperation;
548
+ //#endregion
549
+ //#region src/core/messages.d.ts
550
+ type MessageContext = {
551
+ signal: AbortSignal;
552
+ };
553
+ type RoutedMessage = {
554
+ route: string;
555
+ payload: unknown;
556
+ };
557
+ type MessageDispatcher = (message: unknown, context: MessageContext) => Promise<unknown>;
558
+ type MessageTransport = (message: RoutedMessage, signal?: AbortSignal) => Promise<unknown>;
559
+ type MessageRoute<Input, Output> = {
560
+ input: (value: unknown) => Input;
561
+ output: (value: unknown, input: Input) => Output;
562
+ };
563
+ type MessageRoutes = Record<string, {
564
+ input: (value: unknown) => unknown;
565
+ output: (value: unknown, input: never) => unknown;
566
+ }>;
567
+ type MessageInput<Route extends MessageRoutes[string]> = ReturnType<Route['input']>;
568
+ type MessageHandlers<Routes extends MessageRoutes> = { [Name in keyof Routes]: (payload: MessageInput<Routes[Name]>, context: MessageContext) => ReturnType<Routes[Name]['output']> | Promise<ReturnType<Routes[Name]['output']>>; };
569
+ declare const errorBrand: unique symbol;
570
+ /** Only these deliberate, public failures cross the message boundary. Other errors stay private. */
571
+ declare class MessageRoutingError extends Error {
572
+ readonly code: string;
573
+ readonly requestId?: string | undefined;
574
+ readonly [errorBrand] = true;
575
+ static [Symbol.hasInstance](value: unknown): boolean;
576
+ constructor(code: string, message: string, requestId?: string | undefined,
577
+ /** `cause` stays with the host for logs; the bridge sends only code, message, and request ID. */
578
+ options?: ErrorOptions);
579
+ }
580
+ declare function defineMessageRoute<Input, Output>(route: MessageRoute<Input, Output>): MessageRoute<Input, Output>;
581
+ /** Contracts are shared; handlers are supplied by the host and never belong in the app bundle. */
582
+ declare function createMessageRouter<const Routes extends MessageRoutes>(routes: Routes, handlers: MessageHandlers<NoInfer<Routes>>): {
583
+ dispatch: (value: unknown, context: MessageContext) => Promise<unknown>;
584
+ };
585
+ type DataQueryRoute<Operations extends OperationContracts> = MessageRoute<DataQueryInput<Operations>, TransportResponse> & {
586
+ operations: Operations | undefined;
587
+ };
588
+ type MessageOutput<Route extends MessageRoutes[string], Input> = Route extends DataQueryRoute<infer Operations> ? Input extends {
589
+ operation: infer Name extends keyof Operations;
590
+ } ? TransportResponse<DataQueryBody<OutputOf<Operations[Name]>>> : never : ReturnType<Route['output']>;
591
+ /** Omit contracts only in generic hosts such as the CLI shell, where Bun validates operations. */
592
+ declare function defineDataQueryRoute<Operations extends OperationContracts = OperationContracts>(operations?: Operations): DataQueryRoute<Operations>;
593
+ declare const navigationUpdateRoute: MessageRoute<NavigationUpdate, null>;
594
+ type SqlQueryInput = {
595
+ statement: string;
596
+ limit: number;
597
+ params?: QueryParameters;
598
+ };
599
+ /** SQL delivery for browser-owned operations. Hosts must enforce backend access and resource limits. */
600
+ declare const sqlQueryRoute: MessageRoute<SqlQueryInput, QueryResult>;
601
+ declare const dataAppRoutes: {
602
+ 'data:query': DataQueryRoute<OperationContracts>;
603
+ 'navigation:update': MessageRoute<NavigationUpdate, null>;
604
+ };
605
+ //#endregion
606
+ //#region src/core/annotations.d.ts
607
+ type DataAppAnnotationDraft = {
608
+ id: string;
609
+ target: {
610
+ id: string;
611
+ label: string;
612
+ kind: 'widget' | 'element' | 'app';
613
+ text: string;
614
+ queryNames: string[];
615
+ glossaryIds: string[];
616
+ };
617
+ context: {
618
+ search: string;
619
+ hash: string;
620
+ displayedInput?: unknown;
621
+ /** Normalized position within the selected target, stable across scrolling/resizing. */
622
+ anchor?: {
623
+ x: number;
624
+ y: number;
625
+ };
626
+ cursor?: {
627
+ x: number;
628
+ y: number;
629
+ };
630
+ /** Normalized custom selection rectangle within the iframe document. */
631
+ region?: {
632
+ x: number;
633
+ y: number;
634
+ width: number;
635
+ height: number;
636
+ };
637
+ screenshot?: {
638
+ mimeType: 'image/png';
639
+ dataUrl: string;
640
+ width: number;
641
+ height: number;
642
+ };
643
+ view?: string;
644
+ viewport: {
645
+ width: number;
646
+ height: number;
647
+ };
648
+ rect: {
649
+ x: number;
650
+ y: number;
651
+ width: number;
652
+ height: number;
653
+ };
654
+ };
655
+ comment: string;
656
+ };
657
+ type DataAppAnnotationPresentation = {
658
+ enabled: boolean;
659
+ /** When provided, the host owns the mode and renders the annotation trigger. */
660
+ active?: boolean;
661
+ pinsVisible?: boolean;
662
+ showHint?: boolean;
663
+ readOnly?: boolean;
664
+ targets?: {
665
+ id: string;
666
+ targetId: string;
667
+ number: number;
668
+ comment?: string;
669
+ anchor?: {
670
+ x: number;
671
+ y: number;
672
+ };
673
+ region?: {
674
+ x: number;
675
+ y: number;
676
+ width: number;
677
+ height: number;
678
+ };
679
+ }[];
680
+ selectedAnnotationId?: string;
681
+ selectedTargetId?: string;
682
+ selectionId?: string;
683
+ /** Confirmed host click outside the iframe; occurredAt is epoch milliseconds. */
684
+ dismissal?: {
685
+ id: string;
686
+ occurredAt: number;
687
+ };
688
+ };
689
+ /** Reconstruct at the boundary; discard extra fields and bound the entire JSON payload. */
690
+ declare function parseDataAppAnnotationDraft(value: unknown): DataAppAnnotationDraft;
691
+ declare const annotationDraftRoute: MessageRoute<DataAppAnnotationDraft, null>;
692
+ declare const annotationEditorStateRoute: MessageRoute<{
693
+ hasUnsavedChanges: boolean;
694
+ }, null>;
695
+ /** Request host-owned batch submission without transferring ownership of drafts. */
696
+ declare const annotationSendRoute: MessageRoute<null, null>;
697
+ declare const annotationUpdateRoute: MessageRoute<{
698
+ id: string;
699
+ comment: string;
700
+ }, null>;
701
+ /** A controlled shell acknowledges local exits (for example Escape). */
702
+ declare const annotationModeRoute: MessageRoute<{
703
+ active: boolean;
704
+ }, null>;
705
+ //#endregion
706
+ //#region src/core/contract.d.ts
707
+ declare const sourceErrorBrand: unique symbol;
708
+ declare class DataSourceError extends Error {
709
+ readonly reason: 'unauthorized' | 'forbidden' | 'rate_limited' | 'query_rejected' | 'unavailable';
710
+ readonly status?: number | undefined;
711
+ readonly [sourceErrorBrand] = true;
712
+ queryName?: string;
713
+ static [Symbol.hasInstance](value: unknown): boolean;
714
+ constructor(reason: 'unauthorized' | 'forbidden' | 'rate_limited' | 'query_rejected' | 'unavailable', status?: number | undefined,
715
+ /** `cause` stays on the server or host for logs; responses carry only the reason. */
716
+ options?: ErrorOptions);
717
+ }
718
+ //#endregion
719
+ export { createDimensionFilter as $, QueryDefinitions as $t, DateRangeContractOptions as A, BooleanSelection as At, parseDateRangeInput as B, DimensionSourceQueryName as Bt, dataAppRoutes as C, multiChoiceVariable as Ct, sqlQueryRoute as D, HistoryMode as Dt, navigationUpdateRoute as E, AppLocation as Et, connectionCheck as F, numberFilter as Ft, DimensionFilterOptions as G, DatePresetId as Gt, parseLabel as H, dimensionSource as Ht, defineDateRangeContract as I, numberOperatorLabels as It, DimensionOption as J, inclusiveDays as Jt, DimensionFilterSettings as K, DateRange as Kt, defineOperation as L, parseBooleanSelection as Lt, OperationDefinition as M, NumberOperator as Mt, RegisteredQuery as N, NumberSelection as Nt, ConnectionOperation as O, NavigationUpdate as Ot, ReportingPeriod as P, booleanFilter as Pt, DimensionVariable as Q, KnownRecord as Qt, defineQueryNames as R, parseNumberSelection as Rt, createMessageRouter as S, defineAppVariables as St, defineMessageRoute as T, validateChoiceOptions as Tt, parseTrue as U, variableInput as Ut, parseEmptyInput as V, SourceDimensionVariable as Vt, previousDateRange as W, DatePreset as Wt, DimensionSelectionVariable as X, CheckedQueries as Xt, DimensionSelection as Y, withinBounds as Yt, DimensionValue as Z, IsUnion as Zt, MessageRoutes as _, OutputOf as _n, SearchVariable as _t, annotationEditorStateRoute as a, QueryRow as an, FacetVariable as at, RoutedMessage as b, choiceVariable as bt, annotationUpdateRoute as c, DataOperation as cn, AppVariableValues as ct, MessageContext as d, DataQueryInput as dn, ChoiceOption as dt, QueryField as en, dimensionFilter as et, MessageDispatcher as f, DisclosedQuery as fn, ChoiceVariable as ft, MessageRoute as g, OperationContracts as gn, MultiChoiceVariable as gt, MessageOutput as h, OperationContext as hn, DateRangeVariableOptions as ht, annotationDraftRoute as i, QueryProjections as in, parseFacetOptions as it, DateRangeRequest as j, NumberFilter as jt, DateRangeContract as k, BooleanFilter as kt, parseDataAppAnnotationDraft as l, DataOperations as ln, CheckedFacetContexts as lt, MessageInput as m, Lakehouse as mn, DateRangeVariable as mt, DataAppAnnotationDraft as n, QueryParameterValue as nn, dimensionPredicate as nt, annotationModeRoute as o, QuerySnapshot as on, facetSource as ot, MessageHandlers as p, InputOf as pn, DateRangeSelection as pt, DimensionMember as q, availableDatePresets as qt, DataAppAnnotationPresentation as r, QueryParameters as rn, parseDimensionSelection as rt, annotationSendRoute as s, QueryValueType as sn, AppVariable as st, DataSourceError as t, QueryParameter as tn, dimensionMemberKey as tt, DataQueryRoute as u, DataQueryBody as un, CheckedVariableDeclarations as ut, MessageRoutingError as v, QueryResult as vn, VariableCollection as vt, defineDataQueryRoute as w, searchVariable as wt, SqlQueryInput as x, dateRangeVariable as xt, MessageTransport as y, TransportResponse as yn, VariablePresentation as yt, parseCount as z, DimensionSourceConfig as zt };
720
+ //# sourceMappingURL=contract.d.ts.map