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
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Model, Numeric } from "../../model/types.mjs";
|
|
2
|
+
import { Cell } from "../types.mjs";
|
|
3
|
+
/** The row count every source has in a drill. */
|
|
4
|
+
export declare const ROW_COUNT = "dd_rows";
|
|
5
|
+
/** A one-column key as a field, hidden: a drill looks a linked row up by it. */
|
|
6
|
+
export declare const KEY_FIELD = "dd_key";
|
|
7
|
+
/** The model a drill reads: each source with its drill's own fields (`dd_...`). */
|
|
8
|
+
export declare function drillModel(model: Model): Model;
|
|
9
|
+
/**
|
|
10
|
+
* A measure's own column, read as text by a drill's field, as the measure's values read: an
|
|
11
|
+
* exact number at its scale (minor units moved to it, decimal text padded to it), a float as a
|
|
12
|
+
* number. Text that is not an exact value of the column stays as it came.
|
|
13
|
+
*/
|
|
14
|
+
export declare function storedCell(numeric: Numeric | undefined, value: Cell): Cell;
|
|
15
|
+
/** A true-or-false field as read back: a boolean, whatever text the store wrote it as. */
|
|
16
|
+
export declare function flagCell(cell: Cell): Cell;
|
|
17
|
+
/**
|
|
18
|
+
* The member of the host's model a drill's own field stands for, so an access check asks the
|
|
19
|
+
* host about a member it knows: a measure's field is that measure, a bucket its number field,
|
|
20
|
+
* the row count none (the source's own check covers it). Any other member is itself.
|
|
21
|
+
*/
|
|
22
|
+
export declare function drillOwner(id: string): string | undefined;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { formatExact, storedExact } from "../../exact/decimal.mjs";
|
|
2
|
+
import { parseMemberId } from "../../model/member.mjs";
|
|
3
|
+
import { memberLabel } from "../../result/columns.mjs";
|
|
4
|
+
import { operandColumn } from "./operand.mjs";
|
|
5
|
+
import { FALSE, TRUE, branch, numeratorExpr } from "./synthetic-expr.mjs";
|
|
6
|
+
// src/query/drill/synthetic.ts
|
|
7
|
+
/** The row count every source has in a drill. */
|
|
8
|
+
const ROW_COUNT = "dd_rows";
|
|
9
|
+
const valueName = (measure) => `dd_value_${measure}`;
|
|
10
|
+
const distinctName = (measure) => `dd_distinct_${measure}`;
|
|
11
|
+
/** A one-column key as a field, hidden: a drill looks a linked row up by it. */
|
|
12
|
+
const KEY_FIELD = "dd_key";
|
|
13
|
+
const flagName = (measure) => `dd_flag_${measure}`;
|
|
14
|
+
const setName = (measure) => `dd_set_${measure}`;
|
|
15
|
+
/** A sum's least row value: a share of it is only a share when no row is negative. */
|
|
16
|
+
const minName = (measure) => `dd_min_${measure}`;
|
|
17
|
+
const bucketName = (dimension) => `dd_bucket_${dimension}`;
|
|
18
|
+
/** A column no sensitive or hidden field reads, so showing it row by row shows nothing kept back. */
|
|
19
|
+
function openColumn(def, column) {
|
|
20
|
+
return !Object.values(def.dimensions).some((d) => "column" in d && d.column === column && (d.sensitive === true || d.hidden === true));
|
|
21
|
+
}
|
|
22
|
+
/** A column's values as text, exactly as stored: a drill's own field, never offered. */
|
|
23
|
+
const textField = (column) => ({
|
|
24
|
+
kind: "string",
|
|
25
|
+
column,
|
|
26
|
+
collation: "binary",
|
|
27
|
+
hidden: true
|
|
28
|
+
});
|
|
29
|
+
/** A source's one-column key as a hidden text field, so a linked row can be looked up by its key. */
|
|
30
|
+
const keyField = (def) => {
|
|
31
|
+
const [column, ...more] = def.key;
|
|
32
|
+
return column === void 0 || more.length > 0 ? [] : [[KEY_FIELD, textField(column)]];
|
|
33
|
+
};
|
|
34
|
+
/** The labels of a number's buckets from its edges: "< 10", "10 to 100", "100 or more". */
|
|
35
|
+
const bucketLabels = (edges) => [
|
|
36
|
+
`< ${String(edges[0])}`,
|
|
37
|
+
...edges.slice(1).map((e, i) => `${String(edges[i])} to ${String(e)}`),
|
|
38
|
+
`${String(edges.at(-1))} or more`
|
|
39
|
+
];
|
|
40
|
+
/** "This column is set", true or false: a predicate, never a value, so it may read any column. */
|
|
41
|
+
const setField = (column) => ({
|
|
42
|
+
kind: "expr",
|
|
43
|
+
expr: branch({
|
|
44
|
+
left: { col: column },
|
|
45
|
+
op: "set",
|
|
46
|
+
values: []
|
|
47
|
+
}, TRUE, FALSE),
|
|
48
|
+
type: "boolean",
|
|
49
|
+
hidden: true
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* The fields one measure adds: whether its column is set (for its population, whoever asks),
|
|
53
|
+
* its column per row and its distinct values (only when no kept-back field reads the column),
|
|
54
|
+
* and its numerator flag.
|
|
55
|
+
*/
|
|
56
|
+
function measureFields(def, source, name, m) {
|
|
57
|
+
const operand = operandColumn(m);
|
|
58
|
+
const of = "of" in m && typeof m.of === "string" ? m.of : void 0;
|
|
59
|
+
const distinct = m.kind === "count" ? m.distinct : void 0;
|
|
60
|
+
const expr = m.kind === "ratio" ? numeratorExpr(def, source, m.numerator) : void 0;
|
|
61
|
+
const field = (on, entry) => on ? [entry] : [];
|
|
62
|
+
return [
|
|
63
|
+
...operand === void 0 ? [] : [[setName(name), setField(operand)]],
|
|
64
|
+
...of === void 0 ? [] : field(openColumn(def, of), [valueName(name), textField(of)]),
|
|
65
|
+
...distinct === void 0 ? [] : field(openColumn(def, distinct), [distinctName(name), textField(distinct)]),
|
|
66
|
+
...expr === void 0 ? [] : [[flagName(name), {
|
|
67
|
+
kind: "expr",
|
|
68
|
+
expr,
|
|
69
|
+
type: "boolean",
|
|
70
|
+
hidden: true
|
|
71
|
+
}]]
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
/** A number's declared buckets as a bucket field, offered in Breakdown in its place. */
|
|
75
|
+
function bucketFields(def) {
|
|
76
|
+
return Object.entries(def.dimensions).flatMap(([name, d]) => d.kind === "number" && d.buckets !== void 0 && d.buckets.length > 0 && d.sensitive !== true && d.hidden !== true && d.drill !== false ? [[bucketName(name), {
|
|
77
|
+
kind: "bucket",
|
|
78
|
+
of: d.column,
|
|
79
|
+
edges: d.buckets,
|
|
80
|
+
labels: bucketLabels(d.buckets),
|
|
81
|
+
label: memberLabel(name, d.label)
|
|
82
|
+
}]] : []);
|
|
83
|
+
}
|
|
84
|
+
/** One source with a drill's own fields; a name the source already has is left as it is. */
|
|
85
|
+
function drillSource(source, def) {
|
|
86
|
+
const fields = [
|
|
87
|
+
...Object.entries(def.measures).flatMap(([n, m]) => measureFields(def, source, n, m)),
|
|
88
|
+
...bucketFields(def),
|
|
89
|
+
...keyField(def)
|
|
90
|
+
].filter(([n]) => def.dimensions[n] === void 0);
|
|
91
|
+
const rows = def.measures["dd_rows"] === void 0 ? { [ROW_COUNT]: {
|
|
92
|
+
kind: "count",
|
|
93
|
+
merge: "sum"
|
|
94
|
+
} } : {};
|
|
95
|
+
const least = Object.entries(def.measures).flatMap(([n, m]) => m.kind === "sum" && typeof m.of === "string" && def.measures[minName(n)] === void 0 ? [[minName(n), {
|
|
96
|
+
kind: "min",
|
|
97
|
+
of: m.of,
|
|
98
|
+
numeric: m.numeric,
|
|
99
|
+
merge: "min",
|
|
100
|
+
hidden: true
|
|
101
|
+
}]] : []);
|
|
102
|
+
return {
|
|
103
|
+
...def,
|
|
104
|
+
measures: {
|
|
105
|
+
...def.measures,
|
|
106
|
+
...rows,
|
|
107
|
+
...Object.fromEntries(least)
|
|
108
|
+
},
|
|
109
|
+
dimensions: {
|
|
110
|
+
...def.dimensions,
|
|
111
|
+
...Object.fromEntries(fields)
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** The model a drill reads: each source with its drill's own fields (`dd_...`). */
|
|
116
|
+
function drillModel(model) {
|
|
117
|
+
return {
|
|
118
|
+
...model,
|
|
119
|
+
sources: Object.fromEntries(Object.entries(model.sources).map(([n, s]) => [n, drillSource(n, s)]))
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* A measure's own column, read as text by a drill's field, as the measure's values read: an
|
|
124
|
+
* exact number at its scale (minor units moved to it, decimal text padded to it), a float as a
|
|
125
|
+
* number. Text that is not an exact value of the column stays as it came.
|
|
126
|
+
*/
|
|
127
|
+
function storedCell(numeric, value) {
|
|
128
|
+
if (typeof value === "object") return value;
|
|
129
|
+
const cell = typeof value === "number" && Number.isSafeInteger(value) ? String(value) : value;
|
|
130
|
+
if (numeric === void 0 || numeric === "float") return typeof cell === "string" && cell !== "" && Number.isFinite(Number(cell)) ? Number(cell) : cell;
|
|
131
|
+
const exact = storedExact(cell, numeric.stored, numeric.scale);
|
|
132
|
+
return exact === null ? cell : {
|
|
133
|
+
t: "decimal",
|
|
134
|
+
v: formatExact(exact, numeric.scale)
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/** A true-or-false field as read back: a boolean, whatever text the store wrote it as. */
|
|
138
|
+
function flagCell(cell) {
|
|
139
|
+
if (cell === "true" || cell === "t") return true;
|
|
140
|
+
return cell === "false" || cell === "f" ? false : cell;
|
|
141
|
+
}
|
|
142
|
+
/** A drill's own field's prefix, and whether the rest of its name is a measure's or a dimension's. */
|
|
143
|
+
const OWN = Object.freeze([
|
|
144
|
+
["dd_value_", "measure"],
|
|
145
|
+
["dd_distinct_", "measure"],
|
|
146
|
+
["dd_flag_", "measure"],
|
|
147
|
+
["dd_set_", "measure"],
|
|
148
|
+
["dd_min_", "measure"],
|
|
149
|
+
["dd_bucket_", "dimension"]
|
|
150
|
+
]);
|
|
151
|
+
/**
|
|
152
|
+
* The member of the host's model a drill's own field stands for, so an access check asks the
|
|
153
|
+
* host about a member it knows: a measure's field is that measure, a bucket its number field,
|
|
154
|
+
* the row count none (the source's own check covers it). Any other member is itself.
|
|
155
|
+
*/
|
|
156
|
+
function drillOwner(id) {
|
|
157
|
+
const ref = parseMemberId(id);
|
|
158
|
+
if (ref === void 0 || !ref.name.startsWith("dd_")) return id;
|
|
159
|
+
if (ref.name === "dd_rows") return void 0;
|
|
160
|
+
const own = OWN.find(([prefix]) => ref.name.startsWith(prefix));
|
|
161
|
+
if (own === void 0) return id;
|
|
162
|
+
const name = ref.name.slice(own[0].length);
|
|
163
|
+
return ref.join === void 0 ? `${ref.source}.${name}` : `${ref.source}.${ref.join}.${name}`;
|
|
164
|
+
}
|
|
165
|
+
export { KEY_FIELD, ROW_COUNT, drillModel, drillOwner, flagCell, flagName, minName, setName, storedCell, valueName };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Model } from "../../model/types.mjs";
|
|
2
|
+
import { Moment } from "../../time/temporal.mjs";
|
|
3
|
+
import { Calendar, Grain, WireQuery } from "../types.mjs";
|
|
4
|
+
/** When a request runs, as the engine resolves ranges: its `now`, zone and quantum. */
|
|
5
|
+
export type DrillClock = {
|
|
6
|
+
now: Moment;
|
|
7
|
+
calendar: Calendar;
|
|
8
|
+
quantumSeconds: number;
|
|
9
|
+
};
|
|
10
|
+
/** The rows behind a drill over time: its range (the last 12 months when the tile has none), by a grain. */
|
|
11
|
+
export declare function trendQuery(model: Model, set: WireQuery, clock: DrillClock, grain?: Grain): WireQuery;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { EngineError } from "../../error/refusal.mjs";
|
|
2
|
+
import { resolveDimension } from "../../model/member.mjs";
|
|
3
|
+
import { MICROS_PER_DAY, formatTextTime } from "../../time/instant.mjs";
|
|
4
|
+
import { resolveRange } from "../../time/range.mjs";
|
|
5
|
+
import { momentMicros } from "../../time/temporal.mjs";
|
|
6
|
+
import { trendDimension } from "./fields.mjs";
|
|
7
|
+
// src/query/drill/time.ts
|
|
8
|
+
const refuse = (message) => {
|
|
9
|
+
throw new EngineError("SELECTION_INVALID", message);
|
|
10
|
+
};
|
|
11
|
+
/** A window's instants; refused unless both ends read and `from` is before `to`. */
|
|
12
|
+
function windowSpan(step, calendar) {
|
|
13
|
+
const span = resolveRange(step, 0, calendar);
|
|
14
|
+
if (span === void 0 || span.from >= span.to) return refuse("A time step has no span.");
|
|
15
|
+
return span;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The tile's range, narrowed to every time step's window: never wider than either. Without a
|
|
19
|
+
* time step it is the tile's own range, with no grain and no comparison.
|
|
20
|
+
*/
|
|
21
|
+
function drilledTime(model, query, steps, clock) {
|
|
22
|
+
const buckets = steps.flatMap((s) => "bucket" in s ? [s.bucket] : []);
|
|
23
|
+
const own = query.time;
|
|
24
|
+
if (buckets.length === 0) return own === void 0 ? void 0 : {
|
|
25
|
+
dimension: own.dimension,
|
|
26
|
+
range: own.range
|
|
27
|
+
};
|
|
28
|
+
const dimension = trendDimension(model, query) ?? refuse("This source has no time field.");
|
|
29
|
+
if (buckets.some((b) => b.member !== dimension)) refuse(`A time step is on "${dimension}".`);
|
|
30
|
+
const quantum = clock.quantumSeconds * 1e6 || 1;
|
|
31
|
+
const spans = [...own === void 0 ? [] : [resolveRange(own.range, momentMicros(clock.now), clock.calendar, quantum)], ...buckets.map((b) => windowSpan(b, clock.calendar))];
|
|
32
|
+
const from = Math.max(...spans.map((s) => s?.from ?? -Infinity));
|
|
33
|
+
const to = Math.max(from, Math.min(...spans.map((s) => s?.to ?? Infinity)));
|
|
34
|
+
return {
|
|
35
|
+
dimension,
|
|
36
|
+
range: {
|
|
37
|
+
from: formatTextTime(from),
|
|
38
|
+
to: formatTextTime(to)
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** A grain that draws a range in a readable number of points. */
|
|
43
|
+
function fitGrain(days, dateOnly) {
|
|
44
|
+
if (days <= 2 && !dateOnly) return "hour";
|
|
45
|
+
if (days <= 62) return "day";
|
|
46
|
+
if (days <= 210) return "week";
|
|
47
|
+
return days <= 1100 ? "month" : "quarter";
|
|
48
|
+
}
|
|
49
|
+
/** The rows behind a drill over time: its range (the last 12 months when the tile has none), by a grain. */
|
|
50
|
+
function trendQuery(model, set, clock, grain) {
|
|
51
|
+
const dimension = trendDimension(model, set) ?? refuse("This source has no time field to draw over time.");
|
|
52
|
+
const range = set.time?.range ?? {
|
|
53
|
+
last: 12,
|
|
54
|
+
unit: "month",
|
|
55
|
+
includeCurrent: true
|
|
56
|
+
};
|
|
57
|
+
const span = resolveRange(range, momentMicros(clock.now), clock.calendar);
|
|
58
|
+
const days = span === void 0 ? 0 : (span.to - span.from) / MICROS_PER_DAY;
|
|
59
|
+
const def = resolveDimension(model, set.source, dimension)?.dimension;
|
|
60
|
+
const dateOnly = def?.kind === "time" && def.storage === "date";
|
|
61
|
+
return {
|
|
62
|
+
...set,
|
|
63
|
+
time: {
|
|
64
|
+
dimension,
|
|
65
|
+
range,
|
|
66
|
+
grain: grain ?? fitGrain(days, dateOnly)
|
|
67
|
+
},
|
|
68
|
+
fill: "zero"
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export { drilledTime, trendQuery };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { DrillReason } from "../../error/codes.mjs";
|
|
2
|
+
import { Primitive } from "../../types/primitives.mjs";
|
|
3
|
+
import { Calendar, Cell, Grain, Picks, ResolvedRange, WireQuery } from "../types.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* One step into the rows behind a mark, as the server reads it from the answer it drew:
|
|
6
|
+
*
|
|
7
|
+
* - `group`: a bar, a slice, a table row or a cell, one value per field it is grouped by (a
|
|
8
|
+
* segment carries both). A null value is the group of rows where the field is not set.
|
|
9
|
+
* - `bucket`: a time point, its exact window `[from, to)` from the engine's own calendar.
|
|
10
|
+
* - `other`: the rows a limit left out: those in none of the groups it kept, each group its
|
|
11
|
+
* values of `members`. The kept set is the engine's own, complete, never read off the rows.
|
|
12
|
+
* - `search`: the rows whose field contains a text, as a searched Breakdown read them; it
|
|
13
|
+
* travels with an Other drawn under the search, so that Other stays the searched one.
|
|
14
|
+
*
|
|
15
|
+
* A step never travels as itself: it is sealed into a selection, so a client cannot write one.
|
|
16
|
+
*/
|
|
17
|
+
export type DrillStep = {
|
|
18
|
+
group: readonly {
|
|
19
|
+
member: string;
|
|
20
|
+
value: Primitive;
|
|
21
|
+
}[];
|
|
22
|
+
} | {
|
|
23
|
+
bucket: {
|
|
24
|
+
member: string;
|
|
25
|
+
from: string;
|
|
26
|
+
to: string;
|
|
27
|
+
grain?: Grain;
|
|
28
|
+
};
|
|
29
|
+
} | {
|
|
30
|
+
other: {
|
|
31
|
+
members: readonly string[];
|
|
32
|
+
kept: readonly (readonly Primitive[])[];
|
|
33
|
+
};
|
|
34
|
+
} | {
|
|
35
|
+
search: {
|
|
36
|
+
member: string;
|
|
37
|
+
text: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* What a selection holds, sealed by the server: the steps one mark adds (none for a total or a
|
|
42
|
+
* single number), and the mark's value of each line when it was drawn, by its column id.
|
|
43
|
+
*/
|
|
44
|
+
export type Selection = {
|
|
45
|
+
steps: readonly DrillStep[];
|
|
46
|
+
clicked?: Readonly<Record<string, Cell>>;
|
|
47
|
+
/** A mark of the comparison period: its rows are read in that period's window. */
|
|
48
|
+
previous?: true;
|
|
49
|
+
/** The execution it was drawn under (`PinnedExecution.id`): a selection opens only under it. */
|
|
50
|
+
exec?: string;
|
|
51
|
+
/** The steps it was drawn under, as a digest: a selection opens only after those same steps. */
|
|
52
|
+
parent?: string;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* What an execution holds, sealed by the server: the range the tile resolved to, its calendar
|
|
56
|
+
* and the document's version, so a drill opened at 23:59 still reads the same day at midnight.
|
|
57
|
+
*/
|
|
58
|
+
export type PinnedExecution = {
|
|
59
|
+
/** Names this execution, so a selection drawn under another one is refused. */
|
|
60
|
+
id: string;
|
|
61
|
+
/** Who drew it: the fingerprint of the issuing viewer's access, never readable. */
|
|
62
|
+
by: string;
|
|
63
|
+
/** A draft's content as drawn, so a draft that changed since is stale. */
|
|
64
|
+
revision?: string;
|
|
65
|
+
range?: ResolvedRange;
|
|
66
|
+
/**
|
|
67
|
+
* The instant the answer was drawn at: a relative range ("last 30 days") is read again at
|
|
68
|
+
* it, so the drill reads the same span and the same period before as the tile.
|
|
69
|
+
*/
|
|
70
|
+
now?: string;
|
|
71
|
+
/** The comparison period's range, for a mark of the period before. */
|
|
72
|
+
compare?: ResolvedRange;
|
|
73
|
+
calendar: Calendar;
|
|
74
|
+
version?: number;
|
|
75
|
+
};
|
|
76
|
+
/** A path into a tile, opened: its steps, and which of its lines was clicked (`m1`, `c1`). */
|
|
77
|
+
export type Drill = {
|
|
78
|
+
steps: readonly DrillStep[];
|
|
79
|
+
measure?: string;
|
|
80
|
+
};
|
|
81
|
+
/** Where a drill starts: a dashboard's tile, by reference, or a free query. */
|
|
82
|
+
export type DrillOrigin = {
|
|
83
|
+
kind: "dashboard";
|
|
84
|
+
dashboardId: string;
|
|
85
|
+
widgetId: string;
|
|
86
|
+
/** One of the widget's queries; `main` when not given. */
|
|
87
|
+
query?: string;
|
|
88
|
+
picks: Picks;
|
|
89
|
+
/** An earlier version, or the viewer's draft; the published head when not given. */
|
|
90
|
+
document?: {
|
|
91
|
+
version: number;
|
|
92
|
+
} | {
|
|
93
|
+
draft: true;
|
|
94
|
+
};
|
|
95
|
+
} | {
|
|
96
|
+
kind: "query";
|
|
97
|
+
query: WireQuery;
|
|
98
|
+
};
|
|
99
|
+
/** What a drill shows. */
|
|
100
|
+
export type DrillView = {
|
|
101
|
+
by: "breakdown";
|
|
102
|
+
member?: string;
|
|
103
|
+
search?: string;
|
|
104
|
+
} | {
|
|
105
|
+
by: "trend";
|
|
106
|
+
grain?: Grain;
|
|
107
|
+
} |
|
|
108
|
+
/** `numerator`: a ratio's Items, only the rows its numerator counts. */
|
|
109
|
+
{
|
|
110
|
+
by: "items";
|
|
111
|
+
numerator?: true;
|
|
112
|
+
} | {
|
|
113
|
+
by: "explanation";
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* A drill as plain data: where it starts, which line was clicked (`entry`, a column id such as
|
|
117
|
+
* `m1`; needed when the tile has more than one), the pinned execution and the path, both sealed
|
|
118
|
+
* by the server, and the view open. It lives in a dashboard's view state, so Share and Back keep
|
|
119
|
+
* it, and it is all a page of the host's own needs to open the drill.
|
|
120
|
+
*/
|
|
121
|
+
export type DrillState = {
|
|
122
|
+
origin: DrillOrigin;
|
|
123
|
+
entry?: string;
|
|
124
|
+
execution: string;
|
|
125
|
+
/** Sealed selections, root first; at most `MAX_DRILL_STEPS`. */
|
|
126
|
+
path: readonly string[];
|
|
127
|
+
view: DrillView;
|
|
128
|
+
/** The view each earlier step had, so a breadcrumb opens it as it was. */
|
|
129
|
+
views?: readonly DrillView[];
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* What the limits of an answer kept, as the engine ranked them: each dimension with a limit of
|
|
133
|
+
* its own, by its index, with every value it kept (whether or not a row shows it). A drill's
|
|
134
|
+
* Other is the rows in none of them, so it is read from here, never from the rows drawn.
|
|
135
|
+
*/
|
|
136
|
+
export type Cuts = {
|
|
137
|
+
segments: readonly (readonly [number, readonly Cell[]])[];
|
|
138
|
+
};
|
|
139
|
+
/** A path is at most this many selections; a deeper one is refused. */
|
|
140
|
+
export declare const MAX_DRILL_STEPS = 8;
|
|
141
|
+
/** A field a drill can be broken down by, as a viewer reads it. */
|
|
142
|
+
export type DrillField = {
|
|
143
|
+
id: string;
|
|
144
|
+
label: string;
|
|
145
|
+
};
|
|
146
|
+
/** What the rows behind a line are, and so what its Items list. */
|
|
147
|
+
export type DrillSemantics = "rows" | "non-null" | "distinct" | "ratio" | "expression";
|
|
148
|
+
/** Whether a drill can show a view, and why not when it cannot: a code, and its English text. */
|
|
149
|
+
export type DrillCan = {
|
|
150
|
+
ok: true;
|
|
151
|
+
} | {
|
|
152
|
+
ok: false;
|
|
153
|
+
code: DrillReason;
|
|
154
|
+
reason: string;
|
|
155
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Model } from "../../model/types.mjs";
|
|
2
|
+
import { WireFilter } from "../filter.mjs";
|
|
3
|
+
import { MeasureAlias, WireQuery } from "../types.mjs";
|
|
4
|
+
import { Drill } from "./types.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* The population a line reads: the rows behind the drill that the line counts. It ANDs the
|
|
7
|
+
* line's own filter, its measure's `where` (a ratio's denominator's; with `numerator`, its
|
|
8
|
+
* numerator's too), and, for a measure of a field, that the field is set: read by a predicate
|
|
9
|
+
* of the drill's own (`dd_set_...`), whether or not the field may be shown, so the population
|
|
10
|
+
* never depends on what a viewer may see. Breakdown, Over time and Items all read it, and the
|
|
11
|
+
* drill law checks it against the oracle. A comparison is not part of it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function population(model: Model, set: WireQuery, drill: Drill, numerator?: boolean): WireQuery;
|
|
14
|
+
/** A line's own filter, its rows' `where`, its operand set, and its numerator's `where`; none for a formula. */
|
|
15
|
+
export declare function lineFilter(model: Model, set: WireQuery, drill: Drill, only?: {
|
|
16
|
+
numerator?: boolean;
|
|
17
|
+
operand?: boolean;
|
|
18
|
+
}): WireFilter | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The line's value and how many rows are behind it, in one read: the drill's query with the row
|
|
21
|
+
* count over the line's population (`dd_rows` with the line's filter) as one more measure, and,
|
|
22
|
+
* for a line that counts only rows whose field is set, the rows whether or not it is (`all`).
|
|
23
|
+
* Aliases are returned so each count is read by name.
|
|
24
|
+
*/
|
|
25
|
+
export declare function summaryQuery(model: Model, set: WireQuery, drill: Drill): {
|
|
26
|
+
query: WireQuery;
|
|
27
|
+
count: MeasureAlias;
|
|
28
|
+
all?: MeasureAlias;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The step before a sum's value, with its least row value, so a share of it is shown only
|
|
32
|
+
* when no row can be negative: a parent of 50 made of 100 and -50 has no 200% child.
|
|
33
|
+
*/
|
|
34
|
+
export declare function parentQuery(model: Model, parent: WireQuery, drill: Drill): {
|
|
35
|
+
query: WireQuery;
|
|
36
|
+
least?: MeasureAlias;
|
|
37
|
+
};
|
|
38
|
+
/** How a Breakdown reads: the comparison it shows the change against, and a search in its field. */
|
|
39
|
+
export type BreakdownOptions = {
|
|
40
|
+
compare?: NonNullable<WireQuery["time"]>["compare"];
|
|
41
|
+
search?: string;
|
|
42
|
+
/** The line does not add up (an average, a ratio): its groups rank by their row count. */
|
|
43
|
+
rankByRows?: boolean;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* The rows behind a drill broken down by one field: its top groups, then Other, ranked by the
|
|
47
|
+
* line when it adds up, else by the rows behind each (Rules, section 6: never by an average).
|
|
48
|
+
* With a comparison, each group's value now, before (`c1`) and its change (`c2`), the groups
|
|
49
|
+
* that moved most first (`c3`). With a search, only the groups whose value contains it.
|
|
50
|
+
*/
|
|
51
|
+
export declare function breakdownQuery(rows: WireQuery, member: string, drill: Drill, options?: BreakdownOptions): WireQuery;
|
|
52
|
+
/** How many rows a population holds: every source's rows counted (`dd_rows`, in a drill's model). */
|
|
53
|
+
export declare function countQuery(rows: WireQuery): WireQuery;
|
|
54
|
+
/**
|
|
55
|
+
* A distinct count's items, one page: its distinct values (never "not set": a distinct count
|
|
56
|
+
* skips it), each with its row count, most rows first then by value, so pages never overlap.
|
|
57
|
+
* It reads `take` past `skip`, and one more to say whether a page follows.
|
|
58
|
+
*/
|
|
59
|
+
export declare function distinctQuery(rows: WireQuery, field: string, page: {
|
|
60
|
+
skip: number;
|
|
61
|
+
take: number;
|
|
62
|
+
}): WireQuery;
|