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
@@ -0,0 +1,150 @@
1
+ import { issue } from "./issues.mjs";
2
+ // src/model/validate/shape.ts
3
+ const MEASURE_KINDS = [
4
+ "count",
5
+ "sum",
6
+ "min",
7
+ "max",
8
+ "avg",
9
+ "percentile",
10
+ "ratio"
11
+ ];
12
+ const MERGES = [
13
+ "sum",
14
+ "min",
15
+ "max",
16
+ "none"
17
+ ];
18
+ const PERCENTILES = [
19
+ 50,
20
+ 75,
21
+ 90,
22
+ 95,
23
+ 99
24
+ ];
25
+ const DIMENSION_KINDS = [
26
+ "string",
27
+ "number",
28
+ "boolean",
29
+ "time",
30
+ "ref",
31
+ "bucket",
32
+ "expr"
33
+ ];
34
+ const STORAGES = [
35
+ "timestamptz",
36
+ "date",
37
+ "epoch_ms",
38
+ "epoch_s",
39
+ "text_parseable"
40
+ ];
41
+ const isObject = (v) => typeof v === "object" && v !== null;
42
+ const known = (list, value) => list.includes(value);
43
+ const shape = (path, message) => issue("MODEL_SHAPE", path, message);
44
+ const oneOf = (list) => list.map((v) => JSON.stringify(v)).join(", ");
45
+ /** Fields a kind needs, each named when missing. */
46
+ function needs(m, fields, path) {
47
+ return fields.flatMap((f) => m[f] === void 0 ? [shape([...path, f], `A ${String(m["kind"])} needs "${f}".`)] : []);
48
+ }
49
+ function measureShape(m, path) {
50
+ if (!isObject(m)) return [shape(path, "A measure is an object.")];
51
+ if (!known(MEASURE_KINDS, m["kind"])) return [shape([...path, "kind"], `"${String(m["kind"])}" is not a measure kind: ${oneOf(MEASURE_KINDS)}.`)];
52
+ if (m["kind"] === "ratio") return needs(m, ["numerator", "denominator"], path);
53
+ const merge = known(MERGES, m["merge"]) ? [] : [shape([...path, "merge"], `"${String(m["merge"])}" is not a merge: ${oneOf(MERGES)}.`)];
54
+ if (m["kind"] === "count") return merge;
55
+ const fields = m["kind"] === "percentile" ? ["of", "p"] : ["of", "numeric"];
56
+ const p = m["kind"] === "percentile" && m["p"] !== void 0 && !known(PERCENTILES, m["p"]) ? [shape([...path, "p"], `A percentile is one of ${oneOf(PERCENTILES)}.`)] : [];
57
+ return [
58
+ ...merge,
59
+ ...needs(m, fields, path),
60
+ ...p
61
+ ];
62
+ }
63
+ function storageShape(storage, path) {
64
+ if (typeof storage === "string" && known(STORAGES, storage)) return [];
65
+ if (isObject(storage) && ("timestamp" in storage || "iso_utc_fixed" in storage)) return [];
66
+ return [shape(path, `${JSON.stringify(storage)} is not a time storage: ${oneOf(STORAGES)}, { timestamp: { zone, ... } } or { iso_utc_fixed: { ... } }.`)];
67
+ }
68
+ const DIMENSION_NEEDS = {
69
+ string: ["column"],
70
+ number: ["column"],
71
+ boolean: ["column"],
72
+ time: ["column", "storage"],
73
+ ref: ["join", "label"],
74
+ bucket: [
75
+ "of",
76
+ "edges",
77
+ "labels"
78
+ ],
79
+ expr: ["expr", "type"]
80
+ };
81
+ function dimensionShape(d, path) {
82
+ if (!isObject(d)) return [shape(path, "A dimension is an object.")];
83
+ const kind = d["kind"];
84
+ if (typeof kind !== "string" || !known(DIMENSION_KINDS, kind)) return [shape([...path, "kind"], `"${String(kind)}" is not a dimension kind: ${oneOf(DIMENSION_KINDS)}.`)];
85
+ const missing = needs(d, DIMENSION_NEEDS[kind] ?? [], path);
86
+ if (missing.length > 0) return missing;
87
+ if (kind === "time") return storageShape(d["storage"], [...path, "storage"]);
88
+ return [];
89
+ }
90
+ /** Every member of every source whose shape is wrong, before any check reads it. */
91
+ function shapeIssues(model) {
92
+ const sources = model.sources;
93
+ if (!isObject(sources)) return [shape(["sources"], "A model's sources are an object, by name.")];
94
+ return Object.entries(sources).flatMap(([name, source]) => {
95
+ const path = ["sources", name];
96
+ if (!isObject(source)) return [shape(path, "A source is an object.")];
97
+ const measures = isObject(source["measures"]) ? source["measures"] : {};
98
+ const dimensions = isObject(source["dimensions"]) ? source["dimensions"] : {};
99
+ return [
100
+ ...needs({
101
+ kind: "source",
102
+ ...source
103
+ }, [
104
+ "in",
105
+ "key",
106
+ "measures",
107
+ "dimensions"
108
+ ], path),
109
+ ...Object.entries(measures).flatMap(([m, def]) => measureShape(def, [
110
+ ...path,
111
+ "measures",
112
+ m
113
+ ])),
114
+ ...Object.entries(dimensions).flatMap(([d, def]) => dimensionShape(def, [
115
+ ...path,
116
+ "dimensions",
117
+ d
118
+ ])),
119
+ ...hintShape(source, path)
120
+ ];
121
+ });
122
+ }
123
+ /** Each entry of `records.order` is a field and a direction: `["createdAt", "desc"]`. */
124
+ function orderShape(order, path) {
125
+ if (!Array.isArray(order)) return [];
126
+ return order.flatMap((entry, i) => Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string" && (entry[1] === "asc" || entry[1] === "desc") ? [] : [shape([...path, i], "Each order entry is a field and a direction: [\"createdAt\", \"desc\"].")]);
127
+ }
128
+ /** A source's `records` (its lists) and `noun` (its two words), shaped so later checks can read them. */
129
+ function hintShape(source, path) {
130
+ const records = source["records"];
131
+ const noun = source["noun"];
132
+ const list = (key) => isObject(records) && records[key] !== void 0 && !Array.isArray(records[key]) ? [shape([
133
+ ...path,
134
+ "records",
135
+ key
136
+ ], `records.${key} is a list.`)] : [];
137
+ const words = isObject(noun) && typeof noun["one"] === "string" && typeof noun["other"] === "string";
138
+ return [
139
+ ...records === void 0 || isObject(records) ? [] : [shape([...path, "records"], "records is an object: { title, columns, order, key }.")],
140
+ ...list("columns"),
141
+ ...list("order"),
142
+ ...orderShape(isObject(records) ? records["order"] : void 0, [
143
+ ...path,
144
+ "records",
145
+ "order"
146
+ ]),
147
+ ...noun === void 0 || words ? [] : [shape([...path, "noun"], "noun is { one: \"order\", other: \"orders\" }.")]
148
+ ];
149
+ }
150
+ export { shapeIssues };
@@ -1,4 +1,5 @@
1
1
  import { tenantKeys } from "../defaults.mjs";
2
+ import { drillIssues } from "./drill.mjs";
2
3
  import { modelFilterIssues } from "./filter.mjs";
3
4
  import { issue, nameIssues, when } from "./issues.mjs";
4
5
  import { dimensionIssues, measureIssues } from "./members.mjs";
@@ -18,7 +19,8 @@ function sourceIssues(model, name, source) {
18
19
  ...filterIssues(model, name, source, path),
19
20
  ...memberIssues(model, name, source, path),
20
21
  ...timeIssues(source, [...path, "time"]),
21
- ...recordIssues(source, [...path, "records"])
22
+ ...recordIssues(source, [...path, "records"]),
23
+ ...drillIssues(source, path)
22
24
  ];
23
25
  }
24
26
  /** One SELECT, optionally behind WITH; a trailing semicolon is allowed, none inside. */
@@ -122,7 +124,7 @@ function recordIssues(source, path) {
122
124
  const def = source.dimensions?.[column];
123
125
  return when(def?.sensitive === true || def?.hidden === true, "RECORD_COLUMN_SENSITIVE", at, `"${column}" is ${def?.sensitive === true ? "sensitive" : "hidden"}, so the records cannot show or be ordered by it: they are shown to everyone who sees the tile.`);
124
126
  };
125
- return [...records.columns.flatMap((column, i) => [...unknown(column, [
127
+ return [...(records.columns ?? []).flatMap((column, i) => [...unknown(column, [
126
128
  ...path,
127
129
  "columns",
128
130
  i
@@ -130,7 +132,7 @@ function recordIssues(source, path) {
130
132
  ...path,
131
133
  "columns",
132
134
  i
133
- ])]), ...records.order.flatMap(([column], i) => [...unknown(column, [
135
+ ])]), ...(records.order ?? []).flatMap(([column], i) => [...unknown(column, [
134
136
  ...path,
135
137
  "order",
136
138
  i
@@ -11,4 +11,10 @@ function aliasPart(alias) {
11
11
  index
12
12
  };
13
13
  }
14
- export { aliasPart };
14
+ /** A line's alias (`m1`, `c2`) read from text, as a drill names the line clicked; undefined for anything else. */
15
+ function lineAlias(text) {
16
+ if (!/^[mc][1-9]\d*$/u.test(text)) return void 0;
17
+ const n = Number(text.slice(1));
18
+ return text.startsWith("m") ? `m${n}` : `c${n}`;
19
+ }
20
+ export { aliasPart, lineAlias };
@@ -0,0 +1,22 @@
1
+ import { Model } from "../../model/types.mjs";
2
+ import { WireQuery } from "../types.mjs";
3
+ import { Readable } from "./fields.mjs";
4
+ import { DrillClock } from "./time.mjs";
5
+ import { Drill } from "./types.mjs";
6
+ export type DrillInput = {
7
+ model: Model;
8
+ /** The tile's query as composed: its filters, picks and range already in it. */
9
+ query: WireQuery;
10
+ drill: Drill;
11
+ readable: Readable;
12
+ clock: DrillClock;
13
+ };
14
+ /**
15
+ * The rows behind a drill, as a query with no grouping: the tile's own query (its filters,
16
+ * picks, range and measures) with each step's values ANDed on as filters and its time windows
17
+ * narrowing the range. The lock, required filters, tenancy and row rules travel apart, as for
18
+ * the tile. A calc that reads around its row (a total, a bucket, the period before) is left
19
+ * out: on rows with no grouping it would read the wrong scope. The server evaluates it from
20
+ * each scope's own read (`drillScopes`).
21
+ */
22
+ export declare function composeDrill(input: DrillInput): WireQuery;
@@ -0,0 +1,85 @@
1
+ import { EngineError } from "../../error/refusal.mjs";
2
+ import { drillableMembers } from "./fields.mjs";
3
+ import { aroundCalcs } from "./scopes.mjs";
4
+ import { stepMembers } from "./steps.mjs";
5
+ import { drilledTime } from "./time.mjs";
6
+ import "./types.mjs";
7
+ // src/query/drill/compose.ts
8
+ const refuse = (message) => {
9
+ throw new EngineError("SELECTION_INVALID", message);
10
+ };
11
+ /** One field at one value; no value is the rows where it is not set. */
12
+ function equalsLeaf(member, value) {
13
+ return value === null ? {
14
+ member,
15
+ op: "notSet",
16
+ values: []
17
+ } : {
18
+ member,
19
+ op: "equals",
20
+ values: [value]
21
+ };
22
+ }
23
+ /** The rows in none of the kept groups. */
24
+ function otherFilter(other) {
25
+ return { not: { any: other.kept.map((tuple) => {
26
+ if (tuple.length !== other.members.length) refuse("A kept group has one value per field.");
27
+ return { all: other.members.map((member, i) => equalsLeaf(member, tuple[i] ?? null)) };
28
+ }) } };
29
+ }
30
+ /** Every field the tile groups by, and every field of its source a drill may step on. */
31
+ function allowedMembers(input) {
32
+ const grouped = (input.query.dimensions ?? []).map((d) => d.member);
33
+ return /* @__PURE__ */ new Set([...grouped, ...drillableMembers(input.model, input.query.source, input.readable)]);
34
+ }
35
+ /** The filter one step adds; a field the tile neither groups by nor can be broken down by is refused. */
36
+ function stepFilter(step, allowed) {
37
+ if ("bucket" in step) return void 0;
38
+ const members = stepMembers(step);
39
+ if (members.length === 0) refuse("A step names at least one field.");
40
+ const bad = members.find((m) => !allowed.has(m));
41
+ if (bad !== void 0) refuse(`"${bad}" is not a field this tile can be drilled by.`);
42
+ if ("group" in step) return { all: step.group.map((g) => equalsLeaf(g.member, g.value)) };
43
+ if ("search" in step) return {
44
+ member: step.search.member,
45
+ op: "contains",
46
+ values: [step.search.text]
47
+ };
48
+ return otherFilter(step.other);
49
+ }
50
+ /** The line a drill reads: `m1` and the like; one line's tile needs none named. */
51
+ function checkLine(query, drill) {
52
+ const calc = query.calc ?? [];
53
+ const known = [...query.measures.map((m) => m.id), ...calc.map((c) => c.id)];
54
+ if (drill.measure === void 0 && query.measures.length + calc.length > 1) refuse("This tile has more than one line: name the one clicked (measure).");
55
+ if (drill.measure !== void 0 && !known.includes(drill.measure)) refuse(`The tile has no line "${drill.measure}" to drill.`);
56
+ }
57
+ /**
58
+ * The rows behind a drill, as a query with no grouping: the tile's own query (its filters,
59
+ * picks, range and measures) with each step's values ANDed on as filters and its time windows
60
+ * narrowing the range. The lock, required filters, tenancy and row rules travel apart, as for
61
+ * the tile. A calc that reads around its row (a total, a bucket, the period before) is left
62
+ * out: on rows with no grouping it would read the wrong scope. The server evaluates it from
63
+ * each scope's own read (`drillScopes`).
64
+ */
65
+ function composeDrill(input) {
66
+ const { query, drill } = input;
67
+ if (drill.steps.length > 8) refuse(`A path is at most 8 steps.`);
68
+ const allowed = allowedMembers(input);
69
+ const added = drill.steps.flatMap((step) => stepFilter(step, allowed) ?? []);
70
+ const parts = [...query.filters === void 0 ? [] : [query.filters], ...added];
71
+ const [only, ...more] = parts;
72
+ const around = aroundCalcs(query);
73
+ const calc = (query.calc ?? []).filter((c) => !around.has(c.id));
74
+ checkLine(query, drill);
75
+ const time = drilledTime(input.model, query, drill.steps, input.clock);
76
+ return {
77
+ kind: query.kind,
78
+ source: query.source,
79
+ measures: query.measures,
80
+ ...calc.length === 0 ? {} : { calc },
81
+ ...only === void 0 ? {} : { filters: more.length === 0 ? only : { all: parts } },
82
+ ...time === void 0 ? {} : { time }
83
+ };
84
+ }
85
+ export { composeDrill };
@@ -0,0 +1,21 @@
1
+ import { DimensionDef, Model } from "../../model/types.mjs";
2
+ import { WireFilter } from "../filter.mjs";
3
+ import { WireQuery } from "../types.mjs";
4
+ /** Which members a viewer may see in a drill; the server's answer for sensitive members. */
5
+ export type Readable = (member: string, def: DimensionDef) => boolean;
6
+ /**
7
+ * The fields Breakdown offers at a step: every drill field but those the path fixes or the line's
8
+ * measure fixes. A field the tile groups by is offered where the path does not fix it (its total,
9
+ * a number tile's root), so a total breaks down by the tile's own groups. Under Other, the field Other was cut on comes first:
10
+ * breaking it down again shows the long tail.
11
+ */
12
+ export declare function offeredMembers(model: Model, query: WireQuery, path: {
13
+ fixed: readonly string[];
14
+ other: readonly string[];
15
+ where?: WireFilter | undefined;
16
+ }, readable: Readable): string[];
17
+ /**
18
+ * The time field Over time uses: the tile's own, else the source's default, else its first. A
19
+ * field the tile does not group by must be one a drill may read; else there is none.
20
+ */
21
+ export declare function trendDimension(model: Model, query: WireQuery): string | undefined;
@@ -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;