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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Reader } from "./reader.mjs";
|
|
2
|
-
import { RecordPage } from "./record-layout.mjs";
|
|
2
|
+
import { RecordPage, RecordShape } from "./record-layout.mjs";
|
|
3
3
|
import { EngineInput } from "./types.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* A page of the rows behind a query, ungrouped: the same tenant, policy, locks, required
|
|
@@ -10,5 +10,6 @@ import { EngineInput } from "./types.mjs";
|
|
|
10
10
|
export declare function readRecords(input: EngineInput, page: {
|
|
11
11
|
limit: number;
|
|
12
12
|
after?: string;
|
|
13
|
+
shape?: RecordShape;
|
|
13
14
|
}, reader: Reader): Promise<RecordPage>;
|
|
14
|
-
export type { RecordPage };
|
|
15
|
+
export type { RecordPage, RecordShape };
|
|
@@ -11,7 +11,7 @@ import { recordLayout } from "./record-layout.mjs";
|
|
|
11
11
|
*/
|
|
12
12
|
async function readRecords(input, page, reader) {
|
|
13
13
|
const { query, model } = input;
|
|
14
|
-
const { columns, order, key } = recordLayout(model, query.source);
|
|
14
|
+
const { columns, order, key } = recordLayout(model, query.source, page.shape);
|
|
15
15
|
if (columns.length === 0) return {
|
|
16
16
|
columns: [],
|
|
17
17
|
rows: []
|
|
@@ -45,6 +45,7 @@ async function readRecords(input, page, reader) {
|
|
|
45
45
|
return {
|
|
46
46
|
columns: columns.map((c) => c.id),
|
|
47
47
|
rows: read.rows.slice(0, limit),
|
|
48
|
+
keys: read.at.slice(0, limit).map((at) => at.slice(order.length)),
|
|
48
49
|
...read.rows.length > limit && last !== void 0 ? { next: encodeCursor(last) } : {}
|
|
49
50
|
};
|
|
50
51
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hasSegments, keptQuery, limitedDimensions, rankQuery, segmentOtherQuery, segmentOthers, segmentSplit, uncutQuery } from "../query/segments.mjs";
|
|
1
|
+
import { hasSegments, keptQuery, limitedDimensions, rankQuery, segmentCuts, segmentOtherQuery, segmentOthers, segmentSplit, uncutQuery } from "../query/segments.mjs";
|
|
2
2
|
import { startBase } from "./context.mjs";
|
|
3
3
|
import { postgres } from "./postgres.mjs";
|
|
4
4
|
import { each } from "./reader.mjs";
|
|
@@ -58,7 +58,10 @@ async function readQuery(input, reader) {
|
|
|
58
58
|
}, r, whole);
|
|
59
59
|
const [ran, folded] = await each(r.concurrent, [main, ...other === void 0 ? [] : [other]], run);
|
|
60
60
|
if (ran === void 0) throw new TypeError("The kept query has no answer.");
|
|
61
|
-
return
|
|
61
|
+
return {
|
|
62
|
+
...withSegmentOther(query, ran, folded, truncated),
|
|
63
|
+
cuts: segmentCuts(query, kept)
|
|
64
|
+
};
|
|
62
65
|
}
|
|
63
66
|
/** The kept query's answer with Other's rows, now and in the comparison period. */
|
|
64
67
|
function withSegmentOther(query, main, folded, truncated) {
|
|
@@ -46,7 +46,8 @@ function pagesAfter(sorts, at) {
|
|
|
46
46
|
/** The columns' values and the order's: what each statement of a page selects. */
|
|
47
47
|
function pageSql(base, ask) {
|
|
48
48
|
const { query } = ask;
|
|
49
|
-
const
|
|
49
|
+
const names = (query.dimensions ?? []).map((d) => d.member.slice(query.source.length + 1));
|
|
50
|
+
const { def, columns } = recordLayout(base.input.model, query.source, { columns: names });
|
|
50
51
|
const pass = {
|
|
51
52
|
...base,
|
|
52
53
|
query,
|
|
@@ -9,13 +9,47 @@ const TYPES = {
|
|
|
9
9
|
number: "float",
|
|
10
10
|
boolean: "boolean"
|
|
11
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Past this many groups a restriction is a hashed match, so it reads in linear time. Measured, the
|
|
14
|
+
* hashed match was never slower than `IS NOT DISTINCT FROM` from 2 groups up (2 to 25 times
|
|
15
|
+
* faster), so only a single group keeps the plain form.
|
|
16
|
+
*/
|
|
17
|
+
const HASHED_RESTRICT = 1;
|
|
18
|
+
/** A filler for a missing key value: any value of the type, since the null flag beside it decides. */
|
|
19
|
+
const FILL = {
|
|
20
|
+
string: "",
|
|
21
|
+
number: 0,
|
|
22
|
+
boolean: false
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Only the rows of some groups (or, negated, of the others). A few groups match each key with
|
|
26
|
+
* `IS NOT DISTINCT FROM`. Many groups match each key as two plain equalities, whether it is set
|
|
27
|
+
* and its value with a filler where it is not, which say the same thing but let the database
|
|
28
|
+
* hash the kept groups: the nested loop of `IS NOT DISTINCT FROM` is rows times groups.
|
|
29
|
+
*/
|
|
12
30
|
function restrictSql(b, p, restrict) {
|
|
13
31
|
if (restrict.keys.length === 0) return restrict.negate ? sql`TRUE` : sql`FALSE`;
|
|
14
|
-
const
|
|
32
|
+
const exists = restrict.keys.length > HASHED_RESTRICT ? hashedMatch(b, p, restrict.keys) : plainMatch(b, p, restrict.keys);
|
|
33
|
+
return restrict.negate ? sql`NOT ${exists}` : exists;
|
|
34
|
+
}
|
|
35
|
+
function plainMatch(b, p, keys) {
|
|
36
|
+
const rows = keys.map((key) => sql`(${join(p.keys.map((k, i) => b.dialect.cast(sql`${key[i] ?? null}`, TYPES[k.type])))})`);
|
|
15
37
|
const names = p.keys.map((_k, i) => ident(`k${i}`));
|
|
16
38
|
const match = p.keys.map((k, i) => sql`${ident("kept", `k${i}`)} IS NOT DISTINCT FROM ${k.sql}`);
|
|
17
|
-
|
|
18
|
-
|
|
39
|
+
return sql`EXISTS (SELECT 1 FROM (VALUES ${join(rows)}) AS kept(${join(names)}) WHERE ${and(match)})`;
|
|
40
|
+
}
|
|
41
|
+
function hashedMatch(b, p, keys) {
|
|
42
|
+
const fill = (type) => b.dialect.cast(sql`${FILL[type]}`, TYPES[type]);
|
|
43
|
+
const rows = keys.map((key) => {
|
|
44
|
+
const cells = p.keys.flatMap((k, i) => {
|
|
45
|
+
const value = key[i] ?? null;
|
|
46
|
+
return [value === null ? sql`TRUE` : sql`FALSE`, value === null ? fill(k.type) : b.dialect.cast(sql`${value}`, TYPES[k.type])];
|
|
47
|
+
});
|
|
48
|
+
return sql`(${join(cells)})`;
|
|
49
|
+
});
|
|
50
|
+
const names = p.keys.flatMap((_k, i) => [ident(`n${i}`), ident(`k${i}`)]);
|
|
51
|
+
const match = p.keys.flatMap((k, i) => [sql`${ident("kept", `n${i}`)} = (${k.sql} IS NULL)`, sql`${ident("kept", `k${i}`)} = COALESCE(${k.sql}, ${fill(k.type)})`]);
|
|
52
|
+
return sql`EXISTS (SELECT 1 FROM (VALUES ${join(rows)}) AS kept(${join(names)}) WHERE ${and(match)})`;
|
|
19
53
|
}
|
|
20
54
|
const DIR = {
|
|
21
55
|
asc: keyword("ASC NULLS LAST"),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Model } from "../model/types.mjs";
|
|
2
2
|
import { LockEntry } from "../query/compose.mjs";
|
|
3
|
+
import { Cuts } from "../query/drill/types.mjs";
|
|
3
4
|
import { BoundFilter } from "../query/filter.mjs";
|
|
4
5
|
import { Calendar, Cell, ResolvedRange, WireQuery } from "../query/types.mjs";
|
|
5
6
|
import { Moment } from "../time/temporal.mjs";
|
|
@@ -52,4 +53,6 @@ export type Ran = {
|
|
|
52
53
|
answer: Answer;
|
|
53
54
|
sources: readonly SourceName[];
|
|
54
55
|
range?: ResolvedRange;
|
|
56
|
+
/** What each dimension's own limit kept; absent when no dimension has one. */
|
|
57
|
+
cuts?: Cuts;
|
|
55
58
|
};
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* so an answer cached by older code is never read. `test/engine-version.test.ts` checks it
|
|
5
5
|
* against the files and prints the new value when they change.
|
|
6
6
|
*/
|
|
7
|
-
export declare const ENGINE_VERSION = "
|
|
7
|
+
export declare const ENGINE_VERSION = "c50d674f90366532";
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* so an answer cached by older code is never read. `test/engine-version.test.ts` checks it
|
|
6
6
|
* against the files and prints the new value when they change.
|
|
7
7
|
*/
|
|
8
|
-
const ENGINE_VERSION = "
|
|
8
|
+
const ENGINE_VERSION = "c50d674f90366532";
|
|
9
9
|
export { ENGINE_VERSION };
|
|
@@ -13,6 +13,8 @@ export declare const MODEL_ISSUES: {
|
|
|
13
13
|
readonly BUCKET_LABELS: "A bucket dimension has a different number of labels than buckets.";
|
|
14
14
|
readonly COLLATION_MISSING: "A string dimension does not declare \"binary\" or \"ci\".";
|
|
15
15
|
readonly CONNECTION_MISSING: "A source has no connection.";
|
|
16
|
+
readonly DRILL_PREFER_UNKNOWN: "A source's drill.prefer names a field that is not a dimension, a join or a join's dimension of it.";
|
|
17
|
+
readonly HINT_INVALID: "A records title, a number format or a value's tone names a field or value that does not exist, or sits on a field of another kind.";
|
|
16
18
|
readonly EXACT_EXPR_COEFFICIENT: "A whole-number factor in an exact expression is 2^31 or more.";
|
|
17
19
|
readonly EXACT_EXPR_NOT_LINEAR: "An exact measure is not a linear sum of columns.";
|
|
18
20
|
readonly EXACT_EXPR_TERMS: "An exact expression has too many terms.";
|
|
@@ -29,6 +31,7 @@ export declare const MODEL_ISSUES: {
|
|
|
29
31
|
readonly KEY_MISSING: "A source has no unique key.";
|
|
30
32
|
readonly MEMBER_NAME_CLASH: "Two members of a source share a name.";
|
|
31
33
|
readonly MODEL_FILTER_NOT_BOUND: "A filter in the model uses a viewer value or a variable.";
|
|
34
|
+
readonly MODEL_SHAPE: "A member of the model has a kind, merge or storage that does not exist, or lacks a field its kind needs.";
|
|
32
35
|
readonly MODEL_VERSION: "The model version is not 1.";
|
|
33
36
|
readonly NAME_INVALID: "A name is not a letter followed by letters, digits or underscores.";
|
|
34
37
|
readonly NUMERIC_SCALE: "An exact number's scale is not a whole number from 0 to 38.";
|
|
@@ -90,6 +93,8 @@ export declare const QUERY_REFUSALS: {
|
|
|
90
93
|
readonly SCOPE_UNFIT: "A dashboard filter names a member the tile's source cannot read.";
|
|
91
94
|
readonly TILE_UNKNOWN: "The request names a widget or query the dashboard does not have.";
|
|
92
95
|
readonly MODEL_FILTER_NOT_BOUND: "A source's where holds a viewer value or a variable (the model check refuses it first).";
|
|
96
|
+
readonly SELECTION_INVALID: "A drill's selection, execution or path does not open, does not fit the tile, or is longer than a path holds.";
|
|
97
|
+
readonly DRILL_UNSUPPORTED: "The drill asks for a view its line cannot show (a formula's items, a snapshot measure, a field it cannot be broken down by); the message says why.";
|
|
93
98
|
readonly CURSOR_INVALID: "A records page names a cursor that is not the `next` an earlier page of the same view gave.";
|
|
94
99
|
readonly RANGE_INVALID: "The date range is not valid.";
|
|
95
100
|
readonly RECORDS_UNAVAILABLE: "The source reads through a custom data layer that does not serve the rows behind an answer.";
|
|
@@ -102,6 +107,28 @@ export declare const QUERY_REFUSALS: {
|
|
|
102
107
|
export declare const RESULT_WARNINGS: {
|
|
103
108
|
readonly ROW_CAP: "The answer has more groups or rows than the row cap; it is cut and marked truncated.";
|
|
104
109
|
};
|
|
110
|
+
/**
|
|
111
|
+
* Why a drill cannot show a view, or a mark does not open. Each is a code a host can translate
|
|
112
|
+
* (the React package's `messages.drillReasons`); the English text is the default.
|
|
113
|
+
*/
|
|
114
|
+
export declare const DRILL_REASONS: {
|
|
115
|
+
readonly NO_FIELD: "There is no field to break this down by.";
|
|
116
|
+
readonly NO_TIME: "This source has no time field the viewer may read.";
|
|
117
|
+
readonly FORMULA_ITEMS: "A formula is computed from other lines: see Explanation.";
|
|
118
|
+
readonly RATIO_NOT_ROWS: "This ratio is not a share of rows (its lines sum or count distinct values): see each line on its own.";
|
|
119
|
+
readonly RATIO_UNMARKED: "Rows are not marked: the numerator's condition reads a joined field or a viewer value. Only still lists its rows.";
|
|
120
|
+
readonly FORMULA_SCOPED: "This formula reads the whole chart or the period before, so it does not split by a field: see Explanation.";
|
|
121
|
+
readonly NOT_FORMULA: "Only a formula has an explanation.";
|
|
122
|
+
readonly SNAPSHOT: "A snapshot measure lists no rows yet.";
|
|
123
|
+
readonly RECORDS_DENIED: "The rows of this source are not shown to this viewer.";
|
|
124
|
+
readonly RECORDS_UNAVAILABLE: "This source's data layer does not serve rows.";
|
|
125
|
+
readonly OPERAND_HIDDEN: "The rows behind this value read a field that is kept back.";
|
|
126
|
+
readonly DISTINCT_HIDDEN: "Its distinct field is not one the model may show.";
|
|
127
|
+
readonly OTHER_TOO_LARGE: "Other kept too many groups to open.";
|
|
128
|
+
readonly OTHER_CUT: "Other of a cut that was itself cut, or of a truncated answer, does not open.";
|
|
129
|
+
readonly ROW_CAP: "Only the first rows of this answer open; narrow the filters to open the rest.";
|
|
130
|
+
readonly SOURCE_OFF: "The model turns drilling off for this source.";
|
|
131
|
+
};
|
|
105
132
|
/** A dashboard edit the document reducer refuses. */
|
|
106
133
|
export declare const DOCUMENT_REFUSALS: {
|
|
107
134
|
readonly CONTROL_EXISTS: "A control with that id already exists.";
|
|
@@ -142,6 +169,8 @@ export declare const BASE_ERROR_CODES: {
|
|
|
142
169
|
RETRYABLE: RawError<"RETRYABLE">;
|
|
143
170
|
INTERNAL: RawError<"INTERNAL">;
|
|
144
171
|
NO_HANDLER: RawError<"NO_HANDLER">;
|
|
172
|
+
DRILL_DENIED: RawError<"DRILL_DENIED">;
|
|
173
|
+
DRILL_STALE: RawError<"DRILL_STALE">;
|
|
145
174
|
CONTRACT_MISMATCH: RawError<"CONTRACT_MISMATCH">;
|
|
146
175
|
};
|
|
147
176
|
export type ModelIssueCode = keyof typeof MODEL_ISSUES;
|
|
@@ -149,6 +178,8 @@ export type CatalogIssueCode = keyof typeof CATALOG_ISSUES;
|
|
|
149
178
|
export type QueryRefusalCode = keyof typeof QUERY_REFUSALS;
|
|
150
179
|
export type DocumentRefusalCode = keyof typeof DOCUMENT_REFUSALS;
|
|
151
180
|
export type ResultWarningCode = keyof typeof RESULT_WARNINGS;
|
|
181
|
+
/** Why a drill cannot show a view, or a mark does not open. */
|
|
182
|
+
export type DrillReason = keyof typeof DRILL_REASONS;
|
|
152
183
|
export type RuntimeErrorCode = keyof typeof BASE_ERROR_CODES;
|
|
153
184
|
/** Every code the core can put in an `Issue`. */
|
|
154
185
|
export type IssueCode = ModelIssueCode | CatalogIssueCode | DocumentRefusalCode | ResultWarningCode | "QUERY_INVALID";
|
|
@@ -16,6 +16,8 @@ const MODEL_ISSUES = {
|
|
|
16
16
|
BUCKET_LABELS: "A bucket dimension has a different number of labels than buckets.",
|
|
17
17
|
COLLATION_MISSING: "A string dimension does not declare \"binary\" or \"ci\".",
|
|
18
18
|
CONNECTION_MISSING: "A source has no connection.",
|
|
19
|
+
DRILL_PREFER_UNKNOWN: "A source's drill.prefer names a field that is not a dimension, a join or a join's dimension of it.",
|
|
20
|
+
HINT_INVALID: "A records title, a number format or a value's tone names a field or value that does not exist, or sits on a field of another kind.",
|
|
19
21
|
EXACT_EXPR_COEFFICIENT: "A whole-number factor in an exact expression is 2^31 or more.",
|
|
20
22
|
EXACT_EXPR_NOT_LINEAR: "An exact measure is not a linear sum of columns.",
|
|
21
23
|
EXACT_EXPR_TERMS: "An exact expression has too many terms.",
|
|
@@ -32,6 +34,7 @@ const MODEL_ISSUES = {
|
|
|
32
34
|
KEY_MISSING: "A source has no unique key.",
|
|
33
35
|
MEMBER_NAME_CLASH: "Two members of a source share a name.",
|
|
34
36
|
MODEL_FILTER_NOT_BOUND: "A filter in the model uses a viewer value or a variable.",
|
|
37
|
+
MODEL_SHAPE: "A member of the model has a kind, merge or storage that does not exist, or lacks a field its kind needs.",
|
|
35
38
|
MODEL_VERSION: "The model version is not 1.",
|
|
36
39
|
NAME_INVALID: "A name is not a letter followed by letters, digits or underscores.",
|
|
37
40
|
NUMERIC_SCALE: "An exact number's scale is not a whole number from 0 to 38.",
|
|
@@ -82,6 +85,28 @@ const CATALOG_ISSUES = {
|
|
|
82
85
|
};
|
|
83
86
|
/** A result that answered, with something the viewer should know. Carried in the receipt. */
|
|
84
87
|
const RESULT_WARNINGS = { ROW_CAP: "The answer has more groups or rows than the row cap; it is cut and marked truncated." };
|
|
88
|
+
/**
|
|
89
|
+
* Why a drill cannot show a view, or a mark does not open. Each is a code a host can translate
|
|
90
|
+
* (the React package's `messages.drillReasons`); the English text is the default.
|
|
91
|
+
*/
|
|
92
|
+
const DRILL_REASONS = {
|
|
93
|
+
NO_FIELD: "There is no field to break this down by.",
|
|
94
|
+
NO_TIME: "This source has no time field the viewer may read.",
|
|
95
|
+
FORMULA_ITEMS: "A formula is computed from other lines: see Explanation.",
|
|
96
|
+
RATIO_NOT_ROWS: "This ratio is not a share of rows (its lines sum or count distinct values): see each line on its own.",
|
|
97
|
+
RATIO_UNMARKED: "Rows are not marked: the numerator's condition reads a joined field or a viewer value. Only still lists its rows.",
|
|
98
|
+
FORMULA_SCOPED: "This formula reads the whole chart or the period before, so it does not split by a field: see Explanation.",
|
|
99
|
+
NOT_FORMULA: "Only a formula has an explanation.",
|
|
100
|
+
SNAPSHOT: "A snapshot measure lists no rows yet.",
|
|
101
|
+
RECORDS_DENIED: "The rows of this source are not shown to this viewer.",
|
|
102
|
+
RECORDS_UNAVAILABLE: "This source's data layer does not serve rows.",
|
|
103
|
+
OPERAND_HIDDEN: "The rows behind this value read a field that is kept back.",
|
|
104
|
+
DISTINCT_HIDDEN: "Its distinct field is not one the model may show.",
|
|
105
|
+
OTHER_TOO_LARGE: "Other kept too many groups to open.",
|
|
106
|
+
OTHER_CUT: "Other of a cut that was itself cut, or of a truncated answer, does not open.",
|
|
107
|
+
ROW_CAP: "Only the first rows of this answer open; narrow the filters to open the rest.",
|
|
108
|
+
SOURCE_OFF: "The model turns drilling off for this source."
|
|
109
|
+
};
|
|
85
110
|
/** A dashboard edit the document reducer refuses. */
|
|
86
111
|
const DOCUMENT_REFUSALS = {
|
|
87
112
|
CONTROL_EXISTS: "A control with that id already exists.",
|
|
@@ -122,6 +147,8 @@ const BASE_ERROR_CODES = defineErrorCodes({
|
|
|
122
147
|
RETRYABLE: "The request could not complete. Try again.",
|
|
123
148
|
INTERNAL: "Something went wrong on the server. Its cause is in the host's logs.",
|
|
124
149
|
NO_HANDLER: "No dashboards handler answered at the client's path: mount the handler there or set baseURL.",
|
|
150
|
+
DRILL_DENIED: "No drill here: the server sets drill: false, the model keeps the source out, the viewer is on a public link, or the host keeps its records back.",
|
|
151
|
+
DRILL_STALE: "The dashboard changed since the drill was opened. Open it again from the chart.",
|
|
125
152
|
CONTRACT_MISMATCH: "This page and the dashboards server are from different releases. Reload the page."
|
|
126
153
|
});
|
|
127
|
-
export { BASE_ERROR_CODES, CATALOG_ISSUES, DOCUMENT_REFUSALS, MODEL_ISSUES, RESULT_WARNINGS, defineErrorCodes };
|
|
154
|
+
export { BASE_ERROR_CODES, CATALOG_ISSUES, DOCUMENT_REFUSALS, DRILL_REASONS, MODEL_ISSUES, RESULT_WARNINGS, defineErrorCodes };
|
package/dist/core/index.d.mts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { CustomSource, GroupedRead, HostCell, HostRows, ReadContext, ReadField, ReadFilter, ReadMeasure, RecordsRead } from "./engine/custom/request.mjs";
|
|
2
|
-
import { BASE_ERROR_CODES, CatalogIssueCode, DocumentRefusalCode, IssueCode, ModelIssueCode, QueryRefusalCode, RawError, ResultWarningCode, RuntimeErrorCode, defineErrorCodes } from "./error/codes.mjs";
|
|
2
|
+
import { BASE_ERROR_CODES, CatalogIssueCode, DRILL_REASONS, DocumentRefusalCode, DrillReason, IssueCode, ModelIssueCode, QueryRefusalCode, RawError, ResultWarningCode, RuntimeErrorCode, defineErrorCodes } from "./error/codes.mjs";
|
|
3
3
|
import { checkCatalog } from "./model/catalog/check.mjs";
|
|
4
4
|
import { describeQueries } from "./model/catalog/queries.mjs";
|
|
5
5
|
import { policyBinding } from "./model/defaults.mjs";
|
|
6
6
|
import { DimensionId, JoinedDimensionId, MeasureId, MemberId, ModelError, OwnDimensionId, SourceNameOf, defineModel } from "./model/define.mjs";
|
|
7
|
+
import { DimensionHints, Noun, NumberFormat, RecordsHint, Tone } from "./model/hints.mjs";
|
|
7
8
|
import { MemberRef, ResolvedDimension, parseMemberId, recordDimensions, resolveDimension, resolveMeasure } from "./model/member.mjs";
|
|
8
9
|
import { Moment, isZone, momentMicros } from "./time/temporal.mjs";
|
|
9
10
|
import { MICROS_PER_DAY, MICROS_PER_HOUR, MICROS_PER_SECOND, Micros, formatTextTime, parseDate, parseNaiveTime, parseTextTime } from "./time/instant.mjs";
|
|
@@ -11,9 +12,10 @@ import { bucketLabel, bucketLabels, bucketStart, nextBucketStart, shiftBucket }
|
|
|
11
12
|
import { DatePart, DimensionDef, EXPR_FUNCTIONS, Expr, ExprCondition, ExprFunction, JoinDef, MeasureDef, MemberMeta, Model, Numeric, PolicyBinding, PolicyFilter, PolicyRule, Relationship, RowPolicy, SourceDef, TenantBinding, TimeStorage, Unit, ViewerMatch } from "./model/types.mjs";
|
|
12
13
|
import { LinearTerm, linearTerms } from "./model/validate/expr.mjs";
|
|
13
14
|
import { validateModel } from "./model/validate/index.mjs";
|
|
15
|
+
import { Cuts, Drill, DrillCan, DrillField, DrillOrigin, DrillSemantics, DrillState, DrillStep, DrillView, MAX_DRILL_STEPS, PinnedExecution, Selection } from "./query/drill/types.mjs";
|
|
16
|
+
import { viaJoins } from "./model/validate/via.mjs";
|
|
14
17
|
import { Span, inSpan, resolveRange } from "./time/range.mjs";
|
|
15
18
|
import { NaiveRule, OffsetSegment, offsetSegments, resolveNaive, startOfDate } from "./time/zone.mjs";
|
|
16
|
-
import { viaJoins } from "./model/validate/via.mjs";
|
|
17
19
|
import { BoundRule, bindFilter, bindPolicy, namedPolicy, viewerValues } from "./policy/bind.mjs";
|
|
18
20
|
import { ruleMatches, selectRule } from "./policy/match.mjs";
|
|
19
21
|
import { Command, CommandBody, CommandId, Display, Doc, LayoutItem, Scope, Tab, TabId, Widget, WidgetId, emptyDoc } from "./document/types.mjs";
|
|
@@ -23,7 +25,7 @@ import { Outcome } from "./document/outcome.mjs";
|
|
|
23
25
|
import { lockChanged, reduce, reduceAll } from "./document/reduce.mjs";
|
|
24
26
|
import { Recorded, Replayed, commandWidget, replay } from "./document/replay.mjs";
|
|
25
27
|
import { readingOrder, stepCommands, stepMoves } from "./document/stacked.mjs";
|
|
26
|
-
import { VIEW_PREFIX, ViewState, encodeView, viewFor } from "./document/view.mjs";
|
|
28
|
+
import { EncodeOptions, VIEW_PREFIX, ViewState, encodeView, viewFor, withView } from "./document/view.mjs";
|
|
27
29
|
import { EXACT_LIMIT, Exact, divideExact, formatExact, parseExact, storedExact } from "./exact/decimal.mjs";
|
|
28
30
|
import { ExactSum, Operands, rowValue, sumLinear } from "./exact/sum.mjs";
|
|
29
31
|
import { Closure, queryClosure } from "./query/closure.mjs";
|
|
@@ -37,15 +39,17 @@ import { Alias, QueryReferenceError, toWire } from "./query/to-wire.mjs";
|
|
|
37
39
|
import { CalcAlias, Calendar, Cell, Control, ControlId, DateRange, DimensionAlias, DimensionCut, EntryId, ExplicitRange, Format, Formula, FormulaNode, Grain, MeasureAlias, Picks, RefOf, RelativeRange, ResolvedRange, ScopeCoverage, StoredFormulaNode, StoredQuery, TileRef, TypedFilter, TypedQuery, WireQuery } from "./query/types.mjs";
|
|
38
40
|
import { memberLabel, recordColumns, resultColumns } from "./result/columns.mjs";
|
|
39
41
|
import { isMark, markedRows } from "./result/marks.mjs";
|
|
42
|
+
import { ItemLinks, ItemLinksFor, LINK_PART, itemLink, linkTemplateIssues } from "./query/drill/links.mjs";
|
|
40
43
|
import { Mark, Receipt, RecordColumn, Result, ResultCell, ResultColumn, ResultRows } from "./result/types.mjs";
|
|
41
44
|
import "./time/index.mjs";
|
|
42
45
|
import { ApiError, CONTRACT_VERSION, CoreContract, DashboardListResponse, DashboardResponse, DraftResponse, MetaJoin, MetaMember, MetaResponse, PublishResponse, QueryAnswer, QueryLine, RecordsResponse, TileAnswer, TileLine, TileRequest, TileResult, TilesRequest, ValidateResponse, ValuesResponse } from "./types/api.mjs";
|
|
46
|
+
import { AnswerDrill, ClosedRow, DrillAbilities, DrillAnswer, DrillBody, DrillCrumb, DrillExplanationView, DrillGroupedView, DrillItem, DrillItemsView, DrillOperand, DrillSummary, ItemColumn, SealedAnswer } from "./types/drill-api.mjs";
|
|
43
47
|
import { CoreApi, CreateDash, Dash, EndpointsByPath, HeadersLike, PluginEndpoints, PluginErrorCodes, ServerCall, ServerCallInput, ServerCalls, UniqueIds } from "./types/infer.mjs";
|
|
44
48
|
import { CodeDashboard, DashOptions, SecondaryStorage } from "./types/options.mjs";
|
|
45
|
-
import { DashEndpoint, DashHook, DashPlugin, DocumentSlice, EndpointAccess, EndpointContext, HookContext, createDashEndpoint } from "./types/plugin.mjs";
|
|
46
49
|
import { Field, FieldType, TABLES, TableDef, TableName } from "./store/schema.mjs";
|
|
47
50
|
import { CATALOG, StoreDialect, TableCheck, createTable, schemaChecks, schemaStatements } from "./store/ddl.mjs";
|
|
48
51
|
import { comparisonQuery, comparisonSpan, shiftInstant } from "./time/compare.mjs";
|
|
52
|
+
import { DashEndpoint, DashHook, DashPlugin, DocumentSlice, EndpointAccess, EndpointContext, HookContext, createDashEndpoint } from "./types/plugin.mjs";
|
|
49
53
|
import { Awaitable, Column, ConnectionId, DimensionName, IanaZone, IsoInstant, Issue, JoinName, MeasureName, PolicyName, Primitive, SourceName, TenantKey, WeekStart } from "./types/primitives.mjs";
|
|
50
54
|
import { Catalog, Explanation, PageRequest, QueryCtx, RawLevels, RawResult, RecordPage, RunOptions, SemanticProvider } from "./types/provider.mjs";
|
|
51
55
|
import { ColumnType, DbSchema, IntrospectingConnection, Param, QueryConnection, ReadSession, Sql } from "./types/source.mjs";
|
|
@@ -53,4 +57,4 @@ import { Author, DashAdapter, DashboardHead, DashboardReader, DashboardStore, Da
|
|
|
53
57
|
import { CanFn, Channel, Principal, Resource, TenantKeysOf, Verb, Viewer, ViewerFor, principalTenant } from "./types/viewer.mjs";
|
|
54
58
|
import { canonical } from "./value/canonical.mjs";
|
|
55
59
|
import { fold, foldingPairs } from "./value/casefold.mjs";
|
|
56
|
-
export { type AccessParts, type Alias, type ApiError, type AssertionContext, type Author, type Awaitable, BASE_ERROR_CODES, type BoundFilter, type BoundPolicy, type BoundPolicyFilter, type BoundRule, CATALOG, CONTRACT_VERSION, type CalcAlias, type Calendar, type CanFn, type Catalog, type CatalogIssueCode, type Cell, type Change, type Channel, type Closure, type CodeDashboard, type Column, type ColumnType, type Command, type CommandBody, type CommandId, type ComposeCtx, type ComposeDelta, type ComposedQuery, type ComposedTile, type CompositionPolicy, type ConnectionId, type Control, type ControlId, type CoreApi, type CoreContract, type CreateDash, type CustomSource, DEFAULT_COMPOSITION_POLICY, type Dash, type DashAdapter, type DashEndpoint, type DashHook, type DashOptions, type DashPlugin, type DashboardHead, type DashboardListResponse, type DashboardReader, type DashboardResponse, type DashboardStore, type DashboardSummary, type DatePart, type DateRange, type DbSchema, type DimensionAlias, type DimensionCut, type DimensionDef, type DimensionId, type DimensionName, type Display, type Doc, type DocumentRefusalCode, type DocumentSlice, type Draft, type DraftResponse, type DraftTarget, EXACT_LIMIT, EXPR_FUNCTIONS, type EndpointAccess, type EndpointContext, type EndpointsByPath, type EntryId, type Exact, type ExactSum, type Explanation, type ExplicitRange, type Expr, type ExprCondition, type ExprFunction, type Field, type FieldType, type Format, type Formula, type FormulaNode, type FormulaRef, GRID_COLUMNS, type Gap, type Grain, type GroupedRead, type HeadersLike, type HookContext, type HostCell, type HostRows, type IanaZone, type IntrospectingConnection, type IsoInstant, type Issue, type IssueCode, type JoinDef, type JoinName, type JoinedDimensionId, type LayoutItem, type Leaf, type LinearTerm, type LockEntry, MICROS_PER_DAY, MICROS_PER_HOUR, MICROS_PER_SECOND, type Mark, type MeasureAlias, type MeasureDef, type MeasureId, type MeasureName, type MemberId, type MemberMeta, type MemberRef, type MetaJoin, type MetaMember, type MetaResponse, type Micros, type Model, ModelError, type ModelIssueCode, type Moment, NEGATION_OF, NEGATIVE_OPS, NULL_OPS, type NaiveRule, type NegativeOp, type NodeId, type NullOp, type Numeric, type OffsetSegment, type Op, type Operands, type Outcome, type OverlapPart, type OwnDimensionId, POSITIVE_OPS, type PageRequest, type Param, type Picks, type Placement, type PluginEndpoints, type PluginErrorCodes, type PolicyBinding, type PolicyFilter, type PolicyName, type PolicyRule, type PositiveOp, type Preview, type Primitive, type Principal, type PublishResponse, type Published, type QueryAnswer, type QueryConnection, type QueryCtx, type QueryLine, QueryReferenceError, type QueryRefusalCode, type RawError, type RawLevels, type RawResult, type ReadContext, type ReadField, type ReadFilter, type ReadMeasure, type ReadSession, type Receipt, type RecordColumn, type RecordPage, type Recorded, type RecordsRead, type RecordsResponse, type RefOf, type Refusal, type Relationship, type RelativeRange, type Replayed, type RequiredEntry, type ResolvedDimension, type ResolvedRange, type Resource, type Result, type ResultCell, type ResultColumn, type ResultRows, type ResultWarningCode, type Row, type RowPolicy, type RunOptions, type RuntimeErrorCode, type SchemaDriver, type Scope, type ScopeCoverage, type SecondaryStorage, type SemanticProvider, type ServerCall, type ServerCallInput, type ServerCalls, type SourceDef, type SourceName, type SourceNameOf, type Span, type Sql, type StoreDialect, type StoredFilter, type StoredFormulaNode, type StoredLockEntry, type StoredQuery, type StoredVersion, TABLES, type Tab, type TabId, type TableCheck, type TableDef, type TableName, type Tenant, type TenantBinding, type TenantKey, type TenantKeysOf, type TileAnswer, type TileInput, type TileLine, type TileRef, type TileRequest, type TileResult, type TilesRequest, type TimeStorage, type Token, type TypedFilter, type TypedQuery, type UniqueIds, type Unit, type UnpublishedDraft, VIEW_PREFIX, type ValidateResponse, type ValueLeaf, type ValuesResponse, type VariableLeaf, type Verb, type VersionEntry, type ViewState, type Viewer, type ViewerFor, type ViewerLeaf, type ViewerMatch, type ViewerRef, type WeekStart, type Where, type Widget, type WidgetId, type WidgetPart, type WireFilter, type WireQuery, bindFilter, bindPolicy, bucketLabel, bucketLabels, bucketStart, canonical, changeOf, changedWidget, checkCatalog, closeGaps, closeGapsCommands, commandWidget, comparisonQuery, comparisonSpan, composeTile, createDashEndpoint, createTable, defineErrorCodes, defineModel, describeQueries, diffDocs, divideExact, documentLock, effectiveFilter, emptyDoc, encodeView, fold, foldingPairs, formatExact, formatTextTime, formulaRefs, freeSpot, inSpan, isBound, isDateRange, isLeaf, isMark, isZone, layoutGaps, linearTerms, lockChanged, markShifted, markedRows, memberLabel, momentMicros, namedPolicy, nextBucketStart, offsetSegments, parseDate, parseExact, parseMemberId, parseNaiveTime, parseTextTime, pickProblem, placeItem, placementOf, policyBinding, principalTenant, queryClosure, readingOrder, recordColumns, recordDimensions, reduce, reduceAll, repairLayout, replay, resolveDimension, resolveMeasure, resolveNaive, resolveRange, resultColumns, rowValue, ruleMatches, schemaChecks, schemaStatements, selectRule, shareOf, shiftBucket, shiftInstant, startOfDate, stepCommands, stepMoves, storedExact, stripIds, sumLinear, tileInputs, toWire, validateModel, viaJoins, viewFor, viewerValues, widgetDiff };
|
|
60
|
+
export { type AccessParts, type Alias, type AnswerDrill, type ApiError, type AssertionContext, type Author, type Awaitable, BASE_ERROR_CODES, type BoundFilter, type BoundPolicy, type BoundPolicyFilter, type BoundRule, CATALOG, CONTRACT_VERSION, type CalcAlias, type Calendar, type CanFn, type Catalog, type CatalogIssueCode, type Cell, type Change, type Channel, type ClosedRow, type Closure, type CodeDashboard, type Column, type ColumnType, type Command, type CommandBody, type CommandId, type ComposeCtx, type ComposeDelta, type ComposedQuery, type ComposedTile, type CompositionPolicy, type ConnectionId, type Control, type ControlId, type CoreApi, type CoreContract, type CreateDash, type CustomSource, type Cuts, DEFAULT_COMPOSITION_POLICY, DRILL_REASONS, type Dash, type DashAdapter, type DashEndpoint, type DashHook, type DashOptions, type DashPlugin, type DashboardHead, type DashboardListResponse, type DashboardReader, type DashboardResponse, type DashboardStore, type DashboardSummary, type DatePart, type DateRange, type DbSchema, type DimensionAlias, type DimensionCut, type DimensionDef, type DimensionHints, type DimensionId, type DimensionName, type Display, type Doc, type DocumentRefusalCode, type DocumentSlice, type Draft, type DraftResponse, type DraftTarget, type Drill, type DrillAbilities, type DrillAnswer, type DrillBody, type DrillCan, type DrillCrumb, type DrillExplanationView, type DrillField, type DrillGroupedView, type DrillItem, type DrillItemsView, type DrillOperand, type DrillOrigin, type DrillReason, type DrillSemantics, type DrillState, type DrillStep, type DrillSummary, type DrillView, EXACT_LIMIT, EXPR_FUNCTIONS, type EncodeOptions, type EndpointAccess, type EndpointContext, type EndpointsByPath, type EntryId, type Exact, type ExactSum, type Explanation, type ExplicitRange, type Expr, type ExprCondition, type ExprFunction, type Field, type FieldType, type Format, type Formula, type FormulaNode, type FormulaRef, GRID_COLUMNS, type Gap, type Grain, type GroupedRead, type HeadersLike, type HookContext, type HostCell, type HostRows, type IanaZone, type IntrospectingConnection, type IsoInstant, type Issue, type IssueCode, type ItemColumn, type ItemLinks, type ItemLinksFor, type JoinDef, type JoinName, type JoinedDimensionId, LINK_PART, type LayoutItem, type Leaf, type LinearTerm, type LockEntry, MAX_DRILL_STEPS, MICROS_PER_DAY, MICROS_PER_HOUR, MICROS_PER_SECOND, type Mark, type MeasureAlias, type MeasureDef, type MeasureId, type MeasureName, type MemberId, type MemberMeta, type MemberRef, type MetaJoin, type MetaMember, type MetaResponse, type Micros, type Model, ModelError, type ModelIssueCode, type Moment, NEGATION_OF, NEGATIVE_OPS, NULL_OPS, type NaiveRule, type NegativeOp, type NodeId, type Noun, type NullOp, type NumberFormat, type Numeric, type OffsetSegment, type Op, type Operands, type Outcome, type OverlapPart, type OwnDimensionId, POSITIVE_OPS, type PageRequest, type Param, type Picks, type PinnedExecution, type Placement, type PluginEndpoints, type PluginErrorCodes, type PolicyBinding, type PolicyFilter, type PolicyName, type PolicyRule, type PositiveOp, type Preview, type Primitive, type Principal, type PublishResponse, type Published, type QueryAnswer, type QueryConnection, type QueryCtx, type QueryLine, QueryReferenceError, type QueryRefusalCode, type RawError, type RawLevels, type RawResult, type ReadContext, type ReadField, type ReadFilter, type ReadMeasure, type ReadSession, type Receipt, type RecordColumn, type RecordPage, type Recorded, type RecordsHint, type RecordsRead, type RecordsResponse, type RefOf, type Refusal, type Relationship, type RelativeRange, type Replayed, type RequiredEntry, type ResolvedDimension, type ResolvedRange, type Resource, type Result, type ResultCell, type ResultColumn, type ResultRows, type ResultWarningCode, type Row, type RowPolicy, type RunOptions, type RuntimeErrorCode, type SchemaDriver, type Scope, type ScopeCoverage, type SealedAnswer, type SecondaryStorage, type Selection, type SemanticProvider, type ServerCall, type ServerCallInput, type ServerCalls, type SourceDef, type SourceName, type SourceNameOf, type Span, type Sql, type StoreDialect, type StoredFilter, type StoredFormulaNode, type StoredLockEntry, type StoredQuery, type StoredVersion, TABLES, type Tab, type TabId, type TableCheck, type TableDef, type TableName, type Tenant, type TenantBinding, type TenantKey, type TenantKeysOf, type TileAnswer, type TileInput, type TileLine, type TileRef, type TileRequest, type TileResult, type TilesRequest, type TimeStorage, type Token, type Tone, type TypedFilter, type TypedQuery, type UniqueIds, type Unit, type UnpublishedDraft, VIEW_PREFIX, type ValidateResponse, type ValueLeaf, type ValuesResponse, type VariableLeaf, type Verb, type VersionEntry, type ViewState, type Viewer, type ViewerFor, type ViewerLeaf, type ViewerMatch, type ViewerRef, type WeekStart, type Where, type Widget, type WidgetId, type WidgetPart, type WireFilter, type WireQuery, bindFilter, bindPolicy, bucketLabel, bucketLabels, bucketStart, canonical, changeOf, changedWidget, checkCatalog, closeGaps, closeGapsCommands, commandWidget, comparisonQuery, comparisonSpan, composeTile, createDashEndpoint, createTable, defineErrorCodes, defineModel, describeQueries, diffDocs, divideExact, documentLock, effectiveFilter, emptyDoc, encodeView, fold, foldingPairs, formatExact, formatTextTime, formulaRefs, freeSpot, inSpan, isBound, isDateRange, isLeaf, isMark, isZone, itemLink, layoutGaps, linearTerms, linkTemplateIssues, lockChanged, markShifted, markedRows, memberLabel, momentMicros, namedPolicy, nextBucketStart, offsetSegments, parseDate, parseExact, parseMemberId, parseNaiveTime, parseTextTime, pickProblem, placeItem, placementOf, policyBinding, principalTenant, queryClosure, readingOrder, recordColumns, recordDimensions, reduce, reduceAll, repairLayout, replay, resolveDimension, resolveMeasure, resolveNaive, resolveRange, resultColumns, rowValue, ruleMatches, schemaChecks, schemaStatements, selectRule, shareOf, shiftBucket, shiftInstant, startOfDate, stepCommands, stepMoves, storedExact, stripIds, sumLinear, tileInputs, toWire, validateModel, viaJoins, viewFor, viewerValues, widgetDiff, withView };
|
package/dist/core/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BASE_ERROR_CODES, defineErrorCodes } from "./error/codes.mjs";
|
|
1
|
+
import { BASE_ERROR_CODES, DRILL_REASONS, defineErrorCodes } from "./error/codes.mjs";
|
|
2
2
|
import { changedWidget, diffDocs, markShifted, placementOf, widgetDiff } from "./document/diff.mjs";
|
|
3
3
|
import { GRID_COLUMNS, closeGaps, closeGapsCommands, freeSpot, layoutGaps, placeItem, repairLayout } from "./document/layout.mjs";
|
|
4
4
|
import { lockChanged, reduce, reduceAll } from "./document/reduce.mjs";
|
|
@@ -6,7 +6,7 @@ import { commandWidget, replay } from "./document/replay.mjs";
|
|
|
6
6
|
import { readingOrder, stepCommands, stepMoves } from "./document/stacked.mjs";
|
|
7
7
|
import { emptyDoc } from "./document/types.mjs";
|
|
8
8
|
import { checkCatalog } from "./model/catalog/check.mjs";
|
|
9
|
-
import { VIEW_PREFIX, encodeView, viewFor } from "./document/view.mjs";
|
|
9
|
+
import { VIEW_PREFIX, encodeView, viewFor, withView } from "./document/view.mjs";
|
|
10
10
|
import { describeQueries } from "./model/catalog/queries.mjs";
|
|
11
11
|
import { EXACT_LIMIT, divideExact, formatExact, parseExact, storedExact } from "./exact/decimal.mjs";
|
|
12
12
|
import { rowValue, sumLinear } from "./exact/sum.mjs";
|
|
@@ -28,6 +28,8 @@ import { NEGATION_OF, NEGATIVE_OPS, NULL_OPS, POSITIVE_OPS, isBound, isLeaf, str
|
|
|
28
28
|
import { changeOf, formulaRefs, shareOf } from "./query/formulas.mjs";
|
|
29
29
|
import { isDateRange, pickProblem } from "./query/picks.mjs";
|
|
30
30
|
import { QueryReferenceError, toWire } from "./query/to-wire.mjs";
|
|
31
|
+
import { LINK_PART, itemLink, linkTemplateIssues } from "./query/drill/links.mjs";
|
|
32
|
+
import { MAX_DRILL_STEPS } from "./query/drill/types.mjs";
|
|
31
33
|
import { memberLabel, recordColumns, resultColumns } from "./result/columns.mjs";
|
|
32
34
|
import { isMark, markedRows } from "./result/marks.mjs";
|
|
33
35
|
import { CONTRACT_VERSION } from "./types/api.mjs";
|
|
@@ -42,4 +44,4 @@ import { createDashEndpoint } from "./types/plugin.mjs";
|
|
|
42
44
|
import { principalTenant } from "./types/viewer.mjs";
|
|
43
45
|
import { canonical } from "./value/canonical.mjs";
|
|
44
46
|
import { fold, foldingPairs } from "./value/casefold.mjs";
|
|
45
|
-
export { BASE_ERROR_CODES, CATALOG, CONTRACT_VERSION, DEFAULT_COMPOSITION_POLICY, EXACT_LIMIT, EXPR_FUNCTIONS, GRID_COLUMNS, MICROS_PER_DAY, MICROS_PER_HOUR, MICROS_PER_SECOND, ModelError, NEGATION_OF, NEGATIVE_OPS, NULL_OPS, POSITIVE_OPS, QueryReferenceError, TABLES, VIEW_PREFIX, bindFilter, bindPolicy, bucketLabel, bucketLabels, bucketStart, canonical, changeOf, changedWidget, checkCatalog, closeGaps, closeGapsCommands, commandWidget, comparisonQuery, comparisonSpan, composeTile, createDashEndpoint, createTable, defineErrorCodes, defineModel, describeQueries, diffDocs, divideExact, documentLock, effectiveFilter, emptyDoc, encodeView, fold, foldingPairs, formatExact, formatTextTime, formulaRefs, freeSpot, inSpan, isBound, isDateRange, isLeaf, isMark, isZone, layoutGaps, linearTerms, lockChanged, markShifted, markedRows, memberLabel, momentMicros, namedPolicy, nextBucketStart, offsetSegments, parseDate, parseExact, parseMemberId, parseNaiveTime, parseTextTime, pickProblem, placeItem, placementOf, policyBinding, principalTenant, queryClosure, readingOrder, recordColumns, recordDimensions, reduce, reduceAll, repairLayout, replay, resolveDimension, resolveMeasure, resolveNaive, resolveRange, resultColumns, rowValue, ruleMatches, schemaChecks, schemaStatements, selectRule, shareOf, shiftBucket, shiftInstant, startOfDate, stepCommands, stepMoves, storedExact, stripIds, sumLinear, tileInputs, toWire, validateModel, viaJoins, viewFor, viewerValues, widgetDiff };
|
|
47
|
+
export { BASE_ERROR_CODES, CATALOG, CONTRACT_VERSION, DEFAULT_COMPOSITION_POLICY, DRILL_REASONS, EXACT_LIMIT, EXPR_FUNCTIONS, GRID_COLUMNS, LINK_PART, MAX_DRILL_STEPS, MICROS_PER_DAY, MICROS_PER_HOUR, MICROS_PER_SECOND, ModelError, NEGATION_OF, NEGATIVE_OPS, NULL_OPS, POSITIVE_OPS, QueryReferenceError, TABLES, VIEW_PREFIX, bindFilter, bindPolicy, bucketLabel, bucketLabels, bucketStart, canonical, changeOf, changedWidget, checkCatalog, closeGaps, closeGapsCommands, commandWidget, comparisonQuery, comparisonSpan, composeTile, createDashEndpoint, createTable, defineErrorCodes, defineModel, describeQueries, diffDocs, divideExact, documentLock, effectiveFilter, emptyDoc, encodeView, fold, foldingPairs, formatExact, formatTextTime, formulaRefs, freeSpot, inSpan, isBound, isDateRange, isLeaf, isMark, isZone, itemLink, layoutGaps, linearTerms, linkTemplateIssues, lockChanged, markShifted, markedRows, memberLabel, momentMicros, namedPolicy, nextBucketStart, offsetSegments, parseDate, parseExact, parseMemberId, parseNaiveTime, parseTextTime, pickProblem, placeItem, placementOf, policyBinding, principalTenant, queryClosure, readingOrder, recordColumns, recordDimensions, reduce, reduceAll, repairLayout, replay, resolveDimension, resolveMeasure, resolveNaive, resolveRange, resultColumns, rowValue, ruleMatches, schemaChecks, schemaStatements, selectRule, shareOf, shiftBucket, shiftInstant, startOfDate, stepCommands, stepMoves, storedExact, stripIds, sumLinear, tileInputs, toWire, validateModel, viaJoins, viewFor, viewerValues, widgetDiff, withView };
|
|
@@ -48,7 +48,7 @@ const NUMBER_TYPES = {
|
|
|
48
48
|
float: true
|
|
49
49
|
};
|
|
50
50
|
function dimensionType(dim, column, path) {
|
|
51
|
-
if (dim.kind === "time" && !timeTypes(dim.storage).includes(column.type)) return [issue("COLUMN_TYPE_MISMATCH", path, `"${column.name}" is ${column.type}; time storage ${JSON.stringify(dim.storage)} reads ${timeTypes(dim.storage).join(" or ")}.`)];
|
|
51
|
+
if (dim.kind === "time" && !timeTypes(dim.storage).includes(column.type)) return [issue("COLUMN_TYPE_MISMATCH", path, timeTypes(dim.storage).length === 0 ? `${JSON.stringify(dim.storage)} is not a time storage.` : `"${column.name}" is ${column.type}; time storage ${JSON.stringify(dim.storage)} reads ${timeTypes(dim.storage).join(" or ")}.`)];
|
|
52
52
|
if (dim.kind === "number" && NUMBER_TYPES[column.type] !== true) return [issue("COLUMN_TYPE_MISMATCH", path, `"${column.name}" is ${column.type}; a number dimension reads integer, bigint, numeric or float. Cast it in the source's sql, or make it a string dimension.`)];
|
|
53
53
|
if (dim.kind === "string" && dim.collation === "binary" && column.collation === "citext") return [issue("COLLATION_MISMATCH", path, `"${column.name}" compares without case; declare the dimension's collation "ci".`)];
|
|
54
54
|
return [];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { DimensionName } from "../types/primitives.mjs";
|
|
2
|
+
/** The rows behind a tile or a drill: which fields show, in what order, and how a row is named. */
|
|
3
|
+
export type RecordsHint = {
|
|
4
|
+
/** How rows are ordered; newest first by the source's time when left out. */
|
|
5
|
+
order?: readonly (readonly [DimensionName, "asc" | "desc"])[];
|
|
6
|
+
/** The fields a row shows; the safe default fields when left out. */
|
|
7
|
+
columns?: readonly DimensionName[];
|
|
8
|
+
/** The field that names a row in a list ("name", "subject"). */
|
|
9
|
+
title?: DimensionName;
|
|
10
|
+
/**
|
|
11
|
+
* Whether an item carries its source key (`item.key`), for a link to its page. Exposed by
|
|
12
|
+
* default; never shown as a column either way.
|
|
13
|
+
*/
|
|
14
|
+
key?: "expose" | "hide";
|
|
15
|
+
};
|
|
16
|
+
/** What one row of a source is called: `{ one: "order", other: "orders" }`. */
|
|
17
|
+
export type Noun = {
|
|
18
|
+
one: string;
|
|
19
|
+
other: string;
|
|
20
|
+
};
|
|
21
|
+
/** How a number field reads: a currency or unit, and whether it is stored in minor units. */
|
|
22
|
+
export type NumberFormat = {
|
|
23
|
+
unit?: string;
|
|
24
|
+
minor?: true;
|
|
25
|
+
};
|
|
26
|
+
/** A word's tone when a field shows as a badge: always shown as text, never as color alone. */
|
|
27
|
+
export type Tone = "positive" | "negative" | "warning" | "neutral";
|
|
28
|
+
/** The hints a dimension may carry: drill offers, number format, value tones. */
|
|
29
|
+
export type DimensionHints = {
|
|
30
|
+
/** `false` never offers the field in a drill's Breakdown, nor shows it in default Items. */
|
|
31
|
+
drill?: false;
|
|
32
|
+
format?: NumberFormat;
|
|
33
|
+
/** A number's bucket edges, ascending: Breakdown offers the number by these buckets. */
|
|
34
|
+
buckets?: readonly number[];
|
|
35
|
+
tones?: Readonly<Record<string, Tone>>;
|
|
36
|
+
};
|
|
@@ -20,7 +20,9 @@ export declare function resolveDimension(model: Model, sourceName: string, id: s
|
|
|
20
20
|
/** The measure a member id names. Measures are always the source's own. */
|
|
21
21
|
export declare function resolveMeasure(model: Model, sourceName: string, id: string): MeasureDef | undefined;
|
|
22
22
|
/**
|
|
23
|
-
* The dimensions a records view of a source shows, by name: its `records.columns`, or
|
|
24
|
-
*
|
|
23
|
+
* The dimensions a records view of a source shows, by name: its `records.columns`, or else up
|
|
24
|
+
* to twelve that are neither hidden, sensitive nor `drill: false`: its text fields, then its
|
|
25
|
+
* time field, then numbers and booleans, each in the model's order. The same rule serves the
|
|
26
|
+
* records endpoint and a drill's Items.
|
|
25
27
|
*/
|
|
26
28
|
export declare function recordDimensions(model: Model, sourceName: string): string[];
|
|
@@ -46,13 +46,26 @@ function resolveMeasure(model, sourceName, id) {
|
|
|
46
46
|
if (ref === void 0 || ref.source !== sourceName || ref.join !== void 0) return void 0;
|
|
47
47
|
return model.sources[sourceName]?.measures[ref.name];
|
|
48
48
|
}
|
|
49
|
+
/** A dimension's place in a default records view: text first, then time, then the rest. */
|
|
50
|
+
function shownRank(def, isTime) {
|
|
51
|
+
if (def.kind === "string" || def.kind === "ref" || def.kind === "bucket") return 0;
|
|
52
|
+
if (def.kind === "expr" && def.type === "string") return 0;
|
|
53
|
+
return isTime ? 1 : 2;
|
|
54
|
+
}
|
|
55
|
+
/** A records view's columns when the source names none: up to this many of its dimensions. */
|
|
56
|
+
const DEFAULT_RECORD_COLUMNS = 12;
|
|
49
57
|
/**
|
|
50
|
-
* The dimensions a records view of a source shows, by name: its `records.columns`, or
|
|
51
|
-
*
|
|
58
|
+
* The dimensions a records view of a source shows, by name: its `records.columns`, or else up
|
|
59
|
+
* to twelve that are neither hidden, sensitive nor `drill: false`: its text fields, then its
|
|
60
|
+
* time field, then numbers and booleans, each in the model's order. The same rule serves the
|
|
61
|
+
* records endpoint and a drill's Items.
|
|
52
62
|
*/
|
|
53
63
|
function recordDimensions(model, sourceName) {
|
|
54
64
|
const def = model.sources[sourceName];
|
|
55
65
|
if (def === void 0) return [];
|
|
56
|
-
|
|
66
|
+
if (def.records?.columns !== void 0) return def.records.columns.filter((n) => def.dimensions[n] !== void 0);
|
|
67
|
+
const time = def.time ?? Object.entries(def.dimensions).find(([, d]) => d.kind === "time")?.[0];
|
|
68
|
+
const rank = ([n, d]) => shownRank(d, n === time);
|
|
69
|
+
return Object.entries(def.dimensions).filter(([n]) => !n.startsWith("dd_")).filter(([, d]) => d.hidden !== true && d.sensitive !== true && d.drill !== false).filter(([n, d]) => d.kind !== "time" || n === time).toSorted((a, b) => rank(a) - rank(b)).slice(0, DEFAULT_RECORD_COLUMNS).map(([n]) => n);
|
|
57
70
|
}
|
|
58
71
|
export { parseMemberId, recordDimensions, resolveDimension, resolveMeasure };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Op, ViewerRef, WireFilter } from "../query/filter.mjs";
|
|
2
2
|
import { Column, ConnectionId, DimensionName, IanaZone, JoinName, MeasureName, PolicyName, Primitive, SourceName, TenantKey } from "../types/primitives.mjs";
|
|
3
3
|
import { Channel } from "../types/viewer.mjs";
|
|
4
|
+
import { DimensionHints, Noun, RecordsHint } from "./hints.mjs";
|
|
4
5
|
/**
|
|
5
6
|
* The semantic model: plain data, owned by the host as code. Tenancy and row access are part
|
|
6
7
|
* of it, and both are opt-in: with tenant keys, no source can be queried outside its tenant.
|
|
@@ -125,11 +126,8 @@ export type SourceDef = SourceRelation & {
|
|
|
125
126
|
acknowledgeOpenPolicy?: true;
|
|
126
127
|
/** Always applied, for example `removed_at` is not set. Shown in the receipt. */
|
|
127
128
|
where?: WireFilter;
|
|
128
|
-
records?:
|
|
129
|
-
|
|
130
|
-
columns: readonly DimensionName[];
|
|
131
|
-
link?: string;
|
|
132
|
-
};
|
|
129
|
+
records?: RecordsHint;
|
|
130
|
+
noun?: Noun;
|
|
133
131
|
joins?: Record<JoinName, JoinDef>;
|
|
134
132
|
measures: Record<MeasureName, MeasureDef>;
|
|
135
133
|
dimensions: Record<DimensionName, DimensionDef>;
|
|
@@ -137,6 +135,10 @@ export type SourceDef = SourceRelation & {
|
|
|
137
135
|
limits?: {
|
|
138
136
|
maxWindowDays?: number;
|
|
139
137
|
};
|
|
138
|
+
/** Drill-in: Breakdown's field order (`prefer`), or `false` never to drill into this source. */
|
|
139
|
+
drill?: false | {
|
|
140
|
+
prefer: readonly string[];
|
|
141
|
+
};
|
|
140
142
|
};
|
|
141
143
|
export type MemberMeta = {
|
|
142
144
|
label?: string;
|
|
@@ -201,7 +203,7 @@ export type TimeStorage = "timestamptz" | "date" | "epoch_ms" | "epoch_s" | {
|
|
|
201
203
|
fractionDigits: number;
|
|
202
204
|
};
|
|
203
205
|
} | "text_parseable";
|
|
204
|
-
export type DimensionDef = MemberMeta & ({
|
|
206
|
+
export type DimensionDef = MemberMeta & DimensionHints & ({
|
|
205
207
|
kind: "string";
|
|
206
208
|
column: Column;
|
|
207
209
|
values?: readonly string[] | "lookup";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { parseMemberId } from "../member.mjs";
|
|
2
|
+
import { when } from "./issues.mjs";
|
|
3
|
+
// src/model/validate/drill.ts
|
|
4
|
+
/** Whether a `drill.prefer` entry names a dimension, `join.dimension`, or a join. */
|
|
5
|
+
function names(source, entry) {
|
|
6
|
+
const ref = parseMemberId(`source.${entry}`);
|
|
7
|
+
if (ref === void 0) return false;
|
|
8
|
+
if (ref.join !== void 0) return source.joins?.[ref.join] !== void 0;
|
|
9
|
+
return source.dimensions[ref.name] !== void 0 || source.joins?.[ref.name] !== void 0;
|
|
10
|
+
}
|
|
11
|
+
/** A dimension's hints fit it: a format on a number, tones for values it declares. */
|
|
12
|
+
function dimensionHintIssues(def, path) {
|
|
13
|
+
const declared = def.kind === "string" && Array.isArray(def.values) ? def.values : [];
|
|
14
|
+
const tones = Object.keys(def.tones ?? {});
|
|
15
|
+
return [
|
|
16
|
+
...when(def.buckets !== void 0 && (def.kind !== "number" || def.buckets.length === 0 || def.buckets.some((e, i) => i > 0 && e <= (def.buckets?.[i - 1] ?? e))), "HINT_INVALID", [...path, "buckets"], "Bucket edges sit on a number dimension and go up, one after another."),
|
|
17
|
+
...when(def.format !== void 0 && def.kind !== "number", "HINT_INVALID", [...path, "format"], "A number format sits on a number dimension."),
|
|
18
|
+
...tones.flatMap((value) => when(!declared.includes(value), "HINT_INVALID", [
|
|
19
|
+
...path,
|
|
20
|
+
"tones",
|
|
21
|
+
value
|
|
22
|
+
], `"${value}" is not one of the dimension's declared values.`))
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
/** The keys a `records` hint may have; `link` was removed (routes live in `itemLinks`). */
|
|
26
|
+
const RECORDS_KEYS = Object.freeze({
|
|
27
|
+
order: true,
|
|
28
|
+
columns: true,
|
|
29
|
+
title: true,
|
|
30
|
+
key: true
|
|
31
|
+
});
|
|
32
|
+
/** A `records` hint has only its own keys, a `key` of "expose" or "hide", and a title a list may show. */
|
|
33
|
+
function recordsIssues(source, path) {
|
|
34
|
+
const records = source.records;
|
|
35
|
+
if (records === void 0) return [];
|
|
36
|
+
const at = [...path, "records"];
|
|
37
|
+
const title = source.records?.title;
|
|
38
|
+
const titled = title === void 0 ? void 0 : source.dimensions[title];
|
|
39
|
+
const key = source.records?.key;
|
|
40
|
+
return [
|
|
41
|
+
...Object.keys(records).flatMap((k) => when(!Object.hasOwn(RECORDS_KEYS, k), "MODEL_SHAPE", [...at, k], k === "link" ? "records.link was removed: pass itemLinks to deriveDashboards and the React UI instead." : `records has no "${k}": it takes order, columns, title and key.`)),
|
|
42
|
+
...when(key !== void 0 && key !== "expose" && key !== "hide", "HINT_INVALID", [...at, "key"], `records.key is "expose" or "hide", not ${JSON.stringify(key)}.`),
|
|
43
|
+
...when(titled !== void 0 && (titled.sensitive === true || titled.hidden === true), "HINT_INVALID", [...at, "title"], "A records title is never a sensitive or hidden field: it shows on every item.")
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
/** Each drill and records hint resolves: preferred fields, the records title, tones and formats. */
|
|
47
|
+
function drillIssues(source, path) {
|
|
48
|
+
const prefer = source.drill === false ? [] : source.drill?.prefer ?? [];
|
|
49
|
+
const title = source.records?.title;
|
|
50
|
+
return [
|
|
51
|
+
...recordsIssues(source, path),
|
|
52
|
+
...prefer.flatMap((entry, i) => when(!names(source, entry), "DRILL_PREFER_UNKNOWN", [
|
|
53
|
+
...path,
|
|
54
|
+
"drill",
|
|
55
|
+
"prefer",
|
|
56
|
+
i
|
|
57
|
+
], `"${entry}" is not a dimension, a join or a join's dimension of this source.`)),
|
|
58
|
+
...when(title !== void 0 && source.dimensions[title] === void 0, "HINT_INVALID", [
|
|
59
|
+
...path,
|
|
60
|
+
"records",
|
|
61
|
+
"title"
|
|
62
|
+
], `There is no dimension named "${title ?? ""}".`),
|
|
63
|
+
...Object.entries(source.dimensions).flatMap(([name, def]) => dimensionHintIssues(def, [
|
|
64
|
+
...path,
|
|
65
|
+
"dimensions",
|
|
66
|
+
name
|
|
67
|
+
]))
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
export { drillIssues };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { nameIssues, when } from "./issues.mjs";
|
|
2
2
|
import { rowPolicyIssues } from "./policy.mjs";
|
|
3
|
+
import { shapeIssues } from "./shape.mjs";
|
|
3
4
|
import { sourceIssues } from "./source.mjs";
|
|
4
5
|
import { viaCycleIssues } from "./via.mjs";
|
|
5
6
|
// src/model/validate/index.ts
|
|
@@ -11,6 +12,8 @@ import { viaCycleIssues } from "./via.mjs";
|
|
|
11
12
|
* job of the `check` command.
|
|
12
13
|
*/
|
|
13
14
|
function validateModel(model) {
|
|
15
|
+
const shaped = shapeIssues(model);
|
|
16
|
+
if (shaped.length > 0) return [...headerIssues(model), ...shaped];
|
|
14
17
|
const sources = Object.entries(model.sources ?? {});
|
|
15
18
|
return [
|
|
16
19
|
...headerIssues(model),
|