derive-dashboards 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (410) hide show
  1. package/README.md +8 -5
  2. package/dist/adapter/sql-adapter.mjs +4 -4
  3. package/dist/body.mjs +11 -1
  4. package/dist/cache.d.mts +1 -1
  5. package/dist/cli/add.mjs +130 -0
  6. package/dist/cli/check.mjs +14 -1
  7. package/dist/cli/cli.mjs +14 -12
  8. package/dist/cli/config.mjs +12 -1
  9. package/dist/cli/doctor.mjs +147 -0
  10. package/dist/cli/import/dbt-schema.mjs +2 -2
  11. package/dist/cli/import/index.mjs +2 -2
  12. package/dist/cli/init.mjs +3 -2
  13. package/dist/cli/json.mjs +21 -0
  14. package/dist/cli/layers.mjs +33 -0
  15. package/dist/core/conformance/cases.d.mts +3 -0
  16. package/dist/core/conformance/cases.mjs +20 -4
  17. package/dist/core/conformance/check.mjs +6 -3
  18. package/dist/core/conformance/drill-cases.mjs +120 -0
  19. package/dist/core/document/layout.mjs +1 -1
  20. package/dist/core/document/view-layout.d.mts +14 -0
  21. package/dist/core/document/view-layout.mjs +157 -0
  22. package/dist/core/document/view.d.mts +26 -7
  23. package/dist/core/document/view.mjs +42 -11
  24. package/dist/core/engine/filter.mjs +2 -2
  25. package/dist/core/engine/index.d.mts +14 -2
  26. package/dist/core/engine/index.mjs +12 -1
  27. package/dist/core/engine/leaf.mjs +9 -4
  28. package/dist/core/engine/members.mjs +2 -2
  29. package/dist/core/engine/postgres.mjs +1 -1
  30. package/dist/core/engine/record-layout.d.mts +11 -0
  31. package/dist/core/engine/record-layout.mjs +7 -7
  32. package/dist/core/engine/records.d.mts +3 -2
  33. package/dist/core/engine/records.mjs +2 -1
  34. package/dist/core/engine/segmented.mjs +5 -2
  35. package/dist/core/engine/sql-records.mjs +2 -1
  36. package/dist/core/engine/statement.mjs +37 -3
  37. package/dist/core/engine/types.d.mts +3 -0
  38. package/dist/core/engine/version.d.mts +1 -1
  39. package/dist/core/engine/version.mjs +1 -1
  40. package/dist/core/error/codes.d.mts +33 -1
  41. package/dist/core/error/codes.mjs +30 -2
  42. package/dist/core/index.d.mts +13 -7
  43. package/dist/core/index.mjs +9 -5
  44. package/dist/core/model/catalog/check.mjs +1 -1
  45. package/dist/core/model/hints.d.mts +36 -0
  46. package/dist/core/model/member.d.mts +4 -2
  47. package/dist/core/model/member.mjs +19 -3
  48. package/dist/core/model/types.d.mts +21 -19
  49. package/dist/core/model/validate/drill.mjs +70 -0
  50. package/dist/core/model/validate/index.mjs +3 -0
  51. package/dist/core/model/validate/members.mjs +7 -4
  52. package/dist/core/model/validate/shape.mjs +150 -0
  53. package/dist/core/model/validate/source.mjs +5 -3
  54. package/dist/core/policy/bind-query.d.mts +12 -0
  55. package/dist/core/policy/bind-query.mjs +53 -0
  56. package/dist/core/query/alias.mjs +7 -1
  57. package/dist/core/query/drill/compose.d.mts +22 -0
  58. package/dist/core/query/drill/compose.mjs +85 -0
  59. package/dist/core/query/drill/fields.d.mts +21 -0
  60. package/dist/core/query/drill/fields.mjs +91 -0
  61. package/dist/core/query/drill/internal.d.mts +11 -0
  62. package/dist/core/query/drill/items.d.mts +29 -0
  63. package/dist/core/query/drill/items.mjs +98 -0
  64. package/dist/core/query/drill/line.d.mts +31 -0
  65. package/dist/core/query/drill/line.mjs +183 -0
  66. package/dist/core/query/drill/links.d.mts +33 -0
  67. package/dist/core/query/drill/links.mjs +31 -0
  68. package/dist/core/query/drill/operand.mjs +7 -0
  69. package/dist/core/query/drill/scopes.d.mts +22 -0
  70. package/dist/core/query/drill/scopes.mjs +58 -0
  71. package/dist/core/query/drill/selection.d.mts +37 -0
  72. package/dist/core/query/drill/selection.mjs +144 -0
  73. package/dist/core/query/drill/steps.d.mts +14 -0
  74. package/dist/core/query/drill/steps.mjs +35 -0
  75. package/dist/core/query/drill/synthetic-expr.mjs +85 -0
  76. package/dist/core/query/drill/synthetic.d.mts +22 -0
  77. package/dist/core/query/drill/synthetic.mjs +165 -0
  78. package/dist/core/query/drill/time.d.mts +11 -0
  79. package/dist/core/query/drill/time.mjs +71 -0
  80. package/dist/core/query/drill/types.d.mts +155 -0
  81. package/dist/core/query/drill/types.mjs +4 -0
  82. package/dist/core/query/drill/views.d.mts +62 -0
  83. package/dist/core/query/drill/views.mjs +257 -0
  84. package/dist/core/query/filter.d.mts +6 -0
  85. package/dist/core/query/picks.d.mts +8 -2
  86. package/dist/core/query/picks.mjs +11 -4
  87. package/dist/core/query/segments.d.mts +12 -2
  88. package/dist/core/query/segments.mjs +5 -2
  89. package/dist/core/result/columns.mjs +20 -4
  90. package/dist/core/result/types.d.mts +5 -1
  91. package/dist/core/schema/aliases.d.mts +7 -0
  92. package/dist/core/schema/aliases.mjs +77 -0
  93. package/dist/core/schema/answer-parts.mjs +117 -0
  94. package/dist/core/schema/answers.d.mts +2109 -128
  95. package/dist/core/schema/answers.mjs +11 -113
  96. package/dist/core/schema/commands.d.mts +2 -2
  97. package/dist/core/schema/document.d.mts +1 -1
  98. package/dist/core/schema/drill-answers.mjs +179 -0
  99. package/dist/core/schema/drill.d.mts +260 -0
  100. package/dist/core/schema/drill.mjs +107 -0
  101. package/dist/core/schema/index.d.mts +6 -3
  102. package/dist/core/schema/index.mjs +6 -3
  103. package/dist/core/schema/picks.d.mts +35 -0
  104. package/dist/core/schema/picks.mjs +23 -0
  105. package/dist/core/schema/query.d.mts +82 -1
  106. package/dist/core/schema/query.mjs +9 -5
  107. package/dist/core/schema/tools.mjs +1 -1
  108. package/dist/core/schema/view.d.mts +0 -35
  109. package/dist/core/schema/view.mjs +19 -24
  110. package/dist/core/store/schema.d.mts +5 -0
  111. package/dist/core/store/schema.mjs +10 -0
  112. package/dist/core/types/api.d.mts +21 -1
  113. package/dist/core/types/api.mjs +1 -1
  114. package/dist/core/types/drill-api.d.mts +210 -0
  115. package/dist/core/types/options.d.mts +21 -0
  116. package/dist/core/types/viewer.d.mts +5 -0
  117. package/dist/cursor-seal.d.mts +8 -0
  118. package/dist/cursor-seal.mjs +98 -0
  119. package/dist/dashboard-id.mjs +1 -1
  120. package/dist/dashboards.mjs +4 -0
  121. package/dist/drill-access.mjs +93 -0
  122. package/dist/drill-change.mjs +76 -0
  123. package/dist/drill-crumbs.mjs +113 -0
  124. package/dist/drill-distinct.mjs +130 -0
  125. package/dist/drill-explain.mjs +64 -0
  126. package/dist/drill-identity.mjs +35 -0
  127. package/dist/drill-item-id.mjs +35 -0
  128. package/dist/drill-items.mjs +132 -0
  129. package/dist/drill-open.mjs +169 -0
  130. package/dist/drill-seal.mjs +170 -0
  131. package/dist/drill-secret.mjs +14 -0
  132. package/dist/drill-share.mjs +53 -0
  133. package/dist/drill-summary.mjs +158 -0
  134. package/dist/drill-targets.mjs +53 -0
  135. package/dist/drill-totals.mjs +8 -0
  136. package/dist/drill-views.mjs +175 -0
  137. package/dist/drill.mjs +157 -0
  138. package/dist/editing.mjs +3 -3
  139. package/dist/endpoints/dashboards.mjs +28 -5
  140. package/dist/endpoints/drill.mjs +55 -0
  141. package/dist/endpoints/index.d.mts +245 -4
  142. package/dist/endpoints/index.mjs +5 -1
  143. package/dist/endpoints/meta.mjs +10 -1
  144. package/dist/endpoints/query.mjs +26 -4
  145. package/dist/execute.d.mts +19 -1
  146. package/dist/execute.mjs +34 -27
  147. package/dist/handler.mjs +5 -1
  148. package/dist/index.d.mts +3 -1
  149. package/dist/index.mjs +29 -2
  150. package/dist/llms.txt +22 -0
  151. package/dist/mcp/drill.mjs +61 -0
  152. package/dist/mcp/format.mjs +69 -11
  153. package/dist/mcp/index.d.mts +15 -4
  154. package/dist/mcp/index.mjs +13 -7
  155. package/dist/mcp/query.d.mts +7 -2
  156. package/dist/mcp/query.mjs +40 -6
  157. package/dist/node-postgres.d.mts +8 -4
  158. package/dist/node-postgres.mjs +29 -6
  159. package/dist/owner.mjs +3 -3
  160. package/dist/postgres-connection.d.mts +8 -2
  161. package/dist/postgres-connection.mjs +2 -1
  162. package/dist/postgres-store.mjs +1 -0
  163. package/dist/react/Canvas.mjs +28 -5
  164. package/dist/react/Cell.mjs +2 -1
  165. package/dist/react/Dashboard.d.mts +10 -5
  166. package/dist/react/Dashboard.mjs +62 -22
  167. package/dist/react/DashboardList.mjs +52 -24
  168. package/dist/react/DashboardListRow.mjs +49 -0
  169. package/dist/react/Discard.mjs +12 -4
  170. package/dist/react/Editing.mjs +19 -5
  171. package/dist/react/FilterBar.d.mts +7 -9
  172. package/dist/react/Grid.mjs +19 -24
  173. package/dist/react/Header.mjs +10 -1
  174. package/dist/react/History.mjs +5 -0
  175. package/dist/react/Parts.mjs +6 -2
  176. package/dist/react/ReadFailed.mjs +23 -0
  177. package/dist/react/ReviewPanel.mjs +13 -2
  178. package/dist/react/RowBody.d.mts +19 -0
  179. package/dist/react/RowBody.mjs +55 -0
  180. package/dist/react/Spaces.mjs +15 -1
  181. package/dist/react/Tile.d.mts +3 -1
  182. package/dist/react/Tile.mjs +84 -32
  183. package/dist/react/_virtual/_rolldown/runtime.mjs +12 -0
  184. package/dist/react/arrange-steps.mjs +16 -13
  185. package/dist/react/arrange.mjs +10 -3
  186. package/dist/react/builder/Calcs.mjs +35 -11
  187. package/dist/react/builder/FilterEditor.mjs +196 -0
  188. package/dist/react/builder/Filters.mjs +172 -116
  189. package/dist/react/builder/Formula.mjs +82 -0
  190. package/dist/react/builder/Groups.mjs +1 -0
  191. package/dist/react/builder/Preview.mjs +1 -1
  192. package/dist/react/builder/RangeEditor.mjs +184 -0
  193. package/dist/react/builder/Sections.mjs +41 -6
  194. package/dist/react/builder/Time.mjs +138 -60
  195. package/dist/react/builder/Values.mjs +85 -0
  196. package/dist/react/builder/WidgetBuilder.mjs +50 -49
  197. package/dist/react/builder/base.d.mts +5 -0
  198. package/dist/react/builder/base.mjs +33 -8
  199. package/dist/react/builder/calc.mjs +15 -1
  200. package/dist/react/builder/escape.d.mts +1 -0
  201. package/dist/react/builder/escape.mjs +62 -0
  202. package/dist/react/builder/filter-tree.d.mts +9 -0
  203. package/dist/react/builder/filter-tree.mjs +186 -0
  204. package/dist/react/builder/formula-parse.d.mts +18 -0
  205. package/dist/react/builder/formula-parse.mjs +136 -0
  206. package/dist/react/builder/labels.d.mts +1 -1
  207. package/dist/react/builder/state.d.mts +2 -1
  208. package/dist/react/builder/state.mjs +23 -37
  209. package/dist/react/builder/useBuilder.d.mts +12 -1
  210. package/dist/react/builder/useBuilder.mjs +6 -3
  211. package/dist/react/builder/words.d.mts +59 -0
  212. package/dist/react/builder/words.mjs +73 -0
  213. package/dist/react/client.d.mts +2 -0
  214. package/dist/react/client.mjs +1 -0
  215. package/dist/react/context.d.mts +28 -1
  216. package/dist/react/context.mjs +25 -4
  217. package/dist/react/drill/Bars.mjs +179 -0
  218. package/dist/react/drill/Controls.mjs +173 -0
  219. package/dist/react/drill/DashboardTile.d.mts +18 -0
  220. package/dist/react/drill/DashboardTile.mjs +107 -0
  221. package/dist/react/drill/DrillPanel.d.mts +31 -0
  222. package/dist/react/drill/DrillPanel.mjs +104 -0
  223. package/dist/react/drill/DrillTabs.mjs +52 -0
  224. package/dist/react/drill/Header.mjs +131 -0
  225. package/dist/react/drill/Items.d.mts +22 -0
  226. package/dist/react/drill/Items.mjs +164 -0
  227. package/dist/react/drill/ItemsFoot.mjs +60 -0
  228. package/dist/react/drill/Notes.mjs +58 -0
  229. package/dist/react/drill/PanelBody.mjs +74 -0
  230. package/dist/react/drill/PanelStates.mjs +37 -0
  231. package/dist/react/drill/board.d.mts +18 -0
  232. package/dist/react/drill/board.mjs +91 -0
  233. package/dist/react/drill/counts.mjs +14 -0
  234. package/dist/react/drill/host.mjs +26 -0
  235. package/dist/react/drill/item-parts.d.mts +5 -0
  236. package/dist/react/drill/item-parts.mjs +76 -0
  237. package/dist/react/drill/item-type.d.mts +26 -0
  238. package/dist/react/drill/item-type.mjs +7 -0
  239. package/dist/react/drill/lazy.d.mts +6 -0
  240. package/dist/react/drill/lazy.mjs +17 -0
  241. package/dist/react/drill/pages.mjs +48 -0
  242. package/dist/react/drill/panel-focus.mjs +51 -0
  243. package/dist/react/drill/props.d.mts +25 -0
  244. package/dist/react/drill/props.mjs +72 -0
  245. package/dist/react/drill/state.d.mts +18 -0
  246. package/dist/react/drill/state.mjs +68 -0
  247. package/dist/react/drill/useDrill.d.mts +46 -0
  248. package/dist/react/drill/useDrill.mjs +194 -0
  249. package/dist/react/drill/words.d.mts +101 -0
  250. package/dist/react/drill/words.mjs +79 -0
  251. package/dist/react/english.mjs +29 -6
  252. package/dist/react/filters/bar.d.mts +12 -0
  253. package/dist/react/filters/bar.mjs +135 -0
  254. package/dist/react/filters/calendar.mjs +193 -0
  255. package/dist/react/filters/chip.mjs +174 -0
  256. package/dist/react/filters/context.d.mts +22 -0
  257. package/dist/react/filters/context.mjs +78 -0
  258. package/dist/react/filters/dates.mjs +89 -0
  259. package/dist/react/filters/days.d.mts +36 -0
  260. package/dist/react/filters/days.mjs +87 -0
  261. package/dist/react/filters/field-step.mjs +81 -0
  262. package/dist/react/filters/hooks.d.mts +34 -0
  263. package/dist/react/filters/hooks.mjs +94 -0
  264. package/dist/react/filters/listbox.mjs +131 -0
  265. package/dist/react/filters/logic.d.mts +59 -0
  266. package/dist/react/filters/logic.mjs +109 -0
  267. package/dist/react/filters/menu-search.mjs +211 -0
  268. package/dist/react/filters/menu.mjs +85 -0
  269. package/dist/react/filters/number.mjs +127 -0
  270. package/dist/react/filters/numbers.d.mts +47 -0
  271. package/dist/react/filters/numbers.mjs +151 -0
  272. package/dist/react/filters/operator.mjs +104 -0
  273. package/dist/react/filters/phone.mjs +104 -0
  274. package/dist/react/filters/popover.d.mts +19 -0
  275. package/dist/react/filters/popover.mjs +153 -0
  276. package/dist/react/filters/rules.d.mts +8 -0
  277. package/dist/react/filters/rules.mjs +55 -0
  278. package/dist/react/filters/sheet.mjs +196 -0
  279. package/dist/react/filters/state.mjs +132 -0
  280. package/dist/react/filters/suggest.d.mts +47 -0
  281. package/dist/react/filters/suggest.mjs +97 -0
  282. package/dist/react/filters/values.mjs +166 -0
  283. package/dist/react/filters/words.d.mts +81 -0
  284. package/dist/react/filters/words.mjs +73 -0
  285. package/dist/react/format.d.mts +3 -3
  286. package/dist/react/format.mjs +45 -16
  287. package/dist/react/index.d.mts +34 -5
  288. package/dist/react/index.mjs +15 -4
  289. package/dist/react/messages.d.mts +47 -2
  290. package/dist/react/place.mjs +7 -3
  291. package/dist/react/renderers/index.d.mts +10 -2
  292. package/dist/react/renderers/index.mjs +116 -14
  293. package/dist/react/renderers/list.d.mts +22 -0
  294. package/dist/react/renderers/list.mjs +118 -0
  295. package/dist/react/review-words.mjs +1 -1
  296. package/dist/react/review.mjs +2 -2
  297. package/dist/react/scope.mjs +2 -7
  298. package/dist/react/series.d.mts +54 -0
  299. package/dist/react/series.mjs +191 -0
  300. package/dist/react/theme.css +2734 -1296
  301. package/dist/react/theme.css.d.ts +1 -0
  302. package/dist/react/tile-store.mjs +15 -3
  303. package/dist/react/useBoard.d.mts +7 -0
  304. package/dist/react/useBoard.mjs +4 -1
  305. package/dist/react/useDashboard.d.mts +4 -0
  306. package/dist/react/useDashboard.mjs +8 -1
  307. package/dist/react/useTiles.mjs +50 -15
  308. package/dist/react/view-grid.mjs +16 -0
  309. package/dist/react/view.d.mts +9 -0
  310. package/dist/react/view.mjs +22 -10
  311. package/dist/reading.d.mts +2 -0
  312. package/dist/reading.mjs +9 -1
  313. package/dist/recharts/axes.mjs +28 -0
  314. package/dist/recharts/axis.mjs +84 -0
  315. package/dist/recharts/bar.d.mts +7 -0
  316. package/dist/recharts/bar.mjs +140 -0
  317. package/dist/recharts/charts.d.mts +4 -6
  318. package/dist/recharts/charts.mjs +2 -114
  319. package/dist/recharts/index.d.mts +5 -3
  320. package/dist/recharts/index.mjs +6 -3
  321. package/dist/recharts/line.d.mts +2 -0
  322. package/dist/recharts/line.mjs +111 -0
  323. package/dist/recharts/marks.mjs +112 -0
  324. package/dist/recharts/parts.mjs +88 -0
  325. package/dist/recharts/series.d.mts +2 -22
  326. package/dist/recharts/series.mjs +1 -64
  327. package/dist/recharts/table.mjs +71 -0
  328. package/dist/records-read.mjs +44 -0
  329. package/dist/registry/filter-bar.json +26 -0
  330. package/dist/skills/derive-dashboards/SKILL.md +69 -0
  331. package/dist/store/apply.mjs +5 -5
  332. package/dist/store/commands.mjs +4 -4
  333. package/dist/store/discard.mjs +7 -7
  334. package/dist/store/drafts.mjs +5 -5
  335. package/dist/store/editor.mjs +1 -1
  336. package/dist/store/publish.mjs +12 -12
  337. package/dist/store/reader.mjs +41 -22
  338. package/dist/store/review.mjs +16 -16
  339. package/dist/store/rows.mjs +20 -20
  340. package/dist/store/undo.mjs +3 -3
  341. package/dist/store/unpublished.mjs +4 -4
  342. package/dist/store/versions.mjs +14 -14
  343. package/dist/testing/adapter-suite.mjs +4 -4
  344. package/dist/tiles.mjs +37 -3
  345. package/package.json +12 -10
  346. package/dist/react/FilterBar.mjs +0 -119
  347. package/dist/react/Records.d.mts +0 -12
  348. package/dist/react/Records.mjs +0 -97
  349. package/src/adapter/sql-adapter.ts +0 -95
  350. package/src/adapter/statement.ts +0 -185
  351. package/src/authorize.ts +0 -73
  352. package/src/body.ts +0 -169
  353. package/src/bounded.ts +0 -43
  354. package/src/cache.ts +0 -192
  355. package/src/checks.ts +0 -170
  356. package/src/custom-source.ts +0 -59
  357. package/src/dashboard-id.ts +0 -36
  358. package/src/dashboards.ts +0 -132
  359. package/src/editing.ts +0 -148
  360. package/src/endpoints/access.ts +0 -41
  361. package/src/endpoints/dashboards.ts +0 -92
  362. package/src/endpoints/drafts.ts +0 -138
  363. package/src/endpoints/index.ts +0 -21
  364. package/src/endpoints/meta.ts +0 -137
  365. package/src/endpoints/query.ts +0 -86
  366. package/src/endpoints/read.ts +0 -92
  367. package/src/endpoints/review.ts +0 -89
  368. package/src/endpoints/values.ts +0 -62
  369. package/src/endpoints/versions.ts +0 -104
  370. package/src/execute.ts +0 -207
  371. package/src/handler.ts +0 -232
  372. package/src/http.ts +0 -66
  373. package/src/index.ts +0 -163
  374. package/src/introspect.ts +0 -205
  375. package/src/mcp/api.ts +0 -59
  376. package/src/mcp/format.ts +0 -67
  377. package/src/mcp/index.ts +0 -151
  378. package/src/mcp/query.ts +0 -153
  379. package/src/mcp/resolve.ts +0 -114
  380. package/src/node-postgres.ts +0 -81
  381. package/src/owner.ts +0 -36
  382. package/src/postgres-connection.ts +0 -143
  383. package/src/postgres-store.ts +0 -82
  384. package/src/principal.ts +0 -39
  385. package/src/reading.ts +0 -56
  386. package/src/request-rows.ts +0 -23
  387. package/src/request.ts +0 -22
  388. package/src/storage.ts +0 -63
  389. package/src/store/apply.ts +0 -129
  390. package/src/store/commands.ts +0 -75
  391. package/src/store/conflicts.ts +0 -98
  392. package/src/store/create-tables.ts +0 -104
  393. package/src/store/discard.ts +0 -42
  394. package/src/store/drafts.ts +0 -133
  395. package/src/store/editor.ts +0 -28
  396. package/src/store/log.ts +0 -28
  397. package/src/store/publish.ts +0 -199
  398. package/src/store/publisher.ts +0 -21
  399. package/src/store/reader.ts +0 -139
  400. package/src/store/review.ts +0 -239
  401. package/src/store/rows.ts +0 -250
  402. package/src/store/tenant.ts +0 -28
  403. package/src/store/undo.ts +0 -56
  404. package/src/store/unpublished.ts +0 -33
  405. package/src/store/versions.ts +0 -106
  406. package/src/store/writer.ts +0 -19
  407. package/src/testing/adapter-suite.ts +0 -239
  408. package/src/testing/index.ts +0 -2
  409. package/src/tile-doc.ts +0 -46
  410. package/src/tiles.ts +0 -120
@@ -1,6 +1,7 @@
1
1
  import { Op, ViewerRef, WireFilter } from "../query/filter.mjs";
2
2
  import { Column, ConnectionId, DimensionName, IanaZone, JoinName, MeasureName, PolicyName, Primitive, SourceName, TenantKey } from "../types/primitives.mjs";
3
3
  import { Channel } from "../types/viewer.mjs";
4
+ import { DimensionHints, Noun, RecordsHint } from "./hints.mjs";
4
5
  /**
5
6
  * The semantic model: plain data, owned by the host as code. Tenancy and row access are part
6
7
  * of it, and both are opt-in: with tenant keys, no source can be queried outside its tenant.
@@ -125,11 +126,8 @@ export type SourceDef = SourceRelation & {
125
126
  acknowledgeOpenPolicy?: true;
126
127
  /** Always applied, for example `removed_at` is not set. Shown in the receipt. */
127
128
  where?: WireFilter;
128
- records?: {
129
- order: readonly (readonly [DimensionName, "asc" | "desc"])[];
130
- columns: readonly DimensionName[];
131
- link?: string;
132
- };
129
+ records?: RecordsHint;
130
+ noun?: Noun;
133
131
  joins?: Record<JoinName, JoinDef>;
134
132
  measures: Record<MeasureName, MeasureDef>;
135
133
  dimensions: Record<DimensionName, DimensionDef>;
@@ -137,6 +135,10 @@ export type SourceDef = SourceRelation & {
137
135
  limits?: {
138
136
  maxWindowDays?: number;
139
137
  };
138
+ /** Drill-in: Breakdown's field order (`prefer`), or `false` never to drill into this source. */
139
+ drill?: false | {
140
+ prefer: readonly string[];
141
+ };
140
142
  };
141
143
  export type MemberMeta = {
142
144
  label?: string;
@@ -155,6 +157,15 @@ export type Numeric = "float" | {
155
157
  scale: number;
156
158
  stored: "decimal" | "minor_units";
157
159
  };
160
+ /** What every measure over a column may add: rows it reads, a duration format, a partition. */
161
+ type OverColumn = {
162
+ of: Column | Expr;
163
+ where?: WireFilter;
164
+ /** `duration`: the values are seconds, shown as "3.7 days", "2 h". */
165
+ format?: "duration";
166
+ /** Reserved for snapshot measures (the last value per partition). Refused by the model check until computed. */
167
+ partitionBy?: DimensionName;
168
+ };
158
169
  /** One aggregate per measure, so each has one result type and one merge rule. */
159
170
  export type MeasureDef = MemberMeta & {
160
171
  /** How partial results combine. `none` means they cannot be combined. */
@@ -163,26 +174,17 @@ export type MeasureDef = MemberMeta & {
163
174
  kind: "count";
164
175
  distinct?: Column;
165
176
  where?: WireFilter;
166
- } | {
177
+ } | ({
167
178
  kind: "sum" | "min" | "max";
168
- of: Column | Expr;
169
179
  numeric: Numeric;
170
- where?: WireFilter;
171
180
  unit?: Unit;
172
- partitionBy?: DimensionName;
173
- } | {
181
+ } & OverColumn) | ({
174
182
  kind: "avg";
175
- of: Column | Expr;
176
183
  numeric: Numeric;
177
- where?: WireFilter;
178
- partitionBy?: DimensionName;
179
- } | {
184
+ } & OverColumn) | ({
180
185
  kind: "percentile";
181
- of: Column | Expr;
182
186
  p: 50 | 75 | 90 | 95 | 99;
183
- where?: WireFilter;
184
- partitionBy?: DimensionName;
185
- } | {
187
+ } & OverColumn) | {
186
188
  kind: "ratio";
187
189
  numerator: MeasureName;
188
190
  denominator: MeasureName;
@@ -201,7 +203,7 @@ export type TimeStorage = "timestamptz" | "date" | "epoch_ms" | "epoch_s" | {
201
203
  fractionDigits: number;
202
204
  };
203
205
  } | "text_parseable";
204
- export type DimensionDef = MemberMeta & ({
206
+ export type DimensionDef = MemberMeta & DimensionHints & ({
205
207
  kind: "string";
206
208
  column: Column;
207
209
  values?: readonly string[] | "lookup";
@@ -0,0 +1,70 @@
1
+ import { parseMemberId } from "../member.mjs";
2
+ import { when } from "./issues.mjs";
3
+ // src/model/validate/drill.ts
4
+ /** Whether a `drill.prefer` entry names a dimension, `join.dimension`, or a join. */
5
+ function names(source, entry) {
6
+ const ref = parseMemberId(`source.${entry}`);
7
+ if (ref === void 0) return false;
8
+ if (ref.join !== void 0) return source.joins?.[ref.join] !== void 0;
9
+ return source.dimensions[ref.name] !== void 0 || source.joins?.[ref.name] !== void 0;
10
+ }
11
+ /** A dimension's hints fit it: a format on a number, tones for values it declares. */
12
+ function dimensionHintIssues(def, path) {
13
+ const declared = def.kind === "string" && Array.isArray(def.values) ? def.values : [];
14
+ const tones = Object.keys(def.tones ?? {});
15
+ return [
16
+ ...when(def.buckets !== void 0 && (def.kind !== "number" || def.buckets.length === 0 || def.buckets.some((e, i) => i > 0 && e <= (def.buckets?.[i - 1] ?? e))), "HINT_INVALID", [...path, "buckets"], "Bucket edges sit on a number dimension and go up, one after another."),
17
+ ...when(def.format !== void 0 && def.kind !== "number", "HINT_INVALID", [...path, "format"], "A number format sits on a number dimension."),
18
+ ...tones.flatMap((value) => when(!declared.includes(value), "HINT_INVALID", [
19
+ ...path,
20
+ "tones",
21
+ value
22
+ ], `"${value}" is not one of the dimension's declared values.`))
23
+ ];
24
+ }
25
+ /** The keys a `records` hint may have; `link` was removed (routes live in `itemLinks`). */
26
+ const RECORDS_KEYS = Object.freeze({
27
+ order: true,
28
+ columns: true,
29
+ title: true,
30
+ key: true
31
+ });
32
+ /** A `records` hint has only its own keys, a `key` of "expose" or "hide", and a title a list may show. */
33
+ function recordsIssues(source, path) {
34
+ const records = source.records;
35
+ if (records === void 0) return [];
36
+ const at = [...path, "records"];
37
+ const title = source.records?.title;
38
+ const titled = title === void 0 ? void 0 : source.dimensions[title];
39
+ const key = source.records?.key;
40
+ return [
41
+ ...Object.keys(records).flatMap((k) => when(!Object.hasOwn(RECORDS_KEYS, k), "MODEL_SHAPE", [...at, k], k === "link" ? "records.link was removed: pass itemLinks to deriveDashboards and the React UI instead." : `records has no "${k}": it takes order, columns, title and key.`)),
42
+ ...when(key !== void 0 && key !== "expose" && key !== "hide", "HINT_INVALID", [...at, "key"], `records.key is "expose" or "hide", not ${JSON.stringify(key)}.`),
43
+ ...when(titled !== void 0 && (titled.sensitive === true || titled.hidden === true), "HINT_INVALID", [...at, "title"], "A records title is never a sensitive or hidden field: it shows on every item.")
44
+ ];
45
+ }
46
+ /** Each drill and records hint resolves: preferred fields, the records title, tones and formats. */
47
+ function drillIssues(source, path) {
48
+ const prefer = source.drill === false ? [] : source.drill?.prefer ?? [];
49
+ const title = source.records?.title;
50
+ return [
51
+ ...recordsIssues(source, path),
52
+ ...prefer.flatMap((entry, i) => when(!names(source, entry), "DRILL_PREFER_UNKNOWN", [
53
+ ...path,
54
+ "drill",
55
+ "prefer",
56
+ i
57
+ ], `"${entry}" is not a dimension, a join or a join's dimension of this source.`)),
58
+ ...when(title !== void 0 && source.dimensions[title] === void 0, "HINT_INVALID", [
59
+ ...path,
60
+ "records",
61
+ "title"
62
+ ], `There is no dimension named "${title ?? ""}".`),
63
+ ...Object.entries(source.dimensions).flatMap(([name, def]) => dimensionHintIssues(def, [
64
+ ...path,
65
+ "dimensions",
66
+ name
67
+ ]))
68
+ ];
69
+ }
70
+ export { drillIssues };
@@ -1,5 +1,6 @@
1
1
  import { nameIssues, when } from "./issues.mjs";
2
2
  import { rowPolicyIssues } from "./policy.mjs";
3
+ import { shapeIssues } from "./shape.mjs";
3
4
  import { sourceIssues } from "./source.mjs";
4
5
  import { viaCycleIssues } from "./via.mjs";
5
6
  // src/model/validate/index.ts
@@ -11,6 +12,8 @@ import { viaCycleIssues } from "./via.mjs";
11
12
  * job of the `check` command.
12
13
  */
13
14
  function validateModel(model) {
15
+ const shaped = shapeIssues(model);
16
+ if (shaped.length > 0) return [...headerIssues(model), ...shaped];
14
17
  const sources = Object.entries(model.sources ?? {});
15
18
  return [
16
19
  ...headerIssues(model),
@@ -64,10 +64,13 @@ function numericIssues(numeric, path) {
64
64
  const ok = Number.isInteger(numeric.scale) && numeric.scale >= 0 && numeric.scale <= 38;
65
65
  return when(!ok, "NUMERIC_SCALE", [...path, "scale"], "The scale must be a whole number, 0 to 38.");
66
66
  }
67
- function partitionIssues(source, measure, path) {
68
- const partition = measure.partitionBy;
69
- const unknown = partition !== void 0 && source.dimensions[partition] === void 0;
70
- return when(unknown, "PARTITION_UNKNOWN", path, `There is no dimension named "${partition}".`);
67
+ /**
68
+ * A snapshot measure (`partitionBy`) is refused until the engines compute its meaning, the last
69
+ * value per partition in a bucket: accepting it now would answer an ordinary aggregate where the
70
+ * model's author asked for a snapshot.
71
+ */
72
+ function partitionIssues(_source, measure, path) {
73
+ return when(measure.partitionBy !== void 0, "PARTITION_UNSUPPORTED", path, "Snapshot measures (partitionBy) are not computed yet: remove it, or model the snapshot as a source of last rows.");
71
74
  }
72
75
  function percentileIssues(measure, path) {
73
76
  const bad = measure.kind === "percentile" && measure.merge !== "none";
@@ -0,0 +1,150 @@
1
+ import { issue } from "./issues.mjs";
2
+ // src/model/validate/shape.ts
3
+ const MEASURE_KINDS = [
4
+ "count",
5
+ "sum",
6
+ "min",
7
+ "max",
8
+ "avg",
9
+ "percentile",
10
+ "ratio"
11
+ ];
12
+ const MERGES = [
13
+ "sum",
14
+ "min",
15
+ "max",
16
+ "none"
17
+ ];
18
+ const PERCENTILES = [
19
+ 50,
20
+ 75,
21
+ 90,
22
+ 95,
23
+ 99
24
+ ];
25
+ const DIMENSION_KINDS = [
26
+ "string",
27
+ "number",
28
+ "boolean",
29
+ "time",
30
+ "ref",
31
+ "bucket",
32
+ "expr"
33
+ ];
34
+ const STORAGES = [
35
+ "timestamptz",
36
+ "date",
37
+ "epoch_ms",
38
+ "epoch_s",
39
+ "text_parseable"
40
+ ];
41
+ const isObject = (v) => typeof v === "object" && v !== null;
42
+ const known = (list, value) => list.includes(value);
43
+ const shape = (path, message) => issue("MODEL_SHAPE", path, message);
44
+ const oneOf = (list) => list.map((v) => JSON.stringify(v)).join(", ");
45
+ /** Fields a kind needs, each named when missing. */
46
+ function needs(m, fields, path) {
47
+ return fields.flatMap((f) => m[f] === void 0 ? [shape([...path, f], `A ${String(m["kind"])} needs "${f}".`)] : []);
48
+ }
49
+ function measureShape(m, path) {
50
+ if (!isObject(m)) return [shape(path, "A measure is an object.")];
51
+ if (!known(MEASURE_KINDS, m["kind"])) return [shape([...path, "kind"], `"${String(m["kind"])}" is not a measure kind: ${oneOf(MEASURE_KINDS)}.`)];
52
+ if (m["kind"] === "ratio") return needs(m, ["numerator", "denominator"], path);
53
+ const merge = known(MERGES, m["merge"]) ? [] : [shape([...path, "merge"], `"${String(m["merge"])}" is not a merge: ${oneOf(MERGES)}.`)];
54
+ if (m["kind"] === "count") return merge;
55
+ const fields = m["kind"] === "percentile" ? ["of", "p"] : ["of", "numeric"];
56
+ const p = m["kind"] === "percentile" && m["p"] !== void 0 && !known(PERCENTILES, m["p"]) ? [shape([...path, "p"], `A percentile is one of ${oneOf(PERCENTILES)}.`)] : [];
57
+ return [
58
+ ...merge,
59
+ ...needs(m, fields, path),
60
+ ...p
61
+ ];
62
+ }
63
+ function storageShape(storage, path) {
64
+ if (typeof storage === "string" && known(STORAGES, storage)) return [];
65
+ if (isObject(storage) && ("timestamp" in storage || "iso_utc_fixed" in storage)) return [];
66
+ return [shape(path, `${JSON.stringify(storage)} is not a time storage: ${oneOf(STORAGES)}, { timestamp: { zone, ... } } or { iso_utc_fixed: { ... } }.`)];
67
+ }
68
+ const DIMENSION_NEEDS = {
69
+ string: ["column"],
70
+ number: ["column"],
71
+ boolean: ["column"],
72
+ time: ["column", "storage"],
73
+ ref: ["join", "label"],
74
+ bucket: [
75
+ "of",
76
+ "edges",
77
+ "labels"
78
+ ],
79
+ expr: ["expr", "type"]
80
+ };
81
+ function dimensionShape(d, path) {
82
+ if (!isObject(d)) return [shape(path, "A dimension is an object.")];
83
+ const kind = d["kind"];
84
+ if (typeof kind !== "string" || !known(DIMENSION_KINDS, kind)) return [shape([...path, "kind"], `"${String(kind)}" is not a dimension kind: ${oneOf(DIMENSION_KINDS)}.`)];
85
+ const missing = needs(d, DIMENSION_NEEDS[kind] ?? [], path);
86
+ if (missing.length > 0) return missing;
87
+ if (kind === "time") return storageShape(d["storage"], [...path, "storage"]);
88
+ return [];
89
+ }
90
+ /** Every member of every source whose shape is wrong, before any check reads it. */
91
+ function shapeIssues(model) {
92
+ const sources = model.sources;
93
+ if (!isObject(sources)) return [shape(["sources"], "A model's sources are an object, by name.")];
94
+ return Object.entries(sources).flatMap(([name, source]) => {
95
+ const path = ["sources", name];
96
+ if (!isObject(source)) return [shape(path, "A source is an object.")];
97
+ const measures = isObject(source["measures"]) ? source["measures"] : {};
98
+ const dimensions = isObject(source["dimensions"]) ? source["dimensions"] : {};
99
+ return [
100
+ ...needs({
101
+ kind: "source",
102
+ ...source
103
+ }, [
104
+ "in",
105
+ "key",
106
+ "measures",
107
+ "dimensions"
108
+ ], path),
109
+ ...Object.entries(measures).flatMap(([m, def]) => measureShape(def, [
110
+ ...path,
111
+ "measures",
112
+ m
113
+ ])),
114
+ ...Object.entries(dimensions).flatMap(([d, def]) => dimensionShape(def, [
115
+ ...path,
116
+ "dimensions",
117
+ d
118
+ ])),
119
+ ...hintShape(source, path)
120
+ ];
121
+ });
122
+ }
123
+ /** Each entry of `records.order` is a field and a direction: `["createdAt", "desc"]`. */
124
+ function orderShape(order, path) {
125
+ if (!Array.isArray(order)) return [];
126
+ return order.flatMap((entry, i) => Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string" && (entry[1] === "asc" || entry[1] === "desc") ? [] : [shape([...path, i], "Each order entry is a field and a direction: [\"createdAt\", \"desc\"].")]);
127
+ }
128
+ /** A source's `records` (its lists) and `noun` (its two words), shaped so later checks can read them. */
129
+ function hintShape(source, path) {
130
+ const records = source["records"];
131
+ const noun = source["noun"];
132
+ const list = (key) => isObject(records) && records[key] !== void 0 && !Array.isArray(records[key]) ? [shape([
133
+ ...path,
134
+ "records",
135
+ key
136
+ ], `records.${key} is a list.`)] : [];
137
+ const words = isObject(noun) && typeof noun["one"] === "string" && typeof noun["other"] === "string";
138
+ return [
139
+ ...records === void 0 || isObject(records) ? [] : [shape([...path, "records"], "records is an object: { title, columns, order, key }.")],
140
+ ...list("columns"),
141
+ ...list("order"),
142
+ ...orderShape(isObject(records) ? records["order"] : void 0, [
143
+ ...path,
144
+ "records",
145
+ "order"
146
+ ]),
147
+ ...noun === void 0 || words ? [] : [shape([...path, "noun"], "noun is { one: \"order\", other: \"orders\" }.")]
148
+ ];
149
+ }
150
+ export { shapeIssues };
@@ -1,4 +1,5 @@
1
1
  import { tenantKeys } from "../defaults.mjs";
2
+ import { drillIssues } from "./drill.mjs";
2
3
  import { modelFilterIssues } from "./filter.mjs";
3
4
  import { issue, nameIssues, when } from "./issues.mjs";
4
5
  import { dimensionIssues, measureIssues } from "./members.mjs";
@@ -18,7 +19,8 @@ function sourceIssues(model, name, source) {
18
19
  ...filterIssues(model, name, source, path),
19
20
  ...memberIssues(model, name, source, path),
20
21
  ...timeIssues(source, [...path, "time"]),
21
- ...recordIssues(source, [...path, "records"])
22
+ ...recordIssues(source, [...path, "records"]),
23
+ ...drillIssues(source, path)
22
24
  ];
23
25
  }
24
26
  /** One SELECT, optionally behind WITH; a trailing semicolon is allowed, none inside. */
@@ -122,7 +124,7 @@ function recordIssues(source, path) {
122
124
  const def = source.dimensions?.[column];
123
125
  return when(def?.sensitive === true || def?.hidden === true, "RECORD_COLUMN_SENSITIVE", at, `"${column}" is ${def?.sensitive === true ? "sensitive" : "hidden"}, so the records cannot show or be ordered by it: they are shown to everyone who sees the tile.`);
124
126
  };
125
- return [...records.columns.flatMap((column, i) => [...unknown(column, [
127
+ return [...(records.columns ?? []).flatMap((column, i) => [...unknown(column, [
126
128
  ...path,
127
129
  "columns",
128
130
  i
@@ -130,7 +132,7 @@ function recordIssues(source, path) {
130
132
  ...path,
131
133
  "columns",
132
134
  i
133
- ])]), ...records.order.flatMap(([column], i) => [...unknown(column, [
135
+ ])]), ...(records.order ?? []).flatMap(([column], i) => [...unknown(column, [
134
136
  ...path,
135
137
  "order",
136
138
  i
@@ -0,0 +1,12 @@
1
+ import { WireFilter } from "../query/filter.mjs";
2
+ import { WireQuery } from "../query/types.mjs";
3
+ import { Principal } from "../types/viewer.mjs";
4
+ /**
5
+ * The filter with every viewer reference (`{ viewer: "id" }`) replaced by the signed-in viewer's
6
+ * values, as a row policy binds them. When a value is missing (a public link, a viewer without
7
+ * that attribute), the whole filter matches no rows: a missing value never makes a negated leaf
8
+ * true. Variables are left as they are.
9
+ */
10
+ export declare function bindViewer(filter: WireFilter, principal: Principal): WireFilter;
11
+ /** The query with the viewer bound in its filters and in each measure's own filter. */
12
+ export declare function bindQueryViewer(query: WireQuery, principal: Principal): WireQuery;
@@ -0,0 +1,53 @@
1
+ import { viewerValues } from "./bind.mjs";
2
+ // src/policy/bind-query.ts
3
+ /** No rows: what a filter is when a viewer value it needs is missing. */
4
+ const NOTHING = { any: [] };
5
+ var Missing = class extends Error {};
6
+ function walk(filter, viewer) {
7
+ if ("all" in filter) return { all: filter.all.map((f) => walk(f, viewer)) };
8
+ if ("any" in filter) return { any: filter.any.map((f) => walk(f, viewer)) };
9
+ if ("not" in filter) return { not: walk(filter.not, viewer) };
10
+ if ("some" in filter) return { some: {
11
+ ...filter.some,
12
+ where: walk(filter.some.where, viewer)
13
+ } };
14
+ if ("none" in filter) return { none: {
15
+ ...filter.none,
16
+ where: walk(filter.none.where, viewer)
17
+ } };
18
+ if (!("viewer" in filter)) return filter;
19
+ const values = viewer === void 0 ? [] : viewerValues(viewer, filter.viewer);
20
+ if (values.length === 0) throw new Missing();
21
+ return {
22
+ member: filter.member,
23
+ op: filter.op,
24
+ values
25
+ };
26
+ }
27
+ /**
28
+ * The filter with every viewer reference (`{ viewer: "id" }`) replaced by the signed-in viewer's
29
+ * values, as a row policy binds them. When a value is missing (a public link, a viewer without
30
+ * that attribute), the whole filter matches no rows: a missing value never makes a negated leaf
31
+ * true. Variables are left as they are.
32
+ */
33
+ function bindViewer(filter, principal) {
34
+ const viewer = principal.channel === "user" ? principal.viewer : void 0;
35
+ try {
36
+ return walk(filter, viewer);
37
+ } catch (error) {
38
+ if (error instanceof Missing) return NOTHING;
39
+ throw error;
40
+ }
41
+ }
42
+ /** The query with the viewer bound in its filters and in each measure's own filter. */
43
+ function bindQueryViewer(query, principal) {
44
+ return {
45
+ ...query,
46
+ ...query.filters === void 0 ? {} : { filters: bindViewer(query.filters, principal) },
47
+ measures: query.measures.map((m) => m.filter === void 0 ? m : {
48
+ ...m,
49
+ filter: bindViewer(m.filter, principal)
50
+ })
51
+ };
52
+ }
53
+ export { bindQueryViewer, bindViewer };
@@ -11,4 +11,10 @@ function aliasPart(alias) {
11
11
  index
12
12
  };
13
13
  }
14
- export { aliasPart };
14
+ /** A line's alias (`m1`, `c2`) read from text, as a drill names the line clicked; undefined for anything else. */
15
+ function lineAlias(text) {
16
+ if (!/^[mc][1-9]\d*$/u.test(text)) return void 0;
17
+ const n = Number(text.slice(1));
18
+ return text.startsWith("m") ? `m${n}` : `c${n}`;
19
+ }
20
+ export { aliasPart, lineAlias };
@@ -0,0 +1,22 @@
1
+ import { Model } from "../../model/types.mjs";
2
+ import { WireQuery } from "../types.mjs";
3
+ import { Readable } from "./fields.mjs";
4
+ import { DrillClock } from "./time.mjs";
5
+ import { Drill } from "./types.mjs";
6
+ export type DrillInput = {
7
+ model: Model;
8
+ /** The tile's query as composed: its filters, picks and range already in it. */
9
+ query: WireQuery;
10
+ drill: Drill;
11
+ readable: Readable;
12
+ clock: DrillClock;
13
+ };
14
+ /**
15
+ * The rows behind a drill, as a query with no grouping: the tile's own query (its filters,
16
+ * picks, range and measures) with each step's values ANDed on as filters and its time windows
17
+ * narrowing the range. The lock, required filters, tenancy and row rules travel apart, as for
18
+ * the tile. A calc that reads around its row (a total, a bucket, the period before) is left
19
+ * out: on rows with no grouping it would read the wrong scope. The server evaluates it from
20
+ * each scope's own read (`drillScopes`).
21
+ */
22
+ export declare function composeDrill(input: DrillInput): WireQuery;
@@ -0,0 +1,85 @@
1
+ import { EngineError } from "../../error/refusal.mjs";
2
+ import { drillableMembers } from "./fields.mjs";
3
+ import { aroundCalcs } from "./scopes.mjs";
4
+ import { stepMembers } from "./steps.mjs";
5
+ import { drilledTime } from "./time.mjs";
6
+ import "./types.mjs";
7
+ // src/query/drill/compose.ts
8
+ const refuse = (message) => {
9
+ throw new EngineError("SELECTION_INVALID", message);
10
+ };
11
+ /** One field at one value; no value is the rows where it is not set. */
12
+ function equalsLeaf(member, value) {
13
+ return value === null ? {
14
+ member,
15
+ op: "notSet",
16
+ values: []
17
+ } : {
18
+ member,
19
+ op: "equals",
20
+ values: [value]
21
+ };
22
+ }
23
+ /** The rows in none of the kept groups. */
24
+ function otherFilter(other) {
25
+ return { not: { any: other.kept.map((tuple) => {
26
+ if (tuple.length !== other.members.length) refuse("A kept group has one value per field.");
27
+ return { all: other.members.map((member, i) => equalsLeaf(member, tuple[i] ?? null)) };
28
+ }) } };
29
+ }
30
+ /** Every field the tile groups by, and every field of its source a drill may step on. */
31
+ function allowedMembers(input) {
32
+ const grouped = (input.query.dimensions ?? []).map((d) => d.member);
33
+ return /* @__PURE__ */ new Set([...grouped, ...drillableMembers(input.model, input.query.source, input.readable)]);
34
+ }
35
+ /** The filter one step adds; a field the tile neither groups by nor can be broken down by is refused. */
36
+ function stepFilter(step, allowed) {
37
+ if ("bucket" in step) return void 0;
38
+ const members = stepMembers(step);
39
+ if (members.length === 0) refuse("A step names at least one field.");
40
+ const bad = members.find((m) => !allowed.has(m));
41
+ if (bad !== void 0) refuse(`"${bad}" is not a field this tile can be drilled by.`);
42
+ if ("group" in step) return { all: step.group.map((g) => equalsLeaf(g.member, g.value)) };
43
+ if ("search" in step) return {
44
+ member: step.search.member,
45
+ op: "contains",
46
+ values: [step.search.text]
47
+ };
48
+ return otherFilter(step.other);
49
+ }
50
+ /** The line a drill reads: `m1` and the like; one line's tile needs none named. */
51
+ function checkLine(query, drill) {
52
+ const calc = query.calc ?? [];
53
+ const known = [...query.measures.map((m) => m.id), ...calc.map((c) => c.id)];
54
+ if (drill.measure === void 0 && query.measures.length + calc.length > 1) refuse("This tile has more than one line: name the one clicked (measure).");
55
+ if (drill.measure !== void 0 && !known.includes(drill.measure)) refuse(`The tile has no line "${drill.measure}" to drill.`);
56
+ }
57
+ /**
58
+ * The rows behind a drill, as a query with no grouping: the tile's own query (its filters,
59
+ * picks, range and measures) with each step's values ANDed on as filters and its time windows
60
+ * narrowing the range. The lock, required filters, tenancy and row rules travel apart, as for
61
+ * the tile. A calc that reads around its row (a total, a bucket, the period before) is left
62
+ * out: on rows with no grouping it would read the wrong scope. The server evaluates it from
63
+ * each scope's own read (`drillScopes`).
64
+ */
65
+ function composeDrill(input) {
66
+ const { query, drill } = input;
67
+ if (drill.steps.length > 8) refuse(`A path is at most 8 steps.`);
68
+ const allowed = allowedMembers(input);
69
+ const added = drill.steps.flatMap((step) => stepFilter(step, allowed) ?? []);
70
+ const parts = [...query.filters === void 0 ? [] : [query.filters], ...added];
71
+ const [only, ...more] = parts;
72
+ const around = aroundCalcs(query);
73
+ const calc = (query.calc ?? []).filter((c) => !around.has(c.id));
74
+ checkLine(query, drill);
75
+ const time = drilledTime(input.model, query, drill.steps, input.clock);
76
+ return {
77
+ kind: query.kind,
78
+ source: query.source,
79
+ measures: query.measures,
80
+ ...calc.length === 0 ? {} : { calc },
81
+ ...only === void 0 ? {} : { filters: more.length === 0 ? only : { all: parts } },
82
+ ...time === void 0 ? {} : { time }
83
+ };
84
+ }
85
+ export { composeDrill };
@@ -0,0 +1,21 @@
1
+ import { DimensionDef, Model } from "../../model/types.mjs";
2
+ import { WireFilter } from "../filter.mjs";
3
+ import { WireQuery } from "../types.mjs";
4
+ /** Which members a viewer may see in a drill; the server's answer for sensitive members. */
5
+ export type Readable = (member: string, def: DimensionDef) => boolean;
6
+ /**
7
+ * The fields Breakdown offers at a step: every drill field but those the path fixes or the line's
8
+ * measure fixes. A field the tile groups by is offered where the path does not fix it (its total,
9
+ * a number tile's root), so a total breaks down by the tile's own groups. Under Other, the field Other was cut on comes first:
10
+ * breaking it down again shows the long tail.
11
+ */
12
+ export declare function offeredMembers(model: Model, query: WireQuery, path: {
13
+ fixed: readonly string[];
14
+ other: readonly string[];
15
+ where?: WireFilter | undefined;
16
+ }, readable: Readable): string[];
17
+ /**
18
+ * The time field Over time uses: the tile's own, else the source's default, else its first. A
19
+ * field the tile does not group by must be one a drill may read; else there is none.
20
+ */
21
+ export declare function trendDimension(model: Model, query: WireQuery): string | undefined;