@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
package/dist/api.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Client } from 'openapi-fetch';
2
- import { am as paths, al as components } from './types-C_i7V0DA.js';
2
+ import { am as paths, al as components } from './types-DKQjAL1O.js';
3
3
  import { DatasetDescriptor, Backend, BackendExportRequest, BackendQueryRequest } from './app.js';
4
4
  import { DataAppError } from './app.js';
5
5
 
package/dist/api.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  fromHttpStatus,
6
6
  invalidRequest,
7
7
  toScope
8
- } from "./chunk-SWNVCTT6.js";
8
+ } from "./chunk-HELL45MM.js";
9
9
  import "./chunk-PKBMQBKP.js";
10
10
 
11
11
  // src/api/client.ts
package/dist/app.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { S as Sdk } from './bootstrap-q1J7GUxa.js';
2
- export { A as AnfraPlugins, a as App, C as Control, b as CrossFilter, D as DateDrillControl, c as DeprecatedFeatures, E as Edge, F as Filter, d as FrameKernel, e as FrameMenuEntry, f as FrameMenuItem, I as InstalledPlugins, M as Mapping, g as ModalInput, O as OVERLAY_ID, h as Opened, i as PluginApi, j as PluginMembers, k as PluginName, P as PluginSetup, l as PopoverInput, m as PopoverSide, Q as Query, n as STRUCTURE_ATTRIBUTES, V as VERSION, o as bootstrap, p as buildStructure, q as createSdk, r as parseRef } from './bootstrap-q1J7GUxa.js';
3
- export { A as ApiErrorCode, D as DataAppError, a as DataAppErrorInit, E as ErrorCode, b as ErrorContextEntry, c as ErrorDetails, d as ErrorScope, F as FromHttpStatusOptions, G as GENERIC_CODES, e as GenericCode, V as ValidationError, f as callFailed, g as connectionFailed, h as forbidden, i as fromHttpStatus, j as hasErrorCode, k as invalidRequest, l as isDataAppError } from './errors-IhdhKO-6.js';
4
- 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 QueryRequest, a4 as QueryResult, a5 as QuerySort, a6 as QueryState, a7 as QueryTimings, a8 as RenderFormat, a9 as RenderRequest, aa as Rendering, ab as Row, ac as SdkEnvironment, ad as SdkFeatures, ae as Selection, af as SelectionCondition, ag as SemanticType, ah as StructureKind, ai as StructureNode, aj as Unsubscribe, ak as User } from './types-C_i7V0DA.js';
5
- export { B as BridgeError, a as BridgeMessage, D as DEFAULT_TOKENS, b as DESIGN_TOKENS, F as FrameMessage, H as HostMessage, M as MenuEntry, c as MenuTarget, d as MenuTargetKind, N as NodeTarget, P as PROVISION_ELEMENT_ID, e as PluginInfo, f as Provision, R as RowsTarget, T as THEME_TOKENS, g as TargetRect, h as Theme, i as ThemeInput, j as ThemeScheme, k as ThemeToken, l as ThemeTokens, m as checkTarget, n as designTheme, r as resolveTheme } from './menu-CRAFaQ8s.js';
1
+ import { S as Sdk } from './bootstrap-5xNrSbJb.js';
2
+ export { A as AnfraPlugins, a as App, C as Control, b as CrossFilter, D as DateDrillControl, c as DeprecatedFeatures, E as Edge, F as Filter, d as FrameKernel, e as FrameMenuEntry, f as FrameMenuItem, I as InstalledPlugins, M as Mapping, g as ModalInput, O as OVERLAY_ID, h as Opened, i as PluginApi, j as PluginMembers, k as PluginName, P as PluginSetup, l as PopoverInput, m as PopoverSide, Q as Query, n as STRUCTURE_ATTRIBUTES, V as VERSION, o as bootstrap, p as buildStructure, q as createSdk, r as parseRef } from './bootstrap-5xNrSbJb.js';
3
+ export { A as ApiErrorCode, D as DataAppError, a as DataAppErrorInit, E as ErrorCode, b as ErrorContextEntry, c as ErrorDetails, d as ErrorScope, F as FromHttpStatusOptions, G as GENERIC_CODES, e as GenericCode, V as ValidationError, f as callFailed, g as connectionFailed, h as forbidden, i as fromHttpStatus, j as hasErrorCode, k as invalidRequest, l as isDataAppError } from './errors-BlRfqyty.js';
4
+ 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 QueryRequest, a4 as QueryResult, a5 as QuerySort, a6 as QueryState, a7 as QueryTimings, a8 as RenderFormat, a9 as RenderRequest, aa as Rendering, ab as Row, ac as SdkEnvironment, ad as SdkFeatures, ae as Selection, af as SelectionCondition, ag as SemanticType, ah as StructureKind, ai as StructureNode, aj as Unsubscribe, ak as User } from './types-DKQjAL1O.js';
5
+ export { A as AppConsoleEvent, a as AppErrorEvent, b as AppErrorKind } from './runtimeErrors-gswksjDk.js';
6
+ export { B as BridgeError, a as BridgeMessage, D as DEFAULT_TOKENS, b as DESIGN_TOKENS, F as FrameMessage, H as HostMessage, M as MenuEntry, c as MenuTarget, d as MenuTargetKind, N as NodeTarget, P as PROVISION_ELEMENT_ID, e as PluginInfo, f as Provision, R as RowsTarget, T as THEME_TOKENS, g as TargetRect, h as Theme, i as ThemeInput, j as ThemeScheme, k as ThemeToken, l as ThemeTokens, m as checkTarget, n as designTheme, r as resolveTheme } from './menu-Dmfu51qo.js';
6
7
 
7
8
  declare const SANDBOX_GLOBAL = "Anfra";
8
9
  /**
package/dist/app.js CHANGED
@@ -22,11 +22,11 @@ import {
22
22
  createSdk,
23
23
  installSandbox,
24
24
  parseRef
25
- } from "./chunk-6GBHCW5E.js";
25
+ } from "./chunk-OS4CRPTU.js";
26
26
  import {
27
27
  FILTER_AGGREGATIONS
28
28
  } from "./chunk-XIUFHRZE.js";
29
- import "./chunk-3ZWUCECU.js";
29
+ import "./chunk-SXKJQU7A.js";
30
30
  import {
31
31
  DEFAULT_TOKENS,
32
32
  DESIGN_TOKENS,
@@ -35,7 +35,7 @@ import {
35
35
  designTheme,
36
36
  resolveTheme
37
37
  } from "./chunk-RXPNL7UR.js";
38
- import "./chunk-J5BTCP6T.js";
38
+ import "./chunk-CDZ7MBXC.js";
39
39
  import {
40
40
  DataAppError,
41
41
  GENERIC_CODES,
@@ -47,7 +47,7 @@ import {
47
47
  hasErrorCode,
48
48
  invalidRequest,
49
49
  isDataAppError
50
- } from "./chunk-SWNVCTT6.js";
50
+ } from "./chunk-HELL45MM.js";
51
51
  import "./chunk-PKBMQBKP.js";
52
52
  export {
53
53
  App,
@@ -1,6 +1,6 @@
1
- import { D as DataAppError, V as ValidationError, k as invalidRequest, h as forbidden, g as connectionFailed, f as callFailed, i as fromHttpStatus, j as hasErrorCode, l as isDataAppError } from './errors-IhdhKO-6.js';
2
- import { X as Listener, aj as Unsubscribe, D as DatasetDescriptor, y as ExportOptions, z as ExportResult, a9 as RenderRequest, aa as Rendering, W as LineageTarget, U as LineageOptions, V as LineageResult, E as EntityKind, l as Condition, J as FilterDeclaration, K as FilterValueType, B as Backend, m as ConditionValue, p as DateDrillDeclaration, q as DateGrain, I as FilterAggregation, n as ControlMappingJson, o as CrossFilterJson, ad as SdkFeatures, ae as Selection, af as SelectionCondition, ab as Row, Y as LocateKind, a1 as QueryDeclaration, a6 as QueryState, a4 as QueryResult, a5 as QuerySort, a as AppDeclaration, a3 as QueryRequest, u as ExecuteOptions, v as ExecuteSummary, f as BackendExportRequest, b as AppJson, L as InspectedApp, ak as User, ac as SdkEnvironment, Q as InspectedStructure } from './types-C_i7V0DA.js';
3
- import { e as PluginInfo, j as ThemeScheme, l as ThemeTokens, h as Theme, d as MenuTargetKind, c as MenuTarget, N as NodeTarget } from './menu-CRAFaQ8s.js';
1
+ import { D as DataAppError, V as ValidationError, k as invalidRequest, h as forbidden, g as connectionFailed, f as callFailed, i as fromHttpStatus, j as hasErrorCode, l as isDataAppError } from './errors-BlRfqyty.js';
2
+ import { X as Listener, aj as Unsubscribe, D as DatasetDescriptor, y as ExportOptions, z as ExportResult, a9 as RenderRequest, aa as Rendering, W as LineageTarget, U as LineageOptions, V as LineageResult, E as EntityKind, l as Condition, J as FilterDeclaration, K as FilterValueType, B as Backend, m as ConditionValue, p as DateDrillDeclaration, q as DateGrain, I as FilterAggregation, n as ControlMappingJson, o as CrossFilterJson, ad as SdkFeatures, ae as Selection, af as SelectionCondition, ab as Row, Y as LocateKind, a1 as QueryDeclaration, a6 as QueryState, a4 as QueryResult, a5 as QuerySort, a as AppDeclaration, a3 as QueryRequest, u as ExecuteOptions, v as ExecuteSummary, f as BackendExportRequest, b as AppJson, L as InspectedApp, ak as User, ac as SdkEnvironment, Q as InspectedStructure } from './types-DKQjAL1O.js';
3
+ import { e as PluginInfo, j as ThemeScheme, l as ThemeTokens, h as Theme, d as MenuTargetKind, c as MenuTarget, N as NodeTarget } from './menu-Dmfu51qo.js';
4
4
 
5
5
  interface NotificationTarget {
6
6
  notifyChange(): void;
@@ -269,6 +269,8 @@ declare class Query extends Observable {
269
269
  readonly dataset: DatasetIndex;
270
270
  private readonly app;
271
271
  private _state;
272
+ /** Its last run failed: not a `fetchMore`, whose failure leaves the pages already loaded to keep. */
273
+ private runFailed;
272
274
  private _result?;
273
275
  private _error?;
274
276
  private _page;
@@ -320,7 +322,11 @@ declare class Query extends Observable {
320
322
  * from `shouldRun`, which is true in that case precisely because there is no result yet.
321
323
  */
322
324
  get isDirty(): boolean;
323
- /** @internal */
325
+ /**
326
+ * @internal Also when its last run failed, whatever its inputs: so `execute()` is the retry, of
327
+ * the failed queries only, even after a forced run (`refresh()`) failed with unchanged inputs. Not
328
+ * after a failed `fetchMore`: rerun, it would drop the pages already loaded; `fetchMore` is its retry.
329
+ */
324
330
  shouldRun(force?: boolean): boolean;
325
331
  /** Stops the in-flight request for this query. The pending `execute()` resolves without it. */
326
332
  abort(): void;
@@ -367,8 +373,8 @@ declare class Query extends Observable {
367
373
  markExecuting(): void;
368
374
  /** @internal */
369
375
  markSuccess(result: QueryResult, signature: string, append: boolean): void;
370
- /** @internal */
371
- markError(error: DataAppError): void;
376
+ /** @internal `page` when it is a `fetchMore` that failed, not a run. */
377
+ markError(error: DataAppError, page?: boolean): void;
372
378
  /** @internal Reverts an optimistic page bump when a `fetchMore` fails. */
373
379
  rewindPage(): void;
374
380
  /** @internal */
package/dist/build.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FrameHalf } from './host.js';
2
- import './types-C_i7V0DA.js';
3
- import './menu-CRAFaQ8s.js';
2
+ import './types-DKQjAL1O.js';
3
+ import './menu-Dmfu51qo.js';
4
4
 
5
5
  /**
6
6
  * @holistics/anfra-sdk/build: building an SDK plugin's frame half into the script source a host
@@ -40,28 +40,59 @@ function changesOf(apps) {
40
40
  );
41
41
  }
42
42
 
43
- // src/plugins/inspect/model/issues.ts
43
+ // src/plugins/inspect/model/problems.ts
44
+ var RUNTIME_LABELS = {
45
+ "call.query": "Query failed",
46
+ "app.uncaught": "Uncaught error",
47
+ "app.listener": "A subscribe() listener threw",
48
+ "plugin.uncaught": "A plugin failed",
49
+ "host.internal": "The host failed a call"
50
+ };
51
+ function runtimeLabel(kind) {
52
+ if (Object.hasOwn(RUNTIME_LABELS, kind)) return RUNTIME_LABELS[kind];
53
+ const [source, what] = kind.split(".", 2);
54
+ return source === "call" ? `Unhandled ${what} call failed` : `Error (${kind})`;
55
+ }
56
+ function runtimeProblem(entry, snapshot) {
57
+ const { event, count } = entry;
58
+ const detail = [
59
+ event.call && `Call: ${event.call}`,
60
+ event.code && `Code: ${event.code}${event.scope ? ` (${event.scope})` : ""}`,
61
+ event.requestId && `Request: ${event.requestId}`,
62
+ event.stack
63
+ ].filter(Boolean).join("\n");
64
+ const problem = { level: "error", message: `${runtimeLabel(event.kind)}: ${event.message}` };
65
+ if (detail) problem.detail = detail;
66
+ if (count > 1) problem.count = count;
67
+ const { entity } = event;
68
+ if (entity) {
69
+ const app = snapshot.apps.findIndex((a) => Object.hasOwn(a.queries, entity) || Object.hasOwn(a.controls, entity));
70
+ if (app >= 0) problem.target = { entity: Object.hasOwn(snapshot.apps[app].queries, entity) ? "query" : "control", app, name: entity };
71
+ }
72
+ return problem;
73
+ }
44
74
  function problemNodes(nodes) {
45
75
  return nodes.flatMap((node) => [...node.problems.length ? [node] : [], ...problemNodes(node.children)]);
46
76
  }
47
- function appIssues(app, index, checks = wiringChecks(app)) {
48
- const issues = [];
77
+ function appProblems(app, index, checks = wiringChecks(app)) {
78
+ const problems = [];
49
79
  for (const [name, query] of Object.entries(app.queries)) {
50
80
  if (query.state !== "error") continue;
51
- issues.push({ level: "error", message: `${name} failed: ${query.error?.message ?? "no message"}`, target: { entity: "query", app: index, name } });
81
+ problems.push({ level: "error", message: `${name} failed: ${query.error?.message ?? "no message"}`, target: { entity: "query", app: index, name } });
52
82
  }
53
83
  checks.forEach((check, i) => {
54
84
  if (check.level === "info") return;
55
- issues.push({ level: check.level, message: check.message, target: { check: i, app: index } });
85
+ problems.push({ level: check.level, message: check.message, target: { check: i, app: index } });
56
86
  });
57
- return issues;
87
+ return problems;
58
88
  }
59
- function issuesOf(snapshot, checks) {
60
- const issues = snapshot.apps.flatMap((app, index) => appIssues(app, index, checks?.[index]));
89
+ function problemsOf(snapshot, checks, runtime = []) {
90
+ const problems = snapshot.apps.flatMap((app, index) => appProblems(app, index, checks?.[index]));
91
+ problems.push(...runtime.map((entry) => runtimeProblem(entry, snapshot)));
61
92
  for (const node of problemNodes(snapshot.structure.nodes)) {
62
- for (const problem of node.problems) issues.push({ level: "warn", message: `${handleFor(node)}: ${problem}`, target: { node: node.key } });
93
+ for (const problem of node.problems) problems.push({ level: "warn", message: `${handleFor(node)}: ${problem}`, target: { node: node.key } });
63
94
  }
64
- return [...issues.filter((i) => i.level === "error"), ...issues.filter((i) => i.level === "warn")];
95
+ return [...problems.filter((p) => p.level === "error"), ...problems.filter((p) => p.level === "warn")];
65
96
  }
66
97
  function queryCounts(apps) {
67
98
  const counts = { success: 0, error: 0, executing: 0, idle: 0, dirty: 0, total: 0, dirtyControls: 0 };
@@ -79,6 +110,6 @@ function queryCounts(apps) {
79
110
  export {
80
111
  isChanged,
81
112
  changesOf,
82
- issuesOf,
113
+ problemsOf,
83
114
  queryCounts
84
115
  };
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.17.0";
2
+ var version = "0.19.0";
3
3
 
4
4
  export {
5
5
  version
@@ -170,6 +170,8 @@ function describeError(err) {
170
170
  }
171
171
 
172
172
  // src/plugins/inspect/state.ts
173
+ var RUNTIME_LIMIT = 50;
174
+ var CONSOLE_LIMIT = 200;
173
175
  var states = /* @__PURE__ */ new WeakMap();
174
176
  function stateOf(mount) {
175
177
  let state = states.get(mount);
@@ -192,8 +194,31 @@ function createState() {
192
194
  }
193
195
  });
194
196
  let nonce = 0;
197
+ const errors = [];
198
+ const lines = [];
195
199
  const state = {
196
200
  requests: recorder.log,
201
+ errors,
202
+ console: lines,
203
+ addError(event) {
204
+ if (event.kind === "call.query") return;
205
+ const same = errors.find((entry) => entry.event.kind === event.kind && entry.event.message === event.message && entry.event.call === event.call);
206
+ if (same) {
207
+ same.count += 1;
208
+ same.event = event;
209
+ errors.splice(errors.indexOf(same), 1);
210
+ errors.unshift(same);
211
+ } else {
212
+ errors.unshift({ event, count: 1 });
213
+ errors.length = Math.min(errors.length, RUNTIME_LIMIT);
214
+ }
215
+ changed();
216
+ },
217
+ addConsole(event) {
218
+ lines.push(event);
219
+ if (lines.length > CONSOLE_LIMIT) lines.splice(0, lines.length - CONSOLE_LIMIT);
220
+ changed();
221
+ },
197
222
  record: recorder.record,
198
223
  queries: { search: "", filter: "all", open: /* @__PURE__ */ new Set(), closed: /* @__PURE__ */ new Set() },
199
224
  data: { open: /* @__PURE__ */ new Set() },
@@ -2,6 +2,142 @@ import {
2
2
  __publicField
3
3
  } from "./chunk-PKBMQBKP.js";
4
4
 
5
+ // src/common/runtimeErrors.ts
6
+ var KIND = /^(call|app|plugin|host)\.[a-z][a-z0-9_]*$/;
7
+ function isErrorKind(kind) {
8
+ return typeof kind === "string" && kind.length <= 100 && KIND.test(kind);
9
+ }
10
+ function snakeCase(name) {
11
+ return name.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[^A-Za-z0-9]+/g, "_").toLowerCase();
12
+ }
13
+ var callTags = /* @__PURE__ */ new WeakMap();
14
+ function tagCall(err, api) {
15
+ if (typeof err === "object" && err !== null) callTags.set(err, api);
16
+ }
17
+ function callOf(err) {
18
+ for (let e = err, depth = 0; typeof e === "object" && e !== null && depth < 5; e = e.cause, depth += 1) {
19
+ const tag = callTags.get(e);
20
+ if (tag) return tag;
21
+ }
22
+ return void 0;
23
+ }
24
+ function copyCallTag(from, to) {
25
+ const tag = callTags.get(from);
26
+ if (tag) callTags.set(to, tag);
27
+ return to;
28
+ }
29
+ function namedCall(fn, api) {
30
+ return function(...args) {
31
+ const out = fn.apply(this, args);
32
+ if (out && typeof out.then === "function") {
33
+ return out.then(void 0, (err) => {
34
+ tagCall(err, api);
35
+ throw err;
36
+ });
37
+ }
38
+ return out;
39
+ };
40
+ }
41
+ var MESSAGE_LIMIT = 2e3;
42
+ var STACK_LIMIT = 4e3;
43
+ function truncate(text, limit) {
44
+ return text.length <= limit ? text : `${text.slice(0, limit)}\u2026 (truncated)`;
45
+ }
46
+ function describeError(kind, err) {
47
+ const e = err;
48
+ const isObject = typeof e === "object" && e !== null;
49
+ const out = {
50
+ kind,
51
+ message: truncate(isObject && typeof e.message === "string" ? e.message : String(err), MESSAGE_LIMIT),
52
+ at: (/* @__PURE__ */ new Date()).toISOString()
53
+ };
54
+ if (!isObject) return out;
55
+ for (const key of ["code", "scope", "requestId", "entity"]) {
56
+ const value = e[key];
57
+ if (typeof value === "string") out[key] = value;
58
+ }
59
+ if (!kind.startsWith("call.") && typeof e.stack === "string") out.stack = truncate(e.stack, STACK_LIMIT);
60
+ return out;
61
+ }
62
+ function createBudget(perMinute, onDropped = () => {
63
+ }, now = Date.now) {
64
+ let windowStart = now();
65
+ let taken = 0;
66
+ let dropped = 0;
67
+ let timer;
68
+ const flush = () => {
69
+ timer = void 0;
70
+ const count = dropped;
71
+ dropped = 0;
72
+ if (count > 0) {
73
+ try {
74
+ onDropped(count);
75
+ } catch {
76
+ }
77
+ }
78
+ };
79
+ return {
80
+ take() {
81
+ const t = now();
82
+ if (t - windowStart >= 6e4) {
83
+ if (timer !== void 0) clearTimeout(timer);
84
+ flush();
85
+ windowStart = t;
86
+ taken = 0;
87
+ }
88
+ if (taken < perMinute) {
89
+ taken += 1;
90
+ return true;
91
+ }
92
+ dropped += 1;
93
+ if (timer === void 0) timer = setTimeout(flush, Math.max(0, windowStart + 6e4 - t));
94
+ return false;
95
+ },
96
+ dispose() {
97
+ if (timer !== void 0) clearTimeout(timer);
98
+ flush();
99
+ }
100
+ };
101
+ }
102
+ var str = (value, limit) => typeof value === "string" ? truncate(value, limit) : void 0;
103
+ var SHORT = 200;
104
+ function checkErrorEvent(payload, mount) {
105
+ const p = payload;
106
+ if (!p || typeof p !== "object") return void 0;
107
+ const kind = p.kind;
108
+ if (!isErrorKind(kind) || kind.startsWith("host.")) return void 0;
109
+ const event = {
110
+ kind,
111
+ message: str(p.message, MESSAGE_LIMIT) || "An error with no message.",
112
+ at: typeof p.at === "string" && !Number.isNaN(Date.parse(p.at)) ? p.at : (/* @__PURE__ */ new Date()).toISOString(),
113
+ mount: mount.id
114
+ };
115
+ const code = str(p.code, SHORT);
116
+ const scope = str(p.scope, SHORT);
117
+ const requestId = str(p.requestId, SHORT);
118
+ const entity = str(p.entity, SHORT);
119
+ const stack = kind.startsWith("call.") ? void 0 : str(p.stack, STACK_LIMIT);
120
+ if (code) event.code = code;
121
+ if (scope) event.scope = scope;
122
+ if (requestId) event.requestId = requestId;
123
+ if (entity) event.entity = entity;
124
+ if (stack) event.stack = stack;
125
+ if (mount.title !== void 0) event.title = mount.title;
126
+ return event;
127
+ }
128
+ function checkConsoleEvent(payload, mount) {
129
+ const p = payload;
130
+ if (!p || typeof p !== "object" || p.level !== "error" && p.level !== "warn") return void 0;
131
+ const event = {
132
+ level: p.level,
133
+ message: str(p.message, MESSAGE_LIMIT) ?? "",
134
+ at: typeof p.at === "string" && !Number.isNaN(Date.parse(p.at)) ? p.at : (/* @__PURE__ */ new Date()).toISOString(),
135
+ mount: mount.id
136
+ };
137
+ if (mount.title !== void 0) event.title = mount.title;
138
+ return event;
139
+ }
140
+
5
141
  // src/common/errors.ts
6
142
  var GENERIC_CODES = {
7
143
  query_invalid: "user",
@@ -46,7 +182,7 @@ var DataAppError = class _DataAppError extends Error {
46
182
  /** This error, naming `entity`: the same failure, said of the query or control it concerns. */
47
183
  about(entity) {
48
184
  if (this.entity === entity) return this;
49
- return new _DataAppError({ ...fieldsOf(this), entity });
185
+ return copyCallTag(this, new _DataAppError({ ...fieldsOf(this), entity }));
50
186
  }
51
187
  };
52
188
  var ValidationError = class _ValidationError extends DataAppError {
@@ -59,7 +195,7 @@ var ValidationError = class _ValidationError extends DataAppError {
59
195
  });
60
196
  }
61
197
  about(entity) {
62
- return this.entity === entity ? this : new _ValidationError(this.message, entity);
198
+ return this.entity === entity ? this : copyCallTag(this, new _ValidationError(this.message, entity));
63
199
  }
64
200
  };
65
201
  function isDataAppError(err) {
@@ -146,6 +282,16 @@ function fieldsOf(err) {
146
282
  }
147
283
 
148
284
  export {
285
+ snakeCase,
286
+ tagCall,
287
+ callOf,
288
+ namedCall,
289
+ MESSAGE_LIMIT,
290
+ truncate,
291
+ describeError,
292
+ createBudget,
293
+ checkErrorEvent,
294
+ checkConsoleEvent,
149
295
  GENERIC_CODES,
150
296
  DataAppError,
151
297
  ValidationError,