derive-dashboards 0.5.1 → 0.7.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 (342) hide show
  1. package/README.md +4 -2
  2. package/dist/body.mjs +2 -2
  3. package/dist/charts/data/buckets.d.mts +11 -0
  4. package/dist/charts/data/buckets.mjs +66 -0
  5. package/dist/charts/data/clean.mjs +55 -0
  6. package/dist/charts/data/format.d.mts +19 -0
  7. package/dist/charts/data/format.mjs +174 -0
  8. package/dist/charts/data/input-error.d.mts +5 -0
  9. package/dist/charts/data/input-error.mjs +11 -0
  10. package/dist/charts/data/range.mjs +14 -0
  11. package/dist/charts/data/rows.d.mts +13 -0
  12. package/dist/charts/data/rows.mjs +31 -0
  13. package/dist/charts/data/shares.mjs +55 -0
  14. package/dist/charts/data/types.d.mts +106 -0
  15. package/dist/charts/data/words.d.mts +44 -0
  16. package/dist/charts/data/words.mjs +31 -0
  17. package/dist/charts/describe.mjs +110 -0
  18. package/dist/charts/index.d.mts +34 -0
  19. package/dist/charts/index.mjs +24 -0
  20. package/dist/charts/kinds/area-marks.mjs +120 -0
  21. package/dist/charts/kinds/area.d.mts +23 -0
  22. package/dist/charts/kinds/area.mjs +71 -0
  23. package/dist/charts/kinds/bars-data.d.mts +11 -0
  24. package/dist/charts/kinds/bars-data.mjs +30 -0
  25. package/dist/charts/kinds/bars-layout.mjs +30 -0
  26. package/dist/charts/kinds/bars-marks.mjs +93 -0
  27. package/dist/charts/kinds/bars-words.mjs +56 -0
  28. package/dist/charts/kinds/bars.d.mts +17 -0
  29. package/dist/charts/kinds/bars.mjs +68 -0
  30. package/dist/charts/kinds/columns-data.mjs +116 -0
  31. package/dist/charts/kinds/columns-layout.mjs +29 -0
  32. package/dist/charts/kinds/columns-marks.mjs +200 -0
  33. package/dist/charts/kinds/columns-words.mjs +26 -0
  34. package/dist/charts/kinds/columns.d.mts +13 -0
  35. package/dist/charts/kinds/columns.mjs +80 -0
  36. package/dist/charts/kinds/dumbbell-data.d.mts +22 -0
  37. package/dist/charts/kinds/dumbbell-data.mjs +59 -0
  38. package/dist/charts/kinds/dumbbell-layout.mjs +113 -0
  39. package/dist/charts/kinds/dumbbell-marks.mjs +119 -0
  40. package/dist/charts/kinds/dumbbell-words.d.mts +7 -0
  41. package/dist/charts/kinds/dumbbell-words.mjs +94 -0
  42. package/dist/charts/kinds/dumbbell.d.mts +14 -0
  43. package/dist/charts/kinds/dumbbell.mjs +67 -0
  44. package/dist/charts/kinds/funnel-data.d.mts +11 -0
  45. package/dist/charts/kinds/funnel-data.mjs +70 -0
  46. package/dist/charts/kinds/funnel-layout.mjs +32 -0
  47. package/dist/charts/kinds/funnel-marks.mjs +204 -0
  48. package/dist/charts/kinds/funnel-words.mjs +77 -0
  49. package/dist/charts/kinds/funnel.d.mts +11 -0
  50. package/dist/charts/kinds/funnel.mjs +75 -0
  51. package/dist/charts/kinds/grid-data.d.mts +18 -0
  52. package/dist/charts/kinds/grid-data.mjs +35 -0
  53. package/dist/charts/kinds/grid-layout.mjs +77 -0
  54. package/dist/charts/kinds/grid-marks.mjs +140 -0
  55. package/dist/charts/kinds/grid-time.mjs +41 -0
  56. package/dist/charts/kinds/grid-words.mjs +86 -0
  57. package/dist/charts/kinds/grid.d.mts +22 -0
  58. package/dist/charts/kinds/grid.mjs +55 -0
  59. package/dist/charts/kinds/histogram-data.mjs +142 -0
  60. package/dist/charts/kinds/histogram-layout.mjs +144 -0
  61. package/dist/charts/kinds/histogram-marks.mjs +110 -0
  62. package/dist/charts/kinds/histogram-words.mjs +104 -0
  63. package/dist/charts/kinds/histogram.d.mts +15 -0
  64. package/dist/charts/kinds/histogram.mjs +47 -0
  65. package/dist/charts/kinds/line-marks.mjs +36 -0
  66. package/dist/charts/kinds/line.d.mts +17 -0
  67. package/dist/charts/kinds/line.mjs +52 -0
  68. package/dist/charts/kinds/multiples-grid.mjs +107 -0
  69. package/dist/charts/kinds/multiples-head.mjs +44 -0
  70. package/dist/charts/kinds/multiples-layout.mjs +159 -0
  71. package/dist/charts/kinds/multiples-marks.mjs +95 -0
  72. package/dist/charts/kinds/multiples-words.mjs +110 -0
  73. package/dist/charts/kinds/multiples.d.mts +26 -0
  74. package/dist/charts/kinds/multiples.mjs +42 -0
  75. package/dist/charts/kinds/row-chart.mjs +112 -0
  76. package/dist/charts/kinds/row-marks.mjs +121 -0
  77. package/dist/charts/kinds/scatter-data.d.mts +18 -0
  78. package/dist/charts/kinds/scatter-data.mjs +123 -0
  79. package/dist/charts/kinds/scatter-layout.mjs +189 -0
  80. package/dist/charts/kinds/scatter-marks.mjs +149 -0
  81. package/dist/charts/kinds/scatter-words.mjs +80 -0
  82. package/dist/charts/kinds/scatter.d.mts +21 -0
  83. package/dist/charts/kinds/scatter.mjs +72 -0
  84. package/dist/charts/kinds/stat-data.mjs +91 -0
  85. package/dist/charts/kinds/stat-layout.mjs +108 -0
  86. package/dist/charts/kinds/stat-marks.mjs +85 -0
  87. package/dist/charts/kinds/stat-words.mjs +57 -0
  88. package/dist/charts/kinds/stat.d.mts +28 -0
  89. package/dist/charts/kinds/stat.mjs +35 -0
  90. package/dist/charts/kinds/time-chart.mjs +74 -0
  91. package/dist/charts/kinds/time-frame.mjs +113 -0
  92. package/dist/charts/kinds/time-notes.mjs +36 -0
  93. package/dist/charts/kinds/time-plan.d.mts +8 -0
  94. package/dist/charts/kinds/time-plan.mjs +57 -0
  95. package/dist/charts/kinds/time-plot.mjs +56 -0
  96. package/dist/charts/kinds/time-stops.mjs +56 -0
  97. package/dist/charts/kinds/value-plot.mjs +33 -0
  98. package/dist/charts/kinds/waterfall-data.d.mts +7 -0
  99. package/dist/charts/kinds/waterfall-data.mjs +71 -0
  100. package/dist/charts/kinds/waterfall-layout.mjs +38 -0
  101. package/dist/charts/kinds/waterfall-marks.mjs +82 -0
  102. package/dist/charts/kinds/waterfall-words.mjs +118 -0
  103. package/dist/charts/kinds/waterfall.d.mts +17 -0
  104. package/dist/charts/kinds/waterfall.mjs +66 -0
  105. package/dist/charts/layout/boxes.mjs +28 -0
  106. package/dist/charts/layout/dodge.mjs +75 -0
  107. package/dist/charts/layout/extent.mjs +25 -0
  108. package/dist/charts/layout/frame.mjs +97 -0
  109. package/dist/charts/layout/place-labels.mjs +101 -0
  110. package/dist/charts/layout/stack.mjs +31 -0
  111. package/dist/charts/marks/axes.mjs +137 -0
  112. package/dist/charts/marks/dot.mjs +31 -0
  113. package/dist/charts/marks/end-labels.mjs +124 -0
  114. package/dist/charts/marks/legend.mjs +141 -0
  115. package/dist/charts/marks/lines.d.mts +2 -0
  116. package/dist/charts/marks/lines.mjs +38 -0
  117. package/dist/charts/marks/lit.d.mts +3 -0
  118. package/dist/charts/marks/lit.mjs +63 -0
  119. package/dist/charts/marks/more.mjs +18 -0
  120. package/dist/charts/marks/notes.mjs +253 -0
  121. package/dist/charts/marks/series-line.mjs +110 -0
  122. package/dist/charts/marks/thin.mjs +138 -0
  123. package/dist/charts/marks/x-axis.mjs +32 -0
  124. package/dist/charts/scale/calendar.mjs +174 -0
  125. package/dist/charts/scale/time-ticks.mjs +154 -0
  126. package/dist/charts/scale/time.mjs +33 -0
  127. package/dist/charts/scale/value.mjs +161 -0
  128. package/dist/charts/scene/defs.mjs +33 -0
  129. package/dist/charts/scene/markup.mjs +35 -0
  130. package/dist/charts/scene/nearest.d.mts +11 -0
  131. package/dist/charts/scene/nearest.mjs +49 -0
  132. package/dist/charts/scene/paint.d.mts +12 -0
  133. package/dist/charts/scene/paint.mjs +13 -0
  134. package/dist/charts/scene/svg.d.mts +18 -0
  135. package/dist/charts/scene/svg.mjs +185 -0
  136. package/dist/charts/scene/types.d.mts +177 -0
  137. package/dist/charts/text/measure.d.mts +9 -0
  138. package/dist/charts/text/measure.mjs +123 -0
  139. package/dist/charts/theme.d.mts +47 -0
  140. package/dist/charts/theme.mjs +239 -0
  141. package/dist/charts-react/Chart.d.mts +91 -0
  142. package/dist/charts-react/Chart.mjs +166 -0
  143. package/dist/charts-react/Overlay.mjs +171 -0
  144. package/dist/charts-react/Picture.mjs +22 -0
  145. package/dist/charts-react/Reader.mjs +147 -0
  146. package/dist/charts-react/bucket-names.mjs +29 -0
  147. package/dist/charts-react/chart-unlayered.css +1 -0
  148. package/dist/charts-react/chart-unlayered.css.d.ts +1 -0
  149. package/dist/charts-react/chart.css +1 -0
  150. package/dist/charts-react/chart.css.d.ts +1 -0
  151. package/dist/charts-react/events.mjs +72 -0
  152. package/dist/charts-react/exact-sum.mjs +24 -0
  153. package/dist/charts-react/from-answer.mjs +185 -0
  154. package/dist/charts-react/index.d.mts +3 -0
  155. package/dist/charts-react/index.mjs +4 -0
  156. package/dist/charts-react/keys.mjs +117 -0
  157. package/dist/charts-react/opens.mjs +28 -0
  158. package/dist/charts-react/plan-bars.mjs +95 -0
  159. package/dist/charts-react/plan-funnel.mjs +120 -0
  160. package/dist/charts-react/plan-grid.mjs +121 -0
  161. package/dist/charts-react/plan-parts.d.mts +2 -0
  162. package/dist/charts-react/plan-parts.mjs +30 -0
  163. package/dist/charts-react/plan-time.mjs +84 -0
  164. package/dist/charts-react/plan.d.mts +3 -0
  165. package/dist/charts-react/plan.mjs +37 -0
  166. package/dist/charts-react/point-keys.mjs +22 -0
  167. package/dist/charts-react/pointer.mjs +99 -0
  168. package/dist/charts-react/reader-page.d.mts +8 -0
  169. package/dist/charts-react/reader-page.mjs +116 -0
  170. package/dist/charts-react/tiles.d.mts +24 -0
  171. package/dist/charts-react/tiles.mjs +142 -0
  172. package/dist/charts-react/tip-place.mjs +107 -0
  173. package/dist/charts-react/tip-room.mjs +31 -0
  174. package/dist/charts-react/useClientLayoutEffect.mjs +8 -0
  175. package/dist/charts-react/useScene.mjs +76 -0
  176. package/dist/charts-react/useSize.mjs +44 -0
  177. package/dist/charts-react/useStop.mjs +68 -0
  178. package/dist/core/conformance/memory/aggregate.mjs +2 -1
  179. package/dist/core/conformance/memory/rows.mjs +1 -1
  180. package/dist/core/conformance/memory/source.mjs +3 -2
  181. package/dist/core/document/display-comparisons.mjs +49 -0
  182. package/dist/core/document/display-entries.mjs +2 -1
  183. package/dist/core/document/display-validation.d.mts +12 -0
  184. package/dist/core/document/display-validation.mjs +56 -0
  185. package/dist/core/document/display.d.mts +27 -12
  186. package/dist/core/document/display.mjs +40 -49
  187. package/dist/core/document/view-layout.mjs +16 -0
  188. package/dist/core/engine/access.mjs +4 -2
  189. package/dist/core/engine/context.mjs +5 -7
  190. package/dist/core/engine/custom/cells.mjs +1 -1
  191. package/dist/core/engine/custom/records.mjs +2 -1
  192. package/dist/core/engine/dialect.d.mts +2 -0
  193. package/dist/core/engine/index.mjs +1 -1
  194. package/dist/core/engine/levels.mjs +33 -1
  195. package/dist/core/engine/plan.d.mts +2 -0
  196. package/dist/core/engine/postgres.mjs +1 -0
  197. package/dist/core/engine/rank.mjs +1 -1
  198. package/dist/core/engine/reader.d.mts +4 -0
  199. package/dist/core/engine/sql-partition.mjs +45 -0
  200. package/dist/core/engine/sql-reads.mjs +4 -1
  201. package/dist/core/engine/statement.mjs +4 -4
  202. package/dist/core/engine/version.d.mts +1 -1
  203. package/dist/core/engine/version.mjs +1 -1
  204. package/dist/core/error/codes.d.mts +1 -1
  205. package/dist/core/error/codes.mjs +1 -1
  206. package/dist/core/exact/decimal.d.mts +1 -4
  207. package/dist/core/exact/decimal.mjs +1 -14
  208. package/dist/core/exact/text.d.mts +5 -0
  209. package/dist/core/exact/text.mjs +19 -0
  210. package/dist/core/index.d.mts +9 -6
  211. package/dist/core/index.mjs +11 -8
  212. package/dist/core/model/types.d.mts +2 -0
  213. package/dist/core/model/validate/fields.mjs +1 -1
  214. package/dist/core/model/validate/known-members.mjs +2 -0
  215. package/dist/core/model/validate/shape.mjs +5 -1
  216. package/dist/core/oracle/visibility.mjs +2 -2
  217. package/dist/core/policy/bind.mjs +29 -1
  218. package/dist/core/query/drill/compose.d.mts +2 -0
  219. package/dist/core/query/drill/compose.mjs +1 -1
  220. package/dist/core/query/drill/synthetic.mjs +2 -1
  221. package/dist/core/query/drill/types.d.mts +7 -0
  222. package/dist/core/query/drill/types.mjs +3 -1
  223. package/dist/core/result/number.mjs +2 -1
  224. package/dist/core/result/time-axis.mjs +2 -1
  225. package/dist/core/schema/answers.d.mts +1176 -362
  226. package/dist/core/schema/commands.mjs +2 -1
  227. package/dist/core/schema/document.mjs +27 -2
  228. package/dist/core/schema/drill-answers.mjs +19 -1
  229. package/dist/core/schema/drill.d.mts +21 -6
  230. package/dist/core/schema/drill.mjs +7 -1
  231. package/dist/core/schema/index.d.mts +2 -1
  232. package/dist/core/schema/index.mjs +2 -1
  233. package/dist/core/schema/null-ops.d.mts +6 -0
  234. package/dist/core/schema/null-ops.mjs +18 -0
  235. package/dist/core/schema/query.mjs +30 -4
  236. package/dist/core/schema/tools.mjs +13 -0
  237. package/dist/core/schema/union-error.mjs +38 -0
  238. package/dist/core/time/bucket.mjs +2 -1
  239. package/dist/core/time/index.d.mts +3 -2
  240. package/dist/core/time/instant.d.mts +1 -2
  241. package/dist/core/time/instant.mjs +2 -30
  242. package/dist/core/time/range.mjs +2 -1
  243. package/dist/core/time/stored.mjs +2 -1
  244. package/dist/core/time/text-time.d.mts +10 -0
  245. package/dist/core/time/text-time.mjs +80 -0
  246. package/dist/core/types/api.d.mts +1 -1
  247. package/dist/core/types/api.mjs +1 -1
  248. package/dist/core/types/drill-api.d.mts +22 -2
  249. package/dist/dashboard-documents.d.mts +8 -0
  250. package/dist/dashboard-documents.mjs +52 -0
  251. package/dist/drill-access.mjs +40 -3
  252. package/dist/drill-comparison.mjs +71 -0
  253. package/dist/drill-crumbs.mjs +21 -2
  254. package/dist/drill-group-seal.mjs +13 -0
  255. package/dist/drill-open.mjs +7 -1
  256. package/dist/drill-seal.mjs +4 -6
  257. package/dist/drill-views.mjs +5 -13
  258. package/dist/drill.mjs +28 -58
  259. package/dist/editing.mjs +1 -1
  260. package/dist/endpoints/drill.mjs +2 -3
  261. package/dist/endpoints/index.d.mts +20 -0
  262. package/dist/index.d.mts +2 -1
  263. package/dist/index.mjs +6 -27
  264. package/dist/llms.txt +1 -1
  265. package/dist/react/Cell.mjs +2 -2
  266. package/dist/react/DashboardList.mjs +3 -3
  267. package/dist/react/Editing.mjs +3 -3
  268. package/dist/react/Header.mjs +2 -2
  269. package/dist/react/History.mjs +3 -3
  270. package/dist/react/Parts.mjs +2 -2
  271. package/dist/react/RowBody.d.mts +2 -4
  272. package/dist/react/RowBody.mjs +14 -39
  273. package/dist/react/Tile.mjs +4 -5
  274. package/dist/react/builder/FilterEditor.mjs +2 -2
  275. package/dist/react/builder/Picker.mjs +3 -3
  276. package/dist/react/builder/RangeEditor.mjs +3 -3
  277. package/dist/react/builder/Time.mjs +3 -3
  278. package/dist/react/builder/Values.mjs +2 -2
  279. package/dist/react/builder/WidgetBuilder.mjs +2 -2
  280. package/dist/react/digits.mjs +1 -1
  281. package/dist/react/drill/Bars.mjs +34 -38
  282. package/dist/react/drill/Comparison.mjs +204 -0
  283. package/dist/react/drill/Controls.mjs +8 -12
  284. package/dist/react/drill/DrillDrawer.mjs +42 -0
  285. package/dist/react/drill/DrillPanel.mjs +61 -41
  286. package/dist/react/drill/Header.mjs +65 -35
  287. package/dist/react/drill/ItemLink.mjs +40 -0
  288. package/dist/react/drill/Items.d.mts +2 -1
  289. package/dist/react/drill/Items.mjs +126 -99
  290. package/dist/react/drill/ItemsBody.mjs +38 -0
  291. package/dist/react/drill/ItemsFoot.mjs +24 -19
  292. package/dist/react/drill/Notes.mjs +23 -13
  293. package/dist/react/drill/PanelBody.mjs +7 -25
  294. package/dist/react/drill/RecordRow.mjs +47 -0
  295. package/dist/react/drill/Trend.mjs +186 -0
  296. package/dist/react/drill/board.mjs +21 -11
  297. package/dist/react/drill/drawer-context.mjs +5 -0
  298. package/dist/react/drill/item-parts.mjs +53 -35
  299. package/dist/react/drill/item-type.d.mts +2 -2
  300. package/dist/react/drill/lazy.d.mts +1 -4
  301. package/dist/react/drill/lazy.mjs +29 -11
  302. package/dist/react/drill/panel-focus.mjs +18 -7
  303. package/dist/react/drill/props.d.mts +7 -1
  304. package/dist/react/drill/props.mjs +39 -8
  305. package/dist/react/drill/record-page.mjs +61 -0
  306. package/dist/react/drill/state.mjs +17 -2
  307. package/dist/react/drill/trend-touch.mjs +33 -0
  308. package/dist/react/drill/useDrill.d.mts +3 -3
  309. package/dist/react/drill/useDrill.mjs +35 -15
  310. package/dist/react/drill/words.d.mts +14 -0
  311. package/dist/react/drill/words.mjs +20 -8
  312. package/dist/react/english.d.mts +4 -1
  313. package/dist/react/english.mjs +17 -2
  314. package/dist/react/filters/chip.mjs +2 -2
  315. package/dist/react/filters/menu-search.mjs +5 -5
  316. package/dist/react/filters/menu.mjs +2 -2
  317. package/dist/react/filters/number.mjs +2 -2
  318. package/dist/react/filters/operator.mjs +2 -2
  319. package/dist/react/filters/phone.mjs +2 -2
  320. package/dist/react/filters/values.mjs +4 -4
  321. package/dist/react/format-time.d.mts +2 -1
  322. package/dist/react/format-time.mjs +42 -34
  323. package/dist/react/format.mjs +15 -3
  324. package/dist/react/index.d.mts +4 -3
  325. package/dist/react/index.mjs +4 -3
  326. package/dist/react/messages.d.mts +23 -2
  327. package/dist/react/renderers/entries.d.mts +11 -0
  328. package/dist/react/renderers/list.mjs +8 -10
  329. package/dist/react/renderers/table-cells.mjs +38 -9
  330. package/dist/react/renderers/table-measure.mjs +2 -0
  331. package/dist/react/renderers/table-row.mjs +64 -7
  332. package/dist/react/renderers/table-sort.mjs +2 -8
  333. package/dist/react/renderers/table.mjs +16 -15
  334. package/dist/react/series.mjs +8 -3
  335. package/dist/react/theme-unlayered.css +1 -3144
  336. package/dist/react/theme.css +1 -3146
  337. package/dist/recharts/parts.mjs +1 -1
  338. package/dist/skills/derive-dashboards/SKILL.md +10 -5
  339. package/dist/store/apply.mjs +2 -2
  340. package/dist/store/editor.mjs +2 -2
  341. package/dist/store/writer.mjs +2 -2
  342. package/package.json +27 -2
@@ -1,4 +1,5 @@
1
1
  import { controlSchema as control, displaySchema, lockEntrySchema, placeSchema, storedQuerySchema as storedQuery, widgetSchema } from "./document.mjs";
2
+ import { withNullOpValues } from "./null-ops.mjs";
2
3
  import { idSchema, name } from "./query.mjs";
3
4
  import { z } from "zod";
4
5
  // src/schema/commands.ts
@@ -112,7 +113,7 @@ const commandBodySchema = z.custom((v) => typeof v === "object" && v !== null &&
112
113
  }).success);
113
114
  /** Checks a batch of commands from a client: 1 to 100, each exactly one known kind. */
114
115
  function parseCommands(input) {
115
- const result = z.array(commandSchema).min(1).max(100).safeParse(input);
116
+ const result = z.array(commandSchema).min(1).max(100).safeParse(withNullOpValues(input));
116
117
  if (result.success) return {
117
118
  ok: true,
118
119
  commands: result.data
@@ -1,7 +1,32 @@
1
+ import { withNullOpValues } from "./null-ops.mjs";
1
2
  import { grain, name, op, primitive, range, viewerRef } from "./query.mjs";
3
+ import { unionError } from "./union-error.mjs";
2
4
  import { z } from "zod";
3
5
  // src/schema/document.ts
4
6
  const nodeId = { id: name };
7
+ /** The keys that tell each filter node apart, in the union's order. */
8
+ const FILTER_SHAPES = [
9
+ ["all"],
10
+ ["any"],
11
+ ["not"],
12
+ [
13
+ "member",
14
+ "op",
15
+ "values"
16
+ ],
17
+ [
18
+ "member",
19
+ "op",
20
+ "viewer"
21
+ ],
22
+ [
23
+ "member",
24
+ "op",
25
+ "variable"
26
+ ],
27
+ ["some"],
28
+ ["none"]
29
+ ];
5
30
  const storedFilter = z.lazy(() => z.union([
6
31
  z.looseObject({
7
32
  ...nodeId,
@@ -47,7 +72,7 @@ const storedFilter = z.lazy(() => z.union([
47
72
  where: storedFilter
48
73
  })
49
74
  })
50
- ]));
75
+ ], { error: unionError(FILTER_SHAPES) }));
51
76
  const storedFormula = z.lazy(() => z.union([
52
77
  z.looseObject({
53
78
  ref: name,
@@ -199,7 +224,7 @@ const documentSchema = z.looseObject({
199
224
  });
200
225
  /** Checks a document at the current spec version. Every problem is reported, with its path. */
201
226
  function parseDocument(input) {
202
- const result = documentSchema.safeParse(input);
227
+ const result = documentSchema.safeParse(withNullOpValues(input));
203
228
  if (result.success) return {
204
229
  ok: true,
205
230
  doc: result.data
@@ -80,6 +80,7 @@ const grouped = z.looseObject({
80
80
  grain: grain.exactOptional(),
81
81
  range: range.exactOptional(),
82
82
  grains: z.array(grain).exactOptional(),
83
+ throughNow: z.boolean().exactOptional(),
83
84
  rankedBy: z.string().exactOptional(),
84
85
  change: z.literal(true).exactOptional(),
85
86
  searchable: z.literal(true).exactOptional(),
@@ -165,6 +166,12 @@ const crumbPart = z.looseObject({
165
166
  previous: z.literal(true).exactOptional()
166
167
  });
167
168
  const crumb = crumbPart.extend({ parts: z.array(crumbPart).exactOptional() });
169
+ const comparison = z.looseObject({
170
+ by: z.literal("comparison"),
171
+ drill: sealedAnswer,
172
+ thenBy: field.exactOptional(),
173
+ omitted: z.literal(true).exactOptional()
174
+ });
168
175
  /** A drill's answer: its summary, breadcrumbs, normalized state and view. */
169
176
  const drillAnswerSchema = z.looseObject({
170
177
  summary: summary.exactOptional(),
@@ -173,7 +180,18 @@ const drillAnswerSchema = z.looseObject({
173
180
  view: z.union([
174
181
  grouped,
175
182
  items,
176
- explanation
183
+ explanation,
184
+ comparison.extend({
185
+ foreign: z.never().exactOptional(),
186
+ answer: grouped.shape.answer
187
+ }),
188
+ comparison.extend({
189
+ foreign: z.literal(true),
190
+ answer: grouped.shape.answer.extend({ receipt: receipt.extend({
191
+ queryHash: z.never().exactOptional(),
192
+ filter: z.never().exactOptional()
193
+ }) })
194
+ })
177
195
  ])
178
196
  });
179
197
  export { drillAnswerSchema, queryDrill };
@@ -3,10 +3,14 @@ import { FormulaNode } from "../query/types.mjs";
3
3
  import "../index.mjs";
4
4
  import { z } from "zod";
5
5
  /** What a drill shows. */
6
- export declare const drillViewSchema: z.ZodUnion<readonly [z.ZodObject<{
6
+ export declare const drillViewSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
7
7
  by: z.ZodLiteral<"breakdown">;
8
8
  member: z.ZodExactOptional<z.ZodString>;
9
9
  search: z.ZodExactOptional<z.ZodString>;
10
+ }, z.core.$strict>, z.ZodObject<{
11
+ by: z.ZodLiteral<"comparison">;
12
+ member: z.ZodString;
13
+ thenBy: z.ZodExactOptional<z.ZodString>;
10
14
  }, z.core.$strict>, z.ZodObject<{
11
15
  by: z.ZodLiteral<"trend">;
12
16
  grain: z.ZodExactOptional<z.ZodEnum<{
@@ -19,10 +23,11 @@ export declare const drillViewSchema: z.ZodUnion<readonly [z.ZodObject<{
19
23
  }>>;
20
24
  }, z.core.$strict>, z.ZodObject<{
21
25
  by: z.ZodLiteral<"items">;
26
+ fields: z.ZodExactOptional<z.ZodLiteral<true>>;
22
27
  numerator: z.ZodExactOptional<z.ZodLiteral<true>>;
23
28
  }, z.core.$strict>, z.ZodObject<{
24
29
  by: z.ZodLiteral<"explanation">;
25
- }, z.core.$strict>]>;
30
+ }, z.core.$strict>], "by">;
26
31
  /** A drill as plain data: its origin, line, sealed execution and path, and the view open. */
27
32
  export declare const drillStateSchema: z.ZodObject<{
28
33
  origin: z.ZodUnion<readonly [z.ZodObject<{
@@ -153,10 +158,14 @@ export declare const drillStateSchema: z.ZodObject<{
153
158
  entry: z.ZodExactOptional<z.ZodString>;
154
159
  execution: z.ZodString;
155
160
  path: z.ZodReadonly<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodString]>>>;
156
- view: z.ZodUnion<readonly [z.ZodObject<{
161
+ view: z.ZodDiscriminatedUnion<[z.ZodObject<{
157
162
  by: z.ZodLiteral<"breakdown">;
158
163
  member: z.ZodExactOptional<z.ZodString>;
159
164
  search: z.ZodExactOptional<z.ZodString>;
165
+ }, z.core.$strict>, z.ZodObject<{
166
+ by: z.ZodLiteral<"comparison">;
167
+ member: z.ZodString;
168
+ thenBy: z.ZodExactOptional<z.ZodString>;
160
169
  }, z.core.$strict>, z.ZodObject<{
161
170
  by: z.ZodLiteral<"trend">;
162
171
  grain: z.ZodExactOptional<z.ZodEnum<{
@@ -169,14 +178,19 @@ export declare const drillStateSchema: z.ZodObject<{
169
178
  }>>;
170
179
  }, z.core.$strict>, z.ZodObject<{
171
180
  by: z.ZodLiteral<"items">;
181
+ fields: z.ZodExactOptional<z.ZodLiteral<true>>;
172
182
  numerator: z.ZodExactOptional<z.ZodLiteral<true>>;
173
183
  }, z.core.$strict>, z.ZodObject<{
174
184
  by: z.ZodLiteral<"explanation">;
175
- }, z.core.$strict>]>;
176
- views: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
185
+ }, z.core.$strict>], "by">;
186
+ views: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
177
187
  by: z.ZodLiteral<"breakdown">;
178
188
  member: z.ZodExactOptional<z.ZodString>;
179
189
  search: z.ZodExactOptional<z.ZodString>;
190
+ }, z.core.$strict>, z.ZodObject<{
191
+ by: z.ZodLiteral<"comparison">;
192
+ member: z.ZodString;
193
+ thenBy: z.ZodExactOptional<z.ZodString>;
180
194
  }, z.core.$strict>, z.ZodObject<{
181
195
  by: z.ZodLiteral<"trend">;
182
196
  grain: z.ZodExactOptional<z.ZodEnum<{
@@ -189,10 +203,11 @@ export declare const drillStateSchema: z.ZodObject<{
189
203
  }>>;
190
204
  }, z.core.$strict>, z.ZodObject<{
191
205
  by: z.ZodLiteral<"items">;
206
+ fields: z.ZodExactOptional<z.ZodLiteral<true>>;
192
207
  numerator: z.ZodExactOptional<z.ZodLiteral<true>>;
193
208
  }, z.core.$strict>, z.ZodObject<{
194
209
  by: z.ZodLiteral<"explanation">;
195
- }, z.core.$strict>]>>>>;
210
+ }, z.core.$strict>], "by">>>>;
196
211
  }, z.core.$strict>;
197
212
  /** What a sealed selection opens to, checked again after it opens. */
198
213
  export declare const selectionSchema: z.ZodObject<{
@@ -4,18 +4,24 @@ import { grain, name, primitive, wireQuerySchema } from "./query.mjs";
4
4
  import { z } from "zod";
5
5
  // src/schema/drill.ts
6
6
  /** What a drill shows. */
7
- const drillViewSchema = z.union([
7
+ const drillViewSchema = z.discriminatedUnion("by", [
8
8
  z.strictObject({
9
9
  by: z.literal("breakdown"),
10
10
  member: name.exactOptional(),
11
11
  search: z.string().max(200).exactOptional()
12
12
  }),
13
+ z.strictObject({
14
+ by: z.literal("comparison"),
15
+ member: name,
16
+ thenBy: name.exactOptional()
17
+ }),
13
18
  z.strictObject({
14
19
  by: z.literal("trend"),
15
20
  grain: grain.exactOptional()
16
21
  }),
17
22
  z.strictObject({
18
23
  by: z.literal("items"),
24
+ fields: z.literal(true).exactOptional(),
19
25
  numerator: z.literal(true).exactOptional()
20
26
  }),
21
27
  z.strictObject({ by: z.literal("explanation") })
@@ -5,8 +5,9 @@ import { ParsedCommands, commandSchema, parseCommands } from "./commands.mjs";
5
5
  import { customReadSchemas, groupedReadSchema, recordsReadSchema } from "./custom.mjs";
6
6
  import { ParsedDocument, documentSchema, parseDocument } from "./document.mjs";
7
7
  import { drillStateSchema, drillViewSchema, pinnedSchema, selectionSchema } from "./drill.mjs";
8
+ import { withNullOpValues } from "./null-ops.mjs";
8
9
  import { picksSchema } from "./picks.mjs";
9
10
  import { ParsedQuery, parseWireQuery, wireQuerySchema, wireQueryShape } from "./query.mjs";
10
11
  import { JsonSchema, jsonSchema, toolSchemas } from "./tools.mjs";
11
12
  import { decodeView } from "./view.mjs";
12
- export { type AnswerSchemas, DOCUMENT_UPGRADES, type JsonSchema, type Loaded, type ParsedCommands, type ParsedDocument, type ParsedQuery, SPEC_VERSION, type Upgrade, answerSchemas, commandSchema, customReadSchemas, decodeView, documentSchema, drillStateSchema, drillViewSchema, groupedReadSchema, jsonSchema, loadDocument, parseCommands, parseDocument, parseWireQuery, picksSchema, pinnedSchema, positional, recordsReadSchema, selectionSchema, tileLineSchema, toolSchemas, wireQuerySchema, wireQueryShape };
13
+ export { type AnswerSchemas, DOCUMENT_UPGRADES, type JsonSchema, type Loaded, type ParsedCommands, type ParsedDocument, type ParsedQuery, SPEC_VERSION, type Upgrade, answerSchemas, commandSchema, customReadSchemas, decodeView, documentSchema, drillStateSchema, drillViewSchema, groupedReadSchema, jsonSchema, loadDocument, parseCommands, parseDocument, parseWireQuery, picksSchema, pinnedSchema, positional, recordsReadSchema, selectionSchema, tileLineSchema, toolSchemas, wireQuerySchema, wireQueryShape, withNullOpValues };
@@ -5,8 +5,9 @@ import { commandSchema, parseCommands } from "./commands.mjs";
5
5
  import { customReadSchemas, groupedReadSchema, recordsReadSchema } from "./custom.mjs";
6
6
  import { documentSchema, parseDocument } from "./document.mjs";
7
7
  import { drillStateSchema, drillViewSchema, pinnedSchema, selectionSchema } from "./drill.mjs";
8
+ import { withNullOpValues } from "./null-ops.mjs";
8
9
  import { picksSchema } from "./picks.mjs";
9
10
  import { parseWireQuery, wireQuerySchema, wireQueryShape } from "./query.mjs";
10
11
  import { jsonSchema, toolSchemas } from "./tools.mjs";
11
12
  import { decodeView } from "./view.mjs";
12
- export { DOCUMENT_UPGRADES, SPEC_VERSION, answerSchemas, commandSchema, customReadSchemas, decodeView, documentSchema, drillStateSchema, drillViewSchema, groupedReadSchema, jsonSchema, loadDocument, parseCommands, parseDocument, parseWireQuery, picksSchema, pinnedSchema, positional, recordsReadSchema, selectionSchema, tileLineSchema, toolSchemas, wireQuerySchema, wireQueryShape };
13
+ export { DOCUMENT_UPGRADES, SPEC_VERSION, answerSchemas, commandSchema, customReadSchemas, decodeView, documentSchema, drillStateSchema, drillViewSchema, groupedReadSchema, jsonSchema, loadDocument, parseCommands, parseDocument, parseWireQuery, picksSchema, pinnedSchema, positional, recordsReadSchema, selectionSchema, tileLineSchema, toolSchemas, wireQuerySchema, wireQueryShape, withNullOpValues };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * "is set" and "is not set" read no values, so a test with either that leaves `values` out (and
3
+ * names no viewer or variable) is given an empty list before it is checked. Everything else is
4
+ * returned as it came.
5
+ */
6
+ export declare function withNullOpValues(input: unknown): unknown;
@@ -0,0 +1,18 @@
1
+ import { NULL_OPS } from "../query/filter.mjs";
2
+ // src/schema/null-ops.ts
3
+ const isNullOp = (op) => NULL_OPS.some((known) => known === op);
4
+ /**
5
+ * "is set" and "is not set" read no values, so a test with either that leaves `values` out (and
6
+ * names no viewer or variable) is given an empty list before it is checked. Everything else is
7
+ * returned as it came.
8
+ */
9
+ function withNullOpValues(input) {
10
+ if (Array.isArray(input)) return input.map((item) => withNullOpValues(item));
11
+ if (typeof input !== "object" || input === null) return input;
12
+ const out = Object.fromEntries(Object.entries(input).map(([key, value]) => [key, withNullOpValues(value)]));
13
+ return isNullOp(out["op"]) && !("values" in out || "viewer" in out || "variable" in out) ? {
14
+ ...out,
15
+ values: []
16
+ } : out;
17
+ }
18
+ export { withNullOpValues };
@@ -1,6 +1,9 @@
1
1
  import { NEGATIVE_OPS, NULL_OPS, POSITIVE_OPS } from "../query/filter.mjs";
2
- import { parseDate, parseTextTime } from "../time/instant.mjs";
2
+ import { parseTextTime } from "../time/text-time.mjs";
3
+ import { parseDate } from "../time/instant.mjs";
3
4
  import { checkPositions } from "./aliases.mjs";
5
+ import { withNullOpValues } from "./null-ops.mjs";
6
+ import { unionError } from "./union-error.mjs";
4
7
  import { z } from "zod";
5
8
  // src/schema/query.ts
6
9
  /**
@@ -47,7 +50,23 @@ const leaf = z.union([
47
50
  op,
48
51
  variable: name
49
52
  })
50
- ]);
53
+ ], { error: unionError([
54
+ [
55
+ "member",
56
+ "op",
57
+ "values"
58
+ ],
59
+ [
60
+ "member",
61
+ "op",
62
+ "viewer"
63
+ ],
64
+ [
65
+ "member",
66
+ "op",
67
+ "variable"
68
+ ]
69
+ ]) });
51
70
  const filter = z.lazy(() => z.union([
52
71
  z.strictObject({ all: z.array(filter).max(100).readonly() }),
53
72
  z.strictObject({ any: z.array(filter).max(100).readonly() }),
@@ -61,7 +80,14 @@ const filter = z.lazy(() => z.union([
61
80
  join: name,
62
81
  where: filter
63
82
  }) })
64
- ]));
83
+ ], { error: unionError([
84
+ ["all"],
85
+ ["any"],
86
+ ["not"],
87
+ ["member", "op"],
88
+ ["some"],
89
+ ["none"]
90
+ ]) }));
65
91
  const measureAlias = z.templateLiteral(["m", z.number().int().nonnegative()], { error: "A measure's id in a query is m and a number: m1, m2." });
66
92
  const dimensionAlias = z.templateLiteral(["d", z.number().int().nonnegative()], { error: "A dimension's id in a query is d and a number: d1, d2." });
67
93
  const calcAlias = z.templateLiteral(["c", z.number().int().nonnegative()], { error: "A calculation's id in a query is c and a number: c1, c2." });
@@ -161,7 +187,7 @@ const wireQueryShape = z.strictObject({
161
187
  const wireQuerySchema = wireQueryShape.superRefine(checkPositions);
162
188
  /** Checks an untrusted query. Every problem is reported, with the path to it. */
163
189
  function parseWireQuery(input) {
164
- const result = wireQuerySchema.safeParse(input);
190
+ const result = wireQuerySchema.safeParse(withNullOpValues(input));
165
191
  if (result.success) return {
166
192
  ok: true,
167
193
  query: result.data
@@ -27,6 +27,19 @@ const OPTION_TYPES = {
27
27
  type: "array",
28
28
  items: { type: "string" }
29
29
  },
30
+ comparisons: {
31
+ type: "object",
32
+ additionalProperties: {
33
+ type: "array",
34
+ minItems: 1,
35
+ maxItems: 2,
36
+ uniqueItems: true,
37
+ items: {
38
+ type: "string",
39
+ pattern: "\\S"
40
+ }
41
+ }
42
+ },
30
43
  colors: {
31
44
  type: "object",
32
45
  additionalProperties: { type: "string" }
@@ -0,0 +1,38 @@
1
+ // src/schema/union-error.ts
2
+ const quoted = (keys) => keys.map((key) => `\`${key}\``);
3
+ function oneOf(keys) {
4
+ const words = quoted([...new Set(keys)]);
5
+ return words.length < 2 ? words[0] ?? "" : `${words.slice(0, -1).join(", ")} or ${words.at(-1) ?? ""}`;
6
+ }
7
+ /** Whether every problem with a branch is a key the input does not have. */
8
+ function onlyMissing(issues, own) {
9
+ return issues.every((issue) => issue.code === "invalid_type" && issue.path.length === 1 && !own.includes(String(issue.path[0])));
10
+ }
11
+ function described(issue) {
12
+ if (issue === void 0) return void 0;
13
+ const where = issue.path.map(String).join(".");
14
+ return where === "" ? issue.message : `${where}: ${issue.message}`;
15
+ }
16
+ /**
17
+ * The error for a union of object shapes, each named by the keys that tell it apart. Instead of
18
+ * zod's bare "Invalid input", it picks the shape the input shares the most of those keys with and
19
+ * reports that shape's own first problem, with its path; when the input is several shapes away
20
+ * from complete, it names the keys any of them needs.
21
+ */
22
+ function unionError(shapes) {
23
+ return (issue) => {
24
+ if (issue.code !== "invalid_union") return;
25
+ const { input } = issue;
26
+ const all = shapes.map((keys) => keys[0] ?? "");
27
+ if (typeof input !== "object" || input === null || Array.isArray(input)) return `Expected an object with ${oneOf(all)}.`;
28
+ const own = Object.keys(input);
29
+ const scores = shapes.map((keys) => keys.filter((key) => own.includes(key)).length);
30
+ const best = Math.max(...scores);
31
+ const picked = scores.flatMap((score, at) => score === best ? [at] : []);
32
+ const branches = picked.map((at) => issue.errors[at] ?? []);
33
+ if (best === 0) return `Expected an object with ${oneOf(all)}.`;
34
+ if (picked.length > 1 && branches.every((branch) => onlyMissing(branch, own))) return `Needs ${oneOf(branches.flatMap((branch) => branch.map((it) => String(it.path[0]))))}.`;
35
+ return described(branches[0]?.[0]);
36
+ };
37
+ }
38
+ export { unionError };
@@ -1,4 +1,5 @@
1
- import { MICROS_PER_HOUR, formatTextTime, parseDate, parseTextTime } from "./instant.mjs";
1
+ import { MICROS_PER_HOUR, formatTextTime, parseDate } from "./instant.mjs";
2
+ import { parseTextTime } from "./text-time.mjs";
2
3
  import { Temporal, zonedAt } from "./temporal.mjs";
3
4
  import { lastChange, nextChange, startOfDate } from "./zone.mjs";
4
5
  // src/time/bucket.ts
@@ -1,7 +1,8 @@
1
1
  import { bucketLabel, bucketLabels, bucketStart, nextBucketStart, shiftBucket } from "./bucket.mjs";
2
2
  import { comparisonQuery, comparisonSpan, shiftInstant } from "./compare.mjs";
3
- import { MICROS_PER_DAY, MICROS_PER_HOUR, MICROS_PER_SECOND, Micros, formatTextTime, parseDate, parseNaiveTime, parseTextTime } from "./instant.mjs";
3
+ import { MICROS_PER_DAY, MICROS_PER_HOUR, MICROS_PER_SECOND, Micros, formatTextTime, parseDate, parseNaiveTime } from "./instant.mjs";
4
4
  import { Span, inSpan, resolveRange } from "./range.mjs";
5
5
  import { Moment, isZone, momentMicros } from "./temporal.mjs";
6
+ import { lastIncludedMillisecond, parseTextTime } from "./text-time.mjs";
6
7
  import { NaiveRule, OffsetSegment, offsetSegments, resolveNaive, startOfDate } from "./zone.mjs";
7
- export { MICROS_PER_DAY, MICROS_PER_HOUR, MICROS_PER_SECOND, type Micros, type Moment, type NaiveRule, type OffsetSegment, type Span, bucketLabel, bucketLabels, bucketStart, comparisonQuery, comparisonSpan, formatTextTime, inSpan, isZone, momentMicros, nextBucketStart, offsetSegments, parseDate, parseNaiveTime, parseTextTime, resolveNaive, resolveRange, shiftBucket, shiftInstant, startOfDate };
8
+ export { MICROS_PER_DAY, MICROS_PER_HOUR, MICROS_PER_SECOND, type Micros, type Moment, type NaiveRule, type OffsetSegment, type Span, bucketLabel, bucketLabels, bucketStart, comparisonQuery, comparisonSpan, formatTextTime, inSpan, isZone, lastIncludedMillisecond, momentMicros, nextBucketStart, offsetSegments, parseDate, parseNaiveTime, parseTextTime, resolveNaive, resolveRange, shiftBucket, shiftInstant, startOfDate };
@@ -1,11 +1,10 @@
1
1
  import { Temporal } from "./temporal.mjs";
2
+ import { parseTextTime } from "./text-time.mjs";
2
3
  /** Microseconds since 1970-01-01T00:00:00Z. Exact for every instant from year 1 to 9999. */
3
4
  export type Micros = number;
4
5
  export declare const MICROS_PER_SECOND = 1000000;
5
6
  export declare const MICROS_PER_HOUR: number;
6
7
  export declare const MICROS_PER_DAY: number;
7
- /** The instant a text time names, or undefined when it does not fit the grammar exactly. */
8
- export declare function parseTextTime(text: string): Micros | undefined;
9
8
  /** A wall-clock time with no offset, as a naive timestamp column stores it. */
10
9
  export declare function parseNaiveTime(text: string): Temporal.PlainDateTime | undefined;
11
10
  /** A `date` value: a calendar day. Undefined when it is not a real day. */
@@ -1,37 +1,9 @@
1
- import { Temporal, instantAt, microsOf } from "./temporal.mjs";
1
+ import { Temporal, instantAt } from "./temporal.mjs";
2
+ import { matchTime, parseTextTime } from "./text-time.mjs";
2
3
  // src/time/instant.ts
3
4
  const MICROS_PER_SECOND = 1e6;
4
5
  const MICROS_PER_HOUR = 3600 * MICROS_PER_SECOND;
5
6
  const MICROS_PER_DAY = 24 * MICROS_PER_HOUR;
6
- /**
7
- * The one grammar for text time, a contract with every SQL dialect: `YYYY-MM-DD`, `T` or a
8
- * space, `hh:mm:ss`, an optional fraction of 1 to 6 digits, then `Z` or `+hh:mm` / `-hh:mm`.
9
- * A naive time is the same without the offset.
10
- */
11
- const TEXT_TIME = /^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,6}))?(Z|[+-](\d{2}):(\d{2}))?$/u;
12
- /**
13
- * Fields Temporal would accept differently: it reads second 60 as 59, so the grammar's own
14
- * limits are checked first. Temporal checks the date itself.
15
- */
16
- function inGrammar(match) {
17
- const n = (i) => Number(match[i] ?? "0");
18
- const offsetMinutes = n(9) * 60 + n(10);
19
- return n(4) <= 23 && n(5) <= 59 && n(6) <= 59 && offsetMinutes <= 840 && n(10) <= 59;
20
- }
21
- function matchTime(text, withOffset) {
22
- const match = TEXT_TIME.exec(text);
23
- if (match === null || match[8] !== void 0 !== withOffset) return void 0;
24
- return inGrammar(match) ? match : void 0;
25
- }
26
- /** The instant a text time names, or undefined when it does not fit the grammar exactly. */
27
- function parseTextTime(text) {
28
- if (matchTime(text, true) === void 0) return void 0;
29
- try {
30
- return microsOf(Temporal.Instant.from(text));
31
- } catch {
32
- return;
33
- }
34
- }
35
7
  /** A wall-clock time with no offset, as a naive timestamp column stores it. */
36
8
  function parseNaiveTime(text) {
37
9
  if (matchTime(text, false) === void 0) return void 0;
@@ -1,5 +1,6 @@
1
+ import { parseTextTime } from "./text-time.mjs";
1
2
  import { bucketStart, shiftBucket } from "./bucket.mjs";
2
- import { parseDate, parseTextTime } from "./instant.mjs";
3
+ import { parseDate } from "./instant.mjs";
3
4
  import { startOfDate } from "./zone.mjs";
4
5
  // src/time/range.ts
5
6
  /** An explicit range end: a text time with its offset, or a date meaning its first instant. */
@@ -1,4 +1,5 @@
1
- import { MICROS_PER_SECOND, parseDate, parseNaiveTime, parseTextTime } from "./instant.mjs";
1
+ import { parseTextTime } from "./text-time.mjs";
2
+ import { MICROS_PER_SECOND, parseDate, parseNaiveTime } from "./instant.mjs";
2
3
  import { resolveNaive, startOfDate } from "./zone.mjs";
3
4
  // src/time/stored.ts
4
5
  function epochValue(storage, raw) {
@@ -0,0 +1,10 @@
1
+ import { Micros } from "./instant.mjs";
2
+ /** A text instant at the engine's numeric precision. */
3
+ export declare function parseTextTime(text: string): Micros | undefined;
4
+ /** The last millisecond containing an included instant, for Intl to format in the viewer's zone.
5
+ * The bounds are already resolved instants. No day arithmetic is involved, even across DST.
6
+ */
7
+ export declare function lastIncludedMillisecond(range: {
8
+ from: string;
9
+ to: string;
10
+ }): number | undefined;
@@ -0,0 +1,80 @@
1
+ // src/time/text-time.ts
2
+ /**
3
+ * The one grammar for text time, a contract with every SQL dialect: `YYYY-MM-DD`, `T` or a
4
+ * space, `hh:mm:ss`, an optional fraction of 1 to 6 digits, then `Z` or `+hh:mm` / `-hh:mm`.
5
+ * A naive time is the same without the offset.
6
+ */
7
+ const TEXT_TIME = /^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,6}))?(Z|[+-](\d{2}):(\d{2}))?$/u;
8
+ /** The grammar's own limits on a clock time and an offset: second 60 is no second. */
9
+ function inGrammar(match) {
10
+ const n = (i) => Number(match[i] ?? "0");
11
+ const offsetMinutes = n(9) * 60 + n(10);
12
+ return n(4) <= 23 && n(5) <= 59 && n(6) <= 59 && offsetMinutes <= 840 && n(10) <= 59;
13
+ }
14
+ /** A text's fields when it fits the grammar, with an offset or without one as asked. */
15
+ function matchTime(text, withOffset) {
16
+ const match = TEXT_TIME.exec(text);
17
+ if (match === null || match[8] !== void 0 !== withOffset) return void 0;
18
+ return inGrammar(match) ? match : void 0;
19
+ }
20
+ const MONTH_DAYS = [
21
+ 31,
22
+ 28,
23
+ 31,
24
+ 30,
25
+ 31,
26
+ 30,
27
+ 31,
28
+ 31,
29
+ 30,
30
+ 31,
31
+ 30,
32
+ 31
33
+ ];
34
+ /** Whether a year has a 29 February, in the one calendar every year is counted in. */
35
+ const isLeap = (year) => year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
36
+ /** How many days a month of a year has; none for a month that is not one. */
37
+ const daysIn = (year, month) => month === 2 && isLeap(year) ? 29 : MONTH_DAYS[month - 1] ?? 0;
38
+ /**
39
+ * The days from 1970-01-01 to a calendar day, by counting: years in eras of 400, which all
40
+ * have as many days, and months from March, so the leap day is the last day of its year.
41
+ */
42
+ function daysFromEpoch(year, month, date) {
43
+ const counted = month <= 2 ? year - 1 : year;
44
+ const era = Math.floor(counted / 400);
45
+ const inEra = counted - era * 400;
46
+ const inYear = Math.floor((153 * (month > 2 ? month - 3 : month + 9) + 2) / 5) + date - 1;
47
+ const days = inEra * 365 + Math.floor(inEra / 4) - Math.floor(inEra / 100) + inYear;
48
+ return era * 146097 + days - 719468;
49
+ }
50
+ /** A calendar day's first millisecond in UTC; undefined for a day that is not real (30 February). */
51
+ function dayStart(year, month, date) {
52
+ return date >= 1 && date <= daysIn(year, month) ? daysFromEpoch(year, month, date) * 864e5 : void 0;
53
+ }
54
+ /** The instant a text time names, or undefined when it does not fit the grammar exactly. */
55
+ function exactMicros(text) {
56
+ const match = matchTime(text, true);
57
+ if (match === void 0) return void 0;
58
+ const n = (i) => Number(match[i] ?? "0");
59
+ const start = dayStart(n(1), n(2), n(3));
60
+ if (start === void 0) return void 0;
61
+ const offset = (match[8]?.startsWith("-") === true ? -1 : 1) * (n(9) * 60 + n(10));
62
+ const millis = start + ((n(4) * 60 + n(5) - offset) * 60 + n(6)) * 1e3;
63
+ return BigInt(millis) * 1000n + BigInt((match[7] ?? "").padEnd(6, "0"));
64
+ }
65
+ /** A text instant at the engine's numeric precision. */
66
+ function parseTextTime(text) {
67
+ const micros = exactMicros(text);
68
+ return micros === void 0 ? void 0 : Number(micros);
69
+ }
70
+ /** The last millisecond containing an included instant, for Intl to format in the viewer's zone.
71
+ * The bounds are already resolved instants. No day arithmetic is involved, even across DST.
72
+ */
73
+ function lastIncludedMillisecond(range) {
74
+ const from = exactMicros(range.from);
75
+ const until = exactMicros(range.to);
76
+ if (from === void 0 || until === void 0 || from >= until) return void 0;
77
+ const last = until - 1n;
78
+ return Number(last / 1000n) - Number(last % 1000n < 0n);
79
+ }
80
+ export { lastIncludedMillisecond, matchTime, parseTextTime };
@@ -344,4 +344,4 @@ export type CoreContract = {
344
344
  * than reading a shape it does not know. A test recomputes it from the answer schemas, so a
345
345
  * change to an answer fails until this is updated.
346
346
  */
347
- export declare const CONTRACT_VERSION = "7ce2908a7608aacd";
347
+ export declare const CONTRACT_VERSION = "87905292cf669d4a";
@@ -5,5 +5,5 @@
5
5
  * than reading a shape it does not know. A test recomputes it from the answer schemas, so a
6
6
  * change to an answer fails until this is updated.
7
7
  */
8
- const CONTRACT_VERSION = "7ce2908a7608aacd";
8
+ const CONTRACT_VERSION = "87905292cf669d4a";
9
9
  export { CONTRACT_VERSION };
@@ -132,6 +132,8 @@ export type DrillGroupedView = {
132
132
  /** Over time: the range it draws, and the grains it may be drawn at. */
133
133
  range?: ResolvedRange;
134
134
  grains?: Grain[];
135
+ /** A rolling trend ends at the reporting cutoff, which can precede the receipt's timestamp. */
136
+ throughNow?: boolean;
135
137
  /** A Breakdown of the change: each group now (the line), before (`c1`) and its change (`c2`). */
136
138
  change?: true;
137
139
  /** The field has more values than a Breakdown draws: a search narrows them. */
@@ -140,6 +142,24 @@ export type DrillGroupedView = {
140
142
  /** A Breakdown of a line that does not add up ranks its groups by their rows (`m<n>`). */
141
143
  rankedBy?: string;
142
144
  };
145
+ /** The tile's measures grouped together within a sealed selection. */
146
+ export type DrillComparisonView = {
147
+ by: "comparison";
148
+ drill: SealedAnswer;
149
+ thenBy?: DrillField;
150
+ omitted?: true;
151
+ } & ({
152
+ foreign?: never;
153
+ answer: Result & {
154
+ unreadable?: true;
155
+ };
156
+ } | {
157
+ foreign: true;
158
+ answer: Omit<Result, "receipt"> & {
159
+ receipt: Omit<Receipt, "queryHash" | "filter">;
160
+ unreadable?: true;
161
+ };
162
+ });
143
163
  /** A record column as Items show it: with its number format when the model gives one. */
144
164
  export type ItemColumn = RecordColumn & {
145
165
  format?: NumberFormat;
@@ -202,9 +222,9 @@ export type DrillExplanationView = {
202
222
  };
203
223
  /** A drill's answer: its summary, its path as breadcrumbs, its state normalized, and its view. */
204
224
  export type DrillAnswer = {
205
- /** Absent when the request said it already has it (`summary: false`). */
225
+ /** Absent for a group comparison or when the request said it already has it (`summary: false`). */
206
226
  summary?: DrillSummary;
207
227
  path: DrillCrumb[];
208
228
  state: DrillState;
209
- view: DrillGroupedView | DrillItemsView | DrillExplanationView;
229
+ view: DrillGroupedView | DrillComparisonView | DrillItemsView | DrillExplanationView;
210
230
  };
@@ -0,0 +1,8 @@
1
+ import { DashOptions, Issue } from "derive-dashboards/core";
2
+ /** A host configuration error raised before the server handles any request. */
3
+ export declare class DashboardDocumentError extends Error {
4
+ readonly dashboardKey: string;
5
+ readonly issues: readonly Issue[];
6
+ readonly code = "DOCUMENT_INVALID";
7
+ constructor(dashboardKey: string, reason: string, issues: readonly Issue[]);
8
+ }