@holistics/anfra-sdk 0.19.0 → 0.21.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 (36) 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 +4 -3
  6. package/dist/{bootstrap-5xNrSbJb.d.ts → bootstrap-BxBqFhgm.d.ts} +279 -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-4TXKXLWK.js → chunk-7I2HXY72.js} +1 -1
  12. package/dist/{chunk-ZSIJLBKG.js → chunk-7NZOMBYE.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-CDZ7MBXC.js → chunk-E3Q3FRKQ.js} +1 -1
  16. package/dist/{chunk-SXKJQU7A.js → chunk-GPBYPSWK.js} +22 -36
  17. package/dist/{chunk-OS4CRPTU.js → chunk-IHRNKDMO.js} +830 -265
  18. package/dist/{chunk-EIPHDMZ7.js → chunk-UWRQXPPG.js} +69 -24
  19. package/dist/common.d.ts +3 -3
  20. package/dist/{data-ESPFZ5IM.js → data-SZDYO55C.js} +7 -5
  21. package/dist/{declaration-RYRBX7PH.js → declaration-GYV6OUR3.js} +5 -3
  22. package/dist/{errors-BlRfqyty.d.ts → errors-DR05L6-y.d.ts} +1 -1
  23. package/dist/host.d.ts +2 -2
  24. package/dist/host.js +29 -6
  25. package/dist/{menu-Dmfu51qo.d.ts → menu-CuTKq-dC.d.ts} +2 -1
  26. package/dist/{overview-S6FTM2JT.js → overview-KOQJNG2Y.js} +28 -13
  27. package/dist/{plugin-C_Cc_e9L.d.ts → plugin-BIcighnC.d.ts} +7 -2
  28. package/dist/plugins.d.ts +1 -7
  29. package/dist/plugins.js +53 -17
  30. package/dist/{queries-FWMX7H5Z.js → queries-BWKWZQMG.js} +70 -17
  31. package/dist/{structure-VFRJFC4C.js → structure-JO4YZHKZ.js} +5 -3
  32. package/dist/{tab-XL2HS5W4.js → tab-QPHE7YUQ.js} +3 -3
  33. package/dist/testing.d.ts +2 -1
  34. package/dist/testing.js +8 -7
  35. package/dist/{types-DKQjAL1O.d.ts → types-C_-1rgj2.d.ts} +783 -123
  36. 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-BlRfqyty.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-DKQjAL1O.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-Dmfu51qo.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-DR05L6-y.js';
2
+ import { Y as Listener, ar as Unsubscribe, D as DatasetDescriptor, z as ExportOptions, F as ExportResult, ah as RenderRequest, ai as Rendering, X as LineageTarget, V as LineageOptions, W as LineageResult, E as EntityKind, m as Condition, K as FilterDeclaration, B as Backend, L as FilterValueType, n as ConditionValue, q as DateDrillDeclaration, r as DateGrain, J as FilterAggregation, p as CrossFilterJson, o as ControlMappingJson, a6 as QueryInputDefaults, al as SdkFeatures, am as Selection, an as SelectionCondition, aj as Row, v as ExecuteOptions, w as ExecuteSummary, Z as LocateKind, a5 as QueryInput, a4 as QueryDeclaration, a2 as QueryCacheSettings, ac as QuerySort, ae as QueryState, aa as QueryResult, a as AppDeclaration, at as WeekStartDay, a9 as QueryRequest, f as BackendExportRequest, C as CallStamp, b as AppJson, M as InspectedApp, as as User, ak as SdkEnvironment, R as InspectedStructure } from './types-C_-1rgj2.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-CuTKq-dC.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,42 @@ 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
+ constructor(name: string, app: AppContext & Observable, declaration: QueryDeclaration, id: number);
422
+ /** What it was declared with, or last updated to. */
423
+ get declaration(): QueryDeclaration;
424
+ /** The dataset its declaration names, resolved. */
425
+ get dataset(): DatasetIndex;
426
+ /** False once `remove()` took it out of its app. */
427
+ get isRemoved(): boolean;
428
+ /**
429
+ * Swaps what this query is: its dataset, its AQL, its page size, its cache, checked as `createQuery` checks
430
+ * them. Its name, its edges and its result stay; the result until the rerun replaces it. Runs
431
+ * nothing: the query is dirty, and the next `app.execute()` reruns it, so several edits go out
432
+ * as one run. Back to the first page. A run or page in flight is aborted, and `fetchMore` does
433
+ * nothing until the rerun. A new AQL or dataset clears the sort (unless `sort` is given) and a
434
+ * selection made in this query, whose rows no longer mean the same.
435
+ */
436
+ update(changes: QueryUpdate): void;
437
+ /**
438
+ * Takes this query out of its app: its control mappings and cross-filters go with it, a run in
439
+ * flight is aborted, a selection made in it is cleared, and its name is free again. The queries
440
+ * it cross-filtered rerun without it at the next `app.execute()`. Every method of it throws from
441
+ * then on.
442
+ */
443
+ remove(): void;
444
+ /** @internal Throws once the query was removed. */
445
+ assertLive(): void;
446
+ /** @internal The app's half of `update`, checked by then: swap the declaration. */
447
+ replaceDeclaration(declaration: QueryDeclaration, dataset: DatasetIndex, sort: readonly QuerySort[]): void;
448
+ /** @internal The app's half of `remove`: stop what is in flight, and stay quiet from then on. */
449
+ markRemoved(): void;
293
450
  /**
294
451
  * Bring the elements marked `data-anfra-query` with this query's name into view: scroll to the
295
452
  * first and show them all for a moment. False, and nothing done, when no element on the page is
@@ -307,27 +464,48 @@ declare class Query extends Observable {
307
464
  setSort(sort: readonly QuerySort[]): void;
308
465
  /**
309
466
  * 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.
467
+ * say, whether that page came back full. False after `update` until the rerun.
311
468
  */
312
469
  get hasMore(): boolean;
313
470
  /**
314
471
  * Everything that changes the rows: the declaration, the conditions reaching this query through
315
472
  * mappings, the conditions reaching it from the selection, the sort override, the app's timezone,
316
473
  * and the page. Compared against the last successful run to decide whether re-running would
317
- * produce anything new.
474
+ * produce anything new. `pending` reads the controls and selection as the reader has them,
475
+ * `applied` as the app last applied them; they differ only between a change and `app.execute()`.
318
476
  */
319
- signature(): string;
477
+ signature(phase?: 'pending' | 'applied'): string;
320
478
  /**
321
479
  * False before the first run: with nothing applied there is nothing to have changed. Distinct
322
480
  * from `shouldRun`, which is true in that case precisely because there is no result yet.
323
481
  */
324
482
  get isDirty(): boolean;
483
+ /**
484
+ * @internal For `app.hasChanges`: whether the next `app.execute()` would run it with inputs no run
485
+ * of it has had. Not when its pending inputs are those of its run in flight, its last successful
486
+ * run or, when it last failed, its failed run: a failure is not a change. Never attempted, only
487
+ * once `executed` (the app has run): before that, nothing has been applied to differ from.
488
+ */
489
+ hasUnappliedChange(executed: boolean): boolean;
325
490
  /**
326
491
  * @internal Also when its last run failed, whatever its inputs: so `execute()` is the retry, of
327
492
  * the failed queries only, even after a forced run (`refresh()`) failed with unchanged inputs. Not
328
493
  * after a failed `fetchMore`: rerun, it would drop the pages already loaded; `fetchMore` is its retry.
329
494
  */
330
495
  shouldRun(force?: boolean): boolean;
496
+ /**
497
+ * @internal For `query.execute()`: like `shouldRun`, but against what is applied, since applying
498
+ * the reader's pending changes is the app's, for every query at once. Its own sort and the
499
+ * timezone count; a control or selection the reader changed and the app has not applied does not.
500
+ */
501
+ shouldRunAlone(force?: boolean): boolean;
502
+ /**
503
+ * Runs this query alone, with the inputs the app last applied, if that would produce something
504
+ * new; with `force`, whatever its inputs (a paged query starts over at its first page). Applies
505
+ * none of the reader's pending changes: that is `app.execute()`'s, so the query stays dirty and
506
+ * the next `app.execute()` runs it with them. Never rejects, as `app.execute()` doesn't.
507
+ */
508
+ execute(options?: ExecuteOptions): Promise<ExecuteSummary>;
331
509
  /** Stops the in-flight request for this query. The pending `execute()` resolves without it. */
332
510
  abort(): void;
333
511
  /** Fetches the next page and appends it. Rejects rather than swallowing, unlike `execute()`. */
@@ -371,10 +549,17 @@ declare class Query extends Observable {
371
549
  get selectedRows(): readonly Row[];
372
550
  /** @internal */
373
551
  markExecuting(): void;
552
+ /** @internal The cache duration it runs with: its own, or its app's default. Absent: the backend's default. */
553
+ get cacheDuration(): string | undefined;
554
+ /** @internal The run the result on screen came from, for its next page and its export. */
555
+ get run(): Run | undefined;
374
556
  /** @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;
557
+ markSuccess(result: QueryResult, signature: string, append: boolean, run?: Run): void;
558
+ /**
559
+ * @internal `page` when it is a `fetchMore` that failed, not a run; `signature`, a failed run's
560
+ * inputs.
561
+ */
562
+ markError(error: DataAppError, page?: boolean, signature?: string): void;
378
563
  /** @internal Reverts an optimistic page bump when a `fetchMore` fails. */
379
564
  rewindPage(): void;
380
565
  /** @internal */
@@ -396,6 +581,11 @@ declare class App extends Observable implements AppContext {
396
581
  private readonly extensions?;
397
582
  readonly title?: string;
398
583
  private _timezone?;
584
+ private _weekStartDay?;
585
+ /** The app's `query.default.input`: what its queries use over its own timezone and week start day. */
586
+ private readonly queryInput;
587
+ /** The cache duration of each of the app's queries that declares none (`query.default.cache.duration`). */
588
+ readonly queryCacheDefaultDuration?: string;
399
589
  private readonly datasets;
400
590
  private readonly backend;
401
591
  readonly features?: SdkFeatures;
@@ -406,10 +596,13 @@ declare class App extends Observable implements AppContext {
406
596
  private _selection?;
407
597
  private _appliedSelection?;
408
598
  /**
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.
599
+ * Whether a run has ever committed the selection, that is whether `execute()` has ever run. Needed
600
+ * because `undefined` is a real applied value — "nothing selected" — unlike a control's condition,
601
+ * which is always present.
411
602
  */
412
603
  private selectionCommitted;
604
+ /** The id the next query created gets. */
605
+ private nextQueryId;
413
606
  constructor(declaration: AppDeclaration, datasets: Record<string, DatasetIndex>, backend: Backend, features?: SdkFeatures,
414
607
  /** @internal What plugins add to each query and control. */
415
608
  extensions?: EntityExtensions<Query, Control> | undefined);
@@ -428,7 +621,7 @@ declare class App extends Observable implements AppContext {
428
621
  * because "the control happens to name a field this query also has" is exactly the coupling that
429
622
  * breaks silently when someone renames a dimension.
430
623
  *
431
- * There is no `unmap`: a mapping you do not want is one you do not declare.
624
+ * Edges never change: to change one, `remove()` it and map again.
432
625
  */
433
626
  mapControl(from: Control, to: Query, options: {
434
627
  field: string;
@@ -445,6 +638,19 @@ declare class App extends Observable implements AppContext {
445
638
  * never cascades, so `a -> b` and `b -> a` simply means either chart may drive the other.
446
639
  */
447
640
  mapCrossFilter(from: Query, to: Query): CrossFilter;
641
+ /** @internal Backs `query.update`: checks the change against the app, then swaps it in. */
642
+ updateQuery(query: Query, changes: QueryUpdate): void;
643
+ /** @internal Backs `remove()` on a query or a control: takes it out, with its edges. */
644
+ removeEntity(entity: Query | Control): void;
645
+ /** @internal Backs `remove()` on an edge. */
646
+ removeEdge(edge: Edge): void;
647
+ private readonly removedListeners;
648
+ /** @internal Each query or control removed from this app, for what the kernel shows about one. */
649
+ onRemoved(listener: (entity: Query | Control) => void): () => void;
650
+ /** Takes out the edges that match; whether any did. */
651
+ private dropEdges;
652
+ /** Clears the selection, the reader's and the applied one, when it was made in this query. */
653
+ private dropSelectionFrom;
448
654
  /**
449
655
  * What the reader has picked, if anything.
450
656
  *
@@ -459,7 +665,23 @@ declare class App extends Observable implements AppContext {
459
665
  /** Part of the declaration, not the environment. Changing it makes every query dirty. */
460
666
  setTimezone(timezone: string | undefined): void;
461
667
  get timezone(): string | undefined;
668
+ /**
669
+ * The app's own, like `setTimezone`: for its UI, and for its queries unless
670
+ * `query.default.input.weekStartDay` says otherwise. Changing it makes every query it reaches dirty.
671
+ */
672
+ setWeekStartDay(day: WeekStartDay | undefined): void;
673
+ /** The app's own week start day, for its UI: undefined when it declares none. */
674
+ get weekStartDay(): WeekStartDay | undefined;
675
+ /**
676
+ * What the app's queries get in their input when they set none: its `query.default.input`, or else
677
+ * its own timezone and week start day. A value absent from both is left to the backend's default.
678
+ */
679
+ get queryInputDefaults(): QueryInputDefaults;
462
680
  datasetIndex(uname: string, entity: string): DatasetIndex;
681
+ filterDataset(entity: string, declaration: {
682
+ dataset?: string;
683
+ field?: string;
684
+ }): DatasetIndex | undefined;
463
685
  mappingsTo(queryName: string): Mapping[];
464
686
  /** The expression form, set only when the structured conditions would have been lossy. */
465
687
  selectionExpressionFor(queryName: string, phase: 'pending' | 'applied'): string | undefined;
@@ -480,7 +702,13 @@ declare class App extends Observable implements AppContext {
480
702
  */
481
703
  requestFor(query: Query): QueryRequest;
482
704
  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. */
705
+ /**
706
+ * True when the next `execute()` would apply something: a control or the selection changed since
707
+ * the queries reading them last ran, a query changed since its last run (edited, or an edge or a
708
+ * control taken from it), or, once the app has run, a query was created and never run. A run in
709
+ * flight with the current inputs is not a change, and nor is a failed run: retrying it is
710
+ * `execute()`'s, unasked.
711
+ */
484
712
  get hasChanges(): boolean;
485
713
  /**
486
714
  * False before the first execution, matching `Control.isDirty`: with nothing applied there is
@@ -493,6 +721,16 @@ declare class App extends Observable implements AppContext {
493
721
  * query must not blank the other four. See docs/adr/0002.
494
722
  */
495
723
  execute(options?: ExecuteOptions): Promise<ExecuteSummary>;
724
+ /**
725
+ * @internal Backs `query.execute()`: that query alone, with what is applied, committing nothing.
726
+ * Its signature is the applied one, so a query the reader has pending changes for stays dirty.
727
+ */
728
+ executeQuery(query: Query, options?: ExecuteOptions): Promise<ExecuteSummary>;
729
+ /**
730
+ * One query's run from its first page, with the applied inputs, recorded under `signature`.
731
+ * Undefined when a newer run took the query over, or it was aborted.
732
+ */
733
+ private run;
496
734
  /** Re-runs everything and asks the server to skip its result cache. */
497
735
  refresh(): Promise<ExecuteSummary>;
498
736
  abort(): void;
@@ -503,7 +741,7 @@ declare class App extends Observable implements AppContext {
503
741
  * `fetchPage` is, so the file holds what the reader is looking at, every row of it. `send` makes
504
742
  * the export (the plugin's call); this touches nothing on the query.
505
743
  */
506
- exportQuery(query: Query, options: ExportOptions, send: (request: BackendExportRequest, signal: AbortSignal) => Promise<ExportResult>): Promise<ExportResult>;
744
+ exportQuery(query: Query, options: ExportOptions, send: (request: BackendExportRequest, signal: AbortSignal, stamp: CallStamp) => Promise<ExportResult>): Promise<ExportResult>;
507
745
  /**
508
746
  * The declaration and nothing else — no datasets, no backend, no reader state. This is the
509
747
  * shape a persisted Data App record will take, which is why mapping edges are already generic.
@@ -531,6 +769,8 @@ declare class App extends Observable implements AppContext {
531
769
  * host's locate-by-entity.
532
770
  */
533
771
  locate(kind: LocateKind, name: string): boolean;
772
+ /** What a query's calls are stamped with, so the host can show each under its query. */
773
+ private stampOf;
534
774
  private assertNameFree;
535
775
  /**
536
776
  * A field-backed filter usually lives in an app with one dataset, so requiring `dataset` on every
@@ -756,14 +996,23 @@ type FrameMenuItem = FrameMenuItemBase & ({
756
996
  label?: never;
757
997
  run?: never;
758
998
  });
999
+ /** The query a modal or popover is about: it closes when the query is removed. */
1000
+ interface QueryAbout {
1001
+ app: number;
1002
+ query: string;
1003
+ }
759
1004
  interface ModalInput {
760
1005
  title: string;
1006
+ /** The query it shows something of, if any: removing the query closes it. */
1007
+ about?: QueryAbout;
761
1008
  size?: 'sm' | 'md' | 'lg' | 'full';
762
1009
  /** Draw the content into its own shadow root, on the host's `--anfra-*` tokens; what it returns runs on close. */
763
1010
  mount: (root: ShadowRoot) => void | (() => void);
764
1011
  onClose?: () => void;
765
1012
  }
766
1013
  interface PopoverInput {
1014
+ /** The query it shows something of, if any: removing the query closes it. */
1015
+ about?: QueryAbout;
767
1016
  /** A node (a target's, kept in view as the page scrolls), or a point in the viewport. */
768
1017
  anchor: NodeTarget | {
769
1018
  x: number;
@@ -820,8 +1069,11 @@ interface FrameKernel {
820
1069
  * needs and sends it as `core.submitQuery`, through the pipeline like any query.
821
1070
  */
822
1071
  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>;
1072
+ /**
1073
+ * Make a host half's call, by its full name (`core.submitQuery`). `stamp` names the query the call
1074
+ * is for, so the host shows it under that query (its request log). The kernel adds the query's id.
1075
+ */
1076
+ call: <T = unknown>(name: string, request?: unknown, signal?: AbortSignal, stamp?: CallStamp) => Promise<T>;
825
1077
  /** Send the host one of this plugin's events, by its name under the plugin. */
826
1078
  emit: (name: string, payload?: unknown) => void;
827
1079
  /** Answer one of this plugin's calls made by the host, by its name under the plugin. */
package/dist/build.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FrameHalf } from './host.js';
2
- import './types-DKQjAL1O.js';
3
- import './menu-Dmfu51qo.js';
2
+ import './types-C_-1rgj2.js';
3
+ import './menu-CuTKq-dC.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 = {
@@ -19,6 +19,17 @@ function formatAgo(value, now = Date.now()) {
19
19
  if (seconds < 86400) return `${Math.floor(seconds / 3600)}h ago`;
20
20
  return `${Math.floor(seconds / 86400)}d ago`;
21
21
  }
22
+ function formatIn(value, now = Date.now()) {
23
+ if (!value) return "";
24
+ const time = (value instanceof Date ? value : new Date(value)).getTime();
25
+ if (Number.isNaN(time)) return String(value);
26
+ const seconds = Math.floor((time - now) / 1e3);
27
+ if (seconds < 0) return "expired";
28
+ if (seconds < 60) return "in < 1m";
29
+ if (seconds < 3600) return `in ${Math.floor(seconds / 60)}m`;
30
+ if (seconds < 86400) return `in ${Math.floor(seconds / 3600)}h`;
31
+ return `in ${Math.floor(seconds / 86400)}d`;
32
+ }
22
33
  var plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
23
34
  var entityKey = (kind, app, name) => `${kind}:${app}/${name}`;
24
35
  function entityAttribute(kind, app, name) {
@@ -81,10 +92,22 @@ var STRUCTURE_TAB = "inspect.structure";
81
92
  var DECLARATION_TAB = "inspect.declaration";
82
93
  var LINEAGE_TAB = "lineage.lineage";
83
94
 
95
+ // src/plugins/inspect/model/entities.ts
96
+ function hasEntity(apps, kind, app, name) {
97
+ return Object.hasOwn((kind === "query" ? apps[app]?.queries : apps[app]?.controls) ?? {}, name);
98
+ }
99
+ var ENTITY_KEY = /^(query|control):(\d+)\/(.+)$/;
100
+ function entityGone(key, apps) {
101
+ const match = key ? ENTITY_KEY.exec(key) : null;
102
+ if (!match) return false;
103
+ return !hasEntity(apps, match[1], Number(match[2]), match[3]);
104
+ }
105
+
84
106
  export {
85
107
  formatCondition,
86
108
  formatTime,
87
109
  formatAgo,
110
+ formatIn,
88
111
  plural,
89
112
  entityKey,
90
113
  entityAttribute,
@@ -96,6 +119,8 @@ export {
96
119
  blockNodeKey,
97
120
  entityNodeKey,
98
121
  dedent,
122
+ hasEntity,
123
+ entityGone,
99
124
  OVERVIEW_TAB,
100
125
  DATA_TAB,
101
126
  QUERIES_TAB,
@@ -0,0 +1,32 @@
1
+ // src/common/shortcut.ts
2
+ var MODIFIERS = ["ctrl", "alt", "shift", "meta"];
3
+ function normalizeShortcut(shortcut) {
4
+ if (typeof shortcut !== "string") return void 0;
5
+ const parts = shortcut.split("+").map((part) => part.trim().toLowerCase()).filter(Boolean);
6
+ const key = parts.pop();
7
+ const isModifier = (part) => MODIFIERS.includes(part);
8
+ if (!key || isModifier(key) || !parts.every(isModifier)) return void 0;
9
+ return [...MODIFIERS.filter((modifier) => parts.includes(modifier)), key].join("+");
10
+ }
11
+ function isTyping(target) {
12
+ const element = target;
13
+ if (!element || typeof element.tagName !== "string") return false;
14
+ return element.isContentEditable === true || ["INPUT", "TEXTAREA", "SELECT"].includes(element.tagName.toUpperCase());
15
+ }
16
+ function eventShortcut(event) {
17
+ const code = typeof event.code === "string" ? event.code : "";
18
+ const key = /^Key[A-Z]$/.test(code) ? code.slice(3).toLowerCase() : /^Digit[0-9]$/.test(code) ? code.slice(5) : (event.key ?? "").toLowerCase();
19
+ return [
20
+ event.ctrlKey && "ctrl",
21
+ event.altKey && "alt",
22
+ event.shiftKey && "shift",
23
+ event.metaKey && "meta",
24
+ key
25
+ ].filter(Boolean).join("+");
26
+ }
27
+
28
+ export {
29
+ normalizeShortcut,
30
+ isTyping,
31
+ eventShortcut
32
+ };
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  formatCondition,
6
6
  handleFor
7
- } from "./chunk-H52PO7MP.js";
7
+ } from "./chunk-33HI2ODM.js";
8
8
 
9
9
  // src/plugins/inspect/model/changes.ts
10
10
  function originalCondition(app, name, kind) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  version
3
- } from "./chunk-CDZ7MBXC.js";
3
+ } from "./chunk-E3Q3FRKQ.js";
4
4
 
5
5
  // src/plugins/version.ts
6
6
  var PLUGIN_VERSION = version;