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,257 @@
|
|
|
1
|
+
import { EngineError } from "../../error/refusal.mjs";
|
|
2
|
+
import { drillMeasure, lineMeasure, operandSet, rowsMeasure } from "./line.mjs";
|
|
3
|
+
import { ROW_COUNT, minName } from "./synthetic.mjs";
|
|
4
|
+
// src/query/drill/views.ts
|
|
5
|
+
/** Breakdown draws the top groups and puts the rest in Other. */
|
|
6
|
+
const BREAKDOWN_TOP = 10;
|
|
7
|
+
const anded = (set, parts) => {
|
|
8
|
+
const kept = parts.filter((f) => f !== void 0);
|
|
9
|
+
const [only, ...more] = kept;
|
|
10
|
+
const { filters: _f, ...rest } = set;
|
|
11
|
+
if (only === void 0) return rest;
|
|
12
|
+
return {
|
|
13
|
+
...rest,
|
|
14
|
+
filters: more.length === 0 ? only : { all: kept }
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
/** Filters ANDed into one, or none. */
|
|
18
|
+
const andAll = (parts) => {
|
|
19
|
+
const kept = parts.filter((f) => f !== void 0);
|
|
20
|
+
const [only, ...more] = kept;
|
|
21
|
+
return more.length === 0 ? only : { all: kept };
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The population a line reads: the rows behind the drill that the line counts. It ANDs the
|
|
25
|
+
* line's own filter, its measure's `where` (a ratio's denominator's; with `numerator`, its
|
|
26
|
+
* numerator's too), and, for a measure of a field, that the field is set: read by a predicate
|
|
27
|
+
* of the drill's own (`dd_set_...`), whether or not the field may be shown, so the population
|
|
28
|
+
* never depends on what a viewer may see. Breakdown, Over time and Items all read it, and the
|
|
29
|
+
* drill law checks it against the oracle. A comparison is not part of it.
|
|
30
|
+
*/
|
|
31
|
+
function population(model, set, drill, numerator) {
|
|
32
|
+
const time = set.time === void 0 ? {} : { time: {
|
|
33
|
+
dimension: set.time.dimension,
|
|
34
|
+
range: set.time.range
|
|
35
|
+
} };
|
|
36
|
+
return anded({
|
|
37
|
+
...set,
|
|
38
|
+
...time
|
|
39
|
+
}, [set.filters, lineFilter(model, set, drill, { numerator: numerator === true })]);
|
|
40
|
+
}
|
|
41
|
+
/** A line's own filter, its rows' `where`, its operand set, and its numerator's `where`; none for a formula. */
|
|
42
|
+
function lineFilter(model, set, drill, only) {
|
|
43
|
+
const line = lineMeasure(model, set, drill);
|
|
44
|
+
if (line === void 0) return void 0;
|
|
45
|
+
const rows = rowsMeasure(model, set.source, line);
|
|
46
|
+
if (rows === void 0) throw new EngineError("SELECTION_INVALID", "The ratio's denominator is not a measure of its source.");
|
|
47
|
+
const where = "where" in rows.def ? rows.def.where : void 0;
|
|
48
|
+
const operand = only?.operand === false ? void 0 : operandFilter(model, set.source, rows.name);
|
|
49
|
+
const extra = only?.numerator === true ? numeratorWhere(model, set.source, line.def) : void 0;
|
|
50
|
+
return andAll([
|
|
51
|
+
line.entry.filter,
|
|
52
|
+
where,
|
|
53
|
+
operand,
|
|
54
|
+
extra
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
/** The filter "the operand is set", for a measure that counts only rows with a value. */
|
|
58
|
+
function operandFilter(model, source, name) {
|
|
59
|
+
const isSet = operandSet(model, source, name);
|
|
60
|
+
return isSet === void 0 ? void 0 : {
|
|
61
|
+
member: isSet,
|
|
62
|
+
op: "equals",
|
|
63
|
+
values: [true]
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** A ratio's numerator `where`, for the Only filter. */
|
|
67
|
+
function numeratorWhere(model, source, def) {
|
|
68
|
+
if (def.kind !== "ratio") return;
|
|
69
|
+
const top = model.sources[source]?.measures[def.numerator];
|
|
70
|
+
const where = top !== void 0 && "where" in top ? top.where : void 0;
|
|
71
|
+
return andAll([where, operandFilter(model, source, def.numerator)]);
|
|
72
|
+
}
|
|
73
|
+
/** The row count over a filter, as one more measure of a query. */
|
|
74
|
+
const counted = (set, id, filter) => ({
|
|
75
|
+
id,
|
|
76
|
+
measure: `${set.source}.${ROW_COUNT}`,
|
|
77
|
+
...filter === void 0 ? {} : { filter }
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* The line's value and how many rows are behind it, in one read: the drill's query with the row
|
|
81
|
+
* count over the line's population (`dd_rows` with the line's filter) as one more measure, and,
|
|
82
|
+
* for a line that counts only rows whose field is set, the rows whether or not it is (`all`).
|
|
83
|
+
* Aliases are returned so each count is read by name.
|
|
84
|
+
*/
|
|
85
|
+
function summaryQuery(model, set, drill) {
|
|
86
|
+
const count = `m${set.measures.length + 1}`;
|
|
87
|
+
const filter = lineFilter(model, set, drill);
|
|
88
|
+
const loose = lineFilter(model, set, drill, { operand: false });
|
|
89
|
+
const measures = [...set.measures, counted(set, count, filter)];
|
|
90
|
+
if (JSON.stringify(loose) === JSON.stringify(filter)) return {
|
|
91
|
+
query: {
|
|
92
|
+
...set,
|
|
93
|
+
measures
|
|
94
|
+
},
|
|
95
|
+
count
|
|
96
|
+
};
|
|
97
|
+
const all = `m${set.measures.length + 2}`;
|
|
98
|
+
return {
|
|
99
|
+
query: {
|
|
100
|
+
...set,
|
|
101
|
+
measures: [...measures, counted(set, all, loose)]
|
|
102
|
+
},
|
|
103
|
+
count,
|
|
104
|
+
all
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The step before a sum's value, with its least row value, so a share of it is shown only
|
|
109
|
+
* when no row can be negative: a parent of 50 made of 100 and -50 has no 200% child.
|
|
110
|
+
*/
|
|
111
|
+
function parentQuery(model, parent, drill) {
|
|
112
|
+
const line = lineMeasure(model, parent, drill);
|
|
113
|
+
const name = line?.def.kind === "sum" ? minName(line.name) : void 0;
|
|
114
|
+
const measure = name === void 0 ? void 0 : model.sources[parent.source]?.measures[name];
|
|
115
|
+
if (line === void 0 || measure === void 0) return { query: parent };
|
|
116
|
+
const least = `m${parent.measures.length + 1}`;
|
|
117
|
+
const entry = {
|
|
118
|
+
id: least,
|
|
119
|
+
measure: `${parent.source}.${name}`,
|
|
120
|
+
...line.entry.filter === void 0 ? {} : { filter: line.entry.filter }
|
|
121
|
+
};
|
|
122
|
+
return {
|
|
123
|
+
query: {
|
|
124
|
+
...parent,
|
|
125
|
+
measures: [...parent.measures, entry]
|
|
126
|
+
},
|
|
127
|
+
least
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/** The order a Breakdown ranks its groups by: the line when it adds up, else the row count. */
|
|
131
|
+
function ranking(rows, by, byRows) {
|
|
132
|
+
if (!byRows) return {
|
|
133
|
+
measures: rows.measures,
|
|
134
|
+
order: [{
|
|
135
|
+
by,
|
|
136
|
+
dir: "desc"
|
|
137
|
+
}]
|
|
138
|
+
};
|
|
139
|
+
const count = `m${rows.measures.length + 1}`;
|
|
140
|
+
return {
|
|
141
|
+
measures: [...rows.measures, {
|
|
142
|
+
id: count,
|
|
143
|
+
measure: `${rows.source}.${ROW_COUNT}`
|
|
144
|
+
}],
|
|
145
|
+
order: [{
|
|
146
|
+
by: count,
|
|
147
|
+
dir: "desc"
|
|
148
|
+
}]
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The rows behind a drill broken down by one field: its top groups, then Other, ranked by the
|
|
153
|
+
* line when it adds up, else by the rows behind each (Rules, section 6: never by an average).
|
|
154
|
+
* With a comparison, each group's value now, before (`c1`) and its change (`c2`), the groups
|
|
155
|
+
* that moved most first (`c3`). With a search, only the groups whose value contains it.
|
|
156
|
+
*/
|
|
157
|
+
function breakdownQuery(rows, member, drill, options = {}) {
|
|
158
|
+
const by = drillMeasure(rows, drill) ?? "m1";
|
|
159
|
+
const base = {
|
|
160
|
+
...options.search === void 0 || options.search === "" ? rows : anded(rows, [rows.filters, {
|
|
161
|
+
member,
|
|
162
|
+
op: "contains",
|
|
163
|
+
values: [options.search]
|
|
164
|
+
}]),
|
|
165
|
+
dimensions: [{
|
|
166
|
+
id: "d1",
|
|
167
|
+
member
|
|
168
|
+
}],
|
|
169
|
+
limit: BREAKDOWN_TOP,
|
|
170
|
+
other: true
|
|
171
|
+
};
|
|
172
|
+
if (options.compare === void 0 || rows.time === void 0 || by.startsWith("c")) return {
|
|
173
|
+
...base,
|
|
174
|
+
...ranking(rows, by, options.rankByRows === true)
|
|
175
|
+
};
|
|
176
|
+
const now = { ref: by };
|
|
177
|
+
const before = {
|
|
178
|
+
ref: by,
|
|
179
|
+
of: "previous"
|
|
180
|
+
};
|
|
181
|
+
return {
|
|
182
|
+
...base,
|
|
183
|
+
time: {
|
|
184
|
+
...rows.time,
|
|
185
|
+
compare: options.compare
|
|
186
|
+
},
|
|
187
|
+
calc: [
|
|
188
|
+
{
|
|
189
|
+
id: "c1",
|
|
190
|
+
formula: before,
|
|
191
|
+
label: "Before"
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
id: "c2",
|
|
195
|
+
formula: {
|
|
196
|
+
op: "-",
|
|
197
|
+
args: [now, before]
|
|
198
|
+
},
|
|
199
|
+
label: "Change"
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
id: "c3",
|
|
203
|
+
formula: {
|
|
204
|
+
op: "abs",
|
|
205
|
+
args: [{
|
|
206
|
+
op: "-",
|
|
207
|
+
args: [now, before]
|
|
208
|
+
}]
|
|
209
|
+
},
|
|
210
|
+
label: "Size of change"
|
|
211
|
+
}
|
|
212
|
+
],
|
|
213
|
+
order: [{
|
|
214
|
+
by: "c3",
|
|
215
|
+
dir: "desc"
|
|
216
|
+
}]
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/** How many rows a population holds: every source's rows counted (`dd_rows`, in a drill's model). */
|
|
220
|
+
function countQuery(rows) {
|
|
221
|
+
const { calc: _c, order: _o, limit: _l, other: _ot, total: _t, dimensions: _d, ...rest } = rows;
|
|
222
|
+
return {
|
|
223
|
+
...rest,
|
|
224
|
+
measures: [{
|
|
225
|
+
id: "m1",
|
|
226
|
+
measure: `${rows.source}.${ROW_COUNT}`
|
|
227
|
+
}]
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* A distinct count's items, one page: its distinct values (never "not set": a distinct count
|
|
232
|
+
* skips it), each with its row count, most rows first then by value, so pages never overlap.
|
|
233
|
+
* It reads `take` past `skip`, and one more to say whether a page follows.
|
|
234
|
+
*/
|
|
235
|
+
function distinctQuery(rows, field, page) {
|
|
236
|
+
const all = countQuery(rows);
|
|
237
|
+
return {
|
|
238
|
+
...anded(all, [all.filters, {
|
|
239
|
+
member: field,
|
|
240
|
+
op: "set",
|
|
241
|
+
values: []
|
|
242
|
+
}]),
|
|
243
|
+
dimensions: [{
|
|
244
|
+
id: "d1",
|
|
245
|
+
member: field
|
|
246
|
+
}],
|
|
247
|
+
order: [{
|
|
248
|
+
by: "m1",
|
|
249
|
+
dir: "desc"
|
|
250
|
+
}, {
|
|
251
|
+
by: "d1",
|
|
252
|
+
dir: "asc"
|
|
253
|
+
}],
|
|
254
|
+
limit: page.skip + page.take + 1
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
export { breakdownQuery, countQuery, distinctQuery, lineFilter, parentQuery, population, summaryQuery };
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Cuts } from "./drill/types.mjs";
|
|
2
|
+
import { Cell, WireQuery } from "./types.mjs";
|
|
2
3
|
/**
|
|
3
4
|
* Each limited dimension's values in rank order, by its index: one more than its limit when
|
|
4
5
|
* more exist, so a query can tell that the limit left something out.
|
|
5
6
|
*/
|
|
6
|
-
export type Kept = ReadonlyMap<number, readonly Cell[]>;
|
|
7
|
+
export type Kept = ReadonlyMap<number, readonly Cell[]>;
|
|
8
|
+
/** What each limited dimension kept, as a drill's Other reads it: the values, cut to the limit. */
|
|
9
|
+
export declare const segmentCuts: (query: WireQuery, kept: Kept) => Cuts;
|
|
10
|
+
/** The indexes of the dimensions with a limit of their own. */
|
|
11
|
+
export declare const limitedDimensions: (query: WireQuery) => number[];
|
|
12
|
+
/**
|
|
13
|
+
* The query that ranks one dimension's values alone, over the whole range, by its `rankBy`:
|
|
14
|
+
* by default the first measure descending. Ties go by the value, as in every ranking.
|
|
15
|
+
*/
|
|
16
|
+
export declare function rankQuery(query: WireQuery, index: number): WireQuery;
|
|
@@ -6,6 +6,8 @@ function keptOf(query, index, ranked) {
|
|
|
6
6
|
const limit = query.dimensions?.[index]?.limit;
|
|
7
7
|
return limit === void 0 ? ranked : ranked.slice(0, limit);
|
|
8
8
|
}
|
|
9
|
+
/** What each limited dimension kept, as a drill's Other reads it: the values, cut to the limit. */
|
|
10
|
+
const segmentCuts = (query, kept) => ({ segments: [...kept].map(([i, ranked]) => [i, keptOf(query, i, ranked)]) });
|
|
9
11
|
/** Whether any dimension has a limit of its own. */
|
|
10
12
|
const hasSegments = (query) => (query.dimensions ?? []).some((d) => d.limit !== void 0);
|
|
11
13
|
/** The indexes of the dimensions with a limit of their own. */
|
|
@@ -179,4 +181,4 @@ function segmentOthers(query, folded) {
|
|
|
179
181
|
...before === void 0 ? {} : { before }
|
|
180
182
|
};
|
|
181
183
|
}
|
|
182
|
-
export { foldedColumn, hasSegments, keptQuery, limitedDimensions, rankQuery, segmentOtherQuery, segmentOthers, segmentSplit, uncutQuery };
|
|
184
|
+
export { foldedColumn, hasSegments, keptQuery, limitedDimensions, rankQuery, segmentCuts, segmentOtherQuery, segmentOthers, segmentSplit, uncutQuery };
|
|
@@ -11,6 +11,18 @@ const lastPart = (id) => id.split(".").at(-1) ?? id;
|
|
|
11
11
|
function memberLabel(id, label) {
|
|
12
12
|
return label ?? words(lastPart(id));
|
|
13
13
|
}
|
|
14
|
+
/** How a measure's values read: its unit, and a ratio the model reads as a percent of one. */
|
|
15
|
+
function readsAs(def) {
|
|
16
|
+
const unit = def !== void 0 && "unit" in def ? def.unit : void 0;
|
|
17
|
+
const percent = def?.kind === "ratio" && def.format === "percent";
|
|
18
|
+
return {
|
|
19
|
+
...unit === void 0 ? {} : { unit },
|
|
20
|
+
...percent ? {
|
|
21
|
+
format: "percent",
|
|
22
|
+
fraction: true
|
|
23
|
+
} : {}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
14
26
|
/** A measure's cell type: counts are integers, percentiles float, the rest as declared. */
|
|
15
27
|
function measureType(model, source, def) {
|
|
16
28
|
if (def.kind === "count") return "int";
|
|
@@ -53,7 +65,8 @@ function dimensionColumns(model, query) {
|
|
|
53
65
|
return {
|
|
54
66
|
id: d.id,
|
|
55
67
|
label,
|
|
56
|
-
type: dimensionType(resolved?.dimension)
|
|
68
|
+
type: dimensionType(resolved?.dimension),
|
|
69
|
+
member: d.member
|
|
57
70
|
};
|
|
58
71
|
});
|
|
59
72
|
}
|
|
@@ -64,21 +77,21 @@ function dimensionColumns(model, query) {
|
|
|
64
77
|
*/
|
|
65
78
|
function resultColumns(model, query) {
|
|
66
79
|
const grain = query.time?.grain;
|
|
67
|
-
const bucket = grain === void 0 ? [] : [{
|
|
80
|
+
const bucket = grain === void 0 || query.time === void 0 ? [] : [{
|
|
68
81
|
id: "t",
|
|
69
82
|
label: words(grain),
|
|
70
83
|
type: "time",
|
|
84
|
+
member: query.time.dimension,
|
|
71
85
|
grain
|
|
72
86
|
}];
|
|
73
87
|
const dimensions = dimensionColumns(model, query);
|
|
74
88
|
const measures = query.measures.map((m) => {
|
|
75
89
|
const def = resolveMeasure(model, query.source, m.measure);
|
|
76
|
-
const unit = def !== void 0 && "unit" in def && def.unit !== void 0 ? def.unit : void 0;
|
|
77
90
|
return {
|
|
78
91
|
id: m.id,
|
|
79
92
|
label: m.label ?? memberLabel(m.measure, def?.label),
|
|
80
93
|
type: def === void 0 ? "float" : measureType(model, query.source, def),
|
|
81
|
-
...
|
|
94
|
+
...readsAs(def)
|
|
82
95
|
};
|
|
83
96
|
});
|
|
84
97
|
const types = new Map(measures.map((c) => [c.id, c.type]));
|
|
@@ -9,12 +9,16 @@ export type ResultColumn = {
|
|
|
9
9
|
label: string;
|
|
10
10
|
type: "string" | "number" | "boolean" | "time" | "int" | "decimal" | "float";
|
|
11
11
|
unit?: Unit;
|
|
12
|
+
/** On a dimension or the time bucket: the member it groups by, so a click can drill into it. */
|
|
13
|
+
member?: string;
|
|
12
14
|
/** On the time bucket column: the grain its labels name. */
|
|
13
15
|
grain?: Grain;
|
|
14
|
-
/** On a calc's column: how its values read. */
|
|
16
|
+
/** On a calc's column, or a ratio the model reads as a percent: how its values read. */
|
|
15
17
|
format?: Format;
|
|
16
18
|
/** On a calc that reads the comparison period: a change, shown with its sign (+3.2%). */
|
|
17
19
|
signed?: true;
|
|
20
|
+
/** On a ratio read as a percent: its values are fractions of one (0.55 reads 55%), not points. */
|
|
21
|
+
fraction?: true;
|
|
18
22
|
};
|
|
19
23
|
/** A column of a records page: the member it shows, labelled and typed from the model. */
|
|
20
24
|
export type RecordColumn = {
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { issue } from "./issue.mjs";
|
|
2
|
+
import { grain, op, primitive } from "./query.mjs";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
// src/schema/answer-parts.ts
|
|
5
|
+
const cell = z.union([
|
|
6
|
+
z.string(),
|
|
7
|
+
z.number(),
|
|
8
|
+
z.boolean(),
|
|
9
|
+
z.null(),
|
|
10
|
+
z.looseObject({
|
|
11
|
+
t: z.enum(["int", "decimal"]),
|
|
12
|
+
v: z.string()
|
|
13
|
+
})
|
|
14
|
+
]);
|
|
15
|
+
const resultCell = z.union([cell, z.looseObject({ mark: z.enum(["other", "all"]) })]);
|
|
16
|
+
const rows = z.array(z.array(resultCell).readonly()).readonly();
|
|
17
|
+
const columnType = z.enum([
|
|
18
|
+
"string",
|
|
19
|
+
"number",
|
|
20
|
+
"boolean",
|
|
21
|
+
"time",
|
|
22
|
+
"int",
|
|
23
|
+
"decimal",
|
|
24
|
+
"float"
|
|
25
|
+
]);
|
|
26
|
+
const column = z.looseObject({
|
|
27
|
+
id: z.string(),
|
|
28
|
+
label: z.string(),
|
|
29
|
+
type: columnType,
|
|
30
|
+
unit: z.string().exactOptional(),
|
|
31
|
+
member: z.string().exactOptional(),
|
|
32
|
+
grain: grain.exactOptional(),
|
|
33
|
+
format: z.enum([
|
|
34
|
+
"number",
|
|
35
|
+
"percent",
|
|
36
|
+
"currency",
|
|
37
|
+
"duration"
|
|
38
|
+
]).exactOptional(),
|
|
39
|
+
signed: z.literal(true).exactOptional(),
|
|
40
|
+
fraction: z.literal(true).exactOptional()
|
|
41
|
+
});
|
|
42
|
+
const resolvedRange = z.looseObject({
|
|
43
|
+
from: z.string(),
|
|
44
|
+
to: z.string()
|
|
45
|
+
});
|
|
46
|
+
const boundFilter = z.lazy(() => z.union([
|
|
47
|
+
z.looseObject({ all: z.array(boundFilter).readonly() }),
|
|
48
|
+
z.looseObject({ any: z.array(boundFilter).readonly() }),
|
|
49
|
+
z.looseObject({ not: boundFilter }),
|
|
50
|
+
z.looseObject({
|
|
51
|
+
member: z.string(),
|
|
52
|
+
op,
|
|
53
|
+
values: z.array(primitive).readonly()
|
|
54
|
+
}),
|
|
55
|
+
z.looseObject({ some: z.looseObject({
|
|
56
|
+
join: z.string(),
|
|
57
|
+
where: boundFilter
|
|
58
|
+
}) }),
|
|
59
|
+
z.looseObject({ none: z.looseObject({
|
|
60
|
+
join: z.string(),
|
|
61
|
+
where: boundFilter
|
|
62
|
+
}) })
|
|
63
|
+
]));
|
|
64
|
+
const receipt = z.looseObject({
|
|
65
|
+
queryHash: z.string(),
|
|
66
|
+
provider: z.string(),
|
|
67
|
+
trust: z.enum(["builtin", "external"]),
|
|
68
|
+
sources: z.array(z.string()).readonly(),
|
|
69
|
+
answeredBy: z.string(),
|
|
70
|
+
cache: z.enum([
|
|
71
|
+
"hit",
|
|
72
|
+
"stale",
|
|
73
|
+
"miss",
|
|
74
|
+
"off"
|
|
75
|
+
]),
|
|
76
|
+
range: resolvedRange.exactOptional(),
|
|
77
|
+
calendar: z.looseObject({
|
|
78
|
+
timezone: z.string(),
|
|
79
|
+
weekStart: z.union([
|
|
80
|
+
z.literal(0),
|
|
81
|
+
z.literal(1),
|
|
82
|
+
z.literal(6)
|
|
83
|
+
]),
|
|
84
|
+
fiscalYearStartMonth: z.number()
|
|
85
|
+
}),
|
|
86
|
+
dataThrough: z.string(),
|
|
87
|
+
computedAt: z.string(),
|
|
88
|
+
consistency: z.enum([
|
|
89
|
+
"snapshot",
|
|
90
|
+
"statement",
|
|
91
|
+
"mixed"
|
|
92
|
+
]),
|
|
93
|
+
durationMs: z.number(),
|
|
94
|
+
rowsReturned: z.number(),
|
|
95
|
+
filter: boundFilter,
|
|
96
|
+
coverage: z.looseObject({
|
|
97
|
+
applied: z.array(z.string()).readonly(),
|
|
98
|
+
dropped: z.array(z.string()).readonly()
|
|
99
|
+
}),
|
|
100
|
+
warnings: z.array(issue).readonly()
|
|
101
|
+
});
|
|
102
|
+
const result = z.looseObject({
|
|
103
|
+
rows,
|
|
104
|
+
columns: z.array(column).readonly(),
|
|
105
|
+
compare: z.looseObject({
|
|
106
|
+
rows,
|
|
107
|
+
range: resolvedRange
|
|
108
|
+
}).exactOptional(),
|
|
109
|
+
status: z.enum(["complete", "truncated"]),
|
|
110
|
+
receipt
|
|
111
|
+
});
|
|
112
|
+
const recordColumn = z.looseObject({
|
|
113
|
+
member: z.string(),
|
|
114
|
+
label: z.string(),
|
|
115
|
+
type: columnType
|
|
116
|
+
});
|
|
117
|
+
export { cell, column, receipt, recordColumn, result };
|