@holistics/anfra-sdk 0.20.0 → 0.22.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 +5 -0
  2. package/dist/api.d.ts +11 -8
  3. package/dist/api.js +45 -22
  4. package/dist/app.d.ts +5 -5
  5. package/dist/app.js +5 -4
  6. package/dist/{bootstrap-DHU2haC5.d.ts → bootstrap-fGoj2ap1.d.ts} +324 -27
  7. package/dist/build.d.ts +2 -2
  8. package/dist/{chunk-32566ZNE.js → chunk-2TTGSNHA.js} +1 -1
  9. package/dist/{chunk-H52PO7MP.js → chunk-33HI2ODM.js} +25 -0
  10. package/dist/chunk-4UEESYHH.js +32 -0
  11. package/dist/{chunk-KKSOTHP4.js → chunk-7GQZU5FL.js} +1 -1
  12. package/dist/{chunk-4TXKXLWK.js → chunk-7I2HXY72.js} +1 -1
  13. package/dist/{chunk-DITKCHFQ.js → chunk-CLXZMA5D.js} +1 -1
  14. package/dist/{chunk-GBXK7F2V.js → chunk-D7DIJRAC.js} +14 -1
  15. package/dist/{chunk-ACKFOANJ.js → chunk-DWQUIHUX.js} +4 -1
  16. package/dist/{chunk-FTTVLHNN.js → chunk-EOFPMSND.js} +1 -1
  17. package/dist/{chunk-SXKJQU7A.js → chunk-GPBYPSWK.js} +22 -36
  18. package/dist/{chunk-EIPHDMZ7.js → chunk-UWRQXPPG.js} +69 -24
  19. package/dist/{chunk-T5T76SAR.js → chunk-YPGMBSOZ.js} +1209 -274
  20. package/dist/common.d.ts +3 -3
  21. package/dist/common.js +1 -1
  22. package/dist/{data-ESPFZ5IM.js → data-SZDYO55C.js} +7 -5
  23. package/dist/{declaration-RYRBX7PH.js → declaration-GYV6OUR3.js} +5 -3
  24. package/dist/{errors-189T_Mnc.d.ts → errors-kH5eHvNO.d.ts} +1 -1
  25. package/dist/host.d.ts +2 -2
  26. package/dist/host.js +31 -8
  27. package/dist/{overview-AWPXJACF.js → overview-CD6NY3VQ.js} +28 -13
  28. package/dist/{plugin-rRd-zHGt.d.ts → plugin-DG2NDTCT.d.ts} +7 -2
  29. package/dist/plugins.d.ts +1 -7
  30. package/dist/plugins.js +53 -17
  31. package/dist/{queries-FWMX7H5Z.js → queries-BWKWZQMG.js} +70 -17
  32. package/dist/{structure-VFRJFC4C.js → structure-JO4YZHKZ.js} +5 -3
  33. package/dist/{tab-XL2HS5W4.js → tab-QPHE7YUQ.js} +3 -3
  34. package/dist/testing.d.ts +2 -1
  35. package/dist/testing.js +8 -7
  36. package/dist/{menu-Cam-hOdJ.d.ts → theme-FQ_1b569.d.ts} +72 -55
  37. package/dist/{types-N0V9n38H.d.ts → types-BE767W6G.d.ts} +879 -129
  38. package/package.json +1 -1
@@ -19,6 +19,17 @@ function formatAgo(value, now = Date.now()) {
19
19
  if (seconds < 86400) return `${Math.floor(seconds / 3600)}h ago`;
20
20
  return `${Math.floor(seconds / 86400)}d ago`;
21
21
  }
22
+ function formatIn(value, now = Date.now()) {
23
+ if (!value) return "";
24
+ const time = (value instanceof Date ? value : new Date(value)).getTime();
25
+ if (Number.isNaN(time)) return String(value);
26
+ const seconds = Math.floor((time - now) / 1e3);
27
+ if (seconds < 0) return "expired";
28
+ if (seconds < 60) return "in < 1m";
29
+ if (seconds < 3600) return `in ${Math.floor(seconds / 60)}m`;
30
+ if (seconds < 86400) return `in ${Math.floor(seconds / 3600)}h`;
31
+ return `in ${Math.floor(seconds / 86400)}d`;
32
+ }
22
33
  var plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
23
34
  var entityKey = (kind, app, name) => `${kind}:${app}/${name}`;
24
35
  function entityAttribute(kind, app, name) {
@@ -81,10 +92,22 @@ var STRUCTURE_TAB = "inspect.structure";
81
92
  var DECLARATION_TAB = "inspect.declaration";
82
93
  var LINEAGE_TAB = "lineage.lineage";
83
94
 
95
+ // src/plugins/inspect/model/entities.ts
96
+ function hasEntity(apps, kind, app, name) {
97
+ return Object.hasOwn((kind === "query" ? apps[app]?.queries : apps[app]?.controls) ?? {}, name);
98
+ }
99
+ var ENTITY_KEY = /^(query|control):(\d+)\/(.+)$/;
100
+ function entityGone(key, apps) {
101
+ const match = key ? ENTITY_KEY.exec(key) : null;
102
+ if (!match) return false;
103
+ return !hasEntity(apps, match[1], Number(match[2]), match[3]);
104
+ }
105
+
84
106
  export {
85
107
  formatCondition,
86
108
  formatTime,
87
109
  formatAgo,
110
+ formatIn,
88
111
  plural,
89
112
  entityKey,
90
113
  entityAttribute,
@@ -96,6 +119,8 @@ export {
96
119
  blockNodeKey,
97
120
  entityNodeKey,
98
121
  dedent,
122
+ hasEntity,
123
+ entityGone,
99
124
  OVERVIEW_TAB,
100
125
  DATA_TAB,
101
126
  QUERIES_TAB,
@@ -0,0 +1,32 @@
1
+ // src/common/shortcut.ts
2
+ var MODIFIERS = ["ctrl", "alt", "shift", "meta"];
3
+ function normalizeShortcut(shortcut) {
4
+ if (typeof shortcut !== "string") return void 0;
5
+ const parts = shortcut.split("+").map((part) => part.trim().toLowerCase()).filter(Boolean);
6
+ const key = parts.pop();
7
+ const isModifier = (part) => MODIFIERS.includes(part);
8
+ if (!key || isModifier(key) || !parts.every(isModifier)) return void 0;
9
+ return [...MODIFIERS.filter((modifier) => parts.includes(modifier)), key].join("+");
10
+ }
11
+ function isTyping(target) {
12
+ const element = target;
13
+ if (!element || typeof element.tagName !== "string") return false;
14
+ return element.isContentEditable === true || ["INPUT", "TEXTAREA", "SELECT"].includes(element.tagName.toUpperCase());
15
+ }
16
+ function eventShortcut(event) {
17
+ const code = typeof event.code === "string" ? event.code : "";
18
+ const key = /^Key[A-Z]$/.test(code) ? code.slice(3).toLowerCase() : /^Digit[0-9]$/.test(code) ? code.slice(5) : (event.key ?? "").toLowerCase();
19
+ return [
20
+ event.ctrlKey && "ctrl",
21
+ event.altKey && "alt",
22
+ event.shiftKey && "shift",
23
+ event.metaKey && "meta",
24
+ key
25
+ ].filter(Boolean).join("+");
26
+ }
27
+
28
+ export {
29
+ normalizeShortcut,
30
+ isTyping,
31
+ eventShortcut
32
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  version
3
- } from "./chunk-FTTVLHNN.js";
3
+ } from "./chunk-EOFPMSND.js";
4
4
 
5
5
  // src/plugins/version.ts
6
6
  var PLUGIN_VERSION = version;
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  formatCondition,
6
6
  handleFor
7
- } from "./chunk-H52PO7MP.js";
7
+ } from "./chunk-33HI2ODM.js";
8
8
 
9
9
  // src/plugins/inspect/model/changes.ts
10
10
  function originalCondition(app, name, kind) {
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-K633QHGO.js";
5
5
  import {
6
6
  formatCondition
7
- } from "./chunk-H52PO7MP.js";
7
+ } from "./chunk-33HI2ODM.js";
8
8
 
9
9
  // src/plugins/inspect/model/inputs.ts
10
10
  var MANUAL_TYPES = {
@@ -3,8 +3,9 @@ import {
3
3
  crossFilters
4
4
  } from "./chunk-K633QHGO.js";
5
5
  import {
6
+ entityGone,
6
7
  formatCondition
7
- } from "./chunk-H52PO7MP.js";
8
+ } from "./chunk-33HI2ODM.js";
8
9
 
9
10
  // src/plugins/lineage/model.ts
10
11
  var LINEAGE_KINDS = ["control", "block", "query", "metric", "dimension", "dataset", "model", "table"];
@@ -376,6 +377,7 @@ function createState() {
376
377
  }
377
378
  });
378
379
  let trace;
380
+ let following = false;
379
381
  const state = {
380
382
  get trace() {
381
383
  return trace;
@@ -403,6 +405,17 @@ function createState() {
403
405
  );
404
406
  },
405
407
  changed,
408
+ follow(panel) {
409
+ if (following) return;
410
+ following = true;
411
+ panel.subscribe(() => {
412
+ if (panel.snapshot) state.prune(panel.snapshot.apps);
413
+ });
414
+ },
415
+ prune(apps) {
416
+ if (entityGone(state.view.focus, apps)) state.view.focus = void 0;
417
+ if (entityGone(state.view.selected, apps)) state.view.selected = void 0;
418
+ },
406
419
  subscribe(listener) {
407
420
  listeners.add(listener);
408
421
  return () => {
@@ -1,6 +1,7 @@
1
1
  // src/common/menu.ts
2
2
  var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3
3
  var isRect = (value) => isObject(value) && ["x", "y", "width", "height"].every((key) => typeof value[key] === "number");
4
+ var isPoint = (value) => isObject(value) && Number.isFinite(value.x) && Number.isFinite(value.y);
4
5
  var isNode = (value) => isObject(value) && typeof value.key === "string" && typeof value.kind === "string" && Array.isArray(value.problems) && Array.isArray(value.children);
5
6
  function checkNode(value) {
6
7
  if (!isObject(value) || value.kind !== "node" || !isNode(value.node) || !Array.isArray(value.ancestors) || !value.ancestors.every(isNode) || !isRect(value.rect)) return void 0;
@@ -22,6 +23,7 @@ function checkTarget(value) {
22
23
  if (value.measure !== void 0 && typeof value.measure !== "string") return void 0;
23
24
  const node = value.node === void 0 ? void 0 : checkNode(value.node);
24
25
  if (value.node !== void 0 && !node) return void 0;
26
+ if (value.at !== void 0 && !isPoint(value.at)) return void 0;
25
27
  return {
26
28
  kind: "rows",
27
29
  app: value.app,
@@ -31,7 +33,8 @@ function checkTarget(value) {
31
33
  ...value.measure !== void 0 ? { measure: value.measure } : {},
32
34
  conditions: value.conditions,
33
35
  ...value.expression !== void 0 ? { expression: value.expression } : {},
34
- ...node ? { node } : {}
36
+ ...node ? { node } : {},
37
+ ...value.at !== void 0 ? { at: { x: value.at.x, y: value.at.y } } : {}
35
38
  };
36
39
  }
37
40
 
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.20.0";
2
+ var version = "0.22.0";
3
3
 
4
4
  export {
5
5
  version
@@ -16,6 +16,14 @@ function abortError() {
16
16
  function isAbortError(err) {
17
17
  return err?.name === "AbortError";
18
18
  }
19
+ function copyStamp(stamp) {
20
+ return {
21
+ app: stamp.app,
22
+ query: stamp.query,
23
+ ...stamp.id !== void 0 && { id: stamp.id },
24
+ ...stamp.variant !== void 0 && { variant: stamp.variant }
25
+ };
26
+ }
19
27
  var DETAILED_CODES = /* @__PURE__ */ new Set([
20
28
  "query_invalid",
21
29
  "validation_failed",
@@ -59,10 +67,10 @@ function createEndpoint(post, handlers) {
59
67
  const pending = /* @__PURE__ */ new Map();
60
68
  const inFlight = /* @__PURE__ */ new Map();
61
69
  let nextId = 1;
62
- const answer = (id, name, request) => {
70
+ const answer = (id, name, request, stamp) => {
63
71
  const controller = new AbortController();
64
72
  inFlight.set(id, controller);
65
- Promise.resolve().then(() => handlers.answer(name, request, controller.signal)).then((result) => {
73
+ Promise.resolve().then(() => handlers.answer(name, request, controller.signal, stamp)).then((result) => {
66
74
  if (!controller.signal.aborted) post({ type: "anfra:result", id, ok: true, result });
67
75
  }).catch((err) => {
68
76
  if (controller.signal.aborted || isAbortError(err)) return;
@@ -83,7 +91,7 @@ function createEndpoint(post, handlers) {
83
91
  });
84
92
  };
85
93
  return {
86
- call(name, request, signal) {
94
+ call(name, request, signal, stamp) {
87
95
  return new Promise((resolve, reject) => {
88
96
  if (signal?.aborted) {
89
97
  reject(abortError());
@@ -96,7 +104,13 @@ function createEndpoint(post, handlers) {
96
104
  post({ type: "anfra:cancel", id });
97
105
  reject(abortError());
98
106
  }, { once: true });
99
- post({ type: "anfra:call", id, name, request });
107
+ post({
108
+ type: "anfra:call",
109
+ id,
110
+ name,
111
+ request,
112
+ ...stamp ? { stamp: copyStamp(stamp) } : {}
113
+ });
100
114
  });
101
115
  },
102
116
  emit(name, payload) {
@@ -105,7 +119,7 @@ function createEndpoint(post, handlers) {
105
119
  receive(message) {
106
120
  switch (message?.type) {
107
121
  case "anfra:call":
108
- answer(message.id, message.name, message.request);
122
+ answer(message.id, message.name, message.request, message.stamp);
109
123
  return true;
110
124
  case "anfra:result": {
111
125
  const call = pending.get(message.id);
@@ -135,36 +149,8 @@ function createEndpoint(post, handlers) {
135
149
  };
136
150
  }
137
151
 
138
- // src/common/shortcut.ts
139
- var MODIFIERS = ["ctrl", "alt", "shift", "meta"];
140
- function normalizeShortcut(shortcut) {
141
- if (typeof shortcut !== "string") return void 0;
142
- const parts = shortcut.split("+").map((part) => part.trim().toLowerCase()).filter(Boolean);
143
- const key = parts.pop();
144
- const isModifier = (part) => MODIFIERS.includes(part);
145
- if (!key || isModifier(key) || !parts.every(isModifier)) return void 0;
146
- return [...MODIFIERS.filter((modifier) => parts.includes(modifier)), key].join("+");
147
- }
148
- function isTyping(target) {
149
- const element = target;
150
- if (!element || typeof element.tagName !== "string") return false;
151
- return element.isContentEditable === true || ["INPUT", "TEXTAREA", "SELECT"].includes(element.tagName.toUpperCase());
152
- }
153
- function eventShortcut(event) {
154
- const code = typeof event.code === "string" ? event.code : "";
155
- const key = /^Key[A-Z]$/.test(code) ? code.slice(3).toLowerCase() : /^Digit[0-9]$/.test(code) ? code.slice(5) : (event.key ?? "").toLowerCase();
156
- return [
157
- event.ctrlKey && "ctrl",
158
- event.altKey && "alt",
159
- event.shiftKey && "shift",
160
- event.metaKey && "meta",
161
- key
162
- ].filter(Boolean).join("+");
163
- }
164
-
165
152
  export {
166
- createEndpoint,
167
- normalizeShortcut,
168
- isTyping,
169
- eventShortcut
153
+ abortError,
154
+ copyStamp,
155
+ createEndpoint
170
156
  };
@@ -1,9 +1,14 @@
1
+ import {
2
+ copyStamp
3
+ } from "./chunk-GPBYPSWK.js";
1
4
  import {
2
5
  DATA_TAB,
3
6
  DECLARATION_TAB,
4
7
  QUERIES_TAB,
5
- STRUCTURE_TAB
6
- } from "./chunk-H52PO7MP.js";
8
+ STRUCTURE_TAB,
9
+ entityGone,
10
+ hasEntity
11
+ } from "./chunk-33HI2ODM.js";
7
12
 
8
13
  // src/plugins/inspect/model/requests.ts
9
14
  function describe(call, request) {
@@ -14,10 +19,8 @@ function describe(call, request) {
14
19
  dataset: r.dataset,
15
20
  aql: r.aql,
16
21
  input: r.input,
17
- page: r.page,
18
- pageSize: r.pageSize,
19
- timezone: r.timezone,
20
- bustCache: r.bustCache
22
+ bustCache: r.bustCache,
23
+ minCachedAt: r.minCachedAt
21
24
  };
22
25
  }
23
26
  case "core.fieldSuggestions": {
@@ -30,7 +33,7 @@ function describe(call, request) {
30
33
  dataset: r.dataset,
31
34
  aql: r.aql,
32
35
  input: r.input,
33
- timezone: r.timezone,
36
+ minCachedAt: r.minCachedAt,
34
37
  format: r.format,
35
38
  formatOptions: r.formatOptions,
36
39
  filename: r.filename
@@ -52,6 +55,7 @@ function summarize(call, result, previewRows) {
52
55
  const r = result;
53
56
  return {
54
57
  fromCache: r.debug?.fromCache,
58
+ cache: r.debug?.cache,
55
59
  numRows: r.meta?.numRows ?? r.values.length,
56
60
  columns: r.columns.map((column) => column.name),
57
61
  preview: r.values.slice(0, previewRows)
@@ -59,8 +63,10 @@ function summarize(call, result, previewRows) {
59
63
  }
60
64
  case "core.fieldSuggestions":
61
65
  return { numRows: result.length };
62
- case "export.query":
63
- return { numRows: result.rowCount };
66
+ case "export.query": {
67
+ const r = result;
68
+ return { numRows: r.rowCount, cache: r.cache };
69
+ }
64
70
  case "lineage.trace":
65
71
  return { numRows: result.results.length };
66
72
  default:
@@ -104,6 +110,7 @@ function createRequestLog({ limit = 200, previewRows = 20 } = {}) {
104
110
  ...details,
105
111
  id,
106
112
  call: context.name,
113
+ ...context.stamp && { stamp: copyStamp(context.stamp) },
107
114
  caller: callerOf(context),
108
115
  // A copy: the host keeps adding the middleware after this one.
109
116
  ...context.trace.length > 1 && { trace: context.trace.slice(0, -1) },
@@ -140,28 +147,44 @@ function createRequestLog({ limit = 200, previewRows = 20 } = {}) {
140
147
  }
141
148
  };
142
149
  }
143
- function queriesOf(entry, apps) {
144
- if (entry.call !== "core.submitQuery" && entry.call !== "export.query") return [];
145
- return apps.flatMap(
146
- (app, index) => Object.entries(app.declaration.queries).filter(([, q]) => q.dataset === entry.dataset && q.aql === entry.aql).map(([name]) => ({ app: index, name }))
147
- );
150
+ function queryOf(entry) {
151
+ if (!entry.stamp) return void 0;
152
+ const { app, query, id } = entry.stamp;
153
+ return { app, name: query, ...id !== void 0 && { id } };
154
+ }
155
+ function isCurrent(ref, apps) {
156
+ const queries = apps[ref.app]?.queries ?? {};
157
+ if (!Object.hasOwn(queries, ref.name)) return false;
158
+ const { id } = queries[ref.name];
159
+ return ref.id === void 0 || id === void 0 || ref.id === id;
148
160
  }
149
161
  function attributeRequests(entries, apps) {
150
162
  const byQuery = /* @__PURE__ */ new Map();
151
163
  const other = [];
164
+ const removed = [];
165
+ const removedByKey = /* @__PURE__ */ new Map();
152
166
  for (let i = entries.length - 1; i >= 0; i--) {
153
167
  const entry = entries[i];
154
- const refs = entry.aql && entry.dataset ? queriesOf({ ...entry, dataset: entry.dataset, aql: entry.aql }, apps) : [];
155
- if (refs.length === 0) other.push(entry);
156
- for (const ref of refs) {
157
- const key = `${ref.app}/${ref.name}`;
158
- const item = { entry, shared: refs.length > 1 };
159
- const list = byQuery.get(key);
160
- if (list) list.push(item);
161
- else byQuery.set(key, [item]);
168
+ const ref = queryOf(entry);
169
+ if (!ref) {
170
+ other.push(entry);
171
+ continue;
172
+ }
173
+ const key = `${ref.app}/${ref.name}`;
174
+ if (isCurrent(ref, apps)) {
175
+ byQuery.set(key, [...byQuery.get(key) ?? [], { entry }]);
176
+ continue;
177
+ }
178
+ const gone = removedByKey.get(key);
179
+ if (gone) {
180
+ gone.requests.push({ entry });
181
+ continue;
162
182
  }
183
+ const query = { app: ref.app, name: ref.name, requests: [{ entry }] };
184
+ removedByKey.set(key, query);
185
+ removed.push(query);
163
186
  }
164
- return { byQuery, other };
187
+ return { byQuery, other, removed };
165
188
  }
166
189
  function describeError(err) {
167
190
  if (!(err instanceof Error)) return String(err);
@@ -194,6 +217,7 @@ function createState() {
194
217
  }
195
218
  });
196
219
  let nonce = 0;
220
+ let following = false;
197
221
  const errors = [];
198
222
  const lines = [];
199
223
  const state = {
@@ -248,6 +272,26 @@ function createState() {
248
272
  }
249
273
  changed();
250
274
  },
275
+ follow(panel) {
276
+ if (following) return;
277
+ following = true;
278
+ panel.subscribe(() => {
279
+ if (panel.snapshot) state.prune(panel.snapshot.apps);
280
+ });
281
+ },
282
+ prune(apps) {
283
+ for (const key of state.queries.open) {
284
+ if (entityGone(key, apps)) state.queries.open.delete(key);
285
+ }
286
+ for (const key of state.data.open) {
287
+ const slash = key.indexOf("/");
288
+ if (!hasEntity(apps, "query", Number(key.slice(0, slash)), key.slice(slash + 1))) state.data.open.delete(key);
289
+ }
290
+ const target = state.revealed?.target;
291
+ if (target && "entity" in target && !hasEntity(apps, target.entity, target.app, target.name)) {
292
+ state.revealed = void 0;
293
+ }
294
+ },
251
295
  subscribe(listener) {
252
296
  listeners.add(listener);
253
297
  return () => {
@@ -260,7 +304,8 @@ function createState() {
260
304
  }
261
305
 
262
306
  export {
263
- queriesOf,
307
+ queryOf,
308
+ isCurrent,
264
309
  attributeRequests,
265
310
  stateOf,
266
311
  dropState