derive-dashboards 0.10.0 → 0.11.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/CHANGELOG.md +52 -0
- package/dist/body.mjs +5 -1
- package/dist/charts/data/words.d.mts +5 -0
- package/dist/charts/data/words.mjs +1 -0
- package/dist/charts/kinds/columns-data.mjs +4 -1
- package/dist/charts/kinds/grid-layout.mjs +84 -8
- package/dist/charts/kinds/grid-legend.mjs +27 -4
- package/dist/charts/kinds/grid-marks.mjs +56 -4
- package/dist/charts/kinds/grid.mjs +2 -1
- package/dist/charts/scale/value.mjs +15 -8
- package/dist/charts/scene/types.d.mts +1 -1
- package/dist/core/document/display-entries.mjs +9 -2
- package/dist/core/document/display.d.mts +4 -0
- package/dist/core/document/display.mjs +8 -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 +2 -0
- package/dist/core/error/codes.mjs +2 -0
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.mjs +2 -2
- package/dist/core/model/member.d.mts +6 -0
- package/dist/core/model/member.mjs +11 -1
- package/dist/core/model/types.d.mts +6 -0
- package/dist/core/model/validate/known-members.mjs +1 -0
- package/dist/core/model/validate/members.mjs +12 -1
- package/dist/core/query/closure.mjs +3 -1
- package/dist/core/result/columns.mjs +15 -2
- package/dist/core/result/types.d.mts +2 -0
- package/dist/core/schema/answer-parts.mjs +1 -0
- package/dist/core/schema/answers.d.mts +14 -0
- package/dist/core/schema/answers.mjs +4 -2
- package/dist/core/types/api.d.mts +7 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/endpoints/index.d.mts +5 -4
- package/dist/endpoints/meta.mjs +30 -12
- package/dist/endpoints/query.mjs +11 -5
- package/dist/endpoints/values.mjs +37 -23
- package/dist/execute.mjs +22 -1
- package/dist/labels.mjs +68 -0
- package/dist/listing.mjs +13 -0
- package/dist/react/Canvas.mjs +28 -2
- package/dist/react/builder/base.mjs +11 -6
- package/dist/react/builder/display.mjs +15 -2
- package/dist/react/builder/state.mjs +3 -3
- package/dist/react/builder/words.mjs +8 -0
- package/dist/react/dates-shown.mjs +27 -9
- package/dist/react/filters/bar.d.mts +1 -1
- package/dist/react/filters/bar.mjs +17 -7
- package/dist/react/filters/chip.mjs +5 -3
- package/dist/react/filters/context.mjs +2 -2
- package/dist/react/filters/dates-said.mjs +29 -11
- package/dist/react/filters/hooks.d.mts +8 -0
- package/dist/react/filters/hooks.mjs +39 -2
- package/dist/react/filters/menu.mjs +8 -18
- package/dist/react/filters/phone.mjs +3 -3
- package/dist/react/filters/values.mjs +47 -28
- package/dist/react/filters/words.mjs +2 -2
- package/dist/react/format.d.mts +1 -1
- package/dist/react/format.mjs +8 -2
- package/dist/react/renderers/moved.mjs +160 -0
- package/dist/react/renderers/number-before.mjs +2 -157
- package/dist/react/renderers/table-cells.mjs +97 -11
- package/dist/react/renderers/table-head.mjs +7 -1
- package/dist/react/renderers/table-measure.mjs +147 -25
- package/dist/react/renderers/table-over.mjs +72 -0
- package/dist/react/renderers/table-scale.mjs +54 -1
- package/dist/react/renderers/table-trend.mjs +55 -0
- package/dist/react/renderers/table.d.mts +5 -1
- package/dist/react/renderers/table.mjs +29 -6
- package/dist/react/theme-unlayered.css +1 -1
- package/dist/react/theme.css +1 -1
- package/package.json +1 -1
|
@@ -21,6 +21,12 @@ export type DimensionValueType = "string" | "number" | "boolean" | "time";
|
|
|
21
21
|
* that reaches at most one row. Undefined when it does not exist.
|
|
22
22
|
*/
|
|
23
23
|
export declare function resolveDimension(model: Model, sourceName: string, id: string): ResolvedDimension | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* The member that names a dimension's values, for a string dimension `shownAs` another: the
|
|
26
|
+
* same path, ending in the other's name ("task.projectId" shown as "task.project"). None for
|
|
27
|
+
* any other dimension.
|
|
28
|
+
*/
|
|
29
|
+
export declare function shownAsMember(model: Model, source: string, member: string): string | undefined;
|
|
24
30
|
/**
|
|
25
31
|
* The dimensions a records view of a source shows, by name: its `records.columns`, or else up
|
|
26
32
|
* to twelve that are neither hidden, sensitive nor `drill: false`: its text fields, then its
|
|
@@ -67,6 +67,16 @@ function resolveDimension(model, sourceName, id) {
|
|
|
67
67
|
if (ref === void 0 || ref.source !== sourceName) return void 0;
|
|
68
68
|
return ref.join === void 0 ? ownDimension(model, sourceName, ref.name) : joinedDimension(model, sourceName, ref.join, ref.name);
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* The member that names a dimension's values, for a string dimension `shownAs` another: the
|
|
72
|
+
* same path, ending in the other's name ("task.projectId" shown as "task.project"). None for
|
|
73
|
+
* any other dimension.
|
|
74
|
+
*/
|
|
75
|
+
function shownAsMember(model, source, member) {
|
|
76
|
+
const def = resolveDimension(model, source, member)?.dimension;
|
|
77
|
+
if (def?.kind !== "string" || def.shownAs === void 0) return void 0;
|
|
78
|
+
return `${member.slice(0, member.lastIndexOf("."))}.${def.shownAs}`;
|
|
79
|
+
}
|
|
70
80
|
/** The measure a member id names. Measures are always the source's own. */
|
|
71
81
|
function resolveMeasure(model, sourceName, id) {
|
|
72
82
|
const ref = parseMemberId(id);
|
|
@@ -103,4 +113,4 @@ function recordDimensions(model, sourceName) {
|
|
|
103
113
|
* check holds a merge to the measure's kind, so this is true only of a count or a sum.
|
|
104
114
|
*/
|
|
105
115
|
const mergesBySum = (def) => def.merge === "sum";
|
|
106
|
-
export { dimensionValueType, isOnSource, memberIdOf, mergesBySum, ownEntry, parseMemberId, recordDimensions, resolveDimension, resolveMeasure, sourceOf };
|
|
116
|
+
export { dimensionValueType, isOnSource, memberIdOf, mergesBySum, ownEntry, parseMemberId, recordDimensions, resolveDimension, resolveMeasure, shownAsMember, sourceOf };
|
|
@@ -222,6 +222,12 @@ export type DimensionDef = MemberMeta & DimensionHints & ({
|
|
|
222
222
|
values?: readonly string[] | "lookup";
|
|
223
223
|
search?: boolean;
|
|
224
224
|
collation: "binary" | "ci";
|
|
225
|
+
/**
|
|
226
|
+
* Another string dimension of this source that names each value: rows group and filter
|
|
227
|
+
* by this one (an id), and answers and value lists show it as that one's value (a
|
|
228
|
+
* name), so two rows with one name never merge.
|
|
229
|
+
*/
|
|
230
|
+
shownAs?: DimensionName;
|
|
225
231
|
} | {
|
|
226
232
|
kind: "number" | "boolean";
|
|
227
233
|
column: Column;
|
|
@@ -21,6 +21,13 @@ function bucketIssues(dim, path) {
|
|
|
21
21
|
function collationIssues(collation, path) {
|
|
22
22
|
return when(!(collation === "binary" || collation === "ci"), "COLLATION_MISSING", path, "A string dimension must declare \"binary\" or \"ci\".");
|
|
23
23
|
}
|
|
24
|
+
/** `shownAs` names another string dimension of the source, which is not shown as another itself. */
|
|
25
|
+
function shownAsIssues(source, shownAs, path) {
|
|
26
|
+
if (shownAs === void 0) return [];
|
|
27
|
+
const named = source.dimensions[shownAs];
|
|
28
|
+
const ok = named?.kind === "string" && named.shownAs === void 0;
|
|
29
|
+
return when(!ok, "SHOWN_AS_UNKNOWN", path, `"${shownAs}" is not a string dimension of this source that is shown as itself. Name one of its string dimensions that has no shownAs of its own.`);
|
|
30
|
+
}
|
|
24
31
|
function timeIssues(dim, path) {
|
|
25
32
|
const storage = dim.storage;
|
|
26
33
|
if (typeof storage !== "object" || !("timestamp" in storage)) return [];
|
|
@@ -34,7 +41,11 @@ function timeIssues(dim, path) {
|
|
|
34
41
|
}
|
|
35
42
|
function dimensionIssues(source, dim, path) {
|
|
36
43
|
switch (dim.kind) {
|
|
37
|
-
case "string": return
|
|
44
|
+
case "string": return [
|
|
45
|
+
...collationIssues(dim.collation, [...path, "collation"]),
|
|
46
|
+
...shownAsIssues(source, dim.shownAs, [...path, "shownAs"]),
|
|
47
|
+
...when(dim.shownAs !== void 0 && Array.isArray(dim.values), "SHOWN_AS_VALUES", [...path, "values"], "A dimension shown as another lists its values from the data: leave out its own values list.")
|
|
48
|
+
];
|
|
38
49
|
case "ref": return refIssues(source, dim, [...path, "join"]);
|
|
39
50
|
case "bucket": return bucketIssues(dim, path);
|
|
40
51
|
case "expr": return exprIssues(source, dim.expr, [...path, "expr"]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ownEntry, parseMemberId, resolveDimension, resolveMeasure, sourceOf } from "../model/member.mjs";
|
|
1
|
+
import { ownEntry, parseMemberId, resolveDimension, resolveMeasure, shownAsMember, sourceOf } from "../model/member.mjs";
|
|
2
2
|
import { didYouMean } from "../model/validate/fields.mjs";
|
|
3
3
|
import { derivedIssues } from "./derived-rules.mjs";
|
|
4
4
|
import { formulaRefs } from "./formulas.mjs";
|
|
@@ -29,6 +29,8 @@ function dimension(w, source, id, path) {
|
|
|
29
29
|
const name = parseMemberId(id)?.name ?? id;
|
|
30
30
|
w.sources.add(resolved.source);
|
|
31
31
|
w.members.add(`${resolved.source}.${name}`);
|
|
32
|
+
const shown = parseMemberId(shownAsMember(w.model, source, id) ?? "")?.name;
|
|
33
|
+
if (shown !== void 0) w.members.add(`${resolved.source}.${shown}`);
|
|
32
34
|
return resolved;
|
|
33
35
|
}
|
|
34
36
|
function measure(w, source, id, path) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dimensionValueType, mergesBySum, parseMemberId, resolveDimension, resolveMeasure } from "../model/member.mjs";
|
|
1
|
+
import { dimensionValueType, mergesBySum, parseMemberId, resolveDimension, resolveMeasure, shownAsMember } from "../model/member.mjs";
|
|
2
2
|
import { idRole } from "../query/alias.mjs";
|
|
3
3
|
import { formulaRefs } from "../query/formulas.mjs";
|
|
4
4
|
import { calcAddsUp } from "./additive.mjs";
|
|
@@ -73,7 +73,8 @@ function dimensionColumns(model, query) {
|
|
|
73
73
|
const perJoin = /* @__PURE__ */ new Map();
|
|
74
74
|
for (const { resolved } of resolvedDims) if (resolved?.join !== void 0) perJoin.set(resolved.join, (perJoin.get(resolved.join) ?? 0) + 1);
|
|
75
75
|
return resolvedDims.map(({ d, resolved }) => {
|
|
76
|
-
const
|
|
76
|
+
const shown = shownMember(model, query.source, d.member, resolved);
|
|
77
|
+
const own = memberLabel(shown.member, shown.label);
|
|
77
78
|
const join = resolved?.join;
|
|
78
79
|
const label = join === void 0 ? own : (perJoin.get(join) ?? 0) > 1 ? `${words(join)} ${own.toLowerCase()}` : words(join);
|
|
79
80
|
return {
|
|
@@ -86,6 +87,18 @@ function dimensionColumns(model, query) {
|
|
|
86
87
|
};
|
|
87
88
|
});
|
|
88
89
|
}
|
|
90
|
+
/** The member a column is named by: its own, or for one `shownAs` another, what it shows (a name). */
|
|
91
|
+
function shownMember(model, source, member, resolved) {
|
|
92
|
+
const shown = shownAsMember(model, source, member);
|
|
93
|
+
if (shown === void 0) return {
|
|
94
|
+
member,
|
|
95
|
+
label: resolved?.dimension.label
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
member: shown,
|
|
99
|
+
label: resolveDimension(model, source, shown)?.dimension.label
|
|
100
|
+
};
|
|
101
|
+
}
|
|
89
102
|
/** The values a string dimension declares, for a chart to colour by; none for a lookup or a free field. */
|
|
90
103
|
function declaredValues(def) {
|
|
91
104
|
const values = def?.kind === "string" ? def.values : void 0;
|
|
@@ -22,6 +22,8 @@ export type ResultColumn = {
|
|
|
22
22
|
* gives each a colour by its place here, so a value keeps its colour whatever else is drawn.
|
|
23
23
|
*/
|
|
24
24
|
values?: readonly string[];
|
|
25
|
+
/** On a dimension the model labels: each value's label, for the values in the answer. */
|
|
26
|
+
labels?: Readonly<Record<string, string>>;
|
|
25
27
|
/** On a calc's column, or a ratio the model reads as a percent: how its values read. */
|
|
26
28
|
format?: Format;
|
|
27
29
|
/** On a calc that reads the comparison period: a change, shown with its sign (+3.2%). */
|
|
@@ -37,6 +37,7 @@ const column = z.looseObject({
|
|
|
37
37
|
member: z.string().exactOptional(),
|
|
38
38
|
grain: grain.exactOptional(),
|
|
39
39
|
values: z.array(z.string()).readonly().exactOptional(),
|
|
40
|
+
labels: z.record(z.string(), z.string()).readonly().exactOptional(),
|
|
40
41
|
format: z.enum([
|
|
41
42
|
"number",
|
|
42
43
|
"percent",
|
|
@@ -50,6 +50,7 @@ export declare const tileLineSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
50
50
|
year: "year";
|
|
51
51
|
}>>;
|
|
52
52
|
values: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
53
|
+
labels: z.ZodExactOptional<z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
53
54
|
format: z.ZodExactOptional<z.ZodEnum<{
|
|
54
55
|
number: "number";
|
|
55
56
|
percent: "percent";
|
|
@@ -1980,6 +1981,7 @@ export declare const answerSchemas: {
|
|
|
1980
1981
|
values: z.ZodExactOptional<z.ZodUnion<readonly [z.ZodReadonly<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>, z.ZodLiteral<"lookup">]>>;
|
|
1981
1982
|
aggregate: z.ZodExactOptional<z.ZodString>;
|
|
1982
1983
|
unit: z.ZodExactOptional<z.ZodString>;
|
|
1984
|
+
labelled: z.ZodExactOptional<z.ZodLiteral<true>>;
|
|
1983
1985
|
}, z.core.$loose>>;
|
|
1984
1986
|
dimensions: z.ZodArray<z.ZodObject<{
|
|
1985
1987
|
id: z.ZodString;
|
|
@@ -1995,6 +1997,7 @@ export declare const answerSchemas: {
|
|
|
1995
1997
|
values: z.ZodExactOptional<z.ZodUnion<readonly [z.ZodReadonly<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>, z.ZodLiteral<"lookup">]>>;
|
|
1996
1998
|
aggregate: z.ZodExactOptional<z.ZodString>;
|
|
1997
1999
|
unit: z.ZodExactOptional<z.ZodString>;
|
|
2000
|
+
labelled: z.ZodExactOptional<z.ZodLiteral<true>>;
|
|
1998
2001
|
}, z.core.$loose>>;
|
|
1999
2002
|
joins: z.ZodArray<z.ZodObject<{
|
|
2000
2003
|
name: z.ZodString;
|
|
@@ -2013,6 +2016,7 @@ export declare const answerSchemas: {
|
|
|
2013
2016
|
"/meta/values": z.ZodObject<{
|
|
2014
2017
|
values: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>;
|
|
2015
2018
|
more: z.ZodBoolean;
|
|
2019
|
+
labels: z.ZodExactOptional<z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
2016
2020
|
}, z.core.$loose>;
|
|
2017
2021
|
"/dashboards/list": z.ZodObject<{
|
|
2018
2022
|
dashboards: z.ZodArray<z.ZodObject<{
|
|
@@ -2178,6 +2182,7 @@ export declare const answerSchemas: {
|
|
|
2178
2182
|
"/dashboards/control-values": z.ZodObject<{
|
|
2179
2183
|
values: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>;
|
|
2180
2184
|
more: z.ZodBoolean;
|
|
2185
|
+
labels: z.ZodExactOptional<z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
2181
2186
|
}, z.core.$loose>;
|
|
2182
2187
|
"/dashboards/records": z.ZodObject<{
|
|
2183
2188
|
columns: z.ZodArray<z.ZodObject<{
|
|
@@ -2423,6 +2428,7 @@ export declare const answerSchemas: {
|
|
|
2423
2428
|
year: "year";
|
|
2424
2429
|
}>>;
|
|
2425
2430
|
values: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
2431
|
+
labels: z.ZodExactOptional<z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
2426
2432
|
format: z.ZodExactOptional<z.ZodEnum<{
|
|
2427
2433
|
number: "number";
|
|
2428
2434
|
percent: "percent";
|
|
@@ -2751,6 +2757,7 @@ export declare const answerSchemas: {
|
|
|
2751
2757
|
year: "year";
|
|
2752
2758
|
}>>;
|
|
2753
2759
|
values: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
2760
|
+
labels: z.ZodExactOptional<z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
2754
2761
|
format: z.ZodExactOptional<z.ZodEnum<{
|
|
2755
2762
|
number: "number";
|
|
2756
2763
|
percent: "percent";
|
|
@@ -3335,6 +3342,7 @@ export declare const answerSchemas: {
|
|
|
3335
3342
|
year: "year";
|
|
3336
3343
|
}>>;
|
|
3337
3344
|
values: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
3345
|
+
labels: z.ZodExactOptional<z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
3338
3346
|
format: z.ZodExactOptional<z.ZodEnum<{
|
|
3339
3347
|
number: "number";
|
|
3340
3348
|
percent: "percent";
|
|
@@ -3561,6 +3569,7 @@ export declare const answerSchemas: {
|
|
|
3561
3569
|
year: "year";
|
|
3562
3570
|
}>>;
|
|
3563
3571
|
values: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
3572
|
+
labels: z.ZodExactOptional<z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
3564
3573
|
format: z.ZodExactOptional<z.ZodEnum<{
|
|
3565
3574
|
number: "number";
|
|
3566
3575
|
percent: "percent";
|
|
@@ -3756,6 +3765,7 @@ export declare const answerSchemas: {
|
|
|
3756
3765
|
year: "year";
|
|
3757
3766
|
}>>;
|
|
3758
3767
|
values: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
3768
|
+
labels: z.ZodExactOptional<z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
3759
3769
|
format: z.ZodExactOptional<z.ZodEnum<{
|
|
3760
3770
|
number: "number";
|
|
3761
3771
|
percent: "percent";
|
|
@@ -4248,6 +4258,7 @@ export declare const answerSchemas: {
|
|
|
4248
4258
|
year: "year";
|
|
4249
4259
|
}>>;
|
|
4250
4260
|
values: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
4261
|
+
labels: z.ZodExactOptional<z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
4251
4262
|
format: z.ZodExactOptional<z.ZodEnum<{
|
|
4252
4263
|
number: "number";
|
|
4253
4264
|
percent: "percent";
|
|
@@ -4576,6 +4587,7 @@ export declare const answerSchemas: {
|
|
|
4576
4587
|
year: "year";
|
|
4577
4588
|
}>>;
|
|
4578
4589
|
values: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
4590
|
+
labels: z.ZodExactOptional<z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
4579
4591
|
format: z.ZodExactOptional<z.ZodEnum<{
|
|
4580
4592
|
number: "number";
|
|
4581
4593
|
percent: "percent";
|
|
@@ -5160,6 +5172,7 @@ export declare const answerSchemas: {
|
|
|
5160
5172
|
year: "year";
|
|
5161
5173
|
}>>;
|
|
5162
5174
|
values: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
5175
|
+
labels: z.ZodExactOptional<z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
5163
5176
|
format: z.ZodExactOptional<z.ZodEnum<{
|
|
5164
5177
|
number: "number";
|
|
5165
5178
|
percent: "percent";
|
|
@@ -5386,6 +5399,7 @@ export declare const answerSchemas: {
|
|
|
5386
5399
|
year: "year";
|
|
5387
5400
|
}>>;
|
|
5388
5401
|
values: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
|
|
5402
|
+
labels: z.ZodExactOptional<z.ZodReadonly<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
5389
5403
|
format: z.ZodExactOptional<z.ZodEnum<{
|
|
5390
5404
|
number: "number";
|
|
5391
5405
|
percent: "percent";
|
|
@@ -17,7 +17,8 @@ const queryAnswer = result.extend({
|
|
|
17
17
|
});
|
|
18
18
|
const values = z.looseObject({
|
|
19
19
|
values: z.array(primitive),
|
|
20
|
-
more: z.boolean()
|
|
20
|
+
more: z.boolean(),
|
|
21
|
+
labels: z.record(z.string(), z.string()).readonly().exactOptional()
|
|
21
22
|
});
|
|
22
23
|
const metaMember = z.looseObject({
|
|
23
24
|
id: z.string(),
|
|
@@ -32,7 +33,8 @@ const metaMember = z.looseObject({
|
|
|
32
33
|
]),
|
|
33
34
|
values: z.union([z.array(primitive).readonly(), z.literal("lookup")]).exactOptional(),
|
|
34
35
|
aggregate: z.string().exactOptional(),
|
|
35
|
-
unit: z.string().exactOptional()
|
|
36
|
+
unit: z.string().exactOptional(),
|
|
37
|
+
labelled: z.literal(true).exactOptional()
|
|
36
38
|
});
|
|
37
39
|
const meta = z.looseObject({ sources: z.array(z.looseObject({
|
|
38
40
|
name: z.string(),
|
|
@@ -23,6 +23,8 @@ export type MetaMember = {
|
|
|
23
23
|
tones?: Readonly<Record<string, "positive" | "negative" | "warning" | "neutral">>;
|
|
24
24
|
/** On a number dimension: its bucket edges, ascending, from the model's hints. */
|
|
25
25
|
buckets?: readonly number[];
|
|
26
|
+
/** On a dimension the model labels: values are ids, each shown by its label (`labels`). */
|
|
27
|
+
labelled?: true;
|
|
26
28
|
};
|
|
27
29
|
/** A join a query can group by: `<source>.<join>.<dimension>` names a dimension of `source`. */
|
|
28
30
|
export type MetaJoin = {
|
|
@@ -77,6 +79,8 @@ export type PublishResponse = Published;
|
|
|
77
79
|
export type ValuesResponse = {
|
|
78
80
|
values: Primitive[];
|
|
79
81
|
more: boolean;
|
|
82
|
+
/** For a member the model labels: each listed value's label. */
|
|
83
|
+
labels?: Readonly<Record<string, string>>;
|
|
80
84
|
};
|
|
81
85
|
/**
|
|
82
86
|
* A page of the rows behind a tile or a query: its columns and rows, and when more follow,
|
|
@@ -201,6 +205,8 @@ export type CoreContract = {
|
|
|
201
205
|
dashboardId: string;
|
|
202
206
|
controlId: string;
|
|
203
207
|
search?: string;
|
|
208
|
+
/** Only these values: a pick read back with its labels. */
|
|
209
|
+
keys?: readonly string[];
|
|
204
210
|
limit?: number;
|
|
205
211
|
};
|
|
206
212
|
answer: ValuesResponse;
|
|
@@ -344,4 +350,4 @@ export type CoreContract = {
|
|
|
344
350
|
* than reading a shape it does not know. A test recomputes it from the answer schemas, so a
|
|
345
351
|
* change to an answer fails until this is updated.
|
|
346
352
|
*/
|
|
347
|
-
export declare const CONTRACT_VERSION = "
|
|
353
|
+
export declare const CONTRACT_VERSION = "abd7c4243079e13c";
|
package/dist/core/types/api.mjs
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* than reading a shape it does not know. A test recomputes it from the answer schemas, so a
|
|
6
6
|
* change to an answer fails until this is updated.
|
|
7
7
|
*/
|
|
8
|
-
const CONTRACT_VERSION = "
|
|
8
|
+
const CONTRACT_VERSION = "abd7c4243079e13c";
|
|
9
9
|
export { CONTRACT_VERSION };
|
|
@@ -464,6 +464,7 @@ export declare function coreEndpoints(rt: Runtime): {
|
|
|
464
464
|
total?: boolean;
|
|
465
465
|
fill?: "zero" | "none";
|
|
466
466
|
};
|
|
467
|
+
order?: readonly (readonly [string, "asc" | "desc"])[];
|
|
467
468
|
after?: string;
|
|
468
469
|
limit?: number;
|
|
469
470
|
}, import("derive-dashboards/core").RecordsResponse, "POST">;
|
|
@@ -648,6 +649,7 @@ export declare function coreEndpoints(rt: Runtime): {
|
|
|
648
649
|
dashboardId: string;
|
|
649
650
|
controlId: string;
|
|
650
651
|
search?: string;
|
|
652
|
+
keys?: readonly string[];
|
|
651
653
|
limit?: number;
|
|
652
654
|
draft?: true;
|
|
653
655
|
}, import("derive-dashboards/core").ValuesResponse, "POST">;
|
|
@@ -702,6 +704,7 @@ export declare function coreEndpoints(rt: Runtime): {
|
|
|
702
704
|
unit?: string;
|
|
703
705
|
tones?: Readonly<Record<string, "positive" | "negative" | "warning" | "neutral">>;
|
|
704
706
|
buckets?: readonly number[];
|
|
707
|
+
labelled?: true;
|
|
705
708
|
}[];
|
|
706
709
|
dimensions: {
|
|
707
710
|
id: string;
|
|
@@ -712,6 +715,7 @@ export declare function coreEndpoints(rt: Runtime): {
|
|
|
712
715
|
unit?: string;
|
|
713
716
|
tones?: Readonly<Record<string, "positive" | "negative" | "warning" | "neutral">>;
|
|
714
717
|
buckets?: readonly number[];
|
|
718
|
+
labelled?: true;
|
|
715
719
|
}[];
|
|
716
720
|
joins: {
|
|
717
721
|
name: string;
|
|
@@ -731,8 +735,5 @@ export declare function coreEndpoints(rt: Runtime): {
|
|
|
731
735
|
member: string;
|
|
732
736
|
search?: string;
|
|
733
737
|
limit?: number;
|
|
734
|
-
},
|
|
735
|
-
values: import("derive-dashboards/core").Primitive[];
|
|
736
|
-
more: boolean;
|
|
737
|
-
}, "POST">;
|
|
738
|
+
}, import("derive-dashboards/core").ValuesResponse, "POST">;
|
|
738
739
|
};
|
package/dist/endpoints/meta.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { authorizeFree } from "../authorize.mjs";
|
|
1
2
|
import { bodies, bodySchemas, parseWith } from "../body.mjs";
|
|
2
3
|
import { allows, allowsSensitive } from "../grant.mjs";
|
|
3
4
|
import { nowOf, userOf } from "../request.mjs";
|
|
4
5
|
import { viewMember } from "./access.mjs";
|
|
5
6
|
import { memberValues } from "./values.mjs";
|
|
6
|
-
import { createDashEndpoint, memberLabel } from "derive-dashboards/core";
|
|
7
|
+
import { createDashEndpoint, memberLabel, parseMemberId } from "derive-dashboards/core";
|
|
7
8
|
import { toolSchemas } from "derive-dashboards/core/schema";
|
|
8
9
|
// src/endpoints/meta.ts
|
|
9
10
|
function dimensionType(def) {
|
|
@@ -57,6 +58,10 @@ function unitOf(def) {
|
|
|
57
58
|
}
|
|
58
59
|
/** A dimension's own list of values, when the model gives one. */
|
|
59
60
|
function staticValues(def) {
|
|
61
|
+
if (def.kind === "string" && def.shownAs !== void 0) return {
|
|
62
|
+
values: "lookup",
|
|
63
|
+
labelled: true
|
|
64
|
+
};
|
|
60
65
|
if (def.kind === "string" && def.values !== void 0) return { values: def.values === "lookup" ? "lookup" : def.values };
|
|
61
66
|
return def.kind === "bucket" ? { values: def.labels } : {};
|
|
62
67
|
}
|
|
@@ -116,17 +121,30 @@ function metaEndpoints(rt) {
|
|
|
116
121
|
method: "POST",
|
|
117
122
|
access: viewMember,
|
|
118
123
|
parse: (input) => parseWith(bodies.memberValues, input),
|
|
119
|
-
handler: ({ body, principal, request }) =>
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
handler: async ({ body, principal, request }) => {
|
|
125
|
+
const user = userOf(principal);
|
|
126
|
+
const source = parseMemberId(body.member)?.source ?? "";
|
|
127
|
+
await authorizeFree(rt.options, user.viewer, {
|
|
128
|
+
kind: "aggregate",
|
|
129
|
+
source,
|
|
130
|
+
measures: [],
|
|
131
|
+
dimensions: [{
|
|
132
|
+
id: "d1",
|
|
133
|
+
member: body.member
|
|
134
|
+
}]
|
|
135
|
+
});
|
|
136
|
+
return memberValues({
|
|
137
|
+
rt,
|
|
138
|
+
request,
|
|
139
|
+
principal: user,
|
|
140
|
+
now: nowOf(rt.options),
|
|
141
|
+
lock: [],
|
|
142
|
+
coverage: {
|
|
143
|
+
applied: [],
|
|
144
|
+
dropped: []
|
|
145
|
+
}
|
|
146
|
+
}, body);
|
|
147
|
+
}
|
|
130
148
|
})
|
|
131
149
|
};
|
|
132
150
|
}
|
package/dist/endpoints/query.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { authorizeFree, readableOffer } from "../authorize.mjs";
|
|
1
|
+
import { authorizeFree, checkSensitive, readableOffer } from "../authorize.mjs";
|
|
2
2
|
import { bodies, parseWith } from "../body.mjs";
|
|
3
3
|
import { issueDrill } from "../drill-seal.mjs";
|
|
4
4
|
import { execute, wire } from "../execute.mjs";
|
|
@@ -67,19 +67,25 @@ function queryEndpoints(rt) {
|
|
|
67
67
|
access: { kind: "signed_in" },
|
|
68
68
|
parse: (input) => parseWith(bodies.queryRecords, input, "QUERY_INVALID"),
|
|
69
69
|
handler: async ({ body, principal, request }) => {
|
|
70
|
-
const
|
|
70
|
+
const names = [...recordDimensions(rt.options.model, body.query.source), ...(body.order ?? []).map(([name]) => name)];
|
|
71
|
+
const columns = [...new Set(names)].map((n, i) => ({
|
|
71
72
|
id: `d${i + 1}`,
|
|
72
73
|
member: `${body.query.source}.${n}`
|
|
73
74
|
}));
|
|
74
|
-
|
|
75
|
+
const read = {
|
|
75
76
|
...body.query,
|
|
76
77
|
dimensions: columns
|
|
77
|
-
}
|
|
78
|
+
};
|
|
79
|
+
const user = userOf(principal);
|
|
80
|
+
checkSensitive(rt.options, user, read);
|
|
81
|
+
await authorizeFree(rt.options, user.viewer, read);
|
|
78
82
|
const x = await freeExecution(rt, principal, request, body.query);
|
|
79
83
|
const after = body.after === void 0 ? {} : { after: body.after };
|
|
84
|
+
const shape = body.order === void 0 ? {} : { shape: { order: body.order } };
|
|
80
85
|
return executeRecords(x, {
|
|
81
86
|
limit: body.limit ?? RECORDS_LIMIT,
|
|
82
|
-
...after
|
|
87
|
+
...after,
|
|
88
|
+
...shape
|
|
83
89
|
});
|
|
84
90
|
}
|
|
85
91
|
}),
|
|
@@ -1,33 +1,43 @@
|
|
|
1
1
|
import { execute } from "../execute.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { listingMeasure } from "../listing.mjs";
|
|
3
3
|
import { calendarOf } from "../request.mjs";
|
|
4
|
-
import { isMark, parseMemberId } from "derive-dashboards/core";
|
|
4
|
+
import { isMark, parseMemberId, shownAsMember } from "derive-dashboards/core";
|
|
5
5
|
// src/endpoints/values.ts
|
|
6
6
|
const DEFAULT_LIMIT = 100;
|
|
7
|
-
/** A query listing a member's distinct values in code-point order, narrowed by a search. */
|
|
8
|
-
function valuesQuery(x,
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
7
|
+
/** A query listing a member's distinct values in code-point order (by name, for one shown as another), narrowed by a search. */
|
|
8
|
+
function valuesQuery(x, a, limit) {
|
|
9
|
+
const { model } = x.rt.options;
|
|
10
|
+
const { member, search } = a;
|
|
11
|
+
const source = parseMemberId(member)?.source ?? "";
|
|
12
|
+
const shown = shownAsMember(model, source, member);
|
|
13
|
+
const filters = [...search === void 0 || search === "" ? [] : [{
|
|
14
|
+
member: shown ?? member,
|
|
15
|
+
op: "contains",
|
|
16
|
+
values: [search]
|
|
17
|
+
}], ...a.keys === void 0 ? [] : [{
|
|
18
|
+
member,
|
|
19
|
+
op: "in",
|
|
20
|
+
values: [...a.keys]
|
|
21
|
+
}]];
|
|
14
22
|
return {
|
|
15
23
|
kind: "aggregate",
|
|
16
|
-
source
|
|
24
|
+
source,
|
|
17
25
|
measures: [{
|
|
18
26
|
id: "m1",
|
|
19
|
-
measure:
|
|
27
|
+
measure: listingMeasure(model, member)
|
|
20
28
|
}],
|
|
21
29
|
dimensions: [{
|
|
22
30
|
id: "d1",
|
|
23
31
|
member
|
|
24
|
-
}]
|
|
25
|
-
|
|
26
|
-
member
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
}, ...shown === void 0 ? [] : [{
|
|
33
|
+
id: "d2",
|
|
34
|
+
member: shown
|
|
35
|
+
}]],
|
|
36
|
+
...filters.length === 0 ? {} : { filters: { all: filters } },
|
|
37
|
+
order: [...shown === void 0 ? [] : [{
|
|
38
|
+
by: "d2",
|
|
39
|
+
dir: "asc"
|
|
40
|
+
}], {
|
|
31
41
|
by: "d1",
|
|
32
42
|
dir: "asc"
|
|
33
43
|
}],
|
|
@@ -40,19 +50,23 @@ function valuesQuery(x, member, search, limit) {
|
|
|
40
50
|
*/
|
|
41
51
|
async function memberValues(x, a) {
|
|
42
52
|
const limit = a.limit ?? DEFAULT_LIMIT;
|
|
43
|
-
const query = valuesQuery(x, a
|
|
44
|
-
const
|
|
53
|
+
const query = valuesQuery(x, a, limit);
|
|
54
|
+
const answer = await execute({
|
|
45
55
|
...x,
|
|
46
56
|
query,
|
|
47
57
|
calendar: calendarOf(x.rt.options)
|
|
48
|
-
})
|
|
58
|
+
});
|
|
59
|
+
const rows = answer.rows.flatMap((row) => {
|
|
49
60
|
const cell = row[0] ?? null;
|
|
50
61
|
if (cell === null || typeof cell !== "object") return [cell];
|
|
51
62
|
return isMark(cell) ? [] : [cell.v];
|
|
52
63
|
});
|
|
64
|
+
const page = [...new Set(rows.slice(0, limit))];
|
|
65
|
+
const labels = answer.columns[0]?.labels;
|
|
53
66
|
return {
|
|
54
|
-
values:
|
|
55
|
-
more:
|
|
67
|
+
values: page,
|
|
68
|
+
more: rows.length > limit,
|
|
69
|
+
...labels === void 0 ? {} : { labels }
|
|
56
70
|
};
|
|
57
71
|
}
|
|
58
72
|
export { memberValues };
|
package/dist/execute.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { checkSensitive } from "./authorize.mjs";
|
|
|
2
2
|
import { manifest } from "./cache.mjs";
|
|
3
3
|
import { macHex } from "./cursor-seal.mjs";
|
|
4
4
|
import { adapterFor } from "./dashboards.mjs";
|
|
5
|
+
import { labelColumns } from "./labels.mjs";
|
|
5
6
|
import { withReader } from "./reading.mjs";
|
|
6
7
|
import { logQuery } from "./store/log.mjs";
|
|
7
8
|
import { answerStatus, bindQueryViewer, bindViewer, canonical, formatTextTime, isBound, markedRows, markedWhole, requestInstant, resultColumns, unreadWarnings, withTime } from "derive-dashboards/core";
|
|
@@ -144,10 +145,30 @@ async function compute(x, bound) {
|
|
|
144
145
|
* request (same bound query, policies, calendar and source epochs) is answered from it.
|
|
145
146
|
*/
|
|
146
147
|
async function execute(x) {
|
|
147
|
-
const answer = await answered(x);
|
|
148
|
+
const answer = await labelled(x, await answered(x));
|
|
148
149
|
record(x, answer);
|
|
149
150
|
return answer;
|
|
150
151
|
}
|
|
152
|
+
/** The answer with the labels of each dimension column shown as another, read under the same viewer and lock. */
|
|
153
|
+
async function labelled(x, answer) {
|
|
154
|
+
const sets = [
|
|
155
|
+
answer.rows,
|
|
156
|
+
answer.compare?.rows,
|
|
157
|
+
answer.whole?.rows
|
|
158
|
+
];
|
|
159
|
+
const columns = await labelColumns(x.rt.options.model, {
|
|
160
|
+
query: x.query,
|
|
161
|
+
columns: answer.columns,
|
|
162
|
+
sets
|
|
163
|
+
}, (query) => answered({
|
|
164
|
+
...x,
|
|
165
|
+
query
|
|
166
|
+
}));
|
|
167
|
+
return {
|
|
168
|
+
...answer,
|
|
169
|
+
columns
|
|
170
|
+
};
|
|
171
|
+
}
|
|
151
172
|
/** With `queryLog`, one row per answer, written where the host runs background work; never fails a request. */
|
|
152
173
|
function record(x, answer) {
|
|
153
174
|
const { options } = x.rt;
|