@holistics/anfra-sdk 0.13.5 → 0.14.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 +1 -1
- package/dist/app.d.ts +4 -3
- package/dist/app.js +17 -7
- package/dist/{bootstrap-BbsNvZ8s.d.ts → bootstrap-MhTSkiA1.d.ts} +96 -3
- package/dist/build.d.ts +2 -0
- package/dist/chunk-7IHICYVH.js +10 -0
- package/dist/chunk-CYZQ7ZTJ.js +237 -0
- package/dist/chunk-DITKCHFQ.js +166 -0
- package/dist/chunk-F6MRA7J4.js +65 -0
- package/dist/chunk-GBXK7F2V.js +431 -0
- package/dist/chunk-GOUDXWG4.js +750 -0
- package/dist/chunk-GV7SVWEK.js +84 -0
- package/dist/chunk-H52PO7MP.js +105 -0
- package/dist/chunk-HI3ZAXJK.js +8 -0
- package/dist/{chunk-KI5CAVAR.js → chunk-HZEECB6R.js} +477 -25
- package/dist/chunk-K633QHGO.js +51 -0
- package/dist/chunk-KFD6CHLI.js +38 -0
- package/dist/{chunk-OJ5WIKWE.js → chunk-NOFPRSSI.js} +1 -1
- package/dist/{chunk-ADWBOQW2.js → chunk-S6XLP6U4.js} +31 -1
- package/dist/{chunk-TQ7S5DRE.js → chunk-WI5VJ2Z6.js} +1 -1
- package/dist/common.d.ts +1 -1
- package/dist/common.js +14 -4
- package/dist/data-UCCW2VWH.js +233 -0
- package/dist/declaration-GVDOGQY6.js +218 -0
- package/dist/host.d.ts +42 -4
- package/dist/host.js +412 -9
- package/dist/menu-CdGVKc4_.d.ts +151 -0
- package/dist/overview-3DNXEQNY.js +358 -0
- package/dist/plugin-BmIDirTx.d.ts +303 -0
- package/dist/plugins.d.ts +6 -8
- package/dist/plugins.js +98 -69
- package/dist/queries-2OHKMTPC.js +661 -0
- package/dist/structure-WRDUXHD4.js +256 -0
- package/dist/tab-HMQOITVM.js +932 -0
- package/dist/testing.js +4 -4
- package/package.json +1 -1
- package/dist/bridge-WC7GliCH.d.ts +0 -73
- package/dist/chunk-33B2D4U5.js +0 -6
- package/dist/plugin-056-SKwd.d.ts +0 -132
- /package/dist/{chunk-52LXBYQM.js → chunk-UUKXJSE4.js} +0 -0
|
@@ -101,6 +101,36 @@ function createEndpoint(post, handlers) {
|
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
// src/common/shortcut.ts
|
|
105
|
+
var MODIFIERS = ["ctrl", "alt", "shift", "meta"];
|
|
106
|
+
function normalizeShortcut(shortcut) {
|
|
107
|
+
if (typeof shortcut !== "string") return void 0;
|
|
108
|
+
const parts = shortcut.split("+").map((part) => part.trim().toLowerCase()).filter(Boolean);
|
|
109
|
+
const key = parts.pop();
|
|
110
|
+
const isModifier = (part) => MODIFIERS.includes(part);
|
|
111
|
+
if (!key || isModifier(key) || !parts.every(isModifier)) return void 0;
|
|
112
|
+
return [...MODIFIERS.filter((modifier) => parts.includes(modifier)), key].join("+");
|
|
113
|
+
}
|
|
114
|
+
function isTyping(target) {
|
|
115
|
+
const element = target;
|
|
116
|
+
if (!element || typeof element.tagName !== "string") return false;
|
|
117
|
+
return element.isContentEditable === true || ["INPUT", "TEXTAREA", "SELECT"].includes(element.tagName.toUpperCase());
|
|
118
|
+
}
|
|
119
|
+
function eventShortcut(event) {
|
|
120
|
+
const code = typeof event.code === "string" ? event.code : "";
|
|
121
|
+
const key = /^Key[A-Z]$/.test(code) ? code.slice(3).toLowerCase() : /^Digit[0-9]$/.test(code) ? code.slice(5) : (event.key ?? "").toLowerCase();
|
|
122
|
+
return [
|
|
123
|
+
event.ctrlKey && "ctrl",
|
|
124
|
+
event.altKey && "alt",
|
|
125
|
+
event.shiftKey && "shift",
|
|
126
|
+
event.metaKey && "meta",
|
|
127
|
+
key
|
|
128
|
+
].filter(Boolean).join("+");
|
|
129
|
+
}
|
|
130
|
+
|
|
104
131
|
export {
|
|
105
|
-
createEndpoint
|
|
132
|
+
createEndpoint,
|
|
133
|
+
normalizeShortcut,
|
|
134
|
+
isTyping,
|
|
135
|
+
eventShortcut
|
|
106
136
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/host/plugin.ts
|
|
2
2
|
var NAME = /^[a-z][a-z0-9-]*$/;
|
|
3
|
-
var RESERVED_NAMES = /* @__PURE__ */ new Set(["anfra", "plugins"]);
|
|
3
|
+
var RESERVED_NAMES = /* @__PURE__ */ new Set(["anfra", "plugins", "theme"]);
|
|
4
4
|
var MEMBER = /^[A-Za-z][A-Za-z0-9]*$/;
|
|
5
5
|
function checkPlugin(plugin) {
|
|
6
6
|
if (typeof plugin?.name !== "string" || !NAME.test(plugin.name)) {
|
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
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 QueryTimings, a7 as RenderFormat, a8 as RenderRequest, a9 as Rendering, aa as Row, ab as SdkEnvironment, ac as SdkFeatures, ad as Selection, ae as SelectionCondition, af as SemanticType, ag as StructureKind, ah as StructureNode, ai as Unsubscribe, aj as User } from './types-CWNv6N0y.js';
|
|
3
|
-
export { B as BridgeError, a as BridgeMessage, F as FrameMessage, H as HostMessage, P as PROVISION_ELEMENT_ID,
|
|
3
|
+
export { B as BridgeError, a as BridgeMessage, D as DEFAULT_TOKENS, F as FrameMessage, H as HostMessage, M as MenuEntry, b as MenuTarget, c as MenuTargetKind, N as NodeTarget, P as PROVISION_ELEMENT_ID, d as PluginInfo, e as Provision, R as RowsTarget, T as THEME_TOKENS, f as TargetRect, g as Theme, h as ThemeInput, i as ThemeScheme, j as ThemeToken, k as ThemeTokens, l as checkTarget, r as resolveTheme } from './menu-CdGVKc4_.js';
|
package/dist/common.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import "./chunk-
|
|
1
|
+
import "./chunk-UUKXJSE4.js";
|
|
2
|
+
import {
|
|
3
|
+
checkTarget
|
|
4
|
+
} from "./chunk-KFD6CHLI.js";
|
|
2
5
|
import {
|
|
3
6
|
FILTER_AGGREGATIONS
|
|
4
7
|
} from "./chunk-XIUFHRZE.js";
|
|
5
8
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
DEFAULT_TOKENS,
|
|
10
|
+
PROVISION_ELEMENT_ID,
|
|
11
|
+
THEME_TOKENS,
|
|
12
|
+
resolveTheme
|
|
13
|
+
} from "./chunk-F6MRA7J4.js";
|
|
8
14
|
import {
|
|
9
15
|
DataAppError,
|
|
10
16
|
PermissionError,
|
|
@@ -14,11 +20,15 @@ import {
|
|
|
14
20
|
} from "./chunk-KCTLO3CO.js";
|
|
15
21
|
import "./chunk-PKBMQBKP.js";
|
|
16
22
|
export {
|
|
23
|
+
DEFAULT_TOKENS,
|
|
17
24
|
DataAppError,
|
|
18
25
|
FILTER_AGGREGATIONS,
|
|
19
26
|
PROVISION_ELEMENT_ID,
|
|
20
27
|
PermissionError,
|
|
21
28
|
QueryError,
|
|
29
|
+
THEME_TOKENS,
|
|
22
30
|
TransportError,
|
|
23
|
-
ValidationError
|
|
31
|
+
ValidationError,
|
|
32
|
+
checkTarget,
|
|
33
|
+
resolveTheme
|
|
24
34
|
};
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import {
|
|
2
|
+
columnKind
|
|
3
|
+
} from "./chunk-HI3ZAXJK.js";
|
|
4
|
+
import {
|
|
5
|
+
declaredFilters,
|
|
6
|
+
isActive,
|
|
7
|
+
queryInputs
|
|
8
|
+
} from "./chunk-DITKCHFQ.js";
|
|
9
|
+
import {
|
|
10
|
+
attributeRequests,
|
|
11
|
+
stateOf
|
|
12
|
+
} from "./chunk-CYZQ7ZTJ.js";
|
|
13
|
+
import {
|
|
14
|
+
collapsible,
|
|
15
|
+
columnIcon,
|
|
16
|
+
drawTab,
|
|
17
|
+
filterIndicator,
|
|
18
|
+
flash,
|
|
19
|
+
h,
|
|
20
|
+
icon,
|
|
21
|
+
lineageButton,
|
|
22
|
+
note,
|
|
23
|
+
queryTrust,
|
|
24
|
+
table,
|
|
25
|
+
trustIndicator
|
|
26
|
+
} from "./chunk-GOUDXWG4.js";
|
|
27
|
+
import "./chunk-K633QHGO.js";
|
|
28
|
+
import {
|
|
29
|
+
entityNodeKey,
|
|
30
|
+
formatAgo,
|
|
31
|
+
plural
|
|
32
|
+
} from "./chunk-H52PO7MP.js";
|
|
33
|
+
import "./chunk-PKBMQBKP.js";
|
|
34
|
+
|
|
35
|
+
// src/plugins/inspect/tabs/data.ts
|
|
36
|
+
var CSS = `
|
|
37
|
+
.search-bar { flex: none; padding: 8px 14px 4px; }
|
|
38
|
+
.app-title { margin: 12px 0 6px; font-size: 13px; font-weight: 500; }
|
|
39
|
+
.table-card > .collapsible-body { padding-top: 0; }
|
|
40
|
+
/* Each card is in its own element, so the kit's gap between adjacent tiles doesn't reach them. */
|
|
41
|
+
.table-item + .table-item { margin-top: 8px; }
|
|
42
|
+
.col { display: inline-flex; align-items: center; gap: 4px; cursor: help; }
|
|
43
|
+
.col .icon { color: var(--anfra-color-muted); }
|
|
44
|
+
.count { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; color: var(--anfra-color-muted); }
|
|
45
|
+
.count .row-action { margin-left: auto; }
|
|
46
|
+
.table-state { margin: 4px 0; font-size: 12px; color: var(--anfra-color-muted); }
|
|
47
|
+
`;
|
|
48
|
+
function csvField(value) {
|
|
49
|
+
if (value === null || value === void 0) return "";
|
|
50
|
+
let text = value instanceof Date ? value.toISOString() : typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
51
|
+
if (typeof value === "string" && /^[=+\-@\t\r]/.test(text)) text = `'${text}`;
|
|
52
|
+
return /[",\r\n]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
|
|
53
|
+
}
|
|
54
|
+
function toCsv(columns, rows, labels) {
|
|
55
|
+
const lines = [
|
|
56
|
+
columns.map((column) => csvField(labels[column] || column)),
|
|
57
|
+
...rows.map((row) => columns.map((_, index) => csvField(row[index])))
|
|
58
|
+
];
|
|
59
|
+
return `\uFEFF${lines.map((line) => line.join(",")).join("\r\n")}`;
|
|
60
|
+
}
|
|
61
|
+
function download(doc, filename, text) {
|
|
62
|
+
const win = doc.defaultView;
|
|
63
|
+
if (!win) return;
|
|
64
|
+
const url = win.URL.createObjectURL(new win.Blob([text], { type: "text/csv;charset=utf-8" }));
|
|
65
|
+
const a = doc.createElement("a");
|
|
66
|
+
a.href = url;
|
|
67
|
+
a.download = filename;
|
|
68
|
+
doc.body.append(a);
|
|
69
|
+
a.click();
|
|
70
|
+
a.remove();
|
|
71
|
+
win.setTimeout(() => win.URL.revokeObjectURL(url), 0);
|
|
72
|
+
}
|
|
73
|
+
function rowCount(shown, total) {
|
|
74
|
+
if (shown === 0) return "No rows.";
|
|
75
|
+
return total !== void 0 && total > shown ? `First ${shown} of ${total} rows` : plural(shown, "row");
|
|
76
|
+
}
|
|
77
|
+
function latestRows(requests) {
|
|
78
|
+
return requests?.find(({ entry, shared }) => !shared && entry.status === "ok" && entry.preview && entry.columns && !(entry.page && entry.page > 1))?.entry;
|
|
79
|
+
}
|
|
80
|
+
var handled = /* @__PURE__ */ new WeakMap();
|
|
81
|
+
function dataTab(root, context) {
|
|
82
|
+
const doc = context.document;
|
|
83
|
+
const { panel } = context;
|
|
84
|
+
const state = stateOf(context.mount);
|
|
85
|
+
const hasLineage = context.plugins.some((plugin) => plugin.name === "lineage");
|
|
86
|
+
let search = "";
|
|
87
|
+
const input = h(doc, "input", {
|
|
88
|
+
type: "search",
|
|
89
|
+
placeholder: "Search tables",
|
|
90
|
+
"aria-label": "Search tables",
|
|
91
|
+
"data-testid": "data-search",
|
|
92
|
+
oninput: () => {
|
|
93
|
+
search = input.value;
|
|
94
|
+
tab.redraw();
|
|
95
|
+
},
|
|
96
|
+
onkeydown: (event) => {
|
|
97
|
+
if (event.key !== "Escape" || !search) return;
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
setSearch("");
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
const head = h(doc, "div", { class: "search-bar" }, h(doc, "label", { class: "search" }, icon(doc, "search"), input));
|
|
103
|
+
const setSearch = (text) => {
|
|
104
|
+
search = text;
|
|
105
|
+
input.value = text;
|
|
106
|
+
tab.redraw();
|
|
107
|
+
};
|
|
108
|
+
function header(column, label, meta) {
|
|
109
|
+
if (!meta) return label;
|
|
110
|
+
const lines = [
|
|
111
|
+
meta.label || label,
|
|
112
|
+
columnKind(meta),
|
|
113
|
+
meta.isMeasure && `Type \xB7 ${meta.semantic_type}`,
|
|
114
|
+
meta.adhoc && "Ad hoc: the query's own expression, not the dataset's"
|
|
115
|
+
].filter(Boolean);
|
|
116
|
+
return h(doc, "span", { class: "col", tabindex: "0", "data-tip": lines.join("\n"), "data-testid": `column-${column}` }, columnIcon(doc, meta), label);
|
|
117
|
+
}
|
|
118
|
+
function body(name, query, latest) {
|
|
119
|
+
if (query.state === "error") return note(doc, "This table couldn't load.", { class: "table-state", "data-testid": "table-error" });
|
|
120
|
+
if (!latest?.preview || !latest.columns) {
|
|
121
|
+
return query.state === "success" ? note(doc, "This table's rows aren't available here.", { class: "table-state", "data-testid": "table-gone" }) : note(doc, "Loading this table\u2026", { class: "table-state", "data-testid": "table-loading" });
|
|
122
|
+
}
|
|
123
|
+
const { columns, preview } = latest;
|
|
124
|
+
const metas = new Map(query.columns.map((column) => [column.name, column]));
|
|
125
|
+
const labels = Object.fromEntries(query.columns.filter((column) => column.label).map((column) => [column.name, column.label]));
|
|
126
|
+
const complete = !query.hasMore && query.page <= 1 && (latest.numRows ?? 0) <= preview.length;
|
|
127
|
+
const canExport = context.mount.user.permissions.canExportData && complete;
|
|
128
|
+
const returned = new Date(new Date(latest.at).getTime() + (latest.durationMs ?? 0));
|
|
129
|
+
return h(
|
|
130
|
+
doc,
|
|
131
|
+
"div",
|
|
132
|
+
{},
|
|
133
|
+
preview.length > 0 && table(doc, columns.map((column) => header(column, labels[column] || column, metas.get(column))), preview, { "data-testid": "table-rows" }),
|
|
134
|
+
h(
|
|
135
|
+
doc,
|
|
136
|
+
"div",
|
|
137
|
+
{ class: "count", "data-testid": "table-count" },
|
|
138
|
+
rowCount(preview.length, latest.numRows),
|
|
139
|
+
h(doc, "span", { "aria-hidden": "true" }, "\xB7"),
|
|
140
|
+
h(doc, "span", { "data-tip": returned.toLocaleString() }, formatAgo(returned)),
|
|
141
|
+
canExport && h(doc, "button", {
|
|
142
|
+
type: "button",
|
|
143
|
+
class: "row-action",
|
|
144
|
+
"data-tip": "Download CSV",
|
|
145
|
+
"aria-label": "Download CSV",
|
|
146
|
+
"data-testid": "download-csv",
|
|
147
|
+
onclick: () => download(doc, `${name}.csv`, toCsv(columns, preview, labels))
|
|
148
|
+
}, icon(doc, "download"))
|
|
149
|
+
)
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
function card(app, index, name, query, latest) {
|
|
153
|
+
const key = `${index}/${name}`;
|
|
154
|
+
const declaration = app.declaration.queries[name];
|
|
155
|
+
const active = [...declaredFilters(declaration?.aql), ...queryInputs(app, name)].filter(isActive);
|
|
156
|
+
return collapsible(doc, `table:${key}`, [
|
|
157
|
+
h(doc, "span", { class: "name" }, name),
|
|
158
|
+
query.state === "error" && h(doc, "span", { class: "pill error" }, "couldn't load"),
|
|
159
|
+
h(doc, "span", { class: "spacer" }),
|
|
160
|
+
filterIndicator(doc, active),
|
|
161
|
+
trustIndicator(doc, queryTrust(declaration, query)),
|
|
162
|
+
hasLineage && lineageButton(doc, panel, entityNodeKey(panel.snapshot?.structure?.nodes ?? [], "query", index, name)),
|
|
163
|
+
h(doc, "button", {
|
|
164
|
+
type: "button",
|
|
165
|
+
class: "row-action",
|
|
166
|
+
"data-tip": "Query",
|
|
167
|
+
"aria-label": "Query",
|
|
168
|
+
"data-testid": "show-query",
|
|
169
|
+
onclick: (event) => {
|
|
170
|
+
event.preventDefault();
|
|
171
|
+
event.stopPropagation();
|
|
172
|
+
state.reveal(panel, { entity: "query", app: index, name });
|
|
173
|
+
}
|
|
174
|
+
}, icon(doc, "query"))
|
|
175
|
+
], () => body(name, query, latest), {
|
|
176
|
+
open: state.data.open.has(key),
|
|
177
|
+
class: "row table-card",
|
|
178
|
+
onToggle: (open) => {
|
|
179
|
+
if (open) state.data.open.add(key);
|
|
180
|
+
else state.data.open.delete(key);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
const tab = drawTab(root, context, () => {
|
|
185
|
+
const apps = panel.snapshot?.apps;
|
|
186
|
+
if (!apps) return note(doc, "Waiting for the Data App\u2026", { "data-testid": "inspect-waiting" });
|
|
187
|
+
if (apps.length === 0) return note(doc, "This Data App hasn't created an SDK app.");
|
|
188
|
+
if (apps.every((app) => Object.keys(app.queries).length === 0)) return note(doc, "This app has no tables yet.", { "data-testid": "data-none" });
|
|
189
|
+
const { byQuery } = attributeRequests(state.requests.entries(), apps);
|
|
190
|
+
const term = search.trim().toLowerCase();
|
|
191
|
+
return apps.map((app, index) => {
|
|
192
|
+
const tables = Object.entries(app.queries).filter(([name]) => !term || name.toLowerCase().includes(term));
|
|
193
|
+
return h(
|
|
194
|
+
doc,
|
|
195
|
+
"section",
|
|
196
|
+
{ "data-testid": `data-app-${index}` },
|
|
197
|
+
apps.length > 1 && h(doc, "p", { class: "app-title" }, `App ${index + 1} \xB7 ${app.title || "Untitled"}`),
|
|
198
|
+
tables.length === 0 && term && note(doc, `No tables match "${search.trim()}".`, { "data-testid": "data-no-match" }),
|
|
199
|
+
tables.map(([name, query]) => h(
|
|
200
|
+
doc,
|
|
201
|
+
"div",
|
|
202
|
+
{ class: "table-item", "data-testid": `table-${index}/${name}` },
|
|
203
|
+
card(app, index, name, query, latestRows(byQuery.get(`${index}/${name}`)))
|
|
204
|
+
))
|
|
205
|
+
);
|
|
206
|
+
});
|
|
207
|
+
}, { head, also: [state.subscribe] });
|
|
208
|
+
root.append(h(doc, "style", {}, CSS));
|
|
209
|
+
const reveal = () => {
|
|
210
|
+
const revealed = state.revealed;
|
|
211
|
+
if (!revealed || !("table" in revealed.target) || handled.get(state) === revealed.nonce) return;
|
|
212
|
+
if (!panel.snapshot) return;
|
|
213
|
+
handled.set(state, revealed.nonce);
|
|
214
|
+
if (search) setSearch("");
|
|
215
|
+
const key = `table:${revealed.target.app}/${revealed.target.table}`;
|
|
216
|
+
queueMicrotask(() => {
|
|
217
|
+
const found = [...root.querySelectorAll("details[data-key]")].find((element) => element.dataset.key === key);
|
|
218
|
+
if (found) flash(found);
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
reveal();
|
|
222
|
+
const stops = [panel.subscribe(reveal), state.subscribe(reveal)];
|
|
223
|
+
return () => {
|
|
224
|
+
stops.forEach((stop) => stop());
|
|
225
|
+
tab.dispose();
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
export {
|
|
229
|
+
csvField,
|
|
230
|
+
dataTab as default,
|
|
231
|
+
latestRows,
|
|
232
|
+
toCsv
|
|
233
|
+
};
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import {
|
|
2
|
+
stateOf
|
|
3
|
+
} from "./chunk-CYZQ7ZTJ.js";
|
|
4
|
+
import {
|
|
5
|
+
collapsible,
|
|
6
|
+
copyIcon,
|
|
7
|
+
drawTab,
|
|
8
|
+
flash,
|
|
9
|
+
h,
|
|
10
|
+
icon,
|
|
11
|
+
jsonView,
|
|
12
|
+
link,
|
|
13
|
+
note,
|
|
14
|
+
popover
|
|
15
|
+
} from "./chunk-GOUDXWG4.js";
|
|
16
|
+
import {
|
|
17
|
+
controlMappings,
|
|
18
|
+
crossFilters,
|
|
19
|
+
wiringChecks
|
|
20
|
+
} from "./chunk-K633QHGO.js";
|
|
21
|
+
import "./chunk-H52PO7MP.js";
|
|
22
|
+
import "./chunk-PKBMQBKP.js";
|
|
23
|
+
|
|
24
|
+
// src/plugins/inspect/tabs/declaration.ts
|
|
25
|
+
var CSS = `
|
|
26
|
+
.app-title { margin: 12px 0 0; font-weight: 500; }
|
|
27
|
+
.app-group + .app-group { margin-top: 20px; padding-top: 4px; border-top: 1px solid var(--anfra-color-border); }
|
|
28
|
+
.counts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
|
|
29
|
+
.hint { color: var(--anfra-color-muted); }
|
|
30
|
+
.checks { list-style: none; margin: 0; padding: 0; }
|
|
31
|
+
.check { display: flex; align-items: flex-start; gap: 8px; width: 100%; border: 0; border-radius: 4px; background: none; padding: 4px 6px; text-align: left; overflow-wrap: anywhere; }
|
|
32
|
+
.check:hover { background: var(--hover); }
|
|
33
|
+
.check.info { color: var(--anfra-color-muted); }
|
|
34
|
+
.check .mark { flex: none; width: 14px; text-align: center; font-weight: 600; }
|
|
35
|
+
/* An entity a check names: its own colour even in a muted row, so it reads as a name. */
|
|
36
|
+
.check .entity { padding: 0 4px; border-radius: 4px; background: var(--hover); color: var(--anfra-color-fg); font-size: 12px; font-weight: 500; }
|
|
37
|
+
.check.info .mark { color: var(--anfra-color-muted); }
|
|
38
|
+
.checks .flash { border-radius: 4px; }
|
|
39
|
+
.declaration-code .code-text { max-height: 384px; }
|
|
40
|
+
.wiring .collapsible-body { padding-left: 0; }
|
|
41
|
+
.wiring td.cell { text-align: center; }
|
|
42
|
+
.wiring .unmapped { color: var(--anfra-color-muted); opacity: 0.5; }
|
|
43
|
+
.wiring .mapped { cursor: default; }
|
|
44
|
+
.wiring .link { padding: 0 4px; font-size: 12px; }
|
|
45
|
+
`;
|
|
46
|
+
var MARKS = {
|
|
47
|
+
error: { mark: "\u2715", label: "error", tone: "tone-error" },
|
|
48
|
+
warn: { mark: "\u26A0", label: "warning", tone: "tone-warn" },
|
|
49
|
+
info: { mark: "\u2139", label: "info", tone: "" }
|
|
50
|
+
};
|
|
51
|
+
var handled = /* @__PURE__ */ new WeakMap();
|
|
52
|
+
function declarationTab(root, context) {
|
|
53
|
+
const doc = context.document;
|
|
54
|
+
const { panel } = context;
|
|
55
|
+
const state = stateOf(context.mount);
|
|
56
|
+
const hint = (text) => popover(doc, icon(doc, "info"), () => text, { class: "pop-trigger hint", "aria-label": "About this section" });
|
|
57
|
+
function counts(app) {
|
|
58
|
+
const { queries, filters, dateDrills } = app.declaration;
|
|
59
|
+
const items = [
|
|
60
|
+
[Object.keys(queries).length, "queries", "query"],
|
|
61
|
+
[Object.keys(filters).length + Object.keys(dateDrills).length, "controls", "control"],
|
|
62
|
+
[controlMappings(app).length, "mappings", "mapping"],
|
|
63
|
+
[crossFilters(app).length, "cross-filters", "cross-filter"]
|
|
64
|
+
];
|
|
65
|
+
return h(
|
|
66
|
+
doc,
|
|
67
|
+
"div",
|
|
68
|
+
{ class: "counts", "data-testid": "counts" },
|
|
69
|
+
items.map(([n, label, one]) => h(doc, "span", { class: "pill", "data-testid": `count-${label}` }, `${n} ${n === 1 ? one : label}`))
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
const entityNames = (app) => {
|
|
73
|
+
const { queries, filters, dateDrills } = app.declaration;
|
|
74
|
+
return [.../* @__PURE__ */ new Set([...Object.keys(queries), ...Object.keys(filters), ...Object.keys(dateDrills)])].sort((a, b) => b.length - a.length);
|
|
75
|
+
};
|
|
76
|
+
function named(message, names) {
|
|
77
|
+
if (!names.length) return message;
|
|
78
|
+
const escaped = names.map((name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
79
|
+
const pattern = new RegExp(`(?<![\\w.])(${escaped.join("|")})(?![\\w.])`, "g");
|
|
80
|
+
return message.split(pattern).map((part, i) => i % 2 ? h(doc, "code", { class: "entity" }, part) : part);
|
|
81
|
+
}
|
|
82
|
+
function checks(app, list, index) {
|
|
83
|
+
return [
|
|
84
|
+
h(doc, "h5", {}, "Checks", hint("Static checks on the declaration for mistakes the SDK reports late or never, such as cross-filters across datasets or controls mapped to no query. Click a row to jump to it.")),
|
|
85
|
+
list.length === 0 ? note(doc, "No issues found.", { "data-testid": "checks-none" }) : h(doc, "ul", { class: "checks", "data-testid": "checks" }, list.map((check, i) => {
|
|
86
|
+
const { mark, label, tone } = MARKS[check.level];
|
|
87
|
+
return h(
|
|
88
|
+
doc,
|
|
89
|
+
"li",
|
|
90
|
+
{ "data-check": `${index}:${i}` },
|
|
91
|
+
h(
|
|
92
|
+
doc,
|
|
93
|
+
"button",
|
|
94
|
+
{
|
|
95
|
+
type: "button",
|
|
96
|
+
class: `check ${check.level}`,
|
|
97
|
+
"data-tip": `Show ${check.about.name} in Queries`,
|
|
98
|
+
"data-key": `check:${index}:${i}`,
|
|
99
|
+
"data-testid": `check-${index}-${i}`,
|
|
100
|
+
onclick: () => state.reveal(panel, { entity: check.about.entity, app: index, name: check.about.name })
|
|
101
|
+
},
|
|
102
|
+
h(doc, "span", { class: `mark ${tone}`, role: "img", "aria-label": label }, mark),
|
|
103
|
+
h(doc, "span", {}, named(check.message, entityNames(app)))
|
|
104
|
+
)
|
|
105
|
+
);
|
|
106
|
+
}))
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
function declaration(app, index) {
|
|
110
|
+
const value = app.declaration;
|
|
111
|
+
const empty = !Object.keys(value.queries).length && !Object.keys(value.filters).length && !Object.keys(value.dateDrills).length;
|
|
112
|
+
return [
|
|
113
|
+
h(doc, "h5", {}, "Declaration", hint("What the Data App declared, as anfra reads it: its queries, controls and the mappings between them. A query's AQL shows across its lines, and copies as the JSON it is.")),
|
|
114
|
+
h(
|
|
115
|
+
doc,
|
|
116
|
+
"div",
|
|
117
|
+
{ class: "declaration-code", "data-testid": `declaration-${index}` },
|
|
118
|
+
empty ? h(doc, "div", { class: "code" }, h(doc, "p", { class: "code-empty" }, "Nothing declared.")) : h(
|
|
119
|
+
doc,
|
|
120
|
+
"div",
|
|
121
|
+
{ class: "code" },
|
|
122
|
+
h(doc, "div", { class: "code-corner" }, copyIcon(doc, "Copy the declaration", () => JSON.stringify(value, null, 2))),
|
|
123
|
+
jsonView(doc, value)
|
|
124
|
+
)
|
|
125
|
+
)
|
|
126
|
+
];
|
|
127
|
+
}
|
|
128
|
+
function matrix(app, index) {
|
|
129
|
+
const queries = Object.keys(app.declaration.queries);
|
|
130
|
+
if (queries.length === 0) return null;
|
|
131
|
+
const controls = [...Object.keys(app.declaration.filters), ...Object.keys(app.declaration.dateDrills)];
|
|
132
|
+
const mappings = controlMappings(app);
|
|
133
|
+
const crosses = crossFilters(app);
|
|
134
|
+
const entity = (kind, name) => link(doc, name, () => state.reveal(panel, { entity: kind, app: index, name }), {
|
|
135
|
+
"data-tip": `Show ${name} in Queries`,
|
|
136
|
+
"data-testid": `wiring-${kind}-${name}`
|
|
137
|
+
});
|
|
138
|
+
return collapsible(doc, `wiring:${index}`, ["Wiring", hint("Which controls and cross-filters feed which queries, as declared by the app.")], () => h(
|
|
139
|
+
doc,
|
|
140
|
+
"div",
|
|
141
|
+
{ class: "table-wrap", "data-testid": `wiring-${index}` },
|
|
142
|
+
h(
|
|
143
|
+
doc,
|
|
144
|
+
"table",
|
|
145
|
+
{},
|
|
146
|
+
h(doc, "thead", {}, h(
|
|
147
|
+
doc,
|
|
148
|
+
"tr",
|
|
149
|
+
{},
|
|
150
|
+
h(doc, "th", {}, "query"),
|
|
151
|
+
controls.map((name) => h(doc, "th", {}, entity("control", name))),
|
|
152
|
+
h(doc, "th", {}, "cross-filtered by")
|
|
153
|
+
)),
|
|
154
|
+
h(doc, "tbody", {}, queries.map((query) => {
|
|
155
|
+
const by = crosses.filter((c) => c.to.name === query).map((c) => c.from.name);
|
|
156
|
+
return h(
|
|
157
|
+
doc,
|
|
158
|
+
"tr",
|
|
159
|
+
{ "data-testid": `wiring-row-${query}` },
|
|
160
|
+
h(doc, "td", {}, entity("query", query)),
|
|
161
|
+
controls.map((control) => {
|
|
162
|
+
const m = mappings.find((x) => x.from.name === control && x.to.name === query);
|
|
163
|
+
return h(
|
|
164
|
+
doc,
|
|
165
|
+
"td",
|
|
166
|
+
{ class: "cell", "data-testid": `wiring-cell-${query}-${control}` },
|
|
167
|
+
m ? h(doc, "span", { class: "mapped", "data-tip": `${m.field}${m.aggregation ? ` (${m.aggregation})` : ""}` }, "\u25CF") : h(doc, "span", { class: "unmapped" }, "\xB7")
|
|
168
|
+
);
|
|
169
|
+
}),
|
|
170
|
+
h(doc, "td", { class: "muted", "data-testid": `wiring-by-${query}` }, by.length ? by.join(", ") : "\u2014")
|
|
171
|
+
);
|
|
172
|
+
}))
|
|
173
|
+
)
|
|
174
|
+
), { class: "section wiring" });
|
|
175
|
+
}
|
|
176
|
+
const tab = drawTab(root, context, () => {
|
|
177
|
+
const apps = panel.snapshot?.apps;
|
|
178
|
+
if (!apps) return note(doc, "Waiting for the Data App\u2026", { "data-testid": "inspect-waiting" });
|
|
179
|
+
if (apps.length === 0) return note(doc, "This Data App hasn't created an SDK app.", { "data-testid": "declaration-no-apps" });
|
|
180
|
+
return apps.map((app, index) => h(
|
|
181
|
+
doc,
|
|
182
|
+
"section",
|
|
183
|
+
{ class: "app-group", "data-testid": `app-${index}` },
|
|
184
|
+
apps.length > 1 && h(doc, "p", { class: "app-title" }, `App ${index + 1} \xB7 ${app.title || "Untitled"}`),
|
|
185
|
+
counts(app),
|
|
186
|
+
checks(app, wiringChecks(app), index),
|
|
187
|
+
declaration(app, index),
|
|
188
|
+
matrix(app, index)
|
|
189
|
+
));
|
|
190
|
+
}, { also: [state.subscribe] });
|
|
191
|
+
root.append(h(doc, "style", {}, CSS));
|
|
192
|
+
let seen = handled.get(state);
|
|
193
|
+
let missing;
|
|
194
|
+
const reveal = () => {
|
|
195
|
+
const revealed = state.revealed;
|
|
196
|
+
if (!revealed || seen === revealed.nonce || !("check" in revealed.target)) return;
|
|
197
|
+
const { app, check } = revealed.target;
|
|
198
|
+
const row = root.querySelector(`[data-check="${app}:${check}"]`);
|
|
199
|
+
if (!row) {
|
|
200
|
+
missing = revealed.nonce;
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
seen = revealed.nonce;
|
|
204
|
+
handled.set(state, seen);
|
|
205
|
+
flash(row);
|
|
206
|
+
};
|
|
207
|
+
reveal();
|
|
208
|
+
const stops = [state.subscribe(reveal), panel.subscribe(() => {
|
|
209
|
+
if (missing !== void 0 && missing === state.revealed?.nonce) reveal();
|
|
210
|
+
})];
|
|
211
|
+
return () => {
|
|
212
|
+
stops.forEach((stop) => stop());
|
|
213
|
+
tab.dispose();
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
export {
|
|
217
|
+
declarationTab as default
|
|
218
|
+
};
|
package/dist/host.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PluginInfo, Provision } from './app.js';
|
|
1
|
+
import { PluginInfo, Theme, ThemeInput, Provision } from './app.js';
|
|
2
2
|
import { DatasetDescriptor, User } from './app.js';
|
|
3
|
-
import { C as CallOptions, P as Plugin, M as Middleware } from './plugin-
|
|
4
|
-
export {
|
|
3
|
+
import { C as Command, T as Tab, a as CallOptions, P as Panel, b as CommandState, c as Plugin, M as Middleware, d as CommandContribution, e as TabContribution, f as Contribution } from './plugin-BmIDirTx.js';
|
|
4
|
+
export { g as CallContext, h as CallDefinition, i as CallHandler, j as Caller, k as CommandRun, l as CommandStateContext, E as EventCheck, F as FrameHalf, H as HandlerCallOptions, m as HandlerContext, n as HostHalf, o as MountContext, S as Snapshot, p as TabContext, q as definePlugin } from './plugin-BmIDirTx.js';
|
|
5
5
|
|
|
6
6
|
interface HostOptions {
|
|
7
7
|
/** The plugins this page's Data Apps get. `core` is required: the app model runs its queries with it. */
|
|
@@ -10,12 +10,26 @@ interface HostOptions {
|
|
|
10
10
|
middleware?: readonly Middleware[];
|
|
11
11
|
/** The frame script; the one built into this package unless given (tests). */
|
|
12
12
|
frameScript?: string;
|
|
13
|
+
/** The kernel's UI body, for the frame's menu, modal and popover; the one built in unless given (tests). */
|
|
14
|
+
uiBody?: string;
|
|
13
15
|
/**
|
|
14
16
|
* Origins a Data App may load scripts, styles, fonts and images from, and fetch them from, beside
|
|
15
17
|
* the policy's own CDNs: each `https://<host>[:<port>]`, nothing after it. Never a way to the
|
|
16
18
|
* network at large (docs/designs/security.md).
|
|
17
19
|
*/
|
|
18
20
|
allowOrigins?: readonly string[];
|
|
21
|
+
/** The host's own commands, beside the plugins': ids as given, unique among all. */
|
|
22
|
+
commands?: readonly CommandContribution[];
|
|
23
|
+
/** The host's own tabs, beside the plugins': ids as given, unique among all. */
|
|
24
|
+
tabs?: readonly TabContribution[];
|
|
25
|
+
/**
|
|
26
|
+
* Which contributions, the plugins' and the host's own, the host shows: what it returns false for
|
|
27
|
+
* is left out everywhere (`host.commands`, `host.tabs`, the panel). A plugin's calls stay, so a host
|
|
28
|
+
* can draw its own UI on them instead.
|
|
29
|
+
*/
|
|
30
|
+
contributions?: (contribution: Contribution) => boolean;
|
|
31
|
+
/** The theme plugin UI follows: tabs, and frame halves in the plugin layer. Light defaults unless given. */
|
|
32
|
+
theme?: ThemeInput;
|
|
19
33
|
}
|
|
20
34
|
interface MountOptions {
|
|
21
35
|
/** Where the frame goes: it is appended to this element. */
|
|
@@ -37,12 +51,36 @@ interface MountedDataApp {
|
|
|
37
51
|
emit: (name: string, payload?: unknown) => void;
|
|
38
52
|
/** Listen to the frame's events, by full name. Returns the function that stops listening. */
|
|
39
53
|
on: (name: string, listener: (payload: any) => void) => () => void;
|
|
54
|
+
/** This Data App's panel: the host's devtools over it, with the tabs plugins add. */
|
|
55
|
+
panel: Panel;
|
|
56
|
+
/** How a command, by full id, shows for this Data App now. */
|
|
57
|
+
commandState: (id: string) => CommandState;
|
|
58
|
+
/**
|
|
59
|
+
* Run a command, by full id, for this Data App. Refused while its state says it is disabled. A
|
|
60
|
+
* command for the page's content (`target`) runs from the frame's menu, with its target.
|
|
61
|
+
*/
|
|
62
|
+
run: (id: string) => Promise<unknown>;
|
|
63
|
+
/** Each time commands' state may have changed: a plugin said so, or the panel changed. */
|
|
64
|
+
onCommandsChange: (listener: () => void) => () => void;
|
|
65
|
+
/**
|
|
66
|
+
* Run the command whose shortcut a key event on the host's own page makes, if any: whether one
|
|
67
|
+
* did. Keys pressed while focus is in the frame are forwarded and run without this.
|
|
68
|
+
*/
|
|
69
|
+
handleKeydown: (event: KeyboardEvent) => boolean;
|
|
40
70
|
/** Stop answering the frame, and remove it. */
|
|
41
71
|
unmount: () => void;
|
|
42
72
|
}
|
|
43
73
|
interface Host {
|
|
44
74
|
/** The installed plugins, in install order. */
|
|
45
75
|
readonly plugins: readonly PluginInfo[];
|
|
76
|
+
/** Every command to show: the plugins', then the host's own, as the filter kept them. */
|
|
77
|
+
readonly commands: readonly Command[];
|
|
78
|
+
/** Every tab for a mount's panel, in order, as the filter kept them. */
|
|
79
|
+
readonly tabs: readonly Tab[];
|
|
80
|
+
/** The theme plugin UI follows now, every token resolved. */
|
|
81
|
+
readonly theme: Theme;
|
|
82
|
+
/** Change the theme: every tab and every mounted frame's plugin layer follow it. */
|
|
83
|
+
setTheme: (theme: ThemeInput) => void;
|
|
46
84
|
/** Make a call as the host page, about no frame. */
|
|
47
85
|
call: <T = unknown>(name: string, request?: unknown, options?: CallOptions) => Promise<T>;
|
|
48
86
|
/**
|
|
@@ -109,5 +147,5 @@ declare function checkOrigin(origin: unknown): string;
|
|
|
109
147
|
*/
|
|
110
148
|
declare function contentPolicy(allowOrigins?: readonly string[]): string;
|
|
111
149
|
|
|
112
|
-
export { CallOptions, Middleware, Plugin, SCRIPT_ORIGINS, checkOrigin, composeFrameScript, contentPolicy, createHost, provisionDocument };
|
|
150
|
+
export { CallOptions, Command, CommandContribution, CommandState, Contribution, Middleware, Panel, Plugin, SCRIPT_ORIGINS, Tab, TabContribution, checkOrigin, composeFrameScript, contentPolicy, createHost, provisionDocument };
|
|
113
151
|
export type { Host, HostOptions, MountOptions, MountedDataApp, ProvisionOptions };
|