@holistics/anfra-sdk 0.10.1 → 0.11.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.
@@ -0,0 +1,694 @@
1
+ import { D as DataAppError, V as ValidationError, Q as QueryError, P as PermissionError, T as TransportError } from './errors-CKvqVaqU.js';
2
+ import { X as Listener, ah as Unsubscribe, D as DatasetDescriptor, y as ExportOptions, z as ExportResult, a7 as RenderRequest, a8 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, ab as SdkFeatures, ac as Selection, ad as SelectionCondition, a9 as Row, Y as LocateKind, a1 as QueryDeclaration, a5 as QueryState, a3 as QueryResult, a4 as QuerySort, a as AppDeclaration, u as ExecuteOptions, v as ExecuteSummary, f as BackendExportRequest, b as AppJson, L as InspectedApp, ai as User, aa as SdkEnvironment, Q as InspectedStructure } from './types-BTyDyld7.js';
3
+ import { b as PluginInfo } from './bridge-Byq62yS8.js';
4
+
5
+ interface NotificationTarget {
6
+ notifyChange(): void;
7
+ }
8
+ /**
9
+ * The smallest thing that adapts to every framework: `subscribe(listener) => unsubscribe` is the
10
+ * signature React's `useSyncExternalStore` wants, and a Vue adapter is a `shallowRef` plus a
11
+ * `triggerRef`. Deliberately not named events (a taxonomy to version) nor a signal primitive
12
+ * (owning a reactivity library). See docs/adr/0002.
13
+ */
14
+ declare class Observable implements NotificationTarget {
15
+ private readonly listeners;
16
+ private readonly parent?;
17
+ constructor(parent?: NotificationTarget);
18
+ subscribe(listener: Listener): Unsubscribe;
19
+ /**
20
+ * Public only so a child observable can bubble into its parent — an app subscriber sees every
21
+ * entity's changes through one subscription. Subclasses call the protected `notify` instead.
22
+ */
23
+ notifyChange(): void;
24
+ protected notify(): void;
25
+ }
26
+
27
+ interface ResolvedField {
28
+ /**
29
+ * The model's *name*, not a database id, and absent for a dataset-level metric. Backends resolve
30
+ * fields by name, the way AQL does; `data_models[].id` is not reliably populated.
31
+ */
32
+ modelName?: string;
33
+ fieldName: string;
34
+ isMetric: boolean;
35
+ type: string;
36
+ label: string;
37
+ }
38
+ /**
39
+ * Indexes one dataset's fields so validation is a lookup rather than a scan, and so we have a
40
+ * candidate list to draw typo suggestions from.
41
+ */
42
+ declare class DatasetIndex {
43
+ readonly descriptor: DatasetDescriptor;
44
+ private readonly fields;
45
+ readonly references: string[];
46
+ constructor(descriptor: DatasetDescriptor);
47
+ resolve(reference: string, entity: string): ResolvedField;
48
+ }
49
+
50
+ /**
51
+ * The types of what plugins add to a Data App's frame: one registry, `AnfraPlugins`, from which the
52
+ * members of `Anfra`, a query and a control are derived, each optional, since a plugin adds its
53
+ * API only where its host installed it (docs/designs/sdk-plugins.md, Types). Types only: nothing here
54
+ * runs.
55
+ */
56
+
57
+ /**
58
+ * What a plugin adds, by where: `anfra` is `Anfra.<plugin>`, `query` is `query.<plugin>` on every
59
+ * query, `control` is `control.<plugin>` on every control. Any may be left out.
60
+ */
61
+ interface PluginApi {
62
+ anfra?: unknown;
63
+ query?: unknown;
64
+ control?: unknown;
65
+ }
66
+ /**
67
+ * Every plugin's API, by the plugin's name. anfra's own are here; a plugin outside the SDK adds
68
+ * its entry from its own declarations:
69
+ *
70
+ * ```ts
71
+ * declare module '@holistics/anfra-sdk/app' {
72
+ * interface AnfraPlugins { notes: { anfra: NotesApi, query: QueryNotes } }
73
+ * }
74
+ * ```
75
+ */
76
+ interface AnfraPlugins {
77
+ /**
78
+ * `query.export()`: the query's whole result as a file, saved for the reader. Every row, not only
79
+ * the pages loaded, with what the result on screen was last run with: the mapped controls, the
80
+ * selection, the sort, the timezone. A control the reader changed but has not applied is not in
81
+ * it. Resolves once the file is made and its download has started, with its link and row count;
82
+ * rejects with a `DataAppError` naming the query, and changes nothing on it either way. Offer it
83
+ * only when `Anfra.user.permissions.canExportData` is true too.
84
+ */
85
+ export: {
86
+ query: (options?: ExportOptions) => Promise<ExportResult>;
87
+ };
88
+ /**
89
+ * `Anfra.render()`: the whole app, or one block or container of its structure by id, as a PNG or
90
+ * a PDF, saved for the reader. What is drawn is what the page shows now: `await app.execute()`
91
+ * first for fresh results. Elements marked `data-anfra-render="skip"` are left out. Offer it only
92
+ * when `Anfra.user.permissions.canExportData` is true too.
93
+ */
94
+ render: {
95
+ anfra: (request: RenderRequest) => Promise<Rendering>;
96
+ };
97
+ /**
98
+ * `Anfra.lineage()`: fields traced through the repo's catalog, as a diagram to draw. Name each by
99
+ * its parent and its name in it (`{ parent: 'ecommerce', child: 'revenue' }`). A field that
100
+ * cannot be traced answers its `error`, and the others still answer.
101
+ */
102
+ lineage: {
103
+ anfra: (targets: LineageTarget | readonly LineageTarget[], options?: LineageOptions) => Promise<LineageResult>;
104
+ };
105
+ /** Adds nothing to the app: the host's inspect panel reads the app through it. */
106
+ inspect: Record<never, never>;
107
+ }
108
+ /** A plugin's name: anfra's own and any a plugin's declarations added, for completion, or any other. */
109
+ type PluginName = keyof AnfraPlugins | (string & {});
110
+ /** What the plugins add at `where`, each member optional and named after its plugin. */
111
+ type PluginMembers<Where extends keyof PluginApi> = {
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
+ };
114
+
115
+ declare class Filter extends Control {
116
+ readonly kind: "filter";
117
+ readonly declaration: FilterDeclaration;
118
+ readonly type: FilterValueType;
119
+ private readonly resolved?;
120
+ private readonly datasetName?;
121
+ private readonly backend?;
122
+ private loadedOptions?;
123
+ constructor(name: string, app: AppContext & Observable, declaration: FilterDeclaration, dataset?: DatasetIndex, backend?: Backend);
124
+ setCondition(condition: Condition): void;
125
+ /**
126
+ * A number filter's values are strings, as query results give them, which keep every digit. A JS
127
+ * number may already have lost some (`Number("9007199254740993")` is ...992), and nothing after
128
+ * can tell, so the core API refuses one; this says so where the app hands it over.
129
+ */
130
+ private assertValues;
131
+ /** True for a field-backed filter, false for a manual one. The two are separate axes from `type`. */
132
+ get isFieldBacked(): boolean;
133
+ /** A manual filter's static list, or whatever the last `loadOptions()` returned. */
134
+ get options(): ConditionValue[];
135
+ /**
136
+ * Fetches option values for a field-backed filter.
137
+ *
138
+ * Lazy rather than fetched up front: building a distinct-values query for every filter is slow,
139
+ * and readers often touch none of them. The backend decides which values this reader may see.
140
+ */
141
+ loadOptions(search?: string, signal?: AbortSignal): Promise<ConditionValue[]>;
142
+ toJSON(): FilterDeclaration;
143
+ }
144
+ declare class DateDrillControl extends Control {
145
+ readonly kind: "dateDrill";
146
+ readonly declaration: DateDrillDeclaration;
147
+ constructor(name: string, app: AppContext & Observable, declaration?: DateDrillDeclaration);
148
+ setGrain(grain: DateGrain): void;
149
+ toJSON(): DateDrillDeclaration;
150
+ }
151
+ /**
152
+ * Base for the interactive controls. They are one mechanism — a named condition that
153
+ * maps onto queries — and differ only in the operators they produce. They are separate classes
154
+ * because a single `Filter` accepting all 25 operators would be untypeable in any useful way, and
155
+ * nobody should have to remember that a date drill is `transform_date_drill` with
156
+ * `values: ['datetrunc month']`.
157
+ */
158
+ declare abstract class Control extends Observable {
159
+ readonly name: string;
160
+ abstract readonly kind: EntityKind;
161
+ protected readonly app: AppContext & Observable;
162
+ private pending;
163
+ private applied?;
164
+ private readonly initial;
165
+ protected constructor(name: string, app: AppContext & Observable, initial: Condition);
166
+ /**
167
+ * Bring the elements marked `data-anfra-control` with this control's name into view. False when
168
+ * none is on the page yet; never throws.
169
+ */
170
+ locate(): boolean;
171
+ /** The reader's current value, which `execute()` will commit. */
172
+ get condition(): Condition;
173
+ /** The value this control's mapped queries last ran with. Undefined before the first execution. */
174
+ get appliedCondition(): Condition | undefined;
175
+ /**
176
+ * False before the first execution: with nothing applied there is nothing to differ from, so a
177
+ * control set from a URL at startup is not an unapplied change.
178
+ */
179
+ get isDirty(): boolean;
180
+ setCondition(condition: Condition): void;
181
+ reset(): void;
182
+ /** @internal Called by the executor once the queries reading this control have been submitted. */
183
+ commit(): void;
184
+ abstract toJSON(): unknown;
185
+ }
186
+ /** What the installed plugins add to every control (`AnfraPlugins`): each member is there only where its plugin is. */
187
+ interface Control extends PluginMembers<'control'> {
188
+ }
189
+
190
+ /**
191
+ * A directed edge from an interactive control to one field of one query.
192
+ *
193
+ * Always explicit: the field is never inferred from the control's own field, because "the control
194
+ * happens to name a field this query also has" is exactly the coupling that breaks silently when
195
+ * someone renames a dimension.
196
+ */
197
+ declare class Mapping {
198
+ readonly kind: "control";
199
+ readonly from: Control;
200
+ readonly to: Query;
201
+ readonly field: string;
202
+ readonly aggregation?: FilterAggregation;
203
+ constructor(from: Control, to: Query, field: string, aggregation?: FilterAggregation);
204
+ /**
205
+ * Includes the field, unlike Dashboard as Code's `${from}.${to}` — that form collides the moment
206
+ * one control maps onto one query on two fields.
207
+ */
208
+ get id(): string;
209
+ toJSON(): ControlMappingJson;
210
+ }
211
+ /**
212
+ * A directed edge saying `from` may cross-filter `to`: when the reader selects rows in `from`, the
213
+ * conditions derived from that selection apply to `to`.
214
+ *
215
+ * Carries no field. Which fields a selection conditions is decided at click time, from the rows the
216
+ * author hands over — the same asymmetry that makes `CrossFilterInteraction` the one Dashboard as
217
+ * Code interaction without a `field_path`. Two queries may cross-filter each other; only one
218
+ * selection is live at a time, so a bidirectional pair is not a loop. See docs/adr/0005.
219
+ */
220
+ declare class CrossFilter {
221
+ readonly kind: "crossFilter";
222
+ readonly from: Query;
223
+ readonly to: Query;
224
+ constructor(from: Query, to: Query);
225
+ /** No field to disambiguate, and one pair may only be declared once, so the pair is the id. */
226
+ get id(): string;
227
+ toJSON(): CrossFilterJson;
228
+ }
229
+ /** Either kind of edge. `app.mappings` returns this; narrow on `kind`. */
230
+ type Edge = Mapping | CrossFilter;
231
+
232
+ /**
233
+ * What an entity needs from the app that owns it. An interface, so `query.ts` and `controls.ts`
234
+ * never import `app.ts` at runtime.
235
+ */
236
+ interface AppContext {
237
+ readonly timezone?: string;
238
+ /** Server-side capabilities the host declared, so a declaration can refuse what would be dropped. */
239
+ readonly features?: SdkFeatures;
240
+ /** The live selection, if any. App-scoped: at most one query is the source at a time. */
241
+ readonly selection?: Selection;
242
+ datasetIndex(uname: string, entity: string): DatasetIndex;
243
+ /** Control edges only — cross-filter edges reach a query through the selection instead. */
244
+ mappingsTo(queryName: string): Mapping[];
245
+ /**
246
+ * Conditions the selection puts on this query, empty unless a cross-filter edge reaches it.
247
+ *
248
+ * `pending` is what the reader has picked and `applied` is what the query last ran with, matching
249
+ * `Control.condition` / `Control.appliedCondition`: signatures read pending, payloads read
250
+ * applied, and `execute()` commits between the two.
251
+ */
252
+ selectionConditionsFor(queryName: string, phase: 'pending' | 'applied'): readonly SelectionCondition[];
253
+ /** The expression form, set instead of the conditions when the collapse would have been lossy. */
254
+ selectionExpressionFor(queryName: string, phase: 'pending' | 'applied'): string | undefined;
255
+ /** Replaces the app's selection with these rows of this query. */
256
+ select(query: Query, rows: readonly Row[], fields?: readonly string[]): void;
257
+ /** Runs one more page for a query that already has a result. */
258
+ fetchPage(query: Query): Promise<void>;
259
+ /** Brings an entity's marked elements into view; false when none is on the page. */
260
+ locate(kind: LocateKind, name: string): boolean;
261
+ }
262
+
263
+ declare class Query extends Observable {
264
+ readonly kind: "query";
265
+ readonly name: string;
266
+ readonly declaration: QueryDeclaration;
267
+ readonly dataset: DatasetIndex;
268
+ private readonly app;
269
+ private _state;
270
+ private _result?;
271
+ private _error?;
272
+ private _page;
273
+ /**
274
+ * A sort applied to the result, independent of the query's own AQL — the same mechanism a click
275
+ * on a table's column header uses. Kept off the declaration so setting it never re-authors the
276
+ * query. See docs/adr/0001.
277
+ */
278
+ private _sort;
279
+ /** The input signature of the last successful run; undefined until one has happened. */
280
+ private lastRunSignature?;
281
+ /**
282
+ * Rows in the most recent page, not in the accumulated result. `fetchMore` appends, so comparing
283
+ * the total against the page size would report "more" forever once two pages are held.
284
+ */
285
+ private lastPageRows;
286
+ /** @internal Set by the executor so `abort()` can reach the in-flight request. */
287
+ controller?: AbortController;
288
+ constructor(name: string, app: AppContext & Observable, declaration: QueryDeclaration);
289
+ /**
290
+ * Bring the elements marked `data-anfra-query` with this query's name into view: scroll to the
291
+ * first and show them all for a moment. False, and nothing done, when no element on the page is
292
+ * marked with it yet; never throws, so an author's own button is safe.
293
+ */
294
+ locate(): boolean;
295
+ get state(): QueryState;
296
+ get result(): QueryResult | undefined;
297
+ get error(): DataAppError | undefined;
298
+ /** Rows per page, or undefined for a query that isn't paged and gets every row. */
299
+ get pageSize(): number | undefined;
300
+ get page(): number;
301
+ get sort(): readonly QuerySort[];
302
+ /** Replaces the sort applied to this query's result. Pass `[]` to clear it back to the AQL's own. */
303
+ setSort(sort: readonly QuerySort[]): void;
304
+ get hasMore(): boolean;
305
+ /**
306
+ * Everything that changes the rows: the declaration, the conditions reaching this query through
307
+ * mappings, the conditions reaching it from the selection, the sort override, the app's timezone,
308
+ * and the page. Compared against the last successful run to decide whether re-running would
309
+ * produce anything new.
310
+ */
311
+ signature(): string;
312
+ /**
313
+ * False before the first run: with nothing applied there is nothing to have changed. Distinct
314
+ * from `shouldRun`, which is true in that case precisely because there is no result yet.
315
+ */
316
+ get isDirty(): boolean;
317
+ /** @internal */
318
+ shouldRun(force?: boolean): boolean;
319
+ /** Stops the in-flight request for this query. The pending `execute()` resolves without it. */
320
+ abort(): void;
321
+ /** Fetches the next page and appends it. Rejects rather than swallowing, unlike `execute()`. */
322
+ fetchMore(): Promise<void>;
323
+ /**
324
+ * Cross-filters this query's targets by the rows the reader picked.
325
+ *
326
+ * Replaces whatever was selected, here or in another query: an app holds one selection at a time.
327
+ * Pass no rows to clear it. The SDK never sees the click, so the author calls this from their own
328
+ * chart's handler, passing the result rows they rendered.
329
+ *
330
+ * `fields` narrows which result columns take part, for a chart that renders fewer than the query
331
+ * returned. A measure or an adhoc column never takes part, whether or not it is named here.
332
+ */
333
+ select(rows: Row | readonly Row[], options?: {
334
+ fields?: readonly string[];
335
+ }): void;
336
+ /**
337
+ * The rows of this query's current result that the reader has selected, for redrawing its own
338
+ * highlight. Empty unless this query is the selection's source.
339
+ *
340
+ * Matched by value rather than by object identity. A source is never filtered by its own
341
+ * selection, but it does re-run when it stops being some *other* query's target — which is
342
+ * exactly what happens when the reader moves their selection from another panel to this one. Its
343
+ * rows come back as new objects, and identity would drop the highlight at that moment.
344
+ *
345
+ * `app.selection.rows` still holds what the author passed, verbatim.
346
+ */
347
+ get selectedRows(): readonly Row[];
348
+ /** @internal */
349
+ markExecuting(): void;
350
+ /** @internal */
351
+ markSuccess(result: QueryResult, signature: string, append: boolean): void;
352
+ /** @internal */
353
+ markError(error: DataAppError): void;
354
+ /** @internal Reverts an optimistic page bump when a `fetchMore` fails. */
355
+ rewindPage(): void;
356
+ /** @internal */
357
+ resetPage(): void;
358
+ toJSON(): QueryDeclaration;
359
+ }
360
+ /** What the installed plugins add to every query (`AnfraPlugins`): each member is there only where its plugin is. */
361
+ interface Query extends PluginMembers<'query'> {
362
+ }
363
+
364
+ type Factory<T> = (entity: T) => unknown;
365
+ interface EntityExtensions<Q, C> {
366
+ query: Map<string, Factory<Q>>;
367
+ control: Map<string, Factory<C>>;
368
+ }
369
+
370
+ declare class App extends Observable implements AppContext {
371
+ /** @internal What plugins add to each query and control. */
372
+ private readonly extensions?;
373
+ readonly title?: string;
374
+ private _timezone?;
375
+ private readonly datasets;
376
+ private readonly backend;
377
+ readonly features?: SdkFeatures;
378
+ private readonly _queries;
379
+ private readonly _controls;
380
+ private readonly _mappings;
381
+ private readonly _crossFilters;
382
+ private _selection?;
383
+ private _appliedSelection?;
384
+ /**
385
+ * Whether a run has ever committed the selection. Needed because `undefined` is a real applied
386
+ * value — "nothing selected" — unlike a control's condition, which is always present.
387
+ */
388
+ private selectionCommitted;
389
+ constructor(declaration: AppDeclaration, datasets: Record<string, DatasetIndex>, backend: Backend, features?: SdkFeatures,
390
+ /** @internal What plugins add to each query and control. */
391
+ extensions?: EntityExtensions<Query, Control> | undefined);
392
+ get queries(): Record<string, Query>;
393
+ get controls(): Record<string, Control>;
394
+ /** Every edge in the app's entity graph, of both kinds. Narrow on `kind`. */
395
+ get mappings(): readonly Edge[];
396
+ get crossFilters(): readonly CrossFilter[];
397
+ createQuery(name: string, declaration: QueryDeclaration): Query;
398
+ createFilter(name: string, declaration: FilterDeclaration & {
399
+ dataset?: string;
400
+ }): Filter;
401
+ createDateDrill(name: string, declaration?: DateDrillDeclaration): DateDrillControl;
402
+ /**
403
+ * Declares one edge. Always explicit — the field is never inferred from the control's own field,
404
+ * because "the control happens to name a field this query also has" is exactly the coupling that
405
+ * breaks silently when someone renames a dimension.
406
+ *
407
+ * There is no `unmap`: a mapping you do not want is one you do not declare.
408
+ */
409
+ mapControl(from: Control, to: Query, options: {
410
+ field: string;
411
+ aggregation?: FilterAggregation;
412
+ }): Mapping;
413
+ /**
414
+ * Declares that selecting rows in `from` may cross-filter `to`.
415
+ *
416
+ * No field: which fields a selection conditions is decided when the reader picks rows, not here.
417
+ * Explicit, like every other edge — there is no "cross-filter everything on this dataset",
418
+ * because an author who adds a sixth query should not silently acquire five new edges.
419
+ *
420
+ * Declaring both directions is normal and is not a cycle: one selection is live at a time and
421
+ * never cascades, so `a -> b` and `b -> a` simply means either chart may drive the other.
422
+ */
423
+ mapCrossFilter(from: Query, to: Query): CrossFilter;
424
+ /**
425
+ * What the reader has picked, if anything.
426
+ *
427
+ * Held here rather than on a query because it belongs to none of them: picking rows in a second
428
+ * query replaces it. Every control still owns its own condition — this is the one piece of
429
+ * reader state with no natural owner.
430
+ */
431
+ get selection(): Selection | undefined;
432
+ /** The selection the cross-filtered queries last ran with. */
433
+ get appliedSelection(): Selection | undefined;
434
+ clearSelection(): void;
435
+ /** Part of the declaration, not the environment. Changing it makes every query dirty. */
436
+ setTimezone(timezone: string | undefined): void;
437
+ get timezone(): string | undefined;
438
+ datasetIndex(uname: string, entity: string): DatasetIndex;
439
+ mappingsTo(queryName: string): Mapping[];
440
+ /** The expression form, set only when the structured conditions would have been lossy. */
441
+ selectionExpressionFor(queryName: string, phase: 'pending' | 'applied'): string | undefined;
442
+ private selectionFor;
443
+ selectionConditionsFor(queryName: string, phase: 'pending' | 'applied'): readonly SelectionCondition[];
444
+ /**
445
+ * The transformation each of this query's fields is currently drawn at, from the date drills
446
+ * mapped onto it.
447
+ *
448
+ * `appliedCondition`, not `condition`: a drill the reader has changed but not applied has not
449
+ * rebucketed anything yet, so the rows they are clicking still belong to the applied grain.
450
+ */
451
+ private drillTransformations;
452
+ select(query: Query, rows: readonly Row[], fields?: readonly string[]): void;
453
+ /** True when a control or the selection has changed since the queries reading it last ran. */
454
+ get hasChanges(): boolean;
455
+ /**
456
+ * False before the first execution, matching `Control.isDirty`: with nothing applied there is
457
+ * nothing to differ from, so a selection restored at startup is not an unapplied change.
458
+ */
459
+ private get isSelectionDirty();
460
+ /**
461
+ * Runs every query that would produce something new, and resolves with which succeeded and which
462
+ * failed. Never rejects: a failed query sets its own `state` and `error`, because one broken
463
+ * query must not blank the other four. See docs/adr/0002.
464
+ */
465
+ execute(options?: ExecuteOptions): Promise<ExecuteSummary>;
466
+ /** Re-runs everything and asks the server to skip its result cache. */
467
+ refresh(): Promise<ExecuteSummary>;
468
+ abort(): void;
469
+ /** @internal Backs `query.fetchMore()`. Rejects, so an explicit page request reports its failure. */
470
+ fetchPage(query: Query): Promise<void>;
471
+ /**
472
+ * @internal Backs the `export` plugin's `query.export()`. Built from the applied state, as
473
+ * `fetchPage` is, so the file holds what the reader is looking at, every row of it. `send` makes
474
+ * the export (the plugin's call); this touches nothing on the query.
475
+ */
476
+ exportQuery(query: Query, options: ExportOptions, send: (request: BackendExportRequest, signal: AbortSignal) => Promise<ExportResult>): Promise<ExportResult>;
477
+ /**
478
+ * The declaration and nothing else — no datasets, no backend, no reader state. This is the
479
+ * shape a persisted Data App record will take, which is why mapping edges are already generic.
480
+ */
481
+ toJSON(): AppJson;
482
+ /**
483
+ * Everything a host needs to render this app, as plain data.
484
+ *
485
+ * Separate from `toJSON()` rather than an option on it: `toJSON()` is the declaration and is the
486
+ * shape a persisted app takes, while this is a reading taken at a moment and already behind by
487
+ * the time anyone sees it. Written out field by field because the live objects cannot cross a
488
+ * port — getters are not cloned, and `Query.controller` holds an `AbortController` for exactly
489
+ * as long as someone is likely to be watching. See docs/adr/0007.
490
+ */
491
+ toInspectJSON(): InspectedApp;
492
+ /**
493
+ * @internal This app's index among the frame's apps, which is how a marked element names it
494
+ * (`data-anfra-query="1/revenue"`); 0 unless set by the instance that created it.
495
+ */
496
+ index: number;
497
+ /**
498
+ * Bring an entity's marked elements into view: scroll to the first, show the overlay on all for
499
+ * a moment. False, and nothing done, when the document has none marked with it (or there is no
500
+ * document at all). Used by `Query.locate()` and `Control.locate()`, and by the bootstrap for a
501
+ * host's locate-by-entity.
502
+ */
503
+ locate(kind: LocateKind, name: string): boolean;
504
+ private assertNameFree;
505
+ /**
506
+ * A field-backed filter usually lives in an app with one dataset, so requiring `dataset` on every
507
+ * filter would be noise. With several, it has to be said.
508
+ */
509
+ private soleDataset;
510
+ private assertAcyclic;
511
+ }
512
+
513
+ /** The plugins a host installed, as `Anfra.plugins`. */
514
+ declare class InstalledPlugins {
515
+ /** Each plugin's name and version, in the order the host installed them. */
516
+ readonly list: readonly Readonly<PluginInfo>[];
517
+ constructor(plugins: readonly PluginInfo[]);
518
+ /**
519
+ * Whether the host installed the plugin named `name`. To call a plugin's member, check the member
520
+ * itself (`if (Anfra.render)`, `query.export?.()`): TypeScript narrows that, not this.
521
+ */
522
+ has(name: PluginName): boolean;
523
+ /** The installed plugin's version, or undefined. */
524
+ version(name: PluginName): string | undefined;
525
+ }
526
+ /** The package's version: anfra's own, as each release publishes the SDK with it. */
527
+ declare const VERSION: string;
528
+ /**
529
+ * A provisioned SDK instance: the environment, plus the one factory an author needs.
530
+ *
531
+ * Authors never construct this. The provisioner builds it and exposes it to the sandbox
532
+ * as `Anfra`, so author and agent code contains no setup at all — which matters most for the
533
+ * agent, which cannot write boilerplate about a backend it has never seen. See docs/adr/0003.
534
+ */
535
+ declare class Sdk {
536
+ readonly version: string;
537
+ private readonly _apps;
538
+ /**
539
+ * Readable on purpose: an agent can check a field name against the real schema before writing
540
+ * it. This is the useful half of runtime introspection *for an author*, which is why there is
541
+ * still no `describe()` on this surface. Describing a running app is a separate thing, addressed
542
+ * to the host rather than the author — see `App.toInspectJSON` and docs/adr/0007.
543
+ */
544
+ readonly datasets: Readonly<Record<string, DatasetDescriptor>>;
545
+ /**
546
+ * Who the app is running as. Provisioned like `datasets` rather than fetched, so author code
547
+ * needs no await and no null check to greet someone or hide a control they cannot use.
548
+ */
549
+ readonly user: Readonly<User>;
550
+ private readonly indices;
551
+ private readonly backend;
552
+ /**
553
+ * The plugins the host installed. A plugin adds its API under its own name (`Anfra.lineage`,
554
+ * `query.export`), and a plugin that isn't installed adds nothing: check `Anfra.plugins.has(name)`
555
+ * before using an optional one.
556
+ */
557
+ readonly plugins: InstalledPlugins;
558
+ private readonly features;
559
+ /** @internal What plugins add to each query and control, by plugin name (the kernel's `provideOn*`). */
560
+ readonly extensions: EntityExtensions<Query, Control>;
561
+ constructor(environment: SdkEnvironment);
562
+ createApp(declaration?: AppDeclaration): App;
563
+ /**
564
+ * Every app this instance has built, for a host rendering an inspection panel.
565
+ *
566
+ * Not addressed to author code, which already holds whatever it created — this exists because the
567
+ * bootstrap does not, and cannot otherwise reach an app at all. Holding them means they outlive
568
+ * the author's own reference; the frame is discarded and rebuilt on every Run, which is what
569
+ * bounds it. See docs/adr/0007.
570
+ */
571
+ get apps(): readonly App[];
572
+ }
573
+ /** What the installed plugins add to `Anfra` (`AnfraPlugins`): each member is there only where its plugin is. */
574
+ interface Sdk extends PluginMembers<'anfra'> {
575
+ }
576
+ declare function createSdk(environment: SdkEnvironment): Sdk;
577
+
578
+ declare const OVERLAY_ID = "anfra-overlay";
579
+ /**
580
+ * What the label says, in parts the overlay sets apart: the kind, the id or name, the author's
581
+ * label, a note such as "1 of 3", and the element's size.
582
+ */
583
+ interface OverlayLabel {
584
+ kind: string;
585
+ name: string;
586
+ label?: string;
587
+ note?: string;
588
+ size?: string;
589
+ }
590
+ declare class Overlay {
591
+ private readonly doc;
592
+ private readonly root;
593
+ private shown;
594
+ private text;
595
+ private timer;
596
+ private readonly reposition;
597
+ constructor(doc: Document);
598
+ /** Show the overlay on these elements, labelled, until `hide()` or the next `show()`. */
599
+ show(elements: readonly Element[], text: OverlayLabel): void;
600
+ /** Show for a moment, then hide. */
601
+ flash(elements: readonly Element[], text: OverlayLabel, ms?: number): void;
602
+ hide(): void;
603
+ get visible(): boolean;
604
+ private clearTimer;
605
+ private draw;
606
+ }
607
+
608
+ /**
609
+ * The structure: a Data App's semantic parts, declared by the definition on its own elements with
610
+ * `data-anfra-*` attributes and read from the running page. Optional and partial: anything
611
+ * unmarked is simply not in it. Built only while a host inspects, and never thrown over: a problem
612
+ * in the markup is reported on the node it concerns.
613
+ */
614
+
615
+ declare const ATTR: {
616
+ readonly container: "data-anfra-container";
617
+ readonly block: "data-anfra-block";
618
+ readonly query: "data-anfra-query";
619
+ readonly control: "data-anfra-control";
620
+ readonly label: "data-anfra-label";
621
+ };
622
+ /** A `[app/]name` reference as a marker writes it. */
623
+ interface EntityRef {
624
+ app: number;
625
+ name: string;
626
+ }
627
+ /** Parse one token of a `data-anfra-query` or `data-anfra-control` attribute; undefined if malformed. */
628
+ declare function parseRef(token: string): EntityRef | undefined;
629
+ interface BuiltStructure extends InspectedStructure {
630
+ /** The marked element behind each node key, for highlighting and picking. */
631
+ elements: Map<string, Element>;
632
+ /** The node keys an element stands for: its own node, and one per entity it is marked with. */
633
+ keysOf: Map<Element, string[]>;
634
+ }
635
+ /**
636
+ * Read the structure off the document: one node per container or block, and one per entity a
637
+ * marked element names, placed under the nearest marked ancestor. Keys are index paths (`0.2.1`)
638
+ * so an unchanged tree keeps the same keys from one snapshot to the next.
639
+ */
640
+ declare function buildStructure(doc: Document, apps: readonly App[]): BuiltStructure;
641
+
642
+ /**
643
+ * The kernel, as a plugin's frame half sees it: the app model, the bridge under the plugin's name,
644
+ * a place in the plugin layer, and the ways to add API for the author. One per plugin, made by the
645
+ * bootstrap before the definition runs (docs/designs/sdk-plugins.md).
646
+ */
647
+
648
+ declare const KERNEL_ERRORS: {
649
+ readonly DataAppError: typeof DataAppError;
650
+ readonly ValidationError: typeof ValidationError;
651
+ readonly QueryError: typeof QueryError;
652
+ readonly PermissionError: typeof PermissionError;
653
+ readonly TransportError: typeof TransportError;
654
+ };
655
+ interface FrameKernel {
656
+ /** The plugin's name: what its calls, events and API are named under. */
657
+ readonly plugin: string;
658
+ readonly window: Window;
659
+ /** The SDK instance the definition gets as `Anfra`: its apps, datasets and user. */
660
+ readonly sdk: Sdk;
661
+ /** The SDK's error classes: reject with these, so an author can tell them apart. */
662
+ readonly errors: typeof KERNEL_ERRORS;
663
+ /** The overlay every part of the SDK shows nodes with. */
664
+ readonly overlay: Overlay;
665
+ /** The page's structure as it is now. */
666
+ structure: () => BuiltStructure;
667
+ /** Make a host half's call, by its full name (`core.submitQuery`). */
668
+ call: <T = unknown>(name: string, request?: unknown, signal?: AbortSignal) => Promise<T>;
669
+ /** Send the host one of this plugin's events, by its name under the plugin. */
670
+ emit: (name: string, payload?: unknown) => void;
671
+ /** Answer one of this plugin's calls made by the host, by its name under the plugin. */
672
+ handle: (name: string, handler: (request: any, signal: AbortSignal) => unknown) => void;
673
+ /** Listen to one of this plugin's events from the host, by its name under the plugin. */
674
+ on: (name: string, listener: (payload: any) => void) => void;
675
+ /** Each app the definition creates, and each already created. */
676
+ onApp: (listener: (app: App) => void) => void;
677
+ /** `Anfra.<plugin>`. */
678
+ provide: (api: unknown) => void;
679
+ /** `query.<plugin>` on every query, made once per query. */
680
+ provideOnQuery: (factory: (query: Query) => unknown) => void;
681
+ /** `control.<plugin>` on every control, made once per control. */
682
+ provideOnControl: (factory: (control: Control) => unknown) => void;
683
+ /** This plugin's shadow root in the plugin layer. */
684
+ layer: () => ShadowRoot;
685
+ /** The plugin's frame body, fetched and run on first use: what it exports. */
686
+ body: <T = unknown>() => Promise<T>;
687
+ }
688
+
689
+ /** A plugin's frame setup, as the host's frame script hands it over: its name and its function. */
690
+ type PluginSetup = readonly [name: string, setup: ((kernel: FrameKernel) => void) | undefined];
691
+ /** Provision the SDK in `win` from its host, run the plugins' setups, and install it. Returns once `Anfra` exists. */
692
+ declare function bootstrap(win: Window, setups?: readonly PluginSetup[]): void;
693
+
694
+ export { type AnfraPlugins as A, Control as C, DateDrillControl as D, type Edge as E, Filter as F, InstalledPlugins as I, Mapping as M, OVERLAY_ID as O, type PluginSetup as P, Query as Q, Sdk as S, VERSION as V, App as a, CrossFilter as b, type FrameKernel as c, type PluginApi as d, type PluginMembers as e, type PluginName as f, ATTR as g, bootstrap as h, buildStructure as i, createSdk as j, parseRef as p };