derive-dashboards 0.1.0 → 0.1.1

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 (301) hide show
  1. package/README.md +4 -3
  2. package/dist/adapter/sql-adapter.mjs +4 -4
  3. package/dist/body.mjs +11 -1
  4. package/dist/cache.d.mts +1 -1
  5. package/dist/cli/check.mjs +14 -1
  6. package/dist/cli/import/dbt-schema.mjs +2 -2
  7. package/dist/cli/import/index.mjs +2 -2
  8. package/dist/core/conformance/cases.d.mts +3 -0
  9. package/dist/core/conformance/cases.mjs +20 -4
  10. package/dist/core/conformance/check.mjs +6 -3
  11. package/dist/core/conformance/drill-cases.mjs +120 -0
  12. package/dist/core/document/view.d.mts +26 -7
  13. package/dist/core/document/view.mjs +42 -11
  14. package/dist/core/engine/index.d.mts +14 -2
  15. package/dist/core/engine/index.mjs +12 -1
  16. package/dist/core/engine/members.mjs +1 -1
  17. package/dist/core/engine/postgres.mjs +1 -1
  18. package/dist/core/engine/record-layout.d.mts +11 -0
  19. package/dist/core/engine/record-layout.mjs +7 -7
  20. package/dist/core/engine/records.d.mts +3 -2
  21. package/dist/core/engine/records.mjs +2 -1
  22. package/dist/core/engine/segmented.mjs +5 -2
  23. package/dist/core/engine/sql-records.mjs +2 -1
  24. package/dist/core/engine/statement.mjs +37 -3
  25. package/dist/core/engine/types.d.mts +3 -0
  26. package/dist/core/engine/version.d.mts +1 -1
  27. package/dist/core/engine/version.mjs +1 -1
  28. package/dist/core/error/codes.d.mts +31 -0
  29. package/dist/core/error/codes.mjs +28 -1
  30. package/dist/core/index.d.mts +9 -5
  31. package/dist/core/index.mjs +5 -3
  32. package/dist/core/model/catalog/check.mjs +1 -1
  33. package/dist/core/model/hints.d.mts +36 -0
  34. package/dist/core/model/member.d.mts +4 -2
  35. package/dist/core/model/member.mjs +16 -3
  36. package/dist/core/model/types.d.mts +8 -6
  37. package/dist/core/model/validate/drill.mjs +70 -0
  38. package/dist/core/model/validate/index.mjs +3 -0
  39. package/dist/core/model/validate/shape.mjs +150 -0
  40. package/dist/core/model/validate/source.mjs +5 -3
  41. package/dist/core/query/alias.mjs +7 -1
  42. package/dist/core/query/drill/compose.d.mts +22 -0
  43. package/dist/core/query/drill/compose.mjs +85 -0
  44. package/dist/core/query/drill/fields.d.mts +21 -0
  45. package/dist/core/query/drill/fields.mjs +91 -0
  46. package/dist/core/query/drill/internal.d.mts +11 -0
  47. package/dist/core/query/drill/items.d.mts +29 -0
  48. package/dist/core/query/drill/items.mjs +98 -0
  49. package/dist/core/query/drill/line.d.mts +31 -0
  50. package/dist/core/query/drill/line.mjs +183 -0
  51. package/dist/core/query/drill/links.d.mts +33 -0
  52. package/dist/core/query/drill/links.mjs +31 -0
  53. package/dist/core/query/drill/operand.mjs +7 -0
  54. package/dist/core/query/drill/scopes.d.mts +22 -0
  55. package/dist/core/query/drill/scopes.mjs +58 -0
  56. package/dist/core/query/drill/selection.d.mts +37 -0
  57. package/dist/core/query/drill/selection.mjs +144 -0
  58. package/dist/core/query/drill/steps.d.mts +14 -0
  59. package/dist/core/query/drill/steps.mjs +35 -0
  60. package/dist/core/query/drill/synthetic-expr.mjs +85 -0
  61. package/dist/core/query/drill/synthetic.d.mts +22 -0
  62. package/dist/core/query/drill/synthetic.mjs +165 -0
  63. package/dist/core/query/drill/time.d.mts +11 -0
  64. package/dist/core/query/drill/time.mjs +71 -0
  65. package/dist/core/query/drill/types.d.mts +155 -0
  66. package/dist/core/query/drill/types.mjs +4 -0
  67. package/dist/core/query/drill/views.d.mts +62 -0
  68. package/dist/core/query/drill/views.mjs +257 -0
  69. package/dist/core/query/segments.d.mts +12 -2
  70. package/dist/core/query/segments.mjs +3 -1
  71. package/dist/core/result/columns.mjs +17 -4
  72. package/dist/core/result/types.d.mts +5 -1
  73. package/dist/core/schema/answer-parts.mjs +117 -0
  74. package/dist/core/schema/answers.d.mts +2108 -128
  75. package/dist/core/schema/answers.mjs +10 -113
  76. package/dist/core/schema/commands.d.mts +2 -2
  77. package/dist/core/schema/document.d.mts +1 -1
  78. package/dist/core/schema/drill-answers.mjs +179 -0
  79. package/dist/core/schema/drill.d.mts +260 -0
  80. package/dist/core/schema/drill.mjs +107 -0
  81. package/dist/core/schema/index.d.mts +4 -2
  82. package/dist/core/schema/index.mjs +4 -2
  83. package/dist/core/schema/picks.d.mts +35 -0
  84. package/dist/core/schema/picks.mjs +23 -0
  85. package/dist/core/schema/query.d.mts +1 -1
  86. package/dist/core/schema/tools.mjs +1 -1
  87. package/dist/core/schema/view.d.mts +0 -35
  88. package/dist/core/schema/view.mjs +19 -24
  89. package/dist/core/store/schema.d.mts +5 -0
  90. package/dist/core/store/schema.mjs +10 -0
  91. package/dist/core/types/api.d.mts +15 -1
  92. package/dist/core/types/api.mjs +1 -1
  93. package/dist/core/types/drill-api.d.mts +210 -0
  94. package/dist/core/types/options.d.mts +21 -0
  95. package/dist/core/types/viewer.d.mts +5 -0
  96. package/dist/cursor-seal.d.mts +8 -0
  97. package/dist/cursor-seal.mjs +98 -0
  98. package/dist/dashboard-id.mjs +1 -1
  99. package/dist/drill-access.mjs +93 -0
  100. package/dist/drill-change.mjs +76 -0
  101. package/dist/drill-crumbs.mjs +113 -0
  102. package/dist/drill-distinct.mjs +130 -0
  103. package/dist/drill-explain.mjs +64 -0
  104. package/dist/drill-identity.mjs +35 -0
  105. package/dist/drill-item-id.mjs +35 -0
  106. package/dist/drill-items.mjs +132 -0
  107. package/dist/drill-open.mjs +169 -0
  108. package/dist/drill-seal.mjs +170 -0
  109. package/dist/drill-secret.mjs +14 -0
  110. package/dist/drill-share.mjs +53 -0
  111. package/dist/drill-summary.mjs +158 -0
  112. package/dist/drill-targets.mjs +53 -0
  113. package/dist/drill-totals.mjs +8 -0
  114. package/dist/drill-views.mjs +175 -0
  115. package/dist/drill.mjs +157 -0
  116. package/dist/editing.mjs +2 -2
  117. package/dist/endpoints/dashboards.mjs +11 -3
  118. package/dist/endpoints/drill.mjs +55 -0
  119. package/dist/endpoints/index.d.mts +233 -2
  120. package/dist/endpoints/index.mjs +5 -1
  121. package/dist/endpoints/query.mjs +26 -4
  122. package/dist/execute.d.mts +19 -1
  123. package/dist/execute.mjs +15 -17
  124. package/dist/index.d.mts +3 -1
  125. package/dist/index.mjs +29 -2
  126. package/dist/mcp/drill.mjs +61 -0
  127. package/dist/mcp/format.mjs +27 -3
  128. package/dist/mcp/index.d.mts +15 -4
  129. package/dist/mcp/index.mjs +13 -7
  130. package/dist/mcp/query.d.mts +7 -2
  131. package/dist/mcp/query.mjs +7 -3
  132. package/dist/node-postgres.d.mts +8 -4
  133. package/dist/node-postgres.mjs +29 -6
  134. package/dist/owner.mjs +3 -3
  135. package/dist/postgres-connection.d.mts +8 -2
  136. package/dist/postgres-connection.mjs +2 -1
  137. package/dist/react/Dashboard.d.mts +10 -5
  138. package/dist/react/Dashboard.mjs +51 -23
  139. package/dist/react/DashboardList.mjs +30 -2
  140. package/dist/react/Discard.mjs +7 -2
  141. package/dist/react/Grid.mjs +12 -5
  142. package/dist/react/Header.mjs +9 -0
  143. package/dist/react/Parts.mjs +6 -2
  144. package/dist/react/ReviewPanel.mjs +13 -2
  145. package/dist/react/RowBody.d.mts +19 -0
  146. package/dist/react/RowBody.mjs +55 -0
  147. package/dist/react/Tile.d.mts +1 -1
  148. package/dist/react/Tile.mjs +54 -30
  149. package/dist/react/builder/state.d.mts +1 -1
  150. package/dist/react/client.d.mts +2 -0
  151. package/dist/react/client.mjs +1 -0
  152. package/dist/react/context.d.mts +15 -1
  153. package/dist/react/context.mjs +19 -4
  154. package/dist/react/drill/Bars.mjs +179 -0
  155. package/dist/react/drill/Controls.mjs +173 -0
  156. package/dist/react/drill/DashboardTile.d.mts +18 -0
  157. package/dist/react/drill/DashboardTile.mjs +107 -0
  158. package/dist/react/drill/DrillPanel.d.mts +31 -0
  159. package/dist/react/drill/DrillPanel.mjs +104 -0
  160. package/dist/react/drill/DrillTabs.mjs +52 -0
  161. package/dist/react/drill/Header.mjs +131 -0
  162. package/dist/react/drill/Items.d.mts +22 -0
  163. package/dist/react/drill/Items.mjs +164 -0
  164. package/dist/react/drill/ItemsFoot.mjs +60 -0
  165. package/dist/react/drill/Notes.mjs +58 -0
  166. package/dist/react/drill/PanelBody.mjs +74 -0
  167. package/dist/react/drill/PanelStates.mjs +37 -0
  168. package/dist/react/drill/board.d.mts +18 -0
  169. package/dist/react/drill/board.mjs +91 -0
  170. package/dist/react/drill/counts.mjs +14 -0
  171. package/dist/react/drill/host.mjs +26 -0
  172. package/dist/react/drill/item-parts.d.mts +5 -0
  173. package/dist/react/drill/item-parts.mjs +76 -0
  174. package/dist/react/drill/item-type.d.mts +26 -0
  175. package/dist/react/drill/item-type.mjs +7 -0
  176. package/dist/react/drill/lazy.d.mts +6 -0
  177. package/dist/react/drill/lazy.mjs +17 -0
  178. package/dist/react/drill/pages.mjs +48 -0
  179. package/dist/react/drill/panel-focus.mjs +51 -0
  180. package/dist/react/drill/props.d.mts +25 -0
  181. package/dist/react/drill/props.mjs +72 -0
  182. package/dist/react/drill/state.d.mts +18 -0
  183. package/dist/react/drill/state.mjs +68 -0
  184. package/dist/react/drill/useDrill.d.mts +46 -0
  185. package/dist/react/drill/useDrill.mjs +194 -0
  186. package/dist/react/drill/words.d.mts +98 -0
  187. package/dist/react/drill/words.mjs +77 -0
  188. package/dist/react/english.mjs +9 -1
  189. package/dist/react/format.d.mts +3 -3
  190. package/dist/react/format.mjs +34 -12
  191. package/dist/react/index.d.mts +27 -4
  192. package/dist/react/index.mjs +10 -3
  193. package/dist/react/messages.d.mts +14 -1
  194. package/dist/react/renderers/index.d.mts +10 -2
  195. package/dist/react/renderers/index.mjs +54 -14
  196. package/dist/react/renderers/list.d.mts +22 -0
  197. package/dist/react/renderers/list.mjs +118 -0
  198. package/dist/react/review-words.mjs +1 -1
  199. package/dist/react/review.mjs +2 -2
  200. package/dist/react/scope.mjs +2 -7
  201. package/dist/react/series.d.mts +37 -0
  202. package/dist/react/series.mjs +95 -0
  203. package/dist/react/theme.css +1823 -1296
  204. package/dist/react/theme.css.d.ts +1 -0
  205. package/dist/react/tile-store.mjs +15 -3
  206. package/dist/react/useBoard.d.mts +5 -0
  207. package/dist/react/useBoard.mjs +4 -1
  208. package/dist/react/useDashboard.d.mts +1 -0
  209. package/dist/react/useDashboard.mjs +2 -1
  210. package/dist/react/useTiles.mjs +50 -15
  211. package/dist/react/view.d.mts +9 -0
  212. package/dist/react/view.mjs +22 -10
  213. package/dist/reading.d.mts +2 -0
  214. package/dist/reading.mjs +9 -1
  215. package/dist/recharts/charts.d.mts +0 -1
  216. package/dist/recharts/charts.mjs +128 -34
  217. package/dist/recharts/index.d.mts +2 -2
  218. package/dist/recharts/index.mjs +2 -2
  219. package/dist/recharts/marks.mjs +83 -0
  220. package/dist/recharts/series.d.mts +2 -22
  221. package/dist/recharts/series.mjs +1 -64
  222. package/dist/records-read.mjs +44 -0
  223. package/dist/store/apply.mjs +5 -5
  224. package/dist/store/commands.mjs +4 -4
  225. package/dist/store/discard.mjs +7 -7
  226. package/dist/store/drafts.mjs +5 -5
  227. package/dist/store/editor.mjs +1 -1
  228. package/dist/store/publish.mjs +12 -12
  229. package/dist/store/reader.mjs +41 -22
  230. package/dist/store/review.mjs +16 -16
  231. package/dist/store/rows.mjs +20 -20
  232. package/dist/store/undo.mjs +3 -3
  233. package/dist/store/unpublished.mjs +4 -4
  234. package/dist/store/versions.mjs +14 -14
  235. package/dist/testing/adapter-suite.mjs +4 -4
  236. package/dist/tiles.mjs +37 -3
  237. package/package.json +8 -10
  238. package/dist/react/Records.d.mts +0 -12
  239. package/dist/react/Records.mjs +0 -97
  240. package/src/adapter/sql-adapter.ts +0 -95
  241. package/src/adapter/statement.ts +0 -185
  242. package/src/authorize.ts +0 -73
  243. package/src/body.ts +0 -169
  244. package/src/bounded.ts +0 -43
  245. package/src/cache.ts +0 -192
  246. package/src/checks.ts +0 -170
  247. package/src/custom-source.ts +0 -59
  248. package/src/dashboard-id.ts +0 -36
  249. package/src/dashboards.ts +0 -132
  250. package/src/editing.ts +0 -148
  251. package/src/endpoints/access.ts +0 -41
  252. package/src/endpoints/dashboards.ts +0 -92
  253. package/src/endpoints/drafts.ts +0 -138
  254. package/src/endpoints/index.ts +0 -21
  255. package/src/endpoints/meta.ts +0 -137
  256. package/src/endpoints/query.ts +0 -86
  257. package/src/endpoints/read.ts +0 -92
  258. package/src/endpoints/review.ts +0 -89
  259. package/src/endpoints/values.ts +0 -62
  260. package/src/endpoints/versions.ts +0 -104
  261. package/src/execute.ts +0 -207
  262. package/src/handler.ts +0 -232
  263. package/src/http.ts +0 -66
  264. package/src/index.ts +0 -163
  265. package/src/introspect.ts +0 -205
  266. package/src/mcp/api.ts +0 -59
  267. package/src/mcp/format.ts +0 -67
  268. package/src/mcp/index.ts +0 -151
  269. package/src/mcp/query.ts +0 -153
  270. package/src/mcp/resolve.ts +0 -114
  271. package/src/node-postgres.ts +0 -81
  272. package/src/owner.ts +0 -36
  273. package/src/postgres-connection.ts +0 -143
  274. package/src/postgres-store.ts +0 -82
  275. package/src/principal.ts +0 -39
  276. package/src/reading.ts +0 -56
  277. package/src/request-rows.ts +0 -23
  278. package/src/request.ts +0 -22
  279. package/src/storage.ts +0 -63
  280. package/src/store/apply.ts +0 -129
  281. package/src/store/commands.ts +0 -75
  282. package/src/store/conflicts.ts +0 -98
  283. package/src/store/create-tables.ts +0 -104
  284. package/src/store/discard.ts +0 -42
  285. package/src/store/drafts.ts +0 -133
  286. package/src/store/editor.ts +0 -28
  287. package/src/store/log.ts +0 -28
  288. package/src/store/publish.ts +0 -199
  289. package/src/store/publisher.ts +0 -21
  290. package/src/store/reader.ts +0 -139
  291. package/src/store/review.ts +0 -239
  292. package/src/store/rows.ts +0 -250
  293. package/src/store/tenant.ts +0 -28
  294. package/src/store/undo.ts +0 -56
  295. package/src/store/unpublished.ts +0 -33
  296. package/src/store/versions.ts +0 -106
  297. package/src/store/writer.ts +0 -19
  298. package/src/testing/adapter-suite.ts +0 -239
  299. package/src/testing/index.ts +0 -2
  300. package/src/tile-doc.ts +0 -46
  301. package/src/tiles.ts +0 -120
@@ -47,6 +47,11 @@ export type Resource = {
47
47
  kind: "member";
48
48
  id: string;
49
49
  } |
50
+ /** The rows of a source as items: a drill's list. Ask yes for anyone who may view the source to keep it on. */
51
+ {
52
+ kind: "records";
53
+ source: string;
54
+ } |
50
55
  /** The viewer's tenant as a whole, asked to create a dashboard; in an app of one tenant, the app. */
51
56
  {
52
57
  kind: "tenant";
@@ -0,0 +1,8 @@
1
+ import { Principal } from "derive-dashboards/core";
2
+ /** The AES key WebCrypto gives, under any runtime's types. */
3
+ type SealKey = Awaited<ReturnType<typeof crypto.subtle.importKey>>;
4
+ /** The key that seals: from `options.secret`, or one made for this process. */
5
+ export declare function cursorKey(secret: string | undefined): Promise<SealKey>;
6
+ /** The key that signs (HMAC-SHA-256): from `options.secret` for its own use, or one for this process. */
7
+ export declare function macKey(secret: string | undefined): Promise<SealKey>;
8
+ export {};
@@ -0,0 +1,98 @@
1
+ import { canonical, principalTenant } from "derive-dashboards/core";
2
+ import { EngineError } from "derive-dashboards/core/engine";
3
+ // src/cursor-seal.ts
4
+ /** 32 bytes from the secret for one use, or random ones for this process when there is none. */
5
+ async function keyBytes(secret, use) {
6
+ if (secret === void 0) return crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32));
7
+ const text = use === "" ? secret : `${use}\u0000${secret}`;
8
+ return new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text)));
9
+ }
10
+ /** The key that seals: from `options.secret`, or one made for this process. */
11
+ async function cursorKey(secret) {
12
+ const raw = await keyBytes(secret, "");
13
+ return crypto.subtle.importKey("raw", raw, "AES-GCM", false, ["encrypt", "decrypt"]);
14
+ }
15
+ /** The key that signs (HMAC-SHA-256): from `options.secret` for its own use, or one for this process. */
16
+ async function macKey(secret) {
17
+ const raw = await keyBytes(secret, "derive-dashboards mac");
18
+ return crypto.subtle.importKey("raw", raw, {
19
+ name: "HMAC",
20
+ hash: "SHA-256"
21
+ }, false, ["sign"]);
22
+ }
23
+ const base64url = (bytes) => btoa(Array.from(bytes, (b) => String.fromCodePoint(b)).join("")).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/u, "");
24
+ const fromBase64url = (text) => Uint8Array.from(atob(text.replaceAll("-", "+").replaceAll("_", "/")), (c) => c.codePointAt(0) ?? 0);
25
+ /** A text's HMAC under the key, as 22 URL-safe characters (128 bits): stable, and not reversible without the key. */
26
+ /**
27
+ * A keyed digest in hex: what a receipt names its query by. Keyed, so a person who can guess the
28
+ * query's hidden parts (an Other step's kept names) cannot test a guess against it offline.
29
+ */
30
+ async function macHex(key, text) {
31
+ const signed = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(text));
32
+ return Array.from(new Uint8Array(signed), (b) => b.toString(16).padStart(2, "0")).join("");
33
+ }
34
+ async function mac(key, text) {
35
+ const signed = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(text));
36
+ return base64url(new Uint8Array(signed).slice(0, 16));
37
+ }
38
+ const boundTo = (b) => new TextEncoder().encode(canonical({
39
+ purpose: b.purpose,
40
+ tenant: principalTenant(b.principal),
41
+ on: b.on
42
+ }));
43
+ /** Sealed texts are padded to a whole number of blocks: a token's length says little of what is in it. */
44
+ const PAD_BLOCK = 256;
45
+ const PAD_MARK = "\0";
46
+ function padded(text) {
47
+ const bytes = new TextEncoder().encode(`${text}${PAD_MARK}`);
48
+ const size = Math.ceil(bytes.length / PAD_BLOCK) * PAD_BLOCK;
49
+ const out = new Uint8Array(size).fill(32);
50
+ out.set(bytes);
51
+ return out;
52
+ }
53
+ /** The text a padded one holds: everything before its last pad mark. */
54
+ function unpadded(text) {
55
+ const at = text.lastIndexOf(PAD_MARK);
56
+ return at === -1 ? text : text.slice(0, at);
57
+ }
58
+ /** A text sealed for one purpose, tenant and subject. */
59
+ async function seal(key, text, binding) {
60
+ const iv = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(12));
61
+ const sealed = await crypto.subtle.encrypt({
62
+ name: "AES-GCM",
63
+ iv,
64
+ additionalData: boundTo(binding)
65
+ }, key, padded(text));
66
+ return `${base64url(iv)}.${base64url(new Uint8Array(sealed))}`;
67
+ }
68
+ /** A sealed text opened, or undefined when it is not one sealed for this purpose, tenant and subject. */
69
+ async function unseal(key, sealed, binding) {
70
+ try {
71
+ const [iv = "", body = ""] = sealed.split(".");
72
+ const opened = await crypto.subtle.decrypt({
73
+ name: "AES-GCM",
74
+ iv: fromBase64url(iv),
75
+ additionalData: boundTo(binding)
76
+ }, key, fromBase64url(body));
77
+ return unpadded(new TextDecoder().decode(opened));
78
+ } catch {
79
+ return;
80
+ }
81
+ }
82
+ function sealCursor(key, cursor, at) {
83
+ return seal(key, cursor, {
84
+ purpose: "cursor",
85
+ principal: at.principal,
86
+ on: at.on
87
+ });
88
+ }
89
+ async function openCursor(key, sealed, at) {
90
+ const opened = await unseal(key, sealed, {
91
+ purpose: "cursor",
92
+ principal: at.principal,
93
+ on: at.on
94
+ });
95
+ if (opened !== void 0) return opened;
96
+ throw new EngineError("CURSOR_INVALID", "The records cursor is not one this view gave, or it has expired: start again from the first page.");
97
+ }
98
+ export { base64url, cursorKey, mac, macHex, macKey, openCursor, seal, sealCursor, unseal };
@@ -19,7 +19,7 @@ const builtInId = (key) => `${BUILT_IN}${key}`;
19
19
  */
20
20
  function expectServedAs(row, ref, id) {
21
21
  if (row === null || "key" in ref) return;
22
- if (row["default_of"] !== null && row["default_of"] !== void 0) throw new HttpError(404, "NOT_FOUND", `There is no dashboard "${id}".`);
22
+ if (row.default_of !== null && row.default_of !== void 0) throw new HttpError(404, "NOT_FOUND", `There is no dashboard "${id}".`);
23
23
  }
24
24
  /** An answer that names a dashboard, naming it by the id the client used. */
25
25
  function servedAs(answer, id) {
@@ -0,0 +1,93 @@
1
+ import { execute } from "./execute.mjs";
2
+ import { HttpError } from "./http.mjs";
3
+ import { queryClosure } from "derive-dashboards/core";
4
+ import { drillOwner, stepMembers } from "derive-dashboards/core/engine";
5
+ // src/drill-access.ts
6
+ /** Which fields this viewer may see in a drill: never a sensitive one (Rules, section 6). */
7
+ const readableFor = (_x) => (_member, def) => def.sensitive !== true;
8
+ /** The clock the engine resolves ranges by, so a drill's window matches the tile's. */
9
+ const clockOf = (x) => ({
10
+ now: x.now,
11
+ calendar: x.calendar,
12
+ quantumSeconds: x.rt.options.cache?.quantum ?? 60
13
+ });
14
+ /** The same execution, running another query. */
15
+ const running = (x, query) => ({
16
+ ...x,
17
+ query
18
+ });
19
+ /** The members a tile showed, which its drill reads freely: its groups, its time when it draws by it, its measures. */
20
+ function disclosed(o) {
21
+ if (o.scope.origin.kind === "query") return /* @__PURE__ */ new Set();
22
+ const q = o.x.query;
23
+ return /* @__PURE__ */ new Set([
24
+ ...(q.dimensions ?? []).map((d) => d.member),
25
+ ...q.time?.grain === void 0 ? [] : [q.time.dimension],
26
+ ...q.measures.map((m) => m.measure)
27
+ ]);
28
+ }
29
+ /** Whether the viewer may read a member on its own: `view` on it, asked once per request. */
30
+ function mayRead(o, member) {
31
+ if (disclosed(o).has(member)) return Promise.resolve(true);
32
+ const asked = o.reads.get(member);
33
+ if (asked !== void 0) return asked;
34
+ const { principal } = o.scope;
35
+ const answer = principal.channel === "user" ? Promise.resolve(o.x.rt.options.access.can(principal.viewer, "view", {
36
+ kind: "member",
37
+ id: member
38
+ })) : Promise.resolve(false);
39
+ o.reads.set(member, answer);
40
+ return answer;
41
+ }
42
+ /** The host's members a query reads, as the host names them. */
43
+ function membersOf(o, query) {
44
+ const closure = queryClosure(o.x.rt.options.model, query);
45
+ return new Set(closure.members.flatMap((m) => drillOwner(m) ?? []));
46
+ }
47
+ /**
48
+ * The members a drill's query reads that its tile's own query did not, with the members the
49
+ * drill uses on purpose (its steps, the field it breaks down or draws by, the columns it lists)
50
+ * even when the tile filtered on them: a filter is not a field the tile showed.
51
+ */
52
+ function addedMembers(o, query, used) {
53
+ const tile = membersOf(o, o.x.query);
54
+ const steps = o.drill.steps.flatMap((s) => stepMembers(s));
55
+ const read = [...membersOf(o, query)].filter((m) => !tile.has(m));
56
+ return [.../* @__PURE__ */ new Set([
57
+ ...read,
58
+ ...steps,
59
+ ...used
60
+ ])];
61
+ }
62
+ /** The first member a drill's query adds that this viewer may not read, if any. */
63
+ async function refusedMember(o, query, used = []) {
64
+ const members = addedMembers(o, query, used);
65
+ const answers = await Promise.all(members.map((m) => mayRead(o, m)));
66
+ return members.find((_m, i) => answers[i] !== true);
67
+ }
68
+ /** Refused unless the viewer may read every member the drill adds to what the tile showed. */
69
+ async function authorize(o, query, used = []) {
70
+ const refused = await refusedMember(o, query, used);
71
+ if (refused !== void 0) throw new HttpError(403, "FORBIDDEN", `You cannot read the member "${refused}".`);
72
+ }
73
+ /** A drill's query, authorized for this viewer and run under the drill's execution. */
74
+ async function drillRead(o, query, used = []) {
75
+ await authorize(o, query, used);
76
+ return execute(running(o.x, query));
77
+ }
78
+ /** The columns of a records read this viewer may see: each a member the tile showed or one they may read. */
79
+ async function readableColumns(o, source, names) {
80
+ const answers = await Promise.all(names.map((n) => mayRead(o, `${source}.${n}`)));
81
+ return names.filter((_n, i) => answers[i] === true);
82
+ }
83
+ /** Whether this viewer may see a source's rows as items: `view` on its records. */
84
+ function mayList(o, source) {
85
+ const { principal } = o.scope;
86
+ if (principal.channel !== "user") return Promise.resolve(false);
87
+ const can = o.x.rt.options.access.can;
88
+ return Promise.resolve(can(principal.viewer, "view", {
89
+ kind: "records",
90
+ source
91
+ }));
92
+ }
93
+ export { clockOf, drillRead, mayList, mayRead, readableColumns, readableFor, running };
@@ -0,0 +1,76 @@
1
+ import { formatExact, isMark, parseExact } from "derive-dashboards/core";
2
+ // src/drill-change.ts
3
+ /** A cell's number as whole units of 10^-scale, or undefined for anything else. */
4
+ function units(cell, scale) {
5
+ if (typeof cell === "number") return Number.isFinite(cell) ? parseExact(plainText(cell), scale) : void 0;
6
+ if (typeof cell === "object" && cell !== null && "v" in cell) return parseExact(cell.v, scale);
7
+ }
8
+ /** A float's shortest decimal text, written out where JavaScript would use an exponent (1e-7). */
9
+ const plainText = (n) => {
10
+ const text = String(n);
11
+ return /e/iu.test(text) ? n.toFixed(Math.min(decimalsOf(text), 100)) : text;
12
+ };
13
+ /** The decimal places a number's text holds, an exponent's included ("1e-7" has 7, "1.25e-3" has 5). */
14
+ function decimalsOf(text) {
15
+ const [mantissa = "", exponent = "0"] = text.toLowerCase().split("e");
16
+ const places = mantissa.includes(".") ? mantissa.split(".")[1]?.length ?? 0 : 0;
17
+ return Math.max(0, places - Number(exponent));
18
+ }
19
+ /** The places a set of cells needs to be added exactly: the most any of them has. */
20
+ const placesOf = (cells) => Math.max(0, ...cells.map((c) => {
21
+ return decimalsOf(typeof c === "object" && c !== null && "v" in c ? c.v : typeof c === "number" ? String(c) : "");
22
+ }));
23
+ /** A sum of units at a scale as a cell like the inputs: a number, or exact text. */
24
+ function cellAt(value, scale, exact) {
25
+ if (!exact) return Number(value) / 10 ** scale;
26
+ return {
27
+ t: scale === 0 ? "int" : "decimal",
28
+ v: formatExact(value, scale)
29
+ };
30
+ }
31
+ const isOther = (row) => row.some((c) => isMark(c) && c.mark === "other");
32
+ const isAll = (row) => row.some((c) => isMark(c) && c.mark === "all");
33
+ /**
34
+ * A Breakdown of the change with Other's own change filled in: its value before is the
35
+ * period's total before less the kept groups' before, exactly, so the listed changes add up to
36
+ * the whole change. Its change and the size of its change follow. Left as it is when a value
37
+ * is missing or not a number (a line that does not add up has no total to subtract from).
38
+ */
39
+ function otherChange(answer) {
40
+ const at = (id) => answer.columns.findIndex((c) => c.id === id);
41
+ const places = {
42
+ before: at("c1"),
43
+ change: at("c2"),
44
+ size: at("c3")
45
+ };
46
+ const total = answer.rows.find((r) => isAll(r));
47
+ const other = answer.rows.findIndex((r) => isOther(r));
48
+ const now = answer.columns.findIndex((c) => c.id.startsWith("m"));
49
+ if (places.before < 0 || total === void 0 || other < 0 || now < 0) return answer;
50
+ const kept = answer.rows.filter((r) => !isAll(r) && !isOther(r));
51
+ const row = answer.rows[other] ?? [];
52
+ const filled = fillOther(row, [
53
+ total[places.before],
54
+ row[now],
55
+ ...kept.map((r) => r[places.before])
56
+ ], places);
57
+ return filled === null ? answer : {
58
+ ...answer,
59
+ rows: answer.rows.map((r, i) => i === other ? filled : r)
60
+ };
61
+ }
62
+ /** Other's row with its value before, change and size of change, from the exact cells; null when one is not a number. */
63
+ function fillOther(row, cells, places) {
64
+ const scale = placesOf(cells);
65
+ const read = cells.map((c) => units(c, scale));
66
+ if (read.some((u) => u === void 0)) return null;
67
+ const [whole = 0n, mine = 0n, ...others] = read.map((u) => u ?? 0n);
68
+ const was = whole - others.reduce((a, b) => a + b, 0n);
69
+ const exact = cells.some((c) => typeof c === "object" && c !== null);
70
+ const filled = [...row];
71
+ filled[places.before] = cellAt(was, scale, exact);
72
+ if (places.change >= 0) filled[places.change] = cellAt(mine - was, scale, exact);
73
+ if (places.size >= 0) filled[places.size] = cellAt(mine >= was ? mine - was : was - mine, scale, exact);
74
+ return filled;
75
+ }
76
+ export { otherChange };
@@ -0,0 +1,113 @@
1
+ import { resultColumns } from "derive-dashboards/core";
2
+ // src/drill-crumbs.ts
3
+ /** A field's label as a column of the tile would read it. */
4
+ function fieldLabel(o, member) {
5
+ return resultColumns(o.x.rt.options.model, {
6
+ ...o.x.query,
7
+ dimensions: [{
8
+ id: "d1",
9
+ member
10
+ }]
11
+ }).find((c) => c.id === "d1")?.label ?? member;
12
+ }
13
+ /** One step as a breadcrumb: its fields and its values; a time point with its grain. */
14
+ function crumbOf(o, step) {
15
+ if ("bucket" in step) {
16
+ const { member, from, grain } = step.bucket;
17
+ return {
18
+ label: fieldLabel(o, member),
19
+ value: from,
20
+ kind: "time",
21
+ ...grain === void 0 ? {} : { grain }
22
+ };
23
+ }
24
+ if ("other" in step) return {
25
+ label: step.other.members.map((m) => fieldLabel(o, m)).join(" · "),
26
+ value: null,
27
+ kind: "other"
28
+ };
29
+ if ("search" in step) return {
30
+ label: fieldLabel(o, step.search.member),
31
+ value: step.search.text,
32
+ kind: "search"
33
+ };
34
+ const [only] = step.group;
35
+ const value = step.group.length === 1 && only !== void 0 ? only.value : step.group.map((g) => String(g.value)).join(" · ");
36
+ return {
37
+ label: step.group.map((g) => fieldLabel(o, g.member)).join(" · "),
38
+ value,
39
+ kind: "group"
40
+ };
41
+ }
42
+ /** One selection as a breadcrumb: its one step, its steps as parts, or a total. */
43
+ function selectionCrumb(o, selection) {
44
+ const previous = selection.previous === true ? { previous: true } : {};
45
+ const parts = selection.steps.map((step) => crumbOf(o, step));
46
+ const [only] = parts;
47
+ if (only === void 0) return {
48
+ label: "",
49
+ value: null,
50
+ kind: "total",
51
+ ...previous
52
+ };
53
+ if (parts.length === 1) return {
54
+ ...only,
55
+ ...previous
56
+ };
57
+ const shown = parts.filter((p) => p.kind !== "search");
58
+ const [head] = shown;
59
+ if (shown.length === 1 && head !== void 0) return {
60
+ ...head,
61
+ parts,
62
+ ...previous
63
+ };
64
+ return {
65
+ label: shown.map((p) => p.label).join(" · "),
66
+ value: null,
67
+ kind: "group",
68
+ parts,
69
+ ...previous
70
+ };
71
+ }
72
+ /** The path as breadcrumbs, one per selection, in order. */
73
+ const crumbs = (o) => o.selections.map((s) => selectionCrumb(o, s));
74
+ /**
75
+ * What of a receipt a viewer who did not draw the link may read: a fixed list, so a field added
76
+ * to receipts later is held back until it is listed here. The filter (it states the drill's
77
+ * steps, an Other step's kept names among them) and the query's hash are never on it.
78
+ */
79
+ const OPENER_RECEIPT = /* @__PURE__ */ new Set([
80
+ "provider",
81
+ "trust",
82
+ "sources",
83
+ "answeredBy",
84
+ "cache",
85
+ "range",
86
+ "calendar",
87
+ "dataThrough",
88
+ "computedAt",
89
+ "consistency",
90
+ "durationMs",
91
+ "rowsReturned",
92
+ "coverage",
93
+ "warnings"
94
+ ]);
95
+ /** A value with every receipt in it cut to what the opener may read. */
96
+ function openerReceipts(value) {
97
+ if (Array.isArray(value)) return value.map((v) => openerReceipts(v));
98
+ if (typeof value !== "object" || value === null) return value;
99
+ return Object.fromEntries(Object.entries(value).map(([k, v]) => {
100
+ if (k !== "receipt" || typeof v !== "object" || v === null) return [k, openerReceipts(v)];
101
+ return [k, Object.fromEntries(Object.entries(v).filter(([key]) => OPENER_RECEIPT.has(key)))];
102
+ }));
103
+ }
104
+ /**
105
+ * A drill's answer as a viewer who did not draw its link may read it: a receipt's filter states
106
+ * the drill's steps, and an Other step names the groups it leaves out, which may be groups this
107
+ * viewer's row rules hide. So for them each receipt carries only the fields listed as safe; the
108
+ * rows and counts are already theirs.
109
+ */
110
+ function forOpener(answer, foreign) {
111
+ return foreign ? openerReceipts(answer) : answer;
112
+ }
113
+ export { crumbs, forOpener };
@@ -0,0 +1,130 @@
1
+ import { openCursor, sealCursor } from "./cursor-seal.mjs";
2
+ import { drillRead, running } from "./drill-access.mjs";
3
+ import { fingerprint } from "./drill-identity.mjs";
4
+ import { itemId, keyHidden, linked } from "./drill-item-id.mjs";
5
+ import { mayLink, visibleTargets } from "./drill-targets.mjs";
6
+ import { bind } from "./execute.mjs";
7
+ import { canonical, isMark, recordColumns, resolveDimension } from "derive-dashboards/core";
8
+ import { EngineError, distinctQuery } from "derive-dashboards/core/engine";
9
+ /** A result cell as a value: a mark has none. */
10
+ const cellOf = (cell) => cell === void 0 || isMark(cell) ? null : cell;
11
+ /**
12
+ * The source and key a distinct value names, when its column is a join's own key to one row of
13
+ * another source the viewer may list: the value then links to that row's page.
14
+ */
15
+ function joinedKey(o, field) {
16
+ const { model } = o.x.rt.options;
17
+ const { source } = o.x.query;
18
+ const dim = resolveDimension(model, source, field)?.dimension;
19
+ const column = dim !== void 0 && "column" in dim ? dim.column : void 0;
20
+ const join = Object.values(model.sources[source]?.joins ?? {}).find((j) => j.relationship !== "one_to_many" && j.on.length === 1 && j.on[0]?.[0] === column);
21
+ return join === void 0 ? join : keyOfTarget(model, join);
22
+ }
23
+ /** The join's target and its key, when the join reads exactly that one-column key and it is shown. */
24
+ function keyOfTarget(model, join) {
25
+ const name = join.on[0]?.[1];
26
+ const target = model.sources[join.to];
27
+ return name !== void 0 && target?.key.length === 1 && target.key[0] === name && !keyHidden(model, join.to) ? {
28
+ source: join.to,
29
+ name
30
+ } : void 0;
31
+ }
32
+ /**
33
+ * What a distinct list's cursor is bound to, as a records cursor is: the population and field,
34
+ * the lock and required filters it read under, and who asked (their access fingerprint), so a
35
+ * cursor never continues another viewer's list or one read under another policy.
36
+ */
37
+ async function distinctAt(o, rows, field) {
38
+ const bound = bind(running(o.x, rows));
39
+ const by = await fingerprint(o.x.rt, o.scope.principal);
40
+ return {
41
+ principal: o.scope.principal,
42
+ on: {
43
+ distinct: rows,
44
+ field,
45
+ lock: bound.lock,
46
+ required: bound.required,
47
+ by
48
+ }
49
+ };
50
+ }
51
+ /** How far a distinct list has read, from its sealed cursor. */
52
+ async function distinctPage(o, rows, field, after) {
53
+ if (after === void 0) return 0;
54
+ const at = await distinctAt(o, rows, field);
55
+ const skip = Number(await openCursor(await o.x.rt.cursorKey, after, at));
56
+ if (!Number.isSafeInteger(skip) || skip < 0) throw new EngineError("CURSOR_INVALID", "The list's cursor is not one this view gave.");
57
+ return skip;
58
+ }
59
+ /** One distinct value as an item: a link to its own row when the field is a join's key. */
60
+ async function distinctItem(o, at, row) {
61
+ const value = cellOf(row[0]);
62
+ const values = {
63
+ [at.field]: value,
64
+ count: cellOf(row[1])
65
+ };
66
+ const { target } = at;
67
+ if (target === void 0) return {
68
+ source: at.source,
69
+ id: JSON.stringify(value),
70
+ values
71
+ };
72
+ const plain = typeof value === "object" ? null : value;
73
+ return linked(o, {
74
+ source: target.source,
75
+ id: await itemId(o, target.source, [plain], false),
76
+ key: { [target.name]: plain },
77
+ values
78
+ });
79
+ }
80
+ /**
81
+ * The row each distinct value links to: only when the field is a join's key, the viewer may view
82
+ * that source and list its rows, and their own row rules let them see that row (one read for the page).
83
+ */
84
+ async function linkedTargets(o, field, shown) {
85
+ const joined = joinedKey(o, field);
86
+ const target = joined !== void 0 && await mayLink(o, joined.source) ? joined : void 0;
87
+ const plain = shown.flatMap((row) => {
88
+ const v = cellOf(row[0]);
89
+ return typeof v === "object" || v === null ? [] : [v];
90
+ });
91
+ const visible = target === void 0 ? /* @__PURE__ */ new Set() : await visibleTargets(o, target, plain);
92
+ return (row) => visible.has(canonical(cellOf(row[0]))) ? target : void 0;
93
+ }
94
+ /** A distinct count's items, one page: its distinct values (never "not set"), each with its row count, a value linked to its own page when it is a join's key. */
95
+ async function distinctItems(o, rows, field, page) {
96
+ const { model } = o.x.rt.options;
97
+ const source = rows.source;
98
+ const take = page.limit ?? 50;
99
+ const skip = await distinctPage(o, rows, field, page.after);
100
+ const answer = await drillRead(o, distinctQuery(rows, field, {
101
+ skip,
102
+ take
103
+ }), [field]);
104
+ const [column] = recordColumns(model, source, [field]);
105
+ const columns = [...column === void 0 ? [] : [column], {
106
+ member: "count",
107
+ label: "Rows",
108
+ type: "int"
109
+ }];
110
+ const read = answer.rows.filter((row) => !row.some((c) => isMark(c)));
111
+ const shown = read.slice(skip, skip + take);
112
+ const targetOf = await linkedTargets(o, field, shown);
113
+ const items = await Promise.all(shown.map((row) => distinctItem(o, {
114
+ source,
115
+ field,
116
+ target: targetOf(row)
117
+ }, row)));
118
+ const next = read.length > skip + take ? await sealCursor(await o.x.rt.cursorKey, String(skip + take), await distinctAt(o, rows, field)) : void 0;
119
+ return {
120
+ by: "items",
121
+ source,
122
+ columns,
123
+ items,
124
+ value: field,
125
+ sort: "count",
126
+ ...next === void 0 ? {} : { next },
127
+ ...answer.status === "truncated" ? { truncated: true } : {}
128
+ };
129
+ }
130
+ export { distinctItems };
@@ -0,0 +1,64 @@
1
+ import { pathDigest } from "./drill-identity.mjs";
2
+ import { sealSelection } from "./drill-seal.mjs";
3
+ import { resultColumns } from "derive-dashboards/core";
4
+ import { formulaParts, scopeSteps } from "derive-dashboards/core/engine";
5
+ // src/drill-explain.ts
6
+ /** A path of one sealed selection for a scope's steps, bound to this execution at the root. */
7
+ async function scopePath(o, selection) {
8
+ if (selection.steps.length === 0 && selection.previous !== true) return [];
9
+ const parent = await pathDigest([]);
10
+ return [await sealSelection(o.scope, {
11
+ ...selection,
12
+ exec: o.pinned.id,
13
+ parent
14
+ })];
15
+ }
16
+ /**
17
+ * The drill that opens one part of a formula on its own, in its own scope: the same path for a
18
+ * part of the row, the whole tile for a total, the drill's time point for a bucket, the drill's
19
+ * steps in the period before for a previous value.
20
+ */
21
+ async function operandState(o, entry, scope) {
22
+ const base = {
23
+ origin: o.scope.origin,
24
+ entry,
25
+ execution: o.execution,
26
+ view: { by: "breakdown" }
27
+ };
28
+ if (scope === "row") return {
29
+ ...base,
30
+ path: o.path
31
+ };
32
+ const steps = scopeSteps(o.drill.steps, scope);
33
+ const previous = scope === "previous" ? { previous: true } : {};
34
+ return {
35
+ ...base,
36
+ path: await scopePath(o, {
37
+ steps,
38
+ ...previous
39
+ })
40
+ };
41
+ }
42
+ /**
43
+ * A formula's parts (Rules, section 2): each line it reads in the scope it reads it, with its
44
+ * own value from the summary's reads (none read again), and the drill that opens it on its own.
45
+ */
46
+ async function explanationView(o, summed, entry) {
47
+ const parts = formulaParts(o.x.query, entry);
48
+ const columns = resultColumns(o.x.rt.options.model, o.x.query);
49
+ return {
50
+ by: "explanation",
51
+ operands: await Promise.all(parts.map(async (p) => {
52
+ const value = summed.scoped[p.scope]?.get(p.entry) ?? null;
53
+ return {
54
+ entry: p.entry,
55
+ scope: p.scope,
56
+ label: columns.find((c) => c.id === p.entry)?.label ?? p.entry,
57
+ value,
58
+ state: await operandState(o, p.entry, p.scope),
59
+ can: { ok: true }
60
+ };
61
+ }))
62
+ };
63
+ }
64
+ export { explanationView };
@@ -0,0 +1,35 @@
1
+ import { sha256 } from "./cache.mjs";
2
+ import { mac } from "./cursor-seal.mjs";
3
+ import { canonical, principalTenant } from "derive-dashboards/core";
4
+ // src/drill-identity.ts
5
+ /**
6
+ * The fingerprint of a viewer's access: an HMAC under the server's key of who they are and
7
+ * what decides what they may see (tenant, id, roles, attributes, the person an agent acts for).
8
+ * Two requests with the same fingerprint see the same rows; it reveals nothing about either.
9
+ */
10
+ async function fingerprint(rt, principal) {
11
+ return mac(await rt.macKey, canonical(accessOf(principal)));
12
+ }
13
+ /** What decides what a principal may see, in a stable shape. */
14
+ function accessOf(principal) {
15
+ const base = {
16
+ tenant: principalTenant(principal),
17
+ channel: principal.channel
18
+ };
19
+ return principal.channel === "user" ? {
20
+ ...base,
21
+ ...viewerAccess(principal.viewer)
22
+ } : base;
23
+ }
24
+ /** A signed-in viewer's part of their access: who they are, their roles and attributes. */
25
+ const viewerAccess = (viewer) => ({
26
+ id: viewer.id,
27
+ agent: viewer.agent?.for ?? null,
28
+ roles: [...viewer.roles ?? []].toSorted(),
29
+ attributes: viewer.attributes ?? {}
30
+ });
31
+ /** The tile's composed query as drawn, as a digest: a draft or a version that changed it is stale. */
32
+ const revisionOf = async (query) => (await sha256(canonical(query))).slice(0, 32);
33
+ /** A path's steps as a digest: what a selection drawn under them is bound to. */
34
+ const pathDigest = async (steps) => (await sha256(canonical(steps))).slice(0, 32);
35
+ export { fingerprint, pathDigest, revisionOf };
@@ -0,0 +1,35 @@
1
+ import { mac } from "./cursor-seal.mjs";
2
+ import { canonical, itemLink, principalTenant } from "derive-dashboards/core";
3
+ // src/drill-item-id.ts
4
+ /**
5
+ * Whether items of a source carry their key: not when the model hides it (`records.key: "hide"`),
6
+ * nor when a sensitive or hidden field reads one of its columns. A key never shows as a column.
7
+ */
8
+ function keyHidden(model, source) {
9
+ const def = model.sources[source];
10
+ if (def === void 0 || def.records?.key === "hide") return true;
11
+ const kept = Object.entries(def.dimensions).filter(([name, d]) => !name.startsWith("dd_") && (d.sensitive === true || d.hidden === true)).map(([, d]) => d);
12
+ return def.key.some((column) => kept.some((d) => "column" in d && d.column === column));
13
+ }
14
+ /**
15
+ * An item's stable id: its key's value (its values as JSON, for a key of more than one column),
16
+ * or, when the key is hidden, an HMAC of it under the server's key, bound to the tenant: stable,
17
+ * opaque, and not reversible by enumerating keys.
18
+ */
19
+ async function itemId(o, source, key, hide) {
20
+ if (hide) return mac(await o.x.rt.macKey, canonical({
21
+ tenant: principalTenant(o.scope.principal),
22
+ source,
23
+ key: [...key]
24
+ }));
25
+ return key.length === 1 ? String(key[0]) : JSON.stringify(key);
26
+ }
27
+ /** An item with its link from the server's `itemLinks`; a hidden key never builds one. */
28
+ function linked(o, item) {
29
+ const link = item.key === void 0 ? void 0 : itemLink(o.x.rt.options.itemLinks, item);
30
+ return link === void 0 ? item : {
31
+ ...item,
32
+ link
33
+ };
34
+ }
35
+ export { itemId, keyHidden, linked };