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,91 @@
1
+ import { parseMemberId, resolveDimension } from "../../model/member.mjs";
2
+ // src/query/drill/fields.ts
3
+ /** A field a drill may read at all: not hidden, not sensitive, not marked `drill: false`. */
4
+ const open = (def) => def.hidden !== true && def.sensitive !== true && def.drill !== false;
5
+ /**
6
+ * A field with a known, small set of values (Rules, section 6): declared `values`, a ref, a
7
+ * true-or-false field, or buckets. Free text, ids, numbers and times are not, unless preferred.
8
+ */
9
+ const small = (def) => def.kind === "ref" || def.kind === "bucket" || def.kind === "boolean" || def.kind === "expr" && def.type === "boolean" || def.kind === "string" && Array.isArray(def.values);
10
+ /** A field Breakdown may group by when preferred: anything but a time or a raw number. */
11
+ const groupable = (def) => def.kind !== "time" && def.kind !== "number" && !(def.kind === "expr" && def.type === "number");
12
+ /** A source's own dimensions and those of its one-row joins, as member ids, in the model's order. */
13
+ function listed(model, source, def) {
14
+ const own = Object.keys(def.dimensions).map((name) => `${source}.${name}`);
15
+ const joined = Object.entries(def.joins ?? {}).flatMap(([join, j]) => {
16
+ const target = model.sources[j.to];
17
+ if (j.relationship === "one_to_many" || target === void 0 || target.drill === false) return [];
18
+ return Object.keys(target.dimensions).map((name) => `${source}.${join}.${name}`);
19
+ });
20
+ return [...own, ...joined];
21
+ }
22
+ /** The members one `prefer` entry names: a dimension, `join.dimension`, or a join's every field. */
23
+ function preferred(source, entry, all) {
24
+ const exact = `${source}.${entry}`;
25
+ if (all.includes(exact)) return [exact];
26
+ return all.filter((id) => parseMemberId(id)?.join === entry);
27
+ }
28
+ /** Every field of `source` a drill may step on: open, groupable and readable, in the model's order. */
29
+ function drillableMembers(model, source, readable) {
30
+ const def = model.sources[source];
31
+ if (def === void 0 || def.drill === false) return [];
32
+ return listed(model, source, def).filter((id) => {
33
+ const d = resolveDimension(model, source, id)?.dimension;
34
+ return d !== void 0 && open(d) && groupable(d) && readable(id, d);
35
+ });
36
+ }
37
+ /**
38
+ * Every field a drill into `source` may break down by: the model's preferred ones first
39
+ * (`drill.prefer`), then those with a known small set of values, in the model's order. Never a
40
+ * hidden, sensitive or `drill: false` field; none at all for a source marked `drill: false`.
41
+ */
42
+ function drillMembers(model, source, readable) {
43
+ const def = model.sources[source];
44
+ if (def === void 0 || def.drill === false) return [];
45
+ const fit = listed(model, source, def).flatMap((id) => {
46
+ const resolved = resolveDimension(model, source, id);
47
+ if (resolved === void 0) return [];
48
+ const d = resolved.dimension;
49
+ return open(d) && groupable(d) && readable(id, d) ? [{
50
+ id,
51
+ small: small(d)
52
+ }] : [];
53
+ });
54
+ const all = fit.map((f) => f.id);
55
+ const first = (def.drill?.prefer ?? []).flatMap((entry) => preferred(source, entry, all));
56
+ return [.../* @__PURE__ */ new Set([...first, ...fit.filter((f) => f.small).map((f) => f.id)])];
57
+ }
58
+ /** The fields a measure's own `where` fixes to one value: every row it counts has the same one. */
59
+ function fixedByWhere(where) {
60
+ if (where === void 0) return [];
61
+ if ("all" in where) return where.all.flatMap((f) => fixedByWhere(f));
62
+ return "member" in where && "values" in where && where.op === "equals" && where.values.length === 1 ? [where.member] : [];
63
+ }
64
+ /**
65
+ * The fields Breakdown offers at a step: every drill field but those the path fixes or the line's
66
+ * measure fixes. A field the tile groups by is offered where the path does not fix it (its total,
67
+ * 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:
68
+ * breaking it down again shows the long tail.
69
+ */
70
+ function offeredMembers(model, query, path, readable) {
71
+ const taken = /* @__PURE__ */ new Set([...path.fixed, ...fixedByWhere(path.where)]);
72
+ const all = drillMembers(model, query.source, readable);
73
+ const tail = path.other.filter((m) => all.includes(m) || taken.has(m));
74
+ return [.../* @__PURE__ */ new Set([...tail, ...all.filter((id) => !taken.has(id))])];
75
+ }
76
+ /**
77
+ * The time field Over time uses: the tile's own, else the source's default, else its first. A
78
+ * field the tile does not group by must be one a drill may read; else there is none.
79
+ */
80
+ function trendDimension(model, query) {
81
+ if (query.time !== void 0) return query.time.dimension;
82
+ const def = model.sources[query.source];
83
+ if (def === void 0 || def.drill === false) return void 0;
84
+ const usable = (name) => {
85
+ const d = def.dimensions[name];
86
+ return d !== void 0 && d.kind === "time" && open(d);
87
+ };
88
+ const name = def.time !== void 0 && usable(def.time) ? def.time : Object.keys(def.dimensions).find((n) => usable(n));
89
+ return name === void 0 ? void 0 : `${query.source}.${name}`;
90
+ }
91
+ export { drillMembers, drillableMembers, offeredMembers, trendDimension };
@@ -0,0 +1,11 @@
1
+ import { Readable, offeredMembers, trendDimension } from "./fields.mjs";
2
+ import { DrillInput, composeDrill } from "./compose.mjs";
3
+ import { Drawn, Picked, rowSelection } from "./selection.mjs";
4
+ import { LineSemantics, drillMeasure, lineSemantics } from "./line.mjs";
5
+ import { ItemsOrder, itemsShape } from "./items.mjs";
6
+ import { Scope, formulaParts, lineScopes, measuresOnly, scopeSteps, scopedLines } from "./scopes.mjs";
7
+ import { DrillClock, trendQuery } from "./time.mjs";
8
+ import { keptPath, pathFields, stepMembers } from "./steps.mjs";
9
+ import { KEY_FIELD, ROW_COUNT, drillModel, drillOwner, flagCell, storedCell } from "./synthetic.mjs";
10
+ import { breakdownQuery, countQuery, distinctQuery, lineFilter, parentQuery, population, summaryQuery } from "./views.mjs";
11
+ export { type Drawn, type DrillClock, type DrillInput, type ItemsOrder, KEY_FIELD, type LineSemantics, type Picked, ROW_COUNT, type Readable, type Scope, breakdownQuery, composeDrill, countQuery, distinctQuery, drillMeasure, drillModel, drillOwner, flagCell, formulaParts, itemsShape, keptPath, lineFilter, lineScopes, lineSemantics, measuresOnly, offeredMembers, parentQuery, pathFields, population, rowSelection, scopeSteps, scopedLines, stepMembers, storedCell, summaryQuery, trendDimension, trendQuery };
@@ -0,0 +1,29 @@
1
+ import { Tone } from "../../model/hints.mjs";
2
+ import { Model } from "../../model/types.mjs";
3
+ import { WireQuery } from "../types.mjs";
4
+ import { LineSemantics } from "./line.mjs";
5
+ import { Drill } from "./types.mjs";
6
+ /** How items are sorted, stated truthfully: by the line's value, or the records order. */
7
+ export type ItemsOrder = {
8
+ member: string;
9
+ dir: "asc" | "desc";
10
+ time: boolean;
11
+ };
12
+ /**
13
+ * How a drill's items show: the columns read (the source's record columns, then the line's
14
+ * value and flag fields), their order (by that value, highest first, for an average,
15
+ * percentile, min or max; else the records order, which `sorted` states), the fields that
16
+ * title and badge each item in a list, and the fields the path fixes, which a list leaves out
17
+ * (a table shows every column).
18
+ */
19
+ export declare function itemsShape(model: Model, set: WireQuery, drill: Drill, line: LineSemantics): {
20
+ badge?: {
21
+ tones?: Readonly<Record<string, Tone>>;
22
+ member: string;
23
+ };
24
+ title?: string;
25
+ sorted?: ItemsOrder;
26
+ order?: (readonly [string, "desc"])[];
27
+ columns: string[];
28
+ fixed: string[];
29
+ };
@@ -0,0 +1,98 @@
1
+ import { parseMemberId, recordDimensions } from "../../model/member.mjs";
2
+ // src/query/drill/items.ts
3
+ /** The fields a path fixes: every item has the same value there, so no list row shows it. */
4
+ const fixedBy = (drill) => new Set(drill.steps.flatMap((s) => "group" in s ? s.group.map((g) => g.member) : []));
5
+ /** A field name that names a row in words. */
6
+ const TITLE_NAMES = Object.freeze({
7
+ name: true,
8
+ title: true,
9
+ subject: true,
10
+ summary: true,
11
+ label: true
12
+ });
13
+ /** Field names that read as ids or addresses, never a title. */
14
+ const NOT_TITLE = /(?:^id$|Id$|_id$|email|key$)/iu;
15
+ /** A free text field: not one with declared values, which reads as a category (a badge). */
16
+ const isText = (def) => def.kind === "ref" || def.kind === "string" && !Array.isArray(def.values);
17
+ /** A field a list may show: not hidden, not sensitive. */
18
+ const safe = (def) => def !== void 0 && def.hidden !== true && def.sensitive !== true;
19
+ /**
20
+ * The field that names an item: `records.title` (read even when it is not a column), else a
21
+ * name-like text field, else the first free text field the path does not fix; none when there
22
+ * is no such field (a list then names its rows by the source's noun).
23
+ */
24
+ function titleOf(def, shown) {
25
+ const declared = def.records?.title;
26
+ if (declared !== void 0) return safe(def.dimensions[declared]) ? declared : void 0;
27
+ const text = shown.filter((n) => {
28
+ const d = def.dimensions[n];
29
+ return d !== void 0 && isText(d) && !NOT_TITLE.test(n);
30
+ });
31
+ return text.find((n) => Object.hasOwn(TITLE_NAMES, n)) ?? text[0];
32
+ }
33
+ /** The field shown as a badge: one with declared values the path does not fix. */
34
+ function badgeOf(def, source, shown) {
35
+ const name = shown.find((n) => {
36
+ const d = def.dimensions[n];
37
+ return d?.kind === "string" && Array.isArray(d.values);
38
+ });
39
+ if (name === void 0) return name;
40
+ const tones = def.dimensions[name]?.tones;
41
+ return {
42
+ member: `${source}.${name}`,
43
+ ...tones === void 0 ? {} : { tones }
44
+ };
45
+ }
46
+ function orderOf(def, source) {
47
+ const [first] = def.records?.order ?? (def.time === void 0 ? [] : [[def.time, "desc"]]);
48
+ if (first === void 0) return void 0;
49
+ const [name, dir] = first;
50
+ return {
51
+ member: `${source}.${name}`,
52
+ dir,
53
+ time: def.dimensions[name]?.kind === "time"
54
+ };
55
+ }
56
+ /** A member's own name on the source, when it is the source's own field. */
57
+ const ownName = (source, member) => {
58
+ const ref = member === void 0 ? void 0 : parseMemberId(member);
59
+ return ref?.source === source && ref.join === void 0 ? ref.name : void 0;
60
+ };
61
+ /**
62
+ * How a drill's items show: the columns read (the source's record columns, then the line's
63
+ * value and flag fields), their order (by that value, highest first, for an average,
64
+ * percentile, min or max; else the records order, which `sorted` states), the fields that
65
+ * title and badge each item in a list, and the fields the path fixes, which a list leaves out
66
+ * (a table shows every column).
67
+ */
68
+ function itemsShape(model, set, drill, line) {
69
+ const fixed = fixedBy(drill);
70
+ const source = set.source;
71
+ const def = model.sources[source];
72
+ if (def === void 0) return {
73
+ columns: [],
74
+ fixed: []
75
+ };
76
+ const all = recordDimensions(model, source);
77
+ const free = all.filter((n) => !fixed.has(`${source}.${n}`));
78
+ const value = ownName(source, line.value);
79
+ const flag = ownName(source, line.numerator?.flag);
80
+ const title = titleOf(def, free);
81
+ const extra = [
82
+ title,
83
+ value,
84
+ flag
85
+ ].filter((n) => n !== void 0 && !all.includes(n));
86
+ const ranked = line.ranked === true && value !== void 0;
87
+ const badge = badgeOf(def, source, free);
88
+ const order = ranked ? void 0 : orderOf(def, source);
89
+ return {
90
+ columns: [...all, ...extra],
91
+ fixed: all.filter((n) => fixed.has(`${source}.${n}`)).map((n) => `${source}.${n}`),
92
+ ...ranked ? { order: [[value, "desc"]] } : {},
93
+ ...order === void 0 ? {} : { sorted: order },
94
+ ...title === void 0 ? {} : { title: `${source}.${title}` },
95
+ ...badge === void 0 ? {} : { badge }
96
+ };
97
+ }
98
+ export { itemsShape };
@@ -0,0 +1,31 @@
1
+ import { Model, Numeric } from "../../model/types.mjs";
2
+ import { CalcAlias, MeasureAlias, WireQuery } from "../types.mjs";
3
+ import { Drill, DrillCan, DrillSemantics } from "./types.mjs";
4
+ /** The line a drill reads: the one clicked, or the tile's only measure. */
5
+ export declare function drillMeasure(set: WireQuery, drill: Drill): MeasureAlias | CalcAlias | undefined;
6
+ /** What a line's rows are, how its Items read, and whether it lists any. */
7
+ export type LineSemantics = {
8
+ semantics: DrillSemantics;
9
+ items: DrillCan;
10
+ /** The field each item shows as its value: the summed or ranked field, or the distinct one. */
11
+ value?: string;
12
+ /** Items sorted by that value, highest first. */
13
+ ranked?: true;
14
+ /** A percentile's fraction, for the marker row ("90% took less than 4h"). */
15
+ percentile?: number;
16
+ /** When the value is a drill's own field (stored text), how its digits read. */
17
+ stored?: {
18
+ numeric?: Numeric;
19
+ };
20
+ /** A ratio's numerator: its label, and the field that says a row is in it. */
21
+ numerator?: {
22
+ label: string;
23
+ flag?: string;
24
+ };
25
+ /** The line adds up across groups (a count, a sum): a share of the step before means something. */
26
+ additive: boolean;
27
+ /** Its rows can only add to it: a count. A sum's may be negative. */
28
+ counted: boolean;
29
+ };
30
+ /** What each kind of measure's drill shows (Rules, section 2). */
31
+ export declare function lineSemantics(model: Model, set: WireQuery, drill: Drill): LineSemantics;
@@ -0,0 +1,183 @@
1
+ import { DRILL_REASONS } from "../../error/codes.mjs";
2
+ import { parseMemberId, resolveMeasure } from "../../model/member.mjs";
3
+ import { memberLabel } from "../../result/columns.mjs";
4
+ import { canonical } from "../../value/canonical.mjs";
5
+ import { aliasPart, lineAlias } from "../alias.mjs";
6
+ import { operandColumn } from "./operand.mjs";
7
+ import { flagName, setName, valueName } from "./synthetic.mjs";
8
+ // src/query/drill/line.ts
9
+ /** The line a drill reads: the one clicked, or the tile's only measure. */
10
+ function drillMeasure(set, drill) {
11
+ if (drill.measure !== void 0) return lineAlias(drill.measure);
12
+ return set.measures.length === 1 && (set.calc ?? []).length === 0 ? "m1" : void 0;
13
+ }
14
+ /** The line a drill reads, as a measure of the query; none for a formula or an unknown line. */
15
+ function lineMeasure(model, set, drill) {
16
+ const line = drillMeasure(set, drill);
17
+ if (line === void 0) return void 0;
18
+ const part = aliasPart(line);
19
+ if (part.kind !== "measure") return void 0;
20
+ const entry = set.measures[part.index];
21
+ if (entry === void 0) return void 0;
22
+ const def = resolveMeasure(model, set.source, entry.measure);
23
+ const name = parseMemberId(entry.measure)?.name;
24
+ return def === void 0 || name === void 0 ? void 0 : {
25
+ entry,
26
+ def,
27
+ name
28
+ };
29
+ }
30
+ /** The measure whose rows a line reads, with its name: a ratio's are its denominator's. */
31
+ function rowsMeasure(model, source, line) {
32
+ const { def } = line;
33
+ if (def.kind !== "ratio") return line;
34
+ const denominator = model.sources[source]?.measures[def.denominator];
35
+ return denominator === void 0 ? void 0 : {
36
+ def: denominator,
37
+ name: def.denominator
38
+ };
39
+ }
40
+ /** A field of the source by its name, when the model (with a drill's own fields) has it. */
41
+ const field = (model, source, name) => model.sources[source]?.dimensions[name] === void 0 ? void 0 : `${source}.${name}`;
42
+ /** The column a measure reads row by row: a sum's, an average's, a distinct count's. */
43
+ /**
44
+ * The field a measure adds up or ranks, to show: a number field the model shows on its column,
45
+ * else the drill's own field of that column (`dd_value_...`, exact as stored). None when the
46
+ * column is kept back (a sensitive or hidden field reads it).
47
+ */
48
+ function valueField(model, source, m) {
49
+ const { def } = m;
50
+ if (!("of" in def) || typeof def.of !== "string") return void 0;
51
+ return shownOn(model, source, def.of, true) ?? field(model, source, valueName(m.name));
52
+ }
53
+ /**
54
+ * The predicate field "the measure's operand is set" (`dd_set_...`), apart from whether the
55
+ * operand may be shown: the rows an average or a distinct count reads are those, whoever asks.
56
+ */
57
+ const operandSet = (model, source, name) => field(model, source, setName(name));
58
+ /** A field the model shows on a column (a number one, when asked), never time, sensitive or hidden. */
59
+ function shownOn(model, source, column, numberOnly) {
60
+ const dims = model.sources[source]?.dimensions ?? {};
61
+ const shown = Object.entries(dims).find(([name, d]) => !name.startsWith("dd_") && "column" in d && d.column === column && d.kind !== "time" && (!numberOnly || d.kind === "number") && d.sensitive !== true && d.hidden !== true);
62
+ return shown === void 0 ? void 0 : `${source}.${shown[0]}`;
63
+ }
64
+ const off = (code) => ({
65
+ ok: false,
66
+ code,
67
+ reason: DRILL_REASONS[code]
68
+ });
69
+ const ON = { ok: true };
70
+ const NON_NULL = Object.freeze({
71
+ avg: true,
72
+ min: true,
73
+ max: true,
74
+ percentile: true
75
+ });
76
+ const counts = (def) => def.kind === "count" && def.distinct === void 0;
77
+ /** A ratio's semantics: its denominator's rows, each marked when it is also in the numerator. */
78
+ function ratioSemantics(model, source, line) {
79
+ const { def } = line;
80
+ const base = {
81
+ semantics: "ratio",
82
+ additive: false,
83
+ counted: false
84
+ };
85
+ if (def.kind !== "ratio") return {
86
+ ...base,
87
+ items: ON
88
+ };
89
+ const measures = model.sources[source]?.measures;
90
+ const numerator = measures?.[def.numerator];
91
+ if (!rateOfRows(numerator, measures?.[def.denominator])) return {
92
+ ...base,
93
+ items: off("RATIO_NOT_ROWS")
94
+ };
95
+ const label = memberLabel(def.numerator, numerator?.label);
96
+ const flag = field(model, source, flagName(line.name));
97
+ return {
98
+ ...base,
99
+ items: ON,
100
+ numerator: {
101
+ label,
102
+ ...flag === void 0 ? {} : { flag }
103
+ }
104
+ };
105
+ }
106
+ /** A count of rows: no field of its own (a sum, a distinct count) to read per row. */
107
+ const rowCount = (m) => m?.kind === "count" && m.distinct === void 0;
108
+ /**
109
+ * Whether a ratio is a rate of rows (won deals of closed deals): both lines count rows and every
110
+ * numerator row is a denominator row (the denominator's condition is none, or one the numerator's
111
+ * holds too). Only then does listing the denominator's rows, the numerator's marked, explain it.
112
+ */
113
+ function rateOfRows(numerator, denominator) {
114
+ if (!rowCount(numerator) || !rowCount(denominator)) return false;
115
+ const below = denominator.where;
116
+ if (below === void 0) return true;
117
+ const top = numerator.where;
118
+ return (top === void 0 ? [] : "all" in top ? top.all : [top]).some((p) => canonical(p) === canonical(below));
119
+ }
120
+ /** What each kind of measure's drill shows (Rules, section 2). */
121
+ function lineSemantics(model, set, drill) {
122
+ const line = lineMeasure(model, set, drill);
123
+ if (line === void 0) return {
124
+ semantics: "expression",
125
+ items: off("FORMULA_ITEMS"),
126
+ additive: false,
127
+ counted: false
128
+ };
129
+ const { def } = line;
130
+ const additive = def.merge === "sum";
131
+ if ("partitionBy" in def && def.partitionBy !== void 0) return {
132
+ semantics: "rows",
133
+ items: off("SNAPSHOT"),
134
+ additive: false,
135
+ counted: false
136
+ };
137
+ if (def.kind === "ratio") return ratioSemantics(model, set.source, line);
138
+ if (def.kind === "count" && def.distinct !== void 0) return distinctSemantics(model, set.source, def.distinct);
139
+ return {
140
+ ...valueSemantics(model, set.source, line),
141
+ additive,
142
+ counted: counts(def)
143
+ };
144
+ }
145
+ /** A distinct count's semantics: its distinct values, by a field the model shows or its own. */
146
+ function distinctSemantics(model, source, column) {
147
+ const shown = shownOn(model, source, column, false);
148
+ const own = model.sources[source]?.dimensions;
149
+ const dd = Object.entries(own ?? {}).find(([n, d]) => n.startsWith("dd_distinct_") && "column" in d && d.column === column)?.[0];
150
+ const value = shown ?? (dd === void 0 ? void 0 : `${source}.${dd}`);
151
+ const base = {
152
+ semantics: "distinct",
153
+ additive: false,
154
+ counted: false
155
+ };
156
+ return value === void 0 ? {
157
+ ...base,
158
+ items: off("DISTINCT_HIDDEN")
159
+ } : {
160
+ ...base,
161
+ items: ON,
162
+ value
163
+ };
164
+ }
165
+ /** A count's, sum's or ranked measure's semantics: its rows, with the field it reads. */
166
+ function valueSemantics(model, source, line) {
167
+ const { def } = line;
168
+ const value = valueField(model, source, line);
169
+ const nonNull = Object.hasOwn(NON_NULL, def.kind);
170
+ const own = value === `${source}.${valueName(line.name)}`;
171
+ const hidden = operandColumn(def) !== void 0 && value === void 0;
172
+ return {
173
+ semantics: nonNull ? "non-null" : "rows",
174
+ items: hidden ? off("OPERAND_HIDDEN") : ON,
175
+ ...value === void 0 ? {} : { value },
176
+ ...own ? { stored: storedOf(def) } : {},
177
+ ...nonNull && value !== void 0 ? { ranked: true } : {},
178
+ ...def.kind === "percentile" ? { percentile: def.p } : {}
179
+ };
180
+ }
181
+ /** How a measure's own column is stored: its scale, when it keeps money in minor units. */
182
+ const storedOf = (def) => "numeric" in def && def.numeric !== void 0 ? { numeric: def.numeric } : {};
183
+ export { drillMeasure, lineMeasure, lineSemantics, operandSet, rowsMeasure };
@@ -0,0 +1,33 @@
1
+ import { Primitive } from "../../types/primitives.mjs";
2
+ /**
3
+ * Where each source's items open in the host's app, by source: a path or URL template, such as
4
+ * `{ order: "/orders/{id}" }`. `{id}` is the item's id: its key's value for a key of one
5
+ * column, its values as JSON for a compound key. `{key.<column>}` is one value of its key. Each
6
+ * is encoded for a URL. An item whose key is hidden (`records.key: "hide"`, or a key column a
7
+ * sensitive field reads) carries no key and gets no link. Plain data, so a server component,
8
+ * the React UI and an agent share it. Typed by source from the model with `ItemLinksFor<M>`.
9
+ */
10
+ export type ItemLinks = Readonly<Record<string, string>>;
11
+ /** The source names of a model. */
12
+ type SourcesOf<M> = M extends {
13
+ sources: infer S;
14
+ } ? keyof S & string : string;
15
+ /**
16
+ * A link template per source of a model: `L`, the map as written, may name no other source, so
17
+ * a misspelled one does not compile.
18
+ */
19
+ export type ItemLinksFor<M, L = unknown> = Readonly<Partial<Record<SourcesOf<M>, string>>> & { readonly [K in Exclude<keyof L, SourcesOf<M>>]: never; };
20
+ /** The parts a link template may name: `{id}` and `{key.<column>}`. */
21
+ export declare const LINK_PART: RegExp;
22
+ /**
23
+ * What is wrong with a link template for a source with this key, in words; none when it is right.
24
+ * A template starts with "/" or a scheme, and names only {id} and {key.<column>} of that key.
25
+ */
26
+ export declare function linkTemplateIssues(template: string, key: readonly string[]): string[];
27
+ /** The link to one item, or undefined when its source has no template, its key is hidden, or a part is missing. */
28
+ export declare function itemLink(links: ItemLinks | undefined, item: {
29
+ source: string;
30
+ id: string;
31
+ key?: Readonly<Record<string, Primitive>>;
32
+ }): string | undefined;
33
+ export {};
@@ -0,0 +1,31 @@
1
+ // src/query/drill/links.ts
2
+ /** The parts a link template may name: `{id}` and `{key.<column>}`. */
3
+ const LINK_PART = /\{(id|key\.[^{}]+)\}/gu;
4
+ /**
5
+ * What is wrong with a link template for a source with this key, in words; none when it is right.
6
+ * A template starts with "/" or a scheme, and names only {id} and {key.<column>} of that key.
7
+ */
8
+ function linkTemplateIssues(template, key) {
9
+ const issues = [];
10
+ if (!/^(?:\/|[a-z][a-z\d+.-]*:)/iu.test(template)) issues.push(`"${template}": a link starts with "/" or a scheme ("https://").`);
11
+ if (/^\s*(?:javascript|vbscript|data):/iu.test(template)) issues.push(`"${template}": a link cannot run script or carry inline data.`);
12
+ for (const [, part = ""] of template.matchAll(/\{([^{}]*)\}/gu)) {
13
+ const column = part.startsWith("key.") ? part.slice(4) : void 0;
14
+ if (part !== "id" && column === void 0) issues.push(`names {${part}}: a template names {id} or {key.<column>} only.`);
15
+ if (column !== void 0 && !key.includes(column)) issues.push(`names {${part}}, but "${column}" is not a column of the source's key (${key.join(", ")}).`);
16
+ }
17
+ return issues;
18
+ }
19
+ /** The link to one item, or undefined when its source has no template, its key is hidden, or a part is missing. */
20
+ function itemLink(links, item) {
21
+ const template = links?.[item.source];
22
+ if (template === void 0 || item.key === void 0) return void 0;
23
+ let missing = false;
24
+ const link = template.replaceAll(LINK_PART, (_all, part) => {
25
+ const value = part === "id" ? item.id : item.key?.[part.slice(4)];
26
+ if (value === void 0 || value === null) missing = true;
27
+ return encodeURIComponent(String(value ?? ""));
28
+ });
29
+ return missing ? void 0 : link;
30
+ }
31
+ export { LINK_PART, itemLink, linkTemplateIssues };
@@ -0,0 +1,7 @@
1
+ // src/query/drill/operand.ts
2
+ /** The column a measure reads row by row: a sum's or average's, a distinct count's; none for a count of rows or a ratio. */
3
+ function operandColumn(def) {
4
+ if ("of" in def && typeof def.of === "string") return def.of;
5
+ return def.kind === "count" ? def.distinct : void 0;
6
+ }
7
+ export { operandColumn };
@@ -0,0 +1,22 @@
1
+ import { Cell, RefOf, WireQuery } from "../types.mjs";
2
+ import { DrillStep } from "./types.mjs";
3
+ /** Where a part of a formula is read: the drill's own rows, or a scope around them. */
4
+ export type Scope = "row" | RefOf;
5
+ /** The scopes a line reads, through the calcs it reads in turn. */
6
+ export declare function lineScopes(query: WireQuery, id: string, seen?: Set<string>): Set<RefOf>;
7
+ /** The steps a scope keeps: every step for the row and the period before, the time steps for a bucket, none for the total. */
8
+ export declare function scopeSteps(steps: readonly DrillStep[], scope: Scope): DrillStep[];
9
+ /** A query's measures alone: what one scope reads. */
10
+ export declare function measuresOnly(query: WireQuery): WireQuery;
11
+ /**
12
+ * Every line of the tile on a drill, from each scope's measures (in the tile's measure order):
13
+ * its measures as read on the drill's rows, its calcs worked out from the scopes they read.
14
+ */
15
+ export declare function scopedLines(query: WireQuery, cells: {
16
+ row: readonly Cell[];
17
+ } & { [K in RefOf]?: readonly Cell[]; }): Map<string, Cell>;
18
+ /** A formula's parts, each once: the line it reads and the scope it reads it in. */
19
+ export declare function formulaParts(query: WireQuery, id: string): {
20
+ entry: string;
21
+ scope: Scope;
22
+ }[];
@@ -0,0 +1,58 @@
1
+ import { valueRow } from "../../result/calc.mjs";
2
+ import { formulaRefs } from "../formulas.mjs";
3
+ // src/query/drill/scopes.ts
4
+ const calcOf = (query, id) => (query.calc ?? []).find((c) => c.id === id);
5
+ /** The scopes a line reads, through the calcs it reads in turn. */
6
+ function lineScopes(query, id, seen = /* @__PURE__ */ new Set()) {
7
+ const calc = calcOf(query, id);
8
+ if (calc === void 0 || seen.has(id)) return /* @__PURE__ */ new Set();
9
+ seen.add(id);
10
+ const scopes = /* @__PURE__ */ new Set();
11
+ for (const ref of formulaRefs(calc.formula)) {
12
+ if (ref.of !== void 0) scopes.add(ref.of);
13
+ for (const s of lineScopes(query, ref.ref, seen)) scopes.add(s);
14
+ }
15
+ return scopes;
16
+ }
17
+ /** The calcs that read around their row, themselves or through another calc. */
18
+ function aroundCalcs(query) {
19
+ return new Set((query.calc ?? []).filter((c) => lineScopes(query, c.id).size > 0).map((c) => c.id));
20
+ }
21
+ /** The steps a scope keeps: every step for the row and the period before, the time steps for a bucket, none for the total. */
22
+ function scopeSteps(steps, scope) {
23
+ if (scope === "total") return [];
24
+ if (scope === "bucket") return steps.filter((s) => "bucket" in s);
25
+ return [...steps];
26
+ }
27
+ /** A query's measures alone: what one scope reads. */
28
+ function measuresOnly(query) {
29
+ const { calc: _calc, ...rest } = query;
30
+ return rest;
31
+ }
32
+ /**
33
+ * Every line of the tile on a drill, from each scope's measures (in the tile's measure order):
34
+ * its measures as read on the drill's rows, its calcs worked out from the scopes they read.
35
+ */
36
+ function scopedLines(query, cells) {
37
+ const { row, ...refs } = cells;
38
+ const values = valueRow(query, row, refs);
39
+ const ids = [...query.measures.map((m) => m.id), ...(query.calc ?? []).map((c) => c.id)];
40
+ return new Map(ids.map((id, i) => [id, values[i] ?? null]));
41
+ }
42
+ /** A formula's parts, each once: the line it reads and the scope it reads it in. */
43
+ function formulaParts(query, id) {
44
+ const calc = calcOf(query, id);
45
+ if (calc === void 0) return [];
46
+ const parts = formulaRefs(calc.formula).map((r) => ({
47
+ entry: r.ref,
48
+ scope: r.of ?? "row"
49
+ }));
50
+ const seen = /* @__PURE__ */ new Set();
51
+ return parts.filter((p) => {
52
+ const key = `${p.entry} ${p.scope}`;
53
+ if (seen.has(key)) return false;
54
+ seen.add(key);
55
+ return true;
56
+ });
57
+ }
58
+ export { aroundCalcs, formulaParts, lineScopes, measuresOnly, scopeSteps, scopedLines };
@@ -0,0 +1,37 @@
1
+ import { DrillReason } from "../../error/codes.mjs";
2
+ import { ResultCell, ResultColumn, ResultRows } from "../../result/types.mjs";
3
+ import { Span } from "../../time/range.mjs";
4
+ import { Calendar } from "../types.mjs";
5
+ import { Cuts, Selection } from "./types.mjs";
6
+ /** An answer as it was drawn: its columns and rows, its resolved range and its calendar. */
7
+ export type Drawn = {
8
+ columns: readonly ResultColumn[];
9
+ rows: ResultRows;
10
+ span?: Span;
11
+ calendar: Calendar;
12
+ /** The query has a limit of its own with Other: an all-Other row is that limit's Other. */
13
+ limited?: boolean;
14
+ /** What each dimension's own limit kept, from the engine (`Ran.cuts`). */
15
+ cuts?: Cuts;
16
+ /** The answer was cut at the row cap: no kept set read from it is whole. */
17
+ truncated?: boolean;
18
+ /** The search the answer was read under, which its Other keeps. */
19
+ search?: {
20
+ member: string;
21
+ text: string;
22
+ };
23
+ };
24
+ /** A selection, or why a mark does not open. */
25
+ export type Picked = {
26
+ selection: Selection;
27
+ } | {
28
+ refused: DrillReason;
29
+ };
30
+ /**
31
+ * What a click on one row of an answer selects: its time bucket's exact window, the values of
32
+ * the fields it groups by (a total's folded fields left out, so a total selects its row, its
33
+ * column or the whole tile), and Other with the exact groups its limit kept. Refused, with the
34
+ * reason, for a row that cannot drill: a field the answer does not name, or an Other whose
35
+ * kept set is too large or not whole.
36
+ */
37
+ export declare function rowSelection(drawn: Drawn, row: readonly ResultCell[]): Picked;