derive-dashboards 0.1.0 → 0.2.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 (410) hide show
  1. package/README.md +8 -5
  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/add.mjs +130 -0
  6. package/dist/cli/check.mjs +14 -1
  7. package/dist/cli/cli.mjs +14 -12
  8. package/dist/cli/config.mjs +12 -1
  9. package/dist/cli/doctor.mjs +147 -0
  10. package/dist/cli/import/dbt-schema.mjs +2 -2
  11. package/dist/cli/import/index.mjs +2 -2
  12. package/dist/cli/init.mjs +3 -2
  13. package/dist/cli/json.mjs +21 -0
  14. package/dist/cli/layers.mjs +33 -0
  15. package/dist/core/conformance/cases.d.mts +3 -0
  16. package/dist/core/conformance/cases.mjs +20 -4
  17. package/dist/core/conformance/check.mjs +6 -3
  18. package/dist/core/conformance/drill-cases.mjs +120 -0
  19. package/dist/core/document/layout.mjs +1 -1
  20. package/dist/core/document/view-layout.d.mts +14 -0
  21. package/dist/core/document/view-layout.mjs +157 -0
  22. package/dist/core/document/view.d.mts +26 -7
  23. package/dist/core/document/view.mjs +42 -11
  24. package/dist/core/engine/filter.mjs +2 -2
  25. package/dist/core/engine/index.d.mts +14 -2
  26. package/dist/core/engine/index.mjs +12 -1
  27. package/dist/core/engine/leaf.mjs +9 -4
  28. package/dist/core/engine/members.mjs +2 -2
  29. package/dist/core/engine/postgres.mjs +1 -1
  30. package/dist/core/engine/record-layout.d.mts +11 -0
  31. package/dist/core/engine/record-layout.mjs +7 -7
  32. package/dist/core/engine/records.d.mts +3 -2
  33. package/dist/core/engine/records.mjs +2 -1
  34. package/dist/core/engine/segmented.mjs +5 -2
  35. package/dist/core/engine/sql-records.mjs +2 -1
  36. package/dist/core/engine/statement.mjs +37 -3
  37. package/dist/core/engine/types.d.mts +3 -0
  38. package/dist/core/engine/version.d.mts +1 -1
  39. package/dist/core/engine/version.mjs +1 -1
  40. package/dist/core/error/codes.d.mts +33 -1
  41. package/dist/core/error/codes.mjs +30 -2
  42. package/dist/core/index.d.mts +13 -7
  43. package/dist/core/index.mjs +9 -5
  44. package/dist/core/model/catalog/check.mjs +1 -1
  45. package/dist/core/model/hints.d.mts +36 -0
  46. package/dist/core/model/member.d.mts +4 -2
  47. package/dist/core/model/member.mjs +19 -3
  48. package/dist/core/model/types.d.mts +21 -19
  49. package/dist/core/model/validate/drill.mjs +70 -0
  50. package/dist/core/model/validate/index.mjs +3 -0
  51. package/dist/core/model/validate/members.mjs +7 -4
  52. package/dist/core/model/validate/shape.mjs +150 -0
  53. package/dist/core/model/validate/source.mjs +5 -3
  54. package/dist/core/policy/bind-query.d.mts +12 -0
  55. package/dist/core/policy/bind-query.mjs +53 -0
  56. package/dist/core/query/alias.mjs +7 -1
  57. package/dist/core/query/drill/compose.d.mts +22 -0
  58. package/dist/core/query/drill/compose.mjs +85 -0
  59. package/dist/core/query/drill/fields.d.mts +21 -0
  60. package/dist/core/query/drill/fields.mjs +91 -0
  61. package/dist/core/query/drill/internal.d.mts +11 -0
  62. package/dist/core/query/drill/items.d.mts +29 -0
  63. package/dist/core/query/drill/items.mjs +98 -0
  64. package/dist/core/query/drill/line.d.mts +31 -0
  65. package/dist/core/query/drill/line.mjs +183 -0
  66. package/dist/core/query/drill/links.d.mts +33 -0
  67. package/dist/core/query/drill/links.mjs +31 -0
  68. package/dist/core/query/drill/operand.mjs +7 -0
  69. package/dist/core/query/drill/scopes.d.mts +22 -0
  70. package/dist/core/query/drill/scopes.mjs +58 -0
  71. package/dist/core/query/drill/selection.d.mts +37 -0
  72. package/dist/core/query/drill/selection.mjs +144 -0
  73. package/dist/core/query/drill/steps.d.mts +14 -0
  74. package/dist/core/query/drill/steps.mjs +35 -0
  75. package/dist/core/query/drill/synthetic-expr.mjs +85 -0
  76. package/dist/core/query/drill/synthetic.d.mts +22 -0
  77. package/dist/core/query/drill/synthetic.mjs +165 -0
  78. package/dist/core/query/drill/time.d.mts +11 -0
  79. package/dist/core/query/drill/time.mjs +71 -0
  80. package/dist/core/query/drill/types.d.mts +155 -0
  81. package/dist/core/query/drill/types.mjs +4 -0
  82. package/dist/core/query/drill/views.d.mts +62 -0
  83. package/dist/core/query/drill/views.mjs +257 -0
  84. package/dist/core/query/filter.d.mts +6 -0
  85. package/dist/core/query/picks.d.mts +8 -2
  86. package/dist/core/query/picks.mjs +11 -4
  87. package/dist/core/query/segments.d.mts +12 -2
  88. package/dist/core/query/segments.mjs +5 -2
  89. package/dist/core/result/columns.mjs +20 -4
  90. package/dist/core/result/types.d.mts +5 -1
  91. package/dist/core/schema/aliases.d.mts +7 -0
  92. package/dist/core/schema/aliases.mjs +77 -0
  93. package/dist/core/schema/answer-parts.mjs +117 -0
  94. package/dist/core/schema/answers.d.mts +2109 -128
  95. package/dist/core/schema/answers.mjs +11 -113
  96. package/dist/core/schema/commands.d.mts +2 -2
  97. package/dist/core/schema/document.d.mts +1 -1
  98. package/dist/core/schema/drill-answers.mjs +179 -0
  99. package/dist/core/schema/drill.d.mts +260 -0
  100. package/dist/core/schema/drill.mjs +107 -0
  101. package/dist/core/schema/index.d.mts +6 -3
  102. package/dist/core/schema/index.mjs +6 -3
  103. package/dist/core/schema/picks.d.mts +35 -0
  104. package/dist/core/schema/picks.mjs +23 -0
  105. package/dist/core/schema/query.d.mts +82 -1
  106. package/dist/core/schema/query.mjs +9 -5
  107. package/dist/core/schema/tools.mjs +1 -1
  108. package/dist/core/schema/view.d.mts +0 -35
  109. package/dist/core/schema/view.mjs +19 -24
  110. package/dist/core/store/schema.d.mts +5 -0
  111. package/dist/core/store/schema.mjs +10 -0
  112. package/dist/core/types/api.d.mts +21 -1
  113. package/dist/core/types/api.mjs +1 -1
  114. package/dist/core/types/drill-api.d.mts +210 -0
  115. package/dist/core/types/options.d.mts +21 -0
  116. package/dist/core/types/viewer.d.mts +5 -0
  117. package/dist/cursor-seal.d.mts +8 -0
  118. package/dist/cursor-seal.mjs +98 -0
  119. package/dist/dashboard-id.mjs +1 -1
  120. package/dist/dashboards.mjs +4 -0
  121. package/dist/drill-access.mjs +93 -0
  122. package/dist/drill-change.mjs +76 -0
  123. package/dist/drill-crumbs.mjs +113 -0
  124. package/dist/drill-distinct.mjs +130 -0
  125. package/dist/drill-explain.mjs +64 -0
  126. package/dist/drill-identity.mjs +35 -0
  127. package/dist/drill-item-id.mjs +35 -0
  128. package/dist/drill-items.mjs +132 -0
  129. package/dist/drill-open.mjs +169 -0
  130. package/dist/drill-seal.mjs +170 -0
  131. package/dist/drill-secret.mjs +14 -0
  132. package/dist/drill-share.mjs +53 -0
  133. package/dist/drill-summary.mjs +158 -0
  134. package/dist/drill-targets.mjs +53 -0
  135. package/dist/drill-totals.mjs +8 -0
  136. package/dist/drill-views.mjs +175 -0
  137. package/dist/drill.mjs +157 -0
  138. package/dist/editing.mjs +3 -3
  139. package/dist/endpoints/dashboards.mjs +28 -5
  140. package/dist/endpoints/drill.mjs +55 -0
  141. package/dist/endpoints/index.d.mts +245 -4
  142. package/dist/endpoints/index.mjs +5 -1
  143. package/dist/endpoints/meta.mjs +10 -1
  144. package/dist/endpoints/query.mjs +26 -4
  145. package/dist/execute.d.mts +19 -1
  146. package/dist/execute.mjs +34 -27
  147. package/dist/handler.mjs +5 -1
  148. package/dist/index.d.mts +3 -1
  149. package/dist/index.mjs +29 -2
  150. package/dist/llms.txt +22 -0
  151. package/dist/mcp/drill.mjs +61 -0
  152. package/dist/mcp/format.mjs +69 -11
  153. package/dist/mcp/index.d.mts +15 -4
  154. package/dist/mcp/index.mjs +13 -7
  155. package/dist/mcp/query.d.mts +7 -2
  156. package/dist/mcp/query.mjs +40 -6
  157. package/dist/node-postgres.d.mts +8 -4
  158. package/dist/node-postgres.mjs +29 -6
  159. package/dist/owner.mjs +3 -3
  160. package/dist/postgres-connection.d.mts +8 -2
  161. package/dist/postgres-connection.mjs +2 -1
  162. package/dist/postgres-store.mjs +1 -0
  163. package/dist/react/Canvas.mjs +28 -5
  164. package/dist/react/Cell.mjs +2 -1
  165. package/dist/react/Dashboard.d.mts +10 -5
  166. package/dist/react/Dashboard.mjs +62 -22
  167. package/dist/react/DashboardList.mjs +52 -24
  168. package/dist/react/DashboardListRow.mjs +49 -0
  169. package/dist/react/Discard.mjs +12 -4
  170. package/dist/react/Editing.mjs +19 -5
  171. package/dist/react/FilterBar.d.mts +7 -9
  172. package/dist/react/Grid.mjs +19 -24
  173. package/dist/react/Header.mjs +10 -1
  174. package/dist/react/History.mjs +5 -0
  175. package/dist/react/Parts.mjs +6 -2
  176. package/dist/react/ReadFailed.mjs +23 -0
  177. package/dist/react/ReviewPanel.mjs +13 -2
  178. package/dist/react/RowBody.d.mts +19 -0
  179. package/dist/react/RowBody.mjs +55 -0
  180. package/dist/react/Spaces.mjs +15 -1
  181. package/dist/react/Tile.d.mts +3 -1
  182. package/dist/react/Tile.mjs +84 -32
  183. package/dist/react/_virtual/_rolldown/runtime.mjs +12 -0
  184. package/dist/react/arrange-steps.mjs +16 -13
  185. package/dist/react/arrange.mjs +10 -3
  186. package/dist/react/builder/Calcs.mjs +35 -11
  187. package/dist/react/builder/FilterEditor.mjs +196 -0
  188. package/dist/react/builder/Filters.mjs +172 -116
  189. package/dist/react/builder/Formula.mjs +82 -0
  190. package/dist/react/builder/Groups.mjs +1 -0
  191. package/dist/react/builder/Preview.mjs +1 -1
  192. package/dist/react/builder/RangeEditor.mjs +184 -0
  193. package/dist/react/builder/Sections.mjs +41 -6
  194. package/dist/react/builder/Time.mjs +138 -60
  195. package/dist/react/builder/Values.mjs +85 -0
  196. package/dist/react/builder/WidgetBuilder.mjs +50 -49
  197. package/dist/react/builder/base.d.mts +5 -0
  198. package/dist/react/builder/base.mjs +33 -8
  199. package/dist/react/builder/calc.mjs +15 -1
  200. package/dist/react/builder/escape.d.mts +1 -0
  201. package/dist/react/builder/escape.mjs +62 -0
  202. package/dist/react/builder/filter-tree.d.mts +9 -0
  203. package/dist/react/builder/filter-tree.mjs +186 -0
  204. package/dist/react/builder/formula-parse.d.mts +18 -0
  205. package/dist/react/builder/formula-parse.mjs +136 -0
  206. package/dist/react/builder/labels.d.mts +1 -1
  207. package/dist/react/builder/state.d.mts +2 -1
  208. package/dist/react/builder/state.mjs +23 -37
  209. package/dist/react/builder/useBuilder.d.mts +12 -1
  210. package/dist/react/builder/useBuilder.mjs +6 -3
  211. package/dist/react/builder/words.d.mts +59 -0
  212. package/dist/react/builder/words.mjs +73 -0
  213. package/dist/react/client.d.mts +2 -0
  214. package/dist/react/client.mjs +1 -0
  215. package/dist/react/context.d.mts +28 -1
  216. package/dist/react/context.mjs +25 -4
  217. package/dist/react/drill/Bars.mjs +179 -0
  218. package/dist/react/drill/Controls.mjs +173 -0
  219. package/dist/react/drill/DashboardTile.d.mts +18 -0
  220. package/dist/react/drill/DashboardTile.mjs +107 -0
  221. package/dist/react/drill/DrillPanel.d.mts +31 -0
  222. package/dist/react/drill/DrillPanel.mjs +104 -0
  223. package/dist/react/drill/DrillTabs.mjs +52 -0
  224. package/dist/react/drill/Header.mjs +131 -0
  225. package/dist/react/drill/Items.d.mts +22 -0
  226. package/dist/react/drill/Items.mjs +164 -0
  227. package/dist/react/drill/ItemsFoot.mjs +60 -0
  228. package/dist/react/drill/Notes.mjs +58 -0
  229. package/dist/react/drill/PanelBody.mjs +74 -0
  230. package/dist/react/drill/PanelStates.mjs +37 -0
  231. package/dist/react/drill/board.d.mts +18 -0
  232. package/dist/react/drill/board.mjs +91 -0
  233. package/dist/react/drill/counts.mjs +14 -0
  234. package/dist/react/drill/host.mjs +26 -0
  235. package/dist/react/drill/item-parts.d.mts +5 -0
  236. package/dist/react/drill/item-parts.mjs +76 -0
  237. package/dist/react/drill/item-type.d.mts +26 -0
  238. package/dist/react/drill/item-type.mjs +7 -0
  239. package/dist/react/drill/lazy.d.mts +6 -0
  240. package/dist/react/drill/lazy.mjs +17 -0
  241. package/dist/react/drill/pages.mjs +48 -0
  242. package/dist/react/drill/panel-focus.mjs +51 -0
  243. package/dist/react/drill/props.d.mts +25 -0
  244. package/dist/react/drill/props.mjs +72 -0
  245. package/dist/react/drill/state.d.mts +18 -0
  246. package/dist/react/drill/state.mjs +68 -0
  247. package/dist/react/drill/useDrill.d.mts +46 -0
  248. package/dist/react/drill/useDrill.mjs +194 -0
  249. package/dist/react/drill/words.d.mts +101 -0
  250. package/dist/react/drill/words.mjs +79 -0
  251. package/dist/react/english.mjs +29 -6
  252. package/dist/react/filters/bar.d.mts +12 -0
  253. package/dist/react/filters/bar.mjs +135 -0
  254. package/dist/react/filters/calendar.mjs +193 -0
  255. package/dist/react/filters/chip.mjs +174 -0
  256. package/dist/react/filters/context.d.mts +22 -0
  257. package/dist/react/filters/context.mjs +78 -0
  258. package/dist/react/filters/dates.mjs +89 -0
  259. package/dist/react/filters/days.d.mts +36 -0
  260. package/dist/react/filters/days.mjs +87 -0
  261. package/dist/react/filters/field-step.mjs +81 -0
  262. package/dist/react/filters/hooks.d.mts +34 -0
  263. package/dist/react/filters/hooks.mjs +94 -0
  264. package/dist/react/filters/listbox.mjs +131 -0
  265. package/dist/react/filters/logic.d.mts +59 -0
  266. package/dist/react/filters/logic.mjs +109 -0
  267. package/dist/react/filters/menu-search.mjs +211 -0
  268. package/dist/react/filters/menu.mjs +85 -0
  269. package/dist/react/filters/number.mjs +127 -0
  270. package/dist/react/filters/numbers.d.mts +47 -0
  271. package/dist/react/filters/numbers.mjs +151 -0
  272. package/dist/react/filters/operator.mjs +104 -0
  273. package/dist/react/filters/phone.mjs +104 -0
  274. package/dist/react/filters/popover.d.mts +19 -0
  275. package/dist/react/filters/popover.mjs +153 -0
  276. package/dist/react/filters/rules.d.mts +8 -0
  277. package/dist/react/filters/rules.mjs +55 -0
  278. package/dist/react/filters/sheet.mjs +196 -0
  279. package/dist/react/filters/state.mjs +132 -0
  280. package/dist/react/filters/suggest.d.mts +47 -0
  281. package/dist/react/filters/suggest.mjs +97 -0
  282. package/dist/react/filters/values.mjs +166 -0
  283. package/dist/react/filters/words.d.mts +81 -0
  284. package/dist/react/filters/words.mjs +73 -0
  285. package/dist/react/format.d.mts +3 -3
  286. package/dist/react/format.mjs +45 -16
  287. package/dist/react/index.d.mts +34 -5
  288. package/dist/react/index.mjs +15 -4
  289. package/dist/react/messages.d.mts +47 -2
  290. package/dist/react/place.mjs +7 -3
  291. package/dist/react/renderers/index.d.mts +10 -2
  292. package/dist/react/renderers/index.mjs +116 -14
  293. package/dist/react/renderers/list.d.mts +22 -0
  294. package/dist/react/renderers/list.mjs +118 -0
  295. package/dist/react/review-words.mjs +1 -1
  296. package/dist/react/review.mjs +2 -2
  297. package/dist/react/scope.mjs +2 -7
  298. package/dist/react/series.d.mts +54 -0
  299. package/dist/react/series.mjs +191 -0
  300. package/dist/react/theme.css +2734 -1296
  301. package/dist/react/theme.css.d.ts +1 -0
  302. package/dist/react/tile-store.mjs +15 -3
  303. package/dist/react/useBoard.d.mts +7 -0
  304. package/dist/react/useBoard.mjs +4 -1
  305. package/dist/react/useDashboard.d.mts +4 -0
  306. package/dist/react/useDashboard.mjs +8 -1
  307. package/dist/react/useTiles.mjs +50 -15
  308. package/dist/react/view-grid.mjs +16 -0
  309. package/dist/react/view.d.mts +9 -0
  310. package/dist/react/view.mjs +22 -10
  311. package/dist/reading.d.mts +2 -0
  312. package/dist/reading.mjs +9 -1
  313. package/dist/recharts/axes.mjs +28 -0
  314. package/dist/recharts/axis.mjs +84 -0
  315. package/dist/recharts/bar.d.mts +7 -0
  316. package/dist/recharts/bar.mjs +140 -0
  317. package/dist/recharts/charts.d.mts +4 -6
  318. package/dist/recharts/charts.mjs +2 -114
  319. package/dist/recharts/index.d.mts +5 -3
  320. package/dist/recharts/index.mjs +6 -3
  321. package/dist/recharts/line.d.mts +2 -0
  322. package/dist/recharts/line.mjs +111 -0
  323. package/dist/recharts/marks.mjs +112 -0
  324. package/dist/recharts/parts.mjs +88 -0
  325. package/dist/recharts/series.d.mts +2 -22
  326. package/dist/recharts/series.mjs +1 -64
  327. package/dist/recharts/table.mjs +71 -0
  328. package/dist/records-read.mjs +44 -0
  329. package/dist/registry/filter-bar.json +26 -0
  330. package/dist/skills/derive-dashboards/SKILL.md +69 -0
  331. package/dist/store/apply.mjs +5 -5
  332. package/dist/store/commands.mjs +4 -4
  333. package/dist/store/discard.mjs +7 -7
  334. package/dist/store/drafts.mjs +5 -5
  335. package/dist/store/editor.mjs +1 -1
  336. package/dist/store/publish.mjs +12 -12
  337. package/dist/store/reader.mjs +41 -22
  338. package/dist/store/review.mjs +16 -16
  339. package/dist/store/rows.mjs +20 -20
  340. package/dist/store/undo.mjs +3 -3
  341. package/dist/store/unpublished.mjs +4 -4
  342. package/dist/store/versions.mjs +14 -14
  343. package/dist/testing/adapter-suite.mjs +4 -4
  344. package/dist/tiles.mjs +37 -3
  345. package/package.json +12 -10
  346. package/dist/react/FilterBar.mjs +0 -119
  347. package/dist/react/Records.d.mts +0 -12
  348. package/dist/react/Records.mjs +0 -97
  349. package/src/adapter/sql-adapter.ts +0 -95
  350. package/src/adapter/statement.ts +0 -185
  351. package/src/authorize.ts +0 -73
  352. package/src/body.ts +0 -169
  353. package/src/bounded.ts +0 -43
  354. package/src/cache.ts +0 -192
  355. package/src/checks.ts +0 -170
  356. package/src/custom-source.ts +0 -59
  357. package/src/dashboard-id.ts +0 -36
  358. package/src/dashboards.ts +0 -132
  359. package/src/editing.ts +0 -148
  360. package/src/endpoints/access.ts +0 -41
  361. package/src/endpoints/dashboards.ts +0 -92
  362. package/src/endpoints/drafts.ts +0 -138
  363. package/src/endpoints/index.ts +0 -21
  364. package/src/endpoints/meta.ts +0 -137
  365. package/src/endpoints/query.ts +0 -86
  366. package/src/endpoints/read.ts +0 -92
  367. package/src/endpoints/review.ts +0 -89
  368. package/src/endpoints/values.ts +0 -62
  369. package/src/endpoints/versions.ts +0 -104
  370. package/src/execute.ts +0 -207
  371. package/src/handler.ts +0 -232
  372. package/src/http.ts +0 -66
  373. package/src/index.ts +0 -163
  374. package/src/introspect.ts +0 -205
  375. package/src/mcp/api.ts +0 -59
  376. package/src/mcp/format.ts +0 -67
  377. package/src/mcp/index.ts +0 -151
  378. package/src/mcp/query.ts +0 -153
  379. package/src/mcp/resolve.ts +0 -114
  380. package/src/node-postgres.ts +0 -81
  381. package/src/owner.ts +0 -36
  382. package/src/postgres-connection.ts +0 -143
  383. package/src/postgres-store.ts +0 -82
  384. package/src/principal.ts +0 -39
  385. package/src/reading.ts +0 -56
  386. package/src/request-rows.ts +0 -23
  387. package/src/request.ts +0 -22
  388. package/src/storage.ts +0 -63
  389. package/src/store/apply.ts +0 -129
  390. package/src/store/commands.ts +0 -75
  391. package/src/store/conflicts.ts +0 -98
  392. package/src/store/create-tables.ts +0 -104
  393. package/src/store/discard.ts +0 -42
  394. package/src/store/drafts.ts +0 -133
  395. package/src/store/editor.ts +0 -28
  396. package/src/store/log.ts +0 -28
  397. package/src/store/publish.ts +0 -199
  398. package/src/store/publisher.ts +0 -21
  399. package/src/store/reader.ts +0 -139
  400. package/src/store/review.ts +0 -239
  401. package/src/store/rows.ts +0 -250
  402. package/src/store/tenant.ts +0 -28
  403. package/src/store/undo.ts +0 -56
  404. package/src/store/unpublished.ts +0 -33
  405. package/src/store/versions.ts +0 -106
  406. package/src/store/writer.ts +0 -19
  407. package/src/testing/adapter-suite.ts +0 -239
  408. package/src/testing/index.ts +0 -2
  409. package/src/tile-doc.ts +0 -46
  410. package/src/tiles.ts +0 -120
package/README.md CHANGED
@@ -7,7 +7,8 @@ dashboards inside your app, and every query runs under your access rules: your t
7
7
  row rules when you have them, nothing extra when you do not.
8
8
 
9
9
  > **Status: early (0.x).** On Postgres, dashboards
10
- > defined in code, filters, the rows behind a tile, the widget builder and editing a
10
+ > defined in code, filters, drill-in (a click on a bar, a point, a row or a number opens what is
11
+ > behind it: broken down, over time, or as its items, each a link into your app), the widget builder and editing a
11
12
  > dashboard (a draft per person, drag and resize, undo and redo, review before publish, merging
12
13
  > over someone else's version), new dashboards, version history with in-place preview and
13
14
  > Restore, shareable links, and agents that edit and publish as themselves work end to
@@ -24,7 +25,8 @@ One package. The React UI needs `react`, and the line and bar charts need `recha
24
25
  them only if you use those parts. The `derive-dashboards` command (`npx derive-dashboards init`)
25
26
  comes with it.
26
27
 
27
- Then follow the [quick start](https://github.com/derive-to/dashboards/blob/main/docs/quick-start.md).
28
+ Then follow the [quick start](https://github.com/derive-to/dashboards/blob/main/docs/quick-start.md). Using a coding agent? `npx skills add derive-to/dashboards --skill derive-dashboards`
29
+ gives it the install steps, and [llms.txt](https://github.com/derive-to/dashboards/blob/main/llms.txt) indexes every page (both also ship in the package).
28
30
 
29
31
  ## What is here today
30
32
 
@@ -34,16 +36,17 @@ Embedded dashboards on Postgres, end to end, run by the Acme Tasks sample (`exam
34
36
  | --- | --- |
35
37
  | `derive-dashboards/core` | No I/O and no framework. The model (`defineModel`, `validateModel`), typed member ids, filters and queries, the access kernel (`effectiveFilter`), composition, the oracle every engine must match, the Postgres engine (`/engine`), the document and its schema (`/schema`), and the store's tables as data. |
36
38
  | `derive-dashboards` | `deriveDashboards(options)`: a fetch handler for every endpoint, a Postgres source and store for any driver, the result cache, the query log, `createTables`, and the store contract suite (`/testing`). |
37
- | `derive-dashboards/react` | `Dashboard` with edit mode (Edit, + Add widget, drag and resize, a change count with undo and redo, review before publish, History with in-place preview, Share), `DashboardList` with + New dashboard, `useDraft` and `useReview` for your own edit and review UI, `FilterBar`, `Tile`, the rows panel, the widget builder (`WidgetBuilder`, `useBuilder`) and `theme.css`. |
38
- | `derive-dashboards/recharts` | Line and bar tiles, drawn with Recharts (install `recharts` to use them; any other chart library plugs into `renderers`). |
39
+ | `derive-dashboards/react` | `Dashboard` with edit mode (Edit, + Add widget, drag and resize, a change count with undo and redo, review before publish, History with in-place preview, Share), `DashboardList` with + New dashboard, `useDraft` and `useReview` for your own edit and review UI, the filter bar (`FilterBar`, with chips, a Filter menu, a phone sheet and `filterRules` for your own), `Tile`, drill-in (`DrillPanel`, `DashboardTile`, `useDrill`, and `toSeries` and `rowAt` for any chart kit), the widget builder (`WidgetBuilder`, `useBuilder`) and `theme.css`. |
40
+ | `derive-dashboards/recharts` | Line and bar tiles, drawn with Recharts, each mark a drill (install `recharts` to use them; any other chart library plugs into `renderers`). |
39
41
  | `derive-dashboards/mcp` | Two tools for the MCP server you already run (`addDashboardTools`): `dashboards_query` to ask and read, `dashboards_api` for everything else. See [MCP](https://github.com/derive-to/dashboards/blob/main/docs/mcp.md). |
40
- | `derive-dashboards/cli` | `defineConfig` for `derive-dashboards.config.ts`; the `derive-dashboards` command runs `init`, `check`, `generate`, `create-tables`. |
42
+ | `derive-dashboards/cli` | `defineConfig` for `derive-dashboards.config.ts`; the `derive-dashboards` command runs `init`, `doctor`, `check`, `generate`, `create-tables`. |
41
43
 
42
44
  Tenancy and row policy are opt-in. An app of one tenant leaves them out; once the model has
43
45
  tenant keys, every source must say how it is tied to them. A viewer who can read no row of a
44
46
  tile's source gets "no access", never zeros.
45
47
 
46
48
  Start with the [quick start](https://github.com/derive-to/dashboards/blob/main/docs/quick-start.md), then [concepts](https://github.com/derive-to/dashboards/blob/main/docs/concepts.md),
49
+ [filters](https://github.com/derive-to/dashboards/blob/main/docs/filters.md) (the built-in filter bar, how to theme it, and `npx derive-dashboards add filter-bar` to own its code),
47
50
  [endpoints](https://github.com/derive-to/dashboards/blob/main/docs/endpoints.md), [the store](https://github.com/derive-to/dashboards/blob/main/docs/store.md) and [the CLI](https://github.com/derive-to/dashboards/blob/main/docs/cli.md). To run
48
51
  your own data layer (ClickHouse, an API, your own SQL), see
49
52
  [a custom data layer](https://github.com/derive-to/dashboards/blob/main/docs/custom-data-layer.md). The
@@ -55,7 +55,7 @@ function adapterOver(id, runner) {
55
55
  },
56
56
  async count({ table, where }) {
57
57
  const [row] = await runner.run(count(dialect, table, where ?? []));
58
- return Number(row?.["n"] ?? 0);
58
+ return Number(row?.n ?? 0);
59
59
  },
60
60
  transaction: (fn) => runner.transaction((tx) => fn(adapterOver(id, tx))),
61
61
  classifyError(error) {
@@ -70,9 +70,9 @@ function adapterOver(id, runner) {
70
70
  strings: [CATALOG[dialect]],
71
71
  values: []
72
72
  })).map((row) => ({
73
- table: text(row["table"]),
74
- column: text(row["column"]),
75
- ...row["schema"] === void 0 ? {} : { schema: text(row["schema"]) }
73
+ table: text(row.table),
74
+ column: text(row.column),
75
+ ...row.schema === void 0 ? {} : { schema: text(row.schema) }
76
76
  }))
77
77
  }
78
78
  };
package/dist/body.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { HttpError } from "./http.mjs";
2
- import { commandSchema, jsonSchema, picksSchema, wireQuerySchema } from "derive-dashboards/core/schema";
2
+ import { commandSchema, drillStateSchema, jsonSchema, picksSchema, wireQuerySchema } from "derive-dashboards/core/schema";
3
3
  import { z } from "zod";
4
4
  // src/body.ts
5
5
  /** The request bodies every endpoint checks before anything reads them. Unknown keys are refused. */
@@ -46,6 +46,14 @@ const bodies = {
46
46
  ...tileRef,
47
47
  ...page
48
48
  }),
49
+ drill: z.strictObject({
50
+ state: drillStateSchema,
51
+ page: z.strictObject({
52
+ after: page.after,
53
+ limit: z.int().min(1).max(200).exactOptional()
54
+ }).exactOptional(),
55
+ summary: z.literal(false).exactOptional()
56
+ }),
49
57
  controlValues: z.strictObject({
50
58
  dashboardId: id,
51
59
  controlId: id,
@@ -122,6 +130,8 @@ const BODIES_BY_PATH = {
122
130
  "/dashboards/tile": bodies.tile,
123
131
  "/dashboards/tiles": bodies.tiles,
124
132
  "/dashboards/records": bodies.records,
133
+ "/dashboards/drill": bodies.drill,
134
+ "/query/drill": bodies.drill,
125
135
  "/dashboards/control-values": bodies.controlValues,
126
136
  "/dashboards/new": bodies.newDashboard,
127
137
  "/dashboards/draft/start": bodies.dashboard,
package/dist/cache.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Answered } from "./execute.mjs";
2
- import { DashOptions, Principal, SourceName, WireQuery } from "derive-dashboards/core";
2
+ import { DashOptions, Model, Principal, SourceName, WireQuery } from "derive-dashboards/core";
3
3
  /** What decides an answer, besides the rows: everything that goes into its cache key. */
4
4
  type CacheKey = {
5
5
  principal: Principal;
@@ -0,0 +1,130 @@
1
+ import { ComponentsJson, PackageJson, readJson } from "./json.mjs";
2
+ import { LAYER_LINE, layerOrder } from "./layers.mjs";
3
+ import { spawnSync } from "node:child_process";
4
+ import { existsSync } from "node:fs";
5
+ import { join, resolve } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ // src/add.ts
8
+ /** The shadcn CLI version the registry item is tested with. */
9
+ const SHADCN = "shadcn@4.23.0";
10
+ /** The React version installed in the app, when it is: what will run, not what the range allows. */
11
+ function installedReact(cwd) {
12
+ try {
13
+ return readJson(join(cwd, "node_modules/react/package.json"), PackageJson).version;
14
+ } catch {
15
+ return;
16
+ }
17
+ }
18
+ /**
19
+ * Why this folder is not an app to add the bar to, or undefined when it is: it needs its own
20
+ * package.json (so no package manager walks up into a parent project), React 19, and the library.
21
+ */
22
+ function notAnApp(cwd) {
23
+ const file = join(cwd, "package.json");
24
+ if (!existsSync(file)) return `There is no package.json in ${cwd}. Run this in your React app's folder (where its package.json is), or pass --cwd <folder>.`;
25
+ let manifest;
26
+ try {
27
+ manifest = readJson(file, PackageJson);
28
+ } catch {
29
+ return `${file} is not valid JSON.`;
30
+ }
31
+ const deps = {
32
+ ...manifest.devDependencies,
33
+ ...manifest.dependencies
34
+ };
35
+ if (deps["derive-dashboards"] === void 0) return `${file} does not list derive-dashboards. Install it first: npm install derive-dashboards`;
36
+ const react = installedReact(cwd) ?? deps["react"];
37
+ if (react === void 0) return `${file} does not list react. The filter bar is a React component.`;
38
+ const major = /(\d+)/u.exec(react)?.[1];
39
+ if (major !== void 0 && Number(major) < 19) return `The filter bar needs React 19; ${file} has react ${react}. Upgrade React, or keep the built-in bar.`;
40
+ }
41
+ /** The shadcn bases the copied bar is written for: its triggers render as plain buttons on both. */
42
+ const BASES = /* @__PURE__ */ new Set(["radix", "base"]);
43
+ /**
44
+ * Which primitive library a shadcn app is on, from components.json: its `base`, else the prefix of
45
+ * its `style` ("radix-nova", "base-nova"), else Radix for older apps that name neither.
46
+ */
47
+ function shadcnBase(cwd) {
48
+ try {
49
+ const config = readJson(join(cwd, "components.json"), ComponentsJson);
50
+ return config.base ?? /^([a-z]+)-/u.exec(config.style ?? "")?.[1] ?? "radix";
51
+ } catch {
52
+ return "radix";
53
+ }
54
+ }
55
+ /** Why the copy cannot go into this shadcn app, or undefined when it can. */
56
+ function unsupportedBase(cwd) {
57
+ const base = shadcnBase(cwd);
58
+ if (BASES.has(base)) return void 0;
59
+ return `This app's shadcn components are on ${base === "aria" ? "React Aria" : base}; the filter bar copy is written for Base UI and Radix. Keep the built-in bar (it needs no UI kit), or add a Base UI or Radix popover and command to copy it.`;
60
+ }
61
+ /** The registry item inside this package: dist/cli/add.mjs → dist/registry/filter-bar.json. */
62
+ const registryItem = () => fileURLToPath(new URL("../registry/filter-bar.json", import.meta.url));
63
+ const SHADCN_LINE = `import { DashboardFilterBar } from "@/components/filter-bar";
64
+
65
+ <DashboardsProvider client={client} components={{ FilterBar: DashboardFilterBar }}>`;
66
+ /** Runs (or, for a dry run, prints) the shadcn CLI on the packaged item; false when it failed. */
67
+ function runShadcn(io, dryRun, overwrite) {
68
+ const args = [
69
+ SHADCN,
70
+ "add",
71
+ registryItem(),
72
+ ...overwrite ? ["--overwrite", "--yes"] : []
73
+ ];
74
+ if (dryRun) {
75
+ io.out(`npx ${args.join(" ")}`);
76
+ return true;
77
+ }
78
+ const result = spawnSync("npx", args, {
79
+ cwd: io.cwd,
80
+ stdio: "inherit",
81
+ shell: false
82
+ });
83
+ if (result.status === 0) return true;
84
+ io.err(`npx shadcn failed${result.error ? `: ${result.error.message}` : ""}.`);
85
+ return false;
86
+ }
87
+ /**
88
+ * `derive-dashboards add filter-bar`: the Linear-style filter bar as your own code. Every
89
+ * dashboard already draws it (the built-in bar); in a shadcn app this copies the shadcn version
90
+ * into your components, styled by your tokens. Without shadcn there is nothing to add.
91
+ * `--dry-run` prints the command instead of running it; `--overwrite` replaces a copy you have.
92
+ */
93
+ function add(io, item, dryRun, overwrite = false) {
94
+ const shadcn = existsSync(join(io.cwd, "components.json"));
95
+ const problem = refusal(io.cwd, item, shadcn);
96
+ if (problem !== void 0) {
97
+ io.err(problem);
98
+ return 2;
99
+ }
100
+ if (!shadcn) {
101
+ io.out("Every dashboard already has the filter bar: the built-in one, styled by derive-dashboards/react/theme.css and your own CSS (see docs/filters.md).\nTo own its code instead, set up shadcn/ui (npx shadcn@latest init) and run this again.");
102
+ return 0;
103
+ }
104
+ const base = shadcnBase(io.cwd) === "base" ? "Base UI" : "Radix";
105
+ io.out(`Found components.json (shadcn on ${base}): adding the shadcn filter bar to your components.`);
106
+ if (!runShadcn(io, dryRun, overwrite)) return 1;
107
+ lastSteps(io, overwrite);
108
+ return 0;
109
+ }
110
+ /** Why `add` cannot go ahead here: an unknown item, not an app, or an unsupported shadcn base. */
111
+ function refusal(cwd, item, shadcn) {
112
+ if (item !== "filter-bar") return `add knows one item: filter-bar.${item === void 0 ? "" : ` Not "${item}".`}`;
113
+ return notAnApp(cwd) ?? (shadcn ? unsupportedBase(cwd) : void 0);
114
+ }
115
+ /** What is left after the copy: an existing copy kept, and the one provider line. */
116
+ function lastSteps(io, overwrite) {
117
+ if (!overwrite && existsSync(join(io.cwd, "components/filter-bar.tsx"))) io.out("components/filter-bar.tsx was already there and shadcn keeps it unless you say yes. To update it to this version, commit, run again with --overwrite, and use git diff to put back your own changes.");
118
+ const layers = layerOrder(io.cwd);
119
+ if (layers?.ok === false) io.out(`\nFirst, at the top of ${layers.file}, so the theme sits above Tailwind's reset:\n\n${LAYER_LINE}`);
120
+ io.out(`\nLast step, where you render dashboards (a client component in Next.js):\n\n${SHADCN_LINE}\n\nMore: https://github.com/derive-to/dashboards/blob/main/docs/filters.md`);
121
+ }
122
+ /** The CLI's `add` command: `--cwd` picks the app's folder, `--dry-run` and `--overwrite` pass on. */
123
+ function addCommand(flags, io) {
124
+ const cwd = flags.cwd === void 0 ? io.cwd : resolve(io.cwd, flags.cwd);
125
+ return add({
126
+ ...io,
127
+ cwd
128
+ }, flags.args?.[0], flags["dry-run"] === true, flags.overwrite === true);
129
+ }
130
+ export { BASES, addCommand, shadcnBase };
@@ -1,4 +1,4 @@
1
- import { checkCatalog, describeQueries, validateModel } from "derive-dashboards/core";
1
+ import { checkCatalog, describeQueries, recordDimensions, validateModel } from "derive-dashboards/core";
2
2
  // src/check.ts
3
3
  const introspects = (c) => "introspect" in c;
4
4
  /**
@@ -35,6 +35,17 @@ async function partIssues(part) {
35
35
  const described = await describeQueries(part.model, part.connection, await part.connection.introspect());
36
36
  return [...described.issues, ...checkCatalog(part.model, described.schema)];
37
37
  }
38
+ /**
39
+ * The columns a drill's Items list shows for each source: the model's `records.columns`, or the
40
+ * default the library picks (the key, then up to four shown fields), so a host sees it before a user does.
41
+ */
42
+ function itemsColumns(model) {
43
+ return Object.entries(model.sources).map(([name, def]) => {
44
+ const columns = recordDimensions(model, name);
45
+ const from = def.records?.columns === void 0 ? "default" : "records.columns";
46
+ return ` ${name}: ${columns.length === 0 ? "(none)" : columns.join(", ")} (${from})`;
47
+ });
48
+ }
38
49
  const describeIssue = (i) => ` ${i.code} ${i.path.join(".")}: ${i.message}`;
39
50
  /**
40
51
  * Proves a model against the config's databases and prints every problem: the exit code is 0
@@ -46,6 +57,8 @@ async function checkModel(config, model, io) {
46
57
  const checked = await Promise.all(parts.map((part) => partIssues(part)));
47
58
  const issues = [...validateModel(model), ...checked.flat()];
48
59
  for (const issue of issues) io.err(describeIssue(issue));
60
+ io.out("Items columns:");
61
+ for (const line of itemsColumns(model)) io.out(line);
49
62
  io.out(issues.length === 0 ? "The model matches the database." : `${issues.length} problems.`);
50
63
  return issues.length === 0 ? 0 : 1;
51
64
  }
package/dist/cli/cli.mjs CHANGED
@@ -1,10 +1,10 @@
1
+ import { addCommand } from "./add.mjs";
1
2
  import { checkModel } from "./check.mjs";
2
- import { loadConfig } from "./config.mjs";
3
+ import { configFor } from "./config.mjs";
3
4
  import { checkHost } from "./conformance.mjs";
5
+ import { doctor } from "./doctor.mjs";
4
6
  import { init, writeNew } from "./init.mjs";
5
7
  import { renderDrizzle, renderKysely, renderSql, renderStatements } from "./render.mjs";
6
- import { existsSync } from "node:fs";
7
- import { resolve } from "node:path";
8
8
  import { parseArgs } from "node:util";
9
9
  import { createTables, schemaDiff } from "derive-dashboards";
10
10
  // src/cli.ts
@@ -16,6 +16,9 @@ const USAGE = `Usage: derive-dashboards <command> [options]
16
16
  Import a model from dbt's semantic layer (target/semantic_manifest.json, or the project
17
17
  folder) or Cube's YAML data model (a file or folder); exact storage from the config's
18
18
  connection when there is one, then checked against it.
19
+ doctor
20
+ Look over the setup and say what is missing, each with its fix: the config, model,
21
+ connection and store tables, DASHBOARDS_SECRET, the React peers and the shadcn base.
19
22
  check
20
23
  Prove the config's model against the database: tables, columns, keys, types.
21
24
  check --conformance <module>
@@ -27,6 +30,9 @@ const USAGE = `Usage: derive-dashboards <command> [options]
27
30
  Write the library's tables for your own tool (drizzle-kit, SQL files).
28
31
  generate --orm sql --diff --out <file>
29
32
  Write only what the config's database lacks: new tables, columns, keys, indexes.
33
+ add filter-bar [--cwd <folder>] [--overwrite] [--dry-run]
34
+ Copy the filter bar into a shadcn app as your own code (dashboards already draw the
35
+ built-in one). Prints the one line left to change. --overwrite replaces your copy.
30
36
 
31
37
  --config <file> defaults to derive-dashboards.config.ts
32
38
  -h, --help this text`;
@@ -43,6 +49,8 @@ function need(value, what) {
43
49
  }
44
50
  const COMMANDS = {
45
51
  init,
52
+ add: (_config, flags, io) => Promise.resolve(addCommand(flags, io)),
53
+ doctor: (_config, flags, io) => doctor(io, flags),
46
54
  check(config, flags, io) {
47
55
  if (flags.conformance !== void 0) return checkHost(io, flags.conformance);
48
56
  return checkModel(config, need(config.model, "model"), io);
@@ -71,15 +79,6 @@ const COMMANDS = {
71
79
  return 0;
72
80
  }
73
81
  };
74
- /**
75
- * The config a command reads: none for generating files or checking a custom source; for an
76
- * import, the config when there is one (its connection gives exact storage), else none.
77
- */
78
- function configFor(command, flags, cwd) {
79
- if (command === "generate" && flags.diff !== true || flags.conformance !== void 0) return Promise.resolve({});
80
- if (command === "init" && flags.from !== void 0 && !existsSync(resolve(cwd, flags.config ?? "derive-dashboards.config.ts"))) return Promise.resolve({});
81
- return loadConfig(cwd, flags.config);
82
- }
83
82
  const OPTIONS = {
84
83
  config: { type: "string" },
85
84
  tenant: {
@@ -93,6 +92,9 @@ const OPTIONS = {
93
92
  dialect: { type: "string" },
94
93
  diff: { type: "boolean" },
95
94
  conformance: { type: "string" },
95
+ "dry-run": { type: "boolean" },
96
+ cwd: { type: "string" },
97
+ overwrite: { type: "boolean" },
96
98
  help: {
97
99
  type: "boolean",
98
100
  short: "h"
@@ -1,4 +1,6 @@
1
1
  import { loadModule } from "./load.mjs";
2
+ import { existsSync } from "node:fs";
3
+ import { resolve } from "node:path";
2
4
  // src/config.ts
3
5
  function defineConfig(config) {
4
6
  return config;
@@ -11,4 +13,13 @@ async function loadConfig(cwd, path = "derive-dashboards.config.ts") {
11
13
  if (!isConfig(config)) throw new Error(`${path} must export its config as the default export.`);
12
14
  return config;
13
15
  }
14
- export { defineConfig, loadConfig };
16
+ /**
17
+ * The config a command reads: none for generating files or checking a custom source; for an
18
+ * import, the config when there is one (its connection gives exact storage), else none.
19
+ */
20
+ function configFor(command, flags, cwd) {
21
+ if (command === "add" || command === "doctor" || command === "generate" && flags.diff !== true || flags.conformance !== void 0) return Promise.resolve({});
22
+ if (command === "init" && flags.from !== void 0 && !existsSync(resolve(cwd, flags.config ?? "derive-dashboards.config.ts"))) return Promise.resolve({});
23
+ return loadConfig(cwd, flags.config);
24
+ }
25
+ export { configFor, defineConfig, loadConfig };
@@ -0,0 +1,147 @@
1
+ import { BASES, shadcnBase } from "./add.mjs";
2
+ import { introspects } from "./check.mjs";
3
+ import { loadConfig } from "./config.mjs";
4
+ import { PackageJson, readJson } from "./json.mjs";
5
+ import { LAYER_LINE, layerOrder } from "./layers.mjs";
6
+ import { schemaDiff } from "derive-dashboards";
7
+ import { existsSync } from "node:fs";
8
+ import { join, resolve } from "node:path";
9
+ import { validateModel } from "derive-dashboards/core";
10
+ // src/doctor.ts
11
+ const ok = (what) => ({
12
+ ok: true,
13
+ what
14
+ });
15
+ const bad = (what, fix) => ({
16
+ ok: false,
17
+ what,
18
+ fix
19
+ });
20
+ /** A package's version as installed in the app, else the range it lists, else undefined. */
21
+ function versionOf(cwd, name, listed) {
22
+ try {
23
+ const file = join(cwd, "node_modules", name, "package.json");
24
+ return readJson(file, PackageJson).version;
25
+ } catch {
26
+ return listed[name];
27
+ }
28
+ }
29
+ const plural = (n, word) => `${String(n)} ${word}${n === 1 ? "" : "s"}`;
30
+ const major = (version) => Number(/(\d+)/u.exec(version)?.[1] ?? "0");
31
+ /** The app's own dependencies, as its package.json lists them; undefined with no package.json. */
32
+ function dependenciesOf(cwd) {
33
+ const file = join(cwd, "package.json");
34
+ if (!existsSync(file)) return void 0;
35
+ const manifest = readJson(file, PackageJson);
36
+ return {
37
+ ...manifest.devDependencies,
38
+ ...manifest.dependencies
39
+ };
40
+ }
41
+ /** The peers the React parts need, at the majors they are built for, each when it is used. */
42
+ function peers(cwd) {
43
+ const deps = dependenciesOf(cwd);
44
+ if (deps === void 0) return [bad("No package.json here", "Run this in your app's folder.")];
45
+ if (deps["derive-dashboards"] === void 0) return [bad("derive-dashboards is not installed", "npm install derive-dashboards")];
46
+ return [
47
+ [
48
+ "react",
49
+ 19,
50
+ "derive-dashboards/react"
51
+ ],
52
+ [
53
+ "react-dom",
54
+ 19,
55
+ "derive-dashboards/react"
56
+ ],
57
+ [
58
+ "recharts",
59
+ 3,
60
+ "derive-dashboards/recharts (the built-in charts)"
61
+ ]
62
+ ].flatMap(([name, want, by]) => {
63
+ const version = versionOf(cwd, name, deps);
64
+ if (version === void 0) return name === "react" ? [ok("No React: server only")] : [];
65
+ if (major(version) === want) return [ok(`${name} ${version}`)];
66
+ const what = major(version) < want ? `older than ${by} needs` : `newer than the major ${by} is built for`;
67
+ return [bad(`${name} ${version} is ${what}`, `npm install ${name}@^${String(want)}`)];
68
+ });
69
+ }
70
+ /** The shadcn base, when the app has components.json: one the copied filter bar is written for. */
71
+ function shadcn(cwd) {
72
+ if (!existsSync(join(cwd, "components.json"))) return [];
73
+ const base = shadcnBase(cwd);
74
+ return BASES.has(base) ? [ok(`shadcn on ${base === "base" ? "Base UI" : "Radix"}`)] : [bad(`shadcn on ${base}`, "The copied filter bar needs Radix or Base UI; keep the built-in bar.")];
75
+ }
76
+ /** A Tailwind app's layer order, so Tailwind's reset does not undo the theme. */
77
+ function layers(cwd) {
78
+ const found = layerOrder(cwd);
79
+ if (found === void 0) return [];
80
+ return found.ok ? [ok(`${found.file} puts the theme above Tailwind's reset`)] : [bad(`${found.file} does not name the layer order`, `Add at its top: ${LAYER_LINE}`)];
81
+ }
82
+ /** The seal secret the server reads (quick start step 4), long enough to be a key. */
83
+ function secret(env) {
84
+ const value = env["DASHBOARDS_SECRET"];
85
+ if (value === void 0 || value === "") return bad("DASHBOARDS_SECRET is not set", "Set it to the same long random value on every instance (openssl rand -base64 32), and pass it as deriveDashboards({ secret }).");
86
+ return value.length >= 32 ? ok("DASHBOARDS_SECRET is set") : bad("DASHBOARDS_SECRET is shorter than 32 characters", "Use openssl rand -base64 32.");
87
+ }
88
+ const messageOf = (error) => error instanceof Error ? error.message : String(error);
89
+ /** Whether the connection answers: it reads the database's catalog, as check does. */
90
+ async function reachable(config) {
91
+ const connection = config.connection ?? Object.values(config.connections ?? {}).find((c) => introspects(c));
92
+ if (connection === void 0) return config.connections === void 0 ? bad("The config has no connection", "Add connection: nodePostgres(pool).connection.") : ok("Connections are custom sources (derive-dashboards check --conformance checks them)");
93
+ try {
94
+ await connection.introspect();
95
+ return ok("Connection answers (derive-dashboards check proves the model against it)");
96
+ } catch (error) {
97
+ return bad("Connection does not answer", messageOf(error));
98
+ }
99
+ }
100
+ /** The config's model, connection and store, each checked as far as reading allows. */
101
+ async function configured(config) {
102
+ const model = config.model;
103
+ const issues = model === void 0 ? [] : validateModel(model);
104
+ const found = [model === void 0 ? bad("The config has no model", "derive-dashboards init writes one.") : issues.length === 0 ? ok(`Model: ${plural(Object.keys(model.sources).length, "source")}`) : bad(`Model: ${String(issues.length)} problems`, "derive-dashboards check lists them."), await reachable(config)];
105
+ if (config.database === void 0) return [...found, ok("No store: viewing works; editing needs one (docs/store.md)")];
106
+ let missing;
107
+ try {
108
+ const diff = await schemaDiff(config.database);
109
+ missing = diff.tables.length + diff.columns.length;
110
+ } catch (error) {
111
+ return [...found, bad("Store: could not read its tables", messageOf(error))];
112
+ }
113
+ return [...found, missing === 0 ? ok("Store: every dd_ table and column is there") : bad(`Store: ${String(missing)} tables or columns missing`, "derive-dashboards create-tables")];
114
+ }
115
+ /** The config, or what is wrong with it as a finding. */
116
+ async function configOrFinding(cwd, path) {
117
+ const file = path ?? "derive-dashboards.config.ts";
118
+ if (!existsSync(resolve(cwd, file))) return bad(`No ${file}`, "Make one that default-exports defineConfig({ ... }); see docs/cli.md.");
119
+ try {
120
+ return await loadConfig(cwd, path);
121
+ } catch (error) {
122
+ return bad(`${file} does not load`, messageOf(error));
123
+ }
124
+ }
125
+ /**
126
+ * Looks over a setup and says what is missing, each with its fix: the config, its model,
127
+ * connection and store, the seal secret, the React peers and the shadcn base. It only reads. The
128
+ * exit code is 0 when everything is in place, 1 when something needs fixing.
129
+ */
130
+ async function doctor(io, flags, env = process.env) {
131
+ const config = await configOrFinding(io.cwd, flags.config);
132
+ const findings = [
133
+ ..."ok" in config ? [config] : await configured(config),
134
+ secret(env),
135
+ ...peers(io.cwd),
136
+ ...shadcn(io.cwd),
137
+ ...layers(io.cwd)
138
+ ];
139
+ for (const f of findings) if (f.ok) io.out(` ok ${f.what}`);
140
+ else io.out(` fix ${f.what}\n → ${f.fix}`);
141
+ const left = findings.filter((f) => !f.ok).length;
142
+ io.out(left === 0 ? "Everything here is in place." : `${String(left)} to fix.`);
143
+ io.out("Not checked here: where the handler is mounted and the React provider. Open the app: a wrong mount says NO_HANDLER, a page from another origin names trustedOrigins.");
144
+ if ("close" in config) await config.close?.();
145
+ return left === 0 ? 0 : 1;
146
+ }
147
+ export { configured, doctor };
@@ -49,14 +49,14 @@ const Input = z.union([z.string().transform((name) => ({
49
49
  filter: void 0
50
50
  })), z.object({
51
51
  name: z.string(),
52
- filter: z.unknown()
52
+ filter: z.unknown().optional()
53
53
  })]);
54
54
  const Metric = z.object({
55
55
  name: z.string(),
56
56
  type: z.string(),
57
57
  label: text,
58
58
  description: text,
59
- filter: z.unknown(),
59
+ filter: z.unknown().optional(),
60
60
  type_params: z.object({
61
61
  measure: opt(Input),
62
62
  numerator: opt(Input),
@@ -22,7 +22,7 @@ async function manifestPath(path) {
22
22
  async function readDbt(path) {
23
23
  const file = await manifestPath(path);
24
24
  const parsed = ManifestSchema.safeParse(JSON.parse(await readFile(file, "utf8")));
25
- if (!parsed.success) throw new Error(`${file} is not a dbt semantic manifest: ${parsed.error.issues[0]?.message ?? ""}`);
25
+ if (!parsed.success) throw new Error(`${file} is not a dbt semantic manifest:\n${parsed.error.issues.map((i) => ` ${i.path.map(String).join(".") || "(top)"}: ${i.message}`).join("\n")}`);
26
26
  return importDbt(parsed.data);
27
27
  }
28
28
  const YAML = /* @__PURE__ */ new Set([".yml", ".yaml"]);
@@ -48,7 +48,7 @@ async function cubeFile(file, name) {
48
48
  return parsed.success ? {
49
49
  cubes: [parsed.data],
50
50
  notes: []
51
- } : skipped(`Not imported: ${name}, which is not a Cube model (${parsed.error.issues[0]?.message ?? ""}).`);
51
+ } : skipped(`Not imported: ${name}, which is not a Cube model (${parsed.error.issues.slice(0, 3).map((i) => `${i.path.map(String).join(".") || "(top)"}: ${i.message}`).join("; ")}).`);
52
52
  } catch (error) {
53
53
  return skipped(`Not imported: ${name}, which does not parse as YAML (templated?): ${error instanceof Error ? error.message : String(error)}`);
54
54
  }
package/dist/cli/init.mjs CHANGED
@@ -5,9 +5,9 @@ import { catalogOf } from "./import/catalog.mjs";
5
5
  import { proposeModel } from "./propose.mjs";
6
6
  import { renderModel } from "./render.mjs";
7
7
  import { existsSync } from "node:fs";
8
- import { resolve } from "node:path";
8
+ import { dirname, resolve } from "node:path";
9
9
  import { validateModel } from "derive-dashboards/core";
10
- import { writeFile } from "node:fs/promises";
10
+ import { mkdir, writeFile } from "node:fs/promises";
11
11
  // src/init.ts
12
12
  /** The tenant keys and their columns; none for an app of one tenant. */
13
13
  function tenantOf(pairs) {
@@ -20,6 +20,7 @@ function tenantOf(pairs) {
20
20
  async function writeNew(io, file, text, force) {
21
21
  const path = resolve(io.cwd, file);
22
22
  if (existsSync(path) && !force) throw new Error(`${file} exists. Pass --force to overwrite it.`);
23
+ await mkdir(dirname(path), { recursive: true });
23
24
  await writeFile(path, text);
24
25
  io.out(`Wrote ${file}.`);
25
26
  }
@@ -0,0 +1,21 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { z } from "zod";
3
+ // src/json.ts
4
+ /** A JSON file read as `schema` says it is; throws when it is not JSON or not that shape. */
5
+ function readJson(file, schema) {
6
+ return schema.parse(JSON.parse(readFileSync(file, "utf8")));
7
+ }
8
+ const deps = z.record(z.string(), z.string()).optional();
9
+ /** The parts of a package.json the CLI reads. */
10
+ const PackageJson = z.object({
11
+ version: z.string().optional(),
12
+ dependencies: deps,
13
+ devDependencies: deps
14
+ });
15
+ /** The parts of a shadcn app's components.json the CLI reads. */
16
+ const ComponentsJson = z.object({
17
+ base: z.string().optional(),
18
+ style: z.string().optional(),
19
+ tailwind: z.object({ css: z.string().optional() }).optional()
20
+ });
21
+ export { ComponentsJson, PackageJson, readJson };
@@ -0,0 +1,33 @@
1
+ import { ComponentsJson, readJson } from "./json.mjs";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ // src/layers.ts
5
+ /** The cascade layer order a Tailwind app names once, so the theme sits above Tailwind's reset. */
6
+ const LAYER_LINE = "@layer theme, base, derive-dashboards, components, utilities;";
7
+ /** The app's Tailwind stylesheet, from components.json (`tailwind.css`), when it has one. */
8
+ function stylesheetOf(cwd) {
9
+ try {
10
+ const css = readJson(join(cwd, "components.json"), ComponentsJson).tailwind?.css;
11
+ return css !== void 0 && existsSync(join(cwd, css)) ? css : void 0;
12
+ } catch {
13
+ return;
14
+ }
15
+ }
16
+ /**
17
+ * Whether a Tailwind app's stylesheet names the layer order with the theme between Tailwind's
18
+ * reset and its utilities: undefined when the app has no Tailwind stylesheet to read.
19
+ */
20
+ function layerOrder(cwd) {
21
+ const file = stylesheetOf(cwd);
22
+ if (file === void 0) return void 0;
23
+ const text = readFileSync(join(cwd, file), "utf8");
24
+ if (!text.includes("tailwindcss")) return void 0;
25
+ const order = /@layer\s+([\w\s,-]+);/u.exec(text)?.[1]?.split(",").map((s) => s.trim());
26
+ const at = (name) => order?.indexOf(name) ?? -1;
27
+ const dd = at("derive-dashboards");
28
+ return {
29
+ file,
30
+ ok: dd > at("base") && at("base") >= 0 && (at("utilities") < 0 || dd < at("utilities"))
31
+ };
32
+ }
33
+ export { LAYER_LINE, layerOrder };
@@ -1,3 +1,4 @@
1
+ import { Model } from "../model/types.mjs";
1
2
  import { LockEntry } from "../query/compose.mjs";
2
3
  import { BoundFilter } from "../query/filter.mjs";
3
4
  import { Calendar, WireQuery } from "../query/types.mjs";
@@ -9,4 +10,6 @@ export type KitCase = {
9
10
  principal: Principal;
10
11
  locks: readonly LockEntry<BoundFilter>[];
11
12
  calendar: Calendar;
13
+ /** The model the case reads: the dataset's when absent, the drill's widened one for a drill. */
14
+ model?: Model;
12
15
  };