@holistics/anfra-sdk 0.13.4 → 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/api.d.ts +1 -1
- package/dist/app.d.ts +5 -4
- package/dist/app.js +17 -7
- package/dist/{bootstrap-DctKHBAj.d.ts → bootstrap-MhTSkiA1.d.ts} +97 -4
- 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-ZHIDMLJH.js → chunk-HZEECB6R.js} +477 -25
- package/dist/chunk-K633QHGO.js +51 -0
- package/dist/chunk-KFD6CHLI.js +38 -0
- package/dist/{chunk-2Q4HPPUK.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 +2 -2
- 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/dist/{types-B9DqPgWS.d.ts → types-CWNv6N0y.d.ts} +10 -0
- package/package.json +1 -1
- package/dist/bridge-_Ez5VZV9.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
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isChanged,
|
|
3
|
+
queryCounts
|
|
4
|
+
} from "./chunk-GV7SVWEK.js";
|
|
5
|
+
import {
|
|
6
|
+
columnKind
|
|
7
|
+
} from "./chunk-HI3ZAXJK.js";
|
|
8
|
+
import {
|
|
9
|
+
controlTargets,
|
|
10
|
+
crossFilterTargets,
|
|
11
|
+
declaredFilters,
|
|
12
|
+
isActive,
|
|
13
|
+
queryInputs
|
|
14
|
+
} from "./chunk-DITKCHFQ.js";
|
|
15
|
+
import {
|
|
16
|
+
attributeRequests,
|
|
17
|
+
stateOf
|
|
18
|
+
} from "./chunk-CYZQ7ZTJ.js";
|
|
19
|
+
import {
|
|
20
|
+
codeBlock,
|
|
21
|
+
collapsible,
|
|
22
|
+
columnIcon,
|
|
23
|
+
copyIcon,
|
|
24
|
+
drawTab,
|
|
25
|
+
fields,
|
|
26
|
+
filterIndicator,
|
|
27
|
+
flash,
|
|
28
|
+
h,
|
|
29
|
+
icon,
|
|
30
|
+
lineageButton,
|
|
31
|
+
link,
|
|
32
|
+
note,
|
|
33
|
+
queryTrust,
|
|
34
|
+
stateDot,
|
|
35
|
+
table,
|
|
36
|
+
trustIndicator
|
|
37
|
+
} from "./chunk-GOUDXWG4.js";
|
|
38
|
+
import "./chunk-K633QHGO.js";
|
|
39
|
+
import {
|
|
40
|
+
blockNodeKey,
|
|
41
|
+
dedent,
|
|
42
|
+
entityAttribute,
|
|
43
|
+
entityKey,
|
|
44
|
+
entityNodeKey,
|
|
45
|
+
formatAgo,
|
|
46
|
+
formatCondition,
|
|
47
|
+
formatTime,
|
|
48
|
+
plural,
|
|
49
|
+
usageOf
|
|
50
|
+
} from "./chunk-H52PO7MP.js";
|
|
51
|
+
import "./chunk-PKBMQBKP.js";
|
|
52
|
+
|
|
53
|
+
// src/plugins/inspect/tabs/queries.ts
|
|
54
|
+
var FIRST = 5;
|
|
55
|
+
var FILTERS = ["all", "errors", "dirty"];
|
|
56
|
+
var SOURCE_ICONS = { control: "control", crossFilter: "filter", declared: "code" };
|
|
57
|
+
var handled = /* @__PURE__ */ new WeakMap();
|
|
58
|
+
var matches = (search, ...texts) => !search || texts.some((text) => text?.toLowerCase().includes(search));
|
|
59
|
+
function showQuery(view, app, name, query) {
|
|
60
|
+
if (view.filter === "errors" && query.state !== "error") return false;
|
|
61
|
+
if (view.filter === "dirty" && !query.isDirty) return false;
|
|
62
|
+
return matches(view.search.trim().toLowerCase(), name, app.declaration.queries[name]?.dataset);
|
|
63
|
+
}
|
|
64
|
+
function showControl(view, app, name, control) {
|
|
65
|
+
if (view.filter === "errors") return false;
|
|
66
|
+
if (view.filter === "dirty" && !control.isDirty) return false;
|
|
67
|
+
const declaration = app.declaration.filters[name] ?? app.declaration.dateDrills[name];
|
|
68
|
+
const field = declaration && "field" in declaration ? declaration.field : void 0;
|
|
69
|
+
return matches(view.search.trim().toLowerCase(), name, declaration?.label, field);
|
|
70
|
+
}
|
|
71
|
+
var errorText = (error) => `${error.name}${error.status !== void 0 ? ` (${error.status})` : ""}: ${error.message}`;
|
|
72
|
+
var queriesText = (n) => n === 1 ? "1 query" : `${n} queries`;
|
|
73
|
+
function signatureSource(signature) {
|
|
74
|
+
const source = { label: "Signature", code: signature, empty: "No signature." };
|
|
75
|
+
if (!signature) return source;
|
|
76
|
+
try {
|
|
77
|
+
const value = JSON.parse(signature);
|
|
78
|
+
return { ...source, code: JSON.stringify(value, null, 2), json: value };
|
|
79
|
+
} catch {
|
|
80
|
+
return source;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
var CALL_LABELS = {
|
|
84
|
+
"core.submitQuery": "Query",
|
|
85
|
+
"export.query": "Export",
|
|
86
|
+
"core.fieldSuggestions": "Suggestions",
|
|
87
|
+
"lineage.trace": "Lineage",
|
|
88
|
+
"render.save": "Picture saved"
|
|
89
|
+
};
|
|
90
|
+
var labelOf = (entry) => CALL_LABELS[entry.call] ?? entry.call;
|
|
91
|
+
var titleOf = (entry) => entry.call === "core.fieldSuggestions" && entry.field ? entry.field : entry.dataset || labelOf(entry);
|
|
92
|
+
function summaryOf(entry) {
|
|
93
|
+
const ended = entry.status !== "ok" && entry.status !== "pending" ? entry.status : void 0;
|
|
94
|
+
if (entry.call === "core.fieldSuggestions") {
|
|
95
|
+
return `suggestions for ${entry.field}${entry.q ? ` "${entry.q}"` : ""}${entry.numRows === void 0 ? "" : ` \xB7 ${entry.numRows}`}`;
|
|
96
|
+
}
|
|
97
|
+
if (entry.call === "export.query") {
|
|
98
|
+
return [`export${entry.format ? ` ${entry.format}` : ""}`, entry.status === "ok" ? plural(entry.numRows ?? 0, "row") : ended].filter(Boolean).join(" \xB7 ");
|
|
99
|
+
}
|
|
100
|
+
if (entry.call !== "core.submitQuery") {
|
|
101
|
+
return [entry.targets?.join(", ") ?? entry.filename ?? (entry.caller === "frame" ? void 0 : entry.caller), ended].filter(Boolean).join(" \xB7 ");
|
|
102
|
+
}
|
|
103
|
+
return [
|
|
104
|
+
entry.fromCache === void 0 ? void 0 : entry.fromCache ? "cache" : "database",
|
|
105
|
+
entry.page && entry.page > 1 ? `page ${entry.page}` : void 0,
|
|
106
|
+
entry.status === "ok" ? plural(entry.numRows ?? 0, "row") : ended
|
|
107
|
+
].filter(Boolean).join(" \xB7 ");
|
|
108
|
+
}
|
|
109
|
+
function inputOf(entry) {
|
|
110
|
+
const { input, page, pageSize, timezone, bustCache, dataset, aql, field, q, format, formatOptions, filename, targets, request } = entry;
|
|
111
|
+
const shown = entry.call === "core.submitQuery" ? { dataset, page, pageSize, timezone, bustCache, ...input } : entry.call === "export.query" ? { dataset, timezone, format, formatOptions, filename, ...input } : entry.call === "core.fieldSuggestions" ? { dataset, field, q } : entry.call === "lineage.trace" ? { targets } : entry.call === "render.save" ? { filename } : typeof request === "object" && request !== null && !Array.isArray(request) ? request : { request };
|
|
112
|
+
const kept = Object.entries(shown).filter(([, value]) => value !== void 0 && !(Array.isArray(value) && value.length === 0));
|
|
113
|
+
return kept.length ? JSON.stringify(Object.fromEntries(kept), null, 2) : aql;
|
|
114
|
+
}
|
|
115
|
+
function rowCount(shown, total) {
|
|
116
|
+
if (shown === 0) return "No rows.";
|
|
117
|
+
return total !== void 0 && total > shown ? `First ${shown} of ${total} rows` : plural(shown, "row");
|
|
118
|
+
}
|
|
119
|
+
function filterSource(input) {
|
|
120
|
+
if (input.kind === "declared") return "Declared in this query's AQL filters block";
|
|
121
|
+
if (input.kind === "control") return `Applied from the control "${input.source}"`;
|
|
122
|
+
return input.self ? "Cross-filter from selecting rows in this query's own result" : `Cross-filter from selecting rows in "${input.source}"`;
|
|
123
|
+
}
|
|
124
|
+
var fieldOf = (column) => column.modelId ? `${column.modelId}.${column.fieldName}` : column.fieldName;
|
|
125
|
+
function queriesTab(root, context) {
|
|
126
|
+
const doc = context.document;
|
|
127
|
+
const { panel } = context;
|
|
128
|
+
const state = stateOf(context.mount);
|
|
129
|
+
const view = state.queries;
|
|
130
|
+
const canViewSql = context.mount.user.permissions.canViewGeneratedSql;
|
|
131
|
+
const hasLineage = context.plugins.some((plugin) => plugin.name === "lineage");
|
|
132
|
+
const inner = /* @__PURE__ */ new Map();
|
|
133
|
+
const codeTabs = /* @__PURE__ */ new Map();
|
|
134
|
+
const allFilters = /* @__PURE__ */ new Set();
|
|
135
|
+
const allRequests = /* @__PURE__ */ new Set();
|
|
136
|
+
const toggle = (set, key) => {
|
|
137
|
+
if (set.has(key)) set.delete(key);
|
|
138
|
+
else set.add(key);
|
|
139
|
+
tab.redraw();
|
|
140
|
+
};
|
|
141
|
+
const iconButton = (name, label, onclick, attributes = {}) => h(doc, "button", {
|
|
142
|
+
type: "button",
|
|
143
|
+
class: "row-action",
|
|
144
|
+
"data-tip": label,
|
|
145
|
+
"aria-label": label,
|
|
146
|
+
...attributes,
|
|
147
|
+
onclick: (event) => {
|
|
148
|
+
event.stopPropagation();
|
|
149
|
+
onclick();
|
|
150
|
+
}
|
|
151
|
+
}, icon(doc, name));
|
|
152
|
+
function section(id, app, title, count, shown, empty, body) {
|
|
153
|
+
const closedId = app === void 0 ? id : `${app}:${id}`;
|
|
154
|
+
const details = collapsible(
|
|
155
|
+
doc,
|
|
156
|
+
app === void 0 ? `section:${id}` : `section:${id}:${app}`,
|
|
157
|
+
[title, h(doc, "span", { class: "count" }, shown === void 0 ? String(count) : `${shown} of ${count}`)],
|
|
158
|
+
() => (shown ?? count) === 0 ? note(doc, empty) : body(),
|
|
159
|
+
{ open: !view.closed.has(closedId), onToggle: (open) => open ? view.closed.delete(closedId) : view.closed.add(closedId), class: "section" }
|
|
160
|
+
);
|
|
161
|
+
details.dataset.testid = app === void 0 ? `section-${id}` : `section-${id}-${app}`;
|
|
162
|
+
return details;
|
|
163
|
+
}
|
|
164
|
+
function entityRow(key, summary, body) {
|
|
165
|
+
const row = collapsible(doc, key, summary, body, {
|
|
166
|
+
open: view.open.has(key),
|
|
167
|
+
onToggle: (open) => open ? view.open.add(key) : view.open.delete(key),
|
|
168
|
+
class: "row entity"
|
|
169
|
+
});
|
|
170
|
+
row.dataset.testid = key.replace(":", "-");
|
|
171
|
+
return row;
|
|
172
|
+
}
|
|
173
|
+
function sub(key, title, body, open = true) {
|
|
174
|
+
const details = collapsible(doc, key, title, body, { open: inner.get(key) ?? open, onToggle: (o) => inner.set(key, o), class: "sub" });
|
|
175
|
+
details.dataset.testid = key.slice(key.lastIndexOf(":") + 1);
|
|
176
|
+
return details;
|
|
177
|
+
}
|
|
178
|
+
function drawn(structure, kind, app, name) {
|
|
179
|
+
const usage = usageOf(structure, kind, app, name);
|
|
180
|
+
if (!usage) return h(doc, "span", { class: "muted" }, "Not on the page yet");
|
|
181
|
+
const entity = entityKey(kind, app, name);
|
|
182
|
+
return collapsible(doc, `${entity}:places`, [
|
|
183
|
+
`In ${plural(usage.markers, "place")}${usage.blocks.length ? "" : ", outside any block"}`,
|
|
184
|
+
copyIcon(doc, "Copy the handle", () => entityAttribute(kind, app, name))
|
|
185
|
+
], () => h(
|
|
186
|
+
doc,
|
|
187
|
+
"ul",
|
|
188
|
+
{ class: "places" },
|
|
189
|
+
usage.blocks.length === 0 && h(
|
|
190
|
+
doc,
|
|
191
|
+
"li",
|
|
192
|
+
{},
|
|
193
|
+
h(doc, "span", { class: "muted" }, "Outside any block"),
|
|
194
|
+
iconButton("locate", "Highlight on the page", () => panel.locate({ app, kind, name }), { "data-testid": "locate-entity" })
|
|
195
|
+
),
|
|
196
|
+
usage.blocks.map((block) => {
|
|
197
|
+
const node = blockNodeKey(structure, block, kind, app, name);
|
|
198
|
+
return h(
|
|
199
|
+
doc,
|
|
200
|
+
"li",
|
|
201
|
+
{ onmouseenter: () => node && panel.highlight(node), onmouseleave: () => panel.highlight(null) },
|
|
202
|
+
h(doc, "span", {}, block),
|
|
203
|
+
node && [
|
|
204
|
+
iconButton("locate", "Highlight on the page", () => panel.locate({ node }), { "data-testid": "locate-block" }),
|
|
205
|
+
iconButton("tree", "Show in Structure", () => state.reveal(panel, { node }), { "data-testid": "show-in-structure" })
|
|
206
|
+
]
|
|
207
|
+
);
|
|
208
|
+
})
|
|
209
|
+
), { class: "inline" });
|
|
210
|
+
}
|
|
211
|
+
function mapsTo(key, app, targets, empty) {
|
|
212
|
+
if (targets.length === 0) return empty;
|
|
213
|
+
return collapsible(doc, key, queriesText(targets.length), () => h(doc, "ul", { class: "places" }, targets.map((target) => h(
|
|
214
|
+
doc,
|
|
215
|
+
"li",
|
|
216
|
+
{},
|
|
217
|
+
h(
|
|
218
|
+
doc,
|
|
219
|
+
"span",
|
|
220
|
+
{},
|
|
221
|
+
target.query,
|
|
222
|
+
target.field && h(doc, "span", { class: "muted" }, ` on ${target.field}`),
|
|
223
|
+
target.self && h(doc, "span", { class: "muted" }, " (itself)")
|
|
224
|
+
),
|
|
225
|
+
iconButton("query", "Show query", () => state.reveal(panel, { entity: "query", app, name: target.query }), { "data-testid": "show-query" })
|
|
226
|
+
))), { class: "inline" });
|
|
227
|
+
}
|
|
228
|
+
function requestList(scope, items, card) {
|
|
229
|
+
const all = allRequests.has(scope);
|
|
230
|
+
return [
|
|
231
|
+
h(doc, "div", { class: card ? "request-cards" : "requests" }, (all ? items : items.slice(0, FIRST)).map((item) => requestRow(scope, item, card))),
|
|
232
|
+
items.length > FIRST && link(doc, all ? "Show fewer" : `Show all ${items.length}`, () => toggle(allRequests, scope), { "data-testid": "requests-more" })
|
|
233
|
+
];
|
|
234
|
+
}
|
|
235
|
+
function requestRow(scope, { entry, shared }, card) {
|
|
236
|
+
const dot = h(doc, "span", { class: `dot ${entry.status}`, role: "img", "aria-label": `Status: ${entry.status}`, "data-tip": entry.status });
|
|
237
|
+
const summary = card ? h(
|
|
238
|
+
doc,
|
|
239
|
+
"span",
|
|
240
|
+
{ class: "entry" },
|
|
241
|
+
h(
|
|
242
|
+
doc,
|
|
243
|
+
"span",
|
|
244
|
+
{ class: "line" },
|
|
245
|
+
h(doc, "span", { class: "name" }, titleOf(entry)),
|
|
246
|
+
h(doc, "span", { class: "condition" }, summaryOf(entry)),
|
|
247
|
+
h(doc, "span", { class: "spacer" }),
|
|
248
|
+
dot
|
|
249
|
+
),
|
|
250
|
+
entry.error && h(doc, "span", { class: "error-text", role: "alert" }, entry.error)
|
|
251
|
+
) : h(
|
|
252
|
+
doc,
|
|
253
|
+
"span",
|
|
254
|
+
{ class: "line" },
|
|
255
|
+
dot,
|
|
256
|
+
h(doc, "span", { class: "time" }, formatTime(entry.at)),
|
|
257
|
+
h(doc, "span", { class: "condition" }, summaryOf(entry)),
|
|
258
|
+
shared && h(doc, "span", { class: "pill", "data-tip": "Another query declares the same dataset and AQL" }, "shared"),
|
|
259
|
+
h(doc, "span", { class: "spacer" }),
|
|
260
|
+
h(doc, "span", { class: "rows" }, entry.durationMs === void 0 ? "\u2026" : `${entry.durationMs} ms`)
|
|
261
|
+
);
|
|
262
|
+
const details = collapsible(doc, `${scope}:request:${entry.id}`, summary, () => [
|
|
263
|
+
card ? fields(doc, [
|
|
264
|
+
["Type", labelOf(entry)],
|
|
265
|
+
["Call", entry.call],
|
|
266
|
+
!!entry.dataset && ["Dataset", entry.dataset],
|
|
267
|
+
["Caller", entry.caller],
|
|
268
|
+
!!entry.trace && ["Middleware", entry.trace.join(" \u2192 ")],
|
|
269
|
+
["Sent at", formatTime(entry.at)],
|
|
270
|
+
["Duration", entry.durationMs === void 0 ? "Still running" : `${entry.durationMs} ms`]
|
|
271
|
+
]) : entry.error && h(doc, "p", { class: "error-text" }, entry.error),
|
|
272
|
+
entry.preview && entry.columns && [
|
|
273
|
+
h(doc, "p", { class: "preview-count" }, rowCount(entry.preview.length, entry.numRows)),
|
|
274
|
+
entry.preview.length > 0 && table(doc, entry.columns, entry.preview, { "data-testid": "request-preview" })
|
|
275
|
+
],
|
|
276
|
+
codeBlock(doc, { input: { label: "Input", code: inputOf(entry), lang: "js", empty: "No input." } }, "input")
|
|
277
|
+
], { class: card ? "row entity" : "row request" });
|
|
278
|
+
details.dataset.testid = `request-${entry.id}`;
|
|
279
|
+
return details;
|
|
280
|
+
}
|
|
281
|
+
function columnList(key, title, columns) {
|
|
282
|
+
if (columns.length === 0) return null;
|
|
283
|
+
return sub(`${key}:${title.toLowerCase()}`, [title, h(doc, "span", { class: "count" }, `\xB7 ${columns.length}`)], () => h(
|
|
284
|
+
doc,
|
|
285
|
+
"div",
|
|
286
|
+
{ class: "list" },
|
|
287
|
+
columns.map((column) => {
|
|
288
|
+
const unlabelled = !column.label || column.label === column.name;
|
|
289
|
+
return collapsible(doc, `${key}:column:${column.name}`, [
|
|
290
|
+
h(doc, "span", { class: "type", "aria-hidden": "true" }, columnIcon(doc, column)),
|
|
291
|
+
h(doc, "span", { class: "name", "data-tip": columnKind(column) }, column.name),
|
|
292
|
+
column.adhoc && h(doc, "span", { class: "pill warn" }, "ad hoc"),
|
|
293
|
+
h(doc, "span", { class: "spacer" }),
|
|
294
|
+
unlabelled ? h(doc, "span", { class: "pill warn" }, "no label") : h(doc, "span", { class: "label" }, column.label)
|
|
295
|
+
], () => fields(doc, [
|
|
296
|
+
["Label", column.label || h(doc, "span", { class: "muted" }, "None")],
|
|
297
|
+
["Type", columnKind(column)],
|
|
298
|
+
["Field", h(doc, "code", { class: "wrap" }, fieldOf(column))],
|
|
299
|
+
column.adhoc && ["Ad hoc", "The query's own AQL expression, not a field the dataset defines"],
|
|
300
|
+
["Database type", column.db_type]
|
|
301
|
+
]), { class: "item" });
|
|
302
|
+
})
|
|
303
|
+
));
|
|
304
|
+
}
|
|
305
|
+
function filterList(key, app, filters, active) {
|
|
306
|
+
if (filters.length === 0) return null;
|
|
307
|
+
const all = allFilters.has(key);
|
|
308
|
+
const shown = all ? filters : active;
|
|
309
|
+
const choose = (wanted) => (event) => {
|
|
310
|
+
event.preventDefault();
|
|
311
|
+
event.stopPropagation();
|
|
312
|
+
if (all !== wanted) toggle(allFilters, key);
|
|
313
|
+
};
|
|
314
|
+
return sub(
|
|
315
|
+
`${key}:filters`,
|
|
316
|
+
[
|
|
317
|
+
"Filters",
|
|
318
|
+
h(doc, "span", { class: "count" }, `\xB7 ${shown.length}`),
|
|
319
|
+
h(doc, "span", { class: "spacer" }),
|
|
320
|
+
h(
|
|
321
|
+
doc,
|
|
322
|
+
"span",
|
|
323
|
+
{ class: "segments small", role: "group", "aria-label": "Which filters" },
|
|
324
|
+
h(doc, "button", { type: "button", "aria-pressed": String(!all), "data-testid": "filters-active", onclick: choose(false) }, `Active (${active.length})`),
|
|
325
|
+
h(doc, "button", { type: "button", "aria-pressed": String(all), "data-testid": "filters-all", onclick: choose(true) }, `All (${filters.length})`)
|
|
326
|
+
)
|
|
327
|
+
],
|
|
328
|
+
() => shown.length === 0 ? h(doc, "p", { class: "muted" }, "No active filters.") : h(doc, "ul", { class: "list filters", "data-testid": "filter-list" }, shown.map((input2) => h(
|
|
329
|
+
doc,
|
|
330
|
+
"li",
|
|
331
|
+
{ "data-tip": filterSource(input2) },
|
|
332
|
+
h(doc, "span", { class: "type", "aria-hidden": "true" }, icon(doc, SOURCE_ICONS[input2.kind])),
|
|
333
|
+
h(doc, "span", { class: "field" }, input2.field),
|
|
334
|
+
h(
|
|
335
|
+
doc,
|
|
336
|
+
"span",
|
|
337
|
+
{ class: `value${isActive(input2) ? "" : " muted"}` },
|
|
338
|
+
input2.value,
|
|
339
|
+
input2.pending && h(doc, "span", { class: "pending" }, ` \xB7 pending: ${input2.pending}`)
|
|
340
|
+
),
|
|
341
|
+
h(
|
|
342
|
+
doc,
|
|
343
|
+
"span",
|
|
344
|
+
{ class: "source" },
|
|
345
|
+
input2.kind === "declared" ? h(doc, "span", { class: "muted" }, "query") : input2.self ? h(doc, "span", { class: "muted" }, "itself") : link(doc, input2.source, () => state.reveal(panel, { entity: input2.kind === "control" ? "control" : "query", app, name: input2.source }), { "data-testid": "filter-source" })
|
|
346
|
+
)
|
|
347
|
+
)))
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
function queryRow(app, index, name, query, requests, structure) {
|
|
351
|
+
const key = entityKey("query", index, name);
|
|
352
|
+
const declaration = app.declaration.queries[name];
|
|
353
|
+
const marker = structure && entityNodeKey(structure.nodes, "query", index, name);
|
|
354
|
+
const filters = [...declaredFilters(declaration?.aql), ...queryInputs(app, name)];
|
|
355
|
+
const active = filters.filter(isActive);
|
|
356
|
+
const summary = h(
|
|
357
|
+
doc,
|
|
358
|
+
"span",
|
|
359
|
+
{ class: "entry" },
|
|
360
|
+
h(
|
|
361
|
+
doc,
|
|
362
|
+
"span",
|
|
363
|
+
{ class: "line" },
|
|
364
|
+
h(doc, "span", { class: "name" }, name),
|
|
365
|
+
h(
|
|
366
|
+
doc,
|
|
367
|
+
"span",
|
|
368
|
+
{ class: "rows", "data-tip": query.state === "success" ? plural(query.rowCount, "row") : "No rows yet" },
|
|
369
|
+
query.state === "success" ? query.rowCount.toLocaleString() : "\u2014"
|
|
370
|
+
),
|
|
371
|
+
query.isDirty ? h(doc, "span", { class: "pill warn" }, "dirty") : query.debug?.fromCache && h(doc, "span", { class: "pill" }, "cache"),
|
|
372
|
+
h(doc, "span", { class: "spacer" }),
|
|
373
|
+
filterIndicator(doc, active),
|
|
374
|
+
hasLineage && lineageButton(doc, panel, marker),
|
|
375
|
+
trustIndicator(doc, queryTrust(declaration, query)),
|
|
376
|
+
stateDot(doc, query.state)
|
|
377
|
+
),
|
|
378
|
+
// An error shows open or not: it is what a failing app is inspected for.
|
|
379
|
+
query.error && h(doc, "span", { class: "error-text", role: "alert", "data-testid": "query-error" }, errorText(query.error))
|
|
380
|
+
);
|
|
381
|
+
return entityRow(key, summary, () => {
|
|
382
|
+
const latest = requests.find(({ entry, shared }) => !shared && entry.call === "core.submitQuery" && entry.status !== "pending")?.entry;
|
|
383
|
+
const notRun = query.state === "success" || query.state === "error" ? "Not returned." : "Not run yet.";
|
|
384
|
+
const lastRun = [
|
|
385
|
+
query.debug && (query.debug.fromCache ? "cache" : "database"),
|
|
386
|
+
query.debug?.executedAt && formatAgo(query.debug.executedAt),
|
|
387
|
+
latest?.durationMs !== void 0 && `${latest.durationMs} ms`
|
|
388
|
+
].filter(Boolean).join(" \xB7 ");
|
|
389
|
+
return [
|
|
390
|
+
sub(`${key}:general`, "General", () => [
|
|
391
|
+
fields(doc, [
|
|
392
|
+
["Dataset", declaration?.dataset || h(doc, "span", { class: "muted" }, "none declared")],
|
|
393
|
+
!!lastRun && ["Last run", lastRun],
|
|
394
|
+
["On the page", drawn(structure, "query", index, name)],
|
|
395
|
+
["Cross-filters", mapsTo(`${key}:cross`, index, crossFilterTargets(app, name), h(doc, "span", { class: "muted" }, "No query"))],
|
|
396
|
+
query.selectedRowCount > 0 && ["Selected", plural(query.selectedRowCount, "row")],
|
|
397
|
+
(query.hasMore || query.page > 1) && ["Page", `${query.page}${query.hasMore ? ", more available" : ""}`]
|
|
398
|
+
]),
|
|
399
|
+
h(
|
|
400
|
+
doc,
|
|
401
|
+
"div",
|
|
402
|
+
{ class: "detail-actions" },
|
|
403
|
+
link(doc, [icon(doc, "table"), "Show data"], () => state.reveal(panel, { table: name, app: index }), { "data-testid": "show-data" })
|
|
404
|
+
)
|
|
405
|
+
]),
|
|
406
|
+
query.columns.length === 0 ? sub(`${key}:definition`, "Definition", () => h(doc, "p", { class: "muted" }, notRun === "Not run yet." ? "Known once it runs." : "No fields.")) : [
|
|
407
|
+
columnList(key, "Metrics", query.columns.filter((column) => column.isMeasure)),
|
|
408
|
+
columnList(key, "Dimensions", query.columns.filter((column) => !column.isMeasure))
|
|
409
|
+
],
|
|
410
|
+
filterList(key, index, filters, active),
|
|
411
|
+
sub(`${key}:code`, "Query", () => codeBlock(doc, {
|
|
412
|
+
declared: { label: "Declared AQL", code: declaration?.aql ? dedent(declaration.aql) : void 0, lang: "aql", empty: "Not declared." },
|
|
413
|
+
aql: { label: "Executed AQL", code: query.debug?.executedAql, lang: "aql", empty: notRun },
|
|
414
|
+
sql: { label: "Executed SQL", code: query.debug?.executedSql, lang: "sql", empty: canViewSql ? notRun : "Needs canViewGeneratedSql." },
|
|
415
|
+
signature: signatureSource(query.signature)
|
|
416
|
+
}, codeTabs.get(key) ?? "aql", (t) => codeTabs.set(key, t)), false),
|
|
417
|
+
requests.length > 0 && sub(
|
|
418
|
+
`${key}:requests`,
|
|
419
|
+
["Requests", h(doc, "span", { class: "count" }, `\xB7 ${requests.length}`)],
|
|
420
|
+
() => requestList(key, requests, false),
|
|
421
|
+
false
|
|
422
|
+
)
|
|
423
|
+
];
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
function controlRow(app, index, name, control, structure) {
|
|
427
|
+
const key = entityKey("control", index, name);
|
|
428
|
+
const declaration = app.declaration.filters[name] ?? app.declaration.dateDrills[name];
|
|
429
|
+
const filter = declaration && "field" in declaration ? declaration : void 0;
|
|
430
|
+
const targets = controlTargets(app, name);
|
|
431
|
+
const fixed = filter?.options;
|
|
432
|
+
const options = fixed ?? control.options;
|
|
433
|
+
const fallback = declaration?.default;
|
|
434
|
+
const summary = h(
|
|
435
|
+
doc,
|
|
436
|
+
"span",
|
|
437
|
+
{ class: "line" },
|
|
438
|
+
h(doc, "span", { class: "name" }, name),
|
|
439
|
+
h(doc, "span", { class: "condition" }, control.condition.values?.length ? formatCondition(control.condition) : ""),
|
|
440
|
+
control.isDirty && h(doc, "span", { class: "pill warn" }, "unapplied"),
|
|
441
|
+
h(doc, "span", { class: "spacer" }),
|
|
442
|
+
isChanged(app, name, control) && h(doc, "span", { class: "changed", role: "img", "aria-label": "Changed from the default", "data-tip": "Changed from the default value" }, "M"),
|
|
443
|
+
h(doc, "span", {
|
|
444
|
+
class: "indicator targets",
|
|
445
|
+
"data-tip": targets.length ? `Applies to ${queriesText(targets.length)}
|
|
446
|
+
${targets.map((t) => `${t.query} on ${t.field}`).join("\n")}` : "Applies to no query"
|
|
447
|
+
}, String(targets.length), icon(doc, "query"))
|
|
448
|
+
);
|
|
449
|
+
return entityRow(key, summary, () => fields(doc, [
|
|
450
|
+
["Kind", [
|
|
451
|
+
control.kind === "dateDrill" ? "Date drill" : "Filter",
|
|
452
|
+
filter?.field && h(doc, "span", { class: "muted" }, ` on ${filter.field}`),
|
|
453
|
+
filter?.type && h(doc, "span", { class: "muted" }, ` \xB7 ${filter.type}`)
|
|
454
|
+
]],
|
|
455
|
+
!!declaration?.label && ["Label", declaration.label],
|
|
456
|
+
["Set to", formatCondition(control.condition)],
|
|
457
|
+
["Applied", formatCondition(control.appliedCondition)],
|
|
458
|
+
!!fallback && ["Default", typeof fallback === "string" ? fallback : formatCondition(fallback)],
|
|
459
|
+
options ? ["Options", collapsible(doc, `${key}:options`, `${options.length} ${fixed ? "fixed" : "loaded"}`, () => {
|
|
460
|
+
const selected = control.condition.values?.map(String) ?? [];
|
|
461
|
+
return h(doc, "ul", { class: "chips" }, options.map((option) => h(doc, "li", { class: selected.includes(String(option)) ? "selected" : void 0 }, String(option))));
|
|
462
|
+
}, { class: "inline" })] : control.kind === "filter" && ["Options", h(doc, "span", { class: "muted" }, "Not loaded")],
|
|
463
|
+
["Maps to", mapsTo(`${key}:maps`, index, targets, h(doc, "span", { class: "tone-warn" }, "No query, so it has no effect"))],
|
|
464
|
+
["On the page", drawn(structure, "control", index, name)]
|
|
465
|
+
]));
|
|
466
|
+
}
|
|
467
|
+
function selectionCard(label, selection) {
|
|
468
|
+
return h(
|
|
469
|
+
doc,
|
|
470
|
+
"div",
|
|
471
|
+
{ class: "card", "data-testid": `selection-${label.toLowerCase()}` },
|
|
472
|
+
h(doc, "header", {}, h(doc, "strong", {}, label), selection.lossy && h(doc, "span", { class: "pill warn" }, "lossy")),
|
|
473
|
+
selection.lossy && h(
|
|
474
|
+
doc,
|
|
475
|
+
"p",
|
|
476
|
+
{ class: "tone-warn lossy" },
|
|
477
|
+
"Some selected values can't be expressed as a filter, so the queries it filters see less than was selected."
|
|
478
|
+
),
|
|
479
|
+
fields(doc, [
|
|
480
|
+
["From", selection.source],
|
|
481
|
+
["Rows", String(selection.rowCount)],
|
|
482
|
+
!!selection.expression && ["Expression", h(doc, "code", { class: "wrap" }, selection.expression)],
|
|
483
|
+
...selection.conditions.map((condition) => [condition.field, formatCondition(condition)])
|
|
484
|
+
])
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
function appSection(app, index, several, byQuery, structure) {
|
|
488
|
+
const search = view.search.trim();
|
|
489
|
+
const filtering = search !== "" || view.filter !== "all";
|
|
490
|
+
const queries = Object.entries(app.queries);
|
|
491
|
+
const controls = Object.entries(app.controls);
|
|
492
|
+
const shownQueries = queries.filter(([name, query]) => showQuery(view, app, name, query));
|
|
493
|
+
const shownControls = controls.filter(([name, control]) => showControl(view, app, name, control));
|
|
494
|
+
const none = (what) => search ? `No ${what} match "${search}".` : `No ${what} match the filter.`;
|
|
495
|
+
const selections = [["Current", app.selection], ["Applied", app.appliedSelection]].filter(([, selection]) => selection);
|
|
496
|
+
return h(
|
|
497
|
+
doc,
|
|
498
|
+
"div",
|
|
499
|
+
{ class: "app", "data-testid": `app-${index}` },
|
|
500
|
+
h(
|
|
501
|
+
doc,
|
|
502
|
+
"p",
|
|
503
|
+
{ class: "app-line", "data-testid": "app-line" },
|
|
504
|
+
several && h(doc, "strong", {}, `App ${index + 1} \xB7 `),
|
|
505
|
+
`${app.title || "Untitled"} \xB7 ${app.timezone || "tenant timezone"} \xB7 `,
|
|
506
|
+
app.hasChanges ? h(doc, "span", { class: "tone-warn" }, "unapplied changes") : "no unapplied changes"
|
|
507
|
+
),
|
|
508
|
+
section(
|
|
509
|
+
"queries",
|
|
510
|
+
index,
|
|
511
|
+
"Queries",
|
|
512
|
+
queries.length,
|
|
513
|
+
filtering ? shownQueries.length : void 0,
|
|
514
|
+
filtering ? none("queries") : "None.",
|
|
515
|
+
() => shownQueries.map(([name, query]) => queryRow(app, index, name, query, byQuery.get(`${index}/${name}`) ?? [], structure))
|
|
516
|
+
),
|
|
517
|
+
section(
|
|
518
|
+
"controls",
|
|
519
|
+
index,
|
|
520
|
+
"Controls",
|
|
521
|
+
controls.length,
|
|
522
|
+
filtering ? shownControls.length : void 0,
|
|
523
|
+
view.filter === "errors" ? "Controls have no error state." : filtering ? none("controls") : "This app declares no controls.",
|
|
524
|
+
() => shownControls.map(([name, control]) => controlRow(app, index, name, control, structure))
|
|
525
|
+
),
|
|
526
|
+
selections.length > 0 && section(
|
|
527
|
+
"selection",
|
|
528
|
+
index,
|
|
529
|
+
"Selection",
|
|
530
|
+
selections.length,
|
|
531
|
+
void 0,
|
|
532
|
+
"None.",
|
|
533
|
+
() => selections.map(([label, selection]) => selectionCard(label, selection))
|
|
534
|
+
)
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
const input = h(doc, "input", {
|
|
538
|
+
type: "search",
|
|
539
|
+
placeholder: "Search names, datasets, labels",
|
|
540
|
+
"aria-label": "Search queries and controls",
|
|
541
|
+
"data-testid": "queries-search",
|
|
542
|
+
oninput: () => {
|
|
543
|
+
view.search = input.value;
|
|
544
|
+
tab.redraw();
|
|
545
|
+
},
|
|
546
|
+
onkeydown: (event) => {
|
|
547
|
+
if (event.key !== "Escape" || !input.value) return;
|
|
548
|
+
view.search = "";
|
|
549
|
+
tab.redraw();
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
const buttons = FILTERS.map((filter) => h(doc, "button", {
|
|
553
|
+
type: "button",
|
|
554
|
+
"data-testid": `queries-filter-${filter}`,
|
|
555
|
+
onclick: () => {
|
|
556
|
+
view.filter = filter;
|
|
557
|
+
tab.redraw();
|
|
558
|
+
}
|
|
559
|
+
}));
|
|
560
|
+
const head = h(
|
|
561
|
+
doc,
|
|
562
|
+
"div",
|
|
563
|
+
{ class: "toolbar" },
|
|
564
|
+
h(doc, "label", { class: "search" }, icon(doc, "search"), input),
|
|
565
|
+
h(doc, "div", { class: "segments", role: "group", "aria-label": "Filter" }, buttons)
|
|
566
|
+
);
|
|
567
|
+
const tab = drawTab(root, context, () => {
|
|
568
|
+
const snapshot = panel.snapshot;
|
|
569
|
+
const counts = queryCounts(snapshot?.apps ?? []);
|
|
570
|
+
const labels = { all: "All", errors: `Errors (${counts.error})`, dirty: `Dirty (${counts.dirty + counts.dirtyControls})` };
|
|
571
|
+
if (input.value !== view.search) input.value = view.search;
|
|
572
|
+
buttons.forEach((button, i) => {
|
|
573
|
+
const filter = FILTERS[i];
|
|
574
|
+
button.textContent = labels[filter];
|
|
575
|
+
button.setAttribute("aria-pressed", String(view.filter === filter));
|
|
576
|
+
});
|
|
577
|
+
if (!snapshot) return note(doc, "Waiting for the Data App\u2026", { "data-testid": "inspect-waiting" });
|
|
578
|
+
if (!snapshot.apps.length) return note(doc, "This Data App hasn't created an SDK app.", { "data-testid": "queries-no-app" });
|
|
579
|
+
const { byQuery, other } = attributeRequests(state.requests.entries(), snapshot.apps);
|
|
580
|
+
return [
|
|
581
|
+
snapshot.apps.map((app, index) => appSection(app, index, snapshot.apps.length > 1, byQuery, snapshot.structure)),
|
|
582
|
+
// At the end, so nothing the frame asked is hidden.
|
|
583
|
+
other.length > 0 && section(
|
|
584
|
+
"other",
|
|
585
|
+
void 0,
|
|
586
|
+
"Other requests",
|
|
587
|
+
other.length,
|
|
588
|
+
void 0,
|
|
589
|
+
"None.",
|
|
590
|
+
() => requestList("other", other.map((entry) => ({ entry })), true)
|
|
591
|
+
)
|
|
592
|
+
];
|
|
593
|
+
}, { head, also: [state.subscribe] });
|
|
594
|
+
root.append(h(doc, "style", {}, CSS));
|
|
595
|
+
const reveal = () => {
|
|
596
|
+
const revealed = state.revealed;
|
|
597
|
+
if (!revealed || handled.get(state) === revealed.nonce || !("entity" in revealed.target)) return;
|
|
598
|
+
const key = entityKey(revealed.target.entity, revealed.target.app, revealed.target.name);
|
|
599
|
+
const row = [...root.querySelectorAll("details[data-key]")].find((element) => element.dataset.key === key);
|
|
600
|
+
if (!row) return;
|
|
601
|
+
handled.set(state, revealed.nonce);
|
|
602
|
+
flash(row);
|
|
603
|
+
};
|
|
604
|
+
reveal();
|
|
605
|
+
const stops = [state.subscribe(reveal), panel.subscribe(reveal)];
|
|
606
|
+
return () => {
|
|
607
|
+
stops.forEach((stop) => stop());
|
|
608
|
+
tab.dispose();
|
|
609
|
+
panel.highlight(null);
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
var CSS = `
|
|
613
|
+
.app + .app, .app + .section { margin-top: 18px; }
|
|
614
|
+
.app-line { margin: 8px 0 0; font-size: 12px; color: var(--anfra-color-muted); }
|
|
615
|
+
.app-line strong { color: var(--anfra-color-fg); font-weight: 500; }
|
|
616
|
+
.count { font-weight: normal; letter-spacing: normal; color: var(--anfra-color-muted); font-variant-numeric: tabular-nums; }
|
|
617
|
+
.entity > summary { align-items: center; }
|
|
618
|
+
.entry { flex: 1; min-width: 0; display: flex; flex-direction: column; }
|
|
619
|
+
.line { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; }
|
|
620
|
+
.entry .error-text { margin: 2px 0 0; font-size: 12px; }
|
|
621
|
+
.rows, .time { flex: none; font-size: 12px; color: var(--anfra-color-muted); font-variant-numeric: tabular-nums; }
|
|
622
|
+
.time { color: var(--anfra-color-fg); font-weight: 500; }
|
|
623
|
+
.condition { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--anfra-color-muted); }
|
|
624
|
+
.changed { flex: none; display: grid; place-items: center; width: 16px; height: 16px; border-radius: 4px; background: var(--warn-bg); color: var(--warn); font-size: 10px; font-weight: 600; }
|
|
625
|
+
.indicator.targets { width: 32px; }
|
|
626
|
+
.inline > summary { display: inline-flex; padding: 0; }
|
|
627
|
+
.inline > .collapsible-body { padding: 2px 0 4px 4px; }
|
|
628
|
+
.places, .chips, .list { list-style: none; margin: 0; padding: 0; }
|
|
629
|
+
.places li { display: flex; align-items: center; gap: 2px; padding-left: 6px; border-radius: 4px; }
|
|
630
|
+
.places li:hover { background: var(--hover); }
|
|
631
|
+
.places li > span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
632
|
+
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
|
|
633
|
+
.chips li { max-width: 100%; overflow: hidden; text-overflow: ellipsis; padding: 0 6px; border: 1px solid var(--anfra-color-border); border-radius: 4px; font-size: 12px; color: var(--anfra-color-muted); }
|
|
634
|
+
.chips li.selected { color: var(--anfra-color-fg); font-weight: 600; border-color: var(--anfra-color-accent); background: var(--accent-bg); }
|
|
635
|
+
/* A tile's lists sit on the panel's ground, divided. */
|
|
636
|
+
.list { margin-top: 2px; border-radius: 8px; background: var(--anfra-color-bg); box-shadow: inset 0 0 0 1px var(--anfra-color-border); font-size: 12px; }
|
|
637
|
+
.list > * + * { border-top: 1px solid var(--anfra-color-border); }
|
|
638
|
+
.type { flex: none; display: inline-grid; place-items: center; width: 16px; color: var(--anfra-color-muted); }
|
|
639
|
+
.item > summary { padding: 7px 8px 7px 10px; gap: 8px; }
|
|
640
|
+
.item > summary > .icon { order: 99; color: var(--anfra-color-muted); }
|
|
641
|
+
.item > summary .name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
|
|
642
|
+
.item > summary .label { min-width: 0; color: var(--anfra-color-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
643
|
+
.item > .collapsible-body { padding: 0 10px 10px 34px; }
|
|
644
|
+
/* A filter on one line: where it comes from, the field, its value, and its source. */
|
|
645
|
+
.filters li { display: grid; grid-template-columns: 16px minmax(0, max-content) minmax(0, 1fr) max-content; align-items: baseline; gap: 8px; padding: 7px 10px; }
|
|
646
|
+
.filters .type { align-self: center; }
|
|
647
|
+
.filters .field { font-weight: 500; overflow-wrap: anywhere; }
|
|
648
|
+
.filters .value { overflow-wrap: anywhere; }
|
|
649
|
+
.filters .source { text-align: right; }
|
|
650
|
+
.filters .link { padding: 0; font-size: 12px; }
|
|
651
|
+
.pending { color: var(--warn); font-size: 12px; }
|
|
652
|
+
.segments.small button { padding: 1px 8px; }
|
|
653
|
+
.sub > summary .segments { margin: -2px 0; }
|
|
654
|
+
.requests > .row + .row { margin-top: 6px; }
|
|
655
|
+
.request > summary { min-height: 36px; padding: 4px 8px 4px 10px; }
|
|
656
|
+
.preview-count { margin: 6px 0 4px; font-size: 12px; color: var(--anfra-color-muted); }
|
|
657
|
+
.lossy { margin: 0 0 6px; font-size: 12px; }
|
|
658
|
+
`;
|
|
659
|
+
export {
|
|
660
|
+
queriesTab as default
|
|
661
|
+
};
|