@holistics/anfra-sdk 0.16.0 → 0.18.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 (38) hide show
  1. package/README.md +2 -1
  2. package/dist/ambient.d.ts +2 -1
  3. package/dist/api.d.ts +11 -5
  4. package/dist/api.js +40 -30
  5. package/dist/app.d.ts +5 -5
  6. package/dist/app.js +22 -12
  7. package/dist/{bootstrap-hLhpijIb.d.ts → bootstrap-q1J7GUxa.d.ts} +55 -18
  8. package/dist/build.d.ts +2 -2
  9. package/dist/{chunk-THYCARLT.js → chunk-2O2WVQXO.js} +102 -30
  10. package/dist/chunk-32566ZNE.js +1278 -0
  11. package/dist/{chunk-S6XLP6U4.js → chunk-3ZWUCECU.js} +45 -20
  12. package/dist/{chunk-KFD6CHLI.js → chunk-ACKFOANJ.js} +2 -0
  13. package/dist/{chunk-SKSKC747.js → chunk-B6URV5AO.js} +1 -1
  14. package/dist/{chunk-CYZQ7ZTJ.js → chunk-C26OVN2S.js} +6 -1
  15. package/dist/{chunk-PTNYQOEY.js → chunk-NS7HJHNK.js} +1 -1
  16. package/dist/chunk-SWNVCTT6.js +161 -0
  17. package/dist/common.d.ts +3 -3
  18. package/dist/common.js +19 -9
  19. package/dist/{data-BGX3V42T.js → data-TDUQTG3P.js} +8 -6
  20. package/dist/{declaration-ZL5B676C.js → declaration-RJFU4ZLJ.js} +2 -2
  21. package/dist/errors-IhdhKO-6.d.ts +119 -0
  22. package/dist/host.d.ts +2 -2
  23. package/dist/host.js +17 -17
  24. package/dist/{menu-BFLb7dVq.d.ts → menu-CRAFaQ8s.d.ts} +21 -5
  25. package/dist/{overview-7YU7JW6Q.js → overview-AZCX6SY6.js} +23 -23
  26. package/dist/{plugin-B7SpJLBm.d.ts → plugin-BdLabbah.d.ts} +2 -2
  27. package/dist/plugins.d.ts +11 -2
  28. package/dist/plugins.js +38 -21
  29. package/dist/{queries-QFN4DI25.js → queries-5TTPOB7R.js} +32 -30
  30. package/dist/{structure-Z2QK5MGH.js → structure-MTLCRTJ4.js} +11 -9
  31. package/dist/{tab-LSITVMKV.js → tab-XL2HS5W4.js} +20 -18
  32. package/dist/testing.d.ts +1 -1
  33. package/dist/testing.js +4 -4
  34. package/dist/{types-CKytl8ds.d.ts → types-C_i7V0DA.d.ts} +46 -14
  35. package/package.json +2 -1
  36. package/dist/chunk-F6B3EGFV.js +0 -750
  37. package/dist/chunk-KCTLO3CO.js +0 -41
  38. package/dist/errors-CKvqVaqU.d.ts +0 -30
@@ -1,9 +1,11 @@
1
1
  import {
2
- PermissionError,
3
- QueryError,
4
- TransportError,
5
- ValidationError
6
- } from "./chunk-KCTLO3CO.js";
2
+ DataAppError,
3
+ ValidationError,
4
+ callFailed,
5
+ contextOf,
6
+ isDataAppError,
7
+ toScope
8
+ } from "./chunk-SWNVCTT6.js";
7
9
 
8
10
  // src/common/endpoint.ts
9
11
  function abortError() {
@@ -14,23 +16,44 @@ function abortError() {
14
16
  function isAbortError(err) {
15
17
  return err?.name === "AbortError";
16
18
  }
17
- var SDK_ERRORS = /* @__PURE__ */ new Set(["ValidationError", "QueryError", "PermissionError", "TransportError"]);
19
+ var DETAILED_CODES = /* @__PURE__ */ new Set([
20
+ "query_invalid",
21
+ "validation_failed",
22
+ "invalid_request",
23
+ "result_too_large",
24
+ "page_too_large"
25
+ ]);
26
+ function crossing(name, e) {
27
+ const code = typeof e.code === "string" && e.code ? e.code : "call_failed";
28
+ const out = {
29
+ name,
30
+ code,
31
+ scope: toScope(e.scope),
32
+ message: typeof e.message === "string" && e.message ? e.message : "The call failed."
33
+ };
34
+ if (typeof e.status === "number") out.status = e.status;
35
+ if (e.details !== void 0 && DETAILED_CODES.has(code)) out.details = e.details;
36
+ const context = contextOf(e.context);
37
+ if (context) out.context = context;
38
+ if (typeof e.requestId === "string") out.requestId = e.requestId;
39
+ return out;
40
+ }
18
41
  function toBridgeError(err) {
19
- const e = err;
20
- if (e instanceof Error && SDK_ERRORS.has(e.name)) return { name: e.name, message: e.message || "The call failed." };
21
- return { name: "QueryError", message: "The call failed." };
42
+ return isDataAppError(err) ? crossing(err.name, err) : crossing("DataAppError", callFailed());
22
43
  }
23
44
  function fromBridgeError(error) {
24
- switch (error?.name) {
25
- case "PermissionError":
26
- return new PermissionError(error.message);
27
- case "TransportError":
28
- return new TransportError(error.message);
29
- case "ValidationError":
30
- return new ValidationError(error.message);
31
- default:
32
- return new QueryError(error?.message || "The call failed.");
33
- }
45
+ if (!error || typeof error !== "object") return callFailed();
46
+ const e = crossing(error.name, error);
47
+ if (e.name === "ValidationError" && e.code === "declaration_invalid") return new ValidationError(e.message);
48
+ return new DataAppError({
49
+ code: e.code,
50
+ scope: e.scope,
51
+ message: e.message,
52
+ status: e.status,
53
+ details: e.details,
54
+ context: e.context,
55
+ requestId: e.requestId
56
+ });
34
57
  }
35
58
  function createEndpoint(post, handlers) {
36
59
  const pending = /* @__PURE__ */ new Map();
@@ -43,7 +66,9 @@ function createEndpoint(post, handlers) {
43
66
  if (!controller.signal.aborted) post({ type: "anfra:result", id, ok: true, result });
44
67
  }).catch((err) => {
45
68
  if (controller.signal.aborted || isAbortError(err)) return;
46
- post({ type: "anfra:result", id, ok: false, error: toBridgeError(err) });
69
+ const error = toBridgeError(err);
70
+ if (!isDataAppError(err)) console.error(`anfra: '${name}' failed; the other side is told only that the call failed.`, err);
71
+ post({ type: "anfra:result", id, ok: false, error });
47
72
  }).finally(() => {
48
73
  if (inFlight.get(id) === controller) inFlight.delete(id);
49
74
  });
@@ -19,6 +19,7 @@ function checkTarget(value) {
19
19
  if (!Array.isArray(value.fields) || !value.fields.every((field) => typeof field === "string")) return void 0;
20
20
  if (!Array.isArray(value.conditions) || !value.conditions.every(isObject)) return void 0;
21
21
  if (value.expression !== void 0 && typeof value.expression !== "string") return void 0;
22
+ if (value.measure !== void 0 && typeof value.measure !== "string") return void 0;
22
23
  const node = value.node === void 0 ? void 0 : checkNode(value.node);
23
24
  if (value.node !== void 0 && !node) return void 0;
24
25
  return {
@@ -27,6 +28,7 @@ function checkTarget(value) {
27
28
  query: value.query,
28
29
  rows: value.rows,
29
30
  fields: value.fields,
31
+ ...value.measure !== void 0 ? { measure: value.measure } : {},
30
32
  conditions: value.conditions,
31
33
  ...value.expression !== void 0 ? { expression: value.expression } : {},
32
34
  ...node ? { node } : {}
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.16.0";
2
+ var version = "0.18.0";
3
3
 
4
4
  export {
5
5
  version
@@ -118,7 +118,7 @@ function createRequestLog({ limit = 200, previewRows = 20 } = {}) {
118
118
  settle(id, {
119
119
  status: context.signal.aborted ? "aborted" : "error",
120
120
  durationMs: durationMs(),
121
- error: err instanceof Error ? `${err.name}: ${err.message}` : String(err)
121
+ error: describeError(err)
122
122
  });
123
123
  throw err;
124
124
  }
@@ -163,6 +163,11 @@ function attributeRequests(entries, apps) {
163
163
  }
164
164
  return { byQuery, other };
165
165
  }
166
+ function describeError(err) {
167
+ if (!(err instanceof Error)) return String(err);
168
+ const { code } = err;
169
+ return `${typeof code === "string" ? code : err.name}: ${err.message}`;
170
+ }
166
171
 
167
172
  // src/plugins/inspect/state.ts
168
173
  var states = /* @__PURE__ */ new WeakMap();
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  version
3
- } from "./chunk-SKSKC747.js";
3
+ } from "./chunk-B6URV5AO.js";
4
4
 
5
5
  // src/plugins/version.ts
6
6
  var PLUGIN_VERSION = version;
@@ -0,0 +1,161 @@
1
+ import {
2
+ __publicField
3
+ } from "./chunk-PKBMQBKP.js";
4
+
5
+ // src/common/errors.ts
6
+ var GENERIC_CODES = {
7
+ query_invalid: "user",
8
+ query_failed: "user",
9
+ forbidden: "user",
10
+ unauthenticated: "user",
11
+ invalid_request: "client",
12
+ declaration_invalid: "client",
13
+ connection_failed: "server",
14
+ call_failed: "server",
15
+ internal_server_error: "server"
16
+ };
17
+ var DataAppError = class _DataAppError extends Error {
18
+ constructor(init) {
19
+ super(init.message);
20
+ /** What happened: a generic code, or the backend's own. */
21
+ __publicField(this, "code");
22
+ /** Who must act: `user` (the reader's input or state), `client` (the app), `server`. */
23
+ __publicField(this, "scope");
24
+ /** The HTTP status the backend answered, when it answered one. */
25
+ __publicField(this, "status");
26
+ /** Facts to act on, typed by code: a query's diagnostics, the fields at fault, a row limit. */
27
+ __publicField(this, "details");
28
+ /** The steps the failure happened in, outermost first. */
29
+ __publicField(this, "context");
30
+ /** The id of the server request that failed: the line to look for in its log. */
31
+ __publicField(this, "requestId");
32
+ /** The query, control or dataset that caused this. */
33
+ __publicField(this, "entity");
34
+ __publicField(this, "cause");
35
+ this.name = new.target.name;
36
+ this.code = init.code;
37
+ this.scope = init.scope;
38
+ if (init.status !== void 0) this.status = init.status;
39
+ if (init.details !== void 0) this.details = init.details;
40
+ if (init.context !== void 0) this.context = init.context;
41
+ if (init.requestId !== void 0) this.requestId = init.requestId;
42
+ if (init.entity !== void 0) this.entity = init.entity;
43
+ if (init.cause !== void 0) this.cause = init.cause;
44
+ Object.setPrototypeOf(this, new.target.prototype);
45
+ }
46
+ /** This error, naming `entity`: the same failure, said of the query or control it concerns. */
47
+ about(entity) {
48
+ if (this.entity === entity) return this;
49
+ return new _DataAppError({ ...fieldsOf(this), entity });
50
+ }
51
+ };
52
+ var ValidationError = class _ValidationError extends DataAppError {
53
+ constructor(message, entity) {
54
+ super({
55
+ code: "declaration_invalid",
56
+ scope: "client",
57
+ message,
58
+ entity
59
+ });
60
+ }
61
+ about(entity) {
62
+ return this.entity === entity ? this : new _ValidationError(this.message, entity);
63
+ }
64
+ };
65
+ function isDataAppError(err) {
66
+ if (err instanceof DataAppError) return true;
67
+ const e = err;
68
+ return e instanceof Error && (e.name === "DataAppError" || e.name === "ValidationError") && typeof e.code === "string";
69
+ }
70
+ function hasErrorCode(err, code) {
71
+ return isDataAppError(err) && err.code === code;
72
+ }
73
+ function contextOf(context) {
74
+ if (!Array.isArray(context)) return void 0;
75
+ const entries = context.filter((c) => typeof c?.text === "string").map((c) => typeof c.step === "string" ? { step: c.step, text: c.text } : { text: c.text });
76
+ return entries.length ? entries : void 0;
77
+ }
78
+ function invalidRequest(message, entity) {
79
+ return new DataAppError({
80
+ code: "invalid_request",
81
+ scope: "client",
82
+ message,
83
+ entity
84
+ });
85
+ }
86
+ function forbidden(message, entity) {
87
+ return new DataAppError({
88
+ code: "forbidden",
89
+ scope: "user",
90
+ message,
91
+ entity
92
+ });
93
+ }
94
+ function connectionFailed(message, status) {
95
+ return new DataAppError({
96
+ code: "connection_failed",
97
+ scope: "server",
98
+ message,
99
+ status
100
+ });
101
+ }
102
+ function callFailed(cause) {
103
+ return new DataAppError({
104
+ code: "call_failed",
105
+ scope: "server",
106
+ message: "The call failed.",
107
+ cause
108
+ });
109
+ }
110
+ function fromHttpStatus(status, message, options = {}) {
111
+ const { refused = "invalid_request", requestId, entity } = options;
112
+ let code;
113
+ if (status === void 0 || status === 0) code = "connection_failed";
114
+ else if (status === 401) code = "unauthenticated";
115
+ else if (status === 403) code = "forbidden";
116
+ else if (status >= 400 && status < 500) code = refused;
117
+ else code = "internal_server_error";
118
+ return new DataAppError({
119
+ code,
120
+ scope: scopeOf(code, status),
121
+ message,
122
+ status: status || void 0,
123
+ requestId,
124
+ entity
125
+ });
126
+ }
127
+ function scopeOf(code, status) {
128
+ if (code in GENERIC_CODES) return GENERIC_CODES[code];
129
+ return status !== void 0 && status >= 400 && status < 500 ? "user" : "server";
130
+ }
131
+ function toScope(scope) {
132
+ return scope === "user" || scope === "client" || scope === "server" ? scope : "server";
133
+ }
134
+ function fieldsOf(err) {
135
+ return {
136
+ code: err.code,
137
+ scope: err.scope,
138
+ message: err.message,
139
+ status: err.status,
140
+ details: err.details,
141
+ context: err.context,
142
+ requestId: err.requestId,
143
+ entity: err.entity,
144
+ cause: err.cause
145
+ };
146
+ }
147
+
148
+ export {
149
+ GENERIC_CODES,
150
+ DataAppError,
151
+ ValidationError,
152
+ isDataAppError,
153
+ hasErrorCode,
154
+ contextOf,
155
+ invalidRequest,
156
+ forbidden,
157
+ connectionFailed,
158
+ callFailed,
159
+ fromHttpStatus,
160
+ toScope
161
+ };
package/dist/common.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { D as DataAppError, P as PermissionError, Q as QueryError, T as TransportError, V as ValidationError } from './errors-CKvqVaqU.js';
2
- export { A as Aggregation, a as AppDeclaration, b as AppJson, c as ArrowType, B as Backend, d as BackendCondition, e as BackendDateDrill, f as BackendExportRequest, g as BackendFilter, h as BackendLineageRequest, i as BackendQueryRequest, j as BackendQueryResult, k as BackendSort, C as ColumnMeta, l as Condition, m as ConditionValue, n as ControlMappingJson, o as CrossFilterJson, D as DatasetDescriptor, p as DateDrillDeclaration, q as DateGrain, r as DateTransformation, E as EntityKind, s as EntityRef, t as EntityUsage, u as ExecuteOptions, v as ExecuteSummary, w as ExportFormat, x as ExportFormatOptions, y as ExportOptions, z as ExportResult, F as FILTER_AGGREGATIONS, G as FieldLineage, H as FieldSuggestionsRequest, I as FilterAggregation, J as FilterDeclaration, K as FilterValueType, L as InspectedApp, M as InspectedControl, N as InspectedError, O as InspectedQuery, P as InspectedSelection, Q as InspectedStructure, R as LineageCard, S as LineageDiagram, T as LineageNode, U as LineageOptions, V as LineageResult, W as LineageTarget, X as Listener, Y as LocateKind, Z as LocateTarget, _ as MappingJson, $ as Operator, a0 as QueryDebug, a1 as QueryDeclaration, a2 as QueryInput, a3 as QueryResult, a4 as QuerySort, a5 as QueryState, a6 as 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-CKytl8ds.js';
3
- 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-BFLb7dVq.js';
1
+ 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';
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 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';
3
+ 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';
package/dist/common.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import "./chunk-UUKXJSE4.js";
2
2
  import {
3
3
  checkTarget
4
- } from "./chunk-KFD6CHLI.js";
4
+ } from "./chunk-ACKFOANJ.js";
5
5
  import {
6
6
  FILTER_AGGREGATIONS
7
7
  } from "./chunk-XIUFHRZE.js";
@@ -15,24 +15,34 @@ import {
15
15
  } from "./chunk-RXPNL7UR.js";
16
16
  import {
17
17
  DataAppError,
18
- PermissionError,
19
- QueryError,
20
- TransportError,
21
- ValidationError
22
- } from "./chunk-KCTLO3CO.js";
18
+ GENERIC_CODES,
19
+ ValidationError,
20
+ callFailed,
21
+ connectionFailed,
22
+ forbidden,
23
+ fromHttpStatus,
24
+ hasErrorCode,
25
+ invalidRequest,
26
+ isDataAppError
27
+ } from "./chunk-SWNVCTT6.js";
23
28
  import "./chunk-PKBMQBKP.js";
24
29
  export {
25
30
  DEFAULT_TOKENS,
26
31
  DESIGN_TOKENS,
27
32
  DataAppError,
28
33
  FILTER_AGGREGATIONS,
34
+ GENERIC_CODES,
29
35
  PROVISION_ELEMENT_ID,
30
- PermissionError,
31
- QueryError,
32
36
  THEME_TOKENS,
33
- TransportError,
34
37
  ValidationError,
38
+ callFailed,
35
39
  checkTarget,
40
+ connectionFailed,
36
41
  designTheme,
42
+ forbidden,
43
+ fromHttpStatus,
44
+ hasErrorCode,
45
+ invalidRequest,
46
+ isDataAppError,
37
47
  resolveTheme
38
48
  };
@@ -9,10 +9,12 @@ import {
9
9
  import {
10
10
  attributeRequests,
11
11
  stateOf
12
- } from "./chunk-CYZQ7ZTJ.js";
12
+ } from "./chunk-C26OVN2S.js";
13
13
  import {
14
+ badge,
14
15
  collapsible,
15
16
  columnIcon,
17
+ control,
16
18
  drawTab,
17
19
  filterIndicator,
18
20
  flash,
@@ -23,7 +25,7 @@ import {
23
25
  queryTrust,
24
26
  table,
25
27
  trustIndicator
26
- } from "./chunk-F6B3EGFV.js";
28
+ } from "./chunk-32566ZNE.js";
27
29
  import "./chunk-K633QHGO.js";
28
30
  import {
29
31
  entityNodeKey,
@@ -99,7 +101,7 @@ function dataTab(root, context) {
99
101
  setSearch("");
100
102
  }
101
103
  });
102
- const head = h(doc, "div", { class: "search-bar" }, h(doc, "label", { class: "search" }, icon(doc, "search"), input));
104
+ const head = h(doc, "div", { class: "search-bar" }, h(doc, "label", { class: "a-input search" }, icon(doc, "search"), input));
103
105
  const setSearch = (text) => {
104
106
  search = text;
105
107
  input.value = text;
@@ -140,7 +142,7 @@ function dataTab(root, context) {
140
142
  h(doc, "span", { "data-tip": returned.toLocaleString() }, formatAgo(returned)),
141
143
  canExport && h(doc, "button", {
142
144
  type: "button",
143
- class: "row-action",
145
+ ...control("row-action"),
144
146
  "data-tip": "Download CSV",
145
147
  "aria-label": "Download CSV",
146
148
  "data-testid": "download-csv",
@@ -155,14 +157,14 @@ function dataTab(root, context) {
155
157
  const active = [...declaredFilters(declaration?.aql), ...queryInputs(app, name)].filter(isActive);
156
158
  return collapsible(doc, `table:${key}`, [
157
159
  h(doc, "span", { class: "name" }, name),
158
- query.state === "error" && h(doc, "span", { class: "pill error" }, "couldn't load"),
160
+ query.state === "error" && h(doc, "span", { ...badge("error") }, "couldn't load"),
159
161
  h(doc, "span", { class: "spacer" }),
160
162
  filterIndicator(doc, active),
161
163
  trustIndicator(doc, queryTrust(declaration, query)),
162
164
  hasLineage && lineageButton(doc, panel, entityNodeKey(panel.snapshot?.structure?.nodes ?? [], "query", index, name)),
163
165
  h(doc, "button", {
164
166
  type: "button",
165
- class: "row-action",
167
+ ...control("row-action"),
166
168
  "data-tip": "Query",
167
169
  "aria-label": "Query",
168
170
  "data-testid": "show-query",
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  stateOf
3
- } from "./chunk-CYZQ7ZTJ.js";
3
+ } from "./chunk-C26OVN2S.js";
4
4
  import {
5
5
  collapsible,
6
6
  copyIcon,
@@ -12,7 +12,7 @@ import {
12
12
  link,
13
13
  note,
14
14
  popover
15
- } from "./chunk-F6B3EGFV.js";
15
+ } from "./chunk-32566ZNE.js";
16
16
  import {
17
17
  controlMappings,
18
18
  crossFilters,
@@ -0,0 +1,119 @@
1
+ import { al as components } from './types-C_i7V0DA.js';
2
+
3
+ /**
4
+ * A Data App's errors are the API's error document, not classes picked for it
5
+ * (docs/designs/errors.md, "In a Data App"): every failure of a call is a `DataAppError` with the
6
+ * envelope's fields, and the one other class, `ValidationError`, is what a declaration throws. An
7
+ * app branches on `scope` (who must act) and `code` (what happened), and reads `details`.
8
+ */
9
+ /** Who must act: the reader's input or state, the calling program (the app), or the server side. */
10
+ type ErrorScope = 'user' | 'client' | 'server';
11
+ /**
12
+ * The codes every backend uses where they apply, so an app that branches on them runs on any host.
13
+ * Each reuses an anfra or anfra Cloud code where one exists.
14
+ */
15
+ declare const GENERIC_CODES: {
16
+ readonly query_invalid: "user";
17
+ readonly query_failed: "user";
18
+ readonly forbidden: "user";
19
+ readonly unauthenticated: "user";
20
+ readonly invalid_request: "client";
21
+ readonly declaration_invalid: "client";
22
+ readonly connection_failed: "server";
23
+ readonly call_failed: "server";
24
+ readonly internal_server_error: "server";
25
+ };
26
+ type GenericCode = keyof typeof GENERIC_CODES;
27
+ type Schemas = components['schemas'];
28
+ /** Every error body the core API documents, from its OpenAPI schema. */
29
+ type ApiErrorBodies = Schemas[Extract<keyof Schemas, `ErrorBody${string}`>];
30
+ /** The codes the core API documents. */
31
+ type ApiErrorCode = ApiErrorBodies['code'];
32
+ /** A code: a generic one, anfra's own, or another backend's (any string). */
33
+ type ErrorCode = GenericCode | ApiErrorCode | (string & {});
34
+ /** The `details` a code carries, typed for the core API's codes; `unknown` for any other. */
35
+ type ErrorDetails<C extends string> = C extends ApiErrorCode ? Extract<ApiErrorBodies, {
36
+ code: C;
37
+ }> extends {
38
+ details?: infer D;
39
+ } ? D : undefined : unknown;
40
+ /** One step the failure happened in, as the API names it: its text, for a person. */
41
+ interface ErrorContextEntry {
42
+ step?: string;
43
+ text: string;
44
+ }
45
+ interface DataAppErrorInit {
46
+ code: ErrorCode;
47
+ scope: ErrorScope;
48
+ message: string;
49
+ status?: number;
50
+ details?: unknown;
51
+ context?: ErrorContextEntry[];
52
+ requestId?: string;
53
+ entity?: string;
54
+ cause?: unknown;
55
+ }
56
+ declare class DataAppError extends Error {
57
+ /** What happened: a generic code, or the backend's own. */
58
+ readonly code: ErrorCode;
59
+ /** Who must act: `user` (the reader's input or state), `client` (the app), `server`. */
60
+ readonly scope: ErrorScope;
61
+ /** The HTTP status the backend answered, when it answered one. */
62
+ readonly status?: number;
63
+ /** Facts to act on, typed by code: a query's diagnostics, the fields at fault, a row limit. */
64
+ readonly details?: unknown;
65
+ /** The steps the failure happened in, outermost first. */
66
+ readonly context?: ErrorContextEntry[];
67
+ /** The id of the server request that failed: the line to look for in its log. */
68
+ readonly requestId?: string;
69
+ /** The query, control or dataset that caused this. */
70
+ readonly entity?: string;
71
+ readonly cause?: unknown;
72
+ constructor(init: DataAppErrorInit);
73
+ /** This error, naming `entity`: the same failure, said of the query or control it concerns. */
74
+ about(entity: string): DataAppError;
75
+ }
76
+ /**
77
+ * Thrown synchronously at declaration time. This is the primary feedback channel for an agent
78
+ * authoring an app: it has no REPL, so the thrown error is the whole loop. Messages must carry the
79
+ * offending value and, where we can compute one, a suggestion.
80
+ */
81
+ declare class ValidationError extends DataAppError {
82
+ constructor(message: string, entity?: string);
83
+ about(entity: string): DataAppError;
84
+ }
85
+ /**
86
+ * True when `err` is one of the SDK's errors: this copy's (a subclass too), or another copy's, by
87
+ * name and shape. A host may load a plugin built against its own copy of the SDK, whose classes are
88
+ * not this copy's, so `instanceof` alone would miss its errors.
89
+ */
90
+ declare function isDataAppError(err: unknown): err is DataAppError;
91
+ /** True when `err` is a `DataAppError` with `code`, whose `details` are then typed. */
92
+ declare function hasErrorCode<C extends ErrorCode>(err: unknown, code: C): err is DataAppError & {
93
+ code: C;
94
+ details?: ErrorDetails<C>;
95
+ };
96
+ /** A call the app made wrong: a plugin's refusal. */
97
+ declare function invalidRequest(message: string, entity?: string): DataAppError;
98
+ /** Something this reader may not see or do. */
99
+ declare function forbidden(message: string, entity?: string): DataAppError;
100
+ /** The server could not be reached, or its answer was cut or garbled. */
101
+ declare function connectionFailed(message: string, status?: number): DataAppError;
102
+ /** A call that failed for a reason the app is not shown. */
103
+ declare function callFailed(cause?: unknown): DataAppError;
104
+ interface FromHttpStatusOptions {
105
+ /** The code a 4xx other than 401 and 403 is: the refusal of what was called. Default `invalid_request`. */
106
+ refused?: ErrorCode;
107
+ requestId?: string;
108
+ entity?: string;
109
+ }
110
+ /**
111
+ * The error a backend without anfra's error document answers, from what it has: 401 is
112
+ * `unauthenticated`, 403 `forbidden`, any other 4xx the refusal of what was called, 5xx
113
+ * `internal_server_error`, and no status `connection_failed`. The table every such backend uses, so
114
+ * hosts classify alike.
115
+ */
116
+ declare function fromHttpStatus(status: number | undefined, message: string, options?: FromHttpStatusOptions): DataAppError;
117
+
118
+ export { DataAppError as D, GENERIC_CODES as G, ValidationError as V, callFailed as f, connectionFailed as g, forbidden as h, fromHttpStatus as i, hasErrorCode as j, invalidRequest as k, isDataAppError as l };
119
+ export type { ApiErrorCode as A, ErrorCode as E, FromHttpStatusOptions as F, DataAppErrorInit as a, ErrorContextEntry as b, ErrorDetails as c, ErrorScope as d, GenericCode as e };
package/dist/host.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PluginInfo, Theme, ThemeInput, Provision } from './app.js';
2
2
  import { DatasetDescriptor, User } from './app.js';
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-B7SpJLBm.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, p as PanelVerb, S as Snapshot, q as TabContext, r as definePlugin } from './plugin-B7SpJLBm.js';
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-BdLabbah.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, p as PanelVerb, S as Snapshot, q as TabContext, r as definePlugin } from './plugin-BdLabbah.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. */