@holistics/anfra-sdk 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holistics/anfra-sdk",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Data Apps on anfra: the authoring layer (app), what hosts one (host), the core API client (api), and their shared contract (common)",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -1,645 +0,0 @@
1
- /**
2
- * The aggregations a *filter* may carry — a narrower set than a measure may, for two reasons.
3
- *
4
- * The `running *` four are window functions, and the compiler discards a result-field filter whose
5
- * fragment still carries `hasWindowFunction`: silently, leaving the rows unfiltered. A rejection
6
- * here is the only place that failure is visible.
7
- *
8
- * `custom` means "the field defines its own aggregation", which a filter never needs to say. A
9
- * dataset-level metric is rejected outright below, and a model field that is already a measure
10
- * routes through the aggregated branch on its own. The wire accepts `custom` regardless — the
11
- * dashboard path sends it for a metric — so this is an SDK narrowing, not a transport limit.
12
- *
13
- * Declared `satisfies readonly Aggregation[]` so the subset relationship is checked rather than
14
- * asserted, and the type below is derived from the one list the runtime check uses.
15
- */
16
- declare const FILTER_AGGREGATIONS: readonly ["sum", "avg", "max", "min", "count", "count distinct", "median", "stdev", "stdevp", "var", "varp"];
17
- type FilterAggregation = typeof FILTER_AGGREGATIONS[number];
18
-
19
- /**
20
- * Public types. Nothing here may leak an internal wire shape: `VizSetting` in particular is never
21
- * part of this surface, and the query API's payload shapes are built in `execution/submitQuery.ts`
22
- * rather than exposed. See docs/adr/0001.
23
- */
24
-
25
- /**
26
- * Metadata for one dataset, supplied by the provisioner. The SDK owns this type, so a provisioner
27
- * needs no particular metadata library to build one.
28
- */
29
- interface DatasetDescriptor {
30
- id: string | number;
31
- name: string;
32
- label?: string;
33
- data_models: {
34
- id: string | number;
35
- name: string;
36
- label?: string;
37
- fields: {
38
- name: string;
39
- label?: string;
40
- type: string;
41
- is_custom_measure: boolean;
42
- defined_in_dataset?: boolean;
43
- }[];
44
- }[];
45
- metrics: {
46
- name: string;
47
- label?: string;
48
- type: string;
49
- }[];
50
- }
51
- /**
52
- * Who the app is running as, supplied by the provisioner.
53
- *
54
- * Every field is copied across deliberately. The provisioner holds a much larger current-user
55
- * record (personal settings, client IP, shared dataset ids, tokens) and none of it belongs in
56
- * front of author code, so this is an allowlist rather than a projection of that record.
57
- *
58
- * Note what this is *not*: it does not authorise anything. Queries are re-authorised server-side
59
- * on every call, so `permissions` here is a rendering hint — an app that ignores it renders a
60
- * button that returns blank values, not a leak.
61
- */
62
- interface User {
63
- id: number;
64
- name: string;
65
- /** The external address for an embed user, whose internal one names nothing they'd recognise. */
66
- email: string;
67
- /** Free-form rather than a union: the role set is the host's to change, not this package's. */
68
- role: string;
69
- /**
70
- * The user's reporting timezone. Available, but not a default: an app that declares no timezone
71
- * still sends none and lets the server apply the tenant's. See `AppDeclaration.timezone`.
72
- */
73
- timezone: string;
74
- permissions: {
75
- canViewGeneratedSql: boolean;
76
- canExportData: boolean;
77
- };
78
- }
79
- /**
80
- * Server-side capabilities the host knows about, so a declaration can fail loudly instead of
81
- * silently.
82
- *
83
- * `dateDrill` mirrors `interactive_control:date_drill`: with it off the `transform_date_drill`
84
- * condition still reaches the server, which ignores it and answers at the declared grain. Every
85
- * request succeeds and the grain silently never changes.
86
- */
87
- interface SdkFeatures {
88
- dateDrill?: boolean;
89
- /**
90
- * Whether the host can export a query's result (`query.export()`): its Backend has
91
- * `exportQuery`. `mountDataApp` says so for every frame; `createSdk` reads it off the Backend
92
- * when the host does not. An author shows an export button when this and
93
- * `user.permissions.canExportData` are both true.
94
- */
95
- export?: boolean;
96
- /**
97
- * Whether `Anfra.render()` can save a rendering here: the host turned it on
98
- * (`mountDataApp({ render: true })`). An author shows a render button when this and
99
- * `user.permissions.canExportData` are both true.
100
- */
101
- render?: boolean;
102
- }
103
- interface SdkEnvironment {
104
- datasets: Record<string, DatasetDescriptor>;
105
- user: User;
106
- /** Where queries and field suggestions go. The SDK knows nothing about the server behind it. */
107
- backend: Backend;
108
- /** Absent means the host did not say, and nothing is blocked; only an explicit `false` throws. */
109
- features?: SdkFeatures;
110
- /** Draws and saves a rendering: given by the frame bootstrap, which can reach the page and the host. */
111
- render?: (request: RenderRequest) => Promise<Rendering>;
112
- }
113
- /** A rendering's file format. A PDF is one page the size of the rendering. */
114
- type RenderFormat = 'png' | 'pdf';
115
- /**
116
- * What to render, and how. `block` or `container` names one node of the structure by its id;
117
- * neither renders the whole app.
118
- */
119
- interface RenderRequest {
120
- block?: string;
121
- container?: string;
122
- format: RenderFormat;
123
- /** The file's name, with the format's extension added when it has none. */
124
- filename?: string;
125
- /** Device pixels per CSS pixel. Defaults to the screen's, at least 2, lowered to fit a canvas. */
126
- pixelRatio?: number;
127
- }
128
- /** A picture of the app, or of one node, as the reader saw it: saved for them, and handed back. */
129
- interface Rendering {
130
- filename: string;
131
- format: RenderFormat;
132
- /** In CSS pixels: what was drawn, before `pixelRatio`. */
133
- width: number;
134
- height: number;
135
- blob: Blob;
136
- /**
137
- * Images left blank in the picture, by URL: their servers send no CORS headers, so the browser
138
- * won't let them be drawn. Their space is kept. Empty when nothing was left out.
139
- */
140
- omitted: string[];
141
- }
142
- type ConditionValue = string | number | boolean;
143
- /**
144
- * Mirrors the operator discriminator of the public query API, in full — including operators no
145
- * control constructs. `transform_date_drill` is what `createDateDrill` spells so an author never
146
- * has to; the `transform_pop_*` family has no constructor here at all and is reachable only by
147
- * writing the condition out, which is the point of mirroring the published list rather than the
148
- * subset this package happens to build.
149
- */
150
- type Operator = 'is' | 'is_not' | 'is_null' | 'not_null' | 'greater_than' | 'less_than' | 'between' | 'contains' | 'does_not_contain' | 'starts_with' | 'ends_with' | 'matches' | 'is_true' | 'is_false' | 'last' | 'next' | 'before' | 'after' | 'matches_user_attribute' | 'transform_pop_relative' | 'transform_pop_absolute' | 'transform_pop_none' | 'transform_date_drill' | 'none';
151
- interface Condition {
152
- operator: Operator;
153
- values?: ConditionValue[];
154
- /** Date unit for relative operators (`last`, `next`, `transform_pop_relative`). */
155
- modifier?: string;
156
- }
157
- type DateGrain = 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute';
158
- type DateTransformation = `datetrunc ${DateGrain}`;
159
- type Aggregation = 'sum' | 'avg' | 'max' | 'min' | 'count' | 'count distinct' | 'median' | 'stdev' | 'stdevp' | 'var' | 'varp' | 'running sum' | 'running avg' | 'running max' | 'running min' | 'custom';
160
- /**
161
- * A query is a dataset and a raw AQL body — nothing else. The SDK does not parse or validate the
162
- * AQL: a syntax error, an unknown field, or an ambiguous name surfaces as a `QueryError` at
163
- * execute, not as a `ValidationError` here. See docs/adr/0001.
164
- *
165
- * Everything the AQL text can say — dimensions, measures, adhoc fields, static filters, its own
166
- * sort or limit — belongs in the AQL. `pageSize` is the one exception: paging through a result is
167
- * a viewer interaction, not part of what the query means, so it is declared here rather than
168
- * re-authored on every page turn. A query that declares none isn't paged and gets every row.
169
- *
170
- * ```ts
171
- * app.createQuery('revenue', {
172
- * dataset: 'sales',
173
- * aql: `
174
- * explore {
175
- * dimensions { month: date_trunc(orders.created_at, "month") }
176
- * measures { total: orders | sum(orders.amount) }
177
- * filters { orders.status is "completed" }
178
- * }
179
- * `,
180
- * });
181
- * ```
182
- */
183
- interface QueryDeclaration {
184
- dataset: string;
185
- aql: string;
186
- /**
187
- * Rows per page, a whole number of at least 1. Past the first page, use `fetchMore()`. Leave it
188
- * out to get every row in one result. anfra can't page a pivot query (`rows { }` / `columns { }`),
189
- * so a pivot query must not declare one.
190
- */
191
- pageSize?: number;
192
- }
193
- /**
194
- * A sort applied to a query's result, independent of the query itself — the same mechanism a
195
- * click on a table's column header uses, and one that never re-runs the query against the
196
- * warehouse. `field` is a result column name, as `ColumnMeta.name` reports it, not a field
197
- * reference. See docs/adr/0001.
198
- */
199
- interface QuerySort {
200
- field: string;
201
- direction?: 'asc' | 'desc';
202
- }
203
- type FilterValueType = 'string' | 'number' | 'date' | 'boolean';
204
- interface FilterDeclaration {
205
- /** Present for a field-backed filter: where options come from. Absent means a manual filter. */
206
- field?: string;
207
- /** Required for a manual filter; inferred from `field` otherwise. */
208
- type?: FilterValueType;
209
- /** Static option list for a manual filter. Absent or empty means free input. */
210
- options?: ConditionValue[];
211
- label?: string;
212
- default?: Condition;
213
- }
214
- interface DateDrillDeclaration {
215
- default?: DateGrain;
216
- label?: string;
217
- }
218
- interface AppDeclaration {
219
- title?: string;
220
- /**
221
- * Omitted means the server applies the tenant reporting timezone — the SDK does not guess the
222
- * browser's. Part of the declaration, not the environment: two apps in one host may differ.
223
- */
224
- timezone?: string;
225
- }
226
- /**
227
- * Describes one result column. Classified server-side, since the SDK never parses the AQL that
228
- * produced it: an adhoc field first, else a real dataset field — the same order a filter's target
229
- * resolves in. This is what lets a control mapping or cross-filter know which columns it can
230
- * target. See docs/adr/0001.
231
- */
232
- interface ColumnMeta {
233
- /** This column's key in each result row — see `Row`. Can differ from `fieldName`; see there. */
234
- name: string;
235
- /**
236
- * This column's own field name — always the real one, regardless of what `name` resolved to.
237
- * Paired with `modelId`, this is what a control mapping or cross-filter actually targets.
238
- * Diverges from `name` exactly when the compiled query declared its own alias for an existing
239
- * field or a transformed dimension (`orders: count_i`, or
240
- * `time: date_trunc(beer_orders.order_time, "month")`).
241
- */
242
- fieldName: string;
243
- /** The model this column's field is attached to, absent for a metric-shaped reference. */
244
- modelId?: string;
245
- label: string;
246
- /** True when this column is a query-local AQL expression, not a field the dataset defines. */
247
- adhoc: boolean;
248
- isMeasure: boolean;
249
- aggregation?: string;
250
- /**
251
- * What the column's values mean: decide by it, never by `typeof`. A `number` column's values are
252
- * strings with every digit (`"9007199254740993"`, `"12345.67"`, `"NaN"`). `unknown` when the
253
- * query's type has no meaning in AML yet. See docs/designs/result-values.md.
254
- */
255
- semantic_type: SemanticType;
256
- /** The Arrow type the values were read as: whether a JS number would keep every digit, say. */
257
- arrow_type: ArrowType;
258
- /** The database's own name of the type: for debugging, never to decide on. */
259
- db_type: string;
260
- }
261
- /**
262
- * What a column's values mean, in AML's types, plus `bit`: a true or false stored as a bit, written
263
- * as `true` and `false` or as `"1"` and `"0"` by how the database produced it. `unknown` for a type
264
- * AML gives no meaning yet.
265
- */
266
- type SemanticType = 'text' | 'number' | 'date' | 'datetime' | 'truefalse' | 'json' | 'bit' | 'unknown';
267
- /**
268
- * An Arrow type: Arrow's `Type` of format/Schema.fbs as JSON. `type` is its name (`int`,
269
- * `floating_point`, `decimal`, `utf8`, `timestamp`, …), its other keys that type's fields in
270
- * snake_case (`bit_width`, `scale`, `unit`, …), and `label` how arrow-go spells it, for people.
271
- */
272
- interface ArrowType {
273
- type: string;
274
- label: string;
275
- [field: string]: unknown;
276
- }
277
- type Row = Record<string, unknown>;
278
- /**
279
- * Where a result came from.
280
- *
281
- * `executedAql` and `executedSql` are present only for readers permitted to see generated SQL —
282
- * absent means not permitted, rather than "there was none". `executedAt` on a cached result is
283
- * when the *cached* run happened, which may be hours earlier, so it should be labelled rather
284
- * than shown as if it just ran — the figures can be stale even though they are this reader's own.
285
- */
286
- interface QueryDebug {
287
- executedAql?: string;
288
- executedSql?: string;
289
- fromCache: boolean;
290
- executedAt?: Date;
291
- }
292
- interface QueryResult {
293
- columns: ColumnMeta[];
294
- rows: Row[];
295
- meta: {
296
- /** Present only for a query that declares a `pageSize`. */
297
- page?: number;
298
- /** Present only for a query that declares a `pageSize`. */
299
- pageSize?: number;
300
- numRows: number;
301
- };
302
- debug?: QueryDebug;
303
- }
304
- type QueryState = 'idle' | 'executing' | 'success' | 'error';
305
- interface ExecuteSummary {
306
- succeeded: string[];
307
- failed: string[];
308
- }
309
- interface ExecuteOptions {
310
- /** Re-run every query, not only dirty ones. */
311
- force?: boolean;
312
- /** Ask the server to skip its result cache. */
313
- bustCache?: boolean;
314
- }
315
- type Unsubscribe = () => void;
316
- type Listener = () => void;
317
- /**
318
- * One condition derived from a selection.
319
- *
320
- * A selection's values are never absent — a condition with nothing to match is not emitted at all —
321
- * and it never carries a modifier: the three operators a selection produces — `is`, `is_null` and
322
- * `matches` — take none.
323
- */
324
- interface SelectionCondition {
325
- field: string;
326
- operator: Operator;
327
- values: ConditionValue[];
328
- }
329
- /**
330
- * What the reader has picked out of one query's results, and the conditions it puts on that
331
- * query's cross-filter targets.
332
- *
333
- * App-scoped and singular: a selection belongs to no single query, and picking rows in a second
334
- * query replaces it. Held on the app for that reason alone — every control still owns its own
335
- * condition.
336
- */
337
- interface Selection {
338
- /** Name of the query the rows came from. */
339
- source: string;
340
- /** The rows as the author passed them, verbatim. */
341
- rows: readonly Row[];
342
- /**
343
- * The dimension aliases the conditions were derived from — every declared one, or those
344
- * `select` narrowed to. What makes a re-run of the source comparable against `rows`.
345
- */
346
- fields: readonly string[];
347
- conditions: readonly SelectionCondition[];
348
- /**
349
- * Set instead of `conditions` when the field-by-field collapse would have been lossy: one AQL
350
- * condition saying exactly what the reader picked, as an OR over the rows.
351
- *
352
- * Only reached this way. The structured form is the proven path and stays in charge whenever it
353
- * can say what the selection means, which is every single-dimension and every contiguous case.
354
- */
355
- expression?: string;
356
- /**
357
- * True when the conditions sent admit rows the reader did not pick, or condition on less than
358
- * they picked.
359
- *
360
- * Two causes, and only one is fixable. A field-by-field collapse over-selects — picking
361
- * `(APAC, Jan)` and `(EMEA, Feb)` ANDs to `region IN (APAC, EMEA) AND month IN (Jan, Feb)`,
362
- * which also admits `(APAC, Feb)` — and that case is sent as an `expression` instead, so it is
363
- * not lossy. What survives is a dropped query-local column: an adhoc field exists only in this
364
- * query's result, so no condition of any shape can name it in the target. Reported rather than
365
- * hidden, because otherwise it reads as a data bug.
366
- */
367
- lossy: boolean;
368
- }
369
- type EntityKind = 'query' | 'filter' | 'dateDrill';
370
- interface EntityRef {
371
- kind: EntityKind;
372
- name: string;
373
- }
374
- /**
375
- * One directed edge in the app's entity graph, tagged by kind.
376
- *
377
- * A single list rather than one per kind, mirroring Dashboard as Code's `definition.interactions`,
378
- * which carries all five of its interaction kinds discriminated by `type`. The tag is what makes
379
- * that workable: a consumer branches explicitly instead of inferring the kind from which optional
380
- * fields happen to be present. See docs/adr/0005.
381
- */
382
- /** A control conditioning one field of one query. */
383
- interface ControlMappingJson {
384
- kind: 'control';
385
- id: string;
386
- from: EntityRef;
387
- to: EntityRef;
388
- field: string;
389
- aggregation?: FilterAggregation;
390
- }
391
- /**
392
- * A query that may cross-filter another. Deliberately carries no field: which fields a selection
393
- * conditions is decided when the reader clicks, not when the edge is declared — the same asymmetry
394
- * that makes `CrossFilterInteraction` the one Dashboard as Code interaction without a `field_path`.
395
- */
396
- interface CrossFilterJson {
397
- kind: 'crossFilter';
398
- id: string;
399
- from: EntityRef;
400
- to: EntityRef;
401
- }
402
- type MappingJson = ControlMappingJson | CrossFilterJson;
403
- interface AppJson {
404
- title?: string;
405
- timezone?: string;
406
- queries: Record<string, QueryDeclaration>;
407
- filters: Record<string, FilterDeclaration>;
408
- dateDrills: Record<string, DateDrillDeclaration>;
409
- mappings: MappingJson[];
410
- }
411
- /**
412
- * An app's declaration and runtime state as plain data, for a host to render outside the sandbox.
413
- *
414
- * Built by reading the live objects rather than serialising them. Everything worth showing sits
415
- * behind a getter, and getters do not survive a structured clone; the objects holding them carry
416
- * an `AbortController`, a backend and a bag of closures, which do not survive one either. So this
417
- * is written out field by field, and stays plain all the way down. See docs/adr/0007.
418
- */
419
- interface InspectedError {
420
- name: string;
421
- message: string;
422
- /** The query or control the error is about. Lost if the error itself is cloned. */
423
- entity?: string;
424
- status?: number;
425
- stack?: string;
426
- }
427
- /** The two kinds of entity a marked element can be drawn by. */
428
- type LocateKind = 'query' | 'control';
429
- type StructureKind = 'container' | 'block' | LocateKind;
430
- /**
431
- * One node of the structure. A container or block has an `id`; a query or control node has the
432
- * entity's `app` index and `name`. `key` is the node's index path in the tree (`0.2.1`), what a
433
- * host uses to point at it; it is stable while the tree is unchanged.
434
- */
435
- interface StructureNode {
436
- key: string;
437
- kind: StructureKind;
438
- id?: string;
439
- label?: string;
440
- app?: number;
441
- name?: string;
442
- /** What is wrong with this node's markup, in words. Reported, never thrown. */
443
- problems: string[];
444
- children: StructureNode[];
445
- }
446
- /** Where one entity is drawn: how many marked elements, and which blocks they are in. */
447
- interface EntityUsage {
448
- markers: number;
449
- blocks: string[];
450
- }
451
- interface InspectedStructure {
452
- nodes: StructureNode[];
453
- /** Keyed `query:<app>/<name>` or `control:<app>/<name>`; only entities that exist. */
454
- usage: Record<string, EntityUsage>;
455
- }
456
- /** What a host asks a frame to locate: a node of the structure, or an entity wherever it is drawn. */
457
- type LocateTarget = {
458
- node: string;
459
- } | {
460
- app: number;
461
- kind: LocateKind;
462
- name: string;
463
- };
464
- interface InspectedQuery {
465
- state: QueryState;
466
- /** True when re-running would produce something new. */
467
- isDirty: boolean;
468
- page: number;
469
- hasMore: boolean;
470
- /** Column metadata only. Rows are deliberately absent — see docs/adr/0007. */
471
- columns: ColumnMeta[];
472
- rowCount: number;
473
- selectedRowCount: number;
474
- /** Everything that decides whether this query re-runs, which is the question a stale panel asks. */
475
- signature: string;
476
- error?: InspectedError;
477
- debug?: QueryDebug;
478
- }
479
- interface InspectedControl {
480
- kind: EntityKind;
481
- /** What the reader has set. */
482
- condition: Condition;
483
- /** What the query last ran with, absent before the first execution. */
484
- appliedCondition?: Condition;
485
- isDirty: boolean;
486
- /** Field-backed filters only, and only once loaded. */
487
- options?: ConditionValue[];
488
- }
489
- interface InspectedSelection {
490
- source: string;
491
- fields: readonly string[];
492
- rowCount: number;
493
- conditions: readonly SelectionCondition[];
494
- expression?: string;
495
- /** Surfaced here because it otherwise only ever reaches a `console.warn`. */
496
- lossy: boolean;
497
- }
498
- interface InspectedApp {
499
- title?: string;
500
- timezone?: string;
501
- hasChanges: boolean;
502
- declaration: AppJson;
503
- queries: Record<string, InspectedQuery>;
504
- controls: Record<string, InspectedControl>;
505
- selection?: InspectedSelection;
506
- appliedSelection?: InspectedSelection;
507
- }
508
- /** One control-mapping or cross-filter condition on a query, as structured data. */
509
- interface BackendFilter {
510
- /** `model.field` for a dataset field, or a bare name for a dataset metric. */
511
- field: string;
512
- operator: Operator;
513
- values: ConditionValue[];
514
- /** Date unit for relative operators (`last`, `next`). */
515
- modifier?: string;
516
- /** Present on an aggregated mapping: the condition applies to this aggregate of `field`. */
517
- aggregation?: FilterAggregation;
518
- }
519
- /**
520
- * An AQL condition applied on top of the query: the escape hatch for a cross-filter selection the
521
- * ANDed `filters` cannot express, such as `(A and B) or (C and D)`. Generated, never author-written.
522
- */
523
- interface BackendCondition {
524
- expr: string;
525
- }
526
- /** A reader's sort, naming a result column. Replaces the query's own `sorts` when present. */
527
- interface BackendSort {
528
- field: string;
529
- direction: 'asc' | 'desc';
530
- }
531
- /** Redraw every dimension built directly on `field` at `grain`, keeping its alias. Not a filter. */
532
- interface BackendDateDrill {
533
- field: string;
534
- grain: DateGrain;
535
- }
536
- /** The structured additions a query carries on this run, applied on top of its AQL. */
537
- interface QueryInput {
538
- filters: BackendFilter[];
539
- conditions: BackendCondition[];
540
- sorts: BackendSort[];
541
- dateDrills: BackendDateDrill[];
542
- }
543
- interface BackendQueryRequest {
544
- /** The dataset's `name`, as in `DatasetDescriptor.name`. */
545
- dataset: string;
546
- /** The query's AQL, verbatim. */
547
- aql: string;
548
- input: QueryInput;
549
- /** 1-based. Sent together with `pageSize`, and only for a query that declares one. */
550
- page?: number;
551
- /** Absent for an unpaged query: the backend returns every row. */
552
- pageSize?: number;
553
- /** Absent when the app declares none, leaving the backend's default. */
554
- timezone?: string;
555
- /** Present on `refresh()`: skip any result cache. */
556
- bustCache?: boolean;
557
- }
558
- /** One page of a query's rows. `values` is positional: each row lines up with `columns`. */
559
- interface BackendQueryResult {
560
- columns: ColumnMeta[];
561
- values: unknown[][];
562
- meta?: {
563
- page?: number;
564
- pageSize?: number;
565
- numRows?: number;
566
- };
567
- debug?: QueryDebug;
568
- }
569
- /** A file format an export can be written in. CSV is the only one yet; a server may add more. */
570
- type ExportFormat = 'csv' | (string & {});
571
- /** A format's options. Each applies to the formats it names; the server refuses one given to another. */
572
- interface ExportFormatOptions {
573
- /** csv: the header row: the columns' labels (the default), their names, or none. */
574
- header?: 'labels' | 'names' | 'none';
575
- /** csv: start the file with a UTF-8 byte-order mark, which Excel needs to read non-ASCII text. */
576
- bom?: boolean;
577
- }
578
- /** What `query.export()` takes. Every field is optional. */
579
- interface ExportOptions {
580
- /**
581
- * The file's name, with the format's extension added when it has none. Defaults to the app's
582
- * title and the query's name (`Sales - revenueByMonth.csv`), or the query's name alone.
583
- */
584
- filename?: string;
585
- /** `csv` unless given. */
586
- format?: ExportFormat;
587
- /** For CSV, `bom` defaults to `true`: a person opens what a Data App exports. */
588
- formatOptions?: ExportFormatOptions;
589
- /** Cancels the export. `query.abort()` does not: an export is not the query's run. */
590
- signal?: AbortSignal;
591
- }
592
- /**
593
- * A query's whole result as a file: what the Backend made, and the host has already started
594
- * saving for the reader. `url` works with a plain `GET` until `expiresAt`.
595
- */
596
- interface ExportResult {
597
- url: string;
598
- filename: string;
599
- format: ExportFormat;
600
- /** The rows the file holds. */
601
- rowCount: number;
602
- expiresAt: Date;
603
- }
604
- /**
605
- * An export: the same query a run sends, built by the same code so the two cannot drift, but with
606
- * no page (an export is every row) and no cache to bust; plus the file's format and name.
607
- */
608
- interface BackendExportRequest {
609
- /** The dataset's `name`, as in `DatasetDescriptor.name`. */
610
- dataset: string;
611
- /** The query's AQL, verbatim. */
612
- aql: string;
613
- input: QueryInput;
614
- /** Absent when the app declares none, leaving the backend's default. */
615
- timezone?: string;
616
- format?: ExportFormat;
617
- formatOptions?: ExportFormatOptions;
618
- filename?: string;
619
- }
620
- interface FieldSuggestionsRequest {
621
- /** The dataset's `name`. */
622
- dataset: string;
623
- model: string;
624
- field: string;
625
- /** What the reader has typed so far; empty for the first page of options. */
626
- q: string;
627
- }
628
- /**
629
- * What the SDK sends queries to, supplied by the provisioner. Each call either resolves or
630
- * rejects; how the backend gets there (synchronously, as polled jobs, over a bridge) is its own
631
- * business. A call whose `signal` aborts may reject with an `AbortError`, and its result is
632
- * ignored either way. Reject with a `DataAppError` (`PermissionError`, `QueryError`, ...) to choose
633
- * the error an author sees; anything else surfaces as a `QueryError`.
634
- */
635
- interface Backend {
636
- submitQuery(request: BackendQueryRequest, signal: AbortSignal): Promise<BackendQueryResult>;
637
- fieldSuggestions(request: FieldSuggestionsRequest, signal: AbortSignal): Promise<ConditionValue[]>;
638
- /**
639
- * Export a query's whole result as a file, and answer its link once the file is ready. Optional:
640
- * a host that cannot export leaves it out, and `query.export()` rejects with a `TransportError`.
641
- */
642
- exportQuery?(request: BackendExportRequest, signal: AbortSignal): Promise<ExportResult>;
643
- }
644
-
645
- export { type RenderRequest as $, type Aggregation as A, type Backend as B, type ColumnMeta as C, type DatasetDescriptor as D, type EntityKind as E, FILTER_AGGREGATIONS as F, type FilterAggregation as G, type FilterDeclaration as H, type FilterValueType as I, type InspectedApp as J, type InspectedControl as K, type InspectedError as L, type InspectedQuery as M, type InspectedSelection as N, type InspectedStructure as O, type Listener as P, type LocateKind as Q, type LocateTarget as R, type MappingJson as S, type Operator as T, type QueryDebug as U, type QueryDeclaration as V, type QueryInput as W, type QueryResult as X, type QuerySort as Y, type QueryState as Z, type RenderFormat as _, type AppDeclaration as a, type Rendering as a0, type Row as a1, type SdkEnvironment as a2, type SdkFeatures as a3, type Selection as a4, type SelectionCondition as a5, type SemanticType as a6, type StructureKind as a7, type StructureNode as a8, type Unsubscribe as a9, type User as aa, type AppJson as b, type ArrowType as c, type BackendCondition as d, type BackendDateDrill as e, type BackendExportRequest as f, type BackendFilter as g, type BackendQueryRequest as h, type BackendQueryResult as i, type BackendSort as j, type Condition as k, type ConditionValue as l, type ControlMappingJson as m, type CrossFilterJson as n, type DateDrillDeclaration as o, type DateGrain as p, type DateTransformation as q, type EntityRef as r, type EntityUsage as s, type ExecuteOptions as t, type ExecuteSummary as u, type ExportFormat as v, type ExportFormatOptions as w, type ExportOptions as x, type ExportResult as y, type FieldSuggestionsRequest as z };