@holistics/anfra-sdk 0.20.0 → 0.22.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 (38) hide show
  1. package/README.md +5 -0
  2. package/dist/api.d.ts +11 -8
  3. package/dist/api.js +45 -22
  4. package/dist/app.d.ts +5 -5
  5. package/dist/app.js +5 -4
  6. package/dist/{bootstrap-DHU2haC5.d.ts → bootstrap-fGoj2ap1.d.ts} +324 -27
  7. package/dist/build.d.ts +2 -2
  8. package/dist/{chunk-32566ZNE.js → chunk-2TTGSNHA.js} +1 -1
  9. package/dist/{chunk-H52PO7MP.js → chunk-33HI2ODM.js} +25 -0
  10. package/dist/chunk-4UEESYHH.js +32 -0
  11. package/dist/{chunk-KKSOTHP4.js → chunk-7GQZU5FL.js} +1 -1
  12. package/dist/{chunk-4TXKXLWK.js → chunk-7I2HXY72.js} +1 -1
  13. package/dist/{chunk-DITKCHFQ.js → chunk-CLXZMA5D.js} +1 -1
  14. package/dist/{chunk-GBXK7F2V.js → chunk-D7DIJRAC.js} +14 -1
  15. package/dist/{chunk-ACKFOANJ.js → chunk-DWQUIHUX.js} +4 -1
  16. package/dist/{chunk-FTTVLHNN.js → chunk-EOFPMSND.js} +1 -1
  17. package/dist/{chunk-SXKJQU7A.js → chunk-GPBYPSWK.js} +22 -36
  18. package/dist/{chunk-EIPHDMZ7.js → chunk-UWRQXPPG.js} +69 -24
  19. package/dist/{chunk-T5T76SAR.js → chunk-YPGMBSOZ.js} +1209 -274
  20. package/dist/common.d.ts +3 -3
  21. package/dist/common.js +1 -1
  22. package/dist/{data-ESPFZ5IM.js → data-SZDYO55C.js} +7 -5
  23. package/dist/{declaration-RYRBX7PH.js → declaration-GYV6OUR3.js} +5 -3
  24. package/dist/{errors-189T_Mnc.d.ts → errors-kH5eHvNO.d.ts} +1 -1
  25. package/dist/host.d.ts +2 -2
  26. package/dist/host.js +31 -8
  27. package/dist/{overview-AWPXJACF.js → overview-CD6NY3VQ.js} +28 -13
  28. package/dist/{plugin-rRd-zHGt.d.ts → plugin-DG2NDTCT.d.ts} +7 -2
  29. package/dist/plugins.d.ts +1 -7
  30. package/dist/plugins.js +53 -17
  31. package/dist/{queries-FWMX7H5Z.js → queries-BWKWZQMG.js} +70 -17
  32. package/dist/{structure-VFRJFC4C.js → structure-JO4YZHKZ.js} +5 -3
  33. package/dist/{tab-XL2HS5W4.js → tab-QPHE7YUQ.js} +3 -3
  34. package/dist/testing.d.ts +2 -1
  35. package/dist/testing.js +8 -7
  36. package/dist/{menu-Cam-hOdJ.d.ts → theme-FQ_1b569.d.ts} +72 -55
  37. package/dist/{types-N0V9n38H.d.ts → types-BE767W6G.d.ts} +879 -129
  38. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
- import { D as DataAppError, V as ValidationError, k as invalidRequest, h as forbidden, g as connectionFailed, f as callFailed, i as fromHttpStatus, j as hasErrorCode, l as isDataAppError } from './errors-189T_Mnc.js';
2
- import { X as Listener, aj as Unsubscribe, D as DatasetDescriptor, y as ExportOptions, z as ExportResult, a9 as RenderRequest, aa as Rendering, W as LineageTarget, U as LineageOptions, V as LineageResult, E as EntityKind, l as Condition, J as FilterDeclaration, K as FilterValueType, B as Backend, m as ConditionValue, p as DateDrillDeclaration, q as DateGrain, I as FilterAggregation, n as ControlMappingJson, o as CrossFilterJson, ad as SdkFeatures, ae as Selection, af as SelectionCondition, ab as Row, Y as LocateKind, a1 as QueryDeclaration, a6 as QueryState, a4 as QueryResult, a5 as QuerySort, a as AppDeclaration, a3 as QueryRequest, u as ExecuteOptions, v as ExecuteSummary, f as BackendExportRequest, b as AppJson, L as InspectedApp, ak as User, ac as SdkEnvironment, Q as InspectedStructure } from './types-N0V9n38H.js';
3
- import { e as PluginInfo, j as ThemeScheme, l as ThemeTokens, h as Theme, d as MenuTargetKind, c as MenuTarget, N as NodeTarget } from './menu-Cam-hOdJ.js';
1
+ import { D as DataAppError, V as ValidationError, k as invalidRequest, h as forbidden, g as connectionFailed, f as callFailed, i as fromHttpStatus, j as hasErrorCode, l as isDataAppError } from './errors-kH5eHvNO.js';
2
+ import { a0 as Listener, aA as Unsubscribe, D as DatasetDescriptor, I as ExportOptions, J as ExportResult, am as RenderRequest, an as Rendering, $ as LineageTarget, Z as LineageOptions, _ as LineageResult, E as EntityKind, q as Condition, O as FilterDeclaration, B as Backend, P as FilterValueType, r as ConditionValue, u as DateDrillDeclaration, v as DateGrain, N as FilterAggregation, t as CrossFilterJson, s as ControlMappingJson, aa as QueryInputDefaults, as as SdkFeatures, at as Selection, au as SelectionCondition, ap as Row, z as ExecuteOptions, F as ExecuteSummary, a1 as LocateKind, a9 as QueryInput, a8 as QueryDeclaration, a6 as QueryCacheSettings, ag as QuerySort, ai as QueryState, ae as QueryResult, a as Annotation, b as AnnotationInput, e as AppDeclaration, aD as WeekStartDay, ad as QueryRequest, j as BackendExportRequest, C as CallStamp, f as AppJson, Q as InspectedApp, aB as User, ar as SdkEnvironment, V as InspectedStructure } from './types-BE767W6G.js';
3
+ import { R as RowsTarget, e as PluginInfo, k as ThemeScheme, m as ThemeTokens, i as Theme, d as MenuTargetKind, c as MenuTarget, N as NodeTarget } from './theme-FQ_1b569.js';
4
4
 
5
5
  interface NotificationTarget {
6
6
  notifyChange(): void;
@@ -112,22 +112,39 @@ type PluginMembers<Where extends keyof PluginApi> = {
112
112
  readonly [K in keyof AnfraPlugins as AnfraPlugins[K] extends Record<Where, unknown> ? K : never]?: AnfraPlugins[K] extends Record<Where, infer Api> ? Api : never;
113
113
  };
114
114
 
115
+ /** What `filter.update` may change. Left out, each keeps its value; `undefined` clears it. */
116
+ type FilterUpdate = Partial<FilterDeclaration & {
117
+ dataset: string;
118
+ }>;
115
119
  declare class Filter extends Control {
116
120
  readonly kind: "filter";
117
- readonly declaration: FilterDeclaration;
118
- readonly type: FilterValueType;
119
- private readonly resolved?;
120
- private readonly datasetName?;
121
+ private _declaration;
122
+ private resolution;
121
123
  private readonly backend?;
122
124
  private loadedOptions?;
125
+ /** The `loadOptions` calls in flight, so a removal or a new field can drop them. */
126
+ private readonly loading;
123
127
  constructor(name: string, app: AppContext & Observable, declaration: FilterDeclaration, dataset?: DatasetIndex, backend?: Backend);
128
+ private static resolve;
129
+ /** What it was declared with, or last updated to. */
130
+ get declaration(): FilterDeclaration;
131
+ get type(): FilterValueType;
124
132
  setCondition(condition: Condition): void;
133
+ /**
134
+ * Edits this filter in place. A new label, options or default keep the reader's condition, and
135
+ * `reset()` goes to the new default. A new field, dataset or type is checked as `createFilter`
136
+ * checks it, and the condition goes back to the new default: the old values filtered something
137
+ * else. Its mappings stay as they are: each mapping's own field decides what its condition applies to.
138
+ */
139
+ update(changes: FilterUpdate): void;
140
+ protected dropInFlight(): void;
125
141
  /**
126
142
  * A number filter's values are strings, as query results give them, which keep every digit. A JS
127
143
  * number may already have lost some (`Number("9007199254740993")` is ...992), and nothing after
128
144
  * can tell, so the core API refuses one; this says so where the app hands it over.
129
145
  */
130
146
  private assertValues;
147
+ private assertValuesOf;
131
148
  /** True for a field-backed filter, false for a manual one. The two are separate axes from `type`. */
132
149
  get isFieldBacked(): boolean;
133
150
  /** A manual filter's static list, or whatever the last `loadOptions()` returned. */
@@ -137,14 +154,20 @@ declare class Filter extends Control {
137
154
  *
138
155
  * Lazy rather than fetched up front: building a distinct-values query for every filter is slow,
139
156
  * and readers often touch none of them. The backend decides which values this reader may see.
157
+ * Rejects with an `AbortError` when the filter is removed, or its field changes, before the list
158
+ * arrives: the list is dropped.
140
159
  */
141
160
  loadOptions(search?: string, signal?: AbortSignal): Promise<ConditionValue[]>;
142
161
  toJSON(): FilterDeclaration;
143
162
  }
144
163
  declare class DateDrillControl extends Control {
145
164
  readonly kind: "dateDrill";
146
- readonly declaration: DateDrillDeclaration;
165
+ private _declaration;
147
166
  constructor(name: string, app: AppContext & Observable, declaration?: DateDrillDeclaration);
167
+ /** What it was declared with, or last updated to. */
168
+ get declaration(): DateDrillDeclaration;
169
+ /** Edits its label or default. The reader's grain stays; `reset()` goes to the new default. */
170
+ update(changes: DateDrillDeclaration): void;
148
171
  setGrain(grain: DateGrain): void;
149
172
  toJSON(): DateDrillDeclaration;
150
173
  }
@@ -161,13 +184,34 @@ declare abstract class Control extends Observable {
161
184
  protected readonly app: AppContext & Observable;
162
185
  private pending;
163
186
  private applied?;
164
- private readonly initial;
187
+ private initial;
188
+ /** Set once `remove()` took it out of its app; every method then throws. */
189
+ private removed;
165
190
  protected constructor(name: string, app: AppContext & Observable, initial: Condition);
166
191
  /**
167
192
  * Bring the elements marked `data-anfra-control` with this control's name into view. False when
168
193
  * none is on the page yet; never throws.
169
194
  */
170
195
  locate(): boolean;
196
+ /** False once `remove()` took it out of its app. */
197
+ get isRemoved(): boolean;
198
+ /**
199
+ * Takes this control out of its app, with its mappings: the queries it was mapped to rerun
200
+ * without its condition at the next `app.execute()`. Its name is free again, and every method
201
+ * of it throws from then on.
202
+ */
203
+ remove(): void;
204
+ /** @internal Throws once the control was removed. */
205
+ assertLive(): void;
206
+ /** @internal The app's half of `remove`: stop what is in flight. */
207
+ markRemoved(): void;
208
+ /** @internal Drops work in flight that the control's current declaration no longer wants. */
209
+ protected dropInFlight(): void;
210
+ /**
211
+ * @internal A new declaration's default: `reset()` goes back to it. `restart` also sets the
212
+ * reader's condition to it, for a control that now filters something else.
213
+ */
214
+ protected redefault(initial: Condition, restart: boolean): void;
171
215
  /** The reader's current value, which `execute()` will commit. */
172
216
  get condition(): Condition;
173
217
  /** The value this control's mapped queries last ran with. Undefined before the first execution. */
@@ -187,6 +231,10 @@ declare abstract class Control extends Observable {
187
231
  interface Control extends PluginMembers<'control'> {
188
232
  }
189
233
 
234
+ /** What an edge needs of its app: a way to take it out. */
235
+ interface EdgeOwner {
236
+ removeEdge(edge: Edge): void;
237
+ }
190
238
  /**
191
239
  * A directed edge from an interactive control to one field of one query.
192
240
  *
@@ -200,7 +248,16 @@ declare class Mapping {
200
248
  readonly to: Query;
201
249
  readonly field: string;
202
250
  readonly aggregation?: FilterAggregation;
203
- constructor(from: Control, to: Query, field: string, aggregation?: FilterAggregation);
251
+ private readonly owner?;
252
+ private removed;
253
+ constructor(from: Control, to: Query, field: string, aggregation?: FilterAggregation, owner?: EdgeOwner);
254
+ /**
255
+ * Takes this mapping out of its app: its query reruns without the control's condition at the
256
+ * next `app.execute()`. An edge never changes: to change one, remove it and map again.
257
+ */
258
+ remove(): void;
259
+ /** @internal */
260
+ markRemoved(): void;
204
261
  /**
205
262
  * Includes the field, unlike Dashboard as Code's `${from}.${to}` — that form collides the moment
206
263
  * one control maps onto one query on two fields.
@@ -221,7 +278,16 @@ declare class CrossFilter {
221
278
  readonly kind: "crossFilter";
222
279
  readonly from: Query;
223
280
  readonly to: Query;
224
- constructor(from: Query, to: Query);
281
+ private readonly owner?;
282
+ private removed;
283
+ constructor(from: Query, to: Query, owner?: EdgeOwner);
284
+ /**
285
+ * Takes this cross-filter out of its app: a selection in `from` stops reaching `to`, which
286
+ * reruns without it at the next `app.execute()`. To change one, remove it and map again.
287
+ */
288
+ remove(): void;
289
+ /** @internal */
290
+ markRemoved(): void;
225
291
  /** No field to disambiguate, and one pair may only be declared once, so the pair is the id. */
226
292
  get id(): string;
227
293
  toJSON(): CrossFilterJson;
@@ -235,11 +301,24 @@ type Edge = Mapping | CrossFilter;
235
301
  */
236
302
  interface AppContext {
237
303
  readonly timezone?: string;
304
+ /** What its queries get in their input when they set none: a timezone and a week start day. */
305
+ readonly queryInputDefaults: QueryInputDefaults;
306
+ /** The cache duration of each of its queries that declares none; absent leaves the backend's default. */
307
+ readonly queryCacheDefaultDuration?: string;
238
308
  /** Server-side capabilities the host declared, so a declaration can refuse what would be dropped. */
239
309
  readonly features?: SdkFeatures;
240
310
  /** The live selection, if any. App-scoped: at most one query is the source at a time. */
241
311
  readonly selection?: Selection;
242
312
  datasetIndex(uname: string, entity: string): DatasetIndex;
313
+ /** The dataset a field-backed filter resolves in: the one it names, or the app's only one. */
314
+ filterDataset(entity: string, declaration: {
315
+ dataset?: string;
316
+ field?: string;
317
+ }): DatasetIndex | undefined;
318
+ /** Backs `query.update`: checks the change against the app, then swaps the declaration. */
319
+ updateQuery(query: Query, changes: QueryUpdate): void;
320
+ /** Backs `remove()` on a query or a control: takes it out, with its edges. */
321
+ removeEntity(entity: Query | Control): void;
243
322
  /** Control edges only — cross-filter edges reach a query through the selection instead. */
244
323
  mappingsTo(queryName: string): Mapping[];
245
324
  /**
@@ -254,6 +333,8 @@ interface AppContext {
254
333
  selectionExpressionFor(queryName: string, phase: 'pending' | 'applied'): string | undefined;
255
334
  /** Replaces the app's selection with these rows of this query. */
256
335
  select(query: Query, rows: readonly Row[], fields?: readonly string[]): void;
336
+ /** Runs this query alone, with what is applied, unless that would produce nothing new or `force`. */
337
+ executeQuery(query: Query, options: ExecuteOptions): Promise<ExecuteSummary>;
257
338
  /** Runs one more page for a query that already has a result. */
258
339
  fetchPage(query: Query): Promise<void>;
259
340
  /** Brings an entity's marked elements into view; false when none is on the page. */
@@ -262,11 +343,46 @@ interface AppContext {
262
343
  menu(query: Query, event: Event, rows: readonly Row[], fields?: readonly string[], measure?: string): boolean;
263
344
  }
264
345
 
346
+ /**
347
+ * The run a query's result on screen came from, as its next page and its export continue it: the
348
+ * input it ran with, its seeds filled in, and when its first page's rows were read from the
349
+ * warehouse, if they were cached.
350
+ *
351
+ * Only a run sets it, and a run always starts at the first page. A later page and an export send
352
+ * `cachedAt` as `minCachedAt`, so none of them is older than the first page
353
+ * (docs/designs/query-cache.md#a-runs-later-pages). A call that fetched page x would have to be
354
+ * such a later page, not a new run: a run of page x would set `cachedAt` from page x, and the pages
355
+ * before it would no longer be held to it.
356
+ */
357
+ interface Run {
358
+ input: QueryInput;
359
+ cachedAt?: string;
360
+ }
361
+
362
+ /**
363
+ * What `query.update` may change. `pageSize: undefined` drops the paging, and `cache: undefined`
364
+ * goes back to the app's default cache duration.
365
+ */
366
+ interface QueryUpdate {
367
+ dataset?: string;
368
+ aql?: string;
369
+ pageSize?: number;
370
+ cache?: QueryCacheSettings;
371
+ /** The sort to keep; left out, a new AQL or dataset clears the sort, and anything else keeps it. */
372
+ sort?: readonly QuerySort[];
373
+ }
265
374
  declare class Query extends Observable {
266
375
  readonly kind: "query";
267
376
  readonly name: string;
268
- readonly declaration: QueryDeclaration;
269
- readonly dataset: DatasetIndex;
377
+ /**
378
+ * @internal Which query of its name: its app numbers them as they are created, so one removed and
379
+ * created again by its name is told apart from the first, in the stamp on its calls.
380
+ */
381
+ readonly id: number;
382
+ private _declaration;
383
+ private _dataset;
384
+ /** Set once `remove()` took it out of its app; every method then throws. */
385
+ private removed;
270
386
  private readonly app;
271
387
  private _state;
272
388
  /** Its last run failed: not a `fetchMore`, whose failure leaves the pages already loaded to keep. */
@@ -274,12 +390,18 @@ declare class Query extends Observable {
274
390
  private _result?;
275
391
  private _error?;
276
392
  private _page;
393
+ private _run;
277
394
  /**
278
395
  * A sort applied to the result, independent of the query's own AQL — the same mechanism a click
279
396
  * on a table's column header uses. Kept off the declaration so setting it never re-authors the
280
397
  * query. See docs/adr/0001.
281
398
  */
282
399
  private _sort;
400
+ /**
401
+ * The result belongs to the declaration before the last `update`: it stays on screen until the
402
+ * rerun, but its pages can't be continued with the new AQL. Cleared when a run's first page lands.
403
+ */
404
+ private resultSuperseded;
283
405
  /** The input signature of the last successful run; undefined until one has happened. */
284
406
  private lastRunSignature?;
285
407
  /**
@@ -289,7 +411,52 @@ declare class Query extends Observable {
289
411
  private lastPageRows;
290
412
  /** @internal Set by the executor so `abort()` can reach the in-flight request. */
291
413
  controller?: AbortController;
292
- constructor(name: string, app: AppContext & Observable, declaration: QueryDeclaration);
414
+ /**
415
+ * @internal The signature the run or page in flight was sent with; set and cleared with
416
+ * `controller`, so a run the reader is waiting on is not counted as a change.
417
+ */
418
+ runningSignature?: string;
419
+ /** The signature of its last run, when that run failed. */
420
+ private failedSignature?;
421
+ /** Each plugin's annotations on the current result, by plugin, in the order they were first set. */
422
+ private annotationSets;
423
+ /**
424
+ * The results that are the current one: the last run's, and each that a page extended it into, so
425
+ * annotations computed before a `fetchMore` still land.
426
+ */
427
+ private currentResults;
428
+ /** `annotations` as last read, until a set or the result changes. */
429
+ private resolvedAnnotations?;
430
+ constructor(name: string, app: AppContext & Observable, declaration: QueryDeclaration, id: number);
431
+ /** What it was declared with, or last updated to. */
432
+ get declaration(): QueryDeclaration;
433
+ /** The dataset its declaration names, resolved. */
434
+ get dataset(): DatasetIndex;
435
+ /** False once `remove()` took it out of its app. */
436
+ get isRemoved(): boolean;
437
+ /**
438
+ * Swaps what this query is: its dataset, its AQL, its page size, its cache, checked as `createQuery` checks
439
+ * them. Its name, its edges and its result stay; the result until the rerun replaces it, but its
440
+ * annotations go at once, and plugins can't annotate that result any more. Runs
441
+ * nothing: the query is dirty, and the next `app.execute()` reruns it, so several edits go out
442
+ * as one run. Back to the first page. A run or page in flight is aborted, and `fetchMore` does
443
+ * nothing until the rerun. A new AQL or dataset clears the sort (unless `sort` is given) and a
444
+ * selection made in this query, whose rows no longer mean the same.
445
+ */
446
+ update(changes: QueryUpdate): void;
447
+ /**
448
+ * Takes this query out of its app: its control mappings and cross-filters go with it, a run in
449
+ * flight is aborted, a selection made in it is cleared, and its name is free again. The queries
450
+ * it cross-filtered rerun without it at the next `app.execute()`. Every method of it throws from
451
+ * then on.
452
+ */
453
+ remove(): void;
454
+ /** @internal Throws once the query was removed. */
455
+ assertLive(): void;
456
+ /** @internal The app's half of `update`, checked by then: swap the declaration. */
457
+ replaceDeclaration(declaration: QueryDeclaration, dataset: DatasetIndex, sort: readonly QuerySort[]): void;
458
+ /** @internal The app's half of `remove`: stop what is in flight, and stay quiet from then on. */
459
+ markRemoved(): void;
293
460
  /**
294
461
  * Bring the elements marked `data-anfra-query` with this query's name into view: scroll to the
295
462
  * first and show them all for a moment. False, and nothing done, when no element on the page is
@@ -307,27 +474,48 @@ declare class Query extends Observable {
307
474
  setSort(sort: readonly QuerySort[]): void;
308
475
  /**
309
476
  * Whether another page may follow: as the backend said of the last page, or, when it did not
310
- * say, whether that page came back full.
477
+ * say, whether that page came back full. False after `update` until the rerun.
311
478
  */
312
479
  get hasMore(): boolean;
313
480
  /**
314
481
  * Everything that changes the rows: the declaration, the conditions reaching this query through
315
482
  * mappings, the conditions reaching it from the selection, the sort override, the app's timezone,
316
483
  * and the page. Compared against the last successful run to decide whether re-running would
317
- * produce anything new.
484
+ * produce anything new. `pending` reads the controls and selection as the reader has them,
485
+ * `applied` as the app last applied them; they differ only between a change and `app.execute()`.
318
486
  */
319
- signature(): string;
487
+ signature(phase?: 'pending' | 'applied'): string;
320
488
  /**
321
489
  * False before the first run: with nothing applied there is nothing to have changed. Distinct
322
490
  * from `shouldRun`, which is true in that case precisely because there is no result yet.
323
491
  */
324
492
  get isDirty(): boolean;
493
+ /**
494
+ * @internal For `app.hasChanges`: whether the next `app.execute()` would run it with inputs no run
495
+ * of it has had. Not when its pending inputs are those of its run in flight, its last successful
496
+ * run or, when it last failed, its failed run: a failure is not a change. Never attempted, only
497
+ * once `executed` (the app has run): before that, nothing has been applied to differ from.
498
+ */
499
+ hasUnappliedChange(executed: boolean): boolean;
325
500
  /**
326
501
  * @internal Also when its last run failed, whatever its inputs: so `execute()` is the retry, of
327
502
  * the failed queries only, even after a forced run (`refresh()`) failed with unchanged inputs. Not
328
503
  * after a failed `fetchMore`: rerun, it would drop the pages already loaded; `fetchMore` is its retry.
329
504
  */
330
505
  shouldRun(force?: boolean): boolean;
506
+ /**
507
+ * @internal For `query.execute()`: like `shouldRun`, but against what is applied, since applying
508
+ * the reader's pending changes is the app's, for every query at once. Its own sort and the
509
+ * timezone count; a control or selection the reader changed and the app has not applied does not.
510
+ */
511
+ shouldRunAlone(force?: boolean): boolean;
512
+ /**
513
+ * Runs this query alone, with the inputs the app last applied, if that would produce something
514
+ * new; with `force`, whatever its inputs (a paged query starts over at its first page). Applies
515
+ * none of the reader's pending changes: that is `app.execute()`'s, so the query stays dirty and
516
+ * the next `app.execute()` runs it with them. Never rejects, as `app.execute()` doesn't.
517
+ */
518
+ execute(options?: ExecuteOptions): Promise<ExecuteSummary>;
331
519
  /** Stops the in-flight request for this query. The pending `execute()` resolves without it. */
332
520
  abort(): void;
333
521
  /** Fetches the next page and appends it. Rejects rather than swallowing, unlike `execute()`. */
@@ -369,12 +557,31 @@ declare class Query extends Observable {
369
557
  * `app.selection.rows` still holds what the author passed, verbatim.
370
558
  */
371
559
  get selectedRows(): readonly Row[];
560
+ /**
561
+ * What plugins say about this query's current result, every plugin's merged: draw the kinds your
562
+ * chart declares in `data-anfra-annotations`, by `index` for a rows anchor. Each has its plugin
563
+ * and a stable `key`. A change notifies through `subscribe`; they go when the result is replaced.
564
+ */
565
+ get annotations(): readonly Annotation[];
566
+ /** @internal Whether `result` is this query's current result, or one a page has since extended. */
567
+ isCurrentResult(result: QueryResult): boolean;
568
+ /** @internal `kernel.annotate`'s, checked by then: replace one plugin's set, `[]` clearing it. */
569
+ setAnnotations(plugin: string, annotations: readonly AnnotationInput[]): void;
570
+ /** Every plugin's annotations go, with the result they were about. */
571
+ private clearAnnotations;
372
572
  /** @internal */
373
573
  markExecuting(): void;
574
+ /** @internal The cache duration it runs with: its own, or its app's default. Absent: the backend's default. */
575
+ get cacheDuration(): string | undefined;
576
+ /** @internal The run the result on screen came from, for its next page and its export. */
577
+ get run(): Run | undefined;
374
578
  /** @internal */
375
- markSuccess(result: QueryResult, signature: string, append: boolean): void;
376
- /** @internal `page` when it is a `fetchMore` that failed, not a run. */
377
- markError(error: DataAppError, page?: boolean): void;
579
+ markSuccess(result: QueryResult, signature: string, append: boolean, run?: Run): void;
580
+ /**
581
+ * @internal `page` when it is a `fetchMore` that failed, not a run; `signature`, a failed run's
582
+ * inputs.
583
+ */
584
+ markError(error: DataAppError, page?: boolean, signature?: string): void;
378
585
  /** @internal Reverts an optimistic page bump when a `fetchMore` fails. */
379
586
  rewindPage(): void;
380
587
  /** @internal */
@@ -396,6 +603,11 @@ declare class App extends Observable implements AppContext {
396
603
  private readonly extensions?;
397
604
  readonly title?: string;
398
605
  private _timezone?;
606
+ private _weekStartDay?;
607
+ /** The app's `query.default.input`: what its queries use over its own timezone and week start day. */
608
+ private readonly queryInput;
609
+ /** The cache duration of each of the app's queries that declares none (`query.default.cache.duration`). */
610
+ readonly queryCacheDefaultDuration?: string;
399
611
  private readonly datasets;
400
612
  private readonly backend;
401
613
  readonly features?: SdkFeatures;
@@ -406,10 +618,13 @@ declare class App extends Observable implements AppContext {
406
618
  private _selection?;
407
619
  private _appliedSelection?;
408
620
  /**
409
- * Whether a run has ever committed the selection. Needed because `undefined` is a real applied
410
- * value — "nothing selected" — unlike a control's condition, which is always present.
621
+ * Whether a run has ever committed the selection, that is whether `execute()` has ever run. Needed
622
+ * because `undefined` is a real applied value — "nothing selected" — unlike a control's condition,
623
+ * which is always present.
411
624
  */
412
625
  private selectionCommitted;
626
+ /** The id the next query created gets. */
627
+ private nextQueryId;
413
628
  constructor(declaration: AppDeclaration, datasets: Record<string, DatasetIndex>, backend: Backend, features?: SdkFeatures,
414
629
  /** @internal What plugins add to each query and control. */
415
630
  extensions?: EntityExtensions<Query, Control> | undefined);
@@ -428,7 +643,7 @@ declare class App extends Observable implements AppContext {
428
643
  * because "the control happens to name a field this query also has" is exactly the coupling that
429
644
  * breaks silently when someone renames a dimension.
430
645
  *
431
- * There is no `unmap`: a mapping you do not want is one you do not declare.
646
+ * Edges never change: to change one, `remove()` it and map again.
432
647
  */
433
648
  mapControl(from: Control, to: Query, options: {
434
649
  field: string;
@@ -445,6 +660,19 @@ declare class App extends Observable implements AppContext {
445
660
  * never cascades, so `a -> b` and `b -> a` simply means either chart may drive the other.
446
661
  */
447
662
  mapCrossFilter(from: Query, to: Query): CrossFilter;
663
+ /** @internal Backs `query.update`: checks the change against the app, then swaps it in. */
664
+ updateQuery(query: Query, changes: QueryUpdate): void;
665
+ /** @internal Backs `remove()` on a query or a control: takes it out, with its edges. */
666
+ removeEntity(entity: Query | Control): void;
667
+ /** @internal Backs `remove()` on an edge. */
668
+ removeEdge(edge: Edge): void;
669
+ private readonly removedListeners;
670
+ /** @internal Each query or control removed from this app, for what the kernel shows about one. */
671
+ onRemoved(listener: (entity: Query | Control) => void): () => void;
672
+ /** Takes out the edges that match; whether any did. */
673
+ private dropEdges;
674
+ /** Clears the selection, the reader's and the applied one, when it was made in this query. */
675
+ private dropSelectionFrom;
448
676
  /**
449
677
  * What the reader has picked, if anything.
450
678
  *
@@ -459,7 +687,23 @@ declare class App extends Observable implements AppContext {
459
687
  /** Part of the declaration, not the environment. Changing it makes every query dirty. */
460
688
  setTimezone(timezone: string | undefined): void;
461
689
  get timezone(): string | undefined;
690
+ /**
691
+ * The app's own, like `setTimezone`: for its UI, and for its queries unless
692
+ * `query.default.input.weekStartDay` says otherwise. Changing it makes every query it reaches dirty.
693
+ */
694
+ setWeekStartDay(day: WeekStartDay | undefined): void;
695
+ /** The app's own week start day, for its UI: undefined when it declares none. */
696
+ get weekStartDay(): WeekStartDay | undefined;
697
+ /**
698
+ * What the app's queries get in their input when they set none: its `query.default.input`, or else
699
+ * its own timezone and week start day. A value absent from both is left to the backend's default.
700
+ */
701
+ get queryInputDefaults(): QueryInputDefaults;
462
702
  datasetIndex(uname: string, entity: string): DatasetIndex;
703
+ filterDataset(entity: string, declaration: {
704
+ dataset?: string;
705
+ field?: string;
706
+ }): DatasetIndex | undefined;
463
707
  mappingsTo(queryName: string): Mapping[];
464
708
  /** The expression form, set only when the structured conditions would have been lossy. */
465
709
  selectionExpressionFor(queryName: string, phase: 'pending' | 'applied'): string | undefined;
@@ -474,13 +718,24 @@ declare class App extends Observable implements AppContext {
474
718
  */
475
719
  private drillTransformations;
476
720
  menu(query: Query, event: Event, rows: readonly Row[], fields?: readonly string[], measure?: string): boolean;
721
+ /**
722
+ * @internal What a menu on these rows of the query is about: their conditions, derived as a
723
+ * cross-filter's, and the annotations plugins set on them (on `measure`'s, when given).
724
+ */
725
+ rowsTarget(query: Query, rows: readonly Row[], fields?: readonly string[], measure?: string): RowsTarget;
477
726
  /**
478
727
  * @internal Backs the kernel's `queryRequest(query)`: what the query runs with now, from its applied
479
728
  * state, as `fetchPage` and `exportQuery` build theirs.
480
729
  */
481
730
  requestFor(query: Query): QueryRequest;
482
731
  select(query: Query, rows: readonly Row[], fields?: readonly string[]): void;
483
- /** True when a control or the selection has changed since the queries reading it last ran. */
732
+ /**
733
+ * True when the next `execute()` would apply something: a control or the selection changed since
734
+ * the queries reading them last ran, a query changed since its last run (edited, or an edge or a
735
+ * control taken from it), or, once the app has run, a query was created and never run. A run in
736
+ * flight with the current inputs is not a change, and nor is a failed run: retrying it is
737
+ * `execute()`'s, unasked.
738
+ */
484
739
  get hasChanges(): boolean;
485
740
  /**
486
741
  * False before the first execution, matching `Control.isDirty`: with nothing applied there is
@@ -493,6 +748,16 @@ declare class App extends Observable implements AppContext {
493
748
  * query must not blank the other four. See docs/adr/0002.
494
749
  */
495
750
  execute(options?: ExecuteOptions): Promise<ExecuteSummary>;
751
+ /**
752
+ * @internal Backs `query.execute()`: that query alone, with what is applied, committing nothing.
753
+ * Its signature is the applied one, so a query the reader has pending changes for stays dirty.
754
+ */
755
+ executeQuery(query: Query, options?: ExecuteOptions): Promise<ExecuteSummary>;
756
+ /**
757
+ * One query's run from its first page, with the applied inputs, recorded under `signature`.
758
+ * Undefined when a newer run took the query over, or it was aborted.
759
+ */
760
+ private run;
496
761
  /** Re-runs everything and asks the server to skip its result cache. */
497
762
  refresh(): Promise<ExecuteSummary>;
498
763
  abort(): void;
@@ -503,7 +768,7 @@ declare class App extends Observable implements AppContext {
503
768
  * `fetchPage` is, so the file holds what the reader is looking at, every row of it. `send` makes
504
769
  * the export (the plugin's call); this touches nothing on the query.
505
770
  */
506
- exportQuery(query: Query, options: ExportOptions, send: (request: BackendExportRequest, signal: AbortSignal) => Promise<ExportResult>): Promise<ExportResult>;
771
+ exportQuery(query: Query, options: ExportOptions, send: (request: BackendExportRequest, signal: AbortSignal, stamp: CallStamp) => Promise<ExportResult>): Promise<ExportResult>;
507
772
  /**
508
773
  * The declaration and nothing else — no datasets, no backend, no reader state. This is the
509
774
  * shape a persisted Data App record will take, which is why mapping edges are already generic.
@@ -531,6 +796,8 @@ declare class App extends Observable implements AppContext {
531
796
  * host's locate-by-entity.
532
797
  */
533
798
  locate(kind: LocateKind, name: string): boolean;
799
+ /** What a query's calls are stamped with, so the host can show each under its query. */
800
+ private stampOf;
534
801
  private assertNameFree;
535
802
  /**
536
803
  * A field-backed filter usually lives in an app with one dataset, so requiring `dataset` on every
@@ -714,6 +981,14 @@ interface BuiltStructure extends InspectedStructure {
714
981
  */
715
982
  declare function buildStructure(doc: Document, apps: readonly App[]): BuiltStructure;
716
983
 
984
+ /**
985
+ * The kernel's UI body: the menu, the modal and the popover plugins draw content UI with, in the
986
+ * plugin layer, on the host's `--anfra-*` tokens. Sent to a frame the first time it opens one
987
+ * (`anfra.body` for `anfra`), so a frame that never does carries none of it. The kernel hands it its
988
+ * shadow root, and keeps one open at a time. Also the annotations badge, and the list its popover
989
+ * shows (docs/designs/sdk-plugins.md, Annotations).
990
+ */
991
+
717
992
  /** Which side of its anchor a popover opens on. */
718
993
  type PopoverSide = 'right' | 'left' | 'bottom' | 'top';
719
994
 
@@ -756,14 +1031,23 @@ type FrameMenuItem = FrameMenuItemBase & ({
756
1031
  label?: never;
757
1032
  run?: never;
758
1033
  });
1034
+ /** The query a modal or popover is about: it closes when the query is removed. */
1035
+ interface QueryAbout {
1036
+ app: number;
1037
+ query: string;
1038
+ }
759
1039
  interface ModalInput {
760
1040
  title: string;
1041
+ /** The query it shows something of, if any: removing the query closes it. */
1042
+ about?: QueryAbout;
761
1043
  size?: 'sm' | 'md' | 'lg' | 'full';
762
1044
  /** Draw the content into its own shadow root, on the host's `--anfra-*` tokens; what it returns runs on close. */
763
1045
  mount: (root: ShadowRoot) => void | (() => void);
764
1046
  onClose?: () => void;
765
1047
  }
766
1048
  interface PopoverInput {
1049
+ /** The query it shows something of, if any: removing the query closes it. */
1050
+ about?: QueryAbout;
767
1051
  /** A node (a target's, kept in view as the page scrolls), or a point in the viewport. */
768
1052
  anchor: NodeTarget | {
769
1053
  x: number;
@@ -820,8 +1104,11 @@ interface FrameKernel {
820
1104
  * needs and sends it as `core.submitQuery`, through the pipeline like any query.
821
1105
  */
822
1106
  queryRequest: (query: Query) => QueryRequest;
823
- /** Make a host half's call, by its full name (`core.submitQuery`). */
824
- call: <T = unknown>(name: string, request?: unknown, signal?: AbortSignal) => Promise<T>;
1107
+ /**
1108
+ * Make a host half's call, by its full name (`core.submitQuery`). `stamp` names the query the call
1109
+ * is for, so the host shows it under that query (its request log). The kernel adds the query's id.
1110
+ */
1111
+ call: <T = unknown>(name: string, request?: unknown, signal?: AbortSignal, stamp?: CallStamp) => Promise<T>;
825
1112
  /** Send the host one of this plugin's events, by its name under the plugin. */
826
1113
  emit: (name: string, payload?: unknown) => void;
827
1114
  /** Answer one of this plugin's calls made by the host, by its name under the plugin. */
@@ -850,6 +1137,16 @@ interface FrameKernel {
850
1137
  modal: (input: ModalInput) => Promise<Opened>;
851
1138
  /** Open a popover beside a node or a point, following it as the page scrolls. */
852
1139
  popover: (input: PopoverInput) => Promise<Opened>;
1140
+ /**
1141
+ * Set this plugin's annotations on a query, replacing its last set; `[]` clears it. `result` is
1142
+ * the `query.result` they were computed from: when it is no longer the query's, nothing changes
1143
+ * and this returns false. Throws on a malformed annotation; a rows anchor's row the result lacks
1144
+ * is dropped quietly. They go when the query's result is replaced, or at once when the
1145
+ * definition updates the query, so annotate each new result (`query.subscribe`).
1146
+ */
1147
+ annotate: (query: Query, annotations: readonly AnnotationInput[], options: {
1148
+ result: QueryResult;
1149
+ }) => boolean;
853
1150
  }
854
1151
 
855
1152
  /** A plugin's frame setup, as the host's frame script hands it over: its name and its function. */
package/dist/build.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FrameHalf } from './host.js';
2
- import './types-N0V9n38H.js';
3
- import './menu-Cam-hOdJ.js';
2
+ import './types-BE767W6G.js';
3
+ import './theme-FQ_1b569.js';
4
4
 
5
5
  /**
6
6
  * @holistics/anfra-sdk/build: building an SDK plugin's frame half into the script source a host
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  LINEAGE_TAB,
3
3
  plural
4
- } from "./chunk-H52PO7MP.js";
4
+ } from "./chunk-33HI2ODM.js";
5
5
 
6
6
  // src/plugins/inspect/model/trust.ts
7
7
  var TRUST_LEVELS = {