derive-dashboards 0.5.1 → 0.7.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 (342) hide show
  1. package/README.md +4 -2
  2. package/dist/body.mjs +2 -2
  3. package/dist/charts/data/buckets.d.mts +11 -0
  4. package/dist/charts/data/buckets.mjs +66 -0
  5. package/dist/charts/data/clean.mjs +55 -0
  6. package/dist/charts/data/format.d.mts +19 -0
  7. package/dist/charts/data/format.mjs +174 -0
  8. package/dist/charts/data/input-error.d.mts +5 -0
  9. package/dist/charts/data/input-error.mjs +11 -0
  10. package/dist/charts/data/range.mjs +14 -0
  11. package/dist/charts/data/rows.d.mts +13 -0
  12. package/dist/charts/data/rows.mjs +31 -0
  13. package/dist/charts/data/shares.mjs +55 -0
  14. package/dist/charts/data/types.d.mts +106 -0
  15. package/dist/charts/data/words.d.mts +44 -0
  16. package/dist/charts/data/words.mjs +31 -0
  17. package/dist/charts/describe.mjs +110 -0
  18. package/dist/charts/index.d.mts +34 -0
  19. package/dist/charts/index.mjs +24 -0
  20. package/dist/charts/kinds/area-marks.mjs +120 -0
  21. package/dist/charts/kinds/area.d.mts +23 -0
  22. package/dist/charts/kinds/area.mjs +71 -0
  23. package/dist/charts/kinds/bars-data.d.mts +11 -0
  24. package/dist/charts/kinds/bars-data.mjs +30 -0
  25. package/dist/charts/kinds/bars-layout.mjs +30 -0
  26. package/dist/charts/kinds/bars-marks.mjs +93 -0
  27. package/dist/charts/kinds/bars-words.mjs +56 -0
  28. package/dist/charts/kinds/bars.d.mts +17 -0
  29. package/dist/charts/kinds/bars.mjs +68 -0
  30. package/dist/charts/kinds/columns-data.mjs +116 -0
  31. package/dist/charts/kinds/columns-layout.mjs +29 -0
  32. package/dist/charts/kinds/columns-marks.mjs +200 -0
  33. package/dist/charts/kinds/columns-words.mjs +26 -0
  34. package/dist/charts/kinds/columns.d.mts +13 -0
  35. package/dist/charts/kinds/columns.mjs +80 -0
  36. package/dist/charts/kinds/dumbbell-data.d.mts +22 -0
  37. package/dist/charts/kinds/dumbbell-data.mjs +59 -0
  38. package/dist/charts/kinds/dumbbell-layout.mjs +113 -0
  39. package/dist/charts/kinds/dumbbell-marks.mjs +119 -0
  40. package/dist/charts/kinds/dumbbell-words.d.mts +7 -0
  41. package/dist/charts/kinds/dumbbell-words.mjs +94 -0
  42. package/dist/charts/kinds/dumbbell.d.mts +14 -0
  43. package/dist/charts/kinds/dumbbell.mjs +67 -0
  44. package/dist/charts/kinds/funnel-data.d.mts +11 -0
  45. package/dist/charts/kinds/funnel-data.mjs +70 -0
  46. package/dist/charts/kinds/funnel-layout.mjs +32 -0
  47. package/dist/charts/kinds/funnel-marks.mjs +204 -0
  48. package/dist/charts/kinds/funnel-words.mjs +77 -0
  49. package/dist/charts/kinds/funnel.d.mts +11 -0
  50. package/dist/charts/kinds/funnel.mjs +75 -0
  51. package/dist/charts/kinds/grid-data.d.mts +18 -0
  52. package/dist/charts/kinds/grid-data.mjs +35 -0
  53. package/dist/charts/kinds/grid-layout.mjs +77 -0
  54. package/dist/charts/kinds/grid-marks.mjs +140 -0
  55. package/dist/charts/kinds/grid-time.mjs +41 -0
  56. package/dist/charts/kinds/grid-words.mjs +86 -0
  57. package/dist/charts/kinds/grid.d.mts +22 -0
  58. package/dist/charts/kinds/grid.mjs +55 -0
  59. package/dist/charts/kinds/histogram-data.mjs +142 -0
  60. package/dist/charts/kinds/histogram-layout.mjs +144 -0
  61. package/dist/charts/kinds/histogram-marks.mjs +110 -0
  62. package/dist/charts/kinds/histogram-words.mjs +104 -0
  63. package/dist/charts/kinds/histogram.d.mts +15 -0
  64. package/dist/charts/kinds/histogram.mjs +47 -0
  65. package/dist/charts/kinds/line-marks.mjs +36 -0
  66. package/dist/charts/kinds/line.d.mts +17 -0
  67. package/dist/charts/kinds/line.mjs +52 -0
  68. package/dist/charts/kinds/multiples-grid.mjs +107 -0
  69. package/dist/charts/kinds/multiples-head.mjs +44 -0
  70. package/dist/charts/kinds/multiples-layout.mjs +159 -0
  71. package/dist/charts/kinds/multiples-marks.mjs +95 -0
  72. package/dist/charts/kinds/multiples-words.mjs +110 -0
  73. package/dist/charts/kinds/multiples.d.mts +26 -0
  74. package/dist/charts/kinds/multiples.mjs +42 -0
  75. package/dist/charts/kinds/row-chart.mjs +112 -0
  76. package/dist/charts/kinds/row-marks.mjs +121 -0
  77. package/dist/charts/kinds/scatter-data.d.mts +18 -0
  78. package/dist/charts/kinds/scatter-data.mjs +123 -0
  79. package/dist/charts/kinds/scatter-layout.mjs +189 -0
  80. package/dist/charts/kinds/scatter-marks.mjs +149 -0
  81. package/dist/charts/kinds/scatter-words.mjs +80 -0
  82. package/dist/charts/kinds/scatter.d.mts +21 -0
  83. package/dist/charts/kinds/scatter.mjs +72 -0
  84. package/dist/charts/kinds/stat-data.mjs +91 -0
  85. package/dist/charts/kinds/stat-layout.mjs +108 -0
  86. package/dist/charts/kinds/stat-marks.mjs +85 -0
  87. package/dist/charts/kinds/stat-words.mjs +57 -0
  88. package/dist/charts/kinds/stat.d.mts +28 -0
  89. package/dist/charts/kinds/stat.mjs +35 -0
  90. package/dist/charts/kinds/time-chart.mjs +74 -0
  91. package/dist/charts/kinds/time-frame.mjs +113 -0
  92. package/dist/charts/kinds/time-notes.mjs +36 -0
  93. package/dist/charts/kinds/time-plan.d.mts +8 -0
  94. package/dist/charts/kinds/time-plan.mjs +57 -0
  95. package/dist/charts/kinds/time-plot.mjs +56 -0
  96. package/dist/charts/kinds/time-stops.mjs +56 -0
  97. package/dist/charts/kinds/value-plot.mjs +33 -0
  98. package/dist/charts/kinds/waterfall-data.d.mts +7 -0
  99. package/dist/charts/kinds/waterfall-data.mjs +71 -0
  100. package/dist/charts/kinds/waterfall-layout.mjs +38 -0
  101. package/dist/charts/kinds/waterfall-marks.mjs +82 -0
  102. package/dist/charts/kinds/waterfall-words.mjs +118 -0
  103. package/dist/charts/kinds/waterfall.d.mts +17 -0
  104. package/dist/charts/kinds/waterfall.mjs +66 -0
  105. package/dist/charts/layout/boxes.mjs +28 -0
  106. package/dist/charts/layout/dodge.mjs +75 -0
  107. package/dist/charts/layout/extent.mjs +25 -0
  108. package/dist/charts/layout/frame.mjs +97 -0
  109. package/dist/charts/layout/place-labels.mjs +101 -0
  110. package/dist/charts/layout/stack.mjs +31 -0
  111. package/dist/charts/marks/axes.mjs +137 -0
  112. package/dist/charts/marks/dot.mjs +31 -0
  113. package/dist/charts/marks/end-labels.mjs +124 -0
  114. package/dist/charts/marks/legend.mjs +141 -0
  115. package/dist/charts/marks/lines.d.mts +2 -0
  116. package/dist/charts/marks/lines.mjs +38 -0
  117. package/dist/charts/marks/lit.d.mts +3 -0
  118. package/dist/charts/marks/lit.mjs +63 -0
  119. package/dist/charts/marks/more.mjs +18 -0
  120. package/dist/charts/marks/notes.mjs +253 -0
  121. package/dist/charts/marks/series-line.mjs +110 -0
  122. package/dist/charts/marks/thin.mjs +138 -0
  123. package/dist/charts/marks/x-axis.mjs +32 -0
  124. package/dist/charts/scale/calendar.mjs +174 -0
  125. package/dist/charts/scale/time-ticks.mjs +154 -0
  126. package/dist/charts/scale/time.mjs +33 -0
  127. package/dist/charts/scale/value.mjs +161 -0
  128. package/dist/charts/scene/defs.mjs +33 -0
  129. package/dist/charts/scene/markup.mjs +35 -0
  130. package/dist/charts/scene/nearest.d.mts +11 -0
  131. package/dist/charts/scene/nearest.mjs +49 -0
  132. package/dist/charts/scene/paint.d.mts +12 -0
  133. package/dist/charts/scene/paint.mjs +13 -0
  134. package/dist/charts/scene/svg.d.mts +18 -0
  135. package/dist/charts/scene/svg.mjs +185 -0
  136. package/dist/charts/scene/types.d.mts +177 -0
  137. package/dist/charts/text/measure.d.mts +9 -0
  138. package/dist/charts/text/measure.mjs +123 -0
  139. package/dist/charts/theme.d.mts +47 -0
  140. package/dist/charts/theme.mjs +239 -0
  141. package/dist/charts-react/Chart.d.mts +91 -0
  142. package/dist/charts-react/Chart.mjs +166 -0
  143. package/dist/charts-react/Overlay.mjs +171 -0
  144. package/dist/charts-react/Picture.mjs +22 -0
  145. package/dist/charts-react/Reader.mjs +147 -0
  146. package/dist/charts-react/bucket-names.mjs +29 -0
  147. package/dist/charts-react/chart-unlayered.css +1 -0
  148. package/dist/charts-react/chart-unlayered.css.d.ts +1 -0
  149. package/dist/charts-react/chart.css +1 -0
  150. package/dist/charts-react/chart.css.d.ts +1 -0
  151. package/dist/charts-react/events.mjs +72 -0
  152. package/dist/charts-react/exact-sum.mjs +24 -0
  153. package/dist/charts-react/from-answer.mjs +185 -0
  154. package/dist/charts-react/index.d.mts +3 -0
  155. package/dist/charts-react/index.mjs +4 -0
  156. package/dist/charts-react/keys.mjs +117 -0
  157. package/dist/charts-react/opens.mjs +28 -0
  158. package/dist/charts-react/plan-bars.mjs +95 -0
  159. package/dist/charts-react/plan-funnel.mjs +120 -0
  160. package/dist/charts-react/plan-grid.mjs +121 -0
  161. package/dist/charts-react/plan-parts.d.mts +2 -0
  162. package/dist/charts-react/plan-parts.mjs +30 -0
  163. package/dist/charts-react/plan-time.mjs +84 -0
  164. package/dist/charts-react/plan.d.mts +3 -0
  165. package/dist/charts-react/plan.mjs +37 -0
  166. package/dist/charts-react/point-keys.mjs +22 -0
  167. package/dist/charts-react/pointer.mjs +99 -0
  168. package/dist/charts-react/reader-page.d.mts +8 -0
  169. package/dist/charts-react/reader-page.mjs +116 -0
  170. package/dist/charts-react/tiles.d.mts +24 -0
  171. package/dist/charts-react/tiles.mjs +142 -0
  172. package/dist/charts-react/tip-place.mjs +107 -0
  173. package/dist/charts-react/tip-room.mjs +31 -0
  174. package/dist/charts-react/useClientLayoutEffect.mjs +8 -0
  175. package/dist/charts-react/useScene.mjs +76 -0
  176. package/dist/charts-react/useSize.mjs +44 -0
  177. package/dist/charts-react/useStop.mjs +68 -0
  178. package/dist/core/conformance/memory/aggregate.mjs +2 -1
  179. package/dist/core/conformance/memory/rows.mjs +1 -1
  180. package/dist/core/conformance/memory/source.mjs +3 -2
  181. package/dist/core/document/display-comparisons.mjs +49 -0
  182. package/dist/core/document/display-entries.mjs +2 -1
  183. package/dist/core/document/display-validation.d.mts +12 -0
  184. package/dist/core/document/display-validation.mjs +56 -0
  185. package/dist/core/document/display.d.mts +27 -12
  186. package/dist/core/document/display.mjs +40 -49
  187. package/dist/core/document/view-layout.mjs +16 -0
  188. package/dist/core/engine/access.mjs +4 -2
  189. package/dist/core/engine/context.mjs +5 -7
  190. package/dist/core/engine/custom/cells.mjs +1 -1
  191. package/dist/core/engine/custom/records.mjs +2 -1
  192. package/dist/core/engine/dialect.d.mts +2 -0
  193. package/dist/core/engine/index.mjs +1 -1
  194. package/dist/core/engine/levels.mjs +33 -1
  195. package/dist/core/engine/plan.d.mts +2 -0
  196. package/dist/core/engine/postgres.mjs +1 -0
  197. package/dist/core/engine/rank.mjs +1 -1
  198. package/dist/core/engine/reader.d.mts +4 -0
  199. package/dist/core/engine/sql-partition.mjs +45 -0
  200. package/dist/core/engine/sql-reads.mjs +4 -1
  201. package/dist/core/engine/statement.mjs +4 -4
  202. package/dist/core/engine/version.d.mts +1 -1
  203. package/dist/core/engine/version.mjs +1 -1
  204. package/dist/core/error/codes.d.mts +1 -1
  205. package/dist/core/error/codes.mjs +1 -1
  206. package/dist/core/exact/decimal.d.mts +1 -4
  207. package/dist/core/exact/decimal.mjs +1 -14
  208. package/dist/core/exact/text.d.mts +5 -0
  209. package/dist/core/exact/text.mjs +19 -0
  210. package/dist/core/index.d.mts +9 -6
  211. package/dist/core/index.mjs +11 -8
  212. package/dist/core/model/types.d.mts +2 -0
  213. package/dist/core/model/validate/fields.mjs +1 -1
  214. package/dist/core/model/validate/known-members.mjs +2 -0
  215. package/dist/core/model/validate/shape.mjs +5 -1
  216. package/dist/core/oracle/visibility.mjs +2 -2
  217. package/dist/core/policy/bind.mjs +29 -1
  218. package/dist/core/query/drill/compose.d.mts +2 -0
  219. package/dist/core/query/drill/compose.mjs +1 -1
  220. package/dist/core/query/drill/synthetic.mjs +2 -1
  221. package/dist/core/query/drill/types.d.mts +7 -0
  222. package/dist/core/query/drill/types.mjs +3 -1
  223. package/dist/core/result/number.mjs +2 -1
  224. package/dist/core/result/time-axis.mjs +2 -1
  225. package/dist/core/schema/answers.d.mts +1176 -362
  226. package/dist/core/schema/commands.mjs +2 -1
  227. package/dist/core/schema/document.mjs +27 -2
  228. package/dist/core/schema/drill-answers.mjs +19 -1
  229. package/dist/core/schema/drill.d.mts +21 -6
  230. package/dist/core/schema/drill.mjs +7 -1
  231. package/dist/core/schema/index.d.mts +2 -1
  232. package/dist/core/schema/index.mjs +2 -1
  233. package/dist/core/schema/null-ops.d.mts +6 -0
  234. package/dist/core/schema/null-ops.mjs +18 -0
  235. package/dist/core/schema/query.mjs +30 -4
  236. package/dist/core/schema/tools.mjs +13 -0
  237. package/dist/core/schema/union-error.mjs +38 -0
  238. package/dist/core/time/bucket.mjs +2 -1
  239. package/dist/core/time/index.d.mts +3 -2
  240. package/dist/core/time/instant.d.mts +1 -2
  241. package/dist/core/time/instant.mjs +2 -30
  242. package/dist/core/time/range.mjs +2 -1
  243. package/dist/core/time/stored.mjs +2 -1
  244. package/dist/core/time/text-time.d.mts +10 -0
  245. package/dist/core/time/text-time.mjs +80 -0
  246. package/dist/core/types/api.d.mts +1 -1
  247. package/dist/core/types/api.mjs +1 -1
  248. package/dist/core/types/drill-api.d.mts +22 -2
  249. package/dist/dashboard-documents.d.mts +8 -0
  250. package/dist/dashboard-documents.mjs +52 -0
  251. package/dist/drill-access.mjs +40 -3
  252. package/dist/drill-comparison.mjs +71 -0
  253. package/dist/drill-crumbs.mjs +21 -2
  254. package/dist/drill-group-seal.mjs +13 -0
  255. package/dist/drill-open.mjs +7 -1
  256. package/dist/drill-seal.mjs +4 -6
  257. package/dist/drill-views.mjs +5 -13
  258. package/dist/drill.mjs +28 -58
  259. package/dist/editing.mjs +1 -1
  260. package/dist/endpoints/drill.mjs +2 -3
  261. package/dist/endpoints/index.d.mts +20 -0
  262. package/dist/index.d.mts +2 -1
  263. package/dist/index.mjs +6 -27
  264. package/dist/llms.txt +1 -1
  265. package/dist/react/Cell.mjs +2 -2
  266. package/dist/react/DashboardList.mjs +3 -3
  267. package/dist/react/Editing.mjs +3 -3
  268. package/dist/react/Header.mjs +2 -2
  269. package/dist/react/History.mjs +3 -3
  270. package/dist/react/Parts.mjs +2 -2
  271. package/dist/react/RowBody.d.mts +2 -4
  272. package/dist/react/RowBody.mjs +14 -39
  273. package/dist/react/Tile.mjs +4 -5
  274. package/dist/react/builder/FilterEditor.mjs +2 -2
  275. package/dist/react/builder/Picker.mjs +3 -3
  276. package/dist/react/builder/RangeEditor.mjs +3 -3
  277. package/dist/react/builder/Time.mjs +3 -3
  278. package/dist/react/builder/Values.mjs +2 -2
  279. package/dist/react/builder/WidgetBuilder.mjs +2 -2
  280. package/dist/react/digits.mjs +1 -1
  281. package/dist/react/drill/Bars.mjs +34 -38
  282. package/dist/react/drill/Comparison.mjs +204 -0
  283. package/dist/react/drill/Controls.mjs +8 -12
  284. package/dist/react/drill/DrillDrawer.mjs +42 -0
  285. package/dist/react/drill/DrillPanel.mjs +61 -41
  286. package/dist/react/drill/Header.mjs +65 -35
  287. package/dist/react/drill/ItemLink.mjs +40 -0
  288. package/dist/react/drill/Items.d.mts +2 -1
  289. package/dist/react/drill/Items.mjs +126 -99
  290. package/dist/react/drill/ItemsBody.mjs +38 -0
  291. package/dist/react/drill/ItemsFoot.mjs +24 -19
  292. package/dist/react/drill/Notes.mjs +23 -13
  293. package/dist/react/drill/PanelBody.mjs +7 -25
  294. package/dist/react/drill/RecordRow.mjs +47 -0
  295. package/dist/react/drill/Trend.mjs +186 -0
  296. package/dist/react/drill/board.mjs +21 -11
  297. package/dist/react/drill/drawer-context.mjs +5 -0
  298. package/dist/react/drill/item-parts.mjs +53 -35
  299. package/dist/react/drill/item-type.d.mts +2 -2
  300. package/dist/react/drill/lazy.d.mts +1 -4
  301. package/dist/react/drill/lazy.mjs +29 -11
  302. package/dist/react/drill/panel-focus.mjs +18 -7
  303. package/dist/react/drill/props.d.mts +7 -1
  304. package/dist/react/drill/props.mjs +39 -8
  305. package/dist/react/drill/record-page.mjs +61 -0
  306. package/dist/react/drill/state.mjs +17 -2
  307. package/dist/react/drill/trend-touch.mjs +33 -0
  308. package/dist/react/drill/useDrill.d.mts +3 -3
  309. package/dist/react/drill/useDrill.mjs +35 -15
  310. package/dist/react/drill/words.d.mts +14 -0
  311. package/dist/react/drill/words.mjs +20 -8
  312. package/dist/react/english.d.mts +4 -1
  313. package/dist/react/english.mjs +17 -2
  314. package/dist/react/filters/chip.mjs +2 -2
  315. package/dist/react/filters/menu-search.mjs +5 -5
  316. package/dist/react/filters/menu.mjs +2 -2
  317. package/dist/react/filters/number.mjs +2 -2
  318. package/dist/react/filters/operator.mjs +2 -2
  319. package/dist/react/filters/phone.mjs +2 -2
  320. package/dist/react/filters/values.mjs +4 -4
  321. package/dist/react/format-time.d.mts +2 -1
  322. package/dist/react/format-time.mjs +42 -34
  323. package/dist/react/format.mjs +15 -3
  324. package/dist/react/index.d.mts +4 -3
  325. package/dist/react/index.mjs +4 -3
  326. package/dist/react/messages.d.mts +23 -2
  327. package/dist/react/renderers/entries.d.mts +11 -0
  328. package/dist/react/renderers/list.mjs +8 -10
  329. package/dist/react/renderers/table-cells.mjs +38 -9
  330. package/dist/react/renderers/table-measure.mjs +2 -0
  331. package/dist/react/renderers/table-row.mjs +64 -7
  332. package/dist/react/renderers/table-sort.mjs +2 -8
  333. package/dist/react/renderers/table.mjs +16 -15
  334. package/dist/react/series.mjs +8 -3
  335. package/dist/react/theme-unlayered.css +1 -3144
  336. package/dist/react/theme.css +1 -3146
  337. package/dist/recharts/parts.mjs +1 -1
  338. package/dist/skills/derive-dashboards/SKILL.md +10 -5
  339. package/dist/store/apply.mjs +2 -2
  340. package/dist/store/editor.mjs +2 -2
  341. package/dist/store/writer.mjs +2 -2
  342. package/package.json +27 -2
@@ -0,0 +1,52 @@
1
+ import { displayOf, documentDisplayIssues, resolveDimension } from "derive-dashboards/core";
2
+ import { loadDocument } from "derive-dashboards/core/schema";
3
+ // src/dashboard-documents.ts
4
+ function declaredValues(model, source, member) {
5
+ const dimension = resolveDimension(model, source, member)?.dimension;
6
+ if (dimension?.kind !== "string" || typeof dimension.values === "string") return;
7
+ return dimension.values;
8
+ }
9
+ /** Declared filter choices can catch an authoring typo. Rows may still contain other values. */
10
+ function comparisonKeyHints(doc, model) {
11
+ return Object.entries(doc.widgets).flatMap(([id, widget]) => {
12
+ if (widget.kind !== "table") return [];
13
+ const groups = displayOf("table", widget.display).comparisons;
14
+ const query = widget.queries["main"];
15
+ const member = query?.dimensions?.[0]?.member;
16
+ if (!groups || !query || member === void 0) return [];
17
+ const choices = declaredValues(model, query.source, member);
18
+ if (!choices) return [];
19
+ return Object.keys(groups).filter((key) => !choices.includes(key)).map((key) => `widgets.${id}.display.comparisons: "${key}" is outside the declared choices for "${member}" (${choices.join(", ")}). This action appears only on an exact group value match.`);
20
+ });
21
+ }
22
+ /** A host configuration error raised before the server handles any request. */
23
+ var DashboardDocumentError = class extends Error {
24
+ dashboardKey;
25
+ issues;
26
+ code = "DOCUMENT_INVALID";
27
+ constructor(dashboardKey, reason, issues) {
28
+ const problems = issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ");
29
+ super(`The dashboard "${dashboardKey}" ${reason}: ${problems}`);
30
+ this.dashboardKey = dashboardKey;
31
+ this.issues = issues;
32
+ this.name = "DashboardDocumentError";
33
+ }
34
+ };
35
+ /**
36
+ * Code-defined dashboards are checked when the handler is made, not when a viewer opens one: an
37
+ * invalid document stops the server with every problem named, and a layout is repaired once.
38
+ */
39
+ function checkedDashboards(options, model) {
40
+ return (options.dashboards ?? []).map((d) => {
41
+ const loaded = loadDocument(d.document);
42
+ if (!loaded.ok) throw new DashboardDocumentError(d.key, "is not a valid document", loaded.issues);
43
+ const wrong = documentDisplayIssues(loaded.doc, model);
44
+ if (wrong.length > 0) throw new DashboardDocumentError(d.key, "has display options to fix", wrong);
45
+ for (const hint of comparisonKeyHints(loaded.doc, model)) console.warn(`Dashboard "${d.key}": ${hint}`);
46
+ return {
47
+ key: d.key,
48
+ document: loaded.doc
49
+ };
50
+ });
51
+ }
52
+ export { DashboardDocumentError, checkedDashboards };
@@ -1,7 +1,7 @@
1
1
  import { execute } from "./execute.mjs";
2
2
  import { HttpError } from "./http.mjs";
3
- import { queryClosure } from "derive-dashboards/core";
4
- import { drillOwner, stepMembers } from "derive-dashboards/core/engine";
3
+ import { queryClosure, resultColumns } from "derive-dashboards/core";
4
+ import { drillOwner, lineFilter, offeredMembers, pathFields, stepMembers } from "derive-dashboards/core/engine";
5
5
  // src/drill-access.ts
6
6
  /** Which fields this viewer may see in a drill: never a sensitive one (Rules, section 6). */
7
7
  const readableFor = (_x) => (_member, def) => def.sensitive !== true;
@@ -90,4 +90,41 @@ function mayList(o, source) {
90
90
  source
91
91
  }));
92
92
  }
93
- export { clockOf, drillRead, mayList, mayRead, readableColumns, readableFor, running };
93
+ /** Label the offered dimensions in the same context as the result columns. */
94
+ function labelledFields(o, kept) {
95
+ const model = o.x.rt.options.model;
96
+ const dimensions = kept.map((member, i) => ({
97
+ id: `d${i + 1}`,
98
+ member
99
+ }));
100
+ const columns = resultColumns(model, {
101
+ ...o.x.query,
102
+ dimensions
103
+ });
104
+ return kept.map((id, i) => ({
105
+ id,
106
+ label: columns.find((c) => c.id === `d${i + 1}`)?.label ?? id
107
+ }));
108
+ }
109
+ /** A comparison reads all measures. A single-measure breakdown also excludes fields fixed by that line. */
110
+ function offeredIds(o, set) {
111
+ const model = o.x.rt.options.model;
112
+ const where = set && lineFilter(model, set, o.drill, { operand: false });
113
+ return offeredMembers(model, o.x.query, {
114
+ ...pathFields(o.drill.steps),
115
+ where
116
+ }, readableFor(o.x));
117
+ }
118
+ async function readableIds(o, ids) {
119
+ const allowed = await Promise.all(ids.map((id) => mayRead(o, id)));
120
+ return ids.filter((_id, i) => allowed[i] === true);
121
+ }
122
+ /**
123
+ * The fields Breakdown offers this viewer at this step, each labelled as a column of the tile
124
+ * would read it: the model's preferred and small-valued fields the tile, the path and the line's
125
+ * own measure do not fix, the field an Other was cut on first, each one the viewer may read.
126
+ */
127
+ async function offeredFields(o, set) {
128
+ return labelledFields(o, await readableIds(o, offeredIds(o, set)));
129
+ }
130
+ export { clockOf, drillRead, labelledFields, mayList, mayRead, offeredFields, offeredIds, readableColumns, readableFor, readableIds, running };
@@ -0,0 +1,71 @@
1
+ import { clockOf, drillRead, labelledFields, mayRead, offeredIds, readableFor, readableIds } from "./drill-access.mjs";
2
+ import { crumbs, forOpener, normalizedDrillState } from "./drill-crumbs.mjs";
3
+ import { sealedView } from "./drill-group-seal.mjs";
4
+ import { visibleSelection } from "./drill-open.mjs";
5
+ import { numberOf } from "./drill-totals.mjs";
6
+ import { wire } from "./execute.mjs";
7
+ import { EngineError, breakdownQuery, composeDrill, countQuery } from "derive-dashboards/core/engine";
8
+ // src/drill-comparison.ts
9
+ /** A shared group must contain rows visible to its opener before its name can be shown. */
10
+ function comparisonScope(scope) {
11
+ return visibleSelection(scope, async (o, checkRows) => {
12
+ const set = composeDrill({
13
+ model: o.x.rt.options.model,
14
+ query: o.x.query,
15
+ drill: o.drill,
16
+ comparison: true,
17
+ readable: readableFor(o.x),
18
+ clock: clockOf(o.x)
19
+ });
20
+ const count = checkRows ? await drillRead(o, countQuery(set)) : void 0;
21
+ return {
22
+ value: {
23
+ o,
24
+ set
25
+ },
26
+ empty: (numberOf(count?.rows[0]?.[0]) ?? 0) <= 0
27
+ };
28
+ });
29
+ }
30
+ async function fieldsFor(o, view) {
31
+ const offered = offeredIds(o);
32
+ const check = async (field) => {
33
+ if (offered.includes(field) && await mayRead(o, field)) return;
34
+ const choices = await readableIds(o, offered);
35
+ const hint = choices.length > 0 ? `Available breakdown fields: ${choices.join(", ")}.` : "No breakdown fields are available.";
36
+ throw new EngineError("DRILL_UNSUPPORTED", `Cannot group this selection by "${field}". ${hint}`);
37
+ };
38
+ await check(view.member);
39
+ const id = view.thenBy;
40
+ if (id === void 0) return;
41
+ if (id === view.member) throw new EngineError("DRILL_UNSUPPORTED", "Choose a different field to expand the group.");
42
+ await check(id);
43
+ return labelledFields(o, [id])[0];
44
+ }
45
+ /** Regroup the selected rows. Every measure keeps its own filter and denominator. */
46
+ async function compareGroups(opened, state, requested) {
47
+ const { o, set } = await comparisonScope(opened);
48
+ const thenBy = await fieldsFor(o, requested);
49
+ const view = {
50
+ by: "comparison",
51
+ member: requested.member,
52
+ ...thenBy && { thenBy: thenBy.id }
53
+ };
54
+ const query = breakdownQuery(set, view.member, { steps: [] });
55
+ const answer = await drillRead(o, {
56
+ ...query,
57
+ total: true
58
+ }, [view.member]);
59
+ return forOpener({
60
+ state: normalizedDrillState(state, o.path, view),
61
+ path: crumbs(o),
62
+ view: {
63
+ by: "comparison",
64
+ answer: wire(answer),
65
+ drill: await sealedView(o, answer, { limited: true }),
66
+ ...thenBy && { thenBy },
67
+ ...o.omitted && { omitted: true }
68
+ }
69
+ }, o.foreign);
70
+ }
71
+ export { compareGroups };
@@ -108,6 +108,25 @@ function openerReceipts(value) {
108
108
  * rows and counts are already theirs.
109
109
  */
110
110
  function forOpener(answer, foreign) {
111
- return foreign ? openerReceipts(answer) : answer;
111
+ if (!foreign) return answer;
112
+ const trimmed = openerReceipts(answer);
113
+ return trimmed.view.by === "comparison" ? {
114
+ ...trimmed,
115
+ view: {
116
+ ...trimmed.view,
117
+ foreign: true
118
+ }
119
+ } : trimmed;
112
120
  }
113
- export { crumbs, forOpener };
121
+ /** Keep only the navigation history for the steps this viewer can still open. */
122
+ function normalizedDrillState(state, path, view) {
123
+ const { views, ...rest } = state;
124
+ const kept = views?.slice(0, Math.max(0, path.length - 1));
125
+ return {
126
+ ...rest,
127
+ path,
128
+ view,
129
+ ...kept !== void 0 && kept.length > 0 && { views: kept }
130
+ };
131
+ }
132
+ export { crumbs, forOpener, normalizedDrillState };
@@ -0,0 +1,13 @@
1
+ import { pathDigest } from "./drill-identity.mjs";
2
+ import { drawnOf, sealAnswer } from "./drill-seal.mjs";
3
+ // src/drill-group-seal.ts
4
+ /** An answer of a view sealed once, under this drill's execution and path. */
5
+ async function sealedView(o, answer, extra) {
6
+ const parent = await pathDigest(o.drill.steps);
7
+ const range = answer.receipt.range;
8
+ return sealAnswer(o.scope, drawnOf(answer, answer.rows, range, extra), {
9
+ exec: o.pinned.id,
10
+ parent
11
+ });
12
+ }
13
+ export { sealedView };
@@ -166,4 +166,10 @@ function cutTo(o, steps) {
166
166
  omitted: true
167
167
  };
168
168
  }
169
- export { cutTo, openDrill };
169
+ /** A shared link opens at the deepest selection containing rows visible to its new viewer. */
170
+ async function visibleSelection(scope, read) {
171
+ const checkRows = scope.foreign && scope.selections.length > 0;
172
+ const { value, empty } = await read(scope, checkRows);
173
+ return checkRows && empty ? visibleSelection(cutTo(scope, scope.selections.length - 1), read) : value;
174
+ }
175
+ export { cutTo, openDrill, visibleSelection };
@@ -1,12 +1,10 @@
1
1
  import { base64url, seal, unseal } from "./cursor-seal.mjs";
2
2
  import { fingerprint, pathDigest, revisionOf } from "./drill-identity.mjs";
3
3
  import { warnSecret } from "./drill-secret.mjs";
4
- import { DRILL_REASONS, parseTextTime } from "derive-dashboards/core";
4
+ import { DRILL_REASONS, MAX_DRILL_ROWS, parseTextTime } from "derive-dashboards/core";
5
5
  import { EngineError, rowSelection } from "derive-dashboards/core/engine";
6
6
  import { pinnedSchema, selectionSchema } from "derive-dashboards/core/schema";
7
7
  // src/drill-seal.ts
8
- /** An answer drills only when it is small enough to read row by row. */
9
- const MAX_SELECTIONS = 1e3;
10
8
  const bindingOf = (scope, purpose) => ({
11
9
  purpose,
12
10
  principal: scope.principal,
@@ -33,7 +31,7 @@ const slim = (c) => ({
33
31
  /** What a drawn answer's rows open to, and why the others do not. */
34
32
  function closedRows(drawn) {
35
33
  return drawn.rows.flatMap((row, i) => {
36
- if (i >= MAX_SELECTIONS) return [];
34
+ if (i >= MAX_DRILL_ROWS) return [];
37
35
  const picked = rowSelection(drawn, row);
38
36
  return "refused" in picked ? [{
39
37
  row: i,
@@ -48,7 +46,7 @@ async function sealAnswer(scope, drawn, at) {
48
46
  drawn: {
49
47
  ...drawn,
50
48
  columns: drawn.columns.map((c) => slim(c)),
51
- rows: drawn.rows.slice(0, MAX_SELECTIONS)
49
+ rows: drawn.rows.slice(0, MAX_DRILL_ROWS)
52
50
  },
53
51
  ...at
54
52
  };
@@ -113,7 +111,7 @@ async function issueDrill(scope, answer, at) {
113
111
  previous: true
114
112
  })
115
113
  ]);
116
- const cut = answer.rows.length > MAX_SELECTIONS;
114
+ const cut = answer.rows.length > MAX_DRILL_ROWS;
117
115
  return {
118
116
  execution,
119
117
  ...sealed,
@@ -1,8 +1,8 @@
1
1
  import { clockOf, drillRead } from "./drill-access.mjs";
2
2
  import { otherChange } from "./drill-change.mjs";
3
- import { pathDigest } from "./drill-identity.mjs";
4
- import { drawnOf, sealAnswer } from "./drill-seal.mjs";
3
+ import { sealedView } from "./drill-group-seal.mjs";
5
4
  import { numberOf } from "./drill-totals.mjs";
5
+ import { compareGroups } from "./drill-comparison.mjs";
6
6
  import { isMark, parseTextTime, resolveDimension } from "derive-dashboards/core";
7
7
  import { EngineError, breakdownQuery, population, trendQuery } from "derive-dashboards/core/engine";
8
8
  // src/drill-views.ts
@@ -58,15 +58,6 @@ function grainsFor(range) {
58
58
  ["year", 365]
59
59
  ].filter(([, d]) => days / d >= 2 && days / d <= 400).map(([g]) => g);
60
60
  }
61
- /** An answer of a view sealed once, under this drill's execution and path. */
62
- async function sealedView(o, answer, extra) {
63
- const parent = await pathDigest(o.drill.steps);
64
- const range = answer.receipt.range;
65
- return sealAnswer(o.scope, drawnOf(answer, answer.rows, range, extra), {
66
- exec: o.pinned.id,
67
- parent
68
- });
69
- }
70
61
  /** Over time: the line's population by its time field, at a grain that fits, its range and grains. */
71
62
  async function trendView(o, rows, view, offered) {
72
63
  const query = trendQuery(o.x.rt.options.model, rows, clockOf(o.x), view.grain);
@@ -80,7 +71,8 @@ async function trendView(o, rows, view, offered) {
80
71
  offered,
81
72
  ...time?.grain === void 0 ? {} : { grain: time.grain },
82
73
  ...range === void 0 ? {} : { range },
83
- grains: grainsFor(range)
74
+ grains: grainsFor(range),
75
+ throughNow: time !== void 0 && "last" in time.range && time.range.includeCurrent
84
76
  };
85
77
  }
86
78
  /** A Breakdown or Over time of the line's population, its answer sealed once for its clicks. */
@@ -172,4 +164,4 @@ async function readBreakdown(o, ask) {
172
164
  compared: compare !== void 0
173
165
  };
174
166
  }
175
- export { chosenView, groupedView };
167
+ export { chosenView, compareGroups, groupedView };
package/dist/drill.mjs CHANGED
@@ -1,13 +1,14 @@
1
- import { clockOf, mayRead, readableFor } from "./drill-access.mjs";
2
- import { crumbs, forOpener } from "./drill-crumbs.mjs";
1
+ import { clockOf, mayRead, offeredFields, readableFor } from "./drill-access.mjs";
2
+ import { crumbs, forOpener, normalizedDrillState } from "./drill-crumbs.mjs";
3
3
  import { explanationView } from "./drill-explain.mjs";
4
4
  import { drillItems } from "./drill-items.mjs";
5
- import { cutTo, openDrill } from "./drill-open.mjs";
5
+ import { cutTo, openDrill, visibleSelection } from "./drill-open.mjs";
6
6
  import { abilities, holdsNoRows, summarize } from "./drill-summary.mjs";
7
7
  import { chosenView, groupedView } from "./drill-views.mjs";
8
+ import { compareGroups } from "./drill-comparison.mjs";
8
9
  import { wire } from "./execute.mjs";
9
10
  import { resultColumns } from "derive-dashboards/core";
10
- import { composeDrill, drillMeasure, lineFilter, lineSemantics, offeredMembers, pathFields, stepMembers } from "derive-dashboards/core/engine";
11
+ import { composeDrill, drillMeasure, lineSemantics, stepMembers } from "derive-dashboards/core/engine";
11
12
  // src/drill.ts
12
13
  /** The drill's query and its line, for the path as it stands. */
13
14
  function composed(o) {
@@ -25,34 +26,6 @@ function composed(o) {
25
26
  };
26
27
  }
27
28
  /**
28
- * The fields Breakdown offers this viewer at this step, each labelled as a column of the tile
29
- * would read it: the model's preferred and small-valued fields the tile, the path and the line's
30
- * own measure do not fix, the field an Other was cut on first, each one the viewer may read.
31
- */
32
- async function offeredFields(o, set) {
33
- const { model } = o.x.rt.options;
34
- const where = lineFilter(model, set, o.drill, { operand: false });
35
- const path = {
36
- ...pathFields(o.drill.steps),
37
- where
38
- };
39
- const ids = offeredMembers(model, o.x.query, path, readableFor(o.x));
40
- const allowed = await Promise.all(ids.map((id) => mayRead(o, id)));
41
- const kept = ids.filter((_id, i) => allowed[i] === true);
42
- const dimensions = kept.map((member, i) => ({
43
- id: `d${i + 1}`,
44
- member
45
- }));
46
- const columns = resultColumns(model, {
47
- ...o.x.query,
48
- dimensions
49
- });
50
- return kept.map((id, i) => ({
51
- id,
52
- label: columns.find((c) => c.id === `d${i + 1}`)?.label ?? id
53
- }));
54
- }
55
- /**
56
29
  * The path cut at its first step on a field this viewer may not read: a link opened with less
57
30
  * access opens at the deepest step it can, and says part of it was left out.
58
31
  */
@@ -68,18 +41,23 @@ const needsSummary = (body) => body.summary !== false || body.state.view.by ===
68
41
  * holds no row this viewer can see, so nothing about rows they cannot see is shown, not even
69
42
  * that there are some.
70
43
  */
71
- async function ready(o, body) {
72
- const { set, line } = composed(o);
73
- const offered = await offeredFields(o, set);
74
- const summed = o.foreign || needsSummary(body) ? await summarize(o, set, line, offered) : void 0;
75
- const empty = summed !== void 0 && holdsNoRows(summed.summary);
76
- return o.foreign && empty && o.selections.length > 0 ? ready(cutTo(o, o.selections.length - 1), body) : {
77
- o,
78
- set,
79
- line,
80
- offered,
81
- ...summed === void 0 ? {} : { summed }
82
- };
44
+ function ready(scope, body) {
45
+ return visibleSelection(scope, async (o) => {
46
+ const { set, line } = composed(o);
47
+ const offered = await offeredFields(o, set);
48
+ const summed = o.foreign || needsSummary(body) ? await summarize(o, set, line, offered) : void 0;
49
+ const empty = summed !== void 0 && holdsNoRows(summed.summary);
50
+ return {
51
+ value: {
52
+ o,
53
+ set,
54
+ line,
55
+ offered,
56
+ ...summed === void 0 ? {} : { summed }
57
+ },
58
+ empty
59
+ };
60
+ });
83
61
  }
84
62
  /** The view as the drill shows it, and what it shows. */
85
63
  async function shownView(r, view, page) {
@@ -94,10 +72,7 @@ async function shownView(r, view, page) {
94
72
  column,
95
73
  only: view.numerator === true
96
74
  }, page ?? {}),
97
- view: view.numerator === true ? {
98
- by: "items",
99
- numerator: true
100
- } : { by: "items" }
75
+ view
101
76
  };
102
77
  }
103
78
  if (view.by === "explanation") {
@@ -126,12 +101,14 @@ async function shownView(r, view, page) {
126
101
  * numbers kept apart, its path as breadcrumbs, its state normalized, and the view it shows.
127
102
  */
128
103
  async function runDrill(rt, principal, request, body) {
129
- const r = await ready(await permitted(await openDrill({
104
+ const opened = await permitted(await openDrill({
130
105
  rt,
131
106
  principal,
132
107
  request,
133
108
  state: body.state
134
- })), body);
109
+ }));
110
+ if (body.state.view.by === "comparison") return compareGroups(opened, body.state, body.state.view);
111
+ const r = await ready(opened, body);
135
112
  const can = r.summed?.summary.can ?? await abilities(r.o, r.line, r.offered);
136
113
  const choice = r.summed?.summary ?? {
137
114
  can,
@@ -139,14 +116,7 @@ async function runDrill(rt, principal, request, body) {
139
116
  };
140
117
  const { shown, view } = await shownView(r, chosenView(body.state.view, choice), body.page);
141
118
  const { first: _first, ...plain } = view;
142
- const views = body.state.views?.slice(0, Math.max(0, r.o.path.length - 1));
143
- const { views: _v, ...rest } = body.state;
144
- const state = {
145
- ...rest,
146
- path: r.o.path,
147
- view: plain,
148
- ...views === void 0 || views.length === 0 ? {} : { views }
149
- };
119
+ const state = normalizedDrillState(body.state, r.o.path, plain);
150
120
  return forOpener({
151
121
  ...r.summed === void 0 ? {} : { summary: r.summed.summary },
152
122
  path: crumbs(r.o),
package/dist/editing.mjs CHANGED
@@ -11,7 +11,7 @@ import { principalTenant } from "derive-dashboards/core";
11
11
  function storeFor(rt, request) {
12
12
  const adapter = adapterFor(rt.options, request);
13
13
  if (adapter === void 0) throw new HttpError(400, "STORE_REQUIRED", "Editing dashboards needs a store: pass `database` to deriveDashboards.");
14
- return createStore(adapter);
14
+ return createStore(adapter, rt.drillModel);
15
15
  }
16
16
  /**
17
17
  * What a draft of `id` starts from: a built-in by its key, or a stored dashboard by the one id
@@ -5,9 +5,8 @@ import { createDashEndpoint } from "derive-dashboards/core";
5
5
  // src/endpoints/drill.ts
6
6
  /** The dashboard a drill body starts from, before its schema checks it. */
7
7
  function dashboardOf(body) {
8
- const parsed = bodies.drill.safeParse(body);
9
- const origin = parsed.success ? parsed.data.state.origin : void 0;
10
- if (origin?.kind !== "dashboard") throw new HttpError(400, "BODY_INVALID", "state.origin: a dashboard's tile is required here.");
8
+ const { origin } = parseWith(bodies.drill, body).state;
9
+ if (origin.kind !== "dashboard") throw new HttpError(400, "BODY_INVALID", "state.origin: a dashboard's tile is required here.");
11
10
  return {
12
11
  kind: "dashboard",
13
12
  id: origin.dashboardId
@@ -113,11 +113,16 @@ export declare function coreEndpoints(rt: Runtime): {
113
113
  by: "breakdown";
114
114
  member?: string;
115
115
  search?: string;
116
+ } | {
117
+ by: "comparison";
118
+ member: string;
119
+ thenBy?: string;
116
120
  } | {
117
121
  by: "trend";
118
122
  grain?: "hour" | "day" | "week" | "month" | "quarter" | "year";
119
123
  } | {
120
124
  by: "items";
125
+ fields?: true;
121
126
  numerator?: true;
122
127
  } | {
123
128
  by: "explanation";
@@ -127,11 +132,16 @@ export declare function coreEndpoints(rt: Runtime): {
127
132
  by: "breakdown";
128
133
  member?: string;
129
134
  search?: string;
135
+ } | {
136
+ by: "comparison";
137
+ member: string;
138
+ thenBy?: string;
130
139
  } | {
131
140
  by: "trend";
132
141
  grain?: "hour" | "day" | "week" | "month" | "quarter" | "year";
133
142
  } | {
134
143
  by: "items";
144
+ fields?: true;
135
145
  numerator?: true;
136
146
  } | {
137
147
  by: "explanation";
@@ -223,11 +233,16 @@ export declare function coreEndpoints(rt: Runtime): {
223
233
  by: "breakdown";
224
234
  member?: string;
225
235
  search?: string;
236
+ } | {
237
+ by: "comparison";
238
+ member: string;
239
+ thenBy?: string;
226
240
  } | {
227
241
  by: "trend";
228
242
  grain?: "hour" | "day" | "week" | "month" | "quarter" | "year";
229
243
  } | {
230
244
  by: "items";
245
+ fields?: true;
231
246
  numerator?: true;
232
247
  } | {
233
248
  by: "explanation";
@@ -237,11 +252,16 @@ export declare function coreEndpoints(rt: Runtime): {
237
252
  by: "breakdown";
238
253
  member?: string;
239
254
  search?: string;
255
+ } | {
256
+ by: "comparison";
257
+ member: string;
258
+ thenBy?: string;
240
259
  } | {
241
260
  by: "trend";
242
261
  grain?: "hour" | "day" | "week" | "month" | "quarter" | "year";
243
262
  } | {
244
263
  by: "items";
264
+ fields?: true;
245
265
  numerator?: true;
246
266
  } | {
247
267
  by: "explanation";
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { coreEndpoints } from "./endpoints/index.mjs";
2
+ import { DashboardDocumentError } from "./dashboard-documents.mjs";
2
3
  import { CustomSourceOptions, customSource } from "./custom-source.mjs";
3
4
  import { HttpError } from "./http.mjs";
4
5
  import { PgPool, PgQueryable, nodePostgres } from "./node-postgres.mjs";
@@ -23,4 +24,4 @@ export declare function deriveDashboards<const O extends DashOptions>(options: O
23
24
  /** Typed from the model: a template per source, and no source the model lacks. */
24
25
  itemLinks?: ItemLinksFor<O["model"], O["itemLinks"]>;
25
26
  }): DashServer<O>;
26
- export { type CustomSourceOptions, HttpError, type PgPool, type PgQueryable, type PostgresConnectionOptions, type PostgresStoreOptions, type RunRows, type RunSql, type SchemaDiff, SchemaMismatchError, createTables, customSource, memoryStorage, nodePostgres, postgresConnection, postgresStore, schemaDiff };
27
+ export { type CustomSourceOptions, DashboardDocumentError, HttpError, type PgPool, type PgQueryable, type PostgresConnectionOptions, type PostgresStoreOptions, type RunRows, type RunSql, type SchemaDiff, SchemaMismatchError, createTables, customSource, memoryStorage, nodePostgres, postgresConnection, postgresStore, schemaDiff };
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createCache } from "./cache.mjs";
2
2
  import { cursorKey, macKey } from "./cursor-seal.mjs";
3
+ import { DashboardDocumentError, checkedDashboards } from "./dashboard-documents.mjs";
3
4
  import { warnSecretAtStart } from "./drill-secret.mjs";
4
5
  import { coreEndpoints } from "./endpoints/index.mjs";
5
6
  import { createHandler, serverCall } from "./handler.mjs";
@@ -11,33 +12,10 @@ import { postgresConnection } from "./postgres-connection.mjs";
11
12
  import { postgresStore } from "./postgres-store.mjs";
12
13
  import { memoryStorage } from "./storage.mjs";
13
14
  import { SchemaMismatchError, createTables, schemaDiff } from "./store/create-tables.mjs";
14
- import { BASE_ERROR_CODES, defineModel, documentDisplayIssues, linkTemplateIssues } from "derive-dashboards/core";
15
+ import { BASE_ERROR_CODES, defineModel, linkTemplateIssues } from "derive-dashboards/core";
15
16
  import { drillModel } from "derive-dashboards/core/engine";
16
- import { loadDocument } from "derive-dashboards/core/schema";
17
17
  // src/index.ts
18
18
  /**
19
- * Code-defined dashboards are checked when the handler is made, not when a viewer opens one: an
20
- * invalid document stops the server with every problem named, and a layout is repaired once.
21
- */
22
- function checkedDashboards(options) {
23
- return (options.dashboards ?? []).map((d) => {
24
- const loaded = loadDocument(d.document);
25
- if (!loaded.ok) {
26
- const problems = loaded.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ");
27
- throw new Error(`The dashboard "${d.key}" is not a valid document: ${problems}`);
28
- }
29
- const wrong = documentDisplayIssues(loaded.doc);
30
- if (wrong.length > 0) {
31
- const problems = wrong.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ");
32
- throw new Error(`The dashboard "${d.key}" has display options to fix: ${problems}`);
33
- }
34
- return {
35
- key: d.key,
36
- document: loaded.doc
37
- };
38
- });
39
- }
40
- /**
41
19
  * Every connection the model's sources read is given, and each one given as it is (not per
42
20
  * request) is a connection, or the server does not start.
43
21
  */
@@ -101,16 +79,17 @@ function deriveDashboards(options) {
101
79
  defineModel(options.model);
102
80
  checkConnections(options);
103
81
  checkItemLinks(options);
82
+ const model = drillModel(options.model);
104
83
  const checked = {
105
84
  ...options,
106
- dashboards: checkedDashboards(options)
85
+ dashboards: checkedDashboards(options, model)
107
86
  };
108
87
  const rt = {
109
88
  options: checked,
110
89
  cache: createCache(checked),
111
90
  cursorKey: cursorKey(options.secret),
112
91
  macKey: macKey(options.secret),
113
- drillModel: drillModel(checked.model),
92
+ drillModel: model,
114
93
  warned: { secret: false }
115
94
  };
116
95
  warnSecretAtStart(rt);
@@ -144,4 +123,4 @@ function deriveDashboards(options) {
144
123
  options
145
124
  };
146
125
  }
147
- export { HttpError, SchemaMismatchError, createTables, customSource, deriveDashboards, memoryStorage, nodePostgres, postgresConnection, postgresStore, schemaDiff };
126
+ export { DashboardDocumentError, HttpError, SchemaMismatchError, createTables, customSource, deriveDashboards, memoryStorage, nodePostgres, postgresConnection, postgresStore, schemaDiff };
package/dist/llms.txt CHANGED
@@ -9,7 +9,7 @@ Install skill for coding agents: `npx skills add derive-to/dashboards --skill de
9
9
  - [Quick start](https://github.com/derive-to/dashboards/blob/main/docs/quick-start.md): install, describe your data, mount the handler, show a dashboard, drill in.
10
10
  - [Concepts](https://github.com/derive-to/dashboards/blob/main/docs/concepts.md): the model, measures, joins, tenancy and row policies, access, documents, drill-in.
11
11
  - [Filters](https://github.com/derive-to/dashboards/blob/main/docs/filters.md): the built-in filter bar, theming, options, words, the shadcn copy, custom bars.
12
- - [React](https://github.com/derive-to/dashboards/blob/main/docs/react.md): provider, Dashboard, editing UI, URL state, drill parts, widget builder; the tiles and their `display` options (a number's `value` and `secondary`, a table's `bars`, `heat` and `compact`, a list's lines); a table a viewer sorts; a tile's answer as CSV (`csv={false}` turns the button off, `downloadCsv` and `csvOf` for your own).
12
+ - [React](https://github.com/derive-to/dashboards/blob/main/docs/react.md): provider, Dashboard, editing UI, URL state, drill parts, widget builder; the tiles and their `display` options (a number's `value` and `secondary`, a table's `bars`, `heat`, `compact` and `comparisons` for grouped drill-down, a list's lines); plain SVG functions in `derive-dashboards/charts`, the two chart kits and what each kind draws (`CHARTS_RENDERERS` from `derive-dashboards/charts-react`: line, bar, area, small multiples, heat grid, funnel; a bar's `against`, an area's `share`, small multiples' `ownScales`); a table a viewer sorts; a tile's answer as CSV (`csv={false}` turns the button off, `downloadCsv` and `csvOf` for your own). Use `drill.compare` on a row in a custom renderer. Catch `DashboardDocumentError` for invalid code dashboards. Translate drill labels with `messages.drillMetricTotal`, `drillCompareGroup`, `drillGroupedBy`, `drillRecordPages` and `drillTrendWindow`.
13
13
  - [CLI](https://github.com/derive-to/dashboards/blob/main/docs/cli.md): init, check, generate, create-tables, add, importing from dbt or Cube.
14
14
  - [Endpoints](https://github.com/derive-to/dashboards/blob/main/docs/endpoints.md): every handler endpoint, its body and answer.
15
15
  - [MCP](https://github.com/derive-to/dashboards/blob/main/docs/mcp.md): tools that let agents query and edit dashboards as themselves.
@@ -3,12 +3,12 @@ import { TileActions } from "./Editing.mjs";
3
3
  import { placeOf, useBringIntoView } from "./place.mjs";
4
4
  import { Tile } from "./Tile.mjs";
5
5
  import { memo, useEffect, useMemo } from "react";
6
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
7
7
  // src/Cell.tsx
8
8
  /** The grip that moves a tile, and the corner that resizes it, while the dashboard is a draft. */
9
9
  function Handles(props) {
10
10
  const { messages } = useDashboards();
11
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
11
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("button", {
12
12
  type: "button",
13
13
  className: "dd-move",
14
14
  "aria-label": messages.moveWidget(props.title),