derive-dashboards 0.4.0 → 0.5.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 +2 -3
- package/dist/cli/check.mjs +36 -1
- package/dist/cli/doctor.mjs +2 -2
- package/dist/core/document/display-entries.mjs +48 -0
- package/dist/core/document/display.d.mts +15 -3
- package/dist/core/document/display.mjs +35 -11
- package/dist/core/engine/filter.mjs +4 -2
- package/dist/core/engine/version.d.mts +1 -1
- package/dist/core/engine/version.mjs +1 -1
- package/dist/core/error/codes.d.mts +2 -0
- package/dist/core/error/codes.mjs +2 -0
- package/dist/core/index.d.mts +4 -3
- package/dist/core/index.mjs +8 -7
- package/dist/core/model/catalog/check.mjs +11 -5
- package/dist/core/model/member.mjs +6 -1
- package/dist/core/model/validate/members.mjs +31 -1
- package/dist/core/oracle/visibility.mjs +3 -1
- package/dist/core/query/drill/line.mjs +2 -2
- package/dist/core/query/to-wire.d.mts +7 -0
- package/dist/core/query/to-wire.mjs +18 -7
- package/dist/core/result/additive.d.mts +9 -0
- package/dist/core/result/additive.mjs +59 -0
- package/dist/core/result/columns.mjs +8 -2
- package/dist/core/result/types.d.mts +12 -0
- package/dist/core/schema/answer-parts.mjs +2 -1
- package/dist/core/schema/answers.d.mts +6 -0
- package/dist/core/types/api.d.mts +1 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/handler.mjs +10 -2
- package/dist/index.mjs +1 -1
- package/dist/llms.txt +1 -1
- package/dist/react/History.mjs +1 -1
- package/dist/react/Tile.mjs +18 -10
- package/dist/react/builder/FilterEditor.mjs +2 -7
- package/dist/react/builder/Preview.mjs +1 -1
- package/dist/react/columns.mjs +15 -0
- package/dist/react/context.d.mts +7 -0
- package/dist/react/context.mjs +3 -0
- package/dist/react/digits.mjs +46 -0
- package/dist/react/drill/Bars.mjs +2 -1
- package/dist/react/drill/Controls.mjs +2 -1
- package/dist/react/drill/Header.mjs +2 -1
- package/dist/react/drill/Items.mjs +6 -1
- package/dist/react/drill/Notes.mjs +2 -1
- package/dist/react/drill/item-parts.mjs +2 -1
- package/dist/react/english.mjs +4 -0
- package/dist/react/export/ExportButton.mjs +23 -0
- package/dist/react/export/csv.d.mts +9 -0
- package/dist/react/export/csv.mjs +42 -0
- package/dist/react/export/download.d.mts +5 -0
- package/dist/react/export/download.mjs +61 -0
- package/dist/react/format-time.d.mts +15 -0
- package/dist/react/format-time.mjs +71 -0
- package/dist/react/format.d.mts +6 -16
- package/dist/react/format.mjs +48 -86
- package/dist/react/index.d.mts +8 -3
- package/dist/react/index.mjs +8 -3
- package/dist/react/messages.d.mts +8 -0
- package/dist/react/renderers/entries.mjs +15 -0
- package/dist/react/renderers/exact.d.mts +6 -0
- package/dist/react/renderers/exact.mjs +68 -0
- package/dist/react/renderers/index.d.mts +5 -11
- package/dist/react/renderers/index.mjs +70 -84
- package/dist/react/renderers/list.mjs +5 -17
- package/dist/react/renderers/table-cells.mjs +130 -0
- package/dist/react/renderers/table-fit.mjs +52 -0
- package/dist/react/renderers/table-head.mjs +47 -0
- package/dist/react/renderers/table-measure.mjs +49 -0
- package/dist/react/renderers/table-row.mjs +61 -0
- package/dist/react/renderers/table-scale.mjs +70 -0
- package/dist/react/renderers/table-sort.mjs +99 -0
- package/dist/react/renderers/table.d.mts +3 -0
- package/dist/react/renderers/table.mjs +121 -0
- package/dist/react/series.mjs +1 -1
- package/dist/react/theme-unlayered.css +3144 -0
- package/dist/react/theme-unlayered.css.d.ts +1 -0
- package/dist/react/theme.css +379 -8
- package/dist/recharts/axes.mjs +13 -10
- package/dist/recharts/axis.mjs +25 -1
- package/dist/recharts/bar.d.mts +2 -1
- package/dist/recharts/bar.mjs +29 -6
- package/dist/recharts/parts.mjs +1 -1
- package/dist/skills/derive-dashboards/SKILL.md +13 -1
- package/package.json +42 -4
package/README.md
CHANGED
|
@@ -25,8 +25,7 @@ One package. The React UI needs `react`, and the line and bar charts need `recha
|
|
|
25
25
|
them only if you use those parts. The `derive-dashboards` command (`npx derive-dashboards init`)
|
|
26
26
|
comes with it.
|
|
27
27
|
|
|
28
|
-
Then follow the [quick start](https://github.com/derive-to/dashboards/blob/main/docs/quick-start.md).
|
|
29
|
-
gives it the install steps, and [llms.txt](https://github.com/derive-to/dashboards/blob/main/llms.txt) indexes every page (both also ship in the package).
|
|
28
|
+
Then follow the [quick start](https://github.com/derive-to/dashboards/blob/main/docs/quick-start.md). To have a coding agent add dashboards to your app end to end, investigating your access rules and proving no customer sees another's data: `npx skills add derive-to/dashboards --skill add-dashboards`. For the library's API alone: `npx skills add derive-to/dashboards --skill derive-dashboards`. [llms.txt](https://github.com/derive-to/dashboards/blob/main/llms.txt) indexes every page, and ships in the package.
|
|
30
29
|
|
|
31
30
|
## What is here today
|
|
32
31
|
|
|
@@ -36,7 +35,7 @@ Embedded dashboards on Postgres, end to end, run by the Acme Tasks sample (`exam
|
|
|
36
35
|
| --- | --- |
|
|
37
36
|
| `derive-dashboards/core` | No I/O and no framework. The model (`defineModel`, `validateModel`), typed member ids, filters and queries, the access kernel (`effectiveFilter`), composition, the oracle every engine must match, the Postgres engine (`/engine`), the document and its schema (`/schema`), and the store's tables as data. |
|
|
38
37
|
| `derive-dashboards` | `deriveDashboards(options)`: a fetch handler for every endpoint, a Postgres source and store for any driver, the result cache, the query log, `createTables`, and the store contract suite (`/testing`). |
|
|
39
|
-
| `derive-dashboards/react` | `Dashboard` with edit mode (Edit, + Add widget, drag and resize, a change count with undo and redo, review before publish, History with in-place preview, Share), `DashboardList` with + New dashboard, `useDraft` and `useReview` for your own edit and review UI, the filter bar (`FilterBar`, with chips, a Filter menu, a phone sheet and `filterRules` for your own), `Tile`, drill-in (`DrillPanel`, `DashboardTile`, `useDrill`, and `toSeries` and `rowAt` for any chart kit), the widget builder (`WidgetBuilder`, `useBuilder`) and `theme.css`. |
|
|
38
|
+
| `derive-dashboards/react` | `Dashboard` with edit mode (Edit, + Add widget, drag and resize, a change count with undo and redo, review before publish, History with in-place preview, Share), `DashboardList` with + New dashboard, `useDraft` and `useReview` for your own edit and review UI, the filter bar (`FilterBar`, with chips, a Filter menu, a phone sheet and `filterRules` for your own), `Tile`, the built-in tiles (`NumberTile`, `TableTile` with a viewer's sort, bars and shading), a tile's answer as CSV (`downloadCsv`, `csvOf`, `exportRows`), drill-in (`DrillPanel`, `DashboardTile`, `useDrill`, and `toSeries` and `rowAt` for any chart kit), the widget builder (`WidgetBuilder`, `useBuilder`) and `theme.css`. |
|
|
40
39
|
| `derive-dashboards/recharts` | Line and bar tiles, drawn with Recharts, each mark a drill (install `recharts` to use them; any other chart library plugs into `renderers`). |
|
|
41
40
|
| `derive-dashboards/mcp` | Two tools for the MCP server you already run (`addDashboardTools`): `dashboards_query` to ask and read, `dashboards_api` for everything else. See [MCP](https://github.com/derive-to/dashboards/blob/main/docs/mcp.md). |
|
|
42
41
|
| `derive-dashboards/cli` | `defineConfig` for `derive-dashboards.config.ts`; the `derive-dashboards` command runs `init`, `doctor`, `check`, `generate`, `create-tables`. |
|
package/dist/cli/check.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { checkCatalog, describeQueries, recordDimensions, validateModel } from "derive-dashboards/core";
|
|
2
|
+
import { FOLD_FUNCTION } from "derive-dashboards/core/engine";
|
|
2
3
|
// src/check.ts
|
|
3
4
|
const introspects = (c) => "introspect" in c;
|
|
4
5
|
/**
|
|
@@ -33,7 +34,41 @@ function byConnection(config, model) {
|
|
|
33
34
|
async function partIssues(part) {
|
|
34
35
|
if (part.connection === void 0) return [];
|
|
35
36
|
const described = await describeQueries(part.model, part.connection, await part.connection.introspect());
|
|
36
|
-
return [
|
|
37
|
+
return [
|
|
38
|
+
...described.issues,
|
|
39
|
+
...checkCatalog(part.model, described.schema),
|
|
40
|
+
...await foldIssues(part.model, part.connection)
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
/** Every dimension that compares without case, by its path in the model. */
|
|
44
|
+
const caseless = (model) => Object.entries(model.sources).flatMap(([source, def]) => Object.entries(def.dimensions).flatMap(([name, d]) => d.kind === "string" && d.collation === "ci" ? [[
|
|
45
|
+
"sources",
|
|
46
|
+
source,
|
|
47
|
+
"dimensions",
|
|
48
|
+
name
|
|
49
|
+
]] : []));
|
|
50
|
+
/**
|
|
51
|
+
* A dimension that compares without case runs the library's fold function in the database;
|
|
52
|
+
* without it every query on that source fails. The database is asked whether it has it.
|
|
53
|
+
*/
|
|
54
|
+
async function foldIssues(model, connection) {
|
|
55
|
+
const paths = caseless(model);
|
|
56
|
+
if (paths.length === 0 || connection.dialect.id !== "postgres") return [];
|
|
57
|
+
const options = {
|
|
58
|
+
signal: new AbortController().signal,
|
|
59
|
+
deadline: Date.now() + 3e4,
|
|
60
|
+
maxRows: 1
|
|
61
|
+
};
|
|
62
|
+
const { value } = await connection.session(options, (s) => s.run({
|
|
63
|
+
text: "SELECT 1 FROM pg_proc WHERE proname = $1",
|
|
64
|
+
params: [FOLD_FUNCTION]
|
|
65
|
+
}));
|
|
66
|
+
if (value.rows.length > 0) return [];
|
|
67
|
+
return paths.map((path) => ({
|
|
68
|
+
code: "FOLD_FUNCTION_MISSING",
|
|
69
|
+
path,
|
|
70
|
+
message: `It compares without case ("ci"), which needs ${FOLD_FUNCTION} in the database: run foldFunctionSql() from derive-dashboards/core/engine once (a migration), or make it "binary".`
|
|
71
|
+
}));
|
|
37
72
|
}
|
|
38
73
|
/**
|
|
39
74
|
* The columns a drill's Items list shows for each source: the model's `records.columns`, or the
|
package/dist/cli/doctor.mjs
CHANGED
|
@@ -35,13 +35,13 @@ function majorMinor(version) {
|
|
|
35
35
|
const PEERS = [
|
|
36
36
|
{
|
|
37
37
|
name: "react",
|
|
38
|
-
from: [18,
|
|
38
|
+
from: [18, 2],
|
|
39
39
|
to: 19,
|
|
40
40
|
by: "derive-dashboards/react"
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
43
|
name: "react-dom",
|
|
44
|
-
from: [18,
|
|
44
|
+
from: [18, 2],
|
|
45
45
|
to: 19,
|
|
46
46
|
by: "derive-dashboards/react"
|
|
47
47
|
},
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { entryAliases } from "../query/to-wire.mjs";
|
|
2
|
+
// src/document/display-entries.ts
|
|
3
|
+
/** The options of each kind that name values of the widget's query. */
|
|
4
|
+
const NAMES_VALUES = {
|
|
5
|
+
number: ["value", "secondary"],
|
|
6
|
+
table: ["bars", "heat"]
|
|
7
|
+
};
|
|
8
|
+
/** The names an option holds: its text, or each text of its list; none for a value of another type, which its type check refuses. */
|
|
9
|
+
function namesIn(value) {
|
|
10
|
+
if (typeof value === "string") return [value];
|
|
11
|
+
return Array.isArray(value) ? value.filter((name) => typeof name === "string") : [];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The names a display may give a value of the widget's query: each measure and calc by its
|
|
15
|
+
* own id, and by the id its column has in an answer (m1, c1). A name is read as a renderer
|
|
16
|
+
* reads it: as an entry's own id first, so a group whose own id is "m1" is that group, and no
|
|
17
|
+
* value.
|
|
18
|
+
*/
|
|
19
|
+
function valuesOf(widget) {
|
|
20
|
+
const query = widget.queries["main"];
|
|
21
|
+
if (query === void 0) return void 0;
|
|
22
|
+
const ids = [...query.measures, ...query.calc ?? []].map((entry) => entry.id);
|
|
23
|
+
const aliases = entryAliases(query);
|
|
24
|
+
const answered = new Set(ids.flatMap((id) => aliases.get(id) ?? []));
|
|
25
|
+
return {
|
|
26
|
+
has: (name) => answered.has(aliases.get(name) ?? name),
|
|
27
|
+
names: [...ids, ...answered]
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* What a widget's display names that its query does not have: each option that names a value
|
|
32
|
+
* (a number's `value` and `secondary`, a table's `bars` and `heat`) with a name that is no
|
|
33
|
+
* measure or calc of the widget's main query, at the option's path. None for a kind with no
|
|
34
|
+
* such option, a widget with no main query, or a display that is not an object.
|
|
35
|
+
*/
|
|
36
|
+
function displayEntryIssues(widget, path) {
|
|
37
|
+
const known = valuesOf(widget);
|
|
38
|
+
const display = widget.display;
|
|
39
|
+
if (known === void 0 || typeof display !== "object" || display === null) return [];
|
|
40
|
+
const options = NAMES_VALUES[widget.kind] ?? [];
|
|
41
|
+
const held = { ...display };
|
|
42
|
+
return options.flatMap((option) => namesIn(held[option]).filter((name) => !known.has(name)).map((name) => ({
|
|
43
|
+
code: "DISPLAY_INVALID",
|
|
44
|
+
message: `A ${widget.kind}'s ${option} names "${name}", which is not a value of its query. Its values are: ${known.names.join(", ")}.`,
|
|
45
|
+
path: [...path, option]
|
|
46
|
+
})));
|
|
47
|
+
}
|
|
48
|
+
export { displayEntryIssues };
|
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import { Issue } from "../types/primitives.mjs";
|
|
2
2
|
import { Doc } from "./types.mjs";
|
|
3
3
|
type ValueOf<T> = T extends "boolean" ? boolean : T extends "text" ? string : T extends "texts" ? readonly string[] : Readonly<Record<string, string>>;
|
|
4
|
+
/** Options every widget takes. */
|
|
5
|
+
declare const SHARED: {
|
|
6
|
+
readonly keepDateRange: "boolean";
|
|
7
|
+
readonly empty: "text";
|
|
8
|
+
};
|
|
4
9
|
/** The options of each kind of widget the library draws, and each option's type. */
|
|
5
10
|
export declare const DISPLAY_OPTIONS: {
|
|
6
11
|
readonly number: {
|
|
12
|
+
readonly value: "text";
|
|
13
|
+
readonly secondary: "text";
|
|
7
14
|
readonly keepDateRange: "boolean";
|
|
8
15
|
readonly empty: "text";
|
|
9
16
|
};
|
|
10
17
|
readonly table: {
|
|
18
|
+
readonly bars: "texts";
|
|
19
|
+
readonly heat: "texts";
|
|
20
|
+
readonly compact: "boolean";
|
|
11
21
|
readonly keepDateRange: "boolean";
|
|
12
22
|
readonly empty: "text";
|
|
13
23
|
};
|
|
@@ -42,7 +52,7 @@ export type DisplayOf<K extends DisplayKind> = { readonly [P in keyof (typeof DI
|
|
|
42
52
|
* path. None for a kind the library does not draw, and none for an option it does not know.
|
|
43
53
|
*/
|
|
44
54
|
export declare function displayIssues(kind: string, display: unknown, path?: Issue["path"]): Issue[];
|
|
45
|
-
/** Every widget of a document whose display does not fit its kind, at `widgets.<id>.display`. */
|
|
55
|
+
/** Every widget of a document whose display does not fit its kind or its query, at `widgets.<id>.display`. */
|
|
46
56
|
export declare function documentDisplayIssues(doc: Doc): Issue[];
|
|
47
57
|
/**
|
|
48
58
|
* A widget's options as its kind reads them: each option it knows, when it is of its type. A
|
|
@@ -58,6 +68,8 @@ export declare function displayOf<K extends DisplayKind>(kind: K, display: unkno
|
|
|
58
68
|
* else, and replaying a draft's own commands never refuses one that was accepted.
|
|
59
69
|
*/
|
|
60
70
|
export declare function editedDisplayIssues(before: Doc, after: Doc): Issue[];
|
|
61
|
-
/** The options every widget takes, whatever draws it
|
|
62
|
-
export
|
|
71
|
+
/** The options every widget takes, whatever draws it. */
|
|
72
|
+
export type SharedDisplay = { readonly [P in keyof typeof SHARED]?: ValueOf<(typeof SHARED)[P]>; };
|
|
73
|
+
/** The options every widget takes, whatever draws it: `keepDateRange` and `empty`, and no option of any one kind. */
|
|
74
|
+
export declare const sharedDisplay: (display: unknown) => SharedDisplay;
|
|
63
75
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { canonical } from "../value/canonical.mjs";
|
|
2
|
+
import { displayEntryIssues } from "./display-entries.mjs";
|
|
2
3
|
// src/document/display.ts
|
|
3
4
|
/** Options every widget takes. */
|
|
4
5
|
const SHARED = {
|
|
@@ -11,8 +12,17 @@ const CHART = {
|
|
|
11
12
|
};
|
|
12
13
|
/** The options of each kind of widget the library draws, and each option's type. */
|
|
13
14
|
const DISPLAY_OPTIONS = {
|
|
14
|
-
number:
|
|
15
|
-
|
|
15
|
+
number: {
|
|
16
|
+
...SHARED,
|
|
17
|
+
value: "text",
|
|
18
|
+
secondary: "text"
|
|
19
|
+
},
|
|
20
|
+
table: {
|
|
21
|
+
...SHARED,
|
|
22
|
+
bars: "texts",
|
|
23
|
+
heat: "texts",
|
|
24
|
+
compact: "boolean"
|
|
25
|
+
},
|
|
16
26
|
list: {
|
|
17
27
|
...SHARED,
|
|
18
28
|
title: "text",
|
|
@@ -28,6 +38,11 @@ const DISPLAY_OPTIONS = {
|
|
|
28
38
|
const DISPLAY_HELP = {
|
|
29
39
|
keepDateRange: "Keep the widget's own date range over the viewer's and the dashboard's.",
|
|
30
40
|
empty: "What the tile says when its answer has no rows.",
|
|
41
|
+
value: "The query entry a number tile shows large. Without it: a calc when the query has one, else its first value.",
|
|
42
|
+
secondary: "A query entry a number tile shows as a second, smaller figure under the number, beside its label.",
|
|
43
|
+
bars: "Query entries drawn with a bar in each cell, as long as the value is beside the column's largest.",
|
|
44
|
+
heat: "Query entries whose cells are shaded by their value, darker for more.",
|
|
45
|
+
compact: "Draw a table's rows closer together.",
|
|
31
46
|
colors: "A colour per series, by the series' label: any CSS colour.",
|
|
32
47
|
title: "The query entry shown as the row's title.",
|
|
33
48
|
subtitle: "Query entries shown under the title, joined with a dot.",
|
|
@@ -87,9 +102,16 @@ function displayIssues(kind, display, path = []) {
|
|
|
87
102
|
path: [...path, name]
|
|
88
103
|
}));
|
|
89
104
|
}
|
|
90
|
-
/**
|
|
105
|
+
/**
|
|
106
|
+
* What is wrong with one widget's display: each option of the wrong type for its kind, and
|
|
107
|
+
* each option that names a value its query does not have (`displayEntryIssues`).
|
|
108
|
+
*/
|
|
109
|
+
function widgetDisplayIssues(widget, path) {
|
|
110
|
+
return [...displayIssues(widget.kind, widget.display, path), ...displayEntryIssues(widget, path)];
|
|
111
|
+
}
|
|
112
|
+
/** Every widget of a document whose display does not fit its kind or its query, at `widgets.<id>.display`. */
|
|
91
113
|
function documentDisplayIssues(doc) {
|
|
92
|
-
return Object.entries(doc.widgets).flatMap(([id, widget]) =>
|
|
114
|
+
return Object.entries(doc.widgets).flatMap(([id, widget]) => widgetDisplayIssues(widget, [
|
|
93
115
|
"widgets",
|
|
94
116
|
id,
|
|
95
117
|
"display"
|
|
@@ -102,13 +124,15 @@ function documentDisplayIssues(doc) {
|
|
|
102
124
|
* colours that are text are kept.
|
|
103
125
|
*/
|
|
104
126
|
function displayOf(kind, display) {
|
|
105
|
-
|
|
127
|
+
return read(DISPLAY_OPTIONS[kind], display);
|
|
128
|
+
}
|
|
129
|
+
/** The options of a table of options that a stored display holds, each when it is of its type. */
|
|
130
|
+
function read(options, display) {
|
|
106
131
|
const given = isRecord(display) ? display : {};
|
|
107
|
-
|
|
132
|
+
return Object.fromEntries(Object.entries(options).flatMap(([name, type]) => {
|
|
108
133
|
const value = usable(type, given[name]);
|
|
109
134
|
return value === void 0 ? [] : [[name, value]];
|
|
110
|
-
});
|
|
111
|
-
return Object.fromEntries(read);
|
|
135
|
+
}));
|
|
112
136
|
}
|
|
113
137
|
/** An option as an object holds it: none when it has no such option, which is not the same as holding null. */
|
|
114
138
|
const held = (display, option) => Object.hasOwn(display, option) ? { is: display[option] ?? null } : null;
|
|
@@ -123,7 +147,7 @@ function editedDisplayIssues(before, after) {
|
|
|
123
147
|
const was = before.widgets[id]?.display;
|
|
124
148
|
const old = isRecord(was) ? was : {};
|
|
125
149
|
const now = widget.display;
|
|
126
|
-
return
|
|
150
|
+
return widgetDisplayIssues(widget, [
|
|
127
151
|
"widgets",
|
|
128
152
|
id,
|
|
129
153
|
"display"
|
|
@@ -134,6 +158,6 @@ function editedDisplayIssues(before, after) {
|
|
|
134
158
|
});
|
|
135
159
|
});
|
|
136
160
|
}
|
|
137
|
-
/** The options every widget takes, whatever draws it: `keepDateRange` and `empty
|
|
138
|
-
const sharedDisplay = (display) =>
|
|
161
|
+
/** The options every widget takes, whatever draws it: `keepDateRange` and `empty`, and no option of any one kind. */
|
|
162
|
+
const sharedDisplay = (display) => read(SHARED, display);
|
|
139
163
|
export { DISPLAY_HELP, DISPLAY_OPTIONS, displayIssues, displayOf, documentDisplayIssues, editedDisplayIssues, sharedDisplay };
|
|
@@ -35,9 +35,11 @@ function policySql(b, alias, filter) {
|
|
|
35
35
|
if ("all" in filter) return and(filter.all.map((f) => policySql(b, alias, f)));
|
|
36
36
|
if ("any" in filter) return or(filter.any.map((f) => policySql(b, alias, f)));
|
|
37
37
|
if ("not" in filter) return sql`NOT ${policySql(b, alias, filter.not)}`;
|
|
38
|
+
const type = typeOfValues(filter.values);
|
|
39
|
+
const column = ident(alias, filter.column);
|
|
38
40
|
const operand = {
|
|
39
|
-
sql:
|
|
40
|
-
type
|
|
41
|
+
sql: type === "string" ? b.dialect.cast(column, "text") : column,
|
|
42
|
+
type,
|
|
41
43
|
collation: "binary"
|
|
42
44
|
};
|
|
43
45
|
return leafSql(b, operand, filter);
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* older code, or in an older shape, 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
|
-
export declare const ENGINE_VERSION = "
|
|
8
|
+
export declare const ENGINE_VERSION = "7873f8dc2b6b0ba9";
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
* older code, or in an older shape, is never read. `test/engine-version.test.ts` checks it
|
|
7
7
|
* against the files and prints the new value when they change.
|
|
8
8
|
*/
|
|
9
|
-
const ENGINE_VERSION = "
|
|
9
|
+
const ENGINE_VERSION = "7873f8dc2b6b0ba9";
|
|
10
10
|
export { ENGINE_VERSION };
|
|
@@ -29,6 +29,7 @@ export declare const MODEL_ISSUES: {
|
|
|
29
29
|
readonly JOIN_ON_EMPTY: "A join has no column pair.";
|
|
30
30
|
readonly JOIN_TARGET_UNKNOWN: "A join targets a source that does not exist.";
|
|
31
31
|
readonly KEY_MISSING: "A source has no unique key.";
|
|
32
|
+
readonly MEASURE_MERGE: "A measure has a merge its kind cannot take: a count or a sum takes \"sum\", a min \"min\", a max \"max\", an average or a distinct count none of them. Every kind takes \"none\".";
|
|
32
33
|
readonly MEMBER_NAME_CLASH: "Two members of a source share a name.";
|
|
33
34
|
readonly MODEL_FIELD_UNKNOWN: "The model holds a field the library does not know: a misspelling, or a field of another kind.";
|
|
34
35
|
readonly MODEL_FILTER_NOT_BOUND: "A filter in the model uses a viewer value or a variable.";
|
|
@@ -76,6 +77,7 @@ export declare const CATALOG_ISSUES: {
|
|
|
76
77
|
readonly COLLATION_MISMATCH: "A string dimension compares by code point, but its column compares without case.";
|
|
77
78
|
readonly COLUMN_NOT_FOUND: "The model reads a column the table does not have.";
|
|
78
79
|
readonly COLUMN_TYPE_MISMATCH: "A column's type is not what its measure or dimension reads.";
|
|
80
|
+
readonly FOLD_FUNCTION_MISSING: "A dimension compares without case, but the database lacks the fold function: run foldFunctionSql() once.";
|
|
79
81
|
readonly JOIN_KEY_NOT_UNIQUE: "A join's target columns are not a unique key, so the join could repeat rows.";
|
|
80
82
|
readonly KEY_NOT_UNIQUE: "A source's key is not a unique key the database enforces.";
|
|
81
83
|
readonly SQL_NOT_RUNNABLE: "A source's sql does not run, or lacks a column the source reads; the message is the database's.";
|
|
@@ -32,6 +32,7 @@ const MODEL_ISSUES = {
|
|
|
32
32
|
JOIN_ON_EMPTY: "A join has no column pair.",
|
|
33
33
|
JOIN_TARGET_UNKNOWN: "A join targets a source that does not exist.",
|
|
34
34
|
KEY_MISSING: "A source has no unique key.",
|
|
35
|
+
MEASURE_MERGE: "A measure has a merge its kind cannot take: a count or a sum takes \"sum\", a min \"min\", a max \"max\", an average or a distinct count none of them. Every kind takes \"none\".",
|
|
35
36
|
MEMBER_NAME_CLASH: "Two members of a source share a name.",
|
|
36
37
|
MODEL_FIELD_UNKNOWN: "The model holds a field the library does not know: a misspelling, or a field of another kind.",
|
|
37
38
|
MODEL_FILTER_NOT_BOUND: "A filter in the model uses a viewer value or a variable.",
|
|
@@ -79,6 +80,7 @@ const CATALOG_ISSUES = {
|
|
|
79
80
|
COLLATION_MISMATCH: "A string dimension compares by code point, but its column compares without case.",
|
|
80
81
|
COLUMN_NOT_FOUND: "The model reads a column the table does not have.",
|
|
81
82
|
COLUMN_TYPE_MISMATCH: "A column's type is not what its measure or dimension reads.",
|
|
83
|
+
FOLD_FUNCTION_MISSING: "A dimension compares without case, but the database lacks the fold function: run foldFunctionSql() once.",
|
|
82
84
|
JOIN_KEY_NOT_UNIQUE: "A join's target columns are not a unique key, so the join could repeat rows.",
|
|
83
85
|
KEY_NOT_UNIQUE: "A source's key is not a unique key the database enforces.",
|
|
84
86
|
SQL_NOT_RUNNABLE: "A source's sql does not run, or lacks a column the source reads; the message is the database's.",
|
package/dist/core/index.d.mts
CHANGED
|
@@ -20,7 +20,7 @@ import { viaJoins } from "./model/validate/via.mjs";
|
|
|
20
20
|
import { BoundRule, bindFilter, bindPolicy, namedPolicy, viewerValues } from "./policy/bind.mjs";
|
|
21
21
|
import { Command, CommandBody, CommandId, Display, Doc, LayoutItem, Scope, Tab, TabId, Widget, WidgetId, emptyDoc } from "./document/types.mjs";
|
|
22
22
|
import { Change, Placement, WidgetPart, changedWidget, diffDocs, markShifted, placementOf, widgetDiff } from "./document/diff.mjs";
|
|
23
|
-
import { DISPLAY_HELP, DISPLAY_OPTIONS, DisplayKind, DisplayOf, displayIssues, displayOf, documentDisplayIssues, editedDisplayIssues, sharedDisplay } from "./document/display.mjs";
|
|
23
|
+
import { DISPLAY_HELP, DISPLAY_OPTIONS, DisplayKind, DisplayOf, SharedDisplay, displayIssues, displayOf, documentDisplayIssues, editedDisplayIssues, sharedDisplay } from "./document/display.mjs";
|
|
24
24
|
import { GRID_COLUMNS, Gap, closeGaps, closeGapsCommands, freeSpot, layoutGaps, placeItem, repairLayout } from "./document/layout.mjs";
|
|
25
25
|
import { Outcome } from "./document/outcome.mjs";
|
|
26
26
|
import { lockChanged, reduce, reduceAll } from "./document/reduce.mjs";
|
|
@@ -39,7 +39,7 @@ import { AccessParts, effectiveFilter } from "./query/effective.mjs";
|
|
|
39
39
|
import { BoundFilter, Leaf, NEGATION_OF, NEGATIVE_OPS, NULL_OPS, NegativeOp, NodeId, NullOp, Op, POSITIVE_OPS, PositiveOp, StoredFilter, ValueLeaf, VariableLeaf, ViewerLeaf, ViewerRef, WireFilter, isBound, isLeaf, stripIds } from "./query/filter.mjs";
|
|
40
40
|
import { FormulaRef, changeOf, formulaRefs, shareOf } from "./query/formulas.mjs";
|
|
41
41
|
import { isDateRange, isValuePick, pickProblem } from "./query/picks.mjs";
|
|
42
|
-
import { Alias, QueryReferenceError, toWire } from "./query/to-wire.mjs";
|
|
42
|
+
import { Alias, QueryReferenceError, entryAliases, toWire } from "./query/to-wire.mjs";
|
|
43
43
|
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";
|
|
44
44
|
import "./time/index.mjs";
|
|
45
45
|
import { ItemLinks, ItemLinksFor, LINK_PART, itemLink, linkTemplateIssues } from "./query/drill/links.mjs";
|
|
@@ -47,6 +47,7 @@ import { ApiError, CONTRACT_VERSION, CoreContract, DashboardListResponse, Dashbo
|
|
|
47
47
|
import { AnswerDrill, ClosedRow, DrillAbilities, DrillAnswer, DrillBody, DrillCrumb, DrillExplanationView, DrillGroupedView, DrillItem, DrillItemsView, DrillOperand, DrillSummary, ItemColumn, SealedAnswer } from "./types/drill-api.mjs";
|
|
48
48
|
import { CoreApi, CreateDash, Dash, EndpointsByPath, HeadersLike, PluginEndpoints, PluginErrorCodes, ServerCall, ServerCallInput, ServerCalls, UniqueIds } from "./types/infer.mjs";
|
|
49
49
|
import { CodeDashboard, DashOptions, SecondaryStorage } from "./types/options.mjs";
|
|
50
|
+
import { addsUp } from "./result/additive.mjs";
|
|
50
51
|
import { memberLabel, recordColumns, resultColumns, roleOf } from "./result/columns.mjs";
|
|
51
52
|
import { isMark, markedRows } from "./result/marks.mjs";
|
|
52
53
|
import { timeAxis, withTime } from "./result/time-axis.mjs";
|
|
@@ -61,4 +62,4 @@ import { Author, DashAdapter, DashboardHead, DashboardReader, DashboardStore, Da
|
|
|
61
62
|
import { CanFn, Channel, Principal, Resource, TenantKeysOf, Verb, Viewer, ViewerFor, principalTenant } from "./types/viewer.mjs";
|
|
62
63
|
import { canonical } from "./value/canonical.mjs";
|
|
63
64
|
import { fold, foldingPairs } from "./value/casefold.mjs";
|
|
64
|
-
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 ColumnRole, 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, DISPLAY_HELP, DISPLAY_OPTIONS, 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 DisplayKind, type DisplayOf, 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 TimeAxis, type TimeBucket, 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, bindQueryViewer, bindViewer, bucketLabel, bucketLabels, bucketStart, canonical, changeOf, changedWidget, checkCatalog, closeGaps, closeGapsCommands, commandWidget, comparisonQuery, comparisonSpan, composeTile, createDashEndpoint, createTable, defineErrorCodes, defineModel, describeQueries, diffDocs, displayIssues, displayOf, divideExact, documentDisplayIssues, documentLock, editedDisplayIssues, effectiveFilter, emptyDoc, encodeView, fold, foldingPairs, formatExact, formatTextTime, formulaRefs, freeSpot, inSpan, isBound, isDateRange, isLeaf, isMark, isValuePick, 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, roleOf, rowValue, ruleMatches, schemaChecks, schemaStatements, selectRule, shareOf, sharedDisplay, shiftBucket, shiftInstant, smallestFor, startOfDate, stepCommands, stepMoves, storedExact, stripIds, sumLinear, tileInputs, timeAxis, toWire, validateModel, viaJoins, viewFor, viewLayout, viewerValues, widgetDiff, withTime, withView };
|
|
65
|
+
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 ColumnRole, 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, DISPLAY_HELP, DISPLAY_OPTIONS, 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 DisplayKind, type DisplayOf, 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 SharedDisplay, 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 TimeAxis, type TimeBucket, 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, addsUp, bindFilter, bindPolicy, bindQueryViewer, bindViewer, bucketLabel, bucketLabels, bucketStart, canonical, changeOf, changedWidget, checkCatalog, closeGaps, closeGapsCommands, commandWidget, comparisonQuery, comparisonSpan, composeTile, createDashEndpoint, createTable, defineErrorCodes, defineModel, describeQueries, diffDocs, displayIssues, displayOf, divideExact, documentDisplayIssues, documentLock, editedDisplayIssues, effectiveFilter, emptyDoc, encodeView, entryAliases, fold, foldingPairs, formatExact, formatTextTime, formulaRefs, freeSpot, inSpan, isBound, isDateRange, isLeaf, isMark, isValuePick, 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, roleOf, rowValue, ruleMatches, schemaChecks, schemaStatements, selectRule, shareOf, sharedDisplay, shiftBucket, shiftInstant, smallestFor, startOfDate, stepCommands, stepMoves, storedExact, stripIds, sumLinear, tileInputs, timeAxis, toWire, validateModel, viaJoins, viewFor, viewLayout, viewerValues, widgetDiff, withTime, withView };
|
package/dist/core/index.mjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
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
|
+
import { checkCatalog } from "./model/catalog/check.mjs";
|
|
4
|
+
import { describeQueries } from "./model/catalog/queries.mjs";
|
|
3
5
|
import { DISPLAY_HELP, DISPLAY_OPTIONS, displayIssues, displayOf, documentDisplayIssues, editedDisplayIssues, sharedDisplay } from "./document/display.mjs";
|
|
4
6
|
import { GRID_COLUMNS, closeGaps, closeGapsCommands, freeSpot, layoutGaps, placeItem, repairLayout } from "./document/layout.mjs";
|
|
5
7
|
import { lockChanged, reduce, reduceAll } from "./document/reduce.mjs";
|
|
6
8
|
import { commandWidget, replay } from "./document/replay.mjs";
|
|
7
9
|
import { readingOrder, stepCommands, stepMoves } from "./document/stacked.mjs";
|
|
8
10
|
import { emptyDoc } from "./document/types.mjs";
|
|
9
|
-
import {
|
|
11
|
+
import { policyBinding } from "./model/defaults.mjs";
|
|
10
12
|
import { VIEW_PREFIX, encodeView, viewFor, withView } from "./document/view.mjs";
|
|
11
13
|
import { smallestFor, viewLayout } from "./document/view-layout.mjs";
|
|
12
|
-
import {
|
|
14
|
+
import { ModelError, defineModel } from "./model/define.mjs";
|
|
13
15
|
import { EXACT_LIMIT, divideExact, formatExact, parseExact, storedExact } from "./exact/decimal.mjs";
|
|
14
16
|
import { rowValue, sumLinear } from "./exact/sum.mjs";
|
|
15
|
-
import { policyBinding } from "./model/defaults.mjs";
|
|
16
|
-
import { ModelError, defineModel } from "./model/define.mjs";
|
|
17
17
|
import { parseMemberId, recordDimensions, resolveDimension, resolveMeasure } from "./model/member.mjs";
|
|
18
18
|
import { EXPR_FUNCTIONS } from "./model/types.mjs";
|
|
19
19
|
import { linearTerms } from "./model/validate/expr.mjs";
|
|
@@ -21,8 +21,8 @@ import { validateModel } from "./model/validate/index.mjs";
|
|
|
21
21
|
import { viaJoins } from "./model/validate/via.mjs";
|
|
22
22
|
import { bindFilter, bindPolicy, namedPolicy, viewerValues } from "./policy/bind.mjs";
|
|
23
23
|
import { bindQueryViewer, bindViewer } from "./policy/bind-query.mjs";
|
|
24
|
-
import { isZone, momentMicros } from "./time/temporal.mjs";
|
|
25
24
|
import { ruleMatches, selectRule } from "./policy/match.mjs";
|
|
25
|
+
import { isZone, momentMicros } from "./time/temporal.mjs";
|
|
26
26
|
import { queryClosure } from "./query/closure.mjs";
|
|
27
27
|
import { DEFAULT_COMPOSITION_POLICY } from "./query/compose.mjs";
|
|
28
28
|
import { composeTile, documentLock, tileInputs } from "./query/compose-tile.mjs";
|
|
@@ -30,10 +30,11 @@ import { effectiveFilter } from "./query/effective.mjs";
|
|
|
30
30
|
import { NEGATION_OF, NEGATIVE_OPS, NULL_OPS, POSITIVE_OPS, isBound, isLeaf, stripIds } from "./query/filter.mjs";
|
|
31
31
|
import { changeOf, formulaRefs, shareOf } from "./query/formulas.mjs";
|
|
32
32
|
import { isDateRange, isValuePick, pickProblem } from "./query/picks.mjs";
|
|
33
|
-
import { QueryReferenceError, toWire } from "./query/to-wire.mjs";
|
|
33
|
+
import { QueryReferenceError, entryAliases, toWire } from "./query/to-wire.mjs";
|
|
34
34
|
import { LINK_PART, itemLink, linkTemplateIssues } from "./query/drill/links.mjs";
|
|
35
35
|
import { MAX_DRILL_STEPS } from "./query/drill/types.mjs";
|
|
36
36
|
import { CONTRACT_VERSION } from "./types/api.mjs";
|
|
37
|
+
import { addsUp } from "./result/additive.mjs";
|
|
37
38
|
import { memberLabel, recordColumns, resultColumns, roleOf } from "./result/columns.mjs";
|
|
38
39
|
import { isMark, markedRows } from "./result/marks.mjs";
|
|
39
40
|
import { MICROS_PER_DAY, MICROS_PER_HOUR, MICROS_PER_SECOND, formatTextTime, parseDate, parseNaiveTime, parseTextTime } from "./time/instant.mjs";
|
|
@@ -48,4 +49,4 @@ import { createDashEndpoint } from "./types/plugin.mjs";
|
|
|
48
49
|
import { principalTenant } from "./types/viewer.mjs";
|
|
49
50
|
import { canonical } from "./value/canonical.mjs";
|
|
50
51
|
import { fold, foldingPairs } from "./value/casefold.mjs";
|
|
51
|
-
export { BASE_ERROR_CODES, CATALOG, CONTRACT_VERSION, DEFAULT_COMPOSITION_POLICY, DISPLAY_HELP, DISPLAY_OPTIONS, 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, bindQueryViewer, bindViewer, bucketLabel, bucketLabels, bucketStart, canonical, changeOf, changedWidget, checkCatalog, closeGaps, closeGapsCommands, commandWidget, comparisonQuery, comparisonSpan, composeTile, createDashEndpoint, createTable, defineErrorCodes, defineModel, describeQueries, diffDocs, displayIssues, displayOf, divideExact, documentDisplayIssues, documentLock, editedDisplayIssues, effectiveFilter, emptyDoc, encodeView, fold, foldingPairs, formatExact, formatTextTime, formulaRefs, freeSpot, inSpan, isBound, isDateRange, isLeaf, isMark, isValuePick, 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, roleOf, rowValue, ruleMatches, schemaChecks, schemaStatements, selectRule, shareOf, sharedDisplay, shiftBucket, shiftInstant, smallestFor, startOfDate, stepCommands, stepMoves, storedExact, stripIds, sumLinear, tileInputs, timeAxis, toWire, validateModel, viaJoins, viewFor, viewLayout, viewerValues, widgetDiff, withTime, withView };
|
|
52
|
+
export { BASE_ERROR_CODES, CATALOG, CONTRACT_VERSION, DEFAULT_COMPOSITION_POLICY, DISPLAY_HELP, DISPLAY_OPTIONS, 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, addsUp, bindFilter, bindPolicy, bindQueryViewer, bindViewer, bucketLabel, bucketLabels, bucketStart, canonical, changeOf, changedWidget, checkCatalog, closeGaps, closeGapsCommands, commandWidget, comparisonQuery, comparisonSpan, composeTile, createDashEndpoint, createTable, defineErrorCodes, defineModel, describeQueries, diffDocs, displayIssues, displayOf, divideExact, documentDisplayIssues, documentLock, editedDisplayIssues, effectiveFilter, emptyDoc, encodeView, entryAliases, fold, foldingPairs, formatExact, formatTextTime, formulaRefs, freeSpot, inSpan, isBound, isDateRange, isLeaf, isMark, isValuePick, 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, roleOf, rowValue, ruleMatches, schemaChecks, schemaStatements, selectRule, shareOf, sharedDisplay, shiftBucket, shiftInstant, smallestFor, startOfDate, stepCommands, stepMoves, storedExact, stripIds, sumLinear, tileInputs, timeAxis, toWire, validateModel, viaJoins, viewFor, viewLayout, viewerValues, widgetDiff, withTime, withView };
|
|
@@ -54,20 +54,26 @@ function dimensionType(dim, column, path) {
|
|
|
54
54
|
return [];
|
|
55
55
|
}
|
|
56
56
|
const declaredNumeric = (c) => c.type === "numeric" && c.precision !== void 0 && c.precision >= 1 && c.precision <= 38;
|
|
57
|
+
/**
|
|
58
|
+
* A declared numeric at the measure's scale. A source's own sql is described by its result's
|
|
59
|
+
* types, which carry no precision or scale (a cast to numeric(18, 2) reads as numeric), so
|
|
60
|
+
* there the scale is taken on the author's word, as its key is.
|
|
61
|
+
*/
|
|
62
|
+
const exactAt = (column, scale, fromQuery) => declaredNumeric(column) && column.scale === scale || fromQuery && column.type === "numeric" && column.precision === void 0;
|
|
57
63
|
/** Whether a column holds an exact operand as the measure says it is stored; the reason when not. */
|
|
58
|
-
function storageProblem(column, stored, scale) {
|
|
64
|
+
function storageProblem(column, stored, scale, fromQuery) {
|
|
59
65
|
if (stored === "minor_units") return column.type === "integer" || column.type === "bigint" ? void 0 : `"${column.name}" is ${column.type}; minor units are stored as integers.`;
|
|
60
|
-
if (
|
|
66
|
+
if (exactAt(column, scale, fromQuery)) return void 0;
|
|
61
67
|
const declared = column.precision === void 0 ? "" : `(${column.precision}, ${column.scale ?? 0})`;
|
|
62
68
|
return `"${column.name}" is ${column.type}${declared}; this measure reads numeric with a declared precision and scale ${scale}.`;
|
|
63
69
|
}
|
|
64
70
|
/** An exact measure's columns hold what it says: declared numeric(p, s) at its scale, or integers. */
|
|
65
|
-
function measureType(def, columns, path) {
|
|
71
|
+
function measureType(def, columns, path, fromQuery) {
|
|
66
72
|
if (!("numeric" in def) || def.numeric === "float") return [];
|
|
67
73
|
const { stored, scale } = def.numeric;
|
|
68
74
|
return exprLinearTerms(def.of).flatMap((term) => {
|
|
69
75
|
const column = columns(term.column);
|
|
70
|
-
const problem = column === void 0 ? void 0 : storageProblem(column, stored, scale);
|
|
76
|
+
const problem = column === void 0 ? void 0 : storageProblem(column, stored, scale, fromQuery);
|
|
71
77
|
return problem === void 0 ? [] : [issue("COLUMN_TYPE_MISMATCH", path, problem)];
|
|
72
78
|
});
|
|
73
79
|
}
|
|
@@ -125,7 +131,7 @@ function sourceIssues(model, schema, name, def) {
|
|
|
125
131
|
...path,
|
|
126
132
|
"measures",
|
|
127
133
|
m
|
|
128
|
-
])),
|
|
134
|
+
], def.sql !== void 0)),
|
|
129
135
|
...joinIssues(model, schema, def, path)
|
|
130
136
|
];
|
|
131
137
|
}
|
|
@@ -71,4 +71,9 @@ function recordDimensions(model, sourceName) {
|
|
|
71
71
|
const rank = ([n, d]) => shownRank(d, n === time);
|
|
72
72
|
return lead(Object.entries(def.dimensions).filter(([n]) => !n.startsWith("dd_") && n !== named).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)).map(([n]) => n).slice(0, DEFAULT_RECORD_COLUMNS - (named === void 0 ? 0 : 1)));
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Whether a measure's values add up across groups: the model merges it by a sum. The model
|
|
76
|
+
* check holds a merge to the measure's kind, so this is true only of a count or a sum.
|
|
77
|
+
*/
|
|
78
|
+
const mergesBySum = (def) => def.merge === "sum";
|
|
79
|
+
export { mergesBySum, parseMemberId, recordDimensions, resolveDimension, resolveMeasure };
|
|
@@ -77,6 +77,30 @@ function percentileIssues(measure, path) {
|
|
|
77
77
|
const message = "A percentile cannot be merged from parts; its merge must be \"none\".";
|
|
78
78
|
return when(bad, "PERCENTILE_MERGE", [...path, "merge"], message);
|
|
79
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* What each kind is called, and the merge its values over parts combine into the whole by:
|
|
82
|
+
* counts and sums add up, a least or greatest value is the least or greatest of the parts'.
|
|
83
|
+
* An average and a distinct count have none: neither can be made from its parts' values.
|
|
84
|
+
*/
|
|
85
|
+
const MERGED = {
|
|
86
|
+
count: ["A count", "sum"],
|
|
87
|
+
distinct: ["A distinct count"],
|
|
88
|
+
sum: ["A sum", "sum"],
|
|
89
|
+
min: ["A min", "min"],
|
|
90
|
+
max: ["A max", "max"],
|
|
91
|
+
avg: ["An average"]
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* A merge says how a measure's parts combine, and an answer's column tells a chart from it
|
|
95
|
+
* whether to add them up. So it must be true of the kind: "none", or the kind's own.
|
|
96
|
+
*/
|
|
97
|
+
function mergeIssues(measure, path) {
|
|
98
|
+
const distinct = measure.kind === "count" && measure.distinct !== void 0;
|
|
99
|
+
const [name, by] = MERGED[distinct ? "distinct" : measure.kind];
|
|
100
|
+
const message = by === void 0 ? `${name} cannot be merged from parts; its merge must be "none".` : `${name} is merged by "${by}"; its merge must be "${by}" or "none".`;
|
|
101
|
+
const bad = measure.merge !== "none" && measure.merge !== by;
|
|
102
|
+
return when(bad, "MEASURE_MERGE", [...path, "merge"], message);
|
|
103
|
+
}
|
|
80
104
|
/** The checks that apply only to a measure with an exact or float number type. */
|
|
81
105
|
function numberIssues(measure, path) {
|
|
82
106
|
if (measure.kind === "percentile") return [];
|
|
@@ -96,6 +120,12 @@ function measureIssues(model, sourceName, measure, path) {
|
|
|
96
120
|
if (!source) return [];
|
|
97
121
|
if (measure.kind === "ratio") return ratioIssues(source, measure, path);
|
|
98
122
|
const where = measure.where ? modelFilterIssues(model, sourceName, measure.where, [...path, "where"]) : [];
|
|
99
|
-
|
|
123
|
+
if (measure.kind === "count") return [...where, ...mergeIssues(measure, path)];
|
|
124
|
+
const merge = measure.kind === "percentile" ? [] : mergeIssues(measure, path);
|
|
125
|
+
return [
|
|
126
|
+
...where,
|
|
127
|
+
...aggregateIssues(source, measure, path),
|
|
128
|
+
...merge
|
|
129
|
+
];
|
|
100
130
|
}
|
|
101
131
|
export { dimensionIssues, measureIssues };
|
|
@@ -9,7 +9,9 @@ function policyRows(filter, row) {
|
|
|
9
9
|
if ("any" in filter) return filter.any.some((part) => policyRows(part, row));
|
|
10
10
|
if ("not" in filter) return !policyRows(filter.not, row);
|
|
11
11
|
if (!("values" in filter)) return false;
|
|
12
|
-
|
|
12
|
+
const cell = row[filter.column] ?? null;
|
|
13
|
+
const textual = cell !== null && typeof cell !== "string" && filter.values.every((v) => typeof v === "string");
|
|
14
|
+
return evaluateLeaf(textual ? String(cell) : cell, filter.op, filter.values);
|
|
13
15
|
}
|
|
14
16
|
/** Through a `via` join the row is visible only if its one parent is. */
|
|
15
17
|
function viaParent(input, row, joinName, test) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DRILL_REASONS } from "../../error/codes.mjs";
|
|
2
|
-
import { parseMemberId, resolveMeasure } from "../../model/member.mjs";
|
|
2
|
+
import { mergesBySum, parseMemberId, resolveMeasure } from "../../model/member.mjs";
|
|
3
3
|
import { memberLabel } from "../../result/columns.mjs";
|
|
4
4
|
import { canonical } from "../../value/canonical.mjs";
|
|
5
5
|
import { aliasPart, lineAlias } from "../alias.mjs";
|
|
@@ -127,7 +127,7 @@ function lineSemantics(model, set, drill) {
|
|
|
127
127
|
counted: false
|
|
128
128
|
};
|
|
129
129
|
const { def } = line;
|
|
130
|
-
const additive = def
|
|
130
|
+
const additive = mergesBySum(def);
|
|
131
131
|
if ("partitionBy" in def && def.partitionBy !== void 0) return {
|
|
132
132
|
semantics: "rows",
|
|
133
133
|
items: off("SNAPSHOT"),
|
|
@@ -4,6 +4,13 @@ export declare class QueryReferenceError extends Error {
|
|
|
4
4
|
readonly entryId: EntryId;
|
|
5
5
|
constructor(entryId: EntryId, where: string);
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* The alias each entry of a stored query has in the query that runs, and so the id of its
|
|
9
|
+
* column in an answer, by the entry's editing id. For a reader that names entries as the
|
|
10
|
+
* widget does (a `display` option) and must find them in an answer. Of two entries with one id
|
|
11
|
+
* (which `toWire` refuses) the later is kept.
|
|
12
|
+
*/
|
|
13
|
+
export declare function entryAliases(stored: StoredQuery): ReadonlyMap<EntryId, Alias>;
|
|
7
14
|
/**
|
|
8
15
|
* Turns a stored query into the query that runs.
|
|
9
16
|
*
|