@altertable/data-app 0.76.0 → 0.78.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 (69) hide show
  1. package/CONTRIBUTING.md +3 -0
  2. package/REFERENCE.md +392 -276
  3. package/dist/chunks/contract-gu1rDsV0.js +1588 -0
  4. package/dist/chunks/contract-gu1rDsV0.js.map +1 -0
  5. package/dist/chunks/data-client-BMdL73Ab.js +122 -0
  6. package/dist/chunks/data-client-BMdL73Ab.js.map +1 -0
  7. package/dist/chunks/{date-time-range-value-TE8KCsfV.js → date-time-range-value-D-XfqVTT.js} +28 -31
  8. package/dist/chunks/date-time-range-value-D-XfqVTT.js.map +1 -0
  9. package/dist/chunks/{diagnostics-DhCqGklq.js → diagnostics-CX9SsU79.js} +240 -63
  10. package/dist/chunks/diagnostics-CX9SsU79.js.map +1 -0
  11. package/dist/chunks/record-Cr4Uk1K3.js +9 -0
  12. package/dist/chunks/record-Cr4Uk1K3.js.map +1 -0
  13. package/dist/client/index.js +4 -86
  14. package/dist/client/index.js.map +1 -1
  15. package/dist/core/appearance.js +3 -5
  16. package/dist/core/appearance.js.map +1 -1
  17. package/dist/core/config.js +11 -3
  18. package/dist/core/config.js.map +1 -1
  19. package/dist/core/contract.js +3 -4
  20. package/dist/core/format.js +1 -1
  21. package/dist/internal.js +58 -124
  22. package/dist/internal.js.map +1 -1
  23. package/dist/types/chunks/contract.d.ts +592 -308
  24. package/dist/types/chunks/data-client.d.ts +46 -0
  25. package/dist/types/chunks/date-time-range-value.d.ts +28 -2
  26. package/dist/types/chunks/index.d.ts +65 -53
  27. package/dist/types/client/index.d.ts +4 -3
  28. package/dist/types/core/config.d.ts +16 -6
  29. package/dist/types/core/contract.d.ts +3 -5
  30. package/dist/types/core/format.d.ts +1 -2
  31. package/dist/types/index.d.ts +4 -4
  32. package/dist/types/internal.d.ts +26 -7
  33. package/docs/app-authoring.md +23 -14
  34. package/docs/client.md +14 -48
  35. package/docs/contract.md +58 -56
  36. package/docs/data-context.md +13 -6
  37. package/docs/diagnostics.md +16 -23
  38. package/docs/embed.md +60 -25
  39. package/docs/filters.md +271 -0
  40. package/docs/hosted-apps.md +11 -10
  41. package/docs/layout.md +45 -18
  42. package/docs/local-data-apps.md +5 -6
  43. package/docs/react-embed.md +44 -2
  44. package/docs/react.md +1 -2
  45. package/docs/server-bun.md +8 -5
  46. package/docs/stories-and-export.md +23 -14
  47. package/docs/styling.md +2 -1
  48. package/docs/ui.md +18 -8
  49. package/docs/views.md +63 -26
  50. package/docs/widgets.md +40 -16
  51. package/docs/worker.md +1 -1
  52. package/package.json +1 -5
  53. package/dist/chunks/contract-DsyRYgN_.js +0 -626
  54. package/dist/chunks/contract-DsyRYgN_.js.map +0 -1
  55. package/dist/chunks/contract-kNFYPHRK.js +0 -713
  56. package/dist/chunks/contract-kNFYPHRK.js.map +0 -1
  57. package/dist/chunks/date-time-range-value-TE8KCsfV.js.map +0 -1
  58. package/dist/chunks/diagnostics-DhCqGklq.js.map +0 -1
  59. package/dist/chunks/operation-7tiT4cpJ.js +0 -134
  60. package/dist/chunks/operation-7tiT4cpJ.js.map +0 -1
  61. package/dist/chunks/request-body-H1qPmmTN.js +0 -50
  62. package/dist/chunks/request-body-H1qPmmTN.js.map +0 -1
  63. package/dist/server/index.js +0 -90
  64. package/dist/server/index.js.map +0 -1
  65. package/dist/types/chunks/contract2.d.ts +0 -207
  66. package/dist/types/chunks/date-time-range.d.ts +0 -29
  67. package/dist/types/server/index.d.ts +0 -17
  68. package/docs/server.md +0 -41
  69. package/docs/variables.md +0 -280
@@ -1,110 +1,203 @@
1
- import { n as DateTimeRange, s as ResolvedDateTimeRange } from "./date-time-range.js";
1
+ import { c as DateTimeRange, p as ResolvedDateTimeRange } from "./date-time-range-value.js";
2
2
  //#region src/core/date-time-range-contract.d.ts
3
- /** Resolved UTC-rebased bounds for one execution, optionally with the preceding equal-length interval. */
4
- type DateTimeRangeRequest = {
3
+ /** What an operation receives for a date filter: resolved bounds, `from` inclusive and
4
+ * `to` exclusive, and the same window one selected length earlier while the comparison is on. */
5
+ type DateTimeRangeInput = {
5
6
  range: ResolvedDateTimeRange;
6
7
  comparison: ResolvedDateTimeRange | null;
8
+ /** Original selection, retained so relative bounds can be resolved when a query runs. */
9
+ selection?: DateTimeRangeSelection;
7
10
  };
8
- /** Datetime policy exposed by defineDateRangeContract().datetime. Parsing preserves relative values. */
9
- type DateTimeRangeContract = ReturnType<typeof createDateTimeRangeContract>;
10
- declare function createDateTimeRangeContract(options: DateRangeContractOptions): {
11
+ type DateTimeRangePolicyOptions = {
12
+ minDate?: string;
13
+ maxDate?: string | (() => string);
14
+ maxRangeDays?: number;
15
+ timeZone: string;
16
+ completeDays?: boolean;
17
+ };
18
+ /** A date filter's coverage, duration limit, and reporting time zone. Parsing preserves relative values. */
19
+ type DateTimeRangePolicy = ReturnType<typeof createDateTimeRangePolicy>;
20
+ declare function createDateTimeRangePolicy({ minDate, maxDate: sourceMaxDate, maxRangeDays, timeZone, completeDays }: DateTimeRangePolicyOptions): {
11
21
  timeZone: string;
12
22
  bounds: (now?: Date) => {
13
23
  minDate: string | undefined;
14
24
  maxDate: string;
15
- maxRangeDays: number;
25
+ maxRangeDays: number | undefined;
16
26
  timeZone: string;
17
27
  };
18
28
  /** Validate coverage and duration while preserving symbolic relative bounds. */
19
29
  parse: (value: unknown, now?: Date) => DateTimeRange;
20
30
  /** Resolve to UTC-rebased bounds using reporting-zone wall-clock fields, then validate policy. */
21
- resolve: (value: unknown, now?: Date) => DateTimeRangeRequest['range'];
22
- /** Return the preceding equal-length interval, or null when source coverage excludes it. */
23
- comparison: (value: unknown, now?: Date) => DateTimeRangeRequest['comparison'];
24
- /** Resolve both periods against one reference instant. Use these bounds for comparison queries. */
25
- request(value: unknown, compare?: boolean, now?: Date): DateTimeRangeRequest;
31
+ resolve: (value: unknown, now?: Date) => ResolvedDateTimeRange;
32
+ /** Return the comparison window, or null when source coverage excludes it. */
33
+ comparison: (value: unknown, now?: Date) => ResolvedDateTimeRange | null;
34
+ /** End a resolved range at the reference time when it runs past it. */
35
+ endAtNow: (range: ResolvedDateTimeRange, now?: Date) => ResolvedDateTimeRange;
36
+ /** Resolve both periods against one reference instant, ending the range at now. */
37
+ request(value: unknown, compare?: boolean, now?: Date): DateTimeRangeInput;
26
38
  };
27
39
  //#endregion
28
- //#region src/core/operation-types.d.ts
29
- type OperationContracts = Record<string, {
30
- input: (value: unknown) => unknown;
31
- }>;
32
- type InputOf<T> = T extends {
33
- input: (value: unknown) => infer Input;
34
- } ? Input : never;
35
- /** An operation's data is what its `run` resolves to. */
36
- type OutputOf<T> = T extends {
37
- run: (...args: never[]) => Promise<infer Output>;
38
- } ? Output : unknown;
39
- /** Lakehouse results contain positional unknown cells; registered queries supply decoded records. */
40
- type QueryResult<Row = unknown[]> = {
41
- columns: {
42
- name: string;
43
- type?: string;
44
- }[];
45
- rows: Row[];
46
- queryId?: string;
40
+ //#region src/core/date-time-filter.d.ts
41
+ /** A picker suggestion. Text ranges use the same natural-language parser as typed input. */
42
+ type DateTimeRangePreset = {
43
+ /** Menu label, also shown when this preset matches the selected range. */
44
+ label: string;
45
+ range: DateTimeRange | string;
46
+ /** Optional compact badge, for example "15m". */
47
+ shortcut?: string;
47
48
  };
48
- /** One registered statement an operation ran, with its parameter values. */
49
- type DisclosedQuery = {
50
- name: string;
51
- statement: string;
52
- params?: QueryParameters;
53
- queryId?: string;
49
+ /** Monitoring offers minute/hour windows; analytics offers longer periods and to-date windows. Spread either menu to add custom presets. */
50
+ declare const dateTimeRangePresets: {
51
+ readonly monitoring: readonly DateTimeRangePreset[];
52
+ readonly analytics: readonly DateTimeRangePreset[];
54
53
  };
55
- /** Query interface supplied by a server adapter or an authorized iframe bridge. */
56
- type Lakehouse = {
57
- queryAll(statement: string, options: {
58
- limit: number;
59
- signal: AbortSignal;
60
- name?: string;
61
- params?: QueryParameters;
62
- }): Promise<QueryResult>;
54
+ /** Offer the previous-period comparison, with its toggle starting off or on. */
55
+ type DateTimeRangeComparison = 'off' | 'on';
56
+ type DateTimeRangeFilterOptions<Comparison extends DateTimeRangeComparison | undefined = undefined> = {
57
+ key: string;
58
+ label?: string;
59
+ /** Range text such as "7d" stays relative; `{ from, to }` is absolute. */
60
+ defaultValue: DateTimeRange | string;
61
+ /** Reporting zone for relative ranges, calendar days, and labels. Defaults to UTC. */
62
+ timeZone?: string;
63
+ /** Longest selectable range. */
64
+ maxRangeDays?: number;
65
+ /** First date with data, as YYYY-MM-DD. */
66
+ minDate?: string;
67
+ /** Last date with data, as YYYY-MM-DD. */
68
+ maxDate?: string | (() => string);
69
+ /** End coverage yesterday, for sources that load whole days. */
70
+ completeDays?: boolean;
71
+ /** Offer the previous-period comparison. Omit for none. */
72
+ comparison?: Comparison;
73
+ /** Suggestions in display order. Omit for defaults; [] retains calendar and text entry.
74
+ * Invalid or over-limit suggestions are omitted; typed input is not restricted to the menu.
75
+ */
76
+ presets?: readonly DateTimeRangePreset[];
77
+ history?: HistoryMode;
78
+ presentation?: FilterPresentation;
63
79
  };
64
- type OperationContext = {
65
- lakehouse: Lakehouse;
66
- signal: AbortSignal;
67
- queryParams?: QueryParameters;
80
+ /** The picker's URL state: the selected range, relative or absolute, and the comparison toggle. */
81
+ type DateTimeRangeSelection = {
82
+ range: DateTimeRange;
83
+ comparison?: 'previous';
68
84
  };
69
- /**
70
- * The input parser runs in the operation executor's runtime: server for HTTP apps, browser for
71
- * bundle apps. Browser validation does not replace backend authorization or query limits.
72
- * Registered queries decode rows from their declared projections; `run` derives the operation's data.
85
+ /** Sent from the browser: the resolved input plus the selection and reference time it came from. */
86
+ type DateTimeRangeRequest = DateTimeRangeInput & {
87
+ selection: DateTimeRangeSelection;
88
+ reference: string;
89
+ };
90
+ type DateTimeRangeFilter<Comparable extends boolean = boolean> = AppFilter<DateTimeRangeSelection, 'dateTimeRange'> & {
91
+ /** Whether readers can turn on the previous-period comparison. */
92
+ comparable: Comparable;
93
+ policy: DateTimeRangePolicy;
94
+ maxRangeDays?: number;
95
+ presets?: readonly DateTimeRangePreset[];
96
+ /** Resolve a selection against one reference time. */
97
+ request: (selection: DateTimeRangeSelection, now?: Date) => DateTimeRangeRequest;
98
+ /** Validate untrusted input against coverage and return what the operation receives. */
99
+ parseInput: (value: unknown) => DateTimeRangeInput;
100
+ previous: (selection: DateTimeRangeSelection) => DateTimeRangeInput['comparison'];
101
+ };
102
+ /** One declaration drives the picker, URL state, and the input of operations that list it.
103
+ * Operations receive resolved bounds and the original selection: `from` inclusive, `to` exclusive.
73
104
  */
74
- type DataOperation<Input, Output> = {
75
- input: (value: unknown) => Input;
76
- run: (context: OperationContext, input: Input) => Promise<Output>;
77
- checks: readonly [Input, ...Input[]];
78
- queryNames?: Readonly<Record<string, string>>;
79
- policy: {
80
- maxQueryRows: number;
81
- maxDurationMs: number;
82
- maxResponseBytes?: number;
105
+ declare function dateTimeRangeFilter<Comparison extends DateTimeRangeComparison | undefined = undefined>(options: DateTimeRangeFilterOptions<Comparison>): DateTimeRangeFilter<undefined extends Comparison ? false : true>;
106
+ /** Bind one date selection immediately before dispatching a query. Both periods share one clock. */
107
+ declare function queryDateTimeRangeParams<const Prefix extends string>(filter: Pick<DateTimeRangeFilter, 'request'>, input: DateTimeRangeInput, prefix: Prefix, now?: Date): {
108
+ current: Record<`${Prefix}_from` | `${Prefix}_to`, string>;
109
+ comparison: Record<`${Prefix}_from` | `${Prefix}_to`, string> | null;
110
+ combined: Record<`${Prefix}_from` | `${Prefix}_to`, string>;
111
+ };
112
+ //#endregion
113
+ //#region src/core/facets.d.ts
114
+ declare const facetSource: unique symbol;
115
+ /** A dimension whose options come from an operation. The options follow that
116
+ * operation's own filters, so selecting a period narrows the choices. */
117
+ type FacetFilter<Value extends DimensionValue = DimensionValue, Operation extends string = string> = DimensionSelectionFilter<Value> & {
118
+ readonly optionsSource: 'query';
119
+ readonly [facetSource]: {
120
+ readonly operation: Operation;
83
121
  };
84
122
  };
85
- /** Heterogeneous registry: inputs vary per operation, so checks retain unknown values. */
86
- type DataOperations = Record<string, OperationContracts[string] & Omit<DataOperation<never, unknown>, 'input' | 'checks'> & {
87
- checks: readonly [unknown, ...unknown[]];
88
- }>;
89
- type DataQueryInput<Operations extends OperationContracts> = { [Name in keyof Operations & string]: {
90
- operation: Name;
91
- input: InputOf<Operations[Name]>;
92
- }; }[keyof Operations & string];
93
- type DataQueryBody<Output> = {
94
- data: Output;
95
- requestId: string;
96
- queriedAt: string;
97
- queryIds: string[];
98
- queries?: DisclosedQuery[];
123
+ //#endregion
124
+ //#region src/core/dimension.d.ts
125
+ type DimensionValue = string | number;
126
+ type DimensionMember<T extends DimensionValue = DimensionValue> = {
127
+ kind: 'value';
128
+ value: T;
129
+ } | {
130
+ kind: 'missing';
99
131
  };
100
- /** Delivery envelope shared by HTTP and iframe transports. */
101
- type TransportResponse<Body = unknown> = {
102
- status: number;
103
- body: Body;
132
+ type DimensionSelection<T extends DimensionValue = DimensionValue> = {
133
+ kind: 'all';
134
+ } | {
135
+ kind: 'include' | 'exclude';
136
+ members: readonly DimensionMember<T>[];
137
+ };
138
+ type DimensionOption<T extends DimensionValue = DimensionValue> = {
139
+ value: T;
140
+ label: string;
141
+ count?: number;
142
+ };
143
+ type DimensionSelectionFilter<T extends DimensionValue = DimensionValue> = AppFilter<DimensionSelection<T>, 'dimension'> & {
144
+ readonly optionsSource: 'fixed' | 'query';
145
+ label: string;
146
+ selectionMode: 'single' | 'multiple';
147
+ readonly valueType: T extends number ? 'number' : 'string';
148
+ allowMissing: boolean;
149
+ allowExclusion: boolean;
150
+ maxSelected: number;
151
+ options: readonly DimensionOption<T>[];
152
+ describe: (selection: DimensionSelection<T>, options?: readonly DimensionOption<T>[]) => string;
153
+ };
154
+ /** A fixed-option dimension retains its distinction from query-backed facets. */
155
+ type DimensionFilter<T extends DimensionValue = DimensionValue> = DimensionSelectionFilter<T> & {
156
+ readonly optionsSource: 'fixed';
157
+ readonly [facetSource]?: never;
158
+ };
159
+ declare function dimensionMemberKey(member: DimensionMember): string;
160
+ type DimensionSettings = {
161
+ key: string;
162
+ label: string;
163
+ allowMissing?: boolean;
164
+ allowExclusion?: boolean;
165
+ history?: HistoryMode;
166
+ presentation?: FilterPresentation;
167
+ } & ({
168
+ selectionMode: 'single';
169
+ maxSelected?: 1;
170
+ } | {
171
+ selectionMode: 'multiple';
172
+ maxSelected?: number;
173
+ });
174
+ type DimensionFilterSettings<T extends DimensionValue> = DimensionSettings & {
175
+ valueType: T extends number ? 'number' : 'string';
176
+ /** The selection before readers change it, such as paid orders only. Clearing
177
+ * filters still returns to every member. Defaults to `{ kind: 'all' }`. */
178
+ defaultValue?: DimensionSelection<NoInfer<T>>;
179
+ };
180
+ type DimensionFilterOptions<T extends DimensionValue> = DimensionFilterSettings<T> & {
181
+ options: readonly DimensionOption<T>[];
182
+ facet?: never;
104
183
  };
184
+ /** A bounded categorical filter with app-owned fixed options. */
185
+ declare function dimensionFilter<const T extends string>(config: DimensionFilterOptions<T>): DimensionFilter<T>;
186
+ declare function dimensionFilter<const T extends number>(config: DimensionFilterOptions<T>): DimensionFilter<T>;
187
+ /** Shared fixed-option and query-backed selection behavior. */
188
+ declare function createDimensionFilter<const T extends DimensionValue>(config: DimensionFilterSettings<T> & {
189
+ options: readonly DimensionOption<T>[];
190
+ }, dynamic?: boolean): DimensionSelectionFilter<T>;
191
+ /** Server-side parser; call from the operation input parser before building SQL. */
192
+ declare function parseDimensionSelection<T extends DimensionValue>(value: unknown, filter: DimensionSelectionFilter<T>): DimensionSelection<T>;
193
+ /** Validate bounded facet results before showing them in a picker. */
194
+ declare function parseFacetOptions<T extends DimensionValue>(value: unknown, filter: DimensionSelectionFilter<T>): DimensionOption<T>[];
195
+ /** Central SQL literal encoding for transports without bound parameters. Column is an allowlisted identifier. */
196
+ declare function dimensionPredicate<T extends DimensionValue, const Columns extends readonly string[]>(column: Columns[number], selection: DimensionSelection<T>, allowedColumns: Columns): string;
105
197
  //#endregion
106
198
  //#region src/core/queries.d.ts
107
199
  declare const MAX_QUERY_ROWS = 10000;
200
+ declare const REGISTERED_QUERY_ID_PATTERN: RegExp;
108
201
  type QueryValues = {
109
202
  string: string;
110
203
  number: number;
@@ -123,8 +216,15 @@ type QueryValue<Field extends QueryField> = QueryValues[Field['type']] | (Field
123
216
  } ? null : never);
124
217
  type QueryRow<Projections extends QueryProjections> = { -readonly [Name in keyof Projections]: QueryValue<Projections[Name]>; };
125
218
  type QueryParameterValue = string | number | boolean | null;
126
- /** Typed scalar or datetime-range parameters with optional fallback values. */
219
+ /** Typed scalar, datetime-range, or dimension parameters with optional fallback values.
220
+ * Structured values bind as JSON; statements use DuckDB SQL to read their fields. */
127
221
  type QueryParameter = {
222
+ /** A dimension filter's `DimensionSelection`, bound as validated JSON. */
223
+ type: 'dimension';
224
+ valueType: 'string' | 'number';
225
+ nullable?: false;
226
+ defaultValue?: never;
227
+ } | {
128
228
  type: 'dateTimeRange';
129
229
  nullable?: false;
130
230
  /** Absolute defaults may use canonical UTC ISO strings (including milliseconds) for static manifests. Snapshots hydrate them into Dates. */
@@ -141,7 +241,12 @@ type QueryParameter = {
141
241
  /** Callers may omit values supplied by host context or declaration defaults. */
142
242
  type QueryInputParameters<Params extends Readonly<Record<string, QueryParameter>>> = { [Name in keyof Params]?: Params[Name] extends {
143
243
  type: 'dateTimeRange';
144
- } ? DateTimeRange : Params[Name] extends QueryField ? QueryValue<Params[Name]> : never; };
244
+ } ? DateTimeRange : Params[Name] extends {
245
+ type: 'dimension';
246
+ valueType: 'number';
247
+ } ? DimensionSelection<number> : Params[Name] extends {
248
+ type: 'dimension';
249
+ } ? DimensionSelection<string> : Params[Name] extends QueryField ? QueryValue<Params[Name]> : never; };
145
250
  type QueryDefinition = {
146
251
  statement: string;
147
252
  params: Readonly<Record<string, QueryParameter>>;
@@ -149,7 +254,7 @@ type QueryDefinition = {
149
254
  };
150
255
  type QueryDefinitions = Readonly<Record<string, QueryDefinition>>;
151
256
  type IsUnion<Value, Whole = Value> = Value extends Whole ? [Whole] extends [Value] ? false : true : never;
152
- 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;
257
+ type KnownRecord<RecordType> = string extends keyof RecordType ? never : Exclude<keyof RecordType, string> extends never ? true extends IsUnion<RecordType> ? never : RecordType : never;
153
258
  type CheckedField<Field extends {
154
259
  type: string;
155
260
  nullable?: boolean;
@@ -168,6 +273,8 @@ type FrozenField<Field extends {
168
273
  type: string;
169
274
  nullable?: boolean;
170
275
  }> = Field extends {
276
+ type: 'dimension';
277
+ } ? Readonly<Field> : Field extends {
171
278
  type: 'dateTimeRange';
172
279
  } ? Readonly<{ [Key in keyof Field]: Key extends 'defaultValue' ? DateTimeRange : Field[Key]; }> : Field extends unknown ? Readonly<Field> : never;
173
280
  type QuerySnapshot<Queries extends QueryDefinitions> = { readonly [Name in keyof Queries]: {
@@ -178,84 +285,101 @@ type QuerySnapshot<Queries extends QueryDefinitions> = { readonly [Name in keyof
178
285
  /** Parameters are scalar SQL values, never identifiers or SQL fragments. */
179
286
  type QueryParameters = Readonly<Record<string, QueryParameterValue>>;
180
287
  //#endregion
181
- //#region src/core/date-time-variable.d.ts
182
- /** A picker suggestion. Text ranges use the same natural-language parser as typed input. */
183
- type DateTimeRangePreset = {
184
- /** Menu label, also shown when this preset matches the selected range. */
185
- label: string;
186
- range: DateTimeRange | string;
187
- /** Optional compact badge, for example "15m". */
188
- shortcut?: string;
288
+ //#region src/core/operation-types.d.ts
289
+ type OperationContracts = Record<string, {
290
+ input: (value: unknown) => unknown;
291
+ }>;
292
+ type InputOf<T> = T extends {
293
+ input: (value: unknown) => infer Input;
294
+ } ? Input : never;
295
+ /** An operation's data is what its `run` resolves to. */
296
+ type OutputOf<T> = T extends {
297
+ run: (...args: never[]) => Promise<infer Output>;
298
+ } ? Output : unknown;
299
+ /** Lakehouse results contain positional unknown cells; registered queries supply decoded records. */
300
+ type QueryResult<Row = unknown[]> = {
301
+ columns: {
302
+ name: string;
303
+ type?: string;
304
+ }[];
305
+ rows: Row[];
306
+ queryId?: string;
189
307
  };
190
- /** Monitoring offers minute/hour windows; analytics offers longer periods and to-date windows. Spread either menu to add custom presets. */
191
- declare const dateTimeRangePresets: {
192
- readonly monitoring: readonly DateTimeRangePreset[];
193
- readonly analytics: readonly DateTimeRangePreset[];
308
+ /** One registered statement an operation ran, with its parameter values. */
309
+ type DisclosedQuery = {
310
+ name: string;
311
+ statement: string;
312
+ params?: QueryParameters;
313
+ queryId?: string;
194
314
  };
195
- type DateTimeRangeVariableOptions = {
196
- key: string;
197
- label?: string;
198
- /** Enable the previous-period reporting workflow. Requires a shared contract. */
199
- allowComparison?: false;
200
- /** Relative defaults such as "7d" stay relative. */
201
- defaultValue: DateTimeRange | string;
202
- /** Client limit for determinate durations; the backend must validate timezone-dependent ranges. */
203
- maxRangeDays?: number;
204
- /** Shared reporting coverage, timezone, duration limits, and comparison policy. */
205
- contract?: DateRangeContract;
206
- /** Suggestions in display order. Omit for defaults; [] retains calendar and text entry.
207
- * Invalid or over-limit suggestions are omitted; typed input is not restricted to the menu.
208
- */
209
- presets?: readonly DateTimeRangePreset[];
210
- history?: HistoryMode;
211
- presentation?: VariablePresentation;
315
+ type QueryOptions = {
316
+ limit: number;
317
+ signal: AbortSignal;
318
+ params?: QueryParameters;
212
319
  };
213
- type DateTimeRangeVariable = AppVariable<DateTimeRange, 'dateTimeRange'> & {
214
- parse: (value: unknown) => DateTimeRange;
215
- maxRangeDays?: number;
216
- /** Shared reporting coverage, timezone, duration limits, and comparison policy. */
217
- contract?: DateRangeContract;
218
- presets?: readonly DateTimeRangePreset[];
320
+ /** SQL execution supplied by a local server adapter. */
321
+ type SqlLakehouse = {
322
+ queryAll(statement: string, options: QueryOptions & {
323
+ name?: string;
324
+ }): Promise<QueryResult>;
219
325
  };
220
- type DateTimeRangeComparisonSelection = {
221
- range: DateTimeRange;
222
- comparison?: 'previous';
326
+ /** Registered query execution supplied by an authorized hosted bridge. */
327
+ type HostedLakehouse = {
328
+ queryAllById(queryId: string, options: QueryOptions): Promise<QueryResult>;
223
329
  };
224
- /** An execution snapshot with the relative selection retained for URL and displayed-scope matching. */
225
- type DateTimeRangeComparisonRequest = DateTimeRangeRequest & {
226
- selection: DateTimeRangeComparisonSelection;
227
- reference: string;
330
+ type Lakehouse = SqlLakehouse | HostedLakehouse;
331
+ type OperationContext = {
332
+ lakehouse: SqlLakehouse;
333
+ signal: AbortSignal;
334
+ queryParams?: QueryParameters;
228
335
  };
229
- type DateTimeRangeComparisonVariableOptions = Omit<DateTimeRangeVariableOptions, 'allowComparison' | 'contract'> & {
230
- allowComparison: true;
231
- contract: DateRangeContract;
336
+ /**
337
+ * The input parser runs in the browser. Browser validation does not replace
338
+ * backend authorization or query limits.
339
+ * Registered queries decode rows from their declared projections; `run` derives the operation's data.
340
+ */
341
+ type DataOperation<Input, Output> = {
342
+ /** The app filters the operation reads; its input has one field per filter. */
343
+ filters?: Readonly<FilterCollection>;
344
+ input: (value: unknown) => Input;
345
+ run: (context: OperationContext, input: Input) => Promise<Output>;
346
+ checks: readonly [Input, ...Input[]];
347
+ queryNames?: Readonly<Record<string, string>>;
348
+ policy: {
349
+ maxQueryRows: number;
350
+ maxDurationMs: number;
351
+ maxResponseBytes?: number;
352
+ };
232
353
  };
233
- type DateTimeRangeComparisonVariable = AppVariable<DateTimeRangeComparisonSelection, 'dateTimeRangeComparison'> & {
234
- contract: DateRangeContract;
235
- maxRangeDays?: number;
236
- presets?: readonly DateTimeRangePreset[];
237
- input: (selection: DateTimeRangeComparisonSelection, now?: Date) => DateTimeRangeComparisonRequest;
238
- parseInput: (value: unknown) => DateTimeRangeComparisonRequest;
239
- previous: (selection: DateTimeRangeComparisonSelection) => DateTimeRangeRequest['comparison'];
354
+ /** Heterogeneous registry: inputs vary per operation, so checks retain unknown values. */
355
+ type DataOperations = Record<string, OperationContracts[string] & Omit<DataOperation<never, unknown>, 'input' | 'checks'> & {
356
+ checks: readonly [unknown, ...unknown[]];
357
+ }>;
358
+ type DataQueryInput<Operations extends OperationContracts> = { [Name in keyof Operations & string]: {
359
+ operation: Name;
360
+ input: InputOf<Operations[Name]>;
361
+ }; }[keyof Operations & string];
362
+ type DataQueryBody<Output> = {
363
+ data: Output;
364
+ requestId: string;
365
+ queriedAt: string;
366
+ queryIds: string[];
367
+ queries?: DisclosedQuery[];
368
+ };
369
+ /** Delivery envelope for typed message routes. */
370
+ type TransportResponse<Body = unknown> = {
371
+ status: number;
372
+ body: Body;
240
373
  };
241
- /** One declaration drives the picker, URL state, and operation input.
242
- * With comparison enabled, use input(defaultValue) for operation checks and variableInput()
243
- * to validate request snapshots. Query the resulting range and optional comparison bounds.
244
- */
245
- declare function dateTimeRangeVariable(options: DateTimeRangeComparisonVariableOptions): DateTimeRangeComparisonVariable;
246
- declare function dateTimeRangeVariable(options: DateTimeRangeVariableOptions): DateTimeRangeVariable;
247
374
  //#endregion
248
375
  //#region src/core/dimension-source.d.ts
249
376
  declare const dimensionSource: unique symbol;
250
- type SourceDimensionVariable<Value extends DimensionValue> = DimensionSelectionVariable<Value> & {
377
+ type SourceDimensionFilter<Value extends DimensionValue> = DimensionSelectionFilter<Value> & {
251
378
  readonly optionsSource: 'query';
252
379
  readonly [dimensionSource]: {
253
380
  readonly operation: string;
254
381
  };
255
382
  };
256
- type ParsedVariableValues<Variables extends VariableCollection> = { [Key in keyof Variables]: Variables[Key] extends DateTimeRangeComparisonVariable ? DateTimeRangeComparisonRequest : AppVariableValues<Variables>[Key]; };
257
- /** Validate named variable values at the operation boundary. */
258
- declare function variableInput<Input extends object, const Variables extends VariableCollection>(parse: (value: unknown) => Input, variables: Variables): (value: unknown) => Input & ParsedVariableValues<Variables>;
259
383
  type DimensionSourceConfig<Type extends 'string' | 'number'> = DimensionSettings & {
260
384
  allowMissing?: false;
261
385
  valueType: Type;
@@ -304,12 +428,12 @@ type BooleanSelection = {
304
428
  kind: 'is';
305
429
  value: boolean;
306
430
  };
307
- type NumberFilter = AppVariable<NumberSelection, 'numberFilter'> & {
431
+ type NumberFilter = AppFilter<NumberSelection, 'numberFilter'> & {
308
432
  label: string;
309
433
  min?: number;
310
434
  max?: number;
311
435
  };
312
- type BooleanFilter = AppVariable<BooleanSelection, 'booleanFilter'> & {
436
+ type BooleanFilter = AppFilter<BooleanSelection, 'booleanFilter'> & {
313
437
  label: string;
314
438
  };
315
439
  type FilterOptions<Value> = {
@@ -317,7 +441,7 @@ type FilterOptions<Value> = {
317
441
  label: string;
318
442
  defaultValue?: Value;
319
443
  history?: HistoryMode;
320
- presentation?: VariablePresentation;
444
+ presentation?: FilterPresentation;
321
445
  };
322
446
  declare const numberOperatorLabels: Record<NumberOperator, string>;
323
447
  /** Exact numeric predicates; range bounds are inclusive and may be open-ended. */
@@ -342,10 +466,9 @@ type NavigationUpdate = AppLocation & {
342
466
  title?: string;
343
467
  };
344
468
  //#endregion
345
- //#region src/core/variables.d.ts
346
- type VariablePresentation = {
347
- /** Scope changes the included data; display changes its presentation. Defaults to scope. */
348
- group?: 'scope' | 'display';
469
+ //#region src/core/app-filters.d.ts
470
+ /** Where a filter's or display option's control renders. */
471
+ type FilterPresentation = {
349
472
  /** Widget controls render beside their visualization instead of in the toolbar.
350
473
  * Scope filters remain available in the Filters sheet and active summaries. */
351
474
  control?: 'toolbar' | 'widget';
@@ -353,13 +476,16 @@ type VariablePresentation = {
353
476
  prominence?: 'primary' | 'secondary';
354
477
  };
355
478
  /** An app-owned value with one URL representation. Controls never parse or write routes. */
356
- type AppVariable<Value, Kind extends string = string> = {
479
+ type AppFilter<Value, Kind extends string = string> = {
357
480
  kind: Kind;
358
481
  label?: string;
359
- presentation?: VariablePresentation;
482
+ /** Display options (`displayChoice()`) change how results are shown, not which data is included. */
483
+ presentation?: FilterPresentation & {
484
+ group?: 'scope' | 'display';
485
+ };
360
486
  urlKeys: readonly string[];
361
487
  defaultValue: Value;
362
- /** Unrestricted value, when this variable represents a filter. */
488
+ /** Unrestricted value, when this filter can be cleared. */
363
489
  clearValue?: Value;
364
490
  describe?: (value: Value) => string;
365
491
  history: HistoryMode;
@@ -368,146 +494,110 @@ type AppVariable<Value, Kind extends string = string> = {
368
494
  valid: (value: Value) => boolean;
369
495
  same: (left: Value, right: Value) => boolean;
370
496
  };
371
- type VariableCollection = Record<string, SearchVariable | ChoiceVariable<any> | MultiChoiceVariable | DateTimeRangeVariable | DateTimeRangeComparisonVariable | DimensionVariable<any> | FacetVariable<any, any, string, unknown> | SourceDimensionVariable<any> | NumberFilter | BooleanFilter>;
372
- type AppVariableValues<Variables> = { [Key in keyof Variables]: Variables[Key] extends DimensionSelectionVariable<infer Value> ? DimensionSelection<Value> : Variables[Key] extends AppVariable<infer Value, string> ? Value : never; };
497
+ type FilterCollection = Record<string, SearchFilter | ChoiceFilter<any> | MultiChoiceFilter | DateTimeRangeFilter | DimensionFilter<any> | FacetFilter<any, string> | SourceDimensionFilter<any> | NumberFilter | BooleanFilter>;
498
+ type FilterValues<Collection> = { [Key in keyof Collection]: Collection[Key] extends DimensionSelectionFilter<infer Value> ? DimensionSelection<Value> : Collection[Key] extends AppFilter<infer Value, string> ? Value : never; };
373
499
  /** Keep conditional declarations narrowed so every dependency has one contract. */
374
- 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]; };
375
- /** Every facet dependency must be present with a compatible variable declaration. */
376
- type CheckedFacetContexts<Variables extends VariableCollection> = CheckedVariableDeclarations<Variables> & (string extends keyof Variables ? Extract<Variables[keyof Variables], {
377
- [facetSource]: unknown;
378
- }> extends never ? Variables : never : { [Name in keyof Variables]: Variables[Name] extends {
379
- [facetSource]: {
380
- context: infer Context;
381
- };
382
- } ? string extends keyof Context ? never : Variables extends Context ? Variables[Name] : never : Variables[Name]; });
383
- /** Name variables once in the app. URL keys must be unique across its controls. */
384
- declare function defineAppVariables<const Variables extends VariableCollection>(variables: Variables): Variables;
385
- type ScalarVariableOptions = {
500
+ type CheckedFilterDeclarations<Collection extends FilterCollection> = true extends IsUnion<Collection> ? never : string extends keyof Collection ? Collection : { [Name in keyof Collection]: true extends IsUnion<Collection[Name]> ? never : Collection[Name]; };
501
+ /** Name filters once in the app. URL keys must be unique across its controls. */
502
+ declare function defineAppFilters<const Collection extends FilterCollection>(filters: Collection): Collection;
503
+ type ScalarFilterOptions = {
386
504
  label?: string;
387
505
  key: string;
388
506
  defaultValue?: string;
389
507
  history?: HistoryMode;
390
- presentation?: VariablePresentation;
508
+ presentation?: FilterPresentation;
391
509
  };
392
- type SearchVariable = AppVariable<string, 'search'>;
510
+ type SearchFilter = AppFilter<string, 'search'>;
393
511
  type ChoiceOption = {
394
512
  id: string;
395
513
  label: string;
396
514
  description?: string;
397
515
  };
398
- type ChoiceVariable<Value extends string = string> = AppVariable<Value, 'choice'> & {
516
+ type ChoiceFilter<Value extends string = string> = AppFilter<Value, 'choice'> & {
399
517
  options: readonly ChoiceOption[];
400
518
  };
401
- type MultiChoiceVariable = AppVariable<readonly string[], 'multiChoice'> & {
519
+ type MultiChoiceFilter = AppFilter<readonly string[], 'multiChoice'> & {
402
520
  options: readonly ChoiceOption[];
403
521
  maxSelected: number;
404
522
  };
405
- /** Search query state; typing replaces history by default. */
406
- declare function searchVariable({ key, label, defaultValue, history }: Omit<ScalarVariableOptions, 'presentation'>): SearchVariable;
523
+ /** Search query state; typing replaces history by default. Operations reject text
524
+ * longer than `maxLength` (200 by default). */
525
+ declare function searchFilter({ key, label, defaultValue, history, maxLength }: Omit<ScalarFilterOptions, 'presentation'> & {
526
+ maxLength?: number;
527
+ }): SearchFilter;
407
528
  /** Validate labeled choices before controls or URL state consume them. */
408
529
  declare function validateChoiceOptions(options: readonly ChoiceOption[]): void;
409
- declare function choiceVariable<const Options extends readonly ChoiceOption[], const Presentation extends VariablePresentation | undefined = undefined>({ key, label, defaultValue, options, history, presentation }: Omit<ScalarVariableOptions, 'presentation'> & {
410
- presentation?: Presentation;
530
+ type ChoiceOptions<Options extends readonly ChoiceOption[]> = Omit<ScalarFilterOptions, 'defaultValue'> & {
411
531
  defaultValue: NoInfer<Options[number]['id']>;
412
532
  options: Options & (Options extends readonly [] ? never : unknown);
413
- }): ChoiceVariable<Options[number]['id']> & {
414
- presentation?: Presentation;
415
533
  };
416
- 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'> & {
417
- presentation?: Presentation;
534
+ /** One choice that narrows the included data. */
535
+ declare function choiceFilter<const Options extends readonly ChoiceOption[]>(options: ChoiceOptions<Options>): ChoiceFilter<Options[number]['id']>;
536
+ /** One choice that changes how results are shown, such as a chart breakdown or sort order.
537
+ * Clearing filters keeps it; pass `view.breakdown(name)` to render it beside its chart. */
538
+ declare function displayChoice<const Options extends readonly ChoiceOption[]>(options: ChoiceOptions<Options>): ChoiceFilter<Options[number]['id']> & {
539
+ presentation: {
540
+ group: 'display';
541
+ };
542
+ };
543
+ declare function multiChoiceFilter<const Options extends readonly ChoiceOption[]>({ key, label, defaultValue, options, maxSelected, history, presentation }: Omit<ScalarFilterOptions, 'defaultValue'> & {
418
544
  defaultValue?: readonly NoInfer<Options[number]['id']>[];
419
545
  options: Options & (Options extends readonly [] ? never : unknown);
420
546
  maxSelected?: number;
421
- }): MultiChoiceVariable & {
422
- presentation?: Presentation;
423
- };
547
+ }): MultiChoiceFilter;
424
548
  //#endregion
425
- //#region src/core/facets.d.ts
426
- /** Executable facet sources are attached only by the typed hooks factory. */
427
- declare const facetSource: unique symbol;
428
- type FacetSourceDefinition<Context extends VariableCollection = VariableCollection, Name extends string = string, Input = unknown> = {
429
- readonly context: Context;
430
- readonly operation: Name;
431
- readonly input: (values: Record<string, unknown>) => Input;
432
- };
433
- type FacetVariable<Value extends DimensionValue, Context extends VariableCollection, Name extends string, Input> = DimensionSelectionVariable<Value> & {
434
- readonly optionsSource: 'query';
435
- readonly [facetSource]: FacetSourceDefinition<Context, Name, Input>;
436
- };
549
+ //#region src/core/operation-filters.d.ts
550
+ /** The value an operation receives for one filter: date filters arrive resolved. */
551
+ type FilterInputValue<Filter> = Filter extends DateTimeRangeFilter ? DateTimeRangeInput : FilterValues<{
552
+ value: Filter;
553
+ }>['value'];
554
+ /** An operation's input: one flat field per declared filter. */
555
+ type FilterInput<Filters extends FilterCollection> = keyof Filters extends never ? Record<string, never> : { [Name in keyof Filters]: FilterInputValue<Filters[Name]>; };
556
+ /** Exactly the date filters, so a view knows which one sets its reporting period. */
557
+ type DateFilterNames<Filters extends FilterCollection> = { [Name in keyof Filters]: Filters[Name] extends DateTimeRangeFilter ? Name : never; }[keyof Filters];
558
+ /** Filters are a literal record of known names, and at most one is a date filter:
559
+ * it sets the view's reporting period. */
560
+ type CheckedOperationFilters<Filters extends FilterCollection> = Filters & (string extends keyof Filters ? {
561
+ 'Declare the filters an operation reads as an object literal': never;
562
+ } : unknown) & ([DateFilterNames<Filters>] extends [never] ? unknown : true extends IsUnion<DateFilterNames<Filters>> ? {
563
+ 'An operation reads at most one date filter': never;
564
+ } : unknown);
565
+ /** The name of the operation's date filter, which sets its reporting period. */
566
+ declare function dateFilterName(filters: FilterCollection): string | undefined;
567
+ /** Resolve URL selections to the request the browser sends. Relative date ranges
568
+ * resolve against one reference time so the range and its comparison agree. */
569
+ declare function resolveFilterInput<Filters extends FilterCollection>(filters: Filters, values: FilterValues<Filters>, reference?: Date): FilterInput<Filters>;
570
+ /** Every operation in an app shares one filter per name and one owner per URL key. */
571
+ declare function combineOperationFilters(operations: Readonly<Record<string, FilterCollection>>): FilterCollection;
437
572
  //#endregion
438
- //#region src/core/dimension.d.ts
439
- type DimensionValue = string | number;
440
- type DimensionMember<T extends DimensionValue = DimensionValue> = {
441
- kind: 'value';
442
- value: T;
443
- } | {
444
- kind: 'missing';
445
- };
446
- type DimensionSelection<T extends DimensionValue = DimensionValue> = {
447
- kind: 'all';
448
- } | {
449
- kind: 'include' | 'exclude';
450
- members: readonly DimensionMember<T>[];
451
- };
452
- type DimensionOption<T extends DimensionValue = DimensionValue> = {
453
- value: T;
454
- label: string;
455
- count?: number;
456
- };
457
- type DimensionSelectionVariable<T extends DimensionValue = DimensionValue> = AppVariable<DimensionSelection<T>, 'dimension'> & {
458
- readonly optionsSource: 'fixed' | 'query';
459
- label: string;
460
- selectionMode: 'single' | 'multiple';
461
- readonly valueType: T extends number ? 'number' : 'string';
462
- allowMissing: boolean;
463
- allowExclusion: boolean;
464
- maxSelected: number;
465
- options: readonly DimensionOption<T>[];
466
- describe: (selection: DimensionSelection<T>, options?: readonly DimensionOption<T>[]) => string;
467
- };
468
- /** A fixed-option dimension retains its distinction from query-backed facets. */
469
- type DimensionVariable<T extends DimensionValue = DimensionValue> = DimensionSelectionVariable<T> & {
470
- readonly optionsSource: 'fixed';
471
- readonly [facetSource]?: never;
472
- };
473
- declare function dimensionMemberKey(member: DimensionMember): string;
474
- type DimensionSettings = {
475
- key: string;
476
- label: string;
477
- allowMissing?: boolean;
478
- allowExclusion?: boolean;
479
- history?: HistoryMode;
480
- presentation?: VariablePresentation;
481
- } & ({
482
- selectionMode: 'single';
483
- maxSelected?: 1;
484
- } | {
485
- selectionMode: 'multiple';
486
- maxSelected?: number;
487
- });
488
- type DimensionFilterSettings<T extends DimensionValue> = DimensionSettings & {
489
- valueType: T extends number ? 'number' : 'string';
490
- };
491
- type DimensionFilterOptions<T extends DimensionValue> = DimensionFilterSettings<T> & {
492
- options: readonly DimensionOption<T>[];
493
- facet?: never;
573
+ //#region src/core/facet-filter.d.ts
574
+ type FacetFilterOptions<Value extends DimensionValue, Operation extends string> = DimensionFilterSettings<Value> & {
575
+ /** The registered operation that returns this dimension's options. */
576
+ options: Operation;
577
+ };
578
+ /** Options load from `options`, an operation returning `DimensionOption[]`; the
579
+ * client checks that it is registered. Validate selections like any dimension. */
580
+ declare function facetFilter<const Operation extends string>(config: FacetFilterOptions<string, Operation> & {
581
+ valueType: 'string';
582
+ }): FacetFilter<string, Operation>;
583
+ declare function facetFilter<const Operation extends string>(config: FacetFilterOptions<number, Operation> & {
584
+ valueType: 'number';
585
+ }): FacetFilter<number, Operation>;
586
+ //#endregion
587
+ //#region src/core/date-time-range-sql.d.ts
588
+ /** Bind a resolved filter range as timestamp strings for literal DuckDB SQL.
589
+ * Dates carry reporting-zone wall-clock fields in UTC; omit `Z` for TIMESTAMP casts. */
590
+ declare function resolvedDateTimeRangeParams<const Prefix extends string>(range: ResolvedDateTimeRange, prefix: Prefix): Record<`${Prefix}_from` | `${Prefix}_to`, string>;
591
+ /** DuckDB timestamp expressions using the query session's timezone for relative anchors.
592
+ * Absolute fields remain UTC-rebased TIMESTAMP values. Start is inclusive, end exclusive.
593
+ */
594
+ declare function dateTimeRangeSql(range: DateTimeRange, parameter?: string): {
595
+ from: string;
596
+ to: string;
597
+ params: Record<string, string>;
494
598
  };
495
- /** A bounded categorical filter with app-owned fixed options. */
496
- declare function dimensionFilter<const T extends string>(config: DimensionFilterOptions<T>): DimensionVariable<T>;
497
- declare function dimensionFilter<const T extends number>(config: DimensionFilterOptions<T>): DimensionVariable<T>;
498
- /** Shared fixed-option and query-backed selection behavior. */
499
- declare function createDimensionFilter<const T extends DimensionValue>(config: DimensionFilterSettings<T> & {
500
- options: readonly DimensionOption<T>[];
501
- }, dynamic?: boolean): DimensionSelectionVariable<T>;
502
- /** Server-side parser; call from the operation input parser before building SQL. */
503
- declare function parseDimensionSelection<T extends DimensionValue>(value: unknown, filter: DimensionSelectionVariable<T>): DimensionSelection<T>;
504
- /** Validate bounded facet results before showing them in a picker. */
505
- declare function parseFacetOptions<T extends DimensionValue>(value: unknown, filter: DimensionSelectionVariable<T>): DimensionOption<T>[];
506
- /** Central SQL literal encoding for transports without bound parameters. Column is an allowlisted identifier. */
507
- declare function dimensionPredicate<T extends DimensionValue, const Columns extends readonly string[]>(column: Columns[number], selection: DimensionSelection<T>, allowedColumns: Columns): string;
508
599
  //#endregion
509
600
  //#region src/authoring/contract.d.ts
510
- declare function parseEmptyInput(value: unknown): Record<string, never>;
511
601
  declare function parseTrue(value: unknown): true;
512
602
  type ReportingPeriod = {
513
603
  kind: 'rolling';
@@ -520,37 +610,6 @@ type ReportingPeriod = {
520
610
  end: string;
521
611
  timeZone: string;
522
612
  };
523
- type DateRangeContractOptions = {
524
- minDate?: string;
525
- maxDate?: string | (() => string);
526
- maxRangeDays: number;
527
- timeZone: string;
528
- /** Defaults to complete days through yesterday in the reporting timezone. Set false to include today. */
529
- completeDays?: boolean;
530
- };
531
- /** One source policy for datetime picker validation and operation requests. */
532
- declare function defineDateRangeContract({ minDate, maxDate, maxRangeDays, timeZone, completeDays }: DateRangeContractOptions): {
533
- datetime: {
534
- timeZone: string;
535
- bounds: (now?: Date) => {
536
- minDate: string | undefined;
537
- maxDate: string;
538
- maxRangeDays: number;
539
- timeZone: string;
540
- };
541
- parse: (value: unknown, now?: Date) => DateTimeRange;
542
- resolve: (value: unknown, now?: Date) => DateTimeRangeRequest['range'];
543
- comparison: (value: unknown, now?: Date) => DateTimeRangeRequest['comparison'];
544
- request(value: unknown, compare?: boolean, now?: Date): DateTimeRangeRequest;
545
- };
546
- bounds: (now?: Date) => {
547
- minDate: string | undefined;
548
- maxDate: string;
549
- maxRangeDays: number;
550
- timeZone: string;
551
- };
552
- };
553
- type DateRangeContract = ReturnType<typeof defineDateRangeContract>;
554
613
  /** Accepts numeric strings from DuckDB; rejects negative, fractional, and unsafe integers. */
555
614
  declare function parseCount(value: unknown): number;
556
615
  declare function parseLabel(value: unknown, maxLength?: number): string;
@@ -563,19 +622,50 @@ type QueryLimit<Limit extends number> = number extends Limit ? number : `${Limit
563
622
  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?: {
564
623
  limit?: Limit & QueryLimit<NoInfer<Limit>>;
565
624
  }) => Promise<QueryResult<QueryRow<Queries[Name]['projections']>>>;
566
- /** Infer operation data from run(). */
567
- type OperationDefinition<Input, Output, Queries extends QueryDefinitions> = Omit<DataOperation<Input, Output>, 'run' | 'queryNames'> & {
568
- run: (context: Pick<OperationContext, 'signal'> & {
569
- query: RegisteredQuery<NoInfer<Queries>>;
570
- }, input: Input) => Promise<Output>;
625
+ type OperationRun<Input, Output, Queries extends QueryDefinitions> = (context: Pick<OperationContext, 'signal'> & {
626
+ query: RegisteredQuery<NoInfer<Queries>>;
627
+ }, input: Input) => Promise<Output>;
628
+ type OperationPolicy = DataOperation<unknown, unknown>['policy'];
629
+ /** An operation that reads app filters. Its input has one field per filter, validated by
630
+ * the filters themselves; views derive their filters, scope, and period from it. */
631
+ type FilterOperationDefinition<Filters extends FilterCollection, Output, Queries extends QueryDefinitions> = {
632
+ /** The filters `run` reads. Omit for an operation without inputs. */
633
+ filters?: CheckedOperationFilters<Filters>;
634
+ input?: never;
635
+ checks?: never;
636
+ policy: OperationPolicy;
637
+ run: OperationRun<FilterInput<Filters>, Output, Queries>;
638
+ };
639
+ /** An operation with its own input, such as a detail destination's record id. It may
640
+ * also read filters, such as the displayed scope it lists records for. */
641
+ type InputOperationDefinition<Input, Output, Queries extends QueryDefinitions, Filters extends FilterCollection = {}> = {
642
+ /** Filters the operation reads beside its own input; they are parsed for it. */
643
+ filters?: CheckedOperationFilters<Filters>;
644
+ /** Parses the operation's own fields, without the filters. */
645
+ input: (value: unknown) => Input;
646
+ /** Representative valid own inputs; each must pass `input`. */
647
+ checks: readonly [Input, ...Input[]];
648
+ policy: OperationPolicy;
649
+ run: OperationRun<WithFilterInput<Filters, Input>, Output, Queries>;
571
650
  };
572
- declare function defineOperation<Input, Output, const Queries extends QueryDefinitions>(operation: OperationDefinition<Input, Output, Queries> & {
573
- queries: CheckedQueries<Queries>;
574
- }): Omit<DataOperation<Input, Output>, 'queryNames'> & {
651
+ /** The full input of an operation with its own fields and optional filters. */
652
+ type WithFilterInput<Filters extends FilterCollection, Input> = keyof Filters extends never ? Input : FilterInput<Filters> & Input;
653
+ type DefinedOperation<Input, Output, Queries extends QueryDefinitions, Filters extends FilterCollection | undefined = undefined> = Omit<DataOperation<Input, Output>, 'queryNames' | 'filters'> & {
575
654
  queryNames: { readonly [Name in keyof Queries & string]: Name; };
576
- };
655
+ } & (Filters extends FilterCollection ? {
656
+ readonly filters: Filters;
657
+ } : {
658
+ readonly filters?: never;
659
+ });
660
+ declare function defineOperation<Input, Output, const Queries extends QueryDefinitions, const Filters extends FilterCollection = {}>(operation: InputOperationDefinition<Input, Output, Queries, Filters> & {
661
+ queries: CheckedQueries<Queries>;
662
+ }): DefinedOperation<WithFilterInput<Filters, Input>, Output, Queries, keyof Filters extends never ? undefined : Filters>;
663
+ declare function defineOperation<const Queries extends QueryDefinitions, const Filters extends FilterCollection = {}, Output = unknown>(operation: FilterOperationDefinition<Filters, Output, Queries> & {
664
+ queries: CheckedQueries<Queries>;
665
+ }): DefinedOperation<FilterInput<Filters>, Output, Queries, Filters>;
577
666
  /** The built-in connection operation shares one contract with setup clients. */
578
- type ConnectionOperation = Omit<DataOperation<Record<string, never>, true>, 'queryNames'> & {
667
+ type ConnectionOperation = Omit<DataOperation<Record<string, never>, true>, 'queryNames' | 'filters'> & {
668
+ readonly filters: {};
579
669
  queryNames: {
580
670
  readonly connection: 'connection';
581
671
  };
@@ -585,5 +675,199 @@ declare function connectionCheck<const Queries extends QueryDefinitions & {
585
675
  connection: QueryDefinitions[string];
586
676
  }>(queries: CheckedQueries<Queries>): ConnectionOperation;
587
677
  //#endregion
588
- export { NumberSelection as $, facetSource as A, QuerySnapshot as At, VariablePresentation as B, OperationContracts as Bt, createDimensionFilter as C, QueryDefinitions as Ct, parseDimensionSelection as D, QueryParameters as Dt, dimensionPredicate as E, QueryParameterValue as Et, ChoiceOption as F, DataQueryInput as Ft, validateChoiceOptions as G, DateTimeRangeRequest as Gt, defineAppVariables as H, QueryResult as Ht, ChoiceVariable as I, DisclosedQuery as It, NavigationUpdate as J, AppLocation as K, MultiChoiceVariable as L, InputOf as Lt, AppVariableValues as M, DataOperation as Mt, CheckedFacetContexts as N, DataOperations as Nt, parseFacetOptions as O, QueryProjections as Ot, CheckedVariableDeclarations as P, DataQueryBody as Pt, NumberOperator as Q, SearchVariable as R, Lakehouse as Rt, DimensionVariable as S, MAX_QUERY_ROWS as St, dimensionMemberKey as T, QueryParameter as Tt, multiChoiceVariable as U, TransportResponse as Ut, choiceVariable as V, OutputOf as Vt, searchVariable as W, DateTimeRangeContract as Wt, BooleanSelection as X, BooleanFilter as Y, NumberFilter as Z, DimensionMember as _, dateTimeRangePresets as _t, RegisteredQuery as a, DimensionSourceConfig as at, DimensionSelectionVariable as b, IsUnion as bt, defineDateRangeContract as c, dimensionSource as ct, parseCount as d, DateTimeRangeComparisonSelection as dt, booleanFilter as et, parseEmptyInput as f, DateTimeRangeComparisonVariable as ft, DimensionFilterSettings as g, DateTimeRangeVariableOptions as gt, DimensionFilterOptions as h, DateTimeRangeVariable as ht, OperationDefinition as i, parseNumberSelection as it, AppVariable as j, QueryValueType as jt, FacetVariable as k, QueryRow as kt, defineOperation as l, variableInput as lt, parseTrue as m, DateTimeRangePreset as mt, DateRangeContract as n, numberOperatorLabels as nt, ReportingPeriod as o, DimensionSourceQueryName as ot, parseLabel as p, DateTimeRangeComparisonVariableOptions as pt, HistoryMode as q, DateRangeContractOptions as r, parseBooleanSelection as rt, connectionCheck as s, SourceDimensionVariable as st, ConnectionOperation as t, numberFilter as tt, defineQueryNames as u, DateTimeRangeComparisonRequest as ut, DimensionOption as v, dateTimeRangeVariable as vt, dimensionFilter as w, QueryField as wt, DimensionValue as x, KnownRecord as xt, DimensionSelection as y, CheckedQueries as yt, VariableCollection as z, OperationContext as zt };
678
+ //#region src/core/messages.d.ts
679
+ type MessageContext = {
680
+ signal: AbortSignal;
681
+ };
682
+ type RoutedMessage = {
683
+ route: string;
684
+ payload: unknown;
685
+ };
686
+ type MessageDispatcher = (message: unknown, context: MessageContext) => Promise<unknown>;
687
+ type MessageTransport = (message: RoutedMessage, signal?: AbortSignal) => Promise<unknown>;
688
+ type MessageRoute<Input, Output> = {
689
+ input: (value: unknown) => Input;
690
+ output: (value: unknown, input: Input) => Output;
691
+ };
692
+ type MessageRoutes = Record<string, {
693
+ input: (value: unknown) => unknown;
694
+ output: (value: unknown, input: never) => unknown;
695
+ }>;
696
+ type MessageInput<Route extends MessageRoutes[string]> = ReturnType<Route['input']>;
697
+ type MessageHandlers<Routes extends MessageRoutes> = { [Name in keyof Routes]: (payload: MessageInput<Routes[Name]>, context: MessageContext) => ReturnType<Routes[Name]['output']> | Promise<ReturnType<Routes[Name]['output']>>; };
698
+ declare const errorBrand: unique symbol;
699
+ /** Only these deliberate, public failures cross the message boundary. Other errors stay private. */
700
+ declare class MessageRoutingError extends Error {
701
+ readonly code: string;
702
+ readonly requestId?: string | undefined;
703
+ readonly [errorBrand] = true;
704
+ static [Symbol.hasInstance](value: unknown): boolean;
705
+ constructor(code: string, message: string, requestId?: string | undefined,
706
+ /** `cause` stays with the host for logs; the bridge sends only code, message, and request ID. */
707
+ options?: ErrorOptions);
708
+ }
709
+ declare function defineMessageRoute<Input, Output>(route: MessageRoute<Input, Output>): MessageRoute<Input, Output>;
710
+ /** Contracts are shared; handlers are supplied by the host and never belong in the app bundle. */
711
+ declare function createMessageRouter<const Routes extends MessageRoutes>(routes: Routes, handlers: MessageHandlers<NoInfer<Routes>>): {
712
+ dispatch: (value: unknown, context: MessageContext) => Promise<unknown>;
713
+ };
714
+ type DataOperationRoute<Operations extends OperationContracts> = MessageRoute<DataQueryInput<Operations>, TransportResponse> & {
715
+ operations: Operations | undefined;
716
+ };
717
+ type MessageOutput<Route extends MessageRoutes[string], Input> = Route extends DataOperationRoute<infer Operations> ? Input extends {
718
+ operation: infer Name extends keyof Operations;
719
+ } ? TransportResponse<DataQueryBody<OutputOf<Operations[Name]>>> : never : ReturnType<Route['output']>;
720
+ /** Omit contracts only in generic hosts such as the CLI shell, where Bun validates operations. */
721
+ declare function defineDataOperationRoute<Operations extends OperationContracts = OperationContracts>(operations?: Operations): DataOperationRoute<Operations>;
722
+ declare const navigationUpdateRoute: MessageRoute<NavigationUpdate, null>;
723
+ type RegisteredQueryInput = {
724
+ queryId: string;
725
+ limit: number;
726
+ params?: QueryParameters;
727
+ };
728
+ /** Run a SQL query already registered by the app's defineDataApp manifest. */
729
+ declare const registeredQueryRoute: MessageRoute<RegisteredQueryInput, QueryResult>;
730
+ declare const dataAppRoutes: {
731
+ 'data:query': MessageRoute<RegisteredQueryInput, QueryResult>;
732
+ 'navigation:update': MessageRoute<NavigationUpdate, null>;
733
+ };
734
+ //#endregion
735
+ //#region src/core/annotations.d.ts
736
+ type DataAppAnnotationDraft = {
737
+ id: string;
738
+ target: {
739
+ id: string;
740
+ label: string;
741
+ kind: 'widget' | 'element' | 'app';
742
+ text: string;
743
+ queryNames: string[];
744
+ glossaryIds: string[];
745
+ };
746
+ context: {
747
+ search: string;
748
+ hash: string;
749
+ displayedInput?: unknown;
750
+ /** Normalized position within the selected target, stable across scrolling/resizing. */
751
+ anchor?: {
752
+ x: number;
753
+ y: number;
754
+ };
755
+ cursor?: {
756
+ x: number;
757
+ y: number;
758
+ };
759
+ /** Normalized custom selection rectangle within the iframe document. */
760
+ region?: {
761
+ x: number;
762
+ y: number;
763
+ width: number;
764
+ height: number;
765
+ };
766
+ screenshot?: {
767
+ mimeType: 'image/png';
768
+ dataUrl: string;
769
+ width: number;
770
+ height: number;
771
+ };
772
+ view?: string;
773
+ viewport: {
774
+ width: number;
775
+ height: number;
776
+ };
777
+ rect: {
778
+ x: number;
779
+ y: number;
780
+ width: number;
781
+ height: number;
782
+ };
783
+ };
784
+ comment: string;
785
+ };
786
+ type DataAppAnnotationPresentation = {
787
+ enabled: boolean;
788
+ /** When provided, the host owns the mode and renders the annotation trigger.
789
+ * Without an in-frame toolbar, as on embedded surfaces, the host always owns it; omitted means inactive. */
790
+ active?: boolean;
791
+ pinsVisible?: boolean;
792
+ showHint?: boolean;
793
+ readOnly?: boolean;
794
+ targets?: {
795
+ id: string;
796
+ targetId: string;
797
+ number: number;
798
+ comment?: string;
799
+ anchor?: {
800
+ x: number;
801
+ y: number;
802
+ };
803
+ region?: {
804
+ x: number;
805
+ y: number;
806
+ width: number;
807
+ height: number;
808
+ };
809
+ }[];
810
+ selectedAnnotationId?: string;
811
+ selectedTargetId?: string;
812
+ selectionId?: string;
813
+ /** Confirmed host click outside the iframe; occurredAt is epoch milliseconds. */
814
+ dismissal?: {
815
+ id: string;
816
+ occurredAt: number;
817
+ };
818
+ };
819
+ /** Reconstruct at the boundary; discard extra fields and bound the entire JSON payload. */
820
+ declare function parseDataAppAnnotationDraft(value: unknown): DataAppAnnotationDraft;
821
+ declare const annotationDraftRoute: MessageRoute<DataAppAnnotationDraft, null>;
822
+ declare const annotationEditorStateRoute: MessageRoute<{
823
+ hasUnsavedChanges: boolean;
824
+ }, null>;
825
+ /** Request host-owned batch submission without transferring ownership of drafts. */
826
+ declare const annotationSendRoute: MessageRoute<null, null>;
827
+ declare const annotationUpdateRoute: MessageRoute<{
828
+ id: string;
829
+ comment: string;
830
+ }, null>;
831
+ /** A controlled shell acknowledges local exits (for example Escape). */
832
+ declare const annotationModeRoute: MessageRoute<{
833
+ active: boolean;
834
+ }, null>;
835
+ //#endregion
836
+ //#region src/core/external-link.d.ts
837
+ /** Absolute HTTPS destinations only; URLs must not contain embedded credentials. */
838
+ declare function parseExternalUrl(value: unknown): string;
839
+ type ExternalLinkTarget = 'tab' | 'window';
840
+ type ExternalLinkModifiers = {
841
+ shiftKey: boolean;
842
+ metaKey: boolean;
843
+ ctrlKey: boolean;
844
+ };
845
+ type OpenExternalLink = {
846
+ url: string;
847
+ } & ({
848
+ target?: ExternalLinkTarget;
849
+ } | {
850
+ target: 'event';
851
+ keys: ExternalLinkModifiers;
852
+ });
853
+ type ExternalLinkResult = 'opened' | 'cancelled' | 'ignored';
854
+ /** Shift takes precedence over Ctrl/Cmd; an unmodified event requests no navigation. */
855
+ declare function resolveExternalLinkTarget(input: OpenExternalLink): ExternalLinkTarget | null;
856
+ /** Opt-in host route. Validation does not replace the host's destination policy. */
857
+ declare const openExternalLinkRoute: MessageRoute<OpenExternalLink, ExternalLinkResult>;
858
+ //#endregion
859
+ //#region src/core/contract.d.ts
860
+ declare const sourceErrorBrand: unique symbol;
861
+ declare class DataSourceError extends Error {
862
+ readonly reason: 'unauthorized' | 'forbidden' | 'rate_limited' | 'query_rejected' | 'unavailable';
863
+ readonly status?: number | undefined;
864
+ readonly [sourceErrorBrand] = true;
865
+ queryName?: string;
866
+ static [Symbol.hasInstance](value: unknown): boolean;
867
+ constructor(reason: 'unauthorized' | 'forbidden' | 'rate_limited' | 'query_rejected' | 'unavailable', status?: number | undefined,
868
+ /** `cause` stays on the server or host for logs; responses carry only the reason. */
869
+ options?: ErrorOptions);
870
+ }
871
+ //#endregion
872
+ export { dateFilterName as $, QueryParameter as $t, dataAppRoutes as A, dateTimeRangePresets as An, DimensionSourceQueryName as At, ReportingPeriod as B, Lakehouse as Bt, MessageRoute as C, DateTimeRangeComparison as Cn, NumberSelection as Ct, RegisteredQueryInput as D, DateTimeRangeRequest as Dn, parseBooleanSelection as Dt, MessageTransport as E, DateTimeRangePreset as En, numberOperatorLabels as Et, ConnectionOperation as F, DataQueryBody as Ft, parseCount as G, SqlLakehouse as Gt, connectionCheck as H, OperationContracts as Ht, DefinedOperation as I, DataQueryInput as It, dateTimeRangeSql as J, IsUnion as Jt, parseLabel as K, TransportResponse as Kt, FilterOperationDefinition as L, DisclosedQuery as Lt, defineMessageRoute as M, DateTimeRangeInput as Mn, dimensionSource as Mt, navigationUpdateRoute as N, DateTimeRangePolicy as Nn, DataOperation as Nt, RoutedMessage as O, DateTimeRangeSelection as On, parseNumberSelection as Ot, registeredQueryRoute as P, DataOperations as Pt, combineOperationFilters as Q, QueryField as Qt, InputOperationDefinition as R, HostedLakehouse as Rt, MessageOutput as S, facetSource as Sn, NumberOperator as St, MessageRoutingError as T, DateTimeRangeFilterOptions as Tn, numberFilter as Tt, defineOperation as U, OutputOf as Ut, WithFilterInput as V, OperationContext as Vt, defineQueryNames as W, QueryResult as Wt, facetFilter as X, MAX_QUERY_ROWS as Xt, resolvedDateTimeRangeParams as Y, KnownRecord as Yt, FilterInput as Z, QueryDefinitions as Zt, DataOperationRoute as _, dimensionMemberKey as _n, HistoryMode as _t, OpenExternalLink as a, QueryValueType as an, FilterCollection as at, MessageHandlers as b, parseFacetOptions as bn, BooleanSelection as bt, resolveExternalLinkTarget as c, DimensionFilterOptions as cn, MultiChoiceFilter as ct, annotationDraftRoute as d, DimensionOption as dn, defineAppFilters as dt, QueryParameterValue as en, resolveFilterInput as et, annotationEditorStateRoute as f, DimensionSelection as fn, displayChoice as ft, parseDataAppAnnotationDraft as g, dimensionFilter as gn, AppLocation as gt, annotationUpdateRoute as h, createDimensionFilter as hn, validateChoiceOptions as ht, ExternalLinkTarget as i, QuerySnapshot as in, ChoiceOption as it, defineDataOperationRoute as j, queryDateTimeRangeParams as jn, SourceDimensionFilter as jt, createMessageRouter as k, dateTimeRangeFilter as kn, DimensionSourceConfig as kt, DataAppAnnotationDraft as l, DimensionFilterSettings as ln, SearchFilter as lt, annotationSendRoute as m, DimensionValue as mn, searchFilter as mt, ExternalLinkModifiers as n, QueryProjections as nn, CheckedFilterDeclarations as nt, openExternalLinkRoute as o, REGISTERED_QUERY_ID_PATTERN as on, FilterPresentation as ot, annotationModeRoute as p, DimensionSelectionFilter as pn, multiChoiceFilter as pt, parseTrue as q, CheckedQueries as qt, ExternalLinkResult as r, QueryRow as rn, ChoiceFilter as rt, parseExternalUrl as s, DimensionFilter as sn, FilterValues as st, DataSourceError as t, QueryParameters as tn, AppFilter as tt, DataAppAnnotationPresentation as u, DimensionMember as un, choiceFilter as ut, MessageContext as v, dimensionPredicate as vn, NavigationUpdate as vt, MessageRoutes as w, DateTimeRangeFilter as wn, booleanFilter as wt, MessageInput as x, FacetFilter as xn, NumberFilter as xt, MessageDispatcher as y, parseDimensionSelection as yn, BooleanFilter as yt, RegisteredQuery as z, InputOf as zt };
589
873
  //# sourceMappingURL=contract.d.ts.map