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
@@ -0,0 +1,155 @@
1
+ import { DrillReason } from "../../error/codes.mjs";
2
+ import { Primitive } from "../../types/primitives.mjs";
3
+ import { Calendar, Cell, Grain, Picks, ResolvedRange, WireQuery } from "../types.mjs";
4
+ /**
5
+ * One step into the rows behind a mark, as the server reads it from the answer it drew:
6
+ *
7
+ * - `group`: a bar, a slice, a table row or a cell, one value per field it is grouped by (a
8
+ * segment carries both). A null value is the group of rows where the field is not set.
9
+ * - `bucket`: a time point, its exact window `[from, to)` from the engine's own calendar.
10
+ * - `other`: the rows a limit left out: those in none of the groups it kept, each group its
11
+ * values of `members`. The kept set is the engine's own, complete, never read off the rows.
12
+ * - `search`: the rows whose field contains a text, as a searched Breakdown read them; it
13
+ * travels with an Other drawn under the search, so that Other stays the searched one.
14
+ *
15
+ * A step never travels as itself: it is sealed into a selection, so a client cannot write one.
16
+ */
17
+ export type DrillStep = {
18
+ group: readonly {
19
+ member: string;
20
+ value: Primitive;
21
+ }[];
22
+ } | {
23
+ bucket: {
24
+ member: string;
25
+ from: string;
26
+ to: string;
27
+ grain?: Grain;
28
+ };
29
+ } | {
30
+ other: {
31
+ members: readonly string[];
32
+ kept: readonly (readonly Primitive[])[];
33
+ };
34
+ } | {
35
+ search: {
36
+ member: string;
37
+ text: string;
38
+ };
39
+ };
40
+ /**
41
+ * What a selection holds, sealed by the server: the steps one mark adds (none for a total or a
42
+ * single number), and the mark's value of each line when it was drawn, by its column id.
43
+ */
44
+ export type Selection = {
45
+ steps: readonly DrillStep[];
46
+ clicked?: Readonly<Record<string, Cell>>;
47
+ /** A mark of the comparison period: its rows are read in that period's window. */
48
+ previous?: true;
49
+ /** The execution it was drawn under (`PinnedExecution.id`): a selection opens only under it. */
50
+ exec?: string;
51
+ /** The steps it was drawn under, as a digest: a selection opens only after those same steps. */
52
+ parent?: string;
53
+ };
54
+ /**
55
+ * What an execution holds, sealed by the server: the range the tile resolved to, its calendar
56
+ * and the document's version, so a drill opened at 23:59 still reads the same day at midnight.
57
+ */
58
+ export type PinnedExecution = {
59
+ /** Names this execution, so a selection drawn under another one is refused. */
60
+ id: string;
61
+ /** Who drew it: the fingerprint of the issuing viewer's access, never readable. */
62
+ by: string;
63
+ /** A draft's content as drawn, so a draft that changed since is stale. */
64
+ revision?: string;
65
+ range?: ResolvedRange;
66
+ /**
67
+ * The instant the answer was drawn at: a relative range ("last 30 days") is read again at
68
+ * it, so the drill reads the same span and the same period before as the tile.
69
+ */
70
+ now?: string;
71
+ /** The comparison period's range, for a mark of the period before. */
72
+ compare?: ResolvedRange;
73
+ calendar: Calendar;
74
+ version?: number;
75
+ };
76
+ /** A path into a tile, opened: its steps, and which of its lines was clicked (`m1`, `c1`). */
77
+ export type Drill = {
78
+ steps: readonly DrillStep[];
79
+ measure?: string;
80
+ };
81
+ /** Where a drill starts: a dashboard's tile, by reference, or a free query. */
82
+ export type DrillOrigin = {
83
+ kind: "dashboard";
84
+ dashboardId: string;
85
+ widgetId: string;
86
+ /** One of the widget's queries; `main` when not given. */
87
+ query?: string;
88
+ picks: Picks;
89
+ /** An earlier version, or the viewer's draft; the published head when not given. */
90
+ document?: {
91
+ version: number;
92
+ } | {
93
+ draft: true;
94
+ };
95
+ } | {
96
+ kind: "query";
97
+ query: WireQuery;
98
+ };
99
+ /** What a drill shows. */
100
+ export type DrillView = {
101
+ by: "breakdown";
102
+ member?: string;
103
+ search?: string;
104
+ } | {
105
+ by: "trend";
106
+ grain?: Grain;
107
+ } |
108
+ /** `numerator`: a ratio's Items, only the rows its numerator counts. */
109
+ {
110
+ by: "items";
111
+ numerator?: true;
112
+ } | {
113
+ by: "explanation";
114
+ };
115
+ /**
116
+ * A drill as plain data: where it starts, which line was clicked (`entry`, a column id such as
117
+ * `m1`; needed when the tile has more than one), the pinned execution and the path, both sealed
118
+ * by the server, and the view open. It lives in a dashboard's view state, so Share and Back keep
119
+ * it, and it is all a page of the host's own needs to open the drill.
120
+ */
121
+ export type DrillState = {
122
+ origin: DrillOrigin;
123
+ entry?: string;
124
+ execution: string;
125
+ /** Sealed selections, root first; at most `MAX_DRILL_STEPS`. */
126
+ path: readonly string[];
127
+ view: DrillView;
128
+ /** The view each earlier step had, so a breadcrumb opens it as it was. */
129
+ views?: readonly DrillView[];
130
+ };
131
+ /**
132
+ * What the limits of an answer kept, as the engine ranked them: each dimension with a limit of
133
+ * its own, by its index, with every value it kept (whether or not a row shows it). A drill's
134
+ * Other is the rows in none of them, so it is read from here, never from the rows drawn.
135
+ */
136
+ export type Cuts = {
137
+ segments: readonly (readonly [number, readonly Cell[]])[];
138
+ };
139
+ /** A path is at most this many selections; a deeper one is refused. */
140
+ export declare const MAX_DRILL_STEPS = 8;
141
+ /** A field a drill can be broken down by, as a viewer reads it. */
142
+ export type DrillField = {
143
+ id: string;
144
+ label: string;
145
+ };
146
+ /** What the rows behind a line are, and so what its Items list. */
147
+ export type DrillSemantics = "rows" | "non-null" | "distinct" | "ratio" | "expression";
148
+ /** Whether a drill can show a view, and why not when it cannot: a code, and its English text. */
149
+ export type DrillCan = {
150
+ ok: true;
151
+ } | {
152
+ ok: false;
153
+ code: DrillReason;
154
+ reason: string;
155
+ };
@@ -0,0 +1,4 @@
1
+ // src/query/drill/types.ts
2
+ /** A path is at most this many selections; a deeper one is refused. */
3
+ const MAX_DRILL_STEPS = 8;
4
+ export { MAX_DRILL_STEPS };
@@ -0,0 +1,62 @@
1
+ import { Model } from "../../model/types.mjs";
2
+ import { WireFilter } from "../filter.mjs";
3
+ import { MeasureAlias, WireQuery } from "../types.mjs";
4
+ import { Drill } from "./types.mjs";
5
+ /**
6
+ * The population a line reads: the rows behind the drill that the line counts. It ANDs the
7
+ * line's own filter, its measure's `where` (a ratio's denominator's; with `numerator`, its
8
+ * numerator's too), and, for a measure of a field, that the field is set: read by a predicate
9
+ * of the drill's own (`dd_set_...`), whether or not the field may be shown, so the population
10
+ * never depends on what a viewer may see. Breakdown, Over time and Items all read it, and the
11
+ * drill law checks it against the oracle. A comparison is not part of it.
12
+ */
13
+ export declare function population(model: Model, set: WireQuery, drill: Drill, numerator?: boolean): WireQuery;
14
+ /** A line's own filter, its rows' `where`, its operand set, and its numerator's `where`; none for a formula. */
15
+ export declare function lineFilter(model: Model, set: WireQuery, drill: Drill, only?: {
16
+ numerator?: boolean;
17
+ operand?: boolean;
18
+ }): WireFilter | undefined;
19
+ /**
20
+ * The line's value and how many rows are behind it, in one read: the drill's query with the row
21
+ * count over the line's population (`dd_rows` with the line's filter) as one more measure, and,
22
+ * for a line that counts only rows whose field is set, the rows whether or not it is (`all`).
23
+ * Aliases are returned so each count is read by name.
24
+ */
25
+ export declare function summaryQuery(model: Model, set: WireQuery, drill: Drill): {
26
+ query: WireQuery;
27
+ count: MeasureAlias;
28
+ all?: MeasureAlias;
29
+ };
30
+ /**
31
+ * The step before a sum's value, with its least row value, so a share of it is shown only
32
+ * when no row can be negative: a parent of 50 made of 100 and -50 has no 200% child.
33
+ */
34
+ export declare function parentQuery(model: Model, parent: WireQuery, drill: Drill): {
35
+ query: WireQuery;
36
+ least?: MeasureAlias;
37
+ };
38
+ /** How a Breakdown reads: the comparison it shows the change against, and a search in its field. */
39
+ export type BreakdownOptions = {
40
+ compare?: NonNullable<WireQuery["time"]>["compare"];
41
+ search?: string;
42
+ /** The line does not add up (an average, a ratio): its groups rank by their row count. */
43
+ rankByRows?: boolean;
44
+ };
45
+ /**
46
+ * The rows behind a drill broken down by one field: its top groups, then Other, ranked by the
47
+ * line when it adds up, else by the rows behind each (Rules, section 6: never by an average).
48
+ * With a comparison, each group's value now, before (`c1`) and its change (`c2`), the groups
49
+ * that moved most first (`c3`). With a search, only the groups whose value contains it.
50
+ */
51
+ export declare function breakdownQuery(rows: WireQuery, member: string, drill: Drill, options?: BreakdownOptions): WireQuery;
52
+ /** How many rows a population holds: every source's rows counted (`dd_rows`, in a drill's model). */
53
+ export declare function countQuery(rows: WireQuery): WireQuery;
54
+ /**
55
+ * A distinct count's items, one page: its distinct values (never "not set": a distinct count
56
+ * skips it), each with its row count, most rows first then by value, so pages never overlap.
57
+ * It reads `take` past `skip`, and one more to say whether a page follows.
58
+ */
59
+ export declare function distinctQuery(rows: WireQuery, field: string, page: {
60
+ skip: number;
61
+ take: number;
62
+ }): WireQuery;
@@ -0,0 +1,257 @@
1
+ import { EngineError } from "../../error/refusal.mjs";
2
+ import { drillMeasure, lineMeasure, operandSet, rowsMeasure } from "./line.mjs";
3
+ import { ROW_COUNT, minName } from "./synthetic.mjs";
4
+ // src/query/drill/views.ts
5
+ /** Breakdown draws the top groups and puts the rest in Other. */
6
+ const BREAKDOWN_TOP = 10;
7
+ const anded = (set, parts) => {
8
+ const kept = parts.filter((f) => f !== void 0);
9
+ const [only, ...more] = kept;
10
+ const { filters: _f, ...rest } = set;
11
+ if (only === void 0) return rest;
12
+ return {
13
+ ...rest,
14
+ filters: more.length === 0 ? only : { all: kept }
15
+ };
16
+ };
17
+ /** Filters ANDed into one, or none. */
18
+ const andAll = (parts) => {
19
+ const kept = parts.filter((f) => f !== void 0);
20
+ const [only, ...more] = kept;
21
+ return more.length === 0 ? only : { all: kept };
22
+ };
23
+ /**
24
+ * The population a line reads: the rows behind the drill that the line counts. It ANDs the
25
+ * line's own filter, its measure's `where` (a ratio's denominator's; with `numerator`, its
26
+ * numerator's too), and, for a measure of a field, that the field is set: read by a predicate
27
+ * of the drill's own (`dd_set_...`), whether or not the field may be shown, so the population
28
+ * never depends on what a viewer may see. Breakdown, Over time and Items all read it, and the
29
+ * drill law checks it against the oracle. A comparison is not part of it.
30
+ */
31
+ function population(model, set, drill, numerator) {
32
+ const time = set.time === void 0 ? {} : { time: {
33
+ dimension: set.time.dimension,
34
+ range: set.time.range
35
+ } };
36
+ return anded({
37
+ ...set,
38
+ ...time
39
+ }, [set.filters, lineFilter(model, set, drill, { numerator: numerator === true })]);
40
+ }
41
+ /** A line's own filter, its rows' `where`, its operand set, and its numerator's `where`; none for a formula. */
42
+ function lineFilter(model, set, drill, only) {
43
+ const line = lineMeasure(model, set, drill);
44
+ if (line === void 0) return void 0;
45
+ const rows = rowsMeasure(model, set.source, line);
46
+ if (rows === void 0) throw new EngineError("SELECTION_INVALID", "The ratio's denominator is not a measure of its source.");
47
+ const where = "where" in rows.def ? rows.def.where : void 0;
48
+ const operand = only?.operand === false ? void 0 : operandFilter(model, set.source, rows.name);
49
+ const extra = only?.numerator === true ? numeratorWhere(model, set.source, line.def) : void 0;
50
+ return andAll([
51
+ line.entry.filter,
52
+ where,
53
+ operand,
54
+ extra
55
+ ]);
56
+ }
57
+ /** The filter "the operand is set", for a measure that counts only rows with a value. */
58
+ function operandFilter(model, source, name) {
59
+ const isSet = operandSet(model, source, name);
60
+ return isSet === void 0 ? void 0 : {
61
+ member: isSet,
62
+ op: "equals",
63
+ values: [true]
64
+ };
65
+ }
66
+ /** A ratio's numerator `where`, for the Only filter. */
67
+ function numeratorWhere(model, source, def) {
68
+ if (def.kind !== "ratio") return;
69
+ const top = model.sources[source]?.measures[def.numerator];
70
+ const where = top !== void 0 && "where" in top ? top.where : void 0;
71
+ return andAll([where, operandFilter(model, source, def.numerator)]);
72
+ }
73
+ /** The row count over a filter, as one more measure of a query. */
74
+ const counted = (set, id, filter) => ({
75
+ id,
76
+ measure: `${set.source}.${ROW_COUNT}`,
77
+ ...filter === void 0 ? {} : { filter }
78
+ });
79
+ /**
80
+ * The line's value and how many rows are behind it, in one read: the drill's query with the row
81
+ * count over the line's population (`dd_rows` with the line's filter) as one more measure, and,
82
+ * for a line that counts only rows whose field is set, the rows whether or not it is (`all`).
83
+ * Aliases are returned so each count is read by name.
84
+ */
85
+ function summaryQuery(model, set, drill) {
86
+ const count = `m${set.measures.length + 1}`;
87
+ const filter = lineFilter(model, set, drill);
88
+ const loose = lineFilter(model, set, drill, { operand: false });
89
+ const measures = [...set.measures, counted(set, count, filter)];
90
+ if (JSON.stringify(loose) === JSON.stringify(filter)) return {
91
+ query: {
92
+ ...set,
93
+ measures
94
+ },
95
+ count
96
+ };
97
+ const all = `m${set.measures.length + 2}`;
98
+ return {
99
+ query: {
100
+ ...set,
101
+ measures: [...measures, counted(set, all, loose)]
102
+ },
103
+ count,
104
+ all
105
+ };
106
+ }
107
+ /**
108
+ * The step before a sum's value, with its least row value, so a share of it is shown only
109
+ * when no row can be negative: a parent of 50 made of 100 and -50 has no 200% child.
110
+ */
111
+ function parentQuery(model, parent, drill) {
112
+ const line = lineMeasure(model, parent, drill);
113
+ const name = line?.def.kind === "sum" ? minName(line.name) : void 0;
114
+ const measure = name === void 0 ? void 0 : model.sources[parent.source]?.measures[name];
115
+ if (line === void 0 || measure === void 0) return { query: parent };
116
+ const least = `m${parent.measures.length + 1}`;
117
+ const entry = {
118
+ id: least,
119
+ measure: `${parent.source}.${name}`,
120
+ ...line.entry.filter === void 0 ? {} : { filter: line.entry.filter }
121
+ };
122
+ return {
123
+ query: {
124
+ ...parent,
125
+ measures: [...parent.measures, entry]
126
+ },
127
+ least
128
+ };
129
+ }
130
+ /** The order a Breakdown ranks its groups by: the line when it adds up, else the row count. */
131
+ function ranking(rows, by, byRows) {
132
+ if (!byRows) return {
133
+ measures: rows.measures,
134
+ order: [{
135
+ by,
136
+ dir: "desc"
137
+ }]
138
+ };
139
+ const count = `m${rows.measures.length + 1}`;
140
+ return {
141
+ measures: [...rows.measures, {
142
+ id: count,
143
+ measure: `${rows.source}.${ROW_COUNT}`
144
+ }],
145
+ order: [{
146
+ by: count,
147
+ dir: "desc"
148
+ }]
149
+ };
150
+ }
151
+ /**
152
+ * The rows behind a drill broken down by one field: its top groups, then Other, ranked by the
153
+ * line when it adds up, else by the rows behind each (Rules, section 6: never by an average).
154
+ * With a comparison, each group's value now, before (`c1`) and its change (`c2`), the groups
155
+ * that moved most first (`c3`). With a search, only the groups whose value contains it.
156
+ */
157
+ function breakdownQuery(rows, member, drill, options = {}) {
158
+ const by = drillMeasure(rows, drill) ?? "m1";
159
+ const base = {
160
+ ...options.search === void 0 || options.search === "" ? rows : anded(rows, [rows.filters, {
161
+ member,
162
+ op: "contains",
163
+ values: [options.search]
164
+ }]),
165
+ dimensions: [{
166
+ id: "d1",
167
+ member
168
+ }],
169
+ limit: BREAKDOWN_TOP,
170
+ other: true
171
+ };
172
+ if (options.compare === void 0 || rows.time === void 0 || by.startsWith("c")) return {
173
+ ...base,
174
+ ...ranking(rows, by, options.rankByRows === true)
175
+ };
176
+ const now = { ref: by };
177
+ const before = {
178
+ ref: by,
179
+ of: "previous"
180
+ };
181
+ return {
182
+ ...base,
183
+ time: {
184
+ ...rows.time,
185
+ compare: options.compare
186
+ },
187
+ calc: [
188
+ {
189
+ id: "c1",
190
+ formula: before,
191
+ label: "Before"
192
+ },
193
+ {
194
+ id: "c2",
195
+ formula: {
196
+ op: "-",
197
+ args: [now, before]
198
+ },
199
+ label: "Change"
200
+ },
201
+ {
202
+ id: "c3",
203
+ formula: {
204
+ op: "abs",
205
+ args: [{
206
+ op: "-",
207
+ args: [now, before]
208
+ }]
209
+ },
210
+ label: "Size of change"
211
+ }
212
+ ],
213
+ order: [{
214
+ by: "c3",
215
+ dir: "desc"
216
+ }]
217
+ };
218
+ }
219
+ /** How many rows a population holds: every source's rows counted (`dd_rows`, in a drill's model). */
220
+ function countQuery(rows) {
221
+ const { calc: _c, order: _o, limit: _l, other: _ot, total: _t, dimensions: _d, ...rest } = rows;
222
+ return {
223
+ ...rest,
224
+ measures: [{
225
+ id: "m1",
226
+ measure: `${rows.source}.${ROW_COUNT}`
227
+ }]
228
+ };
229
+ }
230
+ /**
231
+ * A distinct count's items, one page: its distinct values (never "not set": a distinct count
232
+ * skips it), each with its row count, most rows first then by value, so pages never overlap.
233
+ * It reads `take` past `skip`, and one more to say whether a page follows.
234
+ */
235
+ function distinctQuery(rows, field, page) {
236
+ const all = countQuery(rows);
237
+ return {
238
+ ...anded(all, [all.filters, {
239
+ member: field,
240
+ op: "set",
241
+ values: []
242
+ }]),
243
+ dimensions: [{
244
+ id: "d1",
245
+ member: field
246
+ }],
247
+ order: [{
248
+ by: "m1",
249
+ dir: "desc"
250
+ }, {
251
+ by: "d1",
252
+ dir: "asc"
253
+ }],
254
+ limit: page.skip + page.take + 1
255
+ };
256
+ }
257
+ export { breakdownQuery, countQuery, distinctQuery, lineFilter, parentQuery, population, summaryQuery };
@@ -15,6 +15,12 @@ export type ValueLeaf<Member extends string = string> = {
15
15
  member: Member;
16
16
  op: Op;
17
17
  values: readonly Primitive[];
18
+ /**
19
+ * Set only by the engine, on a limited dimension's kept values: a test that keeps most rows,
20
+ * which no index would answer, so its SQL leaves out the tests that are there for an index.
21
+ * The wire schema refuses it, and it changes no answer.
22
+ */
23
+ broad?: true;
18
24
  };
19
25
  export type ViewerLeaf<Member extends string = string> = {
20
26
  member: Member;
@@ -1,10 +1,16 @@
1
+ import { Primitive } from "../types/primitives.mjs";
1
2
  import { Control, DateRange, Picks } from "./types.mjs";
2
3
  /** Whether a pick is a date range: the last N units, or from and to. */
3
4
  export declare function isDateRange(pick: Picks[string]): pick is DateRange;
5
+ /** Whether a pick is a filter's: an operator and its values. */
6
+ export declare function isValuePick(pick: Picks[string] | undefined): pick is Extract<Picks[string], {
7
+ values: readonly Primitive[];
8
+ }>;
4
9
  /**
5
10
  * Why a viewer's pick does not fit its control, or undefined when it does: the one rule the
6
11
  * tiles and a shared link both apply. A filter takes values with one of its operators, from
7
- * its own list when it has one, at least one value, and only one unless it is multi; a date
8
- * range control takes a range; any other control takes no pick yet.
12
+ * its own list when it has one, at least one value (none for set and notSet, which test null),
13
+ * and only one unless it is multi; a date range control takes a range; any other control takes
14
+ * no pick yet.
9
15
  */
10
16
  export declare function pickProblem(control: Control, pick: Picks[string]): string | undefined;
@@ -3,18 +3,25 @@
3
3
  function isDateRange(pick) {
4
4
  return typeof pick === "object" && pick !== null && ("last" in pick || "from" in pick);
5
5
  }
6
+ /** Whether a pick is a filter's: an operator and its values. */
7
+ function isValuePick(pick) {
8
+ return typeof pick === "object" && pick !== null && "values" in pick;
9
+ }
6
10
  /** Whether a filter pick fits its filter: one of its operators, its own values, one unless multi. */
7
11
  function filterFits(control, pick) {
12
+ if (!control.ops.some((op) => op === pick.op)) return false;
13
+ if (pick.op === "set" || pick.op === "notSet") return pick.values.length === 0;
8
14
  const allowed = Array.isArray(control.values) ? control.values : void 0;
9
15
  const inList = allowed === void 0 || pick.values.every((v) => allowed.includes(v));
10
16
  const count = pick.values.length > 0 && (control.multi || pick.values.length === 1);
11
- return control.ops.some((op) => op === pick.op) && inList && count;
17
+ return inList && count;
12
18
  }
13
19
  /**
14
20
  * Why a viewer's pick does not fit its control, or undefined when it does: the one rule the
15
21
  * tiles and a shared link both apply. A filter takes values with one of its operators, from
16
- * its own list when it has one, at least one value, and only one unless it is multi; a date
17
- * range control takes a range; any other control takes no pick yet.
22
+ * its own list when it has one, at least one value (none for set and notSet, which test null),
23
+ * and only one unless it is multi; a date range control takes a range; any other control takes
24
+ * no pick yet.
18
25
  */
19
26
  function pickProblem(control, pick) {
20
27
  if (control.kind === "date_range") return isDateRange(pick) ? void 0 : `The pick for "${control.id}" is not a date range.`;
@@ -22,4 +29,4 @@ function pickProblem(control, pick) {
22
29
  if (typeof pick !== "object" || pick === null || !("op" in pick)) return `The pick for "${control.id}" is not a filter.`;
23
30
  return filterFits(control, pick) ? void 0 : `The pick for "${control.id}" is not one the control allows.`;
24
31
  }
25
- export { isDateRange, pickProblem };
32
+ export { isDateRange, isValuePick, pickProblem };
@@ -1,6 +1,16 @@
1
- import { Cell } from "./types.mjs";
1
+ import { Cuts } from "./drill/types.mjs";
2
+ import { Cell, WireQuery } from "./types.mjs";
2
3
  /**
3
4
  * Each limited dimension's values in rank order, by its index: one more than its limit when
4
5
  * more exist, so a query can tell that the limit left something out.
5
6
  */
6
- export type Kept = ReadonlyMap<number, readonly Cell[]>;
7
+ export type Kept = ReadonlyMap<number, readonly Cell[]>;
8
+ /** What each limited dimension kept, as a drill's Other reads it: the values, cut to the limit. */
9
+ export declare const segmentCuts: (query: WireQuery, kept: Kept) => Cuts;
10
+ /** The indexes of the dimensions with a limit of their own. */
11
+ export declare const limitedDimensions: (query: WireQuery) => number[];
12
+ /**
13
+ * The query that ranks one dimension's values alone, over the whole range, by its `rankBy`:
14
+ * by default the first measure descending. Ties go by the value, as in every ranking.
15
+ */
16
+ export declare function rankQuery(query: WireQuery, index: number): WireQuery;
@@ -6,6 +6,8 @@ function keptOf(query, index, ranked) {
6
6
  const limit = query.dimensions?.[index]?.limit;
7
7
  return limit === void 0 ? ranked : ranked.slice(0, limit);
8
8
  }
9
+ /** What each limited dimension kept, as a drill's Other reads it: the values, cut to the limit. */
10
+ const segmentCuts = (query, kept) => ({ segments: [...kept].map(([i, ranked]) => [i, keptOf(query, i, ranked)]) });
9
11
  /** Whether any dimension has a limit of its own. */
10
12
  const hasSegments = (query) => (query.dimensions ?? []).some((d) => d.limit !== void 0);
11
13
  /** The indexes of the dimensions with a limit of their own. */
@@ -62,7 +64,8 @@ function keptFilter(member, values) {
62
64
  const leaves = [{
63
65
  member,
64
66
  op: "in",
65
- values: values.filter((v) => v !== null && typeof v !== "object")
67
+ values: values.filter((v) => v !== null && typeof v !== "object"),
68
+ broad: true
66
69
  }];
67
70
  if (values.includes(null)) leaves.push({
68
71
  member,
@@ -179,4 +182,4 @@ function segmentOthers(query, folded) {
179
182
  ...before === void 0 ? {} : { before }
180
183
  };
181
184
  }
182
- export { foldedColumn, hasSegments, keptQuery, limitedDimensions, rankQuery, segmentOtherQuery, segmentOthers, segmentSplit, uncutQuery };
185
+ export { foldedColumn, hasSegments, keptQuery, limitedDimensions, rankQuery, segmentCuts, segmentOtherQuery, segmentOthers, segmentSplit, uncutQuery };
@@ -11,6 +11,21 @@ const lastPart = (id) => id.split(".").at(-1) ?? id;
11
11
  function memberLabel(id, label) {
12
12
  return label ?? words(lastPart(id));
13
13
  }
14
+ /** How a measure's values read: its unit, a ratio the model reads as a percent of one, a duration in seconds. */
15
+ function readsAs(def) {
16
+ const unit = def !== void 0 && "unit" in def ? def.unit : void 0;
17
+ const format = def !== void 0 && "format" in def ? def.format : void 0;
18
+ const percent = def?.kind === "ratio" && format === "percent";
19
+ const duration = format === "duration";
20
+ return {
21
+ ...unit === void 0 ? {} : { unit },
22
+ ...percent ? {
23
+ format: "percent",
24
+ fraction: true
25
+ } : {},
26
+ ...duration ? { format: "duration" } : {}
27
+ };
28
+ }
14
29
  /** A measure's cell type: counts are integers, percentiles float, the rest as declared. */
15
30
  function measureType(model, source, def) {
16
31
  if (def.kind === "count") return "int";
@@ -53,7 +68,8 @@ function dimensionColumns(model, query) {
53
68
  return {
54
69
  id: d.id,
55
70
  label,
56
- type: dimensionType(resolved?.dimension)
71
+ type: dimensionType(resolved?.dimension),
72
+ member: d.member
57
73
  };
58
74
  });
59
75
  }
@@ -64,21 +80,21 @@ function dimensionColumns(model, query) {
64
80
  */
65
81
  function resultColumns(model, query) {
66
82
  const grain = query.time?.grain;
67
- const bucket = grain === void 0 ? [] : [{
83
+ const bucket = grain === void 0 || query.time === void 0 ? [] : [{
68
84
  id: "t",
69
85
  label: words(grain),
70
86
  type: "time",
87
+ member: query.time.dimension,
71
88
  grain
72
89
  }];
73
90
  const dimensions = dimensionColumns(model, query);
74
91
  const measures = query.measures.map((m) => {
75
92
  const def = resolveMeasure(model, query.source, m.measure);
76
- const unit = def !== void 0 && "unit" in def && def.unit !== void 0 ? def.unit : void 0;
77
93
  return {
78
94
  id: m.id,
79
95
  label: m.label ?? memberLabel(m.measure, def?.label),
80
96
  type: def === void 0 ? "float" : measureType(model, query.source, def),
81
- ...unit === void 0 ? {} : { unit }
97
+ ...readsAs(def)
82
98
  };
83
99
  });
84
100
  const types = new Map(measures.map((c) => [c.id, c.type]));
@@ -9,12 +9,16 @@ export type ResultColumn = {
9
9
  label: string;
10
10
  type: "string" | "number" | "boolean" | "time" | "int" | "decimal" | "float";
11
11
  unit?: Unit;
12
+ /** On a dimension or the time bucket: the member it groups by, so a click can drill into it. */
13
+ member?: string;
12
14
  /** On the time bucket column: the grain its labels name. */
13
15
  grain?: Grain;
14
- /** On a calc's column: how its values read. */
16
+ /** On a calc's column, or a ratio the model reads as a percent: how its values read. */
15
17
  format?: Format;
16
18
  /** On a calc that reads the comparison period: a change, shown with its sign (+3.2%). */
17
19
  signed?: true;
20
+ /** On a ratio read as a percent: its values are fractions of one (0.55 reads 55%), not points. */
21
+ fraction?: true;
18
22
  };
19
23
  /** A column of a records page: the member it shows, labelled and typed from the model. */
20
24
  export type RecordColumn = {
@@ -0,0 +1,7 @@
1
+ import { WireQuery } from "../query/types.mjs";
2
+ import { z } from "zod";
3
+ /**
4
+ * The query with each id renumbered to its position and every reference following it: for an
5
+ * agent's tool, which takes any ids and answers in text, so the ids never show.
6
+ */
7
+ export declare function positional<Q extends WireQuery>(query: Q): Q;