derive-dashboards 0.0.0-stage → 0.1.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 (530) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +90 -2
  3. package/dist/adapter/sql-adapter.mjs +80 -0
  4. package/dist/adapter/statement.mjs +140 -0
  5. package/dist/authorize.mjs +55 -0
  6. package/dist/body.mjs +164 -0
  7. package/dist/bounded.mjs +31 -0
  8. package/dist/cache.d.mts +21 -0
  9. package/dist/cache.mjs +138 -0
  10. package/dist/checks.mjs +98 -0
  11. package/dist/cli/bin.d.mts +1 -0
  12. package/dist/cli/bin.mjs +13 -0
  13. package/dist/cli/check.mjs +52 -0
  14. package/dist/cli/cli.d.mts +5 -0
  15. package/dist/cli/cli.mjs +144 -0
  16. package/dist/cli/config.d.mts +21 -0
  17. package/dist/cli/config.mjs +14 -0
  18. package/dist/cli/conformance.mjs +34 -0
  19. package/dist/cli/import/build.mjs +118 -0
  20. package/dist/cli/import/catalog.mjs +42 -0
  21. package/dist/cli/import/cube-schema.mjs +51 -0
  22. package/dist/cli/import/cube-sql.mjs +52 -0
  23. package/dist/cli/import/cube.mjs +172 -0
  24. package/dist/cli/import/dbt-metrics.mjs +76 -0
  25. package/dist/cli/import/dbt-schema.mjs +82 -0
  26. package/dist/cli/import/dbt.mjs +154 -0
  27. package/dist/cli/import/draft.mjs +46 -0
  28. package/dist/cli/import/index.mjs +71 -0
  29. package/dist/cli/import/storage.mjs +92 -0
  30. package/dist/cli/import/tenancy.mjs +76 -0
  31. package/dist/cli/index.d.mts +6 -0
  32. package/dist/cli/index.mjs +5 -0
  33. package/dist/cli/init.mjs +72 -0
  34. package/dist/cli/io.d.mts +6 -0
  35. package/dist/cli/load.mjs +18 -0
  36. package/dist/cli/propose.d.mts +13 -0
  37. package/dist/cli/propose.mjs +215 -0
  38. package/dist/cli/render.d.mts +14 -0
  39. package/dist/cli/render.mjs +106 -0
  40. package/dist/core/conformance/cases.d.mts +12 -0
  41. package/dist/core/conformance/cases.mjs +82 -0
  42. package/dist/core/conformance/check.d.mts +33 -0
  43. package/dist/core/conformance/check.mjs +81 -0
  44. package/dist/core/conformance/dataset-model.mjs +306 -0
  45. package/dist/core/conformance/dataset-rows.mjs +246 -0
  46. package/dist/core/conformance/dataset.d.mts +381 -0
  47. package/dist/core/conformance/dataset.mjs +58 -0
  48. package/dist/core/conformance/index.d.mts +10 -0
  49. package/dist/core/conformance/index.mjs +9 -0
  50. package/dist/core/conformance/memory/aggregate.mjs +76 -0
  51. package/dist/core/conformance/memory/rows.d.mts +10 -0
  52. package/dist/core/conformance/memory/rows.mjs +98 -0
  53. package/dist/core/conformance/memory/source.d.mts +4 -0
  54. package/dist/core/conformance/memory/source.mjs +129 -0
  55. package/dist/core/conformance/queries.mjs +108 -0
  56. package/dist/core/conformance/records-cases.mjs +68 -0
  57. package/dist/core/document/diff.d.mts +68 -0
  58. package/dist/core/document/diff.mjs +155 -0
  59. package/dist/core/document/layout.d.mts +51 -0
  60. package/dist/core/document/layout.mjs +228 -0
  61. package/dist/core/document/outcome.d.mts +10 -0
  62. package/dist/core/document/outcome.mjs +14 -0
  63. package/dist/core/document/reduce.d.mts +16 -0
  64. package/dist/core/document/reduce.mjs +191 -0
  65. package/dist/core/document/replay.d.mts +28 -0
  66. package/dist/core/document/replay.mjs +38 -0
  67. package/dist/core/document/stacked.d.mts +14 -0
  68. package/dist/core/document/stacked.mjs +70 -0
  69. package/dist/core/document/tabs.mjs +70 -0
  70. package/dist/core/document/types.d.mts +138 -0
  71. package/dist/core/document/types.mjs +16 -0
  72. package/dist/core/document/upgrade.d.mts +25 -0
  73. package/dist/core/document/upgrade.mjs +49 -0
  74. package/dist/core/document/view.d.mts +30 -0
  75. package/dist/core/document/view.mjs +50 -0
  76. package/dist/core/engine/access.mjs +113 -0
  77. package/dist/core/engine/assert.d.mts +21 -0
  78. package/dist/core/engine/assert.mjs +132 -0
  79. package/dist/core/engine/bucket.mjs +52 -0
  80. package/dist/core/engine/build.mjs +71 -0
  81. package/dist/core/engine/checks.mjs +29 -0
  82. package/dist/core/engine/context.mjs +46 -0
  83. package/dist/core/engine/cursor.mjs +30 -0
  84. package/dist/core/engine/custom/ask.mjs +13 -0
  85. package/dist/core/engine/custom/cells.mjs +80 -0
  86. package/dist/core/engine/custom/fields.mjs +130 -0
  87. package/dist/core/engine/custom/level.mjs +136 -0
  88. package/dist/core/engine/custom/measures.mjs +146 -0
  89. package/dist/core/engine/custom/query.mjs +37 -0
  90. package/dist/core/engine/custom/reader.d.mts +7 -0
  91. package/dist/core/engine/custom/reader.mjs +67 -0
  92. package/dist/core/engine/custom/records.mjs +51 -0
  93. package/dist/core/engine/custom/request.d.mts +283 -0
  94. package/dist/core/engine/custom/seen.mjs +79 -0
  95. package/dist/core/engine/custom/where.mjs +34 -0
  96. package/dist/core/engine/dialect.d.mts +54 -0
  97. package/dist/core/engine/filter.mjs +129 -0
  98. package/dist/core/engine/index.d.mts +16 -0
  99. package/dist/core/engine/index.mjs +9 -0
  100. package/dist/core/engine/leaf.mjs +141 -0
  101. package/dist/core/engine/levels.mjs +175 -0
  102. package/dist/core/engine/measure.mjs +81 -0
  103. package/dist/core/engine/members.mjs +149 -0
  104. package/dist/core/engine/nan.mjs +9 -0
  105. package/dist/core/engine/native.mjs +59 -0
  106. package/dist/core/engine/numbers.mjs +191 -0
  107. package/dist/core/engine/other.mjs +45 -0
  108. package/dist/core/engine/plan.d.mts +54 -0
  109. package/dist/core/engine/postgres.d.mts +6 -0
  110. package/dist/core/engine/postgres.mjs +136 -0
  111. package/dist/core/engine/prepare.mjs +133 -0
  112. package/dist/core/engine/rank-sets.mjs +119 -0
  113. package/dist/core/engine/rank.mjs +149 -0
  114. package/dist/core/engine/read.mjs +74 -0
  115. package/dist/core/engine/reader.d.mts +128 -0
  116. package/dist/core/engine/reader.mjs +18 -0
  117. package/dist/core/engine/record-layout.d.mts +10 -0
  118. package/dist/core/engine/record-layout.mjs +37 -0
  119. package/dist/core/engine/records.d.mts +14 -0
  120. package/dist/core/engine/records.mjs +51 -0
  121. package/dist/core/engine/refs.mjs +58 -0
  122. package/dist/core/engine/run.d.mts +3 -0
  123. package/dist/core/engine/run.mjs +102 -0
  124. package/dist/core/engine/segmented.d.mts +11 -0
  125. package/dist/core/engine/segmented.mjs +80 -0
  126. package/dist/core/engine/series.mjs +95 -0
  127. package/dist/core/engine/shape.d.mts +12 -0
  128. package/dist/core/engine/shape.mjs +92 -0
  129. package/dist/core/engine/sql-marked.mjs +77 -0
  130. package/dist/core/engine/sql-pass.mjs +24 -0
  131. package/dist/core/engine/sql-reader.d.mts +10 -0
  132. package/dist/core/engine/sql-reader.mjs +51 -0
  133. package/dist/core/engine/sql-reads.mjs +28 -0
  134. package/dist/core/engine/sql-records.mjs +100 -0
  135. package/dist/core/engine/sql-split.mjs +158 -0
  136. package/dist/core/engine/sql.d.mts +8 -0
  137. package/dist/core/engine/sql.mjs +33 -0
  138. package/dist/core/engine/statement.mjs +78 -0
  139. package/dist/core/engine/time.mjs +52 -0
  140. package/dist/core/engine/two-step.mjs +104 -0
  141. package/dist/core/engine/types.d.mts +55 -0
  142. package/dist/core/engine/version.d.mts +7 -0
  143. package/dist/core/engine/version.mjs +9 -0
  144. package/dist/core/error/codes.d.mts +154 -0
  145. package/dist/core/error/codes.mjs +127 -0
  146. package/dist/core/error/refusal.d.mts +8 -0
  147. package/dist/core/error/refusal.mjs +11 -0
  148. package/dist/core/exact/decimal.d.mts +22 -0
  149. package/dist/core/exact/decimal.mjs +51 -0
  150. package/dist/core/exact/sum.d.mts +17 -0
  151. package/dist/core/exact/sum.mjs +31 -0
  152. package/dist/core/index.d.mts +56 -0
  153. package/dist/core/index.mjs +45 -0
  154. package/dist/core/model/catalog/check.d.mts +10 -0
  155. package/dist/core/model/catalog/check.mjs +141 -0
  156. package/dist/core/model/catalog/columns.mjs +34 -0
  157. package/dist/core/model/catalog/queries.d.mts +12 -0
  158. package/dist/core/model/catalog/queries.mjs +50 -0
  159. package/dist/core/model/defaults.d.mts +3 -0
  160. package/dist/core/model/defaults.mjs +24 -0
  161. package/dist/core/model/define.d.mts +32 -0
  162. package/dist/core/model/define.mjs +21 -0
  163. package/dist/core/model/member.d.mts +26 -0
  164. package/dist/core/model/member.mjs +58 -0
  165. package/dist/core/model/storage.mjs +28 -0
  166. package/dist/core/model/types.d.mts +270 -0
  167. package/dist/core/model/types.mjs +9 -0
  168. package/dist/core/model/validate/expr.d.mts +10 -0
  169. package/dist/core/model/validate/expr.mjs +56 -0
  170. package/dist/core/model/validate/filter.mjs +28 -0
  171. package/dist/core/model/validate/index.d.mts +10 -0
  172. package/dist/core/model/validate/index.mjs +36 -0
  173. package/dist/core/model/validate/issues.mjs +17 -0
  174. package/dist/core/model/validate/members.mjs +98 -0
  175. package/dist/core/model/validate/policy.mjs +76 -0
  176. package/dist/core/model/validate/source.mjs +143 -0
  177. package/dist/core/model/validate/via.d.mts +4 -0
  178. package/dist/core/model/validate/via.mjs +47 -0
  179. package/dist/core/oracle/data.d.mts +37 -0
  180. package/dist/core/oracle/data.mjs +30 -0
  181. package/dist/core/oracle/evaluate.d.mts +23 -0
  182. package/dist/core/oracle/evaluate.mjs +117 -0
  183. package/dist/core/oracle/expr.mjs +74 -0
  184. package/dist/core/oracle/facts.mjs +72 -0
  185. package/dist/core/oracle/filter.d.mts +6 -0
  186. package/dist/core/oracle/filter.mjs +25 -0
  187. package/dist/core/oracle/groups.mjs +33 -0
  188. package/dist/core/oracle/index.d.mts +4 -0
  189. package/dist/core/oracle/index.mjs +3 -0
  190. package/dist/core/oracle/levels.mjs +46 -0
  191. package/dist/core/oracle/logic.mjs +38 -0
  192. package/dist/core/oracle/measure.mjs +85 -0
  193. package/dist/core/oracle/members.mjs +80 -0
  194. package/dist/core/oracle/request.mjs +38 -0
  195. package/dist/core/oracle/segmented.d.mts +7 -0
  196. package/dist/core/oracle/segmented.mjs +35 -0
  197. package/dist/core/oracle/split.mjs +84 -0
  198. package/dist/core/oracle/time-axis.mjs +37 -0
  199. package/dist/core/oracle/time-value.mjs +28 -0
  200. package/dist/core/oracle/tree.mjs +24 -0
  201. package/dist/core/oracle/values.mjs +41 -0
  202. package/dist/core/oracle/visibility.mjs +49 -0
  203. package/dist/core/policy/bind.d.mts +25 -0
  204. package/dist/core/policy/bind.mjs +64 -0
  205. package/dist/core/policy/match.d.mts +16 -0
  206. package/dist/core/policy/match.mjs +44 -0
  207. package/dist/core/query/alias.mjs +14 -0
  208. package/dist/core/query/closure.d.mts +17 -0
  209. package/dist/core/query/closure.mjs +131 -0
  210. package/dist/core/query/compose-tile.d.mts +50 -0
  211. package/dist/core/query/compose-tile.mjs +140 -0
  212. package/dist/core/query/compose.d.mts +105 -0
  213. package/dist/core/query/compose.mjs +12 -0
  214. package/dist/core/query/derived-rules.mjs +56 -0
  215. package/dist/core/query/effective.d.mts +32 -0
  216. package/dist/core/query/effective.mjs +22 -0
  217. package/dist/core/query/filter.d.mts +99 -0
  218. package/dist/core/query/filter.mjs +79 -0
  219. package/dist/core/query/formulas.d.mts +17 -0
  220. package/dist/core/query/formulas.mjs +52 -0
  221. package/dist/core/query/picks.d.mts +10 -0
  222. package/dist/core/query/picks.mjs +25 -0
  223. package/dist/core/query/segments.d.mts +6 -0
  224. package/dist/core/query/segments.mjs +182 -0
  225. package/dist/core/query/to-wire.d.mts +21 -0
  226. package/dist/core/query/to-wire.mjs +124 -0
  227. package/dist/core/query/types.d.mts +238 -0
  228. package/dist/core/result/calc.mjs +95 -0
  229. package/dist/core/result/columns.d.mts +13 -0
  230. package/dist/core/result/columns.mjs +118 -0
  231. package/dist/core/result/marks.d.mts +20 -0
  232. package/dist/core/result/marks.mjs +35 -0
  233. package/dist/core/result/number.mjs +78 -0
  234. package/dist/core/result/order.d.mts +2 -0
  235. package/dist/core/result/order.mjs +57 -0
  236. package/dist/core/result/types.d.mts +66 -0
  237. package/dist/core/result/zero.mjs +18 -0
  238. package/dist/core/schema/answers.d.mts +2071 -0
  239. package/dist/core/schema/answers.mjs +217 -0
  240. package/dist/core/schema/commands.d.mts +273 -0
  241. package/dist/core/schema/commands.mjs +129 -0
  242. package/dist/core/schema/custom.d.mts +13 -0
  243. package/dist/core/schema/custom.mjs +250 -0
  244. package/dist/core/schema/document.d.mts +149 -0
  245. package/dist/core/schema/document.mjs +216 -0
  246. package/dist/core/schema/editing.mjs +166 -0
  247. package/dist/core/schema/index.d.mts +9 -0
  248. package/dist/core/schema/index.mjs +9 -0
  249. package/dist/core/schema/issue.mjs +18 -0
  250. package/dist/core/schema/query.d.mts +92 -0
  251. package/dist/core/schema/query.mjs +174 -0
  252. package/dist/core/schema/tools.d.mts +17 -0
  253. package/dist/core/schema/tools.mjs +62 -0
  254. package/dist/core/schema/view.d.mts +47 -0
  255. package/dist/core/schema/view.mjs +71 -0
  256. package/dist/core/store/ddl.d.mts +38 -0
  257. package/dist/core/store/ddl.mjs +79 -0
  258. package/dist/core/store/schema.d.mts +315 -0
  259. package/dist/core/store/schema.mjs +181 -0
  260. package/dist/core/time/bucket.d.mts +25 -0
  261. package/dist/core/time/bucket.mjs +103 -0
  262. package/dist/core/time/compare.d.mts +30 -0
  263. package/dist/core/time/compare.mjs +73 -0
  264. package/dist/core/time/index.d.mts +7 -0
  265. package/dist/core/time/instant.d.mts +14 -0
  266. package/dist/core/time/instant.mjs +58 -0
  267. package/dist/core/time/range.d.mts +21 -0
  268. package/dist/core/time/range.mjs +41 -0
  269. package/dist/core/time/stored.d.mts +10 -0
  270. package/dist/core/time/stored.mjs +29 -0
  271. package/dist/core/time/temporal.d.mts +14 -0
  272. package/dist/core/time/temporal.mjs +27 -0
  273. package/dist/core/time/zone.d.mts +27 -0
  274. package/dist/core/time/zone.mjs +55 -0
  275. package/dist/core/types/api.d.mts +327 -0
  276. package/dist/core/types/api.mjs +9 -0
  277. package/dist/core/types/infer.d.mts +91 -0
  278. package/dist/core/types/options.d.mts +94 -0
  279. package/dist/core/types/plugin.d.mts +82 -0
  280. package/dist/core/types/plugin.mjs +12 -0
  281. package/dist/core/types/primitives.d.mts +26 -0
  282. package/dist/core/types/provider.d.mts +74 -0
  283. package/dist/core/types/source.d.mts +73 -0
  284. package/dist/core/types/store.d.mts +327 -0
  285. package/dist/core/types/viewer.d.mts +74 -0
  286. package/dist/core/types/viewer.mjs +6 -0
  287. package/dist/core/value/canonical.d.mts +5 -0
  288. package/dist/core/value/canonical.mjs +10 -0
  289. package/dist/core/value/casefold-data.mjs +3 -0
  290. package/dist/core/value/casefold.d.mts +8 -0
  291. package/dist/core/value/casefold.mjs +36 -0
  292. package/dist/core/value/compare.d.mts +3 -0
  293. package/dist/core/value/compare.mjs +18 -0
  294. package/dist/custom-source.d.mts +21 -0
  295. package/dist/custom-source.mjs +30 -0
  296. package/dist/dashboard-id.mjs +31 -0
  297. package/dist/dashboards.mjs +84 -0
  298. package/dist/editing.mjs +114 -0
  299. package/dist/endpoints/access.mjs +44 -0
  300. package/dist/endpoints/dashboards.mjs +109 -0
  301. package/dist/endpoints/drafts.mjs +138 -0
  302. package/dist/endpoints/index.d.mts +453 -0
  303. package/dist/endpoints/index.mjs +39 -0
  304. package/dist/endpoints/meta.mjs +123 -0
  305. package/dist/endpoints/query.mjs +72 -0
  306. package/dist/endpoints/read.mjs +79 -0
  307. package/dist/endpoints/review.mjs +91 -0
  308. package/dist/endpoints/values.mjs +58 -0
  309. package/dist/endpoints/versions.mjs +103 -0
  310. package/dist/execute.d.mts +10 -0
  311. package/dist/execute.mjs +152 -0
  312. package/dist/handler.mjs +189 -0
  313. package/dist/http.d.mts +16 -0
  314. package/dist/http.mjs +67 -0
  315. package/dist/index.d.mts +24 -0
  316. package/dist/index.mjs +115 -0
  317. package/dist/introspect.mjs +180 -0
  318. package/dist/mcp/api.d.mts +10 -0
  319. package/dist/mcp/api.mjs +34 -0
  320. package/dist/mcp/format.d.mts +10 -0
  321. package/dist/mcp/format.mjs +59 -0
  322. package/dist/mcp/index.d.mts +61 -0
  323. package/dist/mcp/index.mjs +88 -0
  324. package/dist/mcp/query.d.mts +6 -0
  325. package/dist/mcp/query.mjs +123 -0
  326. package/dist/mcp/resolve.mjs +67 -0
  327. package/dist/node-postgres.d.mts +33 -0
  328. package/dist/node-postgres.mjs +59 -0
  329. package/dist/owner.mjs +34 -0
  330. package/dist/postgres-connection.d.mts +33 -0
  331. package/dist/postgres-connection.mjs +84 -0
  332. package/dist/postgres-store.d.mts +38 -0
  333. package/dist/postgres-store.mjs +60 -0
  334. package/dist/principal.mjs +28 -0
  335. package/dist/react/CancelRestore.mjs +21 -0
  336. package/dist/react/Canvas.mjs +97 -0
  337. package/dist/react/Cell.mjs +106 -0
  338. package/dist/react/ConfirmButton.mjs +31 -0
  339. package/dist/react/Dashboard.d.mts +27 -0
  340. package/dist/react/Dashboard.mjs +80 -0
  341. package/dist/react/DashboardList.d.mts +12 -0
  342. package/dist/react/DashboardList.mjs +155 -0
  343. package/dist/react/Discard.mjs +99 -0
  344. package/dist/react/EditBar.d.mts +16 -0
  345. package/dist/react/EditBar.mjs +141 -0
  346. package/dist/react/Editing.mjs +124 -0
  347. package/dist/react/FilterBar.d.mts +9 -0
  348. package/dist/react/FilterBar.mjs +119 -0
  349. package/dist/react/Grid.mjs +133 -0
  350. package/dist/react/Header.mjs +107 -0
  351. package/dist/react/History.d.mts +30 -0
  352. package/dist/react/History.mjs +202 -0
  353. package/dist/react/Notice.d.mts +8 -0
  354. package/dist/react/Notice.mjs +51 -0
  355. package/dist/react/Overlaps.mjs +54 -0
  356. package/dist/react/Panel.d.mts +16 -0
  357. package/dist/react/Panel.mjs +93 -0
  358. package/dist/react/Parts.mjs +98 -0
  359. package/dist/react/Records.d.mts +12 -0
  360. package/dist/react/Records.mjs +97 -0
  361. package/dist/react/ReviewPanel.d.mts +15 -0
  362. package/dist/react/ReviewPanel.mjs +200 -0
  363. package/dist/react/Spaces.mjs +108 -0
  364. package/dist/react/Tile.d.mts +20 -0
  365. package/dist/react/Tile.mjs +123 -0
  366. package/dist/react/arrange-steps.mjs +108 -0
  367. package/dist/react/arrange.mjs +135 -0
  368. package/dist/react/board.d.mts +16 -0
  369. package/dist/react/board.mjs +156 -0
  370. package/dist/react/builder/Calcs.mjs +87 -0
  371. package/dist/react/builder/Filters.mjs +165 -0
  372. package/dist/react/builder/Groups.mjs +189 -0
  373. package/dist/react/builder/Picker.mjs +154 -0
  374. package/dist/react/builder/Preview.d.mts +6 -0
  375. package/dist/react/builder/Preview.mjs +102 -0
  376. package/dist/react/builder/Sections.mjs +85 -0
  377. package/dist/react/builder/Time.mjs +119 -0
  378. package/dist/react/builder/WidgetBuilder.d.mts +23 -0
  379. package/dist/react/builder/WidgetBuilder.mjs +202 -0
  380. package/dist/react/builder/base.d.mts +19 -0
  381. package/dist/react/builder/base.mjs +111 -0
  382. package/dist/react/builder/calc.d.mts +5 -0
  383. package/dist/react/builder/calc.mjs +110 -0
  384. package/dist/react/builder/labels.d.mts +1 -0
  385. package/dist/react/builder/labels.mjs +55 -0
  386. package/dist/react/builder/options.mjs +55 -0
  387. package/dist/react/builder/state.d.mts +12 -0
  388. package/dist/react/builder/state.mjs +201 -0
  389. package/dist/react/builder/useBuilder.d.mts +46 -0
  390. package/dist/react/builder/useBuilder.mjs +60 -0
  391. package/dist/react/builder/usePreview.mjs +56 -0
  392. package/dist/react/client.d.mts +93 -0
  393. package/dist/react/client.mjs +107 -0
  394. package/dist/react/context.d.mts +32 -0
  395. package/dist/react/context.mjs +44 -0
  396. package/dist/react/debounce.mjs +19 -0
  397. package/dist/react/draft.d.mts +55 -0
  398. package/dist/react/draft.mjs +230 -0
  399. package/dist/react/english.d.mts +3 -0
  400. package/dist/react/english.mjs +149 -0
  401. package/dist/react/errors.d.mts +12 -0
  402. package/dist/react/errors.mjs +13 -0
  403. package/dist/react/format.d.mts +25 -0
  404. package/dist/react/format.mjs +153 -0
  405. package/dist/react/index.d.mts +27 -0
  406. package/dist/react/index.mjs +25 -0
  407. package/dist/react/marks.d.mts +11 -0
  408. package/dist/react/marks.mjs +62 -0
  409. package/dist/react/messages.d.mts +159 -0
  410. package/dist/react/place.mjs +21 -0
  411. package/dist/react/read.d.mts +15 -0
  412. package/dist/react/read.mjs +54 -0
  413. package/dist/react/renderers/index.d.mts +19 -0
  414. package/dist/react/renderers/index.mjs +85 -0
  415. package/dist/react/review-words.d.mts +79 -0
  416. package/dist/react/review-words.mjs +132 -0
  417. package/dist/react/review.d.mts +26 -0
  418. package/dist/react/review.mjs +110 -0
  419. package/dist/react/scope.mjs +9 -0
  420. package/dist/react/stable.mjs +39 -0
  421. package/dist/react/theme.css +1337 -0
  422. package/dist/react/tile-keys.d.mts +20 -0
  423. package/dist/react/tile-keys.mjs +21 -0
  424. package/dist/react/tile-store.mjs +99 -0
  425. package/dist/react/useBoard.d.mts +80 -0
  426. package/dist/react/useBoard.mjs +53 -0
  427. package/dist/react/useDashboard.d.mts +51 -0
  428. package/dist/react/useDashboard.mjs +56 -0
  429. package/dist/react/useTiles.d.mts +20 -0
  430. package/dist/react/useTiles.mjs +133 -0
  431. package/dist/react/view.mjs +52 -0
  432. package/dist/reading.mjs +43 -0
  433. package/dist/recharts/charts.d.mts +10 -0
  434. package/dist/recharts/charts.mjs +121 -0
  435. package/dist/recharts/index.d.mts +3 -0
  436. package/dist/recharts/index.mjs +3 -0
  437. package/dist/recharts/series.d.mts +22 -0
  438. package/dist/recharts/series.mjs +64 -0
  439. package/dist/request-rows.mjs +21 -0
  440. package/dist/request.mjs +20 -0
  441. package/dist/storage.d.mts +3 -0
  442. package/dist/storage.mjs +54 -0
  443. package/dist/store/apply.mjs +102 -0
  444. package/dist/store/commands.mjs +74 -0
  445. package/dist/store/conflicts.mjs +79 -0
  446. package/dist/store/create-tables.d.mts +29 -0
  447. package/dist/store/create-tables.mjs +91 -0
  448. package/dist/store/discard.mjs +60 -0
  449. package/dist/store/drafts.mjs +132 -0
  450. package/dist/store/editor.mjs +22 -0
  451. package/dist/store/log.mjs +22 -0
  452. package/dist/store/publish.mjs +177 -0
  453. package/dist/store/publisher.mjs +16 -0
  454. package/dist/store/reader.mjs +139 -0
  455. package/dist/store/review.mjs +177 -0
  456. package/dist/store/rows.mjs +205 -0
  457. package/dist/store/tenant.mjs +23 -0
  458. package/dist/store/undo.mjs +49 -0
  459. package/dist/store/unpublished.mjs +47 -0
  460. package/dist/store/versions.mjs +93 -0
  461. package/dist/store/writer.mjs +19 -0
  462. package/dist/testing/adapter-suite.d.mts +12 -0
  463. package/dist/testing/adapter-suite.mjs +281 -0
  464. package/dist/testing/index.d.mts +2 -0
  465. package/dist/testing/index.mjs +1 -0
  466. package/dist/tile-doc.mjs +44 -0
  467. package/dist/tiles.mjs +102 -0
  468. package/package.json +125 -3
  469. package/src/adapter/sql-adapter.ts +95 -0
  470. package/src/adapter/statement.ts +185 -0
  471. package/src/authorize.ts +73 -0
  472. package/src/body.ts +169 -0
  473. package/src/bounded.ts +43 -0
  474. package/src/cache.ts +192 -0
  475. package/src/checks.ts +170 -0
  476. package/src/custom-source.ts +59 -0
  477. package/src/dashboard-id.ts +36 -0
  478. package/src/dashboards.ts +132 -0
  479. package/src/editing.ts +148 -0
  480. package/src/endpoints/access.ts +41 -0
  481. package/src/endpoints/dashboards.ts +92 -0
  482. package/src/endpoints/drafts.ts +138 -0
  483. package/src/endpoints/index.ts +21 -0
  484. package/src/endpoints/meta.ts +137 -0
  485. package/src/endpoints/query.ts +86 -0
  486. package/src/endpoints/read.ts +92 -0
  487. package/src/endpoints/review.ts +89 -0
  488. package/src/endpoints/values.ts +62 -0
  489. package/src/endpoints/versions.ts +104 -0
  490. package/src/execute.ts +207 -0
  491. package/src/handler.ts +232 -0
  492. package/src/http.ts +66 -0
  493. package/src/index.ts +163 -0
  494. package/src/introspect.ts +205 -0
  495. package/src/mcp/api.ts +59 -0
  496. package/src/mcp/format.ts +67 -0
  497. package/src/mcp/index.ts +151 -0
  498. package/src/mcp/query.ts +153 -0
  499. package/src/mcp/resolve.ts +114 -0
  500. package/src/node-postgres.ts +81 -0
  501. package/src/owner.ts +36 -0
  502. package/src/postgres-connection.ts +143 -0
  503. package/src/postgres-store.ts +82 -0
  504. package/src/principal.ts +39 -0
  505. package/src/reading.ts +56 -0
  506. package/src/request-rows.ts +23 -0
  507. package/src/request.ts +22 -0
  508. package/src/storage.ts +63 -0
  509. package/src/store/apply.ts +129 -0
  510. package/src/store/commands.ts +75 -0
  511. package/src/store/conflicts.ts +98 -0
  512. package/src/store/create-tables.ts +104 -0
  513. package/src/store/discard.ts +42 -0
  514. package/src/store/drafts.ts +133 -0
  515. package/src/store/editor.ts +28 -0
  516. package/src/store/log.ts +28 -0
  517. package/src/store/publish.ts +199 -0
  518. package/src/store/publisher.ts +21 -0
  519. package/src/store/reader.ts +139 -0
  520. package/src/store/review.ts +239 -0
  521. package/src/store/rows.ts +250 -0
  522. package/src/store/tenant.ts +28 -0
  523. package/src/store/undo.ts +56 -0
  524. package/src/store/unpublished.ts +33 -0
  525. package/src/store/versions.ts +106 -0
  526. package/src/store/writer.ts +19 -0
  527. package/src/testing/adapter-suite.ts +239 -0
  528. package/src/testing/index.ts +2 -0
  529. package/src/tile-doc.ts +46 -0
  530. package/src/tiles.ts +120 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Derive
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,91 @@
1
- # Temporary Holding Version
1
+ # Derive Dashboards
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Open-source embedded dashboards for your product. Built by [Derive](https://derive.to).
4
+
5
+ You describe your data once, as a model in code. Your users then build, filter and share
6
+ dashboards inside your app, and every query runs under your access rules: your tenants and
7
+ row rules when you have them, nothing extra when you do not.
8
+
9
+ > **Status: early (0.x).** On Postgres, dashboards
10
+ > defined in code, filters, the rows behind a tile, the widget builder and editing a
11
+ > dashboard (a draft per person, drag and resize, undo and redo, review before publish, merging
12
+ > over someone else's version), new dashboards, version history with in-place preview and
13
+ > Restore, shareable links, and agents that edit and publish as themselves work end to
14
+ > end in the Acme sample, with a client typed from the server. The UI is optional: every flow
15
+ > is an endpoint first. Archiving and SQLite come next.
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ npm install derive-dashboards
21
+ ```
22
+
23
+ One package. The React UI needs `react`, and the line and bar charts need `recharts`: install
24
+ them only if you use those parts. The `derive-dashboards` command (`npx derive-dashboards init`)
25
+ comes with it.
26
+
27
+ Then follow the [quick start](https://github.com/derive-to/dashboards/blob/main/docs/quick-start.md).
28
+
29
+ ## What is here today
30
+
31
+ Embedded dashboards on Postgres, end to end, run by the Acme Tasks sample (`examples/acme`).
32
+
33
+ | Import | Holds |
34
+ | --- | --- |
35
+ | `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
+ | `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/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`. |
41
+
42
+ Tenancy and row policy are opt-in. An app of one tenant leaves them out; once the model has
43
+ tenant keys, every source must say how it is tied to them. A viewer who can read no row of a
44
+ tile's source gets "no access", never zeros.
45
+
46
+ 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),
47
+ [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
+ your own data layer (ClickHouse, an API, your own SQL), see
49
+ [a custom data layer](https://github.com/derive-to/dashboards/blob/main/docs/custom-data-layer.md). The
50
+ [behaviour inventory](https://github.com/derive-to/dashboards/blob/main/docs/behaviour-inventory.md) lists every behaviour the first release
51
+ must cover.
52
+
53
+ ## How correctness is checked
54
+
55
+ Strongest first. [AGENTS.md](https://github.com/derive-to/dashboards/blob/main/AGENTS.md) has the rules.
56
+
57
+ 1. **Types** make wrong states impossible to write.
58
+ 2. **Proofs** (`packages/core/proofs`): the filter operators are defined once and handed to an
59
+ SMT solver, which proves each rule for every possible value.
60
+ The access rules (tenancy, row policy, locks, plugins can only narrow) are also proven in
61
+ **Lean** (`lean/`), and the TypeScript is compared with the Lean model case by case.
62
+ 3. **Laws** (`packages/core/laws`): equations checked on every combination of a small world
63
+ of values, or on generated inputs. Postgres must give the oracle's answer on generated
64
+ queries and on every clock change in the test zones.
65
+ 4. **Hand-worked cases** (`packages/core/conformance`): each answer worked out by hand in a
66
+ comment, run on the oracle and on Postgres.
67
+ 5. **The sample** (`examples/acme`): its tiles equal SQL written by hand, no tile, row or value
68
+ changes when rows a viewer cannot see change, and library overhead stays under 1 ms per
69
+ tile at p95.
70
+ 6. **Example tests**: one case per validation rule, endpoint and adapter.
71
+
72
+ Dates and time zones use TC39 Temporal with the IANA zone database: buckets, ranges and
73
+ comparisons are checked in nine zones chosen for their daylight-saving and offset quirks, and
74
+ on hand-worked New York clock-change days.
75
+
76
+ Case-insensitive text uses Unicode 16 simple case folding, generated from the Unicode data
77
+ in `data/unicode/` and checked in CI.
78
+
79
+ ## Develop
80
+
81
+ ```bash
82
+ pnpm install
83
+ ```
84
+
85
+ ```bash
86
+ pnpm check
87
+ ```
88
+
89
+ ## License
90
+
91
+ MIT
@@ -0,0 +1,80 @@
1
+ import { count, decodeRow, insert, insertAll, remove, select, update } from "./statement.mjs";
2
+ import { CATALOG } from "derive-dashboards/core";
3
+ // src/adapter/sql-adapter.ts
4
+ /** Postgres's codes for a unique violation and a failed serializable or deadlocked transaction. */
5
+ const UNIQUE = /* @__PURE__ */ new Set([
6
+ "23505",
7
+ "SQLITE_CONSTRAINT_UNIQUE",
8
+ "SQLITE_CONSTRAINT_PRIMARYKEY"
9
+ ]);
10
+ const SERIALIZATION = /* @__PURE__ */ new Set([
11
+ "40001",
12
+ "40P01",
13
+ "SQLITE_BUSY"
14
+ ]);
15
+ /** A catalog name, which a driver returns as text. */
16
+ const text = (value) => typeof value === "string" ? value : "";
17
+ function codeOf(error) {
18
+ if (typeof error !== "object" || error === null) return void 0;
19
+ if ("code" in error && typeof error.code === "string") return error.code;
20
+ return "cause" in error ? codeOf(error.cause) : void 0;
21
+ }
22
+ /**
23
+ * The store adapter over any SQL database: the library's reads and writes on its own tables as
24
+ * parameterized statements. A database's store only says how to run a statement, a transaction,
25
+ * and DDL.
26
+ */
27
+ function sqlAdapter(id, runner) {
28
+ return adapterOver(id, runner);
29
+ }
30
+ function adapterOver(id, runner) {
31
+ const { dialect } = runner;
32
+ const rows = async (table, statement) => (await runner.run(statement)).map((row) => decodeRow(table, row));
33
+ return {
34
+ id,
35
+ async createMany({ table, rows: data }) {
36
+ if (data.length > 0) await runner.run(insertAll(dialect, table, data));
37
+ },
38
+ async create({ table, data }) {
39
+ await runner.run(insert(dialect, table, data));
40
+ },
41
+ async findOne({ table, where }) {
42
+ const [first] = await rows(table, select(dialect, {
43
+ table,
44
+ where,
45
+ limit: 1
46
+ }));
47
+ return first ?? null;
48
+ },
49
+ findMany: (a) => rows(a.table, select(dialect, a)),
50
+ async updateMany({ table, where, set }) {
51
+ return (await runner.run(update(dialect, table, where, set))).length;
52
+ },
53
+ async deleteMany({ table, where }) {
54
+ return (await runner.run(remove(dialect, table, where))).length;
55
+ },
56
+ async count({ table, where }) {
57
+ const [row] = await runner.run(count(dialect, table, where ?? []));
58
+ return Number(row?.["n"] ?? 0);
59
+ },
60
+ transaction: (fn) => runner.transaction((tx) => fn(adapterOver(id, tx))),
61
+ classifyError(error) {
62
+ const code = codeOf(error) ?? "";
63
+ if (UNIQUE.has(code)) return "unique";
64
+ return SERIALIZATION.has(code) ? "serialization" : "other";
65
+ },
66
+ schema: {
67
+ dialect,
68
+ execute: (ddl) => runner.execute(ddl),
69
+ columns: async () => (await runner.run({
70
+ strings: [CATALOG[dialect]],
71
+ values: []
72
+ })).map((row) => ({
73
+ table: text(row["table"]),
74
+ column: text(row["column"]),
75
+ ...row["schema"] === void 0 ? {} : { schema: text(row["schema"]) }
76
+ }))
77
+ }
78
+ };
79
+ }
80
+ export { sqlAdapter };
@@ -0,0 +1,140 @@
1
+ import { TABLES } from "derive-dashboards/core";
2
+ // src/adapter/statement.ts
3
+ /** Builds a statement piece by piece: text is appended, values become parameters. */
4
+ var Builder = class {
5
+ #strings = [""];
6
+ #values = [];
7
+ text(part) {
8
+ this.#strings[this.#strings.length - 1] += part;
9
+ return this;
10
+ }
11
+ value(v) {
12
+ this.#values.push(v);
13
+ this.#strings.push("");
14
+ return this;
15
+ }
16
+ build() {
17
+ return {
18
+ strings: [...this.#strings],
19
+ values: [...this.#values]
20
+ };
21
+ }
22
+ };
23
+ const quote = (name) => `"${name.replaceAll("\"", "\"\"")}"`;
24
+ function typeOf(table, field) {
25
+ return TABLES[table].fields[field]?.type;
26
+ }
27
+ /** A column of the table, quoted; any other name is refused before it reaches SQL text. */
28
+ function column(on, field) {
29
+ if (typeOf(on.table, field) === void 0) throw new Error(`"${on.table}" has no field "${field}".`);
30
+ return quote(field);
31
+ }
32
+ /** A value as the column stores it: JSON as text, cast by the statement on Postgres. */
33
+ function param(b, on, field, value) {
34
+ const type = typeOf(on.table, field);
35
+ if (value === null || value === void 0) return b.value(null);
36
+ if (type === "boolean") return b.value(value === true);
37
+ if (type !== "json") return b.value(value);
38
+ const text = JSON.stringify(value);
39
+ return on.dialect === "postgres" ? b.text("CAST(").value(text).text(" AS jsonb)") : b.value(text);
40
+ }
41
+ const OPS = {
42
+ eq: "=",
43
+ ne: "<>",
44
+ lt: "<",
45
+ lte: "<=",
46
+ gt: ">",
47
+ gte: ">="
48
+ };
49
+ function inList(b, on, c) {
50
+ const list = Array.isArray(c.value) ? c.value : [];
51
+ if (list.length === 0) {
52
+ b.text("FALSE");
53
+ return;
54
+ }
55
+ b.text(`${column(on, c.field)} IN (`);
56
+ for (const [i, v] of list.entries()) param(i === 0 ? b : b.text(", "), on, c.field, v);
57
+ b.text(")");
58
+ }
59
+ function condition(b, on, c) {
60
+ const op = c.op ?? "eq";
61
+ const col = column(on, c.field);
62
+ if (op === "isNull") b.text(`${col} IS NULL`);
63
+ else if (op === "notNull") b.text(`${col} IS NOT NULL`);
64
+ else if (op === "in") inList(b, on, c);
65
+ else param(b.text(`${col} ${OPS[op]} `), on, c.field, c.value);
66
+ }
67
+ function where(b, on, conditions) {
68
+ for (const [i, c] of conditions.entries()) condition(b.text(i === 0 ? " WHERE " : " AND "), on, c);
69
+ return b;
70
+ }
71
+ function insert(dialect, table, data) {
72
+ return insertAll(dialect, table, [data]);
73
+ }
74
+ /** One INSERT of every row, each with the first row's fields: one round trip for a batch. */
75
+ function insertAll(dialect, table, rows) {
76
+ const on = {
77
+ dialect,
78
+ table
79
+ };
80
+ const fields = Object.keys(rows[0] ?? {});
81
+ const b = new Builder().text(`INSERT INTO ${quote(table)} (${fields.map((f) => column(on, f)).join(", ")}) VALUES `);
82
+ for (const [r, data] of rows.entries()) {
83
+ b.text(r === 0 ? "(" : ", (");
84
+ for (const [i, f] of fields.entries()) param(i === 0 ? b : b.text(", "), on, f, data[f]);
85
+ b.text(")");
86
+ }
87
+ return b.build();
88
+ }
89
+ function select(dialect, s) {
90
+ const on = {
91
+ dialect,
92
+ table: s.table
93
+ };
94
+ const b = where(new Builder().text(`SELECT * FROM ${quote(s.table)}`), on, s.where ?? []);
95
+ const order = (s.orderBy ?? []).map((o) => `${column(on, o.field)} ${o.direction === "asc" ? "ASC" : "DESC"}`);
96
+ if (order.length > 0) b.text(` ORDER BY ${order.join(", ")}`);
97
+ if (s.limit !== void 0) b.text(" LIMIT ").value(s.limit);
98
+ if (s.offset !== void 0) b.text(" OFFSET ").value(s.offset);
99
+ return b.build();
100
+ }
101
+ function update(dialect, table, conditions, set) {
102
+ const on = {
103
+ dialect,
104
+ table
105
+ };
106
+ const b = new Builder().text(`UPDATE ${quote(table)} SET `);
107
+ for (const [i, f] of Object.keys(set).entries()) param(b.text(`${i === 0 ? "" : ", "}${column(on, f)} = `), on, f, set[f]);
108
+ return where(b, on, conditions).text(" RETURNING 1").build();
109
+ }
110
+ function remove(dialect, table, conditions) {
111
+ const on = {
112
+ dialect,
113
+ table
114
+ };
115
+ return where(new Builder().text(`DELETE FROM ${quote(table)}`), on, conditions).text(" RETURNING 1").build();
116
+ }
117
+ function count(dialect, table, conditions) {
118
+ const on = {
119
+ dialect,
120
+ table
121
+ };
122
+ return where(new Builder().text(`SELECT count(*) AS n FROM ${quote(table)}`), on, conditions).build();
123
+ }
124
+ function timestamp(value) {
125
+ if (value instanceof Date) return value.toISOString();
126
+ if (typeof value === "string" || typeof value === "number") return new Date(value).toISOString();
127
+ throw new TypeError("A timestamp column returned something that is not a time.");
128
+ }
129
+ function decodeValue(type, value) {
130
+ if (value === null || value === void 0) return null;
131
+ if (type === "integer") return Number(value);
132
+ if (type === "boolean") return value === true || value === 1;
133
+ if (type === "json") return typeof value === "string" ? JSON.parse(value) : value;
134
+ return type === "timestamp" ? timestamp(value) : value;
135
+ }
136
+ /** A row as the store reads it: integers as numbers, JSON parsed, timestamps as ISO text. */
137
+ function decodeRow(table, raw) {
138
+ return Object.fromEntries(Object.entries(raw).map(([name, value]) => [name, decodeValue(typeOf(table, name), value)]));
139
+ }
140
+ export { count, decodeRow, insert, insertAll, remove, select, update };
@@ -0,0 +1,55 @@
1
+ import { HttpError } from "./http.mjs";
2
+ import { parseMemberId, queryClosure } from "derive-dashboards/core";
3
+ // src/authorize.ts
4
+ /** Whether the model marks a closure member (`source.name`) sensitive. */
5
+ function isSensitive(options, id) {
6
+ const ref = parseMemberId(id);
7
+ if (ref === void 0) return false;
8
+ const source = options.model.sources[ref.source];
9
+ return (source?.dimensions[ref.name] ?? source?.measures[ref.name])?.sensitive === true;
10
+ }
11
+ /** A member the model marks sensitive is refused unless the host's `sensitive` says yes. */
12
+ function sensitiveAllowed(options, viewer, id) {
13
+ if (!isSensitive(options, id)) return true;
14
+ return viewer !== void 0 && options.access.sensitive?.(viewer, id) === true;
15
+ }
16
+ /**
17
+ * The closure of a query, refused with every problem when it is not valid. The message is the
18
+ * first problem itself, so a person or an agent reads the fix without opening the issues.
19
+ */
20
+ function closureOf(options, query) {
21
+ const closure = queryClosure(options.model, query);
22
+ const [first, ...rest] = closure.issues;
23
+ if (first !== void 0) {
24
+ const more = rest.length === 0 ? "" : ` (and ${rest.length} more)`;
25
+ throw new HttpError(400, "QUERY_INVALID", `${first.message}${more}`, { issues: closure.issues });
26
+ }
27
+ return closure;
28
+ }
29
+ /**
30
+ * Every form of query, by reference or free: no sensitive member unless the host allows it for
31
+ * this viewer. A principal with no viewer (a public link) never reads one.
32
+ */
33
+ function checkSensitive(options, principal, query) {
34
+ const viewer = principal.channel === "user" ? principal.viewer : void 0;
35
+ const refused = closureOf(options, query).members.find((id) => !sensitiveAllowed(options, viewer, id));
36
+ if (refused !== void 0) throw new HttpError(403, "FORBIDDEN", `"${refused}" is sensitive.`);
37
+ }
38
+ /**
39
+ * A free query (the widget builder's preview, an agent's question) is a different grant from viewing a dashboard: the
40
+ * viewer needs `view` on every source and every member it reads.
41
+ */
42
+ async function authorizeFree(options, viewer, query) {
43
+ const closure = closureOf(options, query);
44
+ const checks = [...closure.sources.map((id) => ({
45
+ kind: "source",
46
+ id
47
+ })), ...closure.members.map((id) => ({
48
+ kind: "member",
49
+ id
50
+ }))];
51
+ const answers = await Promise.all(checks.map((r) => Promise.resolve(options.access.can(viewer, "view", r))));
52
+ const refused = checks.find((_r, i) => answers[i] !== true);
53
+ if (refused !== void 0) throw new HttpError(403, "FORBIDDEN", `You cannot read the ${refused.kind} "${refused.id}".`);
54
+ }
55
+ export { authorizeFree, checkSensitive };
package/dist/body.mjs ADDED
@@ -0,0 +1,164 @@
1
+ import { HttpError } from "./http.mjs";
2
+ import { commandSchema, jsonSchema, picksSchema, wireQuerySchema } from "derive-dashboards/core/schema";
3
+ import { z } from "zod";
4
+ // src/body.ts
5
+ /** The request bodies every endpoint checks before anything reads them. Unknown keys are refused. */
6
+ const id = z.string().min(1).max(200);
7
+ const picks = picksSchema;
8
+ /** One edit command, typed as the contract's `Command`, which the schema satisfies. */
9
+ const commands = commandSchema;
10
+ /** A page of rows: after which row it starts (the `next` of the page before) and how many. */
11
+ const page = {
12
+ after: z.string().min(1).max(4e3).exactOptional(),
13
+ limit: z.int().min(1).max(1e3).exactOptional()
14
+ };
15
+ /** A tile by reference: the dashboard, the widget, which of its queries, and the viewer's picks. */
16
+ const tileRef = {
17
+ dashboardId: id,
18
+ widgetId: id,
19
+ query: z.string().max(100).exactOptional(),
20
+ picks: picks.exactOptional(),
21
+ /** The version the client is showing; a different current version is a 409. */
22
+ version: z.int().min(0).exactOptional(),
23
+ /** Run against the viewer's own open draft instead: needs `edit`. */
24
+ draft: z.literal(true).exactOptional(),
25
+ /** Run against what publishing the viewer's draft would make now: needs `edit`. */
26
+ merged: z.literal(true).exactOptional(),
27
+ /** Run against an earlier published version, to preview it: needs `edit`. */
28
+ at: z.int().min(1).exactOptional()
29
+ };
30
+ const bodies = {
31
+ dashboard: z.strictObject({ dashboardId: id }),
32
+ tile: z.strictObject(tileRef),
33
+ tiles: z.strictObject({
34
+ dashboardId: id,
35
+ version: z.int().min(0).exactOptional(),
36
+ tiles: z.array(z.strictObject({
37
+ widgetId: id,
38
+ query: z.string().max(100).exactOptional()
39
+ })).min(1).max(50),
40
+ picks: picks.exactOptional(),
41
+ draft: z.literal(true).exactOptional(),
42
+ merged: z.literal(true).exactOptional(),
43
+ at: z.int().min(1).exactOptional()
44
+ }),
45
+ records: z.strictObject({
46
+ ...tileRef,
47
+ ...page
48
+ }),
49
+ controlValues: z.strictObject({
50
+ dashboardId: id,
51
+ controlId: id,
52
+ search: z.string().max(200).exactOptional(),
53
+ limit: page.limit,
54
+ draft: z.literal(true).exactOptional()
55
+ }),
56
+ memberValues: z.strictObject({
57
+ member: id,
58
+ search: z.string().max(200).exactOptional(),
59
+ limit: page.limit
60
+ }),
61
+ query: z.strictObject({ query: wireQuerySchema }),
62
+ queryBatch: z.strictObject({ queries: z.array(wireQuerySchema).min(1).max(50) }),
63
+ queryRecords: z.strictObject({
64
+ query: wireQuerySchema,
65
+ ...page
66
+ }),
67
+ list: z.strictObject({}),
68
+ newDashboard: z.strictObject({
69
+ title: z.string().min(1).max(500),
70
+ /** The client's id for this create, so a retry makes one dashboard. */
71
+ requestId: z.string().min(1).max(200).exactOptional(),
72
+ /** Start from a published version of another dashboard, as a copy. */
73
+ from: z.strictObject({
74
+ dashboardId: id,
75
+ version: z.int().min(1)
76
+ }).exactOptional()
77
+ }),
78
+ applyDraft: z.strictObject({
79
+ dashboardId: id,
80
+ expectedRevision: z.int().min(0),
81
+ commands: z.array(commands).min(1).max(100).readonly()
82
+ }),
83
+ publishDraft: z.strictObject({
84
+ dashboardId: id,
85
+ expectedRevision: z.int().min(0),
86
+ requestId: id,
87
+ /** The version the review was on top of: another one published since refuses it. */
88
+ head: z.int().min(0)
89
+ }),
90
+ undo: z.strictObject({
91
+ dashboardId: id,
92
+ expectedRevision: z.int().min(0)
93
+ }),
94
+ rebase: z.strictObject({
95
+ dashboardId: id,
96
+ expectedRevision: z.int().min(0),
97
+ head: z.int().min(0),
98
+ drop: z.array(id).max(100).readonly().exactOptional(),
99
+ restore: z.array(id).max(100).readonly().exactOptional()
100
+ }),
101
+ version: z.strictObject({
102
+ dashboardId: id,
103
+ version: z.int().min(1)
104
+ }),
105
+ versions: z.strictObject({
106
+ dashboardId: id,
107
+ before: z.int().min(1).exactOptional()
108
+ }),
109
+ restore: z.strictObject({
110
+ dashboardId: id,
111
+ version: z.number().int().min(1),
112
+ requestId: z.string().min(1).max(200)
113
+ }),
114
+ discardDraft: z.strictObject({
115
+ dashboardId: id,
116
+ expectedRevision: z.int().min(0)
117
+ })
118
+ };
119
+ /** Every endpoint that takes a body, by path, and the body it takes; a test holds it complete. */
120
+ const BODIES_BY_PATH = {
121
+ "/dashboards/get": bodies.dashboard,
122
+ "/dashboards/tile": bodies.tile,
123
+ "/dashboards/tiles": bodies.tiles,
124
+ "/dashboards/records": bodies.records,
125
+ "/dashboards/control-values": bodies.controlValues,
126
+ "/dashboards/new": bodies.newDashboard,
127
+ "/dashboards/draft/start": bodies.dashboard,
128
+ "/dashboards/draft/apply": bodies.applyDraft,
129
+ "/dashboards/draft/undo": bodies.undo,
130
+ "/dashboards/draft/preview": bodies.dashboard,
131
+ "/dashboards/draft/rebase": bodies.rebase,
132
+ "/dashboards/draft/publish": bodies.publishDraft,
133
+ "/dashboards/draft/discard": bodies.discardDraft,
134
+ "/dashboards/versions": bodies.versions,
135
+ "/dashboards/version": bodies.version,
136
+ "/dashboards/restore": bodies.restore,
137
+ "/query/run": bodies.query,
138
+ "/query/validate": bodies.query,
139
+ "/query/batch": bodies.queryBatch,
140
+ "/query/records": bodies.queryRecords,
141
+ "/meta/values": bodies.memberValues
142
+ };
143
+ /** Each endpoint's body as JSON Schema, from the same schemas the endpoints check with. */
144
+ function bodySchemas() {
145
+ return Object.fromEntries(Object.entries(BODIES_BY_PATH).map(([path, schema]) => [path, jsonSchema(schema)]));
146
+ }
147
+ /** Each problem with a body, as one line a person can act on: where it is, and what is wrong. */
148
+ function described(error) {
149
+ return error.issues.map((issue) => {
150
+ const where = issue.path.map(String).join(".");
151
+ const message = /[.!?]$/u.test(issue.message) ? issue.message : `${issue.message}.`;
152
+ return where === "" ? message : `${where}: ${message}`;
153
+ }).join(" ");
154
+ }
155
+ /**
156
+ * Checks a body against its schema; a body it does not accept is a 400 that says where and why.
157
+ * A free query's body is refused as `QUERY_INVALID`, any other as `BODY_INVALID`.
158
+ */
159
+ function parseWith(schema, input, code = "BODY_INVALID") {
160
+ const parsed = schema.safeParse(input);
161
+ if (!parsed.success) throw new HttpError(400, code, described(parsed.error));
162
+ return parsed.data;
163
+ }
164
+ export { bodies, bodySchemas, parseWith };
@@ -0,0 +1,31 @@
1
+ import { HttpError } from "./http.mjs";
2
+ // src/bounded.ts
3
+ const pastDeadline = () => new HttpError(504, "QUERY_TIMEOUT", "The query ran past its deadline.");
4
+ /** Work's result, or QUERY_TIMEOUT at the deadline and the abort's reason on abort. */
5
+ async function bounded(work, options) {
6
+ let timer;
7
+ let onAbort;
8
+ const stop = new Promise((_, reject) => {
9
+ timer = setTimeout(() => {
10
+ reject(pastDeadline());
11
+ }, Math.max(0, options.deadline - Date.now()));
12
+ onAbort = () => {
13
+ const reason = options.signal.reason;
14
+ reject(reason instanceof Error ? reason : /* @__PURE__ */ new Error("The request was aborted."));
15
+ };
16
+ options.signal.addEventListener("abort", onAbort, { once: true });
17
+ });
18
+ try {
19
+ return await Promise.race([work, stop]);
20
+ } finally {
21
+ clearTimeout(timer);
22
+ if (onAbort !== void 0) options.signal.removeEventListener("abort", onAbort);
23
+ }
24
+ }
25
+ /** Starts `work` only when the request is still wanted and inside its deadline, and bounds it. */
26
+ function boundedCall(options, work) {
27
+ options.signal.throwIfAborted();
28
+ if (Date.now() >= options.deadline) throw pastDeadline();
29
+ return bounded(work(), options);
30
+ }
31
+ export { bounded, boundedCall, pastDeadline };
@@ -0,0 +1,21 @@
1
+ import { Answered } from "./execute.mjs";
2
+ import { DashOptions, Principal, SourceName, WireQuery } from "derive-dashboards/core";
3
+ /** What decides an answer, besides the rows: everything that goes into its cache key. */
4
+ type CacheKey = {
5
+ principal: Principal;
6
+ query: WireQuery;
7
+ lock: unknown;
8
+ required: unknown;
9
+ calendar: unknown;
10
+ maxRows: number;
11
+ /** `now` floored to the quantum; only a relative range reads it. */
12
+ now: number;
13
+ /** The sources whose epochs the entry depends on. */
14
+ sources: readonly SourceName[];
15
+ };
16
+ export type Cache = {
17
+ answer(key: CacheKey, compute: () => Promise<Answered>): Promise<Answered>;
18
+ /** Drops a tenant's cached answers that read any of `sources` (every source when absent). */
19
+ invalidate(tenant: Record<string, string>, sources?: readonly SourceName[]): Promise<void>;
20
+ };
21
+ export {};