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
@@ -13,13 +13,13 @@ function undo(db, a) {
13
13
  const { row } = await openDraft(tx, a);
14
14
  expectRevision(row, a.expectedRevision);
15
15
  const base = baseDoc(row);
16
- const kept = await keptCommands(tx, row["id"]);
16
+ const kept = await keptCommands(tx, row.id);
17
17
  if (kept.length === 0) throw new HttpError(409, "NOTHING_TO_UNDO", "The draft has no edits left to undo.");
18
18
  const last = Math.max(...kept.map((k) => k.revision));
19
19
  const remaining = kept.filter((k) => k.revision !== last);
20
20
  const outcome = reduceAll(base, remaining.map((k) => k.body));
21
21
  if (!outcome.ok) throw new HttpError(409, "EDIT_REFUSED", outcome.issue.message, { issues: [outcome.issue] });
22
- const revision = Number(row["revision"]) + 1;
22
+ const revision = Number(row.revision) + 1;
23
23
  const set = {
24
24
  spec: outcome.doc,
25
25
  revision,
@@ -31,7 +31,7 @@ function undo(db, a) {
31
31
  table: "dd_dashboard_draft_command",
32
32
  where: [{
33
33
  field: "draft_id",
34
- value: row["id"]
34
+ value: row.id
35
35
  }, {
36
36
  field: "revision",
37
37
  value: last
@@ -33,13 +33,13 @@ async function unpublished(db, a) {
33
33
  }],
34
34
  limit: 100
35
35
  });
36
- const rows = await Promise.all(drafts.map((d) => dashboardRow(db, a.tenant, { id: String(d["dashboard_id"]) })));
36
+ const rows = await Promise.all(drafts.map((d) => dashboardRow(db, a.tenant, { id: String(d.dashboard_id) })));
37
37
  return drafts.flatMap((d, i) => {
38
38
  const row = rows[i];
39
- if (row === null || row === void 0 || row["current_version"] !== null) return [];
40
- if (row["default_of"] !== null) return [];
39
+ if (row === null || row === void 0 || row.current_version !== null) return [];
40
+ if (row.default_of !== null) return [];
41
41
  return [{
42
- dashboardId: String(row["id"]),
42
+ dashboardId: String(row.id),
43
43
  title: draftDoc(d).meta.title
44
44
  }];
45
45
  });
@@ -16,12 +16,12 @@ const optional = (value) => value === null || value === void 0 ? void 0 : Number
16
16
  */
17
17
  async function versions(db, a) {
18
18
  const row = await existing(db, a.tenant, a.id);
19
- if (row["current_version"] === null) throw new HttpError(404, "NOT_FOUND", `There is no dashboard "${a.id}".`);
19
+ if (row.current_version === null) throw new HttpError(404, "NOT_FOUND", `There is no dashboard "${a.id}".`);
20
20
  return (await db.findMany({
21
21
  table: "dd_dashboard_version",
22
22
  where: [{
23
23
  field: "dashboard_id",
24
- value: row["id"]
24
+ value: row.id
25
25
  }, ...a.before === void 0 ? [] : [{
26
26
  field: "n",
27
27
  op: "lt",
@@ -33,16 +33,16 @@ async function versions(db, a) {
33
33
  }],
34
34
  limit: Math.min(a.limit ?? PAGE, PAGE)
35
35
  })).map((v) => {
36
- const basedOn = optional(v["based_on"]);
37
- const restoredFrom = optional(v["restored_from"]);
38
- const kind = v["author_kind"] === "agent" ? "agent" : "user";
36
+ const basedOn = optional(v.based_on);
37
+ const restoredFrom = optional(v.restored_from);
38
+ const kind = v.author_kind === "agent" ? "agent" : "user";
39
39
  return {
40
- version: Number(v["n"]),
40
+ version: Number(v.n),
41
41
  author: {
42
- id: String(v["author_id"]),
42
+ id: String(v.author_id),
43
43
  kind
44
44
  },
45
- createdAt: String(v["created_at"]),
45
+ createdAt: String(v.created_at),
46
46
  ...basedOn === void 0 ? {} : { basedOn },
47
47
  ...restoredFrom === void 0 ? {} : { restoredFrom }
48
48
  };
@@ -55,16 +55,16 @@ async function versions(db, a) {
55
55
  function restore(db, a) {
56
56
  return inTransaction(db, async (tx) => {
57
57
  const row = await existing(tx, a.tenant, a.id);
58
- const done = await earlier(tx, row["id"], a.requestId, a.author);
58
+ const done = await earlier(tx, row.id, a.requestId, a.author);
59
59
  if (done !== null) return {
60
60
  dashboardId: a.id,
61
- version: Number(done["n"])
61
+ version: Number(done.n)
62
62
  };
63
63
  const old = await tx.findOne({
64
64
  table: "dd_dashboard_version",
65
65
  where: [{
66
66
  field: "dashboard_id",
67
- value: row["id"]
67
+ value: row.id
68
68
  }, {
69
69
  field: "n",
70
70
  value: a.version
@@ -74,16 +74,16 @@ function restore(db, a) {
74
74
  const head = await headDoc(tx, row);
75
75
  if (head.version !== a.expectedHead) throw new HttpError(409, "VERSION_CONFLICT", "The dashboard changed. Reload its history.");
76
76
  if (head.version === a.version) throw new HttpError(409, "VERSION_CONFLICT", `Version ${a.version} is already current.`);
77
- const doc = documentOf(old["spec"], `version ${a.version} of "${a.id}"`);
77
+ const doc = documentOf(old.spec, `version ${a.version} of "${a.id}"`);
78
78
  await insertVersion(tx, {
79
79
  ...a,
80
- dashboardId: row["id"],
80
+ dashboardId: row.id,
81
81
  n: head.version + 1,
82
82
  doc,
83
83
  basedOn: head.version,
84
84
  restoredFrom: a.version
85
85
  });
86
- await advanceHead(tx, row["id"], head.version, doc);
86
+ await advanceHead(tx, row.id, head.version, doc);
87
87
  return {
88
88
  dashboardId: a.id,
89
89
  version: head.version + 1
@@ -119,7 +119,7 @@ function rowCases(get) {
119
119
  limit: 1,
120
120
  offset: 1
121
121
  });
122
- expect(ids.map((r) => r["id"])).toEqual(["d1"]);
122
+ expect(ids.map((r) => r.id)).toEqual(["d1"]);
123
123
  expect(await get().count({
124
124
  table: "dd_dashboard",
125
125
  where: [{
@@ -181,9 +181,9 @@ function batchCases(get) {
181
181
  }]
182
182
  });
183
183
  expect(read.map((r) => [
184
- r["command_id"],
185
- r["body"],
186
- r["seq"]
184
+ r.command_id,
185
+ r.body,
186
+ r.seq
187
187
  ])).toEqual(rows.map((r) => [
188
188
  r.command_id,
189
189
  r.body,
package/dist/tiles.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { execute } from "./execute.mjs";
1
+ import { issueDrill } from "./drill-seal.mjs";
2
+ import { execute, wire } from "./execute.mjs";
2
3
  import { HttpError } from "./http.mjs";
3
4
  import { calendarOf } from "./request.mjs";
4
5
  import { composeTile } from "derive-dashboards/core";
@@ -27,11 +28,44 @@ function tileExecution(ctx, tile) {
27
28
  dashboardId: ctx.dashboardId
28
29
  };
29
30
  }
30
- /** One tile by reference: composed from the document, planned under the viewer's access, run. */
31
+ /** Where a drill into one of these tiles starts. */
32
+ function originOf(ctx, tile, document) {
33
+ return {
34
+ kind: "dashboard",
35
+ dashboardId: ctx.dashboardId,
36
+ widgetId: tile.widgetId,
37
+ ...tile.query === void 0 ? {} : { query: tile.query },
38
+ picks: ctx.picks,
39
+ ...document === void 0 ? {} : { document }
40
+ };
41
+ }
42
+ /**
43
+ * One tile by reference: composed from the document, planned under the viewer's access, run,
44
+ * with what a click on each of its rows drills into.
45
+ */
31
46
  async function runTile(ctx, tile) {
47
+ const x = tileExecution(ctx, tile);
48
+ const answer = await execute(x);
49
+ const { document } = ctx;
50
+ if (document === "merged") return {
51
+ widgetId: tile.widgetId,
52
+ ...wire(answer)
53
+ };
54
+ const scope = {
55
+ rt: ctx.rt,
56
+ principal: ctx.principal,
57
+ origin: originOf(ctx, tile, document)
58
+ };
59
+ const version = document !== void 0 && "version" in document ? document.version : ctx.version;
60
+ const drill = await issueDrill(scope, answer, {
61
+ query: x.query,
62
+ now: x.now,
63
+ ...version === void 0 ? {} : { version }
64
+ });
32
65
  return {
33
66
  widgetId: tile.widgetId,
34
- ...await execute(tileExecution(ctx, tile))
67
+ ...wire(answer),
68
+ ...drill === void 0 ? {} : { drill }
35
69
  };
36
70
  }
37
71
  /** An error a client can act on, as a line; anything else ends the stream. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "derive-dashboards",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Open-source embedded dashboards for your product: the server, the engine, React components, charts and the CLI, in one package.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -13,26 +13,21 @@
13
13
  "**/*.css"
14
14
  ],
15
15
  "files": [
16
- "dist",
17
- "src",
18
- "!src/**/*.test.ts"
16
+ "dist"
19
17
  ],
20
18
  "main": "./dist/index.mjs",
21
19
  "module": "./dist/index.mjs",
22
20
  "types": "./dist/index.d.mts",
23
21
  "exports": {
24
22
  ".": {
25
- "dev-source": "./src/index.ts",
26
23
  "types": "./dist/index.d.mts",
27
24
  "default": "./dist/index.mjs"
28
25
  },
29
26
  "./testing": {
30
- "dev-source": "./src/testing/index.ts",
31
27
  "types": "./dist/testing/index.d.mts",
32
28
  "default": "./dist/testing/index.mjs"
33
29
  },
34
30
  "./mcp": {
35
- "dev-source": "./src/mcp/index.ts",
36
31
  "types": "./dist/mcp/index.d.mts",
37
32
  "default": "./dist/mcp/index.mjs"
38
33
  },
@@ -60,7 +55,10 @@
60
55
  "types": "./dist/react/index.d.mts",
61
56
  "default": "./dist/react/index.mjs"
62
57
  },
63
- "./react/theme.css": "./dist/react/theme.css",
58
+ "./react/theme.css": {
59
+ "types": "./dist/react/theme.css.d.ts",
60
+ "default": "./dist/react/theme.css"
61
+ },
64
62
  "./recharts": {
65
63
  "types": "./dist/recharts/index.d.mts",
66
64
  "default": "./dist/recharts/index.mjs"
@@ -91,7 +89,7 @@
91
89
  "peerDependencies": {
92
90
  "react": "^19.0.0",
93
91
  "recharts": "^3.0.0",
94
- "vitest": "^5.0.0"
92
+ "vitest": "^4.0.0 || ^5.0.0"
95
93
  },
96
94
  "peerDependenciesMeta": {
97
95
  "react": {
@@ -108,7 +106,7 @@
108
106
  "derive-dashboards": "./dist/cli/bin.mjs"
109
107
  },
110
108
  "engines": {
111
- "node": ">=20"
109
+ "node": ">=22.18"
112
110
  },
113
111
  "keywords": [
114
112
  "dashboards",
@@ -1,12 +0,0 @@
1
- import { Widget } from "derive-dashboards/core";
2
- type Props = {
3
- widgetId: string;
4
- widget: Widget;
5
- onClose: () => void;
6
- };
7
- /**
8
- * The rows behind a tile, in a modal dialog: the same tenant, policy, lock and filters as the
9
- * tile, a page at a time. Escape or Close closes it.
10
- */
11
- export declare function RecordsPanel({ widgetId, widget, onClose }: Props): import("react").JSX.Element;
12
- export {};
@@ -1,97 +0,0 @@
1
- import { useDashboards } from "./context.mjs";
2
- import { formatCell } from "./format.mjs";
3
- import { useDashboardScope } from "./scope.mjs";
4
- import { useEffect, useRef } from "react";
5
- import { jsx, jsxs } from "react/jsx-runtime";
6
- import useSWRInfinite from "swr/infinite";
7
- // src/Records.tsx
8
- const PAGE = 50;
9
- /**
10
- * Pages of the rows behind a tile, fetched as the viewer asks for more: each after the last row
11
- * of the page before (its `next` cursor), so a deep page costs what the first does.
12
- */
13
- function usePages(widgetId) {
14
- const { client } = useDashboards();
15
- const { dashboardId, picks, draft } = useDashboardScope();
16
- return useSWRInfinite((index, previous) => index > 0 && previous?.next === void 0 ? null : [
17
- "dd-records",
18
- dashboardId,
19
- widgetId,
20
- picks,
21
- previous?.next ?? null,
22
- draft
23
- ], ([, , , , after]) => client.records({
24
- dashboardId,
25
- widgetId,
26
- picks,
27
- ...after === null ? {} : { after },
28
- limit: PAGE,
29
- ...draft === void 0 ? {} : { draft }
30
- }));
31
- }
32
- function RowsTable({ page, rows }) {
33
- const format = useDashboards();
34
- if (rows.length === 0) return /* @__PURE__ */ jsx("p", {
35
- className: "dd-tile-state",
36
- children: format.messages.noRows
37
- });
38
- return /* @__PURE__ */ jsx("div", {
39
- className: "dd-records-scroll",
40
- children: /* @__PURE__ */ jsxs("table", {
41
- className: "dd-table",
42
- children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: page.columns.map((c) => /* @__PURE__ */ jsx("th", {
43
- scope: "col",
44
- children: c.label
45
- }, c.member)) }) }), /* @__PURE__ */ jsx("tbody", { children: rows.map((row, i) => /* @__PURE__ */ jsx("tr", { children: row.map((cell, j) => /* @__PURE__ */ jsx("td", { children: formatCell(cell, page.columns[j], format) }, page.columns[j]?.member ?? j)) }, i)) })]
46
- })
47
- });
48
- }
49
- /**
50
- * The rows behind a tile, in a modal dialog: the same tenant, policy, lock and filters as the
51
- * tile, a page at a time. Escape or Close closes it.
52
- */
53
- function RecordsPanel({ widgetId, widget, onClose }) {
54
- const dialog = useRef(null);
55
- const pages = usePages(widgetId);
56
- const { messages } = useDashboards();
57
- useEffect(() => {
58
- dialog.current?.showModal();
59
- }, []);
60
- const first = pages.data?.[0];
61
- const more = pages.data?.at(-1)?.next !== void 0;
62
- return /* @__PURE__ */ jsxs("dialog", {
63
- ref: dialog,
64
- className: "dd-records",
65
- "aria-label": messages.rowsBehind(widget.title),
66
- onClose,
67
- children: [
68
- /* @__PURE__ */ jsxs("header", {
69
- className: "dd-records-header",
70
- children: [/* @__PURE__ */ jsx("h3", { children: widget.title }), /* @__PURE__ */ jsx("button", {
71
- type: "button",
72
- onClick: () => dialog.current?.close(),
73
- children: messages.close
74
- })]
75
- }),
76
- pages.error === void 0 ? null : /* @__PURE__ */ jsx("p", {
77
- role: "alert",
78
- className: "dd-tile-error",
79
- children: messages.rowsFailed
80
- }),
81
- first === void 0 ? /* @__PURE__ */ jsx("p", {
82
- "aria-busy": "true",
83
- children: messages.loading
84
- }) : /* @__PURE__ */ jsx(RowsTable, {
85
- page: first,
86
- rows: (pages.data ?? []).flatMap((p) => p.rows)
87
- }),
88
- more ? /* @__PURE__ */ jsx("button", {
89
- type: "button",
90
- className: "dd-records-more",
91
- onClick: () => void pages.setSize(pages.size + 1),
92
- children: messages.showMore
93
- }) : null
94
- ]
95
- });
96
- }
97
- export { RecordsPanel };
@@ -1,95 +0,0 @@
1
- import {
2
- CATALOG,
3
- type DashAdapter,
4
- type Row,
5
- type StoreDialect,
6
- type TableName,
7
- } from "@derive-to/dashboards-core";
8
- import {
9
- count,
10
- decodeRow,
11
- insert,
12
- insertAll,
13
- remove,
14
- type Statement,
15
- select,
16
- update,
17
- } from "./statement";
18
-
19
- /** What a database store supplies: how to run a statement, a transaction and DDL. */
20
- export type SqlRunner = {
21
- readonly dialect: StoreDialect;
22
- /** Rows as objects keyed by column name. */
23
- run(statement: Statement): Promise<Row[]>;
24
- /** Runs `fn` in one transaction with rollback, on a connection nothing else uses meanwhile. */
25
- transaction<T>(fn: (runner: SqlRunner) => Promise<T>): Promise<T>;
26
- execute(ddl: string): Promise<void>;
27
- };
28
-
29
- /** Postgres's codes for a unique violation and a failed serializable or deadlocked transaction. */
30
- const UNIQUE = new Set(["23505", "SQLITE_CONSTRAINT_UNIQUE", "SQLITE_CONSTRAINT_PRIMARYKEY"]);
31
- const SERIALIZATION = new Set(["40001", "40P01", "SQLITE_BUSY"]);
32
-
33
- /** A catalog name, which a driver returns as text. */
34
- const text = (value: unknown): string => (typeof value === "string" ? value : "");
35
-
36
- function codeOf(error: unknown): string | undefined {
37
- if (typeof error !== "object" || error === null) return undefined;
38
- if ("code" in error && typeof error.code === "string") return error.code;
39
- return "cause" in error ? codeOf(error.cause) : undefined;
40
- }
41
-
42
- /**
43
- * The store adapter over any SQL database: the library's reads and writes on its own tables as
44
- * parameterized statements. A database's store only says how to run a statement, a transaction,
45
- * and DDL.
46
- */
47
- export function sqlAdapter(id: string, runner: SqlRunner): DashAdapter {
48
- return adapterOver(id, runner);
49
- }
50
-
51
- function adapterOver(id: string, runner: SqlRunner): DashAdapter {
52
- const { dialect } = runner;
53
- const rows = async (table: TableName, statement: Statement) =>
54
- (await runner.run(statement)).map((row) => decodeRow(table, row));
55
- return {
56
- id,
57
- async createMany({ table, rows: data }) {
58
- if (data.length > 0) await runner.run(insertAll(dialect, table, data));
59
- },
60
- async create({ table, data }) {
61
- await runner.run(insert(dialect, table, data));
62
- },
63
- async findOne({ table, where }) {
64
- const [first] = await rows(table, select(dialect, { table, where, limit: 1 }));
65
- return first ?? null;
66
- },
67
- findMany: (a) => rows(a.table, select(dialect, a)),
68
- async updateMany({ table, where, set }) {
69
- return (await runner.run(update(dialect, table, where, set))).length;
70
- },
71
- async deleteMany({ table, where }) {
72
- return (await runner.run(remove(dialect, table, where))).length;
73
- },
74
- async count({ table, where }) {
75
- const [row] = await runner.run(count(dialect, table, where ?? []));
76
- return Number(row?.["n"] ?? 0);
77
- },
78
- transaction: (fn) => runner.transaction((tx) => fn(adapterOver(id, tx))),
79
- classifyError(error) {
80
- const code = codeOf(error) ?? "";
81
- if (UNIQUE.has(code)) return "unique";
82
- return SERIALIZATION.has(code) ? "serialization" : "other";
83
- },
84
- schema: {
85
- dialect,
86
- execute: (ddl) => runner.execute(ddl),
87
- columns: async () =>
88
- (await runner.run({ strings: [CATALOG[dialect]], values: [] })).map((row) => ({
89
- table: text(row["table"]),
90
- column: text(row["column"]),
91
- ...(row["schema"] === undefined ? {} : { schema: text(row["schema"]) }),
92
- })),
93
- },
94
- };
95
- }
@@ -1,185 +0,0 @@
1
- import {
2
- type FieldType,
3
- type Row,
4
- type StoreDialect,
5
- TABLES,
6
- type TableName,
7
- type Where,
8
- } from "@derive-to/dashboards-core";
9
-
10
- /**
11
- * A statement: the text around the values, and the values, which are always parameters. Table
12
- * and column names come only from `TABLES` and are checked against it. Updates and deletes
13
- * return one row per row they changed, so the count needs nothing from the driver.
14
- */
15
- export type Statement = { strings: readonly string[]; values: readonly unknown[] };
16
-
17
- /** Builds a statement piece by piece: text is appended, values become parameters. */
18
- class Builder {
19
- readonly #strings: string[] = [""];
20
- readonly #values: unknown[] = [];
21
- text(part: string): this {
22
- this.#strings[this.#strings.length - 1] += part;
23
- return this;
24
- }
25
- value(v: unknown): this {
26
- this.#values.push(v);
27
- this.#strings.push("");
28
- return this;
29
- }
30
- build(): Statement {
31
- return { strings: [...this.#strings], values: [...this.#values] };
32
- }
33
- }
34
-
35
- /** The table a statement is about, and the dialect it is written in. */
36
- type On = { dialect: StoreDialect; table: TableName };
37
-
38
- const quote = (name: string) => `"${name.replaceAll('"', '""')}"`;
39
-
40
- function typeOf(table: TableName, field: string): FieldType | undefined {
41
- const fields: Record<string, { type: FieldType }> = TABLES[table].fields;
42
- return fields[field]?.type;
43
- }
44
-
45
- /** A column of the table, quoted; any other name is refused before it reaches SQL text. */
46
- function column(on: On, field: string): string {
47
- if (typeOf(on.table, field) === undefined)
48
- throw new Error(`"${on.table}" has no field "${field}".`);
49
- return quote(field);
50
- }
51
-
52
- /** A value as the column stores it: JSON as text, cast by the statement on Postgres. */
53
- function param(b: Builder, on: On, field: string, value: unknown): Builder {
54
- const type = typeOf(on.table, field);
55
- if (value === null || value === undefined) return b.value(null);
56
- if (type === "boolean") return b.value(value === true);
57
- if (type !== "json") return b.value(value);
58
- const text = JSON.stringify(value);
59
- return on.dialect === "postgres" ? b.text("CAST(").value(text).text(" AS jsonb)") : b.value(text);
60
- }
61
-
62
- const OPS = { eq: "=", ne: "<>", lt: "<", lte: "<=", gt: ">", gte: ">=" } as const;
63
-
64
- function inList(b: Builder, on: On, c: Where): void {
65
- const list: readonly unknown[] = Array.isArray(c.value) ? c.value : [];
66
- if (list.length === 0) {
67
- b.text("FALSE");
68
- return;
69
- }
70
- b.text(`${column(on, c.field)} IN (`);
71
- for (const [i, v] of list.entries()) param(i === 0 ? b : b.text(", "), on, c.field, v);
72
- b.text(")");
73
- }
74
-
75
- function condition(b: Builder, on: On, c: Where): void {
76
- const op = c.op ?? "eq";
77
- const col = column(on, c.field);
78
- if (op === "isNull") b.text(`${col} IS NULL`);
79
- else if (op === "notNull") b.text(`${col} IS NOT NULL`);
80
- else if (op === "in") inList(b, on, c);
81
- else param(b.text(`${col} ${OPS[op]} `), on, c.field, c.value);
82
- }
83
-
84
- function where(b: Builder, on: On, conditions: readonly Where[]): Builder {
85
- for (const [i, c] of conditions.entries())
86
- condition(b.text(i === 0 ? " WHERE " : " AND "), on, c);
87
- return b;
88
- }
89
-
90
- export function insert(dialect: StoreDialect, table: TableName, data: Row): Statement {
91
- return insertAll(dialect, table, [data]);
92
- }
93
-
94
- /** One INSERT of every row, each with the first row's fields: one round trip for a batch. */
95
- export function insertAll(
96
- dialect: StoreDialect,
97
- table: TableName,
98
- rows: readonly Row[],
99
- ): Statement {
100
- const on = { dialect, table };
101
- const fields = Object.keys(rows[0] ?? {});
102
- const b = new Builder().text(
103
- `INSERT INTO ${quote(table)} (${fields.map((f) => column(on, f)).join(", ")}) VALUES `,
104
- );
105
- for (const [r, data] of rows.entries()) {
106
- b.text(r === 0 ? "(" : ", (");
107
- for (const [i, f] of fields.entries()) param(i === 0 ? b : b.text(", "), on, f, data[f]);
108
- b.text(")");
109
- }
110
- return b.build();
111
- }
112
-
113
- export type Select = {
114
- table: TableName;
115
- where?: readonly Where[];
116
- orderBy?: readonly { field: string; direction: "asc" | "desc" }[];
117
- limit?: number;
118
- offset?: number;
119
- };
120
-
121
- export function select(dialect: StoreDialect, s: Select): Statement {
122
- const on = { dialect, table: s.table };
123
- const b = where(new Builder().text(`SELECT * FROM ${quote(s.table)}`), on, s.where ?? []);
124
- const order = (s.orderBy ?? []).map(
125
- (o) => `${column(on, o.field)} ${o.direction === "asc" ? "ASC" : "DESC"}`,
126
- );
127
- if (order.length > 0) b.text(` ORDER BY ${order.join(", ")}`);
128
- if (s.limit !== undefined) b.text(" LIMIT ").value(s.limit);
129
- if (s.offset !== undefined) b.text(" OFFSET ").value(s.offset);
130
- return b.build();
131
- }
132
-
133
- export function update(
134
- dialect: StoreDialect,
135
- table: TableName,
136
- conditions: readonly Where[],
137
- set: Row,
138
- ): Statement {
139
- const on = { dialect, table };
140
- const b = new Builder().text(`UPDATE ${quote(table)} SET `);
141
- for (const [i, f] of Object.keys(set).entries())
142
- param(b.text(`${i === 0 ? "" : ", "}${column(on, f)} = `), on, f, set[f]);
143
- return where(b, on, conditions).text(" RETURNING 1").build();
144
- }
145
-
146
- export function remove(
147
- dialect: StoreDialect,
148
- table: TableName,
149
- conditions: readonly Where[],
150
- ): Statement {
151
- const on = { dialect, table };
152
- const b = new Builder().text(`DELETE FROM ${quote(table)}`);
153
- return where(b, on, conditions).text(" RETURNING 1").build();
154
- }
155
-
156
- export function count(
157
- dialect: StoreDialect,
158
- table: TableName,
159
- conditions: readonly Where[],
160
- ): Statement {
161
- const on = { dialect, table };
162
- const b = new Builder().text(`SELECT count(*) AS n FROM ${quote(table)}`);
163
- return where(b, on, conditions).build();
164
- }
165
-
166
- function timestamp(value: unknown): string {
167
- if (value instanceof Date) return value.toISOString();
168
- if (typeof value === "string" || typeof value === "number") return new Date(value).toISOString();
169
- throw new TypeError("A timestamp column returned something that is not a time.");
170
- }
171
-
172
- function decodeValue(type: FieldType | undefined, value: unknown): unknown {
173
- if (value === null || value === undefined) return null;
174
- if (type === "integer") return Number(value);
175
- if (type === "boolean") return value === true || value === 1;
176
- if (type === "json") return typeof value === "string" ? (JSON.parse(value) as unknown) : value;
177
- return type === "timestamp" ? timestamp(value) : value;
178
- }
179
-
180
- /** A row as the store reads it: integers as numbers, JSON parsed, timestamps as ISO text. */
181
- export function decodeRow(table: TableName, raw: Row): Row {
182
- return Object.fromEntries(
183
- Object.entries(raw).map(([name, value]) => [name, decodeValue(typeOf(table, name), value)]),
184
- );
185
- }