@holistics/anfra-sdk 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/api.d.ts +1 -1
  2. package/dist/api.js +1 -1
  3. package/dist/app.d.ts +6 -5
  4. package/dist/app.js +4 -4
  5. package/dist/{bootstrap-q1J7GUxa.d.ts → bootstrap-5xNrSbJb.d.ts} +12 -6
  6. package/dist/build.d.ts +2 -2
  7. package/dist/{chunk-GV7SVWEK.js → chunk-4TXKXLWK.js} +42 -11
  8. package/dist/{chunk-J5BTCP6T.js → chunk-CDZ7MBXC.js} +1 -1
  9. package/dist/{chunk-C26OVN2S.js → chunk-EIPHDMZ7.js} +25 -0
  10. package/dist/{chunk-SWNVCTT6.js → chunk-HELL45MM.js} +148 -2
  11. package/dist/{chunk-6GBHCW5E.js → chunk-OS4CRPTU.js} +159 -23
  12. package/dist/{chunk-3ZWUCECU.js → chunk-SXKJQU7A.js} +11 -2
  13. package/dist/{chunk-EL7CAVZ3.js → chunk-ZSIJLBKG.js} +1 -1
  14. package/dist/common.d.ts +4 -3
  15. package/dist/common.js +1 -1
  16. package/dist/{data-TDUQTG3P.js → data-ESPFZ5IM.js} +1 -1
  17. package/dist/{declaration-RJFU4ZLJ.js → declaration-RYRBX7PH.js} +2 -2
  18. package/dist/{errors-IhdhKO-6.d.ts → errors-BlRfqyty.d.ts} +2 -2
  19. package/dist/host.d.ts +9 -2
  20. package/dist/host.js +108 -16
  21. package/dist/{menu-CRAFaQ8s.d.ts → menu-Dmfu51qo.d.ts} +4 -2
  22. package/dist/{overview-RV2IV6PJ.js → overview-S6FTM2JT.js} +84 -43
  23. package/dist/{plugin-BdLabbah.d.ts → plugin-C_Cc_e9L.d.ts} +2 -2
  24. package/dist/plugins.d.ts +1 -1
  25. package/dist/plugins.js +15 -11
  26. package/dist/{queries-5TTPOB7R.js → queries-FWMX7H5Z.js} +2 -2
  27. package/dist/runtimeErrors-gswksjDk.d.ts +55 -0
  28. package/dist/{structure-MTLCRTJ4.js → structure-VFRJFC4C.js} +1 -1
  29. package/dist/testing.d.ts +1 -1
  30. package/dist/testing.js +4 -4
  31. package/dist/{types-C_i7V0DA.d.ts → types-DKQjAL1O.d.ts} +69 -72
  32. package/package.json +1 -1
@@ -1,19 +1,19 @@
1
1
  import {
2
2
  changesOf,
3
- issuesOf,
3
+ problemsOf,
4
4
  queryCounts
5
- } from "./chunk-GV7SVWEK.js";
5
+ } from "./chunk-4TXKXLWK.js";
6
6
  import {
7
7
  controlTargets
8
8
  } from "./chunk-DITKCHFQ.js";
9
9
  import {
10
10
  PLUGIN_VERSION
11
- } from "./chunk-EL7CAVZ3.js";
11
+ } from "./chunk-ZSIJLBKG.js";
12
12
  import {
13
13
  queriesOf,
14
14
  stateOf
15
- } from "./chunk-C26OVN2S.js";
16
- import "./chunk-J5BTCP6T.js";
15
+ } from "./chunk-EIPHDMZ7.js";
16
+ import "./chunk-CDZ7MBXC.js";
17
17
  import {
18
18
  LEVELS,
19
19
  TRUST_LEVELS,
@@ -41,7 +41,7 @@ import {
41
41
  import "./chunk-PKBMQBKP.js";
42
42
 
43
43
  // src/plugins/inspect/tabs/overview.ts
44
- var FIRST_ISSUES = 5;
44
+ var FIRST_PROBLEMS = 5;
45
45
  var TICK_MS = 3e4;
46
46
  var CSS = `
47
47
  .overview { display: flex; flex-direction: column; gap: 10px; padding-top: 8px; }
@@ -67,11 +67,18 @@ var CSS = `
67
67
  .stat:hover .go, .stat:focus-visible .go { opacity: 1; }
68
68
  .stat-value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
69
69
  .stat-detail { width: 100%; font-size: 12px; color: var(--anfra-color-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
70
- .issues { list-style: none; margin: 4px 0 0; padding: 0; }
71
- .issue { display: flex; align-items: flex-start; gap: 8px; width: 100%; border: 0; border-radius: 6px; background: none; padding: 5px 6px; text-align: left; overflow-wrap: anywhere; }
72
- .issue:hover { background: var(--hover); }
73
- .issue .mark { flex: none; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; }
74
- .issue .mark.error { background: var(--anfra-color-danger); } .issue .mark.warn { background: var(--warn); }
70
+ .problems { list-style: none; margin: 4px 0 0; padding: 0; }
71
+ .problem { display: flex; align-items: flex-start; gap: 8px; width: 100%; border: 0; border-radius: 6px; background: none; padding: 5px 6px; text-align: left; overflow-wrap: anywhere; }
72
+ .problem:hover { background: var(--hover); }
73
+ .problem .mark { flex: none; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; }
74
+ .problem .mark.error { background: var(--anfra-color-danger); } .problem .mark.warn { background: var(--warn); }
75
+ .problem .times { flex: none; margin-left: auto; font-size: 12px; color: var(--anfra-color-muted); font-variant-numeric: tabular-nums; }
76
+ .problem-detail, .console > li { margin: 0; font-family: var(--anfra-font-mono); font-size: 11px; white-space: pre-wrap; overflow-wrap: anywhere; }
77
+ .problem-detail { margin: 0 6px 6px 22px; padding: 6px 8px; border-radius: 6px; background: var(--subtle); color: var(--anfra-color-muted); }
78
+ .console { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow: auto; }
79
+ .console > li { display: flex; gap: 8px; padding: 2px 0; }
80
+ .console > li.error { color: var(--anfra-color-danger); } .console > li.warn { color: var(--warn); }
81
+ .console .at { flex: none; color: var(--anfra-color-muted); }
75
82
  .overview > h5 { margin: 6px 0 0; }
76
83
  .tile.collapsible { padding: 6px 12px; }
77
84
  .tile.collapsible > summary { font-weight: 500; }
@@ -93,7 +100,8 @@ function overviewTab(root, context) {
93
100
  const doc = context.document;
94
101
  const { panel, mount } = context;
95
102
  const state = stateOf(mount);
96
- let allIssues = false;
103
+ let allProblems = false;
104
+ const opened = /* @__PURE__ */ new Set();
97
105
  const reveal = (target) => state.reveal(panel, target);
98
106
  const showQueries = (filter) => reveal({ tab: QUERIES_TAB, filter });
99
107
  const trustLevels = (trust) => h(
@@ -194,15 +202,15 @@ function overviewTab(root, context) {
194
202
  onclick && h(doc, "span", { class: "go" }, icon(doc, "chevron"))
195
203
  );
196
204
  }
197
- function stats(apps, issues, requests) {
205
+ function stats(apps, problems, requests) {
198
206
  const counts = queryCounts(apps);
199
- const errors = issues.filter((issue) => issue.level === "error").length;
200
- const warnings = issues.length - errors;
207
+ const errors = problems.filter((problem) => problem.level === "error").length;
208
+ const warnings = problems.length - errors;
201
209
  const controls = apps.reduce((n, app) => n + Object.keys(app.controls).length, 0);
202
210
  const unapplied = counts.dirtyControls;
203
211
  const last = requests.findLast((entry) => entry.call === "core.submitQuery" && entry.status !== "pending");
204
212
  const lastQuery = last?.aql && last.dataset ? queriesOf({ ...last, dataset: last.dataset, aql: last.aql }, apps)[0] : void 0;
205
- const first = issues[0];
213
+ const first = problems[0];
206
214
  const queries = [
207
215
  `${counts.success} ok`,
208
216
  counts.error && `${counts.error} failed`,
@@ -215,12 +223,12 @@ function overviewTab(root, context) {
215
223
  "div",
216
224
  { class: "stats three" },
217
225
  stat(
218
- "issues",
219
- "Issues",
220
- String(issues.length),
221
- issues.length ? `${plural(errors, "error")} \xB7 ${plural(warnings, "warning")}` : "None found",
226
+ "problems",
227
+ "Problems",
228
+ String(problems.length),
229
+ problems.length ? `${plural(errors, "error")} \xB7 ${plural(warnings, "warning")}` : "None found",
222
230
  // Failed queries are what Queries' Errors filter lists; warnings have no such list.
223
- counts.error ? () => showQueries("errors") : first ? () => reveal(first.target) : void 0,
231
+ counts.error ? () => showQueries("errors") : first?.target ? () => reveal(first.target) : void 0,
224
232
  errors ? "error" : warnings ? "warn" : void 0
225
233
  ),
226
234
  stat("queries", "Queries", String(counts.total), queries, () => showQueries("all"), counts.error ? "error" : void 0),
@@ -247,29 +255,61 @@ function overviewTab(root, context) {
247
255
  )
248
256
  ];
249
257
  }
250
- function issuesList(issues) {
251
- if (issues.length === 0) return void 0;
252
- const shown = allIssues ? issues : issues.slice(0, FIRST_ISSUES);
258
+ function problemsList(problems) {
259
+ if (problems.length === 0) return void 0;
260
+ const shown = allProblems ? problems : problems.slice(0, FIRST_PROBLEMS);
253
261
  return [
254
- h(doc, "h5", {}, "Issues"),
255
- h(doc, "ul", { class: "issues", "data-testid": "issues" }, shown.map((issue, i) => h(
256
- doc,
257
- "li",
258
- {},
259
- h(doc, "button", {
260
- type: "button",
261
- class: "issue",
262
- "data-key": `issue:${i}`,
263
- "data-testid": "issue",
264
- onclick: () => reveal(issue.target)
265
- }, h(doc, "span", { class: `mark ${issue.level}`, role: "img", "aria-label": issue.level === "error" ? "Error" : "Warning" }), issue.message)
266
- ))),
267
- issues.length > FIRST_ISSUES && link(doc, allIssues ? "Show fewer" : `Show all ${issues.length}`, () => {
268
- allIssues = !allIssues;
262
+ h(doc, "h5", {}, "Problems"),
263
+ h(doc, "ul", { class: "problems", "data-testid": "problems" }, shown.map((problem, i) => {
264
+ const { target, detail } = problem;
265
+ const open = !target && !!detail && opened.has(problem.message);
266
+ return h(
267
+ doc,
268
+ "li",
269
+ {},
270
+ h(
271
+ doc,
272
+ "button",
273
+ {
274
+ type: "button",
275
+ class: "problem",
276
+ "data-key": `problem:${i}`,
277
+ "data-testid": "problem",
278
+ "aria-expanded": !target && detail ? String(open) : void 0,
279
+ onclick: () => {
280
+ if (target) {
281
+ reveal(target);
282
+ return;
283
+ }
284
+ if (!detail) return;
285
+ if (open) opened.delete(problem.message);
286
+ else opened.add(problem.message);
287
+ tab.redraw();
288
+ }
289
+ },
290
+ h(doc, "span", { class: `mark ${problem.level}`, role: "img", "aria-label": problem.level === "error" ? "Error" : "Warning" }),
291
+ problem.message,
292
+ !!problem.count && h(doc, "span", { class: "times", "aria-label": `${problem.count} times` }, `\xD7${problem.count}`)
293
+ ),
294
+ open && h(doc, "pre", { class: "problem-detail", "data-testid": "problem-detail" }, detail)
295
+ );
296
+ })),
297
+ problems.length > FIRST_PROBLEMS && link(doc, allProblems ? "Show fewer" : `Show all ${problems.length}`, () => {
298
+ allProblems = !allProblems;
269
299
  tab.redraw();
270
- }, { "data-key": "issues:all", "data-testid": "issues-all" })
300
+ }, { "data-key": "problems:all", "data-testid": "problems-all" })
271
301
  ];
272
302
  }
303
+ function consoleLines() {
304
+ const lines = state.console;
305
+ if (lines.length === 0) return void 0;
306
+ return collapsible(doc, "console", ["Console", h(doc, "span", { class: "muted" }, plural(lines.length, "line"))], () => h(
307
+ doc,
308
+ "ul",
309
+ { class: "console", "data-testid": "console" },
310
+ lines.map((line) => h(doc, "li", { class: line.level }, h(doc, "span", { class: "at" }, formatTime(line.at)), line.message))
311
+ ), { class: "tile" });
312
+ }
273
313
  function changes(snapshot) {
274
314
  const { apps, structure } = snapshot;
275
315
  const list = changesOf(apps);
@@ -333,15 +373,16 @@ function overviewTab(root, context) {
333
373
  const { snapshot } = panel;
334
374
  if (!snapshot) return note(doc, "Waiting for the Data App\u2026", { "data-testid": "inspect-waiting" });
335
375
  const { apps } = snapshot;
336
- const issues = issuesOf(snapshot);
376
+ const problems = problemsOf(snapshot, void 0, state.errors);
337
377
  return h(
338
378
  doc,
339
379
  "div",
340
380
  { class: "overview" },
341
381
  statusBar(apps),
342
382
  apps.length === 0 ? note(doc, "This Data App hasn't created an SDK app.", { "data-testid": "no-apps" }) : apps.map((app, index) => trustCard(app, apps.length > 1 ? `App ${index + 1}` : void 0)),
343
- stats(apps, issues, state.requests.entries()),
344
- issuesList(issues),
383
+ stats(apps, problems, state.requests.entries()),
384
+ problemsList(problems),
385
+ consoleLines(),
345
386
  changes(snapshot),
346
387
  environment(apps)
347
388
  );
@@ -1,5 +1,5 @@
1
- import { L as InspectedApp, Q as InspectedStructure, Z as LocateTarget, ak as User, D as DatasetDescriptor } from './types-C_i7V0DA.js';
2
- import { d as MenuTargetKind, c as MenuTarget, e as PluginInfo, h as Theme } from './menu-CRAFaQ8s.js';
1
+ import { L as InspectedApp, Q as InspectedStructure, Z as LocateTarget, ak as User, D as DatasetDescriptor } from './types-DKQjAL1O.js';
2
+ import { d as MenuTargetKind, c as MenuTarget, e as PluginInfo, h as Theme } from './menu-Dmfu51qo.js';
3
3
 
4
4
  /**
5
5
  * The panel: one per mounted Data App, the host's devtools over it. The runtime owns its state (open
package/dist/plugins.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Backend } from './app.js';
2
2
  import { Plugin } from './host.js';
3
- import './menu-CRAFaQ8s.js';
3
+ import './menu-Dmfu51qo.js';
4
4
 
5
5
  /**
6
6
  * `core`: running a Data App's queries and suggesting a filter's values. Every host installs it:
package/dist/plugins.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  PLUGIN_VERSION
3
- } from "./chunk-EL7CAVZ3.js";
3
+ } from "./chunk-ZSIJLBKG.js";
4
4
  import {
5
5
  dropState as dropState2,
6
6
  stateOf as stateOf2
7
- } from "./chunk-C26OVN2S.js";
7
+ } from "./chunk-EIPHDMZ7.js";
8
8
  import {
9
9
  definePlugin
10
10
  } from "./chunk-7K6Z63QO.js";
11
- import "./chunk-J5BTCP6T.js";
11
+ import "./chunk-CDZ7MBXC.js";
12
12
  import {
13
13
  invalidRequest
14
- } from "./chunk-SWNVCTT6.js";
14
+ } from "./chunk-HELL45MM.js";
15
15
  import {
16
16
  dropState,
17
17
  stateOf
@@ -233,8 +233,12 @@ function inspectPlugin() {
233
233
  handle: (request, context, next) => context.mount ? stateOf2(context.mount).record(request, context, next) : next(request)
234
234
  }],
235
235
  mount: (mount) => {
236
- stateOf2(mount);
237
- return () => dropState2(mount);
236
+ const state = stateOf2(mount);
237
+ const off = [mount.on("anfra.error", state.addError), mount.on("anfra.console", state.addConsole)];
238
+ return () => {
239
+ off.forEach((stop) => stop());
240
+ dropState2(mount);
241
+ };
238
242
  },
239
243
  commands: [{
240
244
  id: "toggle",
@@ -245,11 +249,11 @@ function inspectPlugin() {
245
249
  run: { tab: OVERVIEW_TAB }
246
250
  }],
247
251
  tabs: [
248
- tab("overview", "Overview", "overview", 10, () => import("./overview-RV2IV6PJ.js")),
249
- tab("data", "Data", "table", 20, () => import("./data-TDUQTG3P.js")),
250
- tab("queries", "Queries", "query", 30, () => import("./queries-5TTPOB7R.js")),
251
- tab("structure", "Structure", "tree", 40, () => import("./structure-MTLCRTJ4.js"), "pick"),
252
- tab("declaration", "Declaration", "code", 50, () => import("./declaration-RJFU4ZLJ.js"))
252
+ tab("overview", "Overview", "overview", 10, () => import("./overview-S6FTM2JT.js")),
253
+ tab("data", "Data", "table", 20, () => import("./data-ESPFZ5IM.js")),
254
+ tab("queries", "Queries", "query", 30, () => import("./queries-FWMX7H5Z.js")),
255
+ tab("structure", "Structure", "tree", 40, () => import("./structure-VFRJFC4C.js"), "pick"),
256
+ tab("declaration", "Declaration", "code", 50, () => import("./declaration-RYRBX7PH.js"))
253
257
  ]
254
258
  }
255
259
  });
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isChanged,
3
3
  queryCounts
4
- } from "./chunk-GV7SVWEK.js";
4
+ } from "./chunk-4TXKXLWK.js";
5
5
  import {
6
6
  columnKind
7
7
  } from "./chunk-HI3ZAXJK.js";
@@ -15,7 +15,7 @@ import {
15
15
  import {
16
16
  attributeRequests,
17
17
  stateOf
18
- } from "./chunk-C26OVN2S.js";
18
+ } from "./chunk-EIPHDMZ7.js";
19
19
  import {
20
20
  badge,
21
21
  codeBlock,
@@ -0,0 +1,55 @@
1
+ /**
2
+ * A Data App's runtime errors and console lines, as its frame reports them to its host
3
+ * (docs/designs/errors/data-apps.md). The frame runs code anyone may write, so the host
4
+ * reads each event through `checkErrorEvent` / `checkConsoleEvent`: only the fields named here,
5
+ * each string capped. Never rows or a request's params.
6
+ */
7
+ /** Whose code failed, or which of the SDK's calls: the first part of an error's kind. */
8
+ type AppErrorSource = 'call' | 'app' | 'plugin' | 'host';
9
+ /**
10
+ * Where a runtime error came from, as `<source>.<what>` in snake_case. Known today:
11
+ *
12
+ * - `call.query`: a query's run ended in `error`, whether or not the app shows it;
13
+ * - `call.<api>`: a call the app made and left unhandled, named as the app called it
14
+ * (`call.fetch_more`, `call.export`, `call.load_options`, `call.lineage`; `Anfra.foo.bar()` is
15
+ * `call.foo_bar`);
16
+ * - `app.uncaught`: an uncaught error or unhandled rejection in the frame;
17
+ * - `app.listener`: a `subscribe()` listener threw;
18
+ * - `plugin.uncaught`: a failure the SDK caught to keep the app running (a plugin's setup, answer
19
+ * or drawing, the menu);
20
+ * - `host.internal`: a call the host failed and showed the frame only as `call_failed`.
21
+ *
22
+ * More may come under these sources: branch on the source, and treat a kind you don't know by it.
23
+ */
24
+ type AppErrorKind = `${AppErrorSource}.${string}`;
25
+ /** One runtime error of a mounted Data App. */
26
+ interface AppErrorEvent {
27
+ kind: AppErrorKind;
28
+ /** The error's code and scope, when it is one of the SDK's (`DataAppError`); absent for an app's own `TypeError`. */
29
+ code?: string;
30
+ scope?: string;
31
+ message: string;
32
+ /** The server request that failed: its line in the server's log has the cause. */
33
+ requestId?: string;
34
+ /** The query or control it concerns. */
35
+ entity?: string;
36
+ /** Where it was thrown, truncated; not for `call.*`, whose stack is the SDK's. */
37
+ stack?: string;
38
+ /** For `host.internal`: the call the host failed (`export.query`). */
39
+ call?: string;
40
+ /** When it happened, ISO 8601. */
41
+ at: string;
42
+ /** The mount it happened in (set by the host): its id, and its title if it was given one. */
43
+ mount: number;
44
+ title?: string;
45
+ }
46
+ /** One `console.error` / `console.warn` line of a mounted Data App, reported only when the host captures them. */
47
+ interface AppConsoleEvent {
48
+ level: 'error' | 'warn';
49
+ message: string;
50
+ at: string;
51
+ mount: number;
52
+ title?: string;
53
+ }
54
+
55
+ export type { AppConsoleEvent as A, AppErrorEvent as a, AppErrorKind as b };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  stateOf
3
- } from "./chunk-C26OVN2S.js";
3
+ } from "./chunk-EIPHDMZ7.js";
4
4
  import {
5
5
  badge,
6
6
  control,
package/dist/testing.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PluginInfo } from './app.js';
2
2
  import { User, DatasetDescriptor } from './app.js';
3
3
  import { Sdk, PluginSetup } from './app.js';
4
- import './errors-IhdhKO-6.js';
4
+ import './errors-BlRfqyty.js';
5
5
 
6
6
  /** The reader a test frame is provisioned with unless given. */
7
7
  declare const TEST_READER: User;
package/dist/testing.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  bootstrap
3
- } from "./chunk-6GBHCW5E.js";
3
+ } from "./chunk-OS4CRPTU.js";
4
4
  import "./chunk-XIUFHRZE.js";
5
5
  import {
6
6
  createEndpoint
7
- } from "./chunk-3ZWUCECU.js";
7
+ } from "./chunk-SXKJQU7A.js";
8
8
  import {
9
9
  PROVISION_ELEMENT_ID
10
10
  } from "./chunk-RXPNL7UR.js";
11
- import "./chunk-J5BTCP6T.js";
12
- import "./chunk-SWNVCTT6.js";
11
+ import "./chunk-CDZ7MBXC.js";
12
+ import "./chunk-HELL45MM.js";
13
13
  import "./chunk-PKBMQBKP.js";
14
14
 
15
15
  // src/testing/frame.ts