@holistics/anfra-sdk 0.10.2 → 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.
- package/README.md +78 -18
- package/dist/api.d.ts +1 -1
- package/dist/api.js +2 -1
- package/dist/app.d.ts +11 -551
- package/dist/app.js +30 -2194
- package/dist/bootstrap-B7r0ggJN.d.ts +694 -0
- package/dist/bridge-Byq62yS8.d.ts +72 -0
- package/dist/build.d.ts +20 -0
- package/dist/build.js +36 -0
- package/dist/chunk-52LXBYQM.js +0 -0
- package/dist/chunk-ADWBOQW2.js +106 -0
- package/dist/chunk-BL7SPVAS.js +2020 -0
- package/dist/chunk-ENWRS6AT.js +6 -0
- package/dist/{chunk-KBXITYQK.js → chunk-KCTLO3CO.js} +3 -4
- package/dist/chunk-PKBMQBKP.js +7 -0
- package/dist/chunk-TQ7S5DRE.js +24 -0
- package/dist/common.d.ts +2 -2
- package/dist/common.js +4 -2
- package/dist/host.d.ts +52 -63
- package/dist/host.js +229 -221
- package/dist/plugin-C5cihcQD.d.ts +131 -0
- package/dist/plugins.d.ts +52 -0
- package/dist/plugins.js +233 -0
- package/dist/testing.d.ts +47 -0
- package/dist/testing.js +104 -0
- package/dist/{types-DznT0m7F.d.ts → types-BTyDyld7.d.ts} +9 -24
- package/package.json +22 -2
- package/dist/bridge-DUKdREoK.d.ts +0 -133
- /package/dist/{chunk-H4XI4B7G.js → chunk-XIUFHRZE.js} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
__publicField
|
|
3
|
+
} from "./chunk-PKBMQBKP.js";
|
|
4
4
|
|
|
5
5
|
// src/common/errors.ts
|
|
6
6
|
var DataAppError = class extends Error {
|
|
@@ -33,7 +33,6 @@ var TransportError = class extends DataAppError {
|
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
export {
|
|
36
|
-
__publicField,
|
|
37
36
|
DataAppError,
|
|
38
37
|
ValidationError,
|
|
39
38
|
QueryError,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
__publicField
|
|
7
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/host/plugin.ts
|
|
2
|
+
var NAME = /^[a-z][a-z0-9-]*$/;
|
|
3
|
+
var RESERVED_NAMES = /* @__PURE__ */ new Set(["anfra", "plugins"]);
|
|
4
|
+
var MEMBER = /^[A-Za-z][A-Za-z0-9]*$/;
|
|
5
|
+
function checkPlugin(plugin) {
|
|
6
|
+
if (typeof plugin?.name !== "string" || !NAME.test(plugin.name)) {
|
|
7
|
+
throw new Error(`A plugin's name is lowercase letters, digits and dashes, starting with a letter: '${String(plugin?.name)}' is not.`);
|
|
8
|
+
}
|
|
9
|
+
if (RESERVED_NAMES.has(plugin.name)) throw new Error(`'${plugin.name}' is reserved for the SDK: name the plugin something else.`);
|
|
10
|
+
for (const [kind, names] of [["call", Object.keys(plugin.host?.calls ?? {})], ["event", Object.keys(plugin.host?.events ?? {})]]) {
|
|
11
|
+
for (const name of names) {
|
|
12
|
+
if (!MEMBER.test(name)) throw new Error(`Plugin '${plugin.name}': '${name}' is not ${kind === "call" ? "a call" : "an event"} name (letters and digits).`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function definePlugin(plugin) {
|
|
17
|
+
checkPlugin(plugin);
|
|
18
|
+
return plugin;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
checkPlugin,
|
|
23
|
+
definePlugin
|
|
24
|
+
};
|
package/dist/common.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { D as DataAppError, P as PermissionError, Q as QueryError, T as TransportError, V as ValidationError } from './errors-CKvqVaqU.js';
|
|
2
|
-
export { A as Aggregation, a as AppDeclaration, b as AppJson, c as ArrowType, B as Backend, d as BackendCondition, e as BackendDateDrill, f as BackendExportRequest, g as BackendFilter, h as BackendLineageRequest, i as BackendQueryRequest, j as BackendQueryResult, k as BackendSort, C as ColumnMeta, l as Condition, m as ConditionValue, n as ControlMappingJson, o as CrossFilterJson, D as DatasetDescriptor, p as DateDrillDeclaration, q as DateGrain, r as DateTransformation, E as EntityKind, s as EntityRef, t as EntityUsage, u as ExecuteOptions, v as ExecuteSummary, w as ExportFormat, x as ExportFormatOptions, y as ExportOptions, z as ExportResult, F as FILTER_AGGREGATIONS, G as FieldLineage, H as FieldSuggestionsRequest, I as FilterAggregation, J as FilterDeclaration, K as FilterValueType, L as InspectedApp, M as InspectedControl, N as InspectedError, O as InspectedQuery, P as InspectedSelection, Q as InspectedStructure, R as LineageCard, S as LineageDiagram, T as LineageNode, U as LineageOptions, V as LineageResult, W as LineageTarget, X as Listener, Y as LocateKind, Z as LocateTarget, _ as MappingJson, $ as Operator, a0 as QueryDebug, a1 as QueryDeclaration, a2 as QueryInput, a3 as QueryResult, a4 as QuerySort, a5 as QueryState, a6 as RenderFormat, a7 as RenderRequest, a8 as Rendering, a9 as Row, aa as SdkEnvironment, ab as SdkFeatures, ac as Selection, ad as SelectionCondition, ae as SemanticType, af as StructureKind, ag as StructureNode, ah as Unsubscribe, ai as User } from './types-
|
|
3
|
-
export { B as BridgeError, a as
|
|
2
|
+
export { A as Aggregation, a as AppDeclaration, b as AppJson, c as ArrowType, B as Backend, d as BackendCondition, e as BackendDateDrill, f as BackendExportRequest, g as BackendFilter, h as BackendLineageRequest, i as BackendQueryRequest, j as BackendQueryResult, k as BackendSort, C as ColumnMeta, l as Condition, m as ConditionValue, n as ControlMappingJson, o as CrossFilterJson, D as DatasetDescriptor, p as DateDrillDeclaration, q as DateGrain, r as DateTransformation, E as EntityKind, s as EntityRef, t as EntityUsage, u as ExecuteOptions, v as ExecuteSummary, w as ExportFormat, x as ExportFormatOptions, y as ExportOptions, z as ExportResult, F as FILTER_AGGREGATIONS, G as FieldLineage, H as FieldSuggestionsRequest, I as FilterAggregation, J as FilterDeclaration, K as FilterValueType, L as InspectedApp, M as InspectedControl, N as InspectedError, O as InspectedQuery, P as InspectedSelection, Q as InspectedStructure, R as LineageCard, S as LineageDiagram, T as LineageNode, U as LineageOptions, V as LineageResult, W as LineageTarget, X as Listener, Y as LocateKind, Z as LocateTarget, _ as MappingJson, $ as Operator, a0 as QueryDebug, a1 as QueryDeclaration, a2 as QueryInput, a3 as QueryResult, a4 as QuerySort, a5 as QueryState, a6 as RenderFormat, a7 as RenderRequest, a8 as Rendering, a9 as Row, aa as SdkEnvironment, ab as SdkFeatures, ac as Selection, ad as SelectionCondition, ae as SemanticType, af as StructureKind, ag as StructureNode, ah as Unsubscribe, ai as User } from './types-BTyDyld7.js';
|
|
3
|
+
export { B as BridgeError, a as BridgeMessage, F as FrameMessage, H as HostMessage, P as PROVISION_ELEMENT_ID, b as PluginInfo, c as Provision } from './bridge-Byq62yS8.js';
|
package/dist/common.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import "./chunk-52LXBYQM.js";
|
|
1
2
|
import {
|
|
2
3
|
FILTER_AGGREGATIONS
|
|
3
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-XIUFHRZE.js";
|
|
4
5
|
import {
|
|
5
6
|
PROVISION_ELEMENT_ID
|
|
6
7
|
} from "./chunk-33B2D4U5.js";
|
|
@@ -10,7 +11,8 @@ import {
|
|
|
10
11
|
QueryError,
|
|
11
12
|
TransportError,
|
|
12
13
|
ValidationError
|
|
13
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-KCTLO3CO.js";
|
|
15
|
+
import "./chunk-PKBMQBKP.js";
|
|
14
16
|
export {
|
|
15
17
|
DataAppError,
|
|
16
18
|
FILTER_AGGREGATIONS,
|
package/dist/host.d.ts
CHANGED
|
@@ -1,46 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { b as PluginInfo, c as Provision } from './bridge-Byq62yS8.js';
|
|
2
|
+
import { D as DatasetDescriptor, ai as User } from './types-BTyDyld7.js';
|
|
3
|
+
import { C as CallOptions, P as Plugin, M as Middleware } from './plugin-C5cihcQD.js';
|
|
4
|
+
export { a as CallContext, b as CallDefinition, c as CallHandler, d as Caller, E as EventCheck, F as FrameHalf, H as HandlerCallOptions, e as HandlerContext, f as HostHalf, g as MountContext, h as definePlugin } from './plugin-C5cihcQD.js';
|
|
3
5
|
|
|
4
|
-
interface
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
* and forget: the frame answers nothing, and does nothing for what is not on the page.
|
|
12
|
-
*/
|
|
13
|
-
locate: (target: LocateTarget) => void;
|
|
14
|
-
/** Start or stop pick mode in the frame: pointing outlines marked elements, a click reports one. */
|
|
15
|
-
setPicking: (on: boolean) => void;
|
|
16
|
-
/**
|
|
17
|
-
* Render the app, or one block or container, once its running queries settle, and save the file
|
|
18
|
-
* for the reader. Rejects with a `ValidationError` when the frame can't, or rendering is off.
|
|
19
|
-
*/
|
|
20
|
-
render: (request: RenderRequest) => Promise<Rendering>;
|
|
21
|
-
stop: () => void;
|
|
22
|
-
}
|
|
23
|
-
interface BridgeOptions {
|
|
24
|
-
/** Whether the frame may render: off unless true, and off, its asks are refused and `render` rejects. */
|
|
25
|
-
render?: boolean;
|
|
26
|
-
/** The renderer's code (`anfra-sdk:renderer`), sent to the frame on its first rendering. */
|
|
27
|
-
renderer?: string;
|
|
28
|
-
}
|
|
29
|
-
interface BridgeCallbacks {
|
|
30
|
-
/** The frame's inspection snapshot: its apps and its structure. */
|
|
31
|
-
onInspect?: (apps: InspectedApp[], structure: InspectedStructure) => void;
|
|
32
|
-
/** In pick mode, the reader chose a node (its key), or left the mode (null). */
|
|
33
|
-
onPick?: (node: string | null) => void;
|
|
6
|
+
interface HostOptions {
|
|
7
|
+
/** The plugins this page's Data Apps get. `core` is required: the app model runs its queries with it. */
|
|
8
|
+
plugins: readonly Plugin[];
|
|
9
|
+
/** Middleware around calls, beside what plugins bring. */
|
|
10
|
+
middleware?: readonly Middleware[];
|
|
11
|
+
/** The frame script; the one built into this package unless given (tests). */
|
|
12
|
+
frameScript?: string;
|
|
34
13
|
}
|
|
35
|
-
|
|
36
|
-
* The bridge, the host's side: answer a Data App frame's Backend calls with `backend`, abort one on
|
|
37
|
-
* the frame's cancel, and relay its inspection snapshots, until `stop`. Only messages from this
|
|
38
|
-
* frame are served (a sandboxed frame has an opaque origin, so its window is what identifies it),
|
|
39
|
-
* and only the Backend's own methods: nothing else of the API is reachable from a frame.
|
|
40
|
-
*/
|
|
41
|
-
declare function serveBridge(frame: HTMLIFrameElement, backend: Backend, callbacks?: BridgeCallbacks, options?: BridgeOptions): BridgeHandle;
|
|
42
|
-
|
|
43
|
-
interface MountOptions extends BridgeCallbacks {
|
|
14
|
+
interface MountOptions {
|
|
44
15
|
/** Where the frame goes: it is appended to this element. */
|
|
45
16
|
container: HTMLElement;
|
|
46
17
|
/** The Data App definition: its HTML, as its author wrote it. */
|
|
@@ -49,45 +20,63 @@ interface MountOptions extends BridgeCallbacks {
|
|
|
49
20
|
baseHref: string;
|
|
50
21
|
datasets: Record<string, DatasetDescriptor>;
|
|
51
22
|
user: User;
|
|
52
|
-
/** What answers the frame's queries: `coreApiBackend` from `@holistics/anfra-sdk/api`, on any host. */
|
|
53
|
-
backend: Backend;
|
|
54
|
-
/** The frame script; the one built into this package unless given (tests). */
|
|
55
|
-
frameScript?: string;
|
|
56
|
-
/**
|
|
57
|
-
* Whether the frame may render itself as a PNG or PDF (`Anfra.render()`, `render()` here). Off
|
|
58
|
-
* unless turned on: rendering has the host save a file the frame made, so a host opts in to it
|
|
59
|
-
* (docs/designs/data-apps.md, Renderings).
|
|
60
|
-
*/
|
|
61
|
-
render?: boolean;
|
|
62
|
-
/** The renderer's script; the one built into this package unless given (tests). */
|
|
63
|
-
renderer?: string;
|
|
64
23
|
title?: string;
|
|
65
24
|
}
|
|
66
|
-
interface MountedDataApp
|
|
25
|
+
interface MountedDataApp {
|
|
67
26
|
frame: HTMLIFrameElement;
|
|
27
|
+
/**
|
|
28
|
+
* Make a call about this frame: a host half's (through the pipeline), or, when no host half
|
|
29
|
+
* answers the name, a frame half's, in the frame.
|
|
30
|
+
*/
|
|
31
|
+
call: <T = unknown>(name: string, request?: unknown, options?: CallOptions) => Promise<T>;
|
|
32
|
+
/** Send the frame an event. */
|
|
33
|
+
emit: (name: string, payload?: unknown) => void;
|
|
34
|
+
/** Listen to the frame's events, by full name. Returns the function that stops listening. */
|
|
35
|
+
on: (name: string, listener: (payload: any) => void) => () => void;
|
|
68
36
|
/** Stop answering the frame, and remove it. */
|
|
69
37
|
unmount: () => void;
|
|
70
38
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
39
|
+
interface Host {
|
|
40
|
+
/** The installed plugins, in install order. */
|
|
41
|
+
readonly plugins: readonly PluginInfo[];
|
|
42
|
+
/** Make a call as the host page, about no frame. */
|
|
43
|
+
call: <T = unknown>(name: string, request?: unknown, options?: CallOptions) => Promise<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Mount a Data App: a sandboxed frame (scripts only, an opaque origin, so its own requests reach
|
|
46
|
+
* no API) whose document is the definition with the SDK and the plugins' frame halves provisioned
|
|
47
|
+
* ahead of it. The bridge is served before the document loads, so no call is missed.
|
|
48
|
+
*/
|
|
49
|
+
mount: (options: MountOptions) => MountedDataApp;
|
|
50
|
+
}
|
|
51
|
+
declare function createHost(options: HostOptions): Host;
|
|
77
52
|
|
|
78
53
|
interface ProvisionOptions {
|
|
79
54
|
/** Where the definition's relative URLs resolve: the directory it was read from. */
|
|
80
55
|
baseHref: string;
|
|
81
56
|
provision: Provision;
|
|
82
|
-
/** The frame script (`@holistics/anfra-sdk/app`'s
|
|
57
|
+
/** The frame script (`@holistics/anfra-sdk/app`'s kernel, as `__anfraKernel`), run before any of the definition's own. */
|
|
83
58
|
frameScript: string;
|
|
59
|
+
/** The installed plugins' frame setups (each assigning `__anfraPlugin`), run after the kernel, in this order. */
|
|
60
|
+
setups?: readonly {
|
|
61
|
+
name: string;
|
|
62
|
+
setup: string;
|
|
63
|
+
}[];
|
|
84
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* The one script a frame starts with: the kernel, then each plugin's setup, then the bootstrap,
|
|
67
|
+
* all inside one function so that neither the kernel nor a setup is left on the frame's window,
|
|
68
|
+
* where the definition would find it.
|
|
69
|
+
*/
|
|
70
|
+
declare function composeFrameScript(frameScript: string, setups?: readonly {
|
|
71
|
+
name: string;
|
|
72
|
+
setup: string;
|
|
73
|
+
}[]): string;
|
|
85
74
|
/**
|
|
86
75
|
* A Data App's frame document: its definition, with its base URL, the provision data and the frame
|
|
87
|
-
* script added at the top of its <head> (after <meta charset> when there is one, so the encoding is
|
|
76
|
+
* script (the kernel and the plugins' setups) added at the top of its <head> (after <meta charset> when there is one, so the encoding is
|
|
88
77
|
* still declared first), so `Anfra` exists before the definition's first script runs. The
|
|
89
78
|
* definition itself never mentions the SDK.
|
|
90
79
|
*/
|
|
91
80
|
declare function provisionDocument(definition: string, options: ProvisionOptions): string;
|
|
92
81
|
|
|
93
|
-
export {
|
|
82
|
+
export { CallOptions, type Host, type HostOptions, Middleware, type MountOptions, type MountedDataApp, Plugin, type ProvisionOptions, composeFrameScript, createHost, provisionDocument };
|