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.
- package/README.md +4 -3
- package/dist/adapter/sql-adapter.mjs +4 -4
- package/dist/body.mjs +11 -1
- package/dist/cache.d.mts +1 -1
- package/dist/cli/check.mjs +14 -1
- package/dist/cli/import/dbt-schema.mjs +2 -2
- package/dist/cli/import/index.mjs +2 -2
- package/dist/core/conformance/cases.d.mts +3 -0
- package/dist/core/conformance/cases.mjs +20 -4
- package/dist/core/conformance/check.mjs +6 -3
- package/dist/core/conformance/drill-cases.mjs +120 -0
- package/dist/core/document/view.d.mts +26 -7
- package/dist/core/document/view.mjs +42 -11
- package/dist/core/engine/index.d.mts +14 -2
- package/dist/core/engine/index.mjs +12 -1
- package/dist/core/engine/members.mjs +1 -1
- package/dist/core/engine/postgres.mjs +1 -1
- package/dist/core/engine/record-layout.d.mts +11 -0
- package/dist/core/engine/record-layout.mjs +7 -7
- package/dist/core/engine/records.d.mts +3 -2
- package/dist/core/engine/records.mjs +2 -1
- package/dist/core/engine/segmented.mjs +5 -2
- package/dist/core/engine/sql-records.mjs +2 -1
- package/dist/core/engine/statement.mjs +37 -3
- package/dist/core/engine/types.d.mts +3 -0
- package/dist/core/engine/version.d.mts +1 -1
- package/dist/core/engine/version.mjs +1 -1
- package/dist/core/error/codes.d.mts +31 -0
- package/dist/core/error/codes.mjs +28 -1
- package/dist/core/index.d.mts +9 -5
- package/dist/core/index.mjs +5 -3
- package/dist/core/model/catalog/check.mjs +1 -1
- package/dist/core/model/hints.d.mts +36 -0
- package/dist/core/model/member.d.mts +4 -2
- package/dist/core/model/member.mjs +16 -3
- package/dist/core/model/types.d.mts +8 -6
- package/dist/core/model/validate/drill.mjs +70 -0
- package/dist/core/model/validate/index.mjs +3 -0
- package/dist/core/model/validate/shape.mjs +150 -0
- package/dist/core/model/validate/source.mjs +5 -3
- package/dist/core/query/alias.mjs +7 -1
- package/dist/core/query/drill/compose.d.mts +22 -0
- package/dist/core/query/drill/compose.mjs +85 -0
- package/dist/core/query/drill/fields.d.mts +21 -0
- package/dist/core/query/drill/fields.mjs +91 -0
- package/dist/core/query/drill/internal.d.mts +11 -0
- package/dist/core/query/drill/items.d.mts +29 -0
- package/dist/core/query/drill/items.mjs +98 -0
- package/dist/core/query/drill/line.d.mts +31 -0
- package/dist/core/query/drill/line.mjs +183 -0
- package/dist/core/query/drill/links.d.mts +33 -0
- package/dist/core/query/drill/links.mjs +31 -0
- package/dist/core/query/drill/operand.mjs +7 -0
- package/dist/core/query/drill/scopes.d.mts +22 -0
- package/dist/core/query/drill/scopes.mjs +58 -0
- package/dist/core/query/drill/selection.d.mts +37 -0
- package/dist/core/query/drill/selection.mjs +144 -0
- package/dist/core/query/drill/steps.d.mts +14 -0
- package/dist/core/query/drill/steps.mjs +35 -0
- package/dist/core/query/drill/synthetic-expr.mjs +85 -0
- package/dist/core/query/drill/synthetic.d.mts +22 -0
- package/dist/core/query/drill/synthetic.mjs +165 -0
- package/dist/core/query/drill/time.d.mts +11 -0
- package/dist/core/query/drill/time.mjs +71 -0
- package/dist/core/query/drill/types.d.mts +155 -0
- package/dist/core/query/drill/types.mjs +4 -0
- package/dist/core/query/drill/views.d.mts +62 -0
- package/dist/core/query/drill/views.mjs +257 -0
- package/dist/core/query/segments.d.mts +12 -2
- package/dist/core/query/segments.mjs +3 -1
- package/dist/core/result/columns.mjs +17 -4
- package/dist/core/result/types.d.mts +5 -1
- package/dist/core/schema/answer-parts.mjs +117 -0
- package/dist/core/schema/answers.d.mts +2108 -128
- package/dist/core/schema/answers.mjs +10 -113
- package/dist/core/schema/commands.d.mts +2 -2
- package/dist/core/schema/document.d.mts +1 -1
- package/dist/core/schema/drill-answers.mjs +179 -0
- package/dist/core/schema/drill.d.mts +260 -0
- package/dist/core/schema/drill.mjs +107 -0
- package/dist/core/schema/index.d.mts +4 -2
- package/dist/core/schema/index.mjs +4 -2
- package/dist/core/schema/picks.d.mts +35 -0
- package/dist/core/schema/picks.mjs +23 -0
- package/dist/core/schema/query.d.mts +1 -1
- package/dist/core/schema/tools.mjs +1 -1
- package/dist/core/schema/view.d.mts +0 -35
- package/dist/core/schema/view.mjs +19 -24
- package/dist/core/store/schema.d.mts +5 -0
- package/dist/core/store/schema.mjs +10 -0
- package/dist/core/types/api.d.mts +15 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/core/types/drill-api.d.mts +210 -0
- package/dist/core/types/options.d.mts +21 -0
- package/dist/core/types/viewer.d.mts +5 -0
- package/dist/cursor-seal.d.mts +8 -0
- package/dist/cursor-seal.mjs +98 -0
- package/dist/dashboard-id.mjs +1 -1
- package/dist/drill-access.mjs +93 -0
- package/dist/drill-change.mjs +76 -0
- package/dist/drill-crumbs.mjs +113 -0
- package/dist/drill-distinct.mjs +130 -0
- package/dist/drill-explain.mjs +64 -0
- package/dist/drill-identity.mjs +35 -0
- package/dist/drill-item-id.mjs +35 -0
- package/dist/drill-items.mjs +132 -0
- package/dist/drill-open.mjs +169 -0
- package/dist/drill-seal.mjs +170 -0
- package/dist/drill-secret.mjs +14 -0
- package/dist/drill-share.mjs +53 -0
- package/dist/drill-summary.mjs +158 -0
- package/dist/drill-targets.mjs +53 -0
- package/dist/drill-totals.mjs +8 -0
- package/dist/drill-views.mjs +175 -0
- package/dist/drill.mjs +157 -0
- package/dist/editing.mjs +2 -2
- package/dist/endpoints/dashboards.mjs +11 -3
- package/dist/endpoints/drill.mjs +55 -0
- package/dist/endpoints/index.d.mts +233 -2
- package/dist/endpoints/index.mjs +5 -1
- package/dist/endpoints/query.mjs +26 -4
- package/dist/execute.d.mts +19 -1
- package/dist/execute.mjs +15 -17
- package/dist/index.d.mts +3 -1
- package/dist/index.mjs +29 -2
- package/dist/mcp/drill.mjs +61 -0
- package/dist/mcp/format.mjs +27 -3
- package/dist/mcp/index.d.mts +15 -4
- package/dist/mcp/index.mjs +13 -7
- package/dist/mcp/query.d.mts +7 -2
- package/dist/mcp/query.mjs +7 -3
- package/dist/node-postgres.d.mts +8 -4
- package/dist/node-postgres.mjs +29 -6
- package/dist/owner.mjs +3 -3
- package/dist/postgres-connection.d.mts +8 -2
- package/dist/postgres-connection.mjs +2 -1
- package/dist/react/Dashboard.d.mts +10 -5
- package/dist/react/Dashboard.mjs +51 -23
- package/dist/react/DashboardList.mjs +30 -2
- package/dist/react/Discard.mjs +7 -2
- package/dist/react/Grid.mjs +12 -5
- package/dist/react/Header.mjs +9 -0
- package/dist/react/Parts.mjs +6 -2
- package/dist/react/ReviewPanel.mjs +13 -2
- package/dist/react/RowBody.d.mts +19 -0
- package/dist/react/RowBody.mjs +55 -0
- package/dist/react/Tile.d.mts +1 -1
- package/dist/react/Tile.mjs +54 -30
- package/dist/react/builder/state.d.mts +1 -1
- package/dist/react/client.d.mts +2 -0
- package/dist/react/client.mjs +1 -0
- package/dist/react/context.d.mts +15 -1
- package/dist/react/context.mjs +19 -4
- package/dist/react/drill/Bars.mjs +179 -0
- package/dist/react/drill/Controls.mjs +173 -0
- package/dist/react/drill/DashboardTile.d.mts +18 -0
- package/dist/react/drill/DashboardTile.mjs +107 -0
- package/dist/react/drill/DrillPanel.d.mts +31 -0
- package/dist/react/drill/DrillPanel.mjs +104 -0
- package/dist/react/drill/DrillTabs.mjs +52 -0
- package/dist/react/drill/Header.mjs +131 -0
- package/dist/react/drill/Items.d.mts +22 -0
- package/dist/react/drill/Items.mjs +164 -0
- package/dist/react/drill/ItemsFoot.mjs +60 -0
- package/dist/react/drill/Notes.mjs +58 -0
- package/dist/react/drill/PanelBody.mjs +74 -0
- package/dist/react/drill/PanelStates.mjs +37 -0
- package/dist/react/drill/board.d.mts +18 -0
- package/dist/react/drill/board.mjs +91 -0
- package/dist/react/drill/counts.mjs +14 -0
- package/dist/react/drill/host.mjs +26 -0
- package/dist/react/drill/item-parts.d.mts +5 -0
- package/dist/react/drill/item-parts.mjs +76 -0
- package/dist/react/drill/item-type.d.mts +26 -0
- package/dist/react/drill/item-type.mjs +7 -0
- package/dist/react/drill/lazy.d.mts +6 -0
- package/dist/react/drill/lazy.mjs +17 -0
- package/dist/react/drill/pages.mjs +48 -0
- package/dist/react/drill/panel-focus.mjs +51 -0
- package/dist/react/drill/props.d.mts +25 -0
- package/dist/react/drill/props.mjs +72 -0
- package/dist/react/drill/state.d.mts +18 -0
- package/dist/react/drill/state.mjs +68 -0
- package/dist/react/drill/useDrill.d.mts +46 -0
- package/dist/react/drill/useDrill.mjs +194 -0
- package/dist/react/drill/words.d.mts +98 -0
- package/dist/react/drill/words.mjs +77 -0
- package/dist/react/english.mjs +9 -1
- package/dist/react/format.d.mts +3 -3
- package/dist/react/format.mjs +34 -12
- package/dist/react/index.d.mts +27 -4
- package/dist/react/index.mjs +10 -3
- package/dist/react/messages.d.mts +14 -1
- package/dist/react/renderers/index.d.mts +10 -2
- package/dist/react/renderers/index.mjs +54 -14
- package/dist/react/renderers/list.d.mts +22 -0
- package/dist/react/renderers/list.mjs +118 -0
- package/dist/react/review-words.mjs +1 -1
- package/dist/react/review.mjs +2 -2
- package/dist/react/scope.mjs +2 -7
- package/dist/react/series.d.mts +37 -0
- package/dist/react/series.mjs +95 -0
- package/dist/react/theme.css +1823 -1296
- package/dist/react/theme.css.d.ts +1 -0
- package/dist/react/tile-store.mjs +15 -3
- package/dist/react/useBoard.d.mts +5 -0
- package/dist/react/useBoard.mjs +4 -1
- package/dist/react/useDashboard.d.mts +1 -0
- package/dist/react/useDashboard.mjs +2 -1
- package/dist/react/useTiles.mjs +50 -15
- package/dist/react/view.d.mts +9 -0
- package/dist/react/view.mjs +22 -10
- package/dist/reading.d.mts +2 -0
- package/dist/reading.mjs +9 -1
- package/dist/recharts/charts.d.mts +0 -1
- package/dist/recharts/charts.mjs +128 -34
- package/dist/recharts/index.d.mts +2 -2
- package/dist/recharts/index.mjs +2 -2
- package/dist/recharts/marks.mjs +83 -0
- package/dist/recharts/series.d.mts +2 -22
- package/dist/recharts/series.mjs +1 -64
- package/dist/records-read.mjs +44 -0
- package/dist/store/apply.mjs +5 -5
- package/dist/store/commands.mjs +4 -4
- package/dist/store/discard.mjs +7 -7
- package/dist/store/drafts.mjs +5 -5
- package/dist/store/editor.mjs +1 -1
- package/dist/store/publish.mjs +12 -12
- package/dist/store/reader.mjs +41 -22
- package/dist/store/review.mjs +16 -16
- package/dist/store/rows.mjs +20 -20
- package/dist/store/undo.mjs +3 -3
- package/dist/store/unpublished.mjs +4 -4
- package/dist/store/versions.mjs +14 -14
- package/dist/testing/adapter-suite.mjs +4 -4
- package/dist/tiles.mjs +37 -3
- package/package.json +8 -10
- package/dist/react/Records.d.mts +0 -12
- package/dist/react/Records.mjs +0 -97
- package/src/adapter/sql-adapter.ts +0 -95
- package/src/adapter/statement.ts +0 -185
- package/src/authorize.ts +0 -73
- package/src/body.ts +0 -169
- package/src/bounded.ts +0 -43
- package/src/cache.ts +0 -192
- package/src/checks.ts +0 -170
- package/src/custom-source.ts +0 -59
- package/src/dashboard-id.ts +0 -36
- package/src/dashboards.ts +0 -132
- package/src/editing.ts +0 -148
- package/src/endpoints/access.ts +0 -41
- package/src/endpoints/dashboards.ts +0 -92
- package/src/endpoints/drafts.ts +0 -138
- package/src/endpoints/index.ts +0 -21
- package/src/endpoints/meta.ts +0 -137
- package/src/endpoints/query.ts +0 -86
- package/src/endpoints/read.ts +0 -92
- package/src/endpoints/review.ts +0 -89
- package/src/endpoints/values.ts +0 -62
- package/src/endpoints/versions.ts +0 -104
- package/src/execute.ts +0 -207
- package/src/handler.ts +0 -232
- package/src/http.ts +0 -66
- package/src/index.ts +0 -163
- package/src/introspect.ts +0 -205
- package/src/mcp/api.ts +0 -59
- package/src/mcp/format.ts +0 -67
- package/src/mcp/index.ts +0 -151
- package/src/mcp/query.ts +0 -153
- package/src/mcp/resolve.ts +0 -114
- package/src/node-postgres.ts +0 -81
- package/src/owner.ts +0 -36
- package/src/postgres-connection.ts +0 -143
- package/src/postgres-store.ts +0 -82
- package/src/principal.ts +0 -39
- package/src/reading.ts +0 -56
- package/src/request-rows.ts +0 -23
- package/src/request.ts +0 -22
- package/src/storage.ts +0 -63
- package/src/store/apply.ts +0 -129
- package/src/store/commands.ts +0 -75
- package/src/store/conflicts.ts +0 -98
- package/src/store/create-tables.ts +0 -104
- package/src/store/discard.ts +0 -42
- package/src/store/drafts.ts +0 -133
- package/src/store/editor.ts +0 -28
- package/src/store/log.ts +0 -28
- package/src/store/publish.ts +0 -199
- package/src/store/publisher.ts +0 -21
- package/src/store/reader.ts +0 -139
- package/src/store/review.ts +0 -239
- package/src/store/rows.ts +0 -250
- package/src/store/tenant.ts +0 -28
- package/src/store/undo.ts +0 -56
- package/src/store/unpublished.ts +0 -33
- package/src/store/versions.ts +0 -106
- package/src/store/writer.ts +0 -19
- package/src/testing/adapter-suite.ts +0 -239
- package/src/testing/index.ts +0 -2
- package/src/tile-doc.ts +0 -46
- package/src/tiles.ts +0 -120
package/README.md
CHANGED
|
@@ -7,7 +7,8 @@ dashboards inside your app, and every query runs under your access rules: your t
|
|
|
7
7
|
row rules when you have them, nothing extra when you do not.
|
|
8
8
|
|
|
9
9
|
> **Status: early (0.x).** On Postgres, dashboards
|
|
10
|
-
> defined in code, filters,
|
|
10
|
+
> defined in code, filters, drill-in (a click on a bar, a point, a row or a number opens what is
|
|
11
|
+
> behind it: broken down, over time, or as its items, each a link into your app), the widget builder and editing a
|
|
11
12
|
> dashboard (a draft per person, drag and resize, undo and redo, review before publish, merging
|
|
12
13
|
> over someone else's version), new dashboards, version history with in-place preview and
|
|
13
14
|
> Restore, shareable links, and agents that edit and publish as themselves work end to
|
|
@@ -34,8 +35,8 @@ Embedded dashboards on Postgres, end to end, run by the Acme Tasks sample (`exam
|
|
|
34
35
|
| --- | --- |
|
|
35
36
|
| `derive-dashboards/core` | No I/O and no framework. The model (`defineModel`, `validateModel`), typed member ids, filters and queries, the access kernel (`effectiveFilter`), composition, the oracle every engine must match, the Postgres engine (`/engine`), the document and its schema (`/schema`), and the store's tables as data. |
|
|
36
37
|
| `derive-dashboards` | `deriveDashboards(options)`: a fetch handler for every endpoint, a Postgres source and store for any driver, the result cache, the query log, `createTables`, and the store contract suite (`/testing`). |
|
|
37
|
-
| `derive-dashboards/react` | `Dashboard` with edit mode (Edit, + Add widget, drag and resize, a change count with undo and redo, review before publish, History with in-place preview, Share), `DashboardList` with + New dashboard, `useDraft` and `useReview` for your own edit and review UI, `FilterBar`, `Tile`,
|
|
38
|
-
| `derive-dashboards/recharts` | Line and bar tiles, drawn with Recharts (install `recharts` to use them; any other chart library plugs into `renderers`). |
|
|
38
|
+
| `derive-dashboards/react` | `Dashboard` with edit mode (Edit, + Add widget, drag and resize, a change count with undo and redo, review before publish, History with in-place preview, Share), `DashboardList` with + New dashboard, `useDraft` and `useReview` for your own edit and review UI, `FilterBar`, `Tile`, drill-in (`DrillPanel`, `DashboardTile`, `useDrill`, and `toSeries` and `rowAt` for any chart kit), the widget builder (`WidgetBuilder`, `useBuilder`) and `theme.css`. |
|
|
39
|
+
| `derive-dashboards/recharts` | Line and bar tiles, drawn with Recharts, each mark a drill (install `recharts` to use them; any other chart library plugs into `renderers`). |
|
|
39
40
|
| `derive-dashboards/mcp` | Two tools for the MCP server you already run (`addDashboardTools`): `dashboards_query` to ask and read, `dashboards_api` for everything else. See [MCP](https://github.com/derive-to/dashboards/blob/main/docs/mcp.md). |
|
|
40
41
|
| `derive-dashboards/cli` | `defineConfig` for `derive-dashboards.config.ts`; the `derive-dashboards` command runs `init`, `check`, `generate`, `create-tables`. |
|
|
41
42
|
|
|
@@ -55,7 +55,7 @@ function adapterOver(id, runner) {
|
|
|
55
55
|
},
|
|
56
56
|
async count({ table, where }) {
|
|
57
57
|
const [row] = await runner.run(count(dialect, table, where ?? []));
|
|
58
|
-
return Number(row?.
|
|
58
|
+
return Number(row?.n ?? 0);
|
|
59
59
|
},
|
|
60
60
|
transaction: (fn) => runner.transaction((tx) => fn(adapterOver(id, tx))),
|
|
61
61
|
classifyError(error) {
|
|
@@ -70,9 +70,9 @@ function adapterOver(id, runner) {
|
|
|
70
70
|
strings: [CATALOG[dialect]],
|
|
71
71
|
values: []
|
|
72
72
|
})).map((row) => ({
|
|
73
|
-
table: text(row
|
|
74
|
-
column: text(row
|
|
75
|
-
...row
|
|
73
|
+
table: text(row.table),
|
|
74
|
+
column: text(row.column),
|
|
75
|
+
...row.schema === void 0 ? {} : { schema: text(row.schema) }
|
|
76
76
|
}))
|
|
77
77
|
}
|
|
78
78
|
};
|
package/dist/body.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpError } from "./http.mjs";
|
|
2
|
-
import { commandSchema, jsonSchema, picksSchema, wireQuerySchema } from "derive-dashboards/core/schema";
|
|
2
|
+
import { commandSchema, drillStateSchema, jsonSchema, picksSchema, wireQuerySchema } from "derive-dashboards/core/schema";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
// src/body.ts
|
|
5
5
|
/** The request bodies every endpoint checks before anything reads them. Unknown keys are refused. */
|
|
@@ -46,6 +46,14 @@ const bodies = {
|
|
|
46
46
|
...tileRef,
|
|
47
47
|
...page
|
|
48
48
|
}),
|
|
49
|
+
drill: z.strictObject({
|
|
50
|
+
state: drillStateSchema,
|
|
51
|
+
page: z.strictObject({
|
|
52
|
+
after: page.after,
|
|
53
|
+
limit: z.int().min(1).max(200).exactOptional()
|
|
54
|
+
}).exactOptional(),
|
|
55
|
+
summary: z.literal(false).exactOptional()
|
|
56
|
+
}),
|
|
49
57
|
controlValues: z.strictObject({
|
|
50
58
|
dashboardId: id,
|
|
51
59
|
controlId: id,
|
|
@@ -122,6 +130,8 @@ const BODIES_BY_PATH = {
|
|
|
122
130
|
"/dashboards/tile": bodies.tile,
|
|
123
131
|
"/dashboards/tiles": bodies.tiles,
|
|
124
132
|
"/dashboards/records": bodies.records,
|
|
133
|
+
"/dashboards/drill": bodies.drill,
|
|
134
|
+
"/query/drill": bodies.drill,
|
|
125
135
|
"/dashboards/control-values": bodies.controlValues,
|
|
126
136
|
"/dashboards/new": bodies.newDashboard,
|
|
127
137
|
"/dashboards/draft/start": bodies.dashboard,
|
package/dist/cache.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Answered } from "./execute.mjs";
|
|
2
|
-
import { DashOptions, Principal, SourceName, WireQuery } from "derive-dashboards/core";
|
|
2
|
+
import { DashOptions, Model, Principal, SourceName, WireQuery } from "derive-dashboards/core";
|
|
3
3
|
/** What decides an answer, besides the rows: everything that goes into its cache key. */
|
|
4
4
|
type CacheKey = {
|
|
5
5
|
principal: Principal;
|
package/dist/cli/check.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { checkCatalog, describeQueries, validateModel } from "derive-dashboards/core";
|
|
1
|
+
import { checkCatalog, describeQueries, recordDimensions, validateModel } from "derive-dashboards/core";
|
|
2
2
|
// src/check.ts
|
|
3
3
|
const introspects = (c) => "introspect" in c;
|
|
4
4
|
/**
|
|
@@ -35,6 +35,17 @@ async function partIssues(part) {
|
|
|
35
35
|
const described = await describeQueries(part.model, part.connection, await part.connection.introspect());
|
|
36
36
|
return [...described.issues, ...checkCatalog(part.model, described.schema)];
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* The columns a drill's Items list shows for each source: the model's `records.columns`, or the
|
|
40
|
+
* default the library picks (the key, then up to four shown fields), so a host sees it before a user does.
|
|
41
|
+
*/
|
|
42
|
+
function itemsColumns(model) {
|
|
43
|
+
return Object.entries(model.sources).map(([name, def]) => {
|
|
44
|
+
const columns = recordDimensions(model, name);
|
|
45
|
+
const from = def.records?.columns === void 0 ? "default" : "records.columns";
|
|
46
|
+
return ` ${name}: ${columns.length === 0 ? "(none)" : columns.join(", ")} (${from})`;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
38
49
|
const describeIssue = (i) => ` ${i.code} ${i.path.join(".")}: ${i.message}`;
|
|
39
50
|
/**
|
|
40
51
|
* Proves a model against the config's databases and prints every problem: the exit code is 0
|
|
@@ -46,6 +57,8 @@ async function checkModel(config, model, io) {
|
|
|
46
57
|
const checked = await Promise.all(parts.map((part) => partIssues(part)));
|
|
47
58
|
const issues = [...validateModel(model), ...checked.flat()];
|
|
48
59
|
for (const issue of issues) io.err(describeIssue(issue));
|
|
60
|
+
io.out("Items columns:");
|
|
61
|
+
for (const line of itemsColumns(model)) io.out(line);
|
|
49
62
|
io.out(issues.length === 0 ? "The model matches the database." : `${issues.length} problems.`);
|
|
50
63
|
return issues.length === 0 ? 0 : 1;
|
|
51
64
|
}
|
|
@@ -49,14 +49,14 @@ const Input = z.union([z.string().transform((name) => ({
|
|
|
49
49
|
filter: void 0
|
|
50
50
|
})), z.object({
|
|
51
51
|
name: z.string(),
|
|
52
|
-
filter: z.unknown()
|
|
52
|
+
filter: z.unknown().optional()
|
|
53
53
|
})]);
|
|
54
54
|
const Metric = z.object({
|
|
55
55
|
name: z.string(),
|
|
56
56
|
type: z.string(),
|
|
57
57
|
label: text,
|
|
58
58
|
description: text,
|
|
59
|
-
filter: z.unknown(),
|
|
59
|
+
filter: z.unknown().optional(),
|
|
60
60
|
type_params: z.object({
|
|
61
61
|
measure: opt(Input),
|
|
62
62
|
numerator: opt(Input),
|
|
@@ -22,7 +22,7 @@ async function manifestPath(path) {
|
|
|
22
22
|
async function readDbt(path) {
|
|
23
23
|
const file = await manifestPath(path);
|
|
24
24
|
const parsed = ManifestSchema.safeParse(JSON.parse(await readFile(file, "utf8")));
|
|
25
|
-
if (!parsed.success) throw new Error(`${file} is not a dbt semantic manifest
|
|
25
|
+
if (!parsed.success) throw new Error(`${file} is not a dbt semantic manifest:\n${parsed.error.issues.map((i) => ` ${i.path.map(String).join(".") || "(top)"}: ${i.message}`).join("\n")}`);
|
|
26
26
|
return importDbt(parsed.data);
|
|
27
27
|
}
|
|
28
28
|
const YAML = /* @__PURE__ */ new Set([".yml", ".yaml"]);
|
|
@@ -48,7 +48,7 @@ async function cubeFile(file, name) {
|
|
|
48
48
|
return parsed.success ? {
|
|
49
49
|
cubes: [parsed.data],
|
|
50
50
|
notes: []
|
|
51
|
-
} : skipped(`Not imported: ${name}, which is not a Cube model (${parsed.error.issues
|
|
51
|
+
} : skipped(`Not imported: ${name}, which is not a Cube model (${parsed.error.issues.slice(0, 3).map((i) => `${i.path.map(String).join(".") || "(top)"}: ${i.message}`).join("; ")}).`);
|
|
52
52
|
} catch (error) {
|
|
53
53
|
return skipped(`Not imported: ${name}, which does not parse as YAML (templated?): ${error instanceof Error ? error.message : String(error)}`);
|
|
54
54
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Model } from "../model/types.mjs";
|
|
1
2
|
import { LockEntry } from "../query/compose.mjs";
|
|
2
3
|
import { BoundFilter } from "../query/filter.mjs";
|
|
3
4
|
import { Calendar, WireQuery } from "../query/types.mjs";
|
|
@@ -9,4 +10,6 @@ export type KitCase = {
|
|
|
9
10
|
principal: Principal;
|
|
10
11
|
locks: readonly LockEntry<BoundFilter>[];
|
|
11
12
|
calendar: Calendar;
|
|
13
|
+
/** The model the case reads: the dataset's when absent, the drill's widened one for a drill. */
|
|
14
|
+
model?: Model;
|
|
12
15
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DRILL_MODEL, DRILL_QUERIES } from "./drill-cases.mjs";
|
|
1
2
|
import { QUERIES } from "./queries.mjs";
|
|
2
3
|
// src/conformance/cases.ts
|
|
3
4
|
const viewer = (id, org, roles) => ({
|
|
@@ -69,9 +70,9 @@ const CALENDARS = {
|
|
|
69
70
|
fiscalYearStartMonth: 4
|
|
70
71
|
}
|
|
71
72
|
};
|
|
72
|
-
/**
|
|
73
|
-
function
|
|
74
|
-
return Object.entries(
|
|
73
|
+
/** Each query, by every principal, under each lock that applies, in each calendar given. */
|
|
74
|
+
function casesOf(queries, calendars) {
|
|
75
|
+
return Object.entries(queries).flatMap(([queryName, query]) => Object.entries(PRINCIPALS).flatMap(([who, principal]) => Object.entries(locksFor(query.source)).flatMap(([lockName, locks]) => Object.entries(calendars).map(([zone, calendar]) => ({
|
|
75
76
|
name: `${queryName}, asked by ${who}${lockName}${zone}`,
|
|
76
77
|
query,
|
|
77
78
|
principal,
|
|
@@ -79,4 +80,19 @@ function kitCases() {
|
|
|
79
80
|
calendar
|
|
80
81
|
})))));
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
+
/** Every query, by every principal, under each lock that applies, in each calendar. */
|
|
84
|
+
function kitCases() {
|
|
85
|
+
return casesOf(QUERIES, CALENDARS);
|
|
86
|
+
}
|
|
87
|
+
/** Every read a drill sends, by every principal, under each lock that applies, in UTC. */
|
|
88
|
+
function drillKitCases() {
|
|
89
|
+
return casesOf(DRILL_QUERIES, { "": {
|
|
90
|
+
timezone: "UTC",
|
|
91
|
+
weekStart: 1,
|
|
92
|
+
fiscalYearStartMonth: 1
|
|
93
|
+
} }).map((c) => ({
|
|
94
|
+
...c,
|
|
95
|
+
model: DRILL_MODEL
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
export { drillKitCases, kitCases };
|
|
@@ -2,7 +2,7 @@ import { customReader } from "../engine/custom/reader.mjs";
|
|
|
2
2
|
import { readQuery } from "../engine/segmented.mjs";
|
|
3
3
|
import { evaluate } from "../oracle/segmented.mjs";
|
|
4
4
|
import { canonical } from "../value/canonical.mjs";
|
|
5
|
-
import { kitCases } from "./cases.mjs";
|
|
5
|
+
import { drillKitCases, kitCases } from "./cases.mjs";
|
|
6
6
|
import { DATASET } from "./dataset.mjs";
|
|
7
7
|
import { pagingCase, recordsCase } from "./records-cases.mjs";
|
|
8
8
|
// src/conformance/check.ts
|
|
@@ -24,7 +24,7 @@ async function settled(run) {
|
|
|
24
24
|
}
|
|
25
25
|
const same = (a, b) => canonical(a) === canonical(b);
|
|
26
26
|
const inputOf = (c, now) => ({
|
|
27
|
-
model: DATASET.model,
|
|
27
|
+
model: c.model ?? DATASET.model,
|
|
28
28
|
query: c.query,
|
|
29
29
|
principal: c.principal,
|
|
30
30
|
locks: c.locks,
|
|
@@ -66,11 +66,14 @@ async function checkConformance(host, options = {}) {
|
|
|
66
66
|
},
|
|
67
67
|
source: host.source
|
|
68
68
|
};
|
|
69
|
-
const
|
|
69
|
+
const drills = drillKitCases();
|
|
70
|
+
const cases = [...kitCases(), ...drills];
|
|
70
71
|
const records = host.source.records === void 0 ? [] : cases.filter((c) => c.query.source === "job" && c.name.startsWith("jobs by status"));
|
|
72
|
+
const pages = host.source.records === void 0 ? [] : drills;
|
|
71
73
|
const results = [];
|
|
72
74
|
for (const c of cases) results.push(await answerCase(c, run));
|
|
73
75
|
for (const c of records) results.push(await recordsCase(c, run), await pagingCase(c, run));
|
|
76
|
+
for (const c of pages) results.push(await pagingCase(c, run));
|
|
74
77
|
const mismatches = results.filter((m) => m !== void 0);
|
|
75
78
|
return {
|
|
76
79
|
cases: results.length,
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { drillModel } from "../query/drill/synthetic.mjs";
|
|
2
|
+
import { deriveModel } from "./dataset-model.mjs";
|
|
3
|
+
// src/conformance/drill-cases.ts
|
|
4
|
+
/** The kit's model with one ratio, so a drill of a ratio has a numerator flag to read. */
|
|
5
|
+
function withRatio(model) {
|
|
6
|
+
const job = model.sources.job;
|
|
7
|
+
if (job === void 0) throw new Error("The kit's model has a job source.");
|
|
8
|
+
const measures = {
|
|
9
|
+
...job.measures,
|
|
10
|
+
done: {
|
|
11
|
+
kind: "count",
|
|
12
|
+
where: {
|
|
13
|
+
member: "job.status",
|
|
14
|
+
op: "equals",
|
|
15
|
+
values: ["done"]
|
|
16
|
+
},
|
|
17
|
+
merge: "sum"
|
|
18
|
+
},
|
|
19
|
+
doneShare: {
|
|
20
|
+
kind: "ratio",
|
|
21
|
+
numerator: "done",
|
|
22
|
+
denominator: "count",
|
|
23
|
+
merge: "none"
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
...model,
|
|
28
|
+
sources: {
|
|
29
|
+
...model.sources,
|
|
30
|
+
job: {
|
|
31
|
+
...job,
|
|
32
|
+
measures
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** The model every drill case reads: the kit's, with a ratio, widened as a drill widens it. */
|
|
38
|
+
const DRILL_MODEL = drillModel(withRatio(deriveModel));
|
|
39
|
+
const q = (source, measures, more = {}) => ({
|
|
40
|
+
kind: "aggregate",
|
|
41
|
+
source,
|
|
42
|
+
measures: measures.map((measure, i) => ({
|
|
43
|
+
id: `m${i + 1}`,
|
|
44
|
+
measure
|
|
45
|
+
})),
|
|
46
|
+
...more
|
|
47
|
+
});
|
|
48
|
+
const by = (member) => ({ dimensions: [{
|
|
49
|
+
id: "d1",
|
|
50
|
+
member
|
|
51
|
+
}] });
|
|
52
|
+
const isTrue = (member) => ({
|
|
53
|
+
member,
|
|
54
|
+
op: "equals",
|
|
55
|
+
values: [true]
|
|
56
|
+
});
|
|
57
|
+
const isSet = (member) => ({
|
|
58
|
+
member,
|
|
59
|
+
op: "set",
|
|
60
|
+
values: []
|
|
61
|
+
});
|
|
62
|
+
const ranked = { order: [{
|
|
63
|
+
by: "m1",
|
|
64
|
+
dir: "desc"
|
|
65
|
+
}, {
|
|
66
|
+
by: "d1",
|
|
67
|
+
dir: "asc"
|
|
68
|
+
}] };
|
|
69
|
+
/** A step on one field: equal to a value, or not set for the empty value. */
|
|
70
|
+
const step = (member, value) => value === null ? {
|
|
71
|
+
member,
|
|
72
|
+
op: "notSet",
|
|
73
|
+
values: []
|
|
74
|
+
} : {
|
|
75
|
+
member,
|
|
76
|
+
op: "equals",
|
|
77
|
+
values: [value]
|
|
78
|
+
};
|
|
79
|
+
/** Other of a limit: the rows in none of the groups it kept. */
|
|
80
|
+
const other = (member, kept) => ({ not: { any: kept.map((v) => ({ all: [step(member, v)] })) } });
|
|
81
|
+
/** The drill reads by name. */
|
|
82
|
+
const DRILL_QUERIES = {
|
|
83
|
+
"drill: a measure's own where is the population": q("comment", ["comment.openThreads", "comment.dd_rows"], {
|
|
84
|
+
...by("comment.artifact.kind"),
|
|
85
|
+
filters: { all: [step("comment.state", "open"), isTrue("comment.dd_set_openThreads")] }
|
|
86
|
+
}),
|
|
87
|
+
"drill: Other of a limit, with a kept empty value, through a join": q("job", ["job.dd_rows", "job.spend"], {
|
|
88
|
+
...by("job.status"),
|
|
89
|
+
filters: other("job.agent.name", [null, "Builder"])
|
|
90
|
+
}),
|
|
91
|
+
"drill: Other of a limit, the empty value in it": q("job", ["job.count"], {
|
|
92
|
+
...by("job.agent.name"),
|
|
93
|
+
filters: other("job.kind", ["ask"])
|
|
94
|
+
}),
|
|
95
|
+
"drill: a ratio's items, flagged by its numerator": q("job", ["job.dd_rows"], { ...by("job.dd_flag_doneShare") }),
|
|
96
|
+
"drill: a distinct count's values, without the empty one, paged": q("view", ["view.dd_rows"], {
|
|
97
|
+
...by("view.dd_distinct_viewers"),
|
|
98
|
+
filters: isSet("view.dd_distinct_viewers"),
|
|
99
|
+
...ranked,
|
|
100
|
+
limit: 2
|
|
101
|
+
}),
|
|
102
|
+
"drill: a distinct count with its own where": q("comment", ["comment.dd_rows"], {
|
|
103
|
+
...by("comment.dd_distinct_openThreads"),
|
|
104
|
+
filters: { all: [step("comment.state", "open"), isSet("comment.dd_distinct_openThreads")] },
|
|
105
|
+
...ranked
|
|
106
|
+
}),
|
|
107
|
+
"drill: a sum's rows with a value, summed exactly, with its least": q("job", [
|
|
108
|
+
"job.spend",
|
|
109
|
+
"job.dd_rows",
|
|
110
|
+
"job.dd_min_spend"
|
|
111
|
+
], { filters: isTrue("job.dd_set_spend") }),
|
|
112
|
+
"drill: each item's value as stored": q("job", ["job.spend"], by("job.dd_value_spend")),
|
|
113
|
+
"drill: rows that tie on their order (versions at one instant)": q("version", ["version.dd_rows"], { filters: step("version.source", "mcp") }),
|
|
114
|
+
"drill: rows that tie on their order (views at one instant)": q("view", ["view.dd_rows"], { filters: {
|
|
115
|
+
member: "view.createdAt",
|
|
116
|
+
op: "set",
|
|
117
|
+
values: []
|
|
118
|
+
} })
|
|
119
|
+
};
|
|
120
|
+
export { DRILL_MODEL, DRILL_QUERIES };
|
|
@@ -1,29 +1,48 @@
|
|
|
1
|
+
import { DrillState } from "../query/drill/types.mjs";
|
|
1
2
|
import { Control, Picks } from "../query/types.mjs";
|
|
2
3
|
import { TabId } from "./types.mjs";
|
|
3
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* What a link carries: the tab open, the filters set, and the drill open. Never who is looking
|
|
6
|
+
* or what they may see: a drill's path is sealed by the server, and every check runs again for
|
|
7
|
+
* the person who opens it. `drill: undefined` says no drill is open; a view with no `drill` key
|
|
8
|
+
* leaves the drill to the dashboard.
|
|
9
|
+
*/
|
|
4
10
|
export type ViewState = {
|
|
5
11
|
tab?: TabId;
|
|
6
12
|
picks: Picks;
|
|
13
|
+
drill?: DrillState | undefined;
|
|
7
14
|
};
|
|
8
15
|
/** The prefix a view's parameters go under by default, beside the host's own. */
|
|
9
16
|
export declare const VIEW_PREFIX = "dd.";
|
|
17
|
+
/** How a view goes into a URL: under which prefix, and whether its drill goes with it. */
|
|
18
|
+
export type EncodeOptions = {
|
|
19
|
+
prefix?: string;
|
|
20
|
+
drill?: "inline" | "omit";
|
|
21
|
+
};
|
|
10
22
|
/**
|
|
11
23
|
* A view as URL search parameters under a prefix (default `dd.`), so a host puts them in its
|
|
12
|
-
* own URL beside its own parameters. Each pick is JSON, so any value round-trips
|
|
24
|
+
* own URL beside its own parameters. Each pick is JSON, so any value round-trips, and so is
|
|
25
|
+
* the drill (`drill: "omit"` leaves it out, for a link to the dashboard alone);
|
|
13
26
|
* `decodeView` (from `derive-dashboards/core/schema`) reads them back.
|
|
14
27
|
*/
|
|
15
|
-
export declare function encodeView(view: ViewState,
|
|
28
|
+
export declare function encodeView(view: ViewState, options?: string | EncodeOptions): [string, string][];
|
|
29
|
+
/**
|
|
30
|
+
* An address's query with the view in it: the host's own parameters kept as they are, the view's
|
|
31
|
+
* (under `prefix`, `dd.` by default) replaced. `withView(location.search, next).toString()`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function withView(search: string | URLSearchParams, view: ViewState, options?: string | EncodeOptions): URLSearchParams;
|
|
16
34
|
/**
|
|
17
|
-
* A view kept to what a dashboard can show: a tab it does not have,
|
|
18
|
-
*
|
|
19
|
-
* left out and named in `dropped
|
|
20
|
-
* rather than shown an error on every tile.
|
|
35
|
+
* A view kept to what a dashboard can show: a tab it does not have, a pick for a filter it does
|
|
36
|
+
* not have or that does not fit that filter (`pickProblem`, the rule the tiles apply), or a
|
|
37
|
+
* drill into a widget it no longer has, is left out and named in `dropped`, so the viewer is
|
|
38
|
+
* told rather than shown an error on every tile.
|
|
21
39
|
*/
|
|
22
40
|
export declare function viewFor(doc: {
|
|
23
41
|
tabs: readonly {
|
|
24
42
|
id: TabId;
|
|
25
43
|
}[];
|
|
26
44
|
controls: readonly Control[];
|
|
45
|
+
widgets?: Readonly<Record<string, unknown>>;
|
|
27
46
|
}, view: ViewState): {
|
|
28
47
|
view: ViewState;
|
|
29
48
|
dropped: string[];
|
|
@@ -5,15 +5,34 @@ const VIEW_PREFIX = "dd.";
|
|
|
5
5
|
/** The parameter names a view uses, under the prefix. */
|
|
6
6
|
const VIEW_KEYS = {
|
|
7
7
|
tab: "tab",
|
|
8
|
-
filter: "f."
|
|
8
|
+
filter: "f.",
|
|
9
|
+
drill: "drill"
|
|
9
10
|
};
|
|
10
11
|
/**
|
|
11
12
|
* A view as URL search parameters under a prefix (default `dd.`), so a host puts them in its
|
|
12
|
-
* own URL beside its own parameters. Each pick is JSON, so any value round-trips
|
|
13
|
+
* own URL beside its own parameters. Each pick is JSON, so any value round-trips, and so is
|
|
14
|
+
* the drill (`drill: "omit"` leaves it out, for a link to the dashboard alone);
|
|
13
15
|
* `decodeView` (from `derive-dashboards/core/schema`) reads them back.
|
|
14
16
|
*/
|
|
15
|
-
function encodeView(view,
|
|
16
|
-
|
|
17
|
+
function encodeView(view, options = {}) {
|
|
18
|
+
const { prefix = "dd.", drill = "inline" } = typeof options === "string" ? { prefix: options } : options;
|
|
19
|
+
const tab = view.tab === void 0 ? [] : [[`${prefix}${VIEW_KEYS.tab}`, view.tab]];
|
|
20
|
+
const pending = view.drill?.path.some((p) => p.includes("#")) === true;
|
|
21
|
+
const drilled = view.drill === void 0 || drill === "omit" || pending ? [] : [[`${prefix}${VIEW_KEYS.drill}`, JSON.stringify(view.drill)]];
|
|
22
|
+
return [
|
|
23
|
+
...tab,
|
|
24
|
+
...drilled,
|
|
25
|
+
...Object.entries(view.picks).map(([id, value]) => [`${prefix}${VIEW_KEYS.filter}${id}`, JSON.stringify(value)])
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* An address's query with the view in it: the host's own parameters kept as they are, the view's
|
|
30
|
+
* (under `prefix`, `dd.` by default) replaced. `withView(location.search, next).toString()`.
|
|
31
|
+
*/
|
|
32
|
+
function withView(search, view, options = {}) {
|
|
33
|
+
const prefix = (typeof options === "string" ? options : options.prefix) ?? "dd.";
|
|
34
|
+
const own = [...new URLSearchParams(search)].filter(([key]) => !key.startsWith(prefix));
|
|
35
|
+
return new URLSearchParams([...own, ...encodeView(view, options)]);
|
|
17
36
|
}
|
|
18
37
|
/** The picks that fit the dashboard's filters, and the names of those that do not. */
|
|
19
38
|
function keptPicks(controls, picks) {
|
|
@@ -29,22 +48,34 @@ function keptPicks(controls, picks) {
|
|
|
29
48
|
dropped
|
|
30
49
|
};
|
|
31
50
|
}
|
|
51
|
+
/** Whether a dashboard can still open a drill: one into a widget it has. */
|
|
52
|
+
function drillFits(doc, drill) {
|
|
53
|
+
if (drill.origin.kind !== "dashboard") return false;
|
|
54
|
+
return doc.widgets === void 0 || Object.hasOwn(doc.widgets, drill.origin.widgetId);
|
|
55
|
+
}
|
|
32
56
|
/**
|
|
33
|
-
* A view kept to what a dashboard can show: a tab it does not have,
|
|
34
|
-
*
|
|
35
|
-
* left out and named in `dropped
|
|
36
|
-
* rather than shown an error on every tile.
|
|
57
|
+
* A view kept to what a dashboard can show: a tab it does not have, a pick for a filter it does
|
|
58
|
+
* not have or that does not fit that filter (`pickProblem`, the rule the tiles apply), or a
|
|
59
|
+
* drill into a widget it no longer has, is left out and named in `dropped`, so the viewer is
|
|
60
|
+
* told rather than shown an error on every tile.
|
|
37
61
|
*/
|
|
38
62
|
function viewFor(doc, view) {
|
|
39
63
|
const tab = doc.tabs.find((t) => t.id === view.tab)?.id;
|
|
40
64
|
const picks = keptPicks(doc.controls, view.picks);
|
|
41
65
|
const lostTab = view.tab === void 0 || tab !== void 0 ? [] : [view.tab];
|
|
66
|
+
const keep = view.drill !== void 0 && drillFits(doc, view.drill);
|
|
67
|
+
const lostDrill = view.drill === void 0 || keep ? [] : [VIEW_KEYS.drill];
|
|
42
68
|
return {
|
|
43
69
|
view: {
|
|
44
70
|
...tab === void 0 ? {} : { tab },
|
|
45
|
-
picks: picks.kept
|
|
71
|
+
picks: picks.kept,
|
|
72
|
+
...keep && view.drill !== void 0 ? { drill: view.drill } : {}
|
|
46
73
|
},
|
|
47
|
-
dropped: [
|
|
74
|
+
dropped: [
|
|
75
|
+
...lostTab,
|
|
76
|
+
...picks.dropped,
|
|
77
|
+
...lostDrill
|
|
78
|
+
]
|
|
48
79
|
};
|
|
49
80
|
}
|
|
50
|
-
export { VIEW_KEYS, VIEW_PREFIX, encodeView, viewFor };
|
|
81
|
+
export { VIEW_KEYS, VIEW_PREFIX, encodeView, viewFor, withView };
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { EngineError, EngineErrorCode } from "../error/refusal.mjs";
|
|
2
2
|
import { Answer, EngineInput, Ran } from "./types.mjs";
|
|
3
|
+
import "../query/drill/internal.mjs";
|
|
4
|
+
import { Readable, offeredMembers, trendDimension } from "../query/drill/fields.mjs";
|
|
5
|
+
import { DrillClock, trendQuery } from "../query/drill/time.mjs";
|
|
6
|
+
import { DrillInput, composeDrill } from "../query/drill/compose.mjs";
|
|
7
|
+
import { LineSemantics, drillMeasure, lineSemantics } from "../query/drill/line.mjs";
|
|
8
|
+
import { ItemsOrder, itemsShape } from "../query/drill/items.mjs";
|
|
9
|
+
import { Scope, formulaParts, lineScopes, measuresOnly, scopeSteps, scopedLines } from "../query/drill/scopes.mjs";
|
|
10
|
+
import { Drawn, Picked, rowSelection } from "../query/drill/selection.mjs";
|
|
11
|
+
import { keptPath, pathFields, stepMembers } from "../query/drill/steps.mjs";
|
|
12
|
+
import { KEY_FIELD, ROW_COUNT, drillModel, drillOwner, flagCell, storedCell } from "../query/drill/synthetic.mjs";
|
|
13
|
+
import { breakdownQuery, countQuery, distinctQuery, lineFilter, parentQuery, population, summaryQuery } from "../query/drill/views.mjs";
|
|
14
|
+
import { limitedDimensions, rankQuery, segmentCuts } from "../query/segments.mjs";
|
|
3
15
|
import { PlanContext, assertPlan } from "./assert.mjs";
|
|
4
16
|
import { customReader } from "./custom/reader.mjs";
|
|
5
17
|
import { CustomSource, GroupedRead, HostCell, HostRows, ReadBucket, ReadContext, ReadExpr, ReadField, ReadFilter, ReadJoin, ReadMeasure, ReadOperand, ReadOrder, ReadTime, ReadValue, RecordsRead } from "./custom/request.mjs";
|
|
6
|
-
import { RecordPage } from "./record-layout.mjs";
|
|
18
|
+
import { RecordPage, RecordShape } from "./record-layout.mjs";
|
|
7
19
|
import { Dialect, SqlType } from "./dialect.mjs";
|
|
8
20
|
import { AccessPlan, AccessTerm, Guard, SourceRef } from "./plan.mjs";
|
|
9
21
|
import { FOLD_FUNCTION, foldFunctionSql, postgres } from "./postgres.mjs";
|
|
@@ -13,4 +25,4 @@ import "./run.mjs";
|
|
|
13
25
|
import { readQuery, runQuery } from "./segmented.mjs";
|
|
14
26
|
import { sqlReader } from "./sql-reader.mjs";
|
|
15
27
|
import { ENGINE_VERSION } from "./version.mjs";
|
|
16
|
-
export { type AccessPlan, type AccessTerm, type Answer, type CustomSource, type Dialect, ENGINE_VERSION, EngineError, type EngineErrorCode, type EngineInput, FOLD_FUNCTION, type GroupedRead, type Guard, type HostCell, type HostRows, type PlanContext, type Ran, type ReadBucket, type ReadContext, type ReadExpr, type ReadField, type ReadFilter, type ReadJoin, type ReadMeasure, type ReadOperand, type ReadOrder, type ReadTime, type ReadValue, type Reader, type RecordPage, type RecordsRead, type SourceRef, type SqlType, assertPlan, customReader, foldFunctionSql, postgres, readQuery, readRecords, runQuery, sqlReader };
|
|
28
|
+
export { type AccessPlan, type AccessTerm, type Answer, type CustomSource, type Dialect, type Drawn, type DrillClock, type DrillInput, ENGINE_VERSION, EngineError, type EngineErrorCode, type EngineInput, FOLD_FUNCTION, type GroupedRead, type Guard, type HostCell, type HostRows, type ItemsOrder, KEY_FIELD, type LineSemantics, type Picked, type PlanContext, ROW_COUNT, type Ran, type ReadBucket, type ReadContext, type ReadExpr, type ReadField, type ReadFilter, type ReadJoin, type ReadMeasure, type ReadOperand, type ReadOrder, type ReadTime, type ReadValue, type Readable, type Reader, type RecordPage, type RecordShape, type RecordsRead, type Scope, type SourceRef, type SqlType, assertPlan, breakdownQuery, composeDrill, countQuery, customReader, distinctQuery, drillMeasure, drillModel, drillOwner, flagCell, foldFunctionSql, formulaParts, itemsShape, keptPath, limitedDimensions, lineFilter, lineScopes, lineSemantics, measuresOnly, offeredMembers, parentQuery, pathFields, population, postgres, rankQuery, readQuery, readRecords, rowSelection, runQuery, scopeSteps, scopedLines, segmentCuts, sqlReader, stepMembers, storedCell, summaryQuery, trendDimension, trendQuery };
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { EngineError } from "../error/refusal.mjs";
|
|
2
|
+
import { limitedDimensions, rankQuery, segmentCuts } from "../query/segments.mjs";
|
|
3
|
+
import { offeredMembers, trendDimension } from "../query/drill/fields.mjs";
|
|
4
|
+
import { formulaParts, lineScopes, measuresOnly, scopeSteps, scopedLines } from "../query/drill/scopes.mjs";
|
|
5
|
+
import { keptPath, pathFields, stepMembers } from "../query/drill/steps.mjs";
|
|
6
|
+
import { trendQuery } from "../query/drill/time.mjs";
|
|
7
|
+
import { composeDrill } from "../query/drill/compose.mjs";
|
|
8
|
+
import { itemsShape } from "../query/drill/items.mjs";
|
|
9
|
+
import { KEY_FIELD, ROW_COUNT, drillModel, drillOwner, flagCell, storedCell } from "../query/drill/synthetic.mjs";
|
|
10
|
+
import { drillMeasure, lineSemantics } from "../query/drill/line.mjs";
|
|
11
|
+
import { rowSelection } from "../query/drill/selection.mjs";
|
|
12
|
+
import { breakdownQuery, countQuery, distinctQuery, lineFilter, parentQuery, population, summaryQuery } from "../query/drill/views.mjs";
|
|
2
13
|
import { assertPlan } from "./assert.mjs";
|
|
3
14
|
import { customReader } from "./custom/reader.mjs";
|
|
4
15
|
import { FOLD_FUNCTION, foldFunctionSql, postgres } from "./postgres.mjs";
|
|
@@ -6,4 +17,4 @@ import { readRecords } from "./records.mjs";
|
|
|
6
17
|
import { readQuery, runQuery } from "./segmented.mjs";
|
|
7
18
|
import { sqlReader } from "./sql-reader.mjs";
|
|
8
19
|
import { ENGINE_VERSION } from "./version.mjs";
|
|
9
|
-
export { ENGINE_VERSION, EngineError, FOLD_FUNCTION, assertPlan, customReader, foldFunctionSql, postgres, readQuery, readRecords, runQuery, sqlReader };
|
|
20
|
+
export { ENGINE_VERSION, EngineError, FOLD_FUNCTION, KEY_FIELD, ROW_COUNT, assertPlan, breakdownQuery, composeDrill, countQuery, customReader, distinctQuery, drillMeasure, drillModel, drillOwner, flagCell, foldFunctionSql, formulaParts, itemsShape, keptPath, limitedDimensions, lineFilter, lineScopes, lineSemantics, measuresOnly, offeredMembers, parentQuery, pathFields, population, postgres, rankQuery, readQuery, readRecords, rowSelection, runQuery, scopeSteps, scopedLines, segmentCuts, sqlReader, stepMembers, storedCell, summaryQuery, trendDimension, trendQuery };
|
|
@@ -67,7 +67,7 @@ function caseSql(ctx, expr) {
|
|
|
67
67
|
function exprSql(ctx, expr) {
|
|
68
68
|
const { b } = ctx;
|
|
69
69
|
if ("col" in expr) return ident(ctx.alias, expr.col);
|
|
70
|
-
if ("lit" in expr) return sql`${expr.lit}`;
|
|
70
|
+
if ("lit" in expr) return typeof expr.lit === "boolean" ? b.dialect.cast(sql`${expr.lit}`, "boolean") : sql`${expr.lit}`;
|
|
71
71
|
if ("op" in expr) {
|
|
72
72
|
const [x, y] = expr.args.map((arg) => b.dialect.cast(exprSql(ctx, arg), "float"));
|
|
73
73
|
return sql`(${x} ${keyword(expr.op)} ${y})`;
|
|
@@ -104,7 +104,7 @@ const postgres = {
|
|
|
104
104
|
const side = (i) => pairs.map((pair) => String.fromCodePoint(pair[i])).join("");
|
|
105
105
|
return sql`translate((${text}) COLLATE "C", ${side(0)}, ${side(1)})`;
|
|
106
106
|
},
|
|
107
|
-
binary: (text) => sql`(${text}) COLLATE "C"`,
|
|
107
|
+
binary: (text) => sql`(CAST(${text} AS text)) COLLATE "C"`,
|
|
108
108
|
recheck,
|
|
109
109
|
equals: (text, value) => sql`(${text} = ${value} AND ${recheck(sql`(${text}) COLLATE "C" = ${value}`)})`,
|
|
110
110
|
textIs: (column, value) => sql`(${column} = ${value} AND ${recheck(sql`(CAST(${column} AS text)) COLLATE "C" = ${value}`)})`,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Cell } from "../query/types.mjs";
|
|
2
|
+
import { Primitive } from "../types/primitives.mjs";
|
|
2
3
|
/**
|
|
3
4
|
* One page of a source's rows: the member ids of the columns, the rows, and when more follow,
|
|
4
5
|
* the cursor of the page after it (`encodeCursor`).
|
|
@@ -6,5 +7,15 @@ import { Cell } from "../query/types.mjs";
|
|
|
6
7
|
export type RecordPage = {
|
|
7
8
|
columns: readonly string[];
|
|
8
9
|
rows: Cell[][];
|
|
10
|
+
/** Each row's values of the source's key columns, in key order. */
|
|
11
|
+
keys?: Primitive[][];
|
|
9
12
|
next?: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Which columns a page shows and how it is ordered, when a caller decides (a drill's items):
|
|
16
|
+
* dimension names of the source. Each is checked to be one a records view may show.
|
|
17
|
+
*/
|
|
18
|
+
export type RecordShape = {
|
|
19
|
+
columns?: readonly string[];
|
|
20
|
+
order?: readonly (readonly [string, "asc" | "desc"])[];
|
|
10
21
|
};
|
|
@@ -2,9 +2,9 @@ import { recordDimensions } from "../model/member.mjs";
|
|
|
2
2
|
import { formatTextTime } from "../time/instant.mjs";
|
|
3
3
|
import { sourceDef } from "./access.mjs";
|
|
4
4
|
// src/engine/record-layout.ts
|
|
5
|
-
/** The columns a records view shows, from the model's one rule (`recordDimensions`). */
|
|
6
|
-
function columnsOf(model, name, def) {
|
|
7
|
-
return recordDimensions(model, name).flatMap((n) => {
|
|
5
|
+
/** The columns a records view shows, from the model's one rule (`recordDimensions`), or the caller's. */
|
|
6
|
+
function columnsOf(model, name, def, shape) {
|
|
7
|
+
return (shape?.columns ?? recordDimensions(model, name)).flatMap((n) => {
|
|
8
8
|
const dim = def.dimensions[n];
|
|
9
9
|
return dim === void 0 ? [] : [{
|
|
10
10
|
id: `${name}.${n}`,
|
|
@@ -14,7 +14,7 @@ function columnsOf(model, name, def) {
|
|
|
14
14
|
}
|
|
15
15
|
/** Newest first by the source's time dimension unless `records.order` says otherwise. */
|
|
16
16
|
function orderOf(def) {
|
|
17
|
-
if (def.records !== void 0) return def.records.order;
|
|
17
|
+
if (def.records?.order !== void 0) return def.records.order;
|
|
18
18
|
return def.time === void 0 ? [] : [[def.time, "desc"]];
|
|
19
19
|
}
|
|
20
20
|
function decode(dim, raw) {
|
|
@@ -25,12 +25,12 @@ function decode(dim, raw) {
|
|
|
25
25
|
return raw instanceof Date ? raw.toISOString() : JSON.stringify(raw);
|
|
26
26
|
}
|
|
27
27
|
/** What a records view of a source reads: its columns, its order, and its key, which breaks every tie. */
|
|
28
|
-
function recordLayout(model, source) {
|
|
28
|
+
function recordLayout(model, source, shape) {
|
|
29
29
|
const def = sourceDef(model, source);
|
|
30
30
|
return {
|
|
31
31
|
def,
|
|
32
|
-
columns: columnsOf(model, source, def),
|
|
33
|
-
order: orderOf(def),
|
|
32
|
+
columns: columnsOf(model, source, def, shape),
|
|
33
|
+
order: shape?.order ?? orderOf(def),
|
|
34
34
|
key: def.key
|
|
35
35
|
};
|
|
36
36
|
}
|