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
@@ -1,92 +0,0 @@
1
- import { createDashEndpoint } from "@derive-to/dashboards-core";
2
- import { bodies, parseWith } from "../body";
3
- import { listDashboards, loadDashboard } from "../dashboards";
4
- import { hasOpenDraft, ownUnpublished, unpublishedFor } from "../editing";
5
- import type { Runtime } from "../execute";
6
- import { HttpError } from "../http";
7
- import { dashboardResource } from "../owner";
8
- import { userOf } from "../request";
9
- import { viewDashboard } from "./access";
10
-
11
- /** A dashboard as its viewer sees it, or the caller's own unpublished one from their draft. */
12
- async function loadOrDraft(
13
- rt: Runtime,
14
- request: Request,
15
- user: ReturnType<typeof userOf>,
16
- id: string,
17
- ) {
18
- try {
19
- return await loadDashboard(rt.options, request, user, { id });
20
- } catch (error) {
21
- if (!(error instanceof HttpError) || error.code !== "NOT_FOUND") throw error;
22
- const draft = await unpublishedFor(rt, request, user, id);
23
- if (draft === null) throw error;
24
- return { id, version: 0, document: draft.doc, unpublished: true as const };
25
- }
26
- }
27
-
28
- /**
29
- * The dashboards a viewer may view, each checked with its owner; their own unpublished ones;
30
- * and whether they may make one.
31
- */
32
- async function listFor(rt: Runtime, request: Request, user: ReturnType<typeof userOf>) {
33
- const { options } = rt;
34
- const { viewer } = user;
35
- const all = await listDashboards(options, request, user);
36
- const allowed = await Promise.all(
37
- all.map(({ owner, ...d }) =>
38
- Promise.resolve(
39
- options.access.can(viewer, "view", {
40
- kind: "dashboard",
41
- id: d.id,
42
- ...(owner === undefined ? {} : { owner }),
43
- }),
44
- ),
45
- ),
46
- );
47
- const own = await ownUnpublished(rt, request, user);
48
- const create =
49
- options.database !== undefined &&
50
- (await options.access.can(viewer, "edit", { kind: "tenant" }));
51
- return {
52
- dashboards: [
53
- ...all.filter((_d, i) => allowed[i] === true).map(({ owner: _o, ...d }) => d),
54
- ...own,
55
- ],
56
- can: { create },
57
- };
58
- }
59
-
60
- /** Listing and reading dashboards. */
61
- export function readEndpoints(rt: Runtime) {
62
- const { options } = rt;
63
- return {
64
- listDashboards: createDashEndpoint("/dashboards/list", {
65
- method: "GET",
66
- access: { kind: "signed_in" },
67
- parse: (input) => parseWith(bodies.list, input),
68
- handler: ({ principal, request }) => listFor(rt, request, userOf(principal)),
69
- }),
70
- getDashboard: createDashEndpoint("/dashboards/get", {
71
- method: "POST",
72
- access: viewDashboard,
73
- parse: (input) => parseWith(bodies.dashboard, input),
74
- handler: async ({ body, principal, request }) => {
75
- const user = userOf(principal);
76
- const loaded = await loadOrDraft(rt, request, user, body.dashboardId);
77
- const resource = await dashboardResource(options, request, user, body.dashboardId);
78
- const [edit, manage] = await Promise.all([
79
- options.access.can(user.viewer, "edit", resource),
80
- options.access.can(user.viewer, "manage", resource),
81
- ]);
82
- const canEdit = edit && options.database !== undefined;
83
- const waiting = canEdit && (await hasOpenDraft(rt, request, user, body.dashboardId));
84
- return {
85
- ...loaded,
86
- can: { edit: canEdit, manage },
87
- ...(waiting ? { hasDraft: true as const } : {}),
88
- };
89
- },
90
- }),
91
- };
92
- }
@@ -1,89 +0,0 @@
1
- import { createDashEndpoint } from "@derive-to/dashboards-core";
2
- import { bodies, parseWith } from "../body";
3
- import { checkWidgets } from "../checks";
4
- import { servedAs } from "../dashboard-id";
5
- import { editorOf, rowId, storeFor } from "../editing";
6
- import type { Runtime } from "../execute";
7
- import { dashboardResource } from "../owner";
8
- import { userOf } from "../request";
9
- import { expectDraftRevision } from "../store/rows";
10
- import { editDashboard } from "./access";
11
-
12
- /** Stepping back an edit, and seeing what publishing would do now. */
13
- function stepEndpoints(rt: Runtime) {
14
- return {
15
- undoDraft: createDashEndpoint("/dashboards/draft/undo", {
16
- method: "POST",
17
- access: editDashboard,
18
- parse: (input) => parseWith(bodies.undo, input),
19
- handler: async ({ body, principal, request }) => {
20
- const user = userOf(principal);
21
- const back = await storeFor(rt, request).undo({
22
- ...editorOf(user),
23
- id: await rowId(rt, request, user, body.dashboardId),
24
- expectedRevision: body.expectedRevision,
25
- });
26
- return { ...back, draft: servedAs(back.draft, body.dashboardId) };
27
- },
28
- }),
29
- previewDraft: createDashEndpoint("/dashboards/draft/preview", {
30
- method: "POST",
31
- access: editDashboard,
32
- parse: (input) => parseWith(bodies.dashboard, input),
33
- handler: async ({ body, principal, request }) => {
34
- const user = userOf(principal);
35
- return storeFor(rt, request).preview({
36
- ...editorOf(user),
37
- id: await rowId(rt, request, user, body.dashboardId),
38
- });
39
- },
40
- }),
41
- };
42
- }
43
-
44
- /** Deciding the changes that no longer apply: each dropped, or its widget put back. */
45
- function rebaseEndpoint(rt: Runtime) {
46
- return {
47
- rebaseDraft: createDashEndpoint("/dashboards/draft/rebase", {
48
- method: "POST",
49
- access: editDashboard,
50
- parse: (input) => parseWith(bodies.rebase, input),
51
- handler: async ({ body, principal, request }) => {
52
- const user = userOf(principal);
53
- const id = await rowId(rt, request, user, body.dashboardId);
54
- const store = storeFor(rt, request);
55
- const restore = body.restore ?? [];
56
- if (restore.length > 0) {
57
- // A widget put back is built again: its queries must be ones the editor may
58
- // read. The store puts back only the draft's own widgets, at the revision named,
59
- // so this checks exactly what comes back.
60
- const draft = await store.getDraft({ ...editorOf(user), id });
61
- expectDraftRevision(draft?.revision, body.expectedRevision);
62
- const resource = await dashboardResource(rt.options, request, user, body.dashboardId);
63
- const widgets = restore.flatMap((w) => {
64
- const widget = draft?.doc.widgets[w];
65
- return widget === undefined ? [] : [widget];
66
- });
67
- await checkWidgets(rt, user.viewer, resource, widgets);
68
- }
69
- const rebased = await store.rebase({
70
- ...editorOf(user),
71
- id,
72
- expectedRevision: body.expectedRevision,
73
- head: body.head,
74
- drop: body.drop ?? [],
75
- restore,
76
- });
77
- return servedAs(rebased, body.dashboardId);
78
- },
79
- }),
80
- };
81
- }
82
-
83
- /**
84
- * Reviewing a draft before it goes live: stepping back an edit, seeing what publishing would
85
- * do now, and deciding the changes that no longer apply on a newer version.
86
- */
87
- export function reviewEndpoints(rt: Runtime) {
88
- return { ...stepEndpoints(rt), ...rebaseEndpoint(rt) };
89
- }
@@ -1,62 +0,0 @@
1
- import { isMark, type Primitive, parseMemberId, type WireQuery } from "@derive-to/dashboards-core";
2
- import { type Execution, execute } from "../execute";
3
- import { HttpError } from "../http";
4
- import { calendarOf } from "../request";
5
-
6
- const DEFAULT_LIMIT = 100;
7
-
8
- /** A query listing a member's distinct values in code-point order, narrowed by a search. */
9
- function valuesQuery(
10
- x: Pick<Execution, "rt">,
11
- member: string,
12
- search: string | undefined,
13
- limit: number,
14
- ): WireQuery {
15
- const ref = parseMemberId(member);
16
- const source = ref === undefined ? undefined : x.rt.options.model.sources[ref.source];
17
- // Any measure groups the values; a plain count is the cheapest to compute alongside.
18
- const measures = source === undefined ? [] : Object.entries(source.measures);
19
- const measure = (measures.find(([, m]) => m.kind === "count" && !("distinct" in m)) ??
20
- measures[0])?.[0];
21
- if (ref === undefined || measure === undefined)
22
- throw new HttpError(
23
- 400,
24
- "QUERY_INVALID",
25
- `"${member}" is not a member whose values can be listed.`,
26
- );
27
- return {
28
- kind: "aggregate",
29
- source: ref.source,
30
- measures: [{ id: "m1", measure: `${ref.source}.${measure}` }],
31
- dimensions: [{ id: "d1", member }],
32
- ...(search === undefined || search === ""
33
- ? {}
34
- : { filters: { member, op: "contains", values: [search] } }),
35
- order: [{ by: "d1", dir: "asc" }],
36
- limit: limit + 1,
37
- };
38
- }
39
-
40
- /**
41
- * A page of a member's distinct values that this viewer can see: run through the planner under
42
- * their tenant, policy and any lock, so a value never comes from a row they cannot read.
43
- */
44
- export async function memberValues(
45
- x: Omit<Execution, "query" | "calendar">,
46
- a: { member: string; search?: string; limit?: number },
47
- ): Promise<{ values: Primitive[]; more: boolean }> {
48
- const limit = a.limit ?? DEFAULT_LIMIT;
49
- const query = valuesQuery(x, a.member, a.search, limit);
50
- const answer = await execute({
51
- ...x,
52
- query,
53
- calendar: calendarOf(x.rt.options),
54
- });
55
- // The values query has no Other or total, so no row is marked.
56
- const values = answer.rows.flatMap((row) => {
57
- const cell = row[0] ?? null;
58
- if (cell === null || typeof cell !== "object") return [cell];
59
- return isMark(cell) ? [] : [cell.v];
60
- });
61
- return { values: values.slice(0, limit), more: values.length > limit };
62
- }
@@ -1,104 +0,0 @@
1
- import { createDashEndpoint } from "@derive-to/dashboards-core";
2
- import { bodies, parseWith } from "../body";
3
- import { checkDocument, versionDoc } from "../checks";
4
- import { servedAs } from "../dashboard-id";
5
- import { editorOf, storedId, storeFor } from "../editing";
6
- import type { Runtime } from "../execute";
7
- import { HttpError } from "../http";
8
- import { dashboardResource } from "../owner";
9
- import { userOf } from "../request";
10
- import { editDashboard, viewDashboard } from "./access";
11
-
12
- /**
13
- * Bringing an old version back as the next one: checked as an edit would be, every query in
14
- * it readable and a different lock only with `manage`.
15
- */
16
- function restoreEndpoint(rt: Runtime) {
17
- return createDashEndpoint("/dashboards/restore", {
18
- method: "POST",
19
- access: editDashboard,
20
- parse: (input) => parseWith(bodies.restore, input),
21
- handler: async ({ body, principal, request }) => {
22
- const user = userOf(principal);
23
- const editor = editorOf(user);
24
- const id = await storedId(rt, request, user, body.dashboardId);
25
- if (id === null)
26
- throw new HttpError(
27
- 404,
28
- "NOT_FOUND",
29
- "This dashboard has no published versions to restore.",
30
- );
31
- const store = storeFor(rt, request);
32
- const old = await store.getVersion({ tenant: editor.tenant, id, version: body.version });
33
- if (old === null)
34
- throw new HttpError(404, "NOT_FOUND", `There is no version ${body.version} to restore.`);
35
- const current = await store.get({ tenant: editor.tenant, ref: { id } });
36
- const resource = await dashboardResource(rt.options, request, user, body.dashboardId);
37
- await checkDocument(rt, user.viewer, resource, {
38
- restored: old.doc,
39
- current: current?.doc,
40
- });
41
- const published = await store.restore({
42
- ...editor,
43
- id,
44
- version: body.version,
45
- requestId: body.requestId,
46
- expectedHead: current?.currentVersion ?? 0,
47
- });
48
- return servedAs(published, body.dashboardId);
49
- },
50
- });
51
- }
52
-
53
- /**
54
- * An earlier version's document, for a preview of it in place. It needs `edit`, as running its
55
- * tiles does: an old version can carry a looser lock than the current one.
56
- */
57
- function versionEndpoint(rt: Runtime) {
58
- return createDashEndpoint("/dashboards/version", {
59
- method: "POST",
60
- access: editDashboard,
61
- parse: (input) => parseWith(bodies.version, input),
62
- handler: async ({ body, principal, request }) => {
63
- const user = userOf(principal);
64
- const old = await versionDoc(rt, request, user, body);
65
- return { version: old.version, document: old.doc };
66
- },
67
- });
68
- }
69
-
70
- /** A dashboard's history: its published versions, and bringing an old one back. */
71
- export function versionEndpoints(rt: Runtime) {
72
- return {
73
- versions: createDashEndpoint("/dashboards/versions", {
74
- method: "POST",
75
- access: viewDashboard,
76
- parse: (input) => parseWith(bodies.versions, input),
77
- handler: async ({ body, principal, request }) => {
78
- const user = userOf(principal);
79
- const id = await storedId(rt, request, user, body.dashboardId);
80
- // A built-in nobody has published over has no history yet.
81
- if (id === null) return { versions: [] };
82
- const { tenant } = editorOf(user);
83
- const page = 50;
84
- const versions = await storeFor(rt, request).versions({
85
- tenant,
86
- id,
87
- limit: page,
88
- ...(body.before === undefined ? {} : { before: body.before }),
89
- });
90
- const last = versions.at(-1);
91
- const next = versions.length === page && last !== undefined ? { next: last.version } : {};
92
- // Who published is the host's people: shown to those who may edit, not to every viewer.
93
- const resource = await dashboardResource(rt.options, request, user, body.dashboardId);
94
- const editor = await rt.options.access.can(user.viewer, "edit", resource);
95
- return {
96
- versions: editor ? versions : versions.map(({ author: _a, ...v }) => v),
97
- ...next,
98
- };
99
- },
100
- }),
101
- version: versionEndpoint(rt),
102
- restore: restoreEndpoint(rt),
103
- };
104
- }
package/src/execute.ts DELETED
@@ -1,207 +0,0 @@
1
- import {
2
- type BoundFilter,
3
- type Calendar,
4
- canonical,
5
- type DashOptions,
6
- type Issue,
7
- isBound,
8
- type LockEntry,
9
- markedRows,
10
- type Principal,
11
- type RecordsResponse,
12
- type Result,
13
- recordColumns,
14
- resultColumns,
15
- type ScopeCoverage,
16
- type WireFilter,
17
- type WireQuery,
18
- } from "@derive-to/dashboards-core";
19
- import {
20
- EngineError,
21
- type EngineInput,
22
- type Reader,
23
- readQuery,
24
- readRecords,
25
- } from "@derive-to/dashboards-core/engine";
26
- import { checkSensitive } from "./authorize";
27
- import { type Cache, manifest, sha256 } from "./cache";
28
- import { adapterFor } from "./dashboards";
29
- import { withReader } from "./reading";
30
- import { logQuery } from "./store/log";
31
-
32
- /** The runtime's state for one handler: its options and its result cache. */
33
- export type Runtime = { options: DashOptions; cache: Cache | undefined };
34
-
35
- /** What one query needs to run: the request around it, and the query as composed. */
36
- export type Execution = {
37
- rt: Runtime;
38
- request: Request;
39
- principal: Principal;
40
- now: Date;
41
- calendar: Calendar;
42
- query: WireQuery;
43
- lock: readonly LockEntry[];
44
- coverage: ScopeCoverage;
45
- /** The dashboard the query belongs to; absent for a free query. */
46
- dashboardId?: string;
47
- };
48
-
49
- export type Answered = Result & { unreadable?: true };
50
-
51
- const DEFAULT_QUANTUM = 60;
52
-
53
- function boundEntries<E extends { filter: WireFilter }>(
54
- entries: readonly E[],
55
- what: string,
56
- ): (E & { filter: BoundFilter })[] {
57
- return entries.map((entry) => {
58
- if (!isBound(entry.filter)) {
59
- throw new EngineError(
60
- "FILTER_UNBOUND",
61
- `A ${what} that uses a viewer value or a variable is not supported yet.`,
62
- );
63
- }
64
- return { ...entry, filter: entry.filter };
65
- });
66
- }
67
-
68
- /** The filters that decided an answer, as the viewer may see them: the query's, each lock's, each required filter's. */
69
- function receiptFilter(bound: Bound): BoundFilter {
70
- const { query } = bound.input;
71
- return {
72
- all: [
73
- ...(query.filters !== undefined && isBound(query.filters) ? [query.filters] : []),
74
- ...bound.lock.map((e) => e.filter),
75
- ...bound.required.map((e) => e.filter),
76
- ],
77
- };
78
- }
79
-
80
- /** The query bound for the engine: no sensitive member, and no viewer value or variable left in the lock or required filters. */
81
- function bind(x: Execution) {
82
- const { options } = x.rt;
83
- checkSensitive(options, x.principal, x.query);
84
- const lock = boundEntries(x.lock, "lock");
85
- const required = boundEntries(
86
- options.compose?.required?.({
87
- principal: x.principal,
88
- calendar: x.calendar,
89
- ...(x.dashboardId === undefined ? {} : { dashboardId: x.dashboardId }),
90
- }) ?? [],
91
- "required filter",
92
- );
93
- const maxRows = options.query?.maxRows ?? 5000;
94
- const input: EngineInput = {
95
- model: options.model,
96
- query: x.query,
97
- principal: x.principal,
98
- locks: lock,
99
- required,
100
- now: x.now,
101
- calendar: x.calendar,
102
- maxRows,
103
- quantumSeconds: options.cache?.quantum ?? DEFAULT_QUANTUM,
104
- };
105
- return { input, lock, required, maxRows };
106
- }
107
-
108
- type Bound = ReturnType<typeof bind>;
109
-
110
- /** Reads through the query's connection, under the request's deadline and abort. */
111
- const reading = <T>(x: Execution, maxRows: number, fn: (reader: Reader) => Promise<T>) =>
112
- withReader({ options: x.rt.options, request: x.request, source: x.query.source, maxRows }, fn);
113
-
114
- /** Runs the engine and shapes its answer as the plan's `Result`, with a receipt of what was read. */
115
- async function compute(x: Execution, bound: Bound): Promise<Answered> {
116
- const started = performance.now();
117
- const computedAt = new Date().toISOString();
118
- const { value, consistency, custom } = await reading(x, bound.maxRows, (reader) =>
119
- readQuery(bound.input, reader),
120
- );
121
- const { truncated, unreadable, compare, ...levels } = value.answer;
122
- const warnings: Issue[] =
123
- truncated === true
124
- ? [{ code: "ROW_CAP", message: `The answer was cut at ${bound.maxRows} rows.`, path: [] }]
125
- : [];
126
- return {
127
- columns: resultColumns(x.rt.options.model, x.query),
128
- rows: markedRows(x.query, levels),
129
- ...(compare === undefined
130
- ? {}
131
- : { compare: { rows: markedRows(x.query, compare), range: compare.range } }),
132
- status: truncated === true ? "truncated" : "complete",
133
- ...(unreadable === true ? { unreadable } : {}),
134
- receipt: {
135
- queryHash: await sha256(
136
- canonical({ query: x.query, lock: bound.lock, required: bound.required }),
137
- ),
138
- // A custom source's rows come from the host's own code, not the library's SQL.
139
- provider: custom ? "custom" : "builtin",
140
- trust: custom ? "external" : "builtin",
141
- sources: value.sources,
142
- answeredBy: "base",
143
- cache: "off",
144
- ...(value.range === undefined ? {} : { range: value.range }),
145
- calendar: x.calendar,
146
- dataThrough: computedAt,
147
- computedAt,
148
- consistency,
149
- durationMs: Math.round(performance.now() - started),
150
- rowsReturned: levels.rows.length,
151
- filter: receiptFilter(bound),
152
- coverage: x.coverage,
153
- warnings,
154
- },
155
- };
156
- }
157
-
158
- /**
159
- * Runs one composed query under the viewer's access and returns the plan's `Result`: rows
160
- * described by their columns, `complete` or `truncated`, and a receipt. With a cache, an equal
161
- * request (same bound query, policies, calendar and source epochs) is answered from it.
162
- */
163
- export async function execute(x: Execution): Promise<Answered> {
164
- const answer = await answered(x);
165
- record(x, answer);
166
- return answer;
167
- }
168
-
169
- /** With `queryLog`, one row per answer, written where the host runs background work; never fails a request. */
170
- function record(x: Execution, answer: Answered): void {
171
- const { options } = x.rt;
172
- const adapter = options.queryLog === true ? adapterFor(options, x.request) : undefined;
173
- if (adapter === undefined) return;
174
- const task = logQuery(adapter, x.principal, x.query.source, answer).catch(() => null);
175
- options.advanced?.backgroundTasks?.handler(task);
176
- }
177
-
178
- function answered(x: Execution): Promise<Answered> {
179
- const bound = bind(x);
180
- const { cache, options } = x.rt;
181
- if (cache === undefined) return compute(x, bound);
182
- const quantum = (options.cache?.quantum ?? DEFAULT_QUANTUM) * 1000;
183
- const on = [...bound.lock, ...bound.required].map((e) => e.on);
184
- const key = {
185
- principal: x.principal,
186
- query: x.query,
187
- lock: bound.lock,
188
- required: bound.required,
189
- calendar: x.calendar,
190
- maxRows: bound.maxRows,
191
- now: x.now.getTime() - (x.now.getTime() % quantum),
192
- sources: manifest(options.model, x.query, on),
193
- };
194
- return cache.answer(key, () => compute(x, bound));
195
- }
196
-
197
- /** A page of the rows behind a query, under the same access, filters and range as its answer. */
198
- export async function executeRecords(
199
- x: Execution,
200
- page: { limit: number; after?: string },
201
- ): Promise<RecordsResponse> {
202
- const bound = bind(x);
203
- const { value } = await reading(x, page.limit, (reader) =>
204
- readRecords(bound.input, page, reader),
205
- );
206
- return { ...value, columns: recordColumns(x.rt.options.model, x.query.source, value.columns) };
207
- }