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
@@ -33,6 +33,226 @@ export declare function coreEndpoints(rt: Runtime): {
33
33
  version: number;
34
34
  requestId: string;
35
35
  }, import("derive-dashboards/core").Published, "POST">;
36
+ drill: import("derive-dashboards/core").DashEndpoint<"/dashboards/drill", {
37
+ state: {
38
+ origin: {
39
+ kind: "dashboard";
40
+ dashboardId: string;
41
+ widgetId: string;
42
+ picks: Record<string, string | number | boolean | {
43
+ op: "set" | "equals" | "in" | "contains" | "startsWith" | "gt" | "gte" | "lt" | "lte" | "between" | "notEquals" | "notIn" | "notContains" | "notSet";
44
+ values: readonly (string | number | boolean | null)[];
45
+ } | {
46
+ last: number;
47
+ unit: "hour" | "day" | "week" | "month" | "quarter" | "year";
48
+ includeCurrent: boolean;
49
+ } | {
50
+ from: string;
51
+ to: string;
52
+ } | null>;
53
+ query?: string;
54
+ document?: {
55
+ version: number;
56
+ } | {
57
+ draft: true;
58
+ };
59
+ } | {
60
+ kind: "query";
61
+ query: {
62
+ kind: "aggregate";
63
+ source: string;
64
+ measures: readonly {
65
+ id: `m${number}`;
66
+ measure: string;
67
+ filter?: import("derive-dashboards/core").WireFilter;
68
+ label?: string;
69
+ }[];
70
+ dimensions?: readonly {
71
+ id: `d${number}`;
72
+ member: string;
73
+ limit?: number;
74
+ other?: boolean;
75
+ rankBy?: {
76
+ by: `m${number}` | `c${number}`;
77
+ dir: "asc" | "desc";
78
+ };
79
+ }[];
80
+ time?: {
81
+ dimension: string;
82
+ range: {
83
+ last: number;
84
+ unit: "hour" | "day" | "week" | "month" | "quarter" | "year";
85
+ includeCurrent: boolean;
86
+ } | {
87
+ from: string;
88
+ to: string;
89
+ };
90
+ grain?: "hour" | "day" | "week" | "month" | "quarter" | "year";
91
+ compare?: "previous_period" | "previous_year";
92
+ };
93
+ filters?: import("derive-dashboards/core").WireFilter;
94
+ calc?: readonly {
95
+ id: `c${number}`;
96
+ formula: import("derive-dashboards/core").FormulaNode;
97
+ format?: "number" | "percent" | "currency" | "duration";
98
+ label?: string;
99
+ }[];
100
+ order?: readonly {
101
+ by: `m${number}` | `c${number}` | `d${number}`;
102
+ dir: "asc" | "desc";
103
+ }[];
104
+ limit?: number;
105
+ other?: boolean;
106
+ total?: boolean;
107
+ fill?: "zero" | "none";
108
+ };
109
+ };
110
+ execution: string;
111
+ path: readonly string[];
112
+ view: {
113
+ by: "breakdown";
114
+ member?: string;
115
+ search?: string;
116
+ } | {
117
+ by: "trend";
118
+ grain?: "hour" | "day" | "week" | "month" | "quarter" | "year";
119
+ } | {
120
+ by: "items";
121
+ numerator?: true;
122
+ } | {
123
+ by: "explanation";
124
+ };
125
+ entry?: string;
126
+ views?: readonly ({
127
+ by: "breakdown";
128
+ member?: string;
129
+ search?: string;
130
+ } | {
131
+ by: "trend";
132
+ grain?: "hour" | "day" | "week" | "month" | "quarter" | "year";
133
+ } | {
134
+ by: "items";
135
+ numerator?: true;
136
+ } | {
137
+ by: "explanation";
138
+ })[];
139
+ };
140
+ page?: {
141
+ after?: string;
142
+ limit?: number;
143
+ };
144
+ summary?: false;
145
+ }, import("derive-dashboards/core").DrillAnswer, "POST">;
146
+ queryDrill: import("derive-dashboards/core").DashEndpoint<"/query/drill", {
147
+ state: {
148
+ origin: {
149
+ kind: "dashboard";
150
+ dashboardId: string;
151
+ widgetId: string;
152
+ picks: Record<string, string | number | boolean | {
153
+ op: "set" | "equals" | "in" | "contains" | "startsWith" | "gt" | "gte" | "lt" | "lte" | "between" | "notEquals" | "notIn" | "notContains" | "notSet";
154
+ values: readonly (string | number | boolean | null)[];
155
+ } | {
156
+ last: number;
157
+ unit: "hour" | "day" | "week" | "month" | "quarter" | "year";
158
+ includeCurrent: boolean;
159
+ } | {
160
+ from: string;
161
+ to: string;
162
+ } | null>;
163
+ query?: string;
164
+ document?: {
165
+ version: number;
166
+ } | {
167
+ draft: true;
168
+ };
169
+ } | {
170
+ kind: "query";
171
+ query: {
172
+ kind: "aggregate";
173
+ source: string;
174
+ measures: readonly {
175
+ id: `m${number}`;
176
+ measure: string;
177
+ filter?: import("derive-dashboards/core").WireFilter;
178
+ label?: string;
179
+ }[];
180
+ dimensions?: readonly {
181
+ id: `d${number}`;
182
+ member: string;
183
+ limit?: number;
184
+ other?: boolean;
185
+ rankBy?: {
186
+ by: `m${number}` | `c${number}`;
187
+ dir: "asc" | "desc";
188
+ };
189
+ }[];
190
+ time?: {
191
+ dimension: string;
192
+ range: {
193
+ last: number;
194
+ unit: "hour" | "day" | "week" | "month" | "quarter" | "year";
195
+ includeCurrent: boolean;
196
+ } | {
197
+ from: string;
198
+ to: string;
199
+ };
200
+ grain?: "hour" | "day" | "week" | "month" | "quarter" | "year";
201
+ compare?: "previous_period" | "previous_year";
202
+ };
203
+ filters?: import("derive-dashboards/core").WireFilter;
204
+ calc?: readonly {
205
+ id: `c${number}`;
206
+ formula: import("derive-dashboards/core").FormulaNode;
207
+ format?: "number" | "percent" | "currency" | "duration";
208
+ label?: string;
209
+ }[];
210
+ order?: readonly {
211
+ by: `m${number}` | `c${number}` | `d${number}`;
212
+ dir: "asc" | "desc";
213
+ }[];
214
+ limit?: number;
215
+ other?: boolean;
216
+ total?: boolean;
217
+ fill?: "zero" | "none";
218
+ };
219
+ };
220
+ execution: string;
221
+ path: readonly string[];
222
+ view: {
223
+ by: "breakdown";
224
+ member?: string;
225
+ search?: string;
226
+ } | {
227
+ by: "trend";
228
+ grain?: "hour" | "day" | "week" | "month" | "quarter" | "year";
229
+ } | {
230
+ by: "items";
231
+ numerator?: true;
232
+ } | {
233
+ by: "explanation";
234
+ };
235
+ entry?: string;
236
+ views?: readonly ({
237
+ by: "breakdown";
238
+ member?: string;
239
+ search?: string;
240
+ } | {
241
+ by: "trend";
242
+ grain?: "hour" | "day" | "week" | "month" | "quarter" | "year";
243
+ } | {
244
+ by: "items";
245
+ numerator?: true;
246
+ } | {
247
+ by: "explanation";
248
+ })[];
249
+ };
250
+ page?: {
251
+ after?: string;
252
+ limit?: number;
253
+ };
254
+ summary?: false;
255
+ }, import("derive-dashboards/core").DrillAnswer, "POST">;
36
256
  queryRun: import("derive-dashboards/core").DashEndpoint<"/query/run", {
37
257
  query: {
38
258
  kind: "aggregate";
@@ -82,7 +302,18 @@ export declare function coreEndpoints(rt: Runtime): {
82
302
  total?: boolean;
83
303
  fill?: "zero" | "none";
84
304
  };
85
- }, Answered, "POST">;
305
+ }, Omit<Answered, "cuts"> | {
306
+ drill: import("derive-dashboards/core").AnswerDrill;
307
+ compare?: {
308
+ rows: import("derive-dashboards/core").ResultRows;
309
+ range: import("derive-dashboards/core").ResolvedRange;
310
+ };
311
+ rows: import("derive-dashboards/core").ResultRows;
312
+ columns: readonly import("derive-dashboards/core").ResultColumn[];
313
+ status: "complete" | "truncated";
314
+ receipt: import("derive-dashboards/core").Receipt;
315
+ unreadable?: true;
316
+ }, "POST">;
86
317
  queryBatch: import("derive-dashboards/core").DashEndpoint<"/query/batch", {
87
318
  queries: {
88
319
  kind: "aggregate";
@@ -141,7 +372,7 @@ export declare function coreEndpoints(rt: Runtime): {
141
372
  } | {
142
373
  i: number;
143
374
  ok: true;
144
- result: Answered;
375
+ result: Omit<Answered, "cuts">;
145
376
  }, any, any>, "POST">;
146
377
  queryRecords: import("derive-dashboards/core").DashEndpoint<"/query/records", {
147
378
  query: {
@@ -1,5 +1,6 @@
1
1
  import { dashboardEndpoints } from "./dashboards.mjs";
2
2
  import { draftEndpoints } from "./drafts.mjs";
3
+ import { drillEndpoints } from "./drill.mjs";
3
4
  import { metaEndpoints } from "./meta.mjs";
4
5
  import { queryEndpoints } from "./query.mjs";
5
6
  import { readEndpoints } from "./read.mjs";
@@ -17,7 +18,10 @@ function coreEndpoints(rt) {
17
18
  ...draftEndpoints(rt),
18
19
  ...reviewEndpoints(rt)
19
20
  };
20
- const query = queryEndpoints(rt);
21
+ const query = {
22
+ ...queryEndpoints(rt),
23
+ ...drillEndpoints(rt)
24
+ };
21
25
  const history = versionEndpoints(rt);
22
26
  const names = [
23
27
  meta,
@@ -1,6 +1,8 @@
1
1
  import { authorizeFree } from "../authorize.mjs";
2
2
  import { bodies, parseWith } from "../body.mjs";
3
- import { execute, executeRecords } from "../execute.mjs";
3
+ import { issueDrill } from "../drill-seal.mjs";
4
+ import { execute, wire } from "../execute.mjs";
5
+ import { executeRecords } from "../records-read.mjs";
4
6
  import { calendarOf, nowOf, userOf } from "../request.mjs";
5
7
  import { concurrencyOf, streamLines } from "../tiles.mjs";
6
8
  import { createDashEndpoint, queryClosure, recordDimensions } from "derive-dashboards/core";
@@ -24,6 +26,26 @@ async function freeExecution(rt, principal, request, query) {
24
26
  }
25
27
  };
26
28
  }
29
+ /** A free query's answer, with what a click on each of its rows drills into. */
30
+ async function runFree(rt, principal, request, query) {
31
+ const x = await freeExecution(rt, principal, request, query);
32
+ const answer = await execute(x);
33
+ const drill = await issueDrill({
34
+ rt,
35
+ principal: x.principal,
36
+ origin: {
37
+ kind: "query",
38
+ query
39
+ }
40
+ }, answer, {
41
+ query,
42
+ now: x.now
43
+ });
44
+ return drill === void 0 ? wire(answer) : {
45
+ ...wire(answer),
46
+ drill
47
+ };
48
+ }
27
49
  /** Free queries: the widget builder's preview, an agent's question. A different grant from viewing a dashboard. */
28
50
  function queryEndpoints(rt) {
29
51
  return {
@@ -31,14 +53,14 @@ function queryEndpoints(rt) {
31
53
  method: "POST",
32
54
  access: { kind: "signed_in" },
33
55
  parse: (input) => parseWith(bodies.query, input, "QUERY_INVALID"),
34
- handler: async ({ body, principal, request }) => execute(await freeExecution(rt, principal, request, body.query))
56
+ handler: ({ body, principal, request }) => runFree(rt, principal, request, body.query)
35
57
  }),
36
58
  queryBatch: createDashEndpoint("/query/batch", {
37
59
  method: "POST",
38
60
  access: { kind: "signed_in" },
39
61
  respond: "ndjson",
40
62
  parse: (input) => parseWith(bodies.queryBatch, input, "QUERY_INVALID"),
41
- handler: ({ body, principal, request }) => streamLines(body.queries.map((q) => async () => execute(await freeExecution(rt, principal, request, q))), concurrencyOf(rt))
63
+ handler: ({ body, principal, request }) => streamLines(body.queries.map((q) => async () => wire(await execute(await freeExecution(rt, principal, request, q)))), concurrencyOf(rt))
42
64
  }),
43
65
  queryRecords: createDashEndpoint("/query/records", {
44
66
  method: "POST",
@@ -69,4 +91,4 @@ function queryEndpoints(rt) {
69
91
  })
70
92
  };
71
93
  }
72
- export { queryEndpoints };
94
+ export { freeExecution, queryEndpoints };
@@ -1,10 +1,28 @@
1
+ import "./reading.mjs";
1
2
  import { Cache } from "./cache.mjs";
2
- import { DashOptions, Principal, Result, WireQuery } from "derive-dashboards/core";
3
+ import { cursorKey, macKey } from "./cursor-seal.mjs";
4
+ import { Cuts, DashOptions, Model, Principal, Result, WireQuery } from "derive-dashboards/core";
5
+ import "derive-dashboards/core/engine";
3
6
  /** The runtime's state for one handler: its options and its result cache. */
4
7
  export type Runtime = {
5
8
  options: DashOptions;
6
9
  cache: Cache | undefined;
10
+ /** Seals records cursors and a drill's parts (`cursor-seal`). */
11
+ cursorKey: ReturnType<typeof cursorKey>;
12
+ /** Signs what must be stable and unreadable: a hidden item id, a viewer's access fingerprint. */
13
+ macKey: ReturnType<typeof macKey>;
14
+ /** The model a drill reads (`drillModel`), built once. */
15
+ drillModel: Model;
16
+ /** Whether the missing-`secret` warning was given, so it is given once. */
17
+ warned: {
18
+ secret: boolean;
19
+ };
7
20
  };
21
+ /**
22
+ * An answer as the server keeps it: with what each dimension's own limit kept (`cuts`), which a
23
+ * drill reads its Other from. `cuts` never leaves the server (`wire`).
24
+ */
8
25
  export type Answered = Result & {
9
26
  unreadable?: true;
27
+ cuts?: Cuts;
10
28
  };
package/dist/execute.mjs CHANGED
@@ -1,12 +1,17 @@
1
1
  import { checkSensitive } from "./authorize.mjs";
2
- import { manifest, sha256 } from "./cache.mjs";
2
+ import { manifest } from "./cache.mjs";
3
+ import { macHex } from "./cursor-seal.mjs";
3
4
  import { adapterFor } from "./dashboards.mjs";
4
5
  import { withReader } from "./reading.mjs";
5
6
  import { logQuery } from "./store/log.mjs";
6
- import { canonical, isBound, markedRows, recordColumns, resultColumns } from "derive-dashboards/core";
7
- import { EngineError, readQuery, readRecords } from "derive-dashboards/core/engine";
7
+ import { canonical, isBound, markedRows, resultColumns } from "derive-dashboards/core";
8
+ import { EngineError, readQuery } from "derive-dashboards/core/engine";
8
9
  // src/execute.ts
9
- const DEFAULT_QUANTUM = 60;
10
+ /** An answer as a client reads it: without what only the server reads. */
11
+ function wire(answer) {
12
+ const { cuts: _cuts, ...rest } = answer;
13
+ return rest;
14
+ }
10
15
  function boundEntries(entries, what) {
11
16
  return entries.map((entry) => {
12
17
  if (!isBound(entry.filter)) throw new EngineError("FILTER_UNBOUND", `A ${what} that uses a viewer value or a variable is not supported yet.`);
@@ -46,7 +51,7 @@ function bind(x) {
46
51
  now: x.now,
47
52
  calendar: x.calendar,
48
53
  maxRows,
49
- quantumSeconds: options.cache?.quantum ?? DEFAULT_QUANTUM
54
+ quantumSeconds: options.cache?.quantum ?? 60
50
55
  },
51
56
  lock,
52
57
  required,
@@ -65,6 +70,7 @@ async function compute(x, bound) {
65
70
  const started = performance.now();
66
71
  const computedAt = (/* @__PURE__ */ new Date()).toISOString();
67
72
  const { value, consistency, custom } = await reading(x, bound.maxRows, (reader) => readQuery(bound.input, reader));
73
+ const cuts = value.cuts === void 0 ? {} : { cuts: value.cuts };
68
74
  const { truncated, unreadable, compare, ...levels } = value.answer;
69
75
  const warnings = truncated === true ? [{
70
76
  code: "ROW_CAP",
@@ -80,8 +86,9 @@ async function compute(x, bound) {
80
86
  } },
81
87
  status: truncated === true ? "truncated" : "complete",
82
88
  ...unreadable === true ? { unreadable } : {},
89
+ ...cuts,
83
90
  receipt: {
84
- queryHash: await sha256(canonical({
91
+ queryHash: await macHex(await x.rt.macKey, canonical({
85
92
  query: x.query,
86
93
  lock: bound.lock,
87
94
  required: bound.required
@@ -126,7 +133,7 @@ function answered(x) {
126
133
  const bound = bind(x);
127
134
  const { cache, options } = x.rt;
128
135
  if (cache === void 0) return compute(x, bound);
129
- const quantum = (options.cache?.quantum ?? DEFAULT_QUANTUM) * 1e3;
136
+ const quantum = (options.cache?.quantum ?? 60) * 1e3;
130
137
  const on = [...bound.lock, ...bound.required].map((e) => e.on);
131
138
  const key = {
132
139
  principal: x.principal,
@@ -140,13 +147,4 @@ function answered(x) {
140
147
  };
141
148
  return cache.answer(key, () => compute(x, bound));
142
149
  }
143
- /** A page of the rows behind a query, under the same access, filters and range as its answer. */
144
- async function executeRecords(x, page) {
145
- const bound = bind(x);
146
- const { value } = await reading(x, page.limit, (reader) => readRecords(bound.input, page, reader));
147
- return {
148
- ...value,
149
- columns: recordColumns(x.rt.options.model, x.query.source, value.columns)
150
- };
151
- }
152
- export { execute, executeRecords };
150
+ export { bind, execute, reading, wire };
package/dist/index.d.mts CHANGED
@@ -6,7 +6,7 @@ import { PostgresConnectionOptions, RunSql, postgresConnection } from "./postgre
6
6
  import { PostgresStoreOptions, RunRows, postgresStore } from "./postgres-store.mjs";
7
7
  import { memoryStorage } from "./storage.mjs";
8
8
  import { SchemaDiff, SchemaMismatchError, createTables, schemaDiff } from "./store/create-tables.mjs";
9
- import { Awaitable, Dash, DashOptions, UniqueIds, ViewerFor } from "derive-dashboards/core";
9
+ import { Awaitable, Dash, DashOptions, ItemLinksFor, UniqueIds, ViewerFor } from "derive-dashboards/core";
10
10
  /** What `deriveDashboards` returns: `api` calls every endpoint; `$Infer.Endpoints` types a client. */
11
11
  export type DashServer<O extends DashOptions> = Dash<O, ReturnType<typeof coreEndpoints>>;
12
12
  /**
@@ -20,5 +20,7 @@ export declare function deriveDashboards<const O extends DashOptions>(options: O
20
20
  plugins?: UniqueIds<O["plugins"]>;
21
21
  /** Typed from the model: with tenant keys, the viewer must carry a value for each. */
22
22
  viewer: (request: Request) => Awaitable<ViewerFor<O["model"]> | null>;
23
+ /** Typed from the model: a template per source, and no source the model lacks. */
24
+ itemLinks?: ItemLinksFor<O["model"], O["itemLinks"]>;
23
25
  }): DashServer<O>;
24
26
  export { type CustomSourceOptions, HttpError, type PgPool, type PgQueryable, type PostgresConnectionOptions, type PostgresStoreOptions, type RunRows, type RunSql, type SchemaDiff, SchemaMismatchError, createTables, customSource, memoryStorage, nodePostgres, postgresConnection, postgresStore, schemaDiff };
package/dist/index.mjs CHANGED
@@ -1,4 +1,6 @@
1
1
  import { createCache } from "./cache.mjs";
2
+ import { cursorKey, macKey } from "./cursor-seal.mjs";
3
+ import { warnSecretAtStart } from "./drill-secret.mjs";
2
4
  import { coreEndpoints } from "./endpoints/index.mjs";
3
5
  import { createHandler, serverCall } from "./handler.mjs";
4
6
  import { HttpError } from "./http.mjs";
@@ -9,7 +11,8 @@ import { postgresConnection } from "./postgres-connection.mjs";
9
11
  import { postgresStore } from "./postgres-store.mjs";
10
12
  import { memoryStorage } from "./storage.mjs";
11
13
  import { SchemaMismatchError, createTables, schemaDiff } from "./store/create-tables.mjs";
12
- import { BASE_ERROR_CODES, defineModel } from "derive-dashboards/core";
14
+ import { BASE_ERROR_CODES, defineModel, linkTemplateIssues } from "derive-dashboards/core";
15
+ import { drillModel } from "derive-dashboards/core/engine";
13
16
  import { loadDocument } from "derive-dashboards/core/schema";
14
17
  // src/index.ts
15
18
  /**
@@ -54,6 +57,24 @@ function checkPluginIds(options, taken) {
54
57
  function isStream(output) {
55
58
  return typeof output === "object" && output !== null && typeof Reflect.get(output, Symbol.asyncIterator) === "function";
56
59
  }
60
+ /**
61
+ * Each `itemLinks` template names a source of the model and only parts its items have: `{id}`,
62
+ * or `{key.<column>}` for a column of the source's key. A misspelled source or column would
63
+ * otherwise only show as links that never appear: refuse to start.
64
+ */
65
+ /**
66
+ * Each `itemLinks` template names a source of the model and is one core's link filler reads:
67
+ * it starts with "/" or a scheme, and names only {id} and {key.<column>} of that source's key. A
68
+ * misspelling would otherwise only show as links that never appear: refuse to start.
69
+ */
70
+ function checkItemLinks(options) {
71
+ for (const [source, template] of Object.entries(options.itemLinks ?? {})) {
72
+ const def = options.model.sources[source];
73
+ if (def === void 0) throw new Error(`itemLinks names "${source}", which is not a source of the model.`);
74
+ const [problem] = linkTemplateIssues(template, def.key);
75
+ if (problem !== void 0) throw new Error(`itemLinks.${source} ${problem}`);
76
+ }
77
+ }
57
78
  /** One endpoint by path; a streamed answer is read to its end and comes back as its lines. */
58
79
  async function callPath(byPath, path, input) {
59
80
  const call = byPath.get(path);
@@ -74,14 +95,20 @@ async function callPath(byPath, path, input) {
74
95
  function deriveDashboards(options) {
75
96
  defineModel(options.model);
76
97
  checkConnections(options);
98
+ checkItemLinks(options);
77
99
  const checked = {
78
100
  ...options,
79
101
  dashboards: checkedDashboards(options)
80
102
  };
81
103
  const rt = {
82
104
  options: checked,
83
- cache: createCache(checked)
105
+ cache: createCache(checked),
106
+ cursorKey: cursorKey(options.secret),
107
+ macKey: macKey(options.secret),
108
+ drillModel: drillModel(checked.model),
109
+ warned: { secret: false }
84
110
  };
111
+ warnSecretAtStart(rt);
85
112
  const library = coreEndpoints(rt);
86
113
  checkPluginIds(options, ["cache", ...Object.keys(library)]);
87
114
  const plugins = options.plugins ?? [];
@@ -0,0 +1,61 @@
1
+ import { ok, table } from "./format.mjs";
2
+ import { itemLink } from "derive-dashboards/core";
3
+ // src/mcp/drill.ts
4
+ /** A value as text: a plain value as itself, an exact number by its digits. */
5
+ const text = (cell) => typeof cell === "object" && cell !== null ? cell.v : String(cell);
6
+ /** One breadcrumb in words: Other only for an Other step, "not set" for a group with no value. */
7
+ function crumbText(p) {
8
+ if (p.parts !== void 0) return p.parts.map((q) => crumbText(q)).join(", ");
9
+ if (p.kind === "other") return `${p.label}: Other`;
10
+ if (p.kind === "search") return `${p.label} contains "${text(p.value ?? "")}"`;
11
+ if (p.kind === "total") return "Total";
12
+ return `${p.label}: ${p.value === null ? "not set" : text(p.value)}`;
13
+ }
14
+ /** What the answer is about, in one line: how many rows, behind which path. */
15
+ function heading(answer, shown) {
16
+ const where = answer.path.map((p) => crumbText(p)).join(" › ");
17
+ return `${text(answer.summary?.itemCount ?? shown)} rows behind ${where === "" ? "the tile" : where}`;
18
+ }
19
+ /** The drill's answer, asked as the agent's person: of a dashboard's tile, or of a free query. */
20
+ function ask(c, drill, page) {
21
+ const body = {
22
+ state: {
23
+ ...drill,
24
+ view: { by: "items" }
25
+ },
26
+ page: {
27
+ limit: page.limit ?? 50,
28
+ ...page.after === void 0 ? {} : { after: page.after }
29
+ }
30
+ };
31
+ return drill.origin.kind === "dashboard" ? c.dashboards.api.drill({
32
+ body,
33
+ viewer: c.viewer
34
+ }) : c.dashboards.api.queryDrill({
35
+ body,
36
+ viewer: c.viewer
37
+ });
38
+ }
39
+ /**
40
+ * The rows behind one mark, for an agent: the same drill a person opens, with the same checks,
41
+ * as a table of its items, each with its link in the host's app when `itemLinks` gives one.
42
+ */
43
+ async function drillRows(c, drill, page) {
44
+ const answer = await ask(c, drill, page);
45
+ const view = answer.view.by === "items" ? answer.view : void 0;
46
+ const items = (view?.items ?? []).map((item) => ({
47
+ ...item,
48
+ link: item.link ?? itemLink(c.itemLinks, item)
49
+ }));
50
+ const columns = view?.columns ?? [];
51
+ const labels = [...columns.map((col) => col.label), "Link"];
52
+ const rows = items.map((item) => [...columns.map((col) => item.values[col.member] ?? null), item.link ?? ""]);
53
+ return ok(`${heading(answer, items.length)}\n\n${table(labels, rows)}`, {
54
+ ...answer,
55
+ view: {
56
+ ...view,
57
+ items
58
+ }
59
+ });
60
+ }
61
+ export { drillRows };
@@ -1,4 +1,5 @@
1
1
  import { HttpError } from "../http.mjs";
2
+ import { EngineError } from "derive-dashboards/core/engine";
2
3
  // src/mcp/format.ts
3
4
  /** The most rows a table shows the model; the rest are counted, and all are in the structured answer. */
4
5
  const SHOWN = 30;
@@ -40,9 +41,32 @@ const ok = (text, data) => ({
40
41
  }],
41
42
  ...data === void 0 ? {} : { structuredContent: { result: data } }
42
43
  });
43
- /** A refusal the model can act on: the code, the reason, each problem with the input, and a hint. */
44
- function refused(error, hint) {
45
- if (!(error instanceof HttpError)) throw error;
44
+ /**
45
+ * A refusal the model can act on: the code, the reason, each problem with the input, and a hint.
46
+ * An engine refusal keeps its code; anything else goes to `onError` and the model reads only
47
+ * INTERNAL, never a database's own message, which can name columns or echo stored values.
48
+ */
49
+ function refused(error, hint, onError = (e) => {
50
+ console.error(e);
51
+ }) {
52
+ if (error instanceof EngineError) return {
53
+ content: [{
54
+ type: "text",
55
+ text: `${error.code}: ${error.message}`
56
+ }],
57
+ isError: true
58
+ };
59
+ if (!(error instanceof HttpError)) {
60
+ onError(error);
61
+ return {
62
+ content: [{
63
+ type: "text",
64
+ text: "INTERNAL: Something went wrong answering this. It was logged."
65
+ }],
66
+ isError: true
67
+ };
68
+ }
69
+ if (error.cause !== void 0) onError(error.cause);
46
70
  const issues = (error.issues ?? []).map((i) => `- ${i.path.join(".") || "input"}: ${i.message}`);
47
71
  return {
48
72
  content: [{
@@ -1,6 +1,6 @@
1
1
  import { ApiServer } from "./api.mjs";
2
2
  import { ToolResult } from "./format.mjs";
3
- import { Viewer } from "derive-dashboards/core";
3
+ import { ItemLinks, Viewer, ViewerFor } from "derive-dashboards/core";
4
4
  import { z } from "zod";
5
5
  /** MCP's tool annotations: what a client may assume about a tool before it runs it. */
6
6
  export type ToolAnnotations = {
@@ -29,6 +29,10 @@ export type DashboardToolsOptions = {
29
29
  api?: boolean;
30
30
  /** The link to a dashboard in your app, given with every dashboard the agent opens. */
31
31
  linkFor?: (dashboardId: string) => string;
32
+ /** Where each source's items open in your app; by default the server's own `itemLinks`. */
33
+ itemLinks?: ItemLinks;
34
+ /** Where an unexpected error goes (its message never reaches the model); the console without one. */
35
+ onError?: (error: unknown) => void;
32
36
  };
33
37
  /** The two tools, as plain data: `name`, `description`, `inputSchema` (Zod), `annotations`, `run(input, viewer)`. */
34
38
  export declare function dashboardTools(dashboards: ApiServer, options?: DashboardToolsOptions): DashboardTool[];
@@ -51,11 +55,18 @@ export type McpServerLike = {
51
55
  annotations?: ToolAnnotations;
52
56
  }, callback: (input: Record<string, unknown>, extra: McpCallExtra) => Promise<ToolResult>): unknown;
53
57
  };
58
+ /** The model a dashboards server was made with, when its type says; else any. */
59
+ type ModelOf<S> = S extends {
60
+ options: {
61
+ model: infer M;
62
+ };
63
+ } ? M : unknown;
54
64
  /**
55
65
  * Adds the two tools to an MCP server you already run. `viewer` reads the person from the
56
- * call (`extra.authInfo` from your MCP auth); none refuses the call.
66
+ * call (`extra.authInfo` from your MCP auth); none refuses the call. It is typed from the
67
+ * server's model, as `deriveDashboards`'s own `viewer` is: with tenant keys, each is required.
57
68
  */
58
- export declare function addDashboardTools(server: McpServerLike, dashboards: ApiServer, options: DashboardToolsOptions & {
59
- viewer: (extra: McpCallExtra) => Viewer | null | Promise<Viewer | null>;
69
+ export declare function addDashboardTools<S extends ApiServer>(server: McpServerLike, dashboards: S, options: DashboardToolsOptions & {
70
+ viewer: (extra: McpCallExtra) => ViewerFor<ModelOf<S>> | null | Promise<ViewerFor<ModelOf<S>> | null>;
60
71
  }): void;
61
72
  export type { ToolResult };