derive-dashboards 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (570) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +91 -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 +174 -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 +65 -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 +15 -0
  41. package/dist/core/conformance/cases.mjs +98 -0
  42. package/dist/core/conformance/check.d.mts +33 -0
  43. package/dist/core/conformance/check.mjs +84 -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/drill-cases.mjs +120 -0
  49. package/dist/core/conformance/index.d.mts +10 -0
  50. package/dist/core/conformance/index.mjs +9 -0
  51. package/dist/core/conformance/memory/aggregate.mjs +76 -0
  52. package/dist/core/conformance/memory/rows.d.mts +10 -0
  53. package/dist/core/conformance/memory/rows.mjs +98 -0
  54. package/dist/core/conformance/memory/source.d.mts +4 -0
  55. package/dist/core/conformance/memory/source.mjs +129 -0
  56. package/dist/core/conformance/queries.mjs +108 -0
  57. package/dist/core/conformance/records-cases.mjs +68 -0
  58. package/dist/core/document/diff.d.mts +68 -0
  59. package/dist/core/document/diff.mjs +155 -0
  60. package/dist/core/document/layout.d.mts +51 -0
  61. package/dist/core/document/layout.mjs +228 -0
  62. package/dist/core/document/outcome.d.mts +10 -0
  63. package/dist/core/document/outcome.mjs +14 -0
  64. package/dist/core/document/reduce.d.mts +16 -0
  65. package/dist/core/document/reduce.mjs +191 -0
  66. package/dist/core/document/replay.d.mts +28 -0
  67. package/dist/core/document/replay.mjs +38 -0
  68. package/dist/core/document/stacked.d.mts +14 -0
  69. package/dist/core/document/stacked.mjs +70 -0
  70. package/dist/core/document/tabs.mjs +70 -0
  71. package/dist/core/document/types.d.mts +138 -0
  72. package/dist/core/document/types.mjs +16 -0
  73. package/dist/core/document/upgrade.d.mts +25 -0
  74. package/dist/core/document/upgrade.mjs +49 -0
  75. package/dist/core/document/view.d.mts +49 -0
  76. package/dist/core/document/view.mjs +81 -0
  77. package/dist/core/engine/access.mjs +113 -0
  78. package/dist/core/engine/assert.d.mts +21 -0
  79. package/dist/core/engine/assert.mjs +132 -0
  80. package/dist/core/engine/bucket.mjs +52 -0
  81. package/dist/core/engine/build.mjs +71 -0
  82. package/dist/core/engine/checks.mjs +29 -0
  83. package/dist/core/engine/context.mjs +46 -0
  84. package/dist/core/engine/cursor.mjs +30 -0
  85. package/dist/core/engine/custom/ask.mjs +13 -0
  86. package/dist/core/engine/custom/cells.mjs +80 -0
  87. package/dist/core/engine/custom/fields.mjs +130 -0
  88. package/dist/core/engine/custom/level.mjs +136 -0
  89. package/dist/core/engine/custom/measures.mjs +146 -0
  90. package/dist/core/engine/custom/query.mjs +37 -0
  91. package/dist/core/engine/custom/reader.d.mts +7 -0
  92. package/dist/core/engine/custom/reader.mjs +67 -0
  93. package/dist/core/engine/custom/records.mjs +51 -0
  94. package/dist/core/engine/custom/request.d.mts +283 -0
  95. package/dist/core/engine/custom/seen.mjs +79 -0
  96. package/dist/core/engine/custom/where.mjs +34 -0
  97. package/dist/core/engine/dialect.d.mts +54 -0
  98. package/dist/core/engine/filter.mjs +129 -0
  99. package/dist/core/engine/index.d.mts +28 -0
  100. package/dist/core/engine/index.mjs +20 -0
  101. package/dist/core/engine/leaf.mjs +141 -0
  102. package/dist/core/engine/levels.mjs +175 -0
  103. package/dist/core/engine/measure.mjs +81 -0
  104. package/dist/core/engine/members.mjs +149 -0
  105. package/dist/core/engine/nan.mjs +9 -0
  106. package/dist/core/engine/native.mjs +59 -0
  107. package/dist/core/engine/numbers.mjs +191 -0
  108. package/dist/core/engine/other.mjs +45 -0
  109. package/dist/core/engine/plan.d.mts +54 -0
  110. package/dist/core/engine/postgres.d.mts +6 -0
  111. package/dist/core/engine/postgres.mjs +136 -0
  112. package/dist/core/engine/prepare.mjs +133 -0
  113. package/dist/core/engine/rank-sets.mjs +119 -0
  114. package/dist/core/engine/rank.mjs +149 -0
  115. package/dist/core/engine/read.mjs +74 -0
  116. package/dist/core/engine/reader.d.mts +128 -0
  117. package/dist/core/engine/reader.mjs +18 -0
  118. package/dist/core/engine/record-layout.d.mts +21 -0
  119. package/dist/core/engine/record-layout.mjs +37 -0
  120. package/dist/core/engine/records.d.mts +15 -0
  121. package/dist/core/engine/records.mjs +52 -0
  122. package/dist/core/engine/refs.mjs +58 -0
  123. package/dist/core/engine/run.d.mts +3 -0
  124. package/dist/core/engine/run.mjs +102 -0
  125. package/dist/core/engine/segmented.d.mts +11 -0
  126. package/dist/core/engine/segmented.mjs +83 -0
  127. package/dist/core/engine/series.mjs +95 -0
  128. package/dist/core/engine/shape.d.mts +12 -0
  129. package/dist/core/engine/shape.mjs +92 -0
  130. package/dist/core/engine/sql-marked.mjs +77 -0
  131. package/dist/core/engine/sql-pass.mjs +24 -0
  132. package/dist/core/engine/sql-reader.d.mts +10 -0
  133. package/dist/core/engine/sql-reader.mjs +51 -0
  134. package/dist/core/engine/sql-reads.mjs +28 -0
  135. package/dist/core/engine/sql-records.mjs +101 -0
  136. package/dist/core/engine/sql-split.mjs +158 -0
  137. package/dist/core/engine/sql.d.mts +8 -0
  138. package/dist/core/engine/sql.mjs +33 -0
  139. package/dist/core/engine/statement.mjs +112 -0
  140. package/dist/core/engine/time.mjs +52 -0
  141. package/dist/core/engine/two-step.mjs +104 -0
  142. package/dist/core/engine/types.d.mts +58 -0
  143. package/dist/core/engine/version.d.mts +7 -0
  144. package/dist/core/engine/version.mjs +9 -0
  145. package/dist/core/error/codes.d.mts +185 -0
  146. package/dist/core/error/codes.mjs +154 -0
  147. package/dist/core/error/refusal.d.mts +8 -0
  148. package/dist/core/error/refusal.mjs +11 -0
  149. package/dist/core/exact/decimal.d.mts +22 -0
  150. package/dist/core/exact/decimal.mjs +51 -0
  151. package/dist/core/exact/sum.d.mts +17 -0
  152. package/dist/core/exact/sum.mjs +31 -0
  153. package/dist/core/index.d.mts +60 -0
  154. package/dist/core/index.mjs +47 -0
  155. package/dist/core/model/catalog/check.d.mts +10 -0
  156. package/dist/core/model/catalog/check.mjs +141 -0
  157. package/dist/core/model/catalog/columns.mjs +34 -0
  158. package/dist/core/model/catalog/queries.d.mts +12 -0
  159. package/dist/core/model/catalog/queries.mjs +50 -0
  160. package/dist/core/model/defaults.d.mts +3 -0
  161. package/dist/core/model/defaults.mjs +24 -0
  162. package/dist/core/model/define.d.mts +32 -0
  163. package/dist/core/model/define.mjs +21 -0
  164. package/dist/core/model/hints.d.mts +36 -0
  165. package/dist/core/model/member.d.mts +28 -0
  166. package/dist/core/model/member.mjs +71 -0
  167. package/dist/core/model/storage.mjs +28 -0
  168. package/dist/core/model/types.d.mts +272 -0
  169. package/dist/core/model/types.mjs +9 -0
  170. package/dist/core/model/validate/drill.mjs +70 -0
  171. package/dist/core/model/validate/expr.d.mts +10 -0
  172. package/dist/core/model/validate/expr.mjs +56 -0
  173. package/dist/core/model/validate/filter.mjs +28 -0
  174. package/dist/core/model/validate/index.d.mts +10 -0
  175. package/dist/core/model/validate/index.mjs +39 -0
  176. package/dist/core/model/validate/issues.mjs +17 -0
  177. package/dist/core/model/validate/members.mjs +98 -0
  178. package/dist/core/model/validate/policy.mjs +76 -0
  179. package/dist/core/model/validate/shape.mjs +150 -0
  180. package/dist/core/model/validate/source.mjs +145 -0
  181. package/dist/core/model/validate/via.d.mts +4 -0
  182. package/dist/core/model/validate/via.mjs +47 -0
  183. package/dist/core/oracle/data.d.mts +37 -0
  184. package/dist/core/oracle/data.mjs +30 -0
  185. package/dist/core/oracle/evaluate.d.mts +23 -0
  186. package/dist/core/oracle/evaluate.mjs +117 -0
  187. package/dist/core/oracle/expr.mjs +74 -0
  188. package/dist/core/oracle/facts.mjs +72 -0
  189. package/dist/core/oracle/filter.d.mts +6 -0
  190. package/dist/core/oracle/filter.mjs +25 -0
  191. package/dist/core/oracle/groups.mjs +33 -0
  192. package/dist/core/oracle/index.d.mts +4 -0
  193. package/dist/core/oracle/index.mjs +3 -0
  194. package/dist/core/oracle/levels.mjs +46 -0
  195. package/dist/core/oracle/logic.mjs +38 -0
  196. package/dist/core/oracle/measure.mjs +85 -0
  197. package/dist/core/oracle/members.mjs +80 -0
  198. package/dist/core/oracle/request.mjs +38 -0
  199. package/dist/core/oracle/segmented.d.mts +7 -0
  200. package/dist/core/oracle/segmented.mjs +35 -0
  201. package/dist/core/oracle/split.mjs +84 -0
  202. package/dist/core/oracle/time-axis.mjs +37 -0
  203. package/dist/core/oracle/time-value.mjs +28 -0
  204. package/dist/core/oracle/tree.mjs +24 -0
  205. package/dist/core/oracle/values.mjs +41 -0
  206. package/dist/core/oracle/visibility.mjs +49 -0
  207. package/dist/core/policy/bind.d.mts +25 -0
  208. package/dist/core/policy/bind.mjs +64 -0
  209. package/dist/core/policy/match.d.mts +16 -0
  210. package/dist/core/policy/match.mjs +44 -0
  211. package/dist/core/query/alias.mjs +20 -0
  212. package/dist/core/query/closure.d.mts +17 -0
  213. package/dist/core/query/closure.mjs +131 -0
  214. package/dist/core/query/compose-tile.d.mts +50 -0
  215. package/dist/core/query/compose-tile.mjs +140 -0
  216. package/dist/core/query/compose.d.mts +105 -0
  217. package/dist/core/query/compose.mjs +12 -0
  218. package/dist/core/query/derived-rules.mjs +56 -0
  219. package/dist/core/query/drill/compose.d.mts +22 -0
  220. package/dist/core/query/drill/compose.mjs +85 -0
  221. package/dist/core/query/drill/fields.d.mts +21 -0
  222. package/dist/core/query/drill/fields.mjs +91 -0
  223. package/dist/core/query/drill/internal.d.mts +11 -0
  224. package/dist/core/query/drill/items.d.mts +29 -0
  225. package/dist/core/query/drill/items.mjs +98 -0
  226. package/dist/core/query/drill/line.d.mts +31 -0
  227. package/dist/core/query/drill/line.mjs +183 -0
  228. package/dist/core/query/drill/links.d.mts +33 -0
  229. package/dist/core/query/drill/links.mjs +31 -0
  230. package/dist/core/query/drill/operand.mjs +7 -0
  231. package/dist/core/query/drill/scopes.d.mts +22 -0
  232. package/dist/core/query/drill/scopes.mjs +58 -0
  233. package/dist/core/query/drill/selection.d.mts +37 -0
  234. package/dist/core/query/drill/selection.mjs +144 -0
  235. package/dist/core/query/drill/steps.d.mts +14 -0
  236. package/dist/core/query/drill/steps.mjs +35 -0
  237. package/dist/core/query/drill/synthetic-expr.mjs +85 -0
  238. package/dist/core/query/drill/synthetic.d.mts +22 -0
  239. package/dist/core/query/drill/synthetic.mjs +165 -0
  240. package/dist/core/query/drill/time.d.mts +11 -0
  241. package/dist/core/query/drill/time.mjs +71 -0
  242. package/dist/core/query/drill/types.d.mts +155 -0
  243. package/dist/core/query/drill/types.mjs +4 -0
  244. package/dist/core/query/drill/views.d.mts +62 -0
  245. package/dist/core/query/drill/views.mjs +257 -0
  246. package/dist/core/query/effective.d.mts +32 -0
  247. package/dist/core/query/effective.mjs +22 -0
  248. package/dist/core/query/filter.d.mts +99 -0
  249. package/dist/core/query/filter.mjs +79 -0
  250. package/dist/core/query/formulas.d.mts +17 -0
  251. package/dist/core/query/formulas.mjs +52 -0
  252. package/dist/core/query/picks.d.mts +10 -0
  253. package/dist/core/query/picks.mjs +25 -0
  254. package/dist/core/query/segments.d.mts +16 -0
  255. package/dist/core/query/segments.mjs +184 -0
  256. package/dist/core/query/to-wire.d.mts +21 -0
  257. package/dist/core/query/to-wire.mjs +124 -0
  258. package/dist/core/query/types.d.mts +238 -0
  259. package/dist/core/result/calc.mjs +95 -0
  260. package/dist/core/result/columns.d.mts +13 -0
  261. package/dist/core/result/columns.mjs +131 -0
  262. package/dist/core/result/marks.d.mts +20 -0
  263. package/dist/core/result/marks.mjs +35 -0
  264. package/dist/core/result/number.mjs +78 -0
  265. package/dist/core/result/order.d.mts +2 -0
  266. package/dist/core/result/order.mjs +57 -0
  267. package/dist/core/result/types.d.mts +70 -0
  268. package/dist/core/result/zero.mjs +18 -0
  269. package/dist/core/schema/answer-parts.mjs +117 -0
  270. package/dist/core/schema/answers.d.mts +4051 -0
  271. package/dist/core/schema/answers.mjs +114 -0
  272. package/dist/core/schema/commands.d.mts +273 -0
  273. package/dist/core/schema/commands.mjs +129 -0
  274. package/dist/core/schema/custom.d.mts +13 -0
  275. package/dist/core/schema/custom.mjs +250 -0
  276. package/dist/core/schema/document.d.mts +149 -0
  277. package/dist/core/schema/document.mjs +216 -0
  278. package/dist/core/schema/drill-answers.mjs +179 -0
  279. package/dist/core/schema/drill.d.mts +260 -0
  280. package/dist/core/schema/drill.mjs +107 -0
  281. package/dist/core/schema/editing.mjs +166 -0
  282. package/dist/core/schema/index.d.mts +11 -0
  283. package/dist/core/schema/index.mjs +11 -0
  284. package/dist/core/schema/issue.mjs +18 -0
  285. package/dist/core/schema/picks.d.mts +35 -0
  286. package/dist/core/schema/picks.mjs +23 -0
  287. package/dist/core/schema/query.d.mts +92 -0
  288. package/dist/core/schema/query.mjs +174 -0
  289. package/dist/core/schema/tools.d.mts +17 -0
  290. package/dist/core/schema/tools.mjs +62 -0
  291. package/dist/core/schema/view.d.mts +12 -0
  292. package/dist/core/schema/view.mjs +66 -0
  293. package/dist/core/store/ddl.d.mts +38 -0
  294. package/dist/core/store/ddl.mjs +79 -0
  295. package/dist/core/store/schema.d.mts +320 -0
  296. package/dist/core/store/schema.mjs +191 -0
  297. package/dist/core/time/bucket.d.mts +25 -0
  298. package/dist/core/time/bucket.mjs +103 -0
  299. package/dist/core/time/compare.d.mts +30 -0
  300. package/dist/core/time/compare.mjs +73 -0
  301. package/dist/core/time/index.d.mts +7 -0
  302. package/dist/core/time/instant.d.mts +14 -0
  303. package/dist/core/time/instant.mjs +58 -0
  304. package/dist/core/time/range.d.mts +21 -0
  305. package/dist/core/time/range.mjs +41 -0
  306. package/dist/core/time/stored.d.mts +10 -0
  307. package/dist/core/time/stored.mjs +29 -0
  308. package/dist/core/time/temporal.d.mts +14 -0
  309. package/dist/core/time/temporal.mjs +27 -0
  310. package/dist/core/time/zone.d.mts +27 -0
  311. package/dist/core/time/zone.mjs +55 -0
  312. package/dist/core/types/api.d.mts +341 -0
  313. package/dist/core/types/api.mjs +9 -0
  314. package/dist/core/types/drill-api.d.mts +210 -0
  315. package/dist/core/types/infer.d.mts +91 -0
  316. package/dist/core/types/options.d.mts +115 -0
  317. package/dist/core/types/plugin.d.mts +82 -0
  318. package/dist/core/types/plugin.mjs +12 -0
  319. package/dist/core/types/primitives.d.mts +26 -0
  320. package/dist/core/types/provider.d.mts +74 -0
  321. package/dist/core/types/source.d.mts +73 -0
  322. package/dist/core/types/store.d.mts +327 -0
  323. package/dist/core/types/viewer.d.mts +79 -0
  324. package/dist/core/types/viewer.mjs +6 -0
  325. package/dist/core/value/canonical.d.mts +5 -0
  326. package/dist/core/value/canonical.mjs +10 -0
  327. package/dist/core/value/casefold-data.mjs +3 -0
  328. package/dist/core/value/casefold.d.mts +8 -0
  329. package/dist/core/value/casefold.mjs +36 -0
  330. package/dist/core/value/compare.d.mts +3 -0
  331. package/dist/core/value/compare.mjs +18 -0
  332. package/dist/cursor-seal.d.mts +8 -0
  333. package/dist/cursor-seal.mjs +98 -0
  334. package/dist/custom-source.d.mts +21 -0
  335. package/dist/custom-source.mjs +30 -0
  336. package/dist/dashboard-id.mjs +31 -0
  337. package/dist/dashboards.mjs +84 -0
  338. package/dist/drill-access.mjs +93 -0
  339. package/dist/drill-change.mjs +76 -0
  340. package/dist/drill-crumbs.mjs +113 -0
  341. package/dist/drill-distinct.mjs +130 -0
  342. package/dist/drill-explain.mjs +64 -0
  343. package/dist/drill-identity.mjs +35 -0
  344. package/dist/drill-item-id.mjs +35 -0
  345. package/dist/drill-items.mjs +132 -0
  346. package/dist/drill-open.mjs +169 -0
  347. package/dist/drill-seal.mjs +170 -0
  348. package/dist/drill-secret.mjs +14 -0
  349. package/dist/drill-share.mjs +53 -0
  350. package/dist/drill-summary.mjs +158 -0
  351. package/dist/drill-targets.mjs +53 -0
  352. package/dist/drill-totals.mjs +8 -0
  353. package/dist/drill-views.mjs +175 -0
  354. package/dist/drill.mjs +157 -0
  355. package/dist/editing.mjs +114 -0
  356. package/dist/endpoints/access.mjs +44 -0
  357. package/dist/endpoints/dashboards.mjs +117 -0
  358. package/dist/endpoints/drafts.mjs +138 -0
  359. package/dist/endpoints/drill.mjs +55 -0
  360. package/dist/endpoints/index.d.mts +684 -0
  361. package/dist/endpoints/index.mjs +43 -0
  362. package/dist/endpoints/meta.mjs +123 -0
  363. package/dist/endpoints/query.mjs +94 -0
  364. package/dist/endpoints/read.mjs +79 -0
  365. package/dist/endpoints/review.mjs +91 -0
  366. package/dist/endpoints/values.mjs +58 -0
  367. package/dist/endpoints/versions.mjs +103 -0
  368. package/dist/execute.d.mts +28 -0
  369. package/dist/execute.mjs +150 -0
  370. package/dist/handler.mjs +189 -0
  371. package/dist/http.d.mts +16 -0
  372. package/dist/http.mjs +67 -0
  373. package/dist/index.d.mts +26 -0
  374. package/dist/index.mjs +142 -0
  375. package/dist/introspect.mjs +180 -0
  376. package/dist/mcp/api.d.mts +10 -0
  377. package/dist/mcp/api.mjs +34 -0
  378. package/dist/mcp/drill.mjs +61 -0
  379. package/dist/mcp/format.d.mts +10 -0
  380. package/dist/mcp/format.mjs +83 -0
  381. package/dist/mcp/index.d.mts +72 -0
  382. package/dist/mcp/index.mjs +94 -0
  383. package/dist/mcp/query.d.mts +11 -0
  384. package/dist/mcp/query.mjs +127 -0
  385. package/dist/mcp/resolve.mjs +67 -0
  386. package/dist/node-postgres.d.mts +37 -0
  387. package/dist/node-postgres.mjs +82 -0
  388. package/dist/owner.mjs +34 -0
  389. package/dist/postgres-connection.d.mts +39 -0
  390. package/dist/postgres-connection.mjs +85 -0
  391. package/dist/postgres-store.d.mts +38 -0
  392. package/dist/postgres-store.mjs +60 -0
  393. package/dist/principal.mjs +28 -0
  394. package/dist/react/CancelRestore.mjs +21 -0
  395. package/dist/react/Canvas.mjs +97 -0
  396. package/dist/react/Cell.mjs +106 -0
  397. package/dist/react/ConfirmButton.mjs +31 -0
  398. package/dist/react/Dashboard.d.mts +32 -0
  399. package/dist/react/Dashboard.mjs +108 -0
  400. package/dist/react/DashboardList.d.mts +12 -0
  401. package/dist/react/DashboardList.mjs +183 -0
  402. package/dist/react/Discard.mjs +104 -0
  403. package/dist/react/EditBar.d.mts +16 -0
  404. package/dist/react/EditBar.mjs +141 -0
  405. package/dist/react/Editing.mjs +124 -0
  406. package/dist/react/FilterBar.d.mts +9 -0
  407. package/dist/react/FilterBar.mjs +119 -0
  408. package/dist/react/Grid.mjs +140 -0
  409. package/dist/react/Header.mjs +116 -0
  410. package/dist/react/History.d.mts +30 -0
  411. package/dist/react/History.mjs +202 -0
  412. package/dist/react/Notice.d.mts +8 -0
  413. package/dist/react/Notice.mjs +51 -0
  414. package/dist/react/Overlaps.mjs +54 -0
  415. package/dist/react/Panel.d.mts +16 -0
  416. package/dist/react/Panel.mjs +93 -0
  417. package/dist/react/Parts.mjs +102 -0
  418. package/dist/react/ReviewPanel.d.mts +15 -0
  419. package/dist/react/ReviewPanel.mjs +211 -0
  420. package/dist/react/RowBody.d.mts +19 -0
  421. package/dist/react/RowBody.mjs +55 -0
  422. package/dist/react/Spaces.mjs +108 -0
  423. package/dist/react/Tile.d.mts +20 -0
  424. package/dist/react/Tile.mjs +147 -0
  425. package/dist/react/arrange-steps.mjs +108 -0
  426. package/dist/react/arrange.mjs +135 -0
  427. package/dist/react/board.d.mts +16 -0
  428. package/dist/react/board.mjs +156 -0
  429. package/dist/react/builder/Calcs.mjs +87 -0
  430. package/dist/react/builder/Filters.mjs +165 -0
  431. package/dist/react/builder/Groups.mjs +189 -0
  432. package/dist/react/builder/Picker.mjs +154 -0
  433. package/dist/react/builder/Preview.d.mts +6 -0
  434. package/dist/react/builder/Preview.mjs +102 -0
  435. package/dist/react/builder/Sections.mjs +85 -0
  436. package/dist/react/builder/Time.mjs +119 -0
  437. package/dist/react/builder/WidgetBuilder.d.mts +23 -0
  438. package/dist/react/builder/WidgetBuilder.mjs +202 -0
  439. package/dist/react/builder/base.d.mts +19 -0
  440. package/dist/react/builder/base.mjs +111 -0
  441. package/dist/react/builder/calc.d.mts +5 -0
  442. package/dist/react/builder/calc.mjs +110 -0
  443. package/dist/react/builder/labels.d.mts +1 -0
  444. package/dist/react/builder/labels.mjs +55 -0
  445. package/dist/react/builder/options.mjs +55 -0
  446. package/dist/react/builder/state.d.mts +12 -0
  447. package/dist/react/builder/state.mjs +201 -0
  448. package/dist/react/builder/useBuilder.d.mts +46 -0
  449. package/dist/react/builder/useBuilder.mjs +60 -0
  450. package/dist/react/builder/usePreview.mjs +56 -0
  451. package/dist/react/client.d.mts +95 -0
  452. package/dist/react/client.mjs +108 -0
  453. package/dist/react/context.d.mts +46 -0
  454. package/dist/react/context.mjs +59 -0
  455. package/dist/react/debounce.mjs +19 -0
  456. package/dist/react/draft.d.mts +55 -0
  457. package/dist/react/draft.mjs +230 -0
  458. package/dist/react/drill/Bars.mjs +179 -0
  459. package/dist/react/drill/Controls.mjs +173 -0
  460. package/dist/react/drill/DashboardTile.d.mts +18 -0
  461. package/dist/react/drill/DashboardTile.mjs +107 -0
  462. package/dist/react/drill/DrillPanel.d.mts +31 -0
  463. package/dist/react/drill/DrillPanel.mjs +104 -0
  464. package/dist/react/drill/DrillTabs.mjs +52 -0
  465. package/dist/react/drill/Header.mjs +131 -0
  466. package/dist/react/drill/Items.d.mts +22 -0
  467. package/dist/react/drill/Items.mjs +164 -0
  468. package/dist/react/drill/ItemsFoot.mjs +60 -0
  469. package/dist/react/drill/Notes.mjs +58 -0
  470. package/dist/react/drill/PanelBody.mjs +74 -0
  471. package/dist/react/drill/PanelStates.mjs +37 -0
  472. package/dist/react/drill/board.d.mts +18 -0
  473. package/dist/react/drill/board.mjs +91 -0
  474. package/dist/react/drill/counts.mjs +14 -0
  475. package/dist/react/drill/host.mjs +26 -0
  476. package/dist/react/drill/item-parts.d.mts +5 -0
  477. package/dist/react/drill/item-parts.mjs +76 -0
  478. package/dist/react/drill/item-type.d.mts +26 -0
  479. package/dist/react/drill/item-type.mjs +7 -0
  480. package/dist/react/drill/lazy.d.mts +6 -0
  481. package/dist/react/drill/lazy.mjs +17 -0
  482. package/dist/react/drill/pages.mjs +48 -0
  483. package/dist/react/drill/panel-focus.mjs +51 -0
  484. package/dist/react/drill/props.d.mts +25 -0
  485. package/dist/react/drill/props.mjs +72 -0
  486. package/dist/react/drill/state.d.mts +18 -0
  487. package/dist/react/drill/state.mjs +68 -0
  488. package/dist/react/drill/useDrill.d.mts +46 -0
  489. package/dist/react/drill/useDrill.mjs +194 -0
  490. package/dist/react/drill/words.d.mts +98 -0
  491. package/dist/react/drill/words.mjs +77 -0
  492. package/dist/react/english.d.mts +3 -0
  493. package/dist/react/english.mjs +157 -0
  494. package/dist/react/errors.d.mts +12 -0
  495. package/dist/react/errors.mjs +13 -0
  496. package/dist/react/format.d.mts +25 -0
  497. package/dist/react/format.mjs +175 -0
  498. package/dist/react/index.d.mts +50 -0
  499. package/dist/react/index.mjs +32 -0
  500. package/dist/react/marks.d.mts +11 -0
  501. package/dist/react/marks.mjs +62 -0
  502. package/dist/react/messages.d.mts +172 -0
  503. package/dist/react/place.mjs +21 -0
  504. package/dist/react/read.d.mts +15 -0
  505. package/dist/react/read.mjs +54 -0
  506. package/dist/react/renderers/index.d.mts +27 -0
  507. package/dist/react/renderers/index.mjs +125 -0
  508. package/dist/react/renderers/list.d.mts +22 -0
  509. package/dist/react/renderers/list.mjs +118 -0
  510. package/dist/react/review-words.d.mts +79 -0
  511. package/dist/react/review-words.mjs +132 -0
  512. package/dist/react/review.d.mts +26 -0
  513. package/dist/react/review.mjs +110 -0
  514. package/dist/react/scope.mjs +4 -0
  515. package/dist/react/series.d.mts +37 -0
  516. package/dist/react/series.mjs +95 -0
  517. package/dist/react/stable.mjs +39 -0
  518. package/dist/react/theme.css +1864 -0
  519. package/dist/react/theme.css.d.ts +1 -0
  520. package/dist/react/tile-keys.d.mts +20 -0
  521. package/dist/react/tile-keys.mjs +21 -0
  522. package/dist/react/tile-store.mjs +111 -0
  523. package/dist/react/useBoard.d.mts +85 -0
  524. package/dist/react/useBoard.mjs +56 -0
  525. package/dist/react/useDashboard.d.mts +52 -0
  526. package/dist/react/useDashboard.mjs +57 -0
  527. package/dist/react/useTiles.d.mts +20 -0
  528. package/dist/react/useTiles.mjs +168 -0
  529. package/dist/react/view.d.mts +9 -0
  530. package/dist/react/view.mjs +64 -0
  531. package/dist/reading.d.mts +2 -0
  532. package/dist/reading.mjs +51 -0
  533. package/dist/recharts/charts.d.mts +9 -0
  534. package/dist/recharts/charts.mjs +215 -0
  535. package/dist/recharts/index.d.mts +3 -0
  536. package/dist/recharts/index.mjs +3 -0
  537. package/dist/recharts/marks.mjs +83 -0
  538. package/dist/recharts/series.d.mts +2 -0
  539. package/dist/recharts/series.mjs +1 -0
  540. package/dist/records-read.mjs +44 -0
  541. package/dist/request-rows.mjs +21 -0
  542. package/dist/request.mjs +20 -0
  543. package/dist/storage.d.mts +3 -0
  544. package/dist/storage.mjs +54 -0
  545. package/dist/store/apply.mjs +102 -0
  546. package/dist/store/commands.mjs +74 -0
  547. package/dist/store/conflicts.mjs +79 -0
  548. package/dist/store/create-tables.d.mts +29 -0
  549. package/dist/store/create-tables.mjs +91 -0
  550. package/dist/store/discard.mjs +60 -0
  551. package/dist/store/drafts.mjs +132 -0
  552. package/dist/store/editor.mjs +22 -0
  553. package/dist/store/log.mjs +22 -0
  554. package/dist/store/publish.mjs +177 -0
  555. package/dist/store/publisher.mjs +16 -0
  556. package/dist/store/reader.mjs +158 -0
  557. package/dist/store/review.mjs +177 -0
  558. package/dist/store/rows.mjs +205 -0
  559. package/dist/store/tenant.mjs +23 -0
  560. package/dist/store/undo.mjs +49 -0
  561. package/dist/store/unpublished.mjs +47 -0
  562. package/dist/store/versions.mjs +93 -0
  563. package/dist/store/writer.mjs +19 -0
  564. package/dist/testing/adapter-suite.d.mts +12 -0
  565. package/dist/testing/adapter-suite.mjs +281 -0
  566. package/dist/testing/index.d.mts +2 -0
  567. package/dist/testing/index.mjs +1 -0
  568. package/dist/tile-doc.mjs +44 -0
  569. package/dist/tiles.mjs +136 -0
  570. package/package.json +123 -3
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,92 @@
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, drill-in (a click on a bar, a point, a row or a number opens what is
11
+ > behind it: broken down, over time, or as its items, each a link into your app), the widget builder and editing a
12
+ > dashboard (a draft per person, drag and resize, undo and redo, review before publish, merging
13
+ > over someone else's version), new dashboards, version history with in-place preview and
14
+ > Restore, shareable links, and agents that edit and publish as themselves work end to
15
+ > end in the Acme sample, with a client typed from the server. The UI is optional: every flow
16
+ > is an endpoint first. Archiving and SQLite come next.
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ npm install derive-dashboards
22
+ ```
23
+
24
+ One package. The React UI needs `react`, and the line and bar charts need `recharts`: install
25
+ them only if you use those parts. The `derive-dashboards` command (`npx derive-dashboards init`)
26
+ comes with it.
27
+
28
+ Then follow the [quick start](https://github.com/derive-to/dashboards/blob/main/docs/quick-start.md).
29
+
30
+ ## What is here today
31
+
32
+ Embedded dashboards on Postgres, end to end, run by the Acme Tasks sample (`examples/acme`).
33
+
34
+ | Import | Holds |
35
+ | --- | --- |
36
+ | `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. |
37
+ | `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`). |
38
+ | `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`, drill-in (`DrillPanel`, `DashboardTile`, `useDrill`, and `toSeries` and `rowAt` for any chart kit), the widget builder (`WidgetBuilder`, `useBuilder`) and `theme.css`. |
39
+ | `derive-dashboards/recharts` | Line and bar tiles, drawn with Recharts, each mark a drill (install `recharts` to use them; any other chart library plugs into `renderers`). |
40
+ | `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). |
41
+ | `derive-dashboards/cli` | `defineConfig` for `derive-dashboards.config.ts`; the `derive-dashboards` command runs `init`, `check`, `generate`, `create-tables`. |
42
+
43
+ Tenancy and row policy are opt-in. An app of one tenant leaves them out; once the model has
44
+ tenant keys, every source must say how it is tied to them. A viewer who can read no row of a
45
+ tile's source gets "no access", never zeros.
46
+
47
+ 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),
48
+ [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
49
+ your own data layer (ClickHouse, an API, your own SQL), see
50
+ [a custom data layer](https://github.com/derive-to/dashboards/blob/main/docs/custom-data-layer.md). The
51
+ [behaviour inventory](https://github.com/derive-to/dashboards/blob/main/docs/behaviour-inventory.md) lists every behaviour the first release
52
+ must cover.
53
+
54
+ ## How correctness is checked
55
+
56
+ Strongest first. [AGENTS.md](https://github.com/derive-to/dashboards/blob/main/AGENTS.md) has the rules.
57
+
58
+ 1. **Types** make wrong states impossible to write.
59
+ 2. **Proofs** (`packages/core/proofs`): the filter operators are defined once and handed to an
60
+ SMT solver, which proves each rule for every possible value.
61
+ The access rules (tenancy, row policy, locks, plugins can only narrow) are also proven in
62
+ **Lean** (`lean/`), and the TypeScript is compared with the Lean model case by case.
63
+ 3. **Laws** (`packages/core/laws`): equations checked on every combination of a small world
64
+ of values, or on generated inputs. Postgres must give the oracle's answer on generated
65
+ queries and on every clock change in the test zones.
66
+ 4. **Hand-worked cases** (`packages/core/conformance`): each answer worked out by hand in a
67
+ comment, run on the oracle and on Postgres.
68
+ 5. **The sample** (`examples/acme`): its tiles equal SQL written by hand, no tile, row or value
69
+ changes when rows a viewer cannot see change, and library overhead stays under 1 ms per
70
+ tile at p95.
71
+ 6. **Example tests**: one case per validation rule, endpoint and adapter.
72
+
73
+ Dates and time zones use TC39 Temporal with the IANA zone database: buckets, ranges and
74
+ comparisons are checked in nine zones chosen for their daylight-saving and offset quirks, and
75
+ on hand-worked New York clock-change days.
76
+
77
+ Case-insensitive text uses Unicode 16 simple case folding, generated from the Unicode data
78
+ in `data/unicode/` and checked in CI.
79
+
80
+ ## Develop
81
+
82
+ ```bash
83
+ pnpm install
84
+ ```
85
+
86
+ ```bash
87
+ pnpm check
88
+ ```
89
+
90
+ ## License
91
+
92
+ 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,174 @@
1
+ import { HttpError } from "./http.mjs";
2
+ import { commandSchema, drillStateSchema, 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
+ drill: z.strictObject({
50
+ state: drillStateSchema,
51
+ page: z.strictObject({
52
+ after: page.after,
53
+ limit: z.int().min(1).max(200).exactOptional()
54
+ }).exactOptional(),
55
+ summary: z.literal(false).exactOptional()
56
+ }),
57
+ controlValues: z.strictObject({
58
+ dashboardId: id,
59
+ controlId: id,
60
+ search: z.string().max(200).exactOptional(),
61
+ limit: page.limit,
62
+ draft: z.literal(true).exactOptional()
63
+ }),
64
+ memberValues: z.strictObject({
65
+ member: id,
66
+ search: z.string().max(200).exactOptional(),
67
+ limit: page.limit
68
+ }),
69
+ query: z.strictObject({ query: wireQuerySchema }),
70
+ queryBatch: z.strictObject({ queries: z.array(wireQuerySchema).min(1).max(50) }),
71
+ queryRecords: z.strictObject({
72
+ query: wireQuerySchema,
73
+ ...page
74
+ }),
75
+ list: z.strictObject({}),
76
+ newDashboard: z.strictObject({
77
+ title: z.string().min(1).max(500),
78
+ /** The client's id for this create, so a retry makes one dashboard. */
79
+ requestId: z.string().min(1).max(200).exactOptional(),
80
+ /** Start from a published version of another dashboard, as a copy. */
81
+ from: z.strictObject({
82
+ dashboardId: id,
83
+ version: z.int().min(1)
84
+ }).exactOptional()
85
+ }),
86
+ applyDraft: z.strictObject({
87
+ dashboardId: id,
88
+ expectedRevision: z.int().min(0),
89
+ commands: z.array(commands).min(1).max(100).readonly()
90
+ }),
91
+ publishDraft: z.strictObject({
92
+ dashboardId: id,
93
+ expectedRevision: z.int().min(0),
94
+ requestId: id,
95
+ /** The version the review was on top of: another one published since refuses it. */
96
+ head: z.int().min(0)
97
+ }),
98
+ undo: z.strictObject({
99
+ dashboardId: id,
100
+ expectedRevision: z.int().min(0)
101
+ }),
102
+ rebase: z.strictObject({
103
+ dashboardId: id,
104
+ expectedRevision: z.int().min(0),
105
+ head: z.int().min(0),
106
+ drop: z.array(id).max(100).readonly().exactOptional(),
107
+ restore: z.array(id).max(100).readonly().exactOptional()
108
+ }),
109
+ version: z.strictObject({
110
+ dashboardId: id,
111
+ version: z.int().min(1)
112
+ }),
113
+ versions: z.strictObject({
114
+ dashboardId: id,
115
+ before: z.int().min(1).exactOptional()
116
+ }),
117
+ restore: z.strictObject({
118
+ dashboardId: id,
119
+ version: z.number().int().min(1),
120
+ requestId: z.string().min(1).max(200)
121
+ }),
122
+ discardDraft: z.strictObject({
123
+ dashboardId: id,
124
+ expectedRevision: z.int().min(0)
125
+ })
126
+ };
127
+ /** Every endpoint that takes a body, by path, and the body it takes; a test holds it complete. */
128
+ const BODIES_BY_PATH = {
129
+ "/dashboards/get": bodies.dashboard,
130
+ "/dashboards/tile": bodies.tile,
131
+ "/dashboards/tiles": bodies.tiles,
132
+ "/dashboards/records": bodies.records,
133
+ "/dashboards/drill": bodies.drill,
134
+ "/query/drill": bodies.drill,
135
+ "/dashboards/control-values": bodies.controlValues,
136
+ "/dashboards/new": bodies.newDashboard,
137
+ "/dashboards/draft/start": bodies.dashboard,
138
+ "/dashboards/draft/apply": bodies.applyDraft,
139
+ "/dashboards/draft/undo": bodies.undo,
140
+ "/dashboards/draft/preview": bodies.dashboard,
141
+ "/dashboards/draft/rebase": bodies.rebase,
142
+ "/dashboards/draft/publish": bodies.publishDraft,
143
+ "/dashboards/draft/discard": bodies.discardDraft,
144
+ "/dashboards/versions": bodies.versions,
145
+ "/dashboards/version": bodies.version,
146
+ "/dashboards/restore": bodies.restore,
147
+ "/query/run": bodies.query,
148
+ "/query/validate": bodies.query,
149
+ "/query/batch": bodies.queryBatch,
150
+ "/query/records": bodies.queryRecords,
151
+ "/meta/values": bodies.memberValues
152
+ };
153
+ /** Each endpoint's body as JSON Schema, from the same schemas the endpoints check with. */
154
+ function bodySchemas() {
155
+ return Object.fromEntries(Object.entries(BODIES_BY_PATH).map(([path, schema]) => [path, jsonSchema(schema)]));
156
+ }
157
+ /** Each problem with a body, as one line a person can act on: where it is, and what is wrong. */
158
+ function described(error) {
159
+ return error.issues.map((issue) => {
160
+ const where = issue.path.map(String).join(".");
161
+ const message = /[.!?]$/u.test(issue.message) ? issue.message : `${issue.message}.`;
162
+ return where === "" ? message : `${where}: ${message}`;
163
+ }).join(" ");
164
+ }
165
+ /**
166
+ * Checks a body against its schema; a body it does not accept is a 400 that says where and why.
167
+ * A free query's body is refused as `QUERY_INVALID`, any other as `BODY_INVALID`.
168
+ */
169
+ function parseWith(schema, input, code = "BODY_INVALID") {
170
+ const parsed = schema.safeParse(input);
171
+ if (!parsed.success) throw new HttpError(400, code, described(parsed.error));
172
+ return parsed.data;
173
+ }
174
+ 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, Model, 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 {};