derive-dashboards 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. package/README.md +4 -3
  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/check.mjs +14 -1
  6. package/dist/cli/import/dbt-schema.mjs +2 -2
  7. package/dist/cli/import/index.mjs +2 -2
  8. package/dist/core/conformance/cases.d.mts +3 -0
  9. package/dist/core/conformance/cases.mjs +20 -4
  10. package/dist/core/conformance/check.mjs +6 -3
  11. package/dist/core/conformance/drill-cases.mjs +120 -0
  12. package/dist/core/document/view.d.mts +26 -7
  13. package/dist/core/document/view.mjs +42 -11
  14. package/dist/core/engine/index.d.mts +14 -2
  15. package/dist/core/engine/index.mjs +12 -1
  16. package/dist/core/engine/members.mjs +1 -1
  17. package/dist/core/engine/postgres.mjs +1 -1
  18. package/dist/core/engine/record-layout.d.mts +11 -0
  19. package/dist/core/engine/record-layout.mjs +7 -7
  20. package/dist/core/engine/records.d.mts +3 -2
  21. package/dist/core/engine/records.mjs +2 -1
  22. package/dist/core/engine/segmented.mjs +5 -2
  23. package/dist/core/engine/sql-records.mjs +2 -1
  24. package/dist/core/engine/statement.mjs +37 -3
  25. package/dist/core/engine/types.d.mts +3 -0
  26. package/dist/core/engine/version.d.mts +1 -1
  27. package/dist/core/engine/version.mjs +1 -1
  28. package/dist/core/error/codes.d.mts +31 -0
  29. package/dist/core/error/codes.mjs +28 -1
  30. package/dist/core/index.d.mts +9 -5
  31. package/dist/core/index.mjs +5 -3
  32. package/dist/core/model/catalog/check.mjs +1 -1
  33. package/dist/core/model/hints.d.mts +36 -0
  34. package/dist/core/model/member.d.mts +4 -2
  35. package/dist/core/model/member.mjs +16 -3
  36. package/dist/core/model/types.d.mts +8 -6
  37. package/dist/core/model/validate/drill.mjs +70 -0
  38. package/dist/core/model/validate/index.mjs +3 -0
  39. package/dist/core/model/validate/shape.mjs +150 -0
  40. package/dist/core/model/validate/source.mjs +5 -3
  41. package/dist/core/query/alias.mjs +7 -1
  42. package/dist/core/query/drill/compose.d.mts +22 -0
  43. package/dist/core/query/drill/compose.mjs +85 -0
  44. package/dist/core/query/drill/fields.d.mts +21 -0
  45. package/dist/core/query/drill/fields.mjs +91 -0
  46. package/dist/core/query/drill/internal.d.mts +11 -0
  47. package/dist/core/query/drill/items.d.mts +29 -0
  48. package/dist/core/query/drill/items.mjs +98 -0
  49. package/dist/core/query/drill/line.d.mts +31 -0
  50. package/dist/core/query/drill/line.mjs +183 -0
  51. package/dist/core/query/drill/links.d.mts +33 -0
  52. package/dist/core/query/drill/links.mjs +31 -0
  53. package/dist/core/query/drill/operand.mjs +7 -0
  54. package/dist/core/query/drill/scopes.d.mts +22 -0
  55. package/dist/core/query/drill/scopes.mjs +58 -0
  56. package/dist/core/query/drill/selection.d.mts +37 -0
  57. package/dist/core/query/drill/selection.mjs +144 -0
  58. package/dist/core/query/drill/steps.d.mts +14 -0
  59. package/dist/core/query/drill/steps.mjs +35 -0
  60. package/dist/core/query/drill/synthetic-expr.mjs +85 -0
  61. package/dist/core/query/drill/synthetic.d.mts +22 -0
  62. package/dist/core/query/drill/synthetic.mjs +165 -0
  63. package/dist/core/query/drill/time.d.mts +11 -0
  64. package/dist/core/query/drill/time.mjs +71 -0
  65. package/dist/core/query/drill/types.d.mts +155 -0
  66. package/dist/core/query/drill/types.mjs +4 -0
  67. package/dist/core/query/drill/views.d.mts +62 -0
  68. package/dist/core/query/drill/views.mjs +257 -0
  69. package/dist/core/query/segments.d.mts +12 -2
  70. package/dist/core/query/segments.mjs +3 -1
  71. package/dist/core/result/columns.mjs +17 -4
  72. package/dist/core/result/types.d.mts +5 -1
  73. package/dist/core/schema/answer-parts.mjs +117 -0
  74. package/dist/core/schema/answers.d.mts +2108 -128
  75. package/dist/core/schema/answers.mjs +10 -113
  76. package/dist/core/schema/commands.d.mts +2 -2
  77. package/dist/core/schema/document.d.mts +1 -1
  78. package/dist/core/schema/drill-answers.mjs +179 -0
  79. package/dist/core/schema/drill.d.mts +260 -0
  80. package/dist/core/schema/drill.mjs +107 -0
  81. package/dist/core/schema/index.d.mts +4 -2
  82. package/dist/core/schema/index.mjs +4 -2
  83. package/dist/core/schema/picks.d.mts +35 -0
  84. package/dist/core/schema/picks.mjs +23 -0
  85. package/dist/core/schema/query.d.mts +1 -1
  86. package/dist/core/schema/tools.mjs +1 -1
  87. package/dist/core/schema/view.d.mts +0 -35
  88. package/dist/core/schema/view.mjs +19 -24
  89. package/dist/core/store/schema.d.mts +5 -0
  90. package/dist/core/store/schema.mjs +10 -0
  91. package/dist/core/types/api.d.mts +15 -1
  92. package/dist/core/types/api.mjs +1 -1
  93. package/dist/core/types/drill-api.d.mts +210 -0
  94. package/dist/core/types/options.d.mts +21 -0
  95. package/dist/core/types/viewer.d.mts +5 -0
  96. package/dist/cursor-seal.d.mts +8 -0
  97. package/dist/cursor-seal.mjs +98 -0
  98. package/dist/dashboard-id.mjs +1 -1
  99. package/dist/drill-access.mjs +93 -0
  100. package/dist/drill-change.mjs +76 -0
  101. package/dist/drill-crumbs.mjs +113 -0
  102. package/dist/drill-distinct.mjs +130 -0
  103. package/dist/drill-explain.mjs +64 -0
  104. package/dist/drill-identity.mjs +35 -0
  105. package/dist/drill-item-id.mjs +35 -0
  106. package/dist/drill-items.mjs +132 -0
  107. package/dist/drill-open.mjs +169 -0
  108. package/dist/drill-seal.mjs +170 -0
  109. package/dist/drill-secret.mjs +14 -0
  110. package/dist/drill-share.mjs +53 -0
  111. package/dist/drill-summary.mjs +158 -0
  112. package/dist/drill-targets.mjs +53 -0
  113. package/dist/drill-totals.mjs +8 -0
  114. package/dist/drill-views.mjs +175 -0
  115. package/dist/drill.mjs +157 -0
  116. package/dist/editing.mjs +2 -2
  117. package/dist/endpoints/dashboards.mjs +11 -3
  118. package/dist/endpoints/drill.mjs +55 -0
  119. package/dist/endpoints/index.d.mts +233 -2
  120. package/dist/endpoints/index.mjs +5 -1
  121. package/dist/endpoints/query.mjs +26 -4
  122. package/dist/execute.d.mts +19 -1
  123. package/dist/execute.mjs +15 -17
  124. package/dist/index.d.mts +3 -1
  125. package/dist/index.mjs +29 -2
  126. package/dist/mcp/drill.mjs +61 -0
  127. package/dist/mcp/format.mjs +27 -3
  128. package/dist/mcp/index.d.mts +15 -4
  129. package/dist/mcp/index.mjs +13 -7
  130. package/dist/mcp/query.d.mts +7 -2
  131. package/dist/mcp/query.mjs +7 -3
  132. package/dist/node-postgres.d.mts +8 -4
  133. package/dist/node-postgres.mjs +29 -6
  134. package/dist/owner.mjs +3 -3
  135. package/dist/postgres-connection.d.mts +8 -2
  136. package/dist/postgres-connection.mjs +2 -1
  137. package/dist/react/Dashboard.d.mts +10 -5
  138. package/dist/react/Dashboard.mjs +51 -23
  139. package/dist/react/DashboardList.mjs +30 -2
  140. package/dist/react/Discard.mjs +7 -2
  141. package/dist/react/Grid.mjs +12 -5
  142. package/dist/react/Header.mjs +9 -0
  143. package/dist/react/Parts.mjs +6 -2
  144. package/dist/react/ReviewPanel.mjs +13 -2
  145. package/dist/react/RowBody.d.mts +19 -0
  146. package/dist/react/RowBody.mjs +55 -0
  147. package/dist/react/Tile.d.mts +1 -1
  148. package/dist/react/Tile.mjs +54 -30
  149. package/dist/react/builder/state.d.mts +1 -1
  150. package/dist/react/client.d.mts +2 -0
  151. package/dist/react/client.mjs +1 -0
  152. package/dist/react/context.d.mts +15 -1
  153. package/dist/react/context.mjs +19 -4
  154. package/dist/react/drill/Bars.mjs +179 -0
  155. package/dist/react/drill/Controls.mjs +173 -0
  156. package/dist/react/drill/DashboardTile.d.mts +18 -0
  157. package/dist/react/drill/DashboardTile.mjs +107 -0
  158. package/dist/react/drill/DrillPanel.d.mts +31 -0
  159. package/dist/react/drill/DrillPanel.mjs +104 -0
  160. package/dist/react/drill/DrillTabs.mjs +52 -0
  161. package/dist/react/drill/Header.mjs +131 -0
  162. package/dist/react/drill/Items.d.mts +22 -0
  163. package/dist/react/drill/Items.mjs +164 -0
  164. package/dist/react/drill/ItemsFoot.mjs +60 -0
  165. package/dist/react/drill/Notes.mjs +58 -0
  166. package/dist/react/drill/PanelBody.mjs +74 -0
  167. package/dist/react/drill/PanelStates.mjs +37 -0
  168. package/dist/react/drill/board.d.mts +18 -0
  169. package/dist/react/drill/board.mjs +91 -0
  170. package/dist/react/drill/counts.mjs +14 -0
  171. package/dist/react/drill/host.mjs +26 -0
  172. package/dist/react/drill/item-parts.d.mts +5 -0
  173. package/dist/react/drill/item-parts.mjs +76 -0
  174. package/dist/react/drill/item-type.d.mts +26 -0
  175. package/dist/react/drill/item-type.mjs +7 -0
  176. package/dist/react/drill/lazy.d.mts +6 -0
  177. package/dist/react/drill/lazy.mjs +17 -0
  178. package/dist/react/drill/pages.mjs +48 -0
  179. package/dist/react/drill/panel-focus.mjs +51 -0
  180. package/dist/react/drill/props.d.mts +25 -0
  181. package/dist/react/drill/props.mjs +72 -0
  182. package/dist/react/drill/state.d.mts +18 -0
  183. package/dist/react/drill/state.mjs +68 -0
  184. package/dist/react/drill/useDrill.d.mts +46 -0
  185. package/dist/react/drill/useDrill.mjs +194 -0
  186. package/dist/react/drill/words.d.mts +98 -0
  187. package/dist/react/drill/words.mjs +77 -0
  188. package/dist/react/english.mjs +9 -1
  189. package/dist/react/format.d.mts +3 -3
  190. package/dist/react/format.mjs +34 -12
  191. package/dist/react/index.d.mts +27 -4
  192. package/dist/react/index.mjs +10 -3
  193. package/dist/react/messages.d.mts +14 -1
  194. package/dist/react/renderers/index.d.mts +10 -2
  195. package/dist/react/renderers/index.mjs +54 -14
  196. package/dist/react/renderers/list.d.mts +22 -0
  197. package/dist/react/renderers/list.mjs +118 -0
  198. package/dist/react/review-words.mjs +1 -1
  199. package/dist/react/review.mjs +2 -2
  200. package/dist/react/scope.mjs +2 -7
  201. package/dist/react/series.d.mts +37 -0
  202. package/dist/react/series.mjs +95 -0
  203. package/dist/react/theme.css +1823 -1296
  204. package/dist/react/theme.css.d.ts +1 -0
  205. package/dist/react/tile-store.mjs +15 -3
  206. package/dist/react/useBoard.d.mts +5 -0
  207. package/dist/react/useBoard.mjs +4 -1
  208. package/dist/react/useDashboard.d.mts +1 -0
  209. package/dist/react/useDashboard.mjs +2 -1
  210. package/dist/react/useTiles.mjs +50 -15
  211. package/dist/react/view.d.mts +9 -0
  212. package/dist/react/view.mjs +22 -10
  213. package/dist/reading.d.mts +2 -0
  214. package/dist/reading.mjs +9 -1
  215. package/dist/recharts/charts.d.mts +0 -1
  216. package/dist/recharts/charts.mjs +128 -34
  217. package/dist/recharts/index.d.mts +2 -2
  218. package/dist/recharts/index.mjs +2 -2
  219. package/dist/recharts/marks.mjs +83 -0
  220. package/dist/recharts/series.d.mts +2 -22
  221. package/dist/recharts/series.mjs +1 -64
  222. package/dist/records-read.mjs +44 -0
  223. package/dist/store/apply.mjs +5 -5
  224. package/dist/store/commands.mjs +4 -4
  225. package/dist/store/discard.mjs +7 -7
  226. package/dist/store/drafts.mjs +5 -5
  227. package/dist/store/editor.mjs +1 -1
  228. package/dist/store/publish.mjs +12 -12
  229. package/dist/store/reader.mjs +41 -22
  230. package/dist/store/review.mjs +16 -16
  231. package/dist/store/rows.mjs +20 -20
  232. package/dist/store/undo.mjs +3 -3
  233. package/dist/store/unpublished.mjs +4 -4
  234. package/dist/store/versions.mjs +14 -14
  235. package/dist/testing/adapter-suite.mjs +4 -4
  236. package/dist/tiles.mjs +37 -3
  237. package/package.json +8 -10
  238. package/dist/react/Records.d.mts +0 -12
  239. package/dist/react/Records.mjs +0 -97
  240. package/src/adapter/sql-adapter.ts +0 -95
  241. package/src/adapter/statement.ts +0 -185
  242. package/src/authorize.ts +0 -73
  243. package/src/body.ts +0 -169
  244. package/src/bounded.ts +0 -43
  245. package/src/cache.ts +0 -192
  246. package/src/checks.ts +0 -170
  247. package/src/custom-source.ts +0 -59
  248. package/src/dashboard-id.ts +0 -36
  249. package/src/dashboards.ts +0 -132
  250. package/src/editing.ts +0 -148
  251. package/src/endpoints/access.ts +0 -41
  252. package/src/endpoints/dashboards.ts +0 -92
  253. package/src/endpoints/drafts.ts +0 -138
  254. package/src/endpoints/index.ts +0 -21
  255. package/src/endpoints/meta.ts +0 -137
  256. package/src/endpoints/query.ts +0 -86
  257. package/src/endpoints/read.ts +0 -92
  258. package/src/endpoints/review.ts +0 -89
  259. package/src/endpoints/values.ts +0 -62
  260. package/src/endpoints/versions.ts +0 -104
  261. package/src/execute.ts +0 -207
  262. package/src/handler.ts +0 -232
  263. package/src/http.ts +0 -66
  264. package/src/index.ts +0 -163
  265. package/src/introspect.ts +0 -205
  266. package/src/mcp/api.ts +0 -59
  267. package/src/mcp/format.ts +0 -67
  268. package/src/mcp/index.ts +0 -151
  269. package/src/mcp/query.ts +0 -153
  270. package/src/mcp/resolve.ts +0 -114
  271. package/src/node-postgres.ts +0 -81
  272. package/src/owner.ts +0 -36
  273. package/src/postgres-connection.ts +0 -143
  274. package/src/postgres-store.ts +0 -82
  275. package/src/principal.ts +0 -39
  276. package/src/reading.ts +0 -56
  277. package/src/request-rows.ts +0 -23
  278. package/src/request.ts +0 -22
  279. package/src/storage.ts +0 -63
  280. package/src/store/apply.ts +0 -129
  281. package/src/store/commands.ts +0 -75
  282. package/src/store/conflicts.ts +0 -98
  283. package/src/store/create-tables.ts +0 -104
  284. package/src/store/discard.ts +0 -42
  285. package/src/store/drafts.ts +0 -133
  286. package/src/store/editor.ts +0 -28
  287. package/src/store/log.ts +0 -28
  288. package/src/store/publish.ts +0 -199
  289. package/src/store/publisher.ts +0 -21
  290. package/src/store/reader.ts +0 -139
  291. package/src/store/review.ts +0 -239
  292. package/src/store/rows.ts +0 -250
  293. package/src/store/tenant.ts +0 -28
  294. package/src/store/undo.ts +0 -56
  295. package/src/store/unpublished.ts +0 -33
  296. package/src/store/versions.ts +0 -106
  297. package/src/store/writer.ts +0 -19
  298. package/src/testing/adapter-suite.ts +0 -239
  299. package/src/testing/index.ts +0 -2
  300. package/src/tile-doc.ts +0 -46
  301. package/src/tiles.ts +0 -120
@@ -1,7 +1,8 @@
1
+ import { cell, recordColumn, result } from "./answer-parts.mjs";
1
2
  import { documentSchema } from "./document.mjs";
3
+ import { drillAnswerSchema, queryDrill } from "./drill-answers.mjs";
2
4
  import { editingAnswers } from "./editing.mjs";
3
- import { issue } from "./issue.mjs";
4
- import { grain, op, primitive } from "./query.mjs";
5
+ import { primitive } from "./query.mjs";
5
6
  import { z } from "zod";
6
7
  // src/schema/answers.ts
7
8
  /**
@@ -10,112 +11,10 @@ import { z } from "zod";
10
11
  * loose, so a field a newer server adds is kept rather than refused; a server from another
11
12
  * release is caught first by the contract fingerprint.
12
13
  */
13
- const cell = z.union([
14
- z.string(),
15
- z.number(),
16
- z.boolean(),
17
- z.null(),
18
- z.looseObject({
19
- t: z.enum(["int", "decimal"]),
20
- v: z.string()
21
- })
22
- ]);
23
- const resultCell = z.union([cell, z.looseObject({ mark: z.enum(["other", "all"]) })]);
24
- const rows = z.array(z.array(resultCell).readonly()).readonly();
25
- const columnType = z.enum([
26
- "string",
27
- "number",
28
- "boolean",
29
- "time",
30
- "int",
31
- "decimal",
32
- "float"
33
- ]);
34
- const column = z.looseObject({
35
- id: z.string(),
36
- label: z.string(),
37
- type: columnType,
38
- unit: z.string().exactOptional(),
39
- grain: grain.exactOptional(),
40
- format: z.enum([
41
- "number",
42
- "percent",
43
- "currency",
44
- "duration"
45
- ]).exactOptional(),
46
- signed: z.literal(true).exactOptional()
47
- });
48
- const resolvedRange = z.looseObject({
49
- from: z.string(),
50
- to: z.string()
14
+ const queryAnswer = result.extend({
15
+ unreadable: z.literal(true).exactOptional(),
16
+ drill: queryDrill
51
17
  });
52
- const boundFilter = z.lazy(() => z.union([
53
- z.looseObject({ all: z.array(boundFilter).readonly() }),
54
- z.looseObject({ any: z.array(boundFilter).readonly() }),
55
- z.looseObject({ not: boundFilter }),
56
- z.looseObject({
57
- member: z.string(),
58
- op,
59
- values: z.array(primitive).readonly()
60
- }),
61
- z.looseObject({ some: z.looseObject({
62
- join: z.string(),
63
- where: boundFilter
64
- }) }),
65
- z.looseObject({ none: z.looseObject({
66
- join: z.string(),
67
- where: boundFilter
68
- }) })
69
- ]));
70
- const receipt = z.looseObject({
71
- queryHash: z.string(),
72
- provider: z.string(),
73
- trust: z.enum(["builtin", "external"]),
74
- sources: z.array(z.string()).readonly(),
75
- answeredBy: z.string(),
76
- cache: z.enum([
77
- "hit",
78
- "stale",
79
- "miss",
80
- "off"
81
- ]),
82
- range: resolvedRange.exactOptional(),
83
- calendar: z.looseObject({
84
- timezone: z.string(),
85
- weekStart: z.union([
86
- z.literal(0),
87
- z.literal(1),
88
- z.literal(6)
89
- ]),
90
- fiscalYearStartMonth: z.number()
91
- }),
92
- dataThrough: z.string(),
93
- computedAt: z.string(),
94
- consistency: z.enum([
95
- "snapshot",
96
- "statement",
97
- "mixed"
98
- ]),
99
- durationMs: z.number(),
100
- rowsReturned: z.number(),
101
- filter: boundFilter,
102
- coverage: z.looseObject({
103
- applied: z.array(z.string()).readonly(),
104
- dropped: z.array(z.string()).readonly()
105
- }),
106
- warnings: z.array(issue).readonly()
107
- });
108
- const result = z.looseObject({
109
- rows,
110
- columns: z.array(column).readonly(),
111
- compare: z.looseObject({
112
- rows,
113
- range: resolvedRange
114
- }).exactOptional(),
115
- status: z.enum(["complete", "truncated"]),
116
- receipt
117
- });
118
- const queryAnswer = result.extend({ unreadable: z.literal(true).exactOptional() });
119
18
  const values = z.looseObject({
120
19
  values: z.array(primitive),
121
20
  more: z.boolean()
@@ -166,11 +65,6 @@ const list = z.looseObject({
166
65
  })),
167
66
  can: z.looseObject({ create: z.boolean() })
168
67
  });
169
- const recordColumn = z.looseObject({
170
- member: z.string(),
171
- label: z.string(),
172
- type: columnType
173
- });
174
68
  const records = z.looseObject({
175
69
  columns: z.array(recordColumn),
176
70
  rows: z.array(z.array(cell)),
@@ -187,7 +81,8 @@ const tileLineSchema = z.union([
187
81
  ok: z.literal(true),
188
82
  result: result.extend({
189
83
  widgetId: z.string(),
190
- unreadable: z.literal(true).exactOptional()
84
+ unreadable: z.literal(true).exactOptional(),
85
+ drill: queryDrill
191
86
  })
192
87
  }),
193
88
  z.looseObject({
@@ -211,7 +106,9 @@ const answerSchemas = {
211
106
  "/dashboards/get": dashboard,
212
107
  "/dashboards/control-values": values,
213
108
  "/dashboards/records": records,
109
+ "/dashboards/drill": drillAnswerSchema,
214
110
  "/query/run": queryAnswer,
111
+ "/query/drill": drillAnswerSchema,
215
112
  ...editingAnswers
216
113
  };
217
114
  export { answerSchemas, tileLineSchema };
@@ -97,8 +97,8 @@ export declare const commandSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
97
97
  other: z.ZodExactOptional<z.ZodBoolean>;
98
98
  total: z.ZodExactOptional<z.ZodBoolean>;
99
99
  fill: z.ZodExactOptional<z.ZodEnum<{
100
- zero: "zero";
101
100
  none: "none";
101
+ zero: "zero";
102
102
  }>>;
103
103
  }, z.core.$loose>>;
104
104
  display: z.ZodExactOptional<z.ZodObject<{
@@ -196,8 +196,8 @@ export declare const commandSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
196
196
  other: z.ZodExactOptional<z.ZodBoolean>;
197
197
  total: z.ZodExactOptional<z.ZodBoolean>;
198
198
  fill: z.ZodExactOptional<z.ZodEnum<{
199
- zero: "zero";
200
199
  none: "none";
200
+ zero: "zero";
201
201
  }>>;
202
202
  }, z.core.$loose>;
203
203
  }, z.core.$strict>, z.ZodObject<{
@@ -100,8 +100,8 @@ export declare const documentSchema: z.ZodObject<{
100
100
  other: z.ZodExactOptional<z.ZodBoolean>;
101
101
  total: z.ZodExactOptional<z.ZodBoolean>;
102
102
  fill: z.ZodExactOptional<z.ZodEnum<{
103
- zero: "zero";
104
103
  none: "none";
104
+ zero: "zero";
105
105
  }>>;
106
106
  }, z.core.$loose>>;
107
107
  display: z.ZodExactOptional<z.ZodObject<{
@@ -0,0 +1,179 @@
1
+ import { DRILL_REASONS } from "../error/codes.mjs";
2
+ import { cell, column, receipt, recordColumn, result } from "./answer-parts.mjs";
3
+ import { drillStateSchema } from "./drill.mjs";
4
+ import { grain, primitive } from "./query.mjs";
5
+ import { z } from "zod";
6
+ // src/schema/drill-answers.ts
7
+ const reason = z.enum(Object.keys(DRILL_REASONS));
8
+ const closed = z.array(z.looseObject({
9
+ row: z.int(),
10
+ code: reason,
11
+ reason: z.string()
12
+ })).exactOptional();
13
+ /** An answer sealed once, with the rows that do not open. */
14
+ const sealedAnswer = z.looseObject({
15
+ answer: z.string(),
16
+ closed
17
+ });
18
+ /** What an answer gives a client to drill with: its sealed execution and the answer sealed once. */
19
+ const queryDrill = sealedAnswer.extend({
20
+ execution: z.string(),
21
+ previous: sealedAnswer.exactOptional(),
22
+ code: reason.exactOptional(),
23
+ reason: z.string().exactOptional()
24
+ }).exactOptional();
25
+ const can = z.union([z.looseObject({ ok: z.literal(true) }), z.looseObject({
26
+ ok: z.literal(false),
27
+ code: reason,
28
+ reason: z.string()
29
+ })]);
30
+ const field = z.looseObject({
31
+ id: z.string(),
32
+ label: z.string()
33
+ });
34
+ const range = z.looseObject({
35
+ from: z.string(),
36
+ to: z.string()
37
+ });
38
+ const summary = z.looseObject({
39
+ value: cell,
40
+ clicked: cell.exactOptional(),
41
+ itemCount: cell.exactOptional(),
42
+ semantics: z.enum([
43
+ "rows",
44
+ "non-null",
45
+ "distinct",
46
+ "ratio",
47
+ "expression"
48
+ ]),
49
+ counted: z.literal(true).exactOptional(),
50
+ share: z.looseObject({
51
+ value: z.number(),
52
+ of: z.enum(["parent", "tile"])
53
+ }).exactOptional(),
54
+ rows: cell.exactOptional(),
55
+ operand: z.string().exactOptional(),
56
+ can: z.looseObject({
57
+ breakdown: can,
58
+ trend: can,
59
+ items: can,
60
+ explanation: can
61
+ }),
62
+ offered: z.array(field),
63
+ receipt,
64
+ column: column.exactOptional(),
65
+ noun: z.looseObject({
66
+ one: z.string(),
67
+ other: z.string()
68
+ }).exactOptional(),
69
+ range: range.exactOptional(),
70
+ previous: z.literal(true).exactOptional(),
71
+ foreign: z.literal(true).exactOptional(),
72
+ omitted: z.literal(true).exactOptional()
73
+ });
74
+ const grouped = z.looseObject({
75
+ by: z.enum(["breakdown", "trend"]),
76
+ answer: result.extend({ unreadable: z.literal(true).exactOptional() }),
77
+ drill: sealedAnswer,
78
+ offered: z.array(field),
79
+ member: z.string().exactOptional(),
80
+ grain: grain.exactOptional(),
81
+ range: range.exactOptional(),
82
+ grains: z.array(grain).exactOptional(),
83
+ rankedBy: z.string().exactOptional(),
84
+ change: z.literal(true).exactOptional(),
85
+ searchable: z.literal(true).exactOptional(),
86
+ search: z.string().exactOptional()
87
+ });
88
+ const items = z.looseObject({
89
+ by: z.literal("items"),
90
+ source: z.string(),
91
+ columns: z.array(recordColumn.extend({
92
+ format: z.looseObject({
93
+ unit: z.string().exactOptional(),
94
+ minor: z.literal(true).exactOptional()
95
+ }).exactOptional(),
96
+ unit: z.string().exactOptional()
97
+ })),
98
+ items: z.array(z.looseObject({
99
+ source: z.string(),
100
+ id: z.string(),
101
+ key: z.record(z.string(), primitive).exactOptional(),
102
+ values: z.record(z.string(), cell),
103
+ link: z.string().exactOptional()
104
+ })),
105
+ next: z.string().exactOptional(),
106
+ value: z.string().exactOptional(),
107
+ sort: z.enum([
108
+ "records",
109
+ "value",
110
+ "count"
111
+ ]),
112
+ sorted: z.looseObject({
113
+ member: z.string(),
114
+ dir: z.enum(["asc", "desc"]),
115
+ time: z.boolean()
116
+ }).exactOptional(),
117
+ fixed: z.array(z.string()).exactOptional(),
118
+ percentile: z.number().exactOptional(),
119
+ truncated: z.literal(true).exactOptional(),
120
+ title: z.string().exactOptional(),
121
+ badge: z.looseObject({
122
+ member: z.string(),
123
+ tones: z.record(z.string(), z.enum([
124
+ "positive",
125
+ "negative",
126
+ "warning",
127
+ "neutral"
128
+ ])).exactOptional()
129
+ }).exactOptional(),
130
+ numerator: z.looseObject({
131
+ label: z.string(),
132
+ count: cell.exactOptional(),
133
+ flag: z.string().exactOptional(),
134
+ only: z.literal(true).exactOptional(),
135
+ unmarked: z.literal(true).exactOptional()
136
+ }).exactOptional()
137
+ });
138
+ const explanation = z.looseObject({
139
+ by: z.literal("explanation"),
140
+ operands: z.array(z.looseObject({
141
+ entry: z.string(),
142
+ scope: z.enum([
143
+ "row",
144
+ "total",
145
+ "bucket",
146
+ "previous"
147
+ ]),
148
+ label: z.string(),
149
+ value: cell,
150
+ state: drillStateSchema.exactOptional(),
151
+ can
152
+ }))
153
+ });
154
+ const crumbPart = z.looseObject({
155
+ label: z.string(),
156
+ value: cell,
157
+ kind: z.enum([
158
+ "group",
159
+ "time",
160
+ "other",
161
+ "total",
162
+ "search"
163
+ ]).exactOptional(),
164
+ grain: grain.exactOptional(),
165
+ previous: z.literal(true).exactOptional()
166
+ });
167
+ const crumb = crumbPart.extend({ parts: z.array(crumbPart).exactOptional() });
168
+ /** A drill's answer: its summary, breadcrumbs, normalized state and view. */
169
+ const drillAnswerSchema = z.looseObject({
170
+ summary: summary.exactOptional(),
171
+ path: z.array(crumb),
172
+ state: drillStateSchema,
173
+ view: z.union([
174
+ grouped,
175
+ items,
176
+ explanation
177
+ ])
178
+ });
179
+ export { drillAnswerSchema, queryDrill };
@@ -0,0 +1,260 @@
1
+ import { WireFilter } from "../query/filter.mjs";
2
+ import { FormulaNode } from "../query/types.mjs";
3
+ import "../index.mjs";
4
+ import { z } from "zod";
5
+ /** What a drill shows. */
6
+ export declare const drillViewSchema: z.ZodUnion<readonly [z.ZodObject<{
7
+ by: z.ZodLiteral<"breakdown">;
8
+ member: z.ZodExactOptional<z.ZodString>;
9
+ search: z.ZodExactOptional<z.ZodString>;
10
+ }, z.core.$strict>, z.ZodObject<{
11
+ by: z.ZodLiteral<"trend">;
12
+ grain: z.ZodExactOptional<z.ZodEnum<{
13
+ hour: "hour";
14
+ day: "day";
15
+ week: "week";
16
+ month: "month";
17
+ quarter: "quarter";
18
+ year: "year";
19
+ }>>;
20
+ }, z.core.$strict>, z.ZodObject<{
21
+ by: z.ZodLiteral<"items">;
22
+ numerator: z.ZodExactOptional<z.ZodLiteral<true>>;
23
+ }, z.core.$strict>, z.ZodObject<{
24
+ by: z.ZodLiteral<"explanation">;
25
+ }, z.core.$strict>]>;
26
+ /** A drill as plain data: its origin, line, sealed execution and path, and the view open. */
27
+ export declare const drillStateSchema: z.ZodObject<{
28
+ origin: z.ZodUnion<readonly [z.ZodObject<{
29
+ kind: z.ZodLiteral<"dashboard">;
30
+ dashboardId: z.ZodString;
31
+ widgetId: z.ZodString;
32
+ query: z.ZodExactOptional<z.ZodString>;
33
+ picks: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
34
+ op: z.ZodEnum<{
35
+ equals: "equals";
36
+ in: "in";
37
+ contains: "contains";
38
+ startsWith: "startsWith";
39
+ gt: "gt";
40
+ gte: "gte";
41
+ lt: "lt";
42
+ lte: "lte";
43
+ between: "between";
44
+ notEquals: "notEquals";
45
+ notIn: "notIn";
46
+ notContains: "notContains";
47
+ set: "set";
48
+ notSet: "notSet";
49
+ }>;
50
+ values: z.ZodReadonly<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
51
+ }, z.core.$strict>, z.ZodObject<{
52
+ last: z.ZodInt;
53
+ unit: z.ZodEnum<{
54
+ hour: "hour";
55
+ day: "day";
56
+ week: "week";
57
+ month: "month";
58
+ quarter: "quarter";
59
+ year: "year";
60
+ }>;
61
+ includeCurrent: z.ZodBoolean;
62
+ }, z.core.$strict>, z.ZodObject<{
63
+ from: z.ZodString;
64
+ to: z.ZodString;
65
+ }, z.core.$strict>, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>]>>;
66
+ document: z.ZodExactOptional<z.ZodUnion<readonly [z.ZodObject<{
67
+ version: z.ZodInt;
68
+ }, z.core.$strict>, z.ZodObject<{
69
+ draft: z.ZodLiteral<true>;
70
+ }, z.core.$strict>]>>;
71
+ }, z.core.$strict>, z.ZodObject<{
72
+ kind: z.ZodLiteral<"query">;
73
+ query: z.ZodObject<{
74
+ kind: z.ZodLiteral<"aggregate">;
75
+ source: z.ZodString;
76
+ measures: z.ZodReadonly<z.ZodArray<z.ZodObject<{
77
+ id: z.ZodTemplateLiteral<`m${number}`>;
78
+ measure: z.ZodString;
79
+ filter: z.ZodExactOptional<z.ZodType<WireFilter, unknown, z.core.$ZodTypeInternals<WireFilter, unknown>>>;
80
+ label: z.ZodExactOptional<z.ZodString>;
81
+ }, z.core.$strict>>>;
82
+ dimensions: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
83
+ id: z.ZodTemplateLiteral<`d${number}`>;
84
+ member: z.ZodString;
85
+ limit: z.ZodExactOptional<z.ZodNumber>;
86
+ other: z.ZodExactOptional<z.ZodBoolean>;
87
+ rankBy: z.ZodExactOptional<z.ZodObject<{
88
+ by: z.ZodUnion<readonly [z.ZodTemplateLiteral<`m${number}`>, z.ZodTemplateLiteral<`c${number}`>]>;
89
+ dir: z.ZodEnum<{
90
+ asc: "asc";
91
+ desc: "desc";
92
+ }>;
93
+ }, z.core.$strict>>;
94
+ }, z.core.$strict>>>>;
95
+ time: z.ZodExactOptional<z.ZodObject<{
96
+ dimension: z.ZodString;
97
+ grain: z.ZodExactOptional<z.ZodEnum<{
98
+ hour: "hour";
99
+ day: "day";
100
+ week: "week";
101
+ month: "month";
102
+ quarter: "quarter";
103
+ year: "year";
104
+ }>>;
105
+ range: z.ZodUnion<readonly [z.ZodObject<{
106
+ last: z.ZodNumber;
107
+ unit: z.ZodEnum<{
108
+ hour: "hour";
109
+ day: "day";
110
+ week: "week";
111
+ month: "month";
112
+ quarter: "quarter";
113
+ year: "year";
114
+ }>;
115
+ includeCurrent: z.ZodBoolean;
116
+ }, z.core.$strict>, z.ZodObject<{
117
+ from: z.ZodString;
118
+ to: z.ZodString;
119
+ }, z.core.$strict>]>;
120
+ compare: z.ZodExactOptional<z.ZodEnum<{
121
+ previous_period: "previous_period";
122
+ previous_year: "previous_year";
123
+ }>>;
124
+ }, z.core.$strict>>;
125
+ filters: z.ZodExactOptional<z.ZodType<WireFilter, unknown, z.core.$ZodTypeInternals<WireFilter, unknown>>>;
126
+ calc: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
127
+ id: z.ZodTemplateLiteral<`c${number}`>;
128
+ formula: z.ZodType<FormulaNode, unknown, z.core.$ZodTypeInternals<FormulaNode, unknown>>;
129
+ format: z.ZodExactOptional<z.ZodEnum<{
130
+ number: "number";
131
+ percent: "percent";
132
+ currency: "currency";
133
+ duration: "duration";
134
+ }>>;
135
+ label: z.ZodExactOptional<z.ZodString>;
136
+ }, z.core.$strict>>>>;
137
+ order: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
138
+ by: z.ZodUnion<readonly [z.ZodTemplateLiteral<`m${number}`>, z.ZodTemplateLiteral<`c${number}`>, z.ZodTemplateLiteral<`d${number}`>]>;
139
+ dir: z.ZodEnum<{
140
+ asc: "asc";
141
+ desc: "desc";
142
+ }>;
143
+ }, z.core.$strict>>>>;
144
+ limit: z.ZodExactOptional<z.ZodNumber>;
145
+ other: z.ZodExactOptional<z.ZodBoolean>;
146
+ total: z.ZodExactOptional<z.ZodBoolean>;
147
+ fill: z.ZodExactOptional<z.ZodEnum<{
148
+ none: "none";
149
+ zero: "zero";
150
+ }>>;
151
+ }, z.core.$strict>;
152
+ }, z.core.$strict>]>;
153
+ entry: z.ZodExactOptional<z.ZodString>;
154
+ execution: z.ZodString;
155
+ path: z.ZodReadonly<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodString]>>>;
156
+ view: z.ZodUnion<readonly [z.ZodObject<{
157
+ by: z.ZodLiteral<"breakdown">;
158
+ member: z.ZodExactOptional<z.ZodString>;
159
+ search: z.ZodExactOptional<z.ZodString>;
160
+ }, z.core.$strict>, z.ZodObject<{
161
+ by: z.ZodLiteral<"trend">;
162
+ grain: z.ZodExactOptional<z.ZodEnum<{
163
+ hour: "hour";
164
+ day: "day";
165
+ week: "week";
166
+ month: "month";
167
+ quarter: "quarter";
168
+ year: "year";
169
+ }>>;
170
+ }, z.core.$strict>, z.ZodObject<{
171
+ by: z.ZodLiteral<"items">;
172
+ numerator: z.ZodExactOptional<z.ZodLiteral<true>>;
173
+ }, z.core.$strict>, z.ZodObject<{
174
+ by: z.ZodLiteral<"explanation">;
175
+ }, z.core.$strict>]>;
176
+ views: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
177
+ by: z.ZodLiteral<"breakdown">;
178
+ member: z.ZodExactOptional<z.ZodString>;
179
+ search: z.ZodExactOptional<z.ZodString>;
180
+ }, z.core.$strict>, z.ZodObject<{
181
+ by: z.ZodLiteral<"trend">;
182
+ grain: z.ZodExactOptional<z.ZodEnum<{
183
+ hour: "hour";
184
+ day: "day";
185
+ week: "week";
186
+ month: "month";
187
+ quarter: "quarter";
188
+ year: "year";
189
+ }>>;
190
+ }, z.core.$strict>, z.ZodObject<{
191
+ by: z.ZodLiteral<"items">;
192
+ numerator: z.ZodExactOptional<z.ZodLiteral<true>>;
193
+ }, z.core.$strict>, z.ZodObject<{
194
+ by: z.ZodLiteral<"explanation">;
195
+ }, z.core.$strict>]>>>>;
196
+ }, z.core.$strict>;
197
+ /** What a sealed selection opens to, checked again after it opens. */
198
+ export declare const selectionSchema: z.ZodObject<{
199
+ steps: z.ZodReadonly<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
200
+ group: z.ZodReadonly<z.ZodArray<z.ZodObject<{
201
+ member: z.ZodString;
202
+ value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
203
+ }, z.core.$strict>>>;
204
+ }, z.core.$strict>, z.ZodObject<{
205
+ bucket: z.ZodObject<{
206
+ member: z.ZodString;
207
+ from: z.ZodString;
208
+ to: z.ZodString;
209
+ grain: z.ZodExactOptional<z.ZodEnum<{
210
+ hour: "hour";
211
+ day: "day";
212
+ week: "week";
213
+ month: "month";
214
+ quarter: "quarter";
215
+ year: "year";
216
+ }>>;
217
+ }, z.core.$strict>;
218
+ }, z.core.$strict>, z.ZodObject<{
219
+ other: z.ZodObject<{
220
+ members: z.ZodReadonly<z.ZodArray<z.ZodString>>;
221
+ kept: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>>>;
222
+ }, z.core.$strict>;
223
+ }, z.core.$strict>, z.ZodObject<{
224
+ search: z.ZodObject<{
225
+ member: z.ZodString;
226
+ text: z.ZodString;
227
+ }, z.core.$strict>;
228
+ }, z.core.$strict>]>>>;
229
+ clicked: z.ZodExactOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>, z.ZodObject<{
230
+ t: z.ZodEnum<{
231
+ decimal: "decimal";
232
+ int: "int";
233
+ }>;
234
+ v: z.ZodString;
235
+ }, z.core.$strict>]>>>;
236
+ previous: z.ZodExactOptional<z.ZodLiteral<true>>;
237
+ exec: z.ZodExactOptional<z.ZodString>;
238
+ parent: z.ZodExactOptional<z.ZodString>;
239
+ }, z.core.$strict>;
240
+ /** What a sealed execution opens to. */
241
+ export declare const pinnedSchema: z.ZodObject<{
242
+ id: z.ZodString;
243
+ by: z.ZodString;
244
+ revision: z.ZodExactOptional<z.ZodString>;
245
+ range: z.ZodExactOptional<z.ZodObject<{
246
+ from: z.ZodString;
247
+ to: z.ZodString;
248
+ }, z.core.$strict>>;
249
+ compare: z.ZodExactOptional<z.ZodObject<{
250
+ from: z.ZodString;
251
+ to: z.ZodString;
252
+ }, z.core.$strict>>;
253
+ now: z.ZodExactOptional<z.ZodString>;
254
+ calendar: z.ZodObject<{
255
+ timezone: z.ZodString;
256
+ weekStart: z.ZodUnion<readonly [z.ZodLiteral<0>, z.ZodLiteral<1>, z.ZodLiteral<6>]>;
257
+ fiscalYearStartMonth: z.ZodInt;
258
+ }, z.core.$strict>;
259
+ version: z.ZodExactOptional<z.ZodInt>;
260
+ }, z.core.$strict>;