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