derive-dashboards 0.6.0 → 0.7.0
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/dist/charts/kinds/area-marks.mjs +2 -1
- package/dist/charts/kinds/funnel-words.mjs +1 -1
- package/dist/charts/kinds/grid-marks.mjs +9 -4
- package/dist/charts/theme.d.mts +13 -13
- package/dist/charts/theme.mjs +17 -14
- package/dist/charts-react/Overlay.mjs +1 -0
- package/dist/charts-react/chart-unlayered.css +1 -107
- package/dist/charts-react/chart.css +1 -121
- package/dist/charts-react/tip-place.mjs +30 -15
- package/dist/core/document/display-comparisons.mjs +49 -0
- package/dist/core/document/display-validation.d.mts +12 -0
- package/dist/core/document/display-validation.mjs +56 -0
- package/dist/core/document/display.d.mts +6 -12
- package/dist/core/document/display.mjs +23 -48
- package/dist/core/engine/dialect.d.mts +2 -0
- package/dist/core/engine/index.mjs +1 -1
- package/dist/core/engine/levels.mjs +33 -1
- package/dist/core/engine/postgres.mjs +1 -0
- package/dist/core/engine/rank.mjs +1 -1
- package/dist/core/engine/reader.d.mts +4 -0
- package/dist/core/engine/sql-partition.mjs +45 -0
- package/dist/core/engine/sql-reads.mjs +4 -1
- package/dist/core/engine/statement.mjs +4 -4
- package/dist/core/engine/version.d.mts +1 -1
- package/dist/core/engine/version.mjs +1 -1
- package/dist/core/error/codes.d.mts +1 -1
- package/dist/core/error/codes.mjs +1 -1
- package/dist/core/index.d.mts +6 -5
- package/dist/core/index.mjs +8 -7
- package/dist/core/model/validate/fields.mjs +1 -1
- package/dist/core/query/drill/compose.d.mts +2 -0
- package/dist/core/query/drill/compose.mjs +1 -1
- package/dist/core/query/drill/synthetic.mjs +1 -1
- package/dist/core/query/drill/types.d.mts +7 -0
- package/dist/core/query/drill/types.mjs +3 -1
- package/dist/core/schema/answers.d.mts +1176 -362
- package/dist/core/schema/drill-answers.mjs +19 -1
- package/dist/core/schema/drill.d.mts +21 -6
- package/dist/core/schema/drill.mjs +7 -1
- package/dist/core/schema/tools.mjs +13 -0
- package/dist/core/time/index.d.mts +2 -2
- package/dist/core/time/text-time.d.mts +9 -2
- package/dist/core/time/text-time.mjs +18 -3
- package/dist/core/types/api.d.mts +1 -1
- package/dist/core/types/api.mjs +1 -1
- package/dist/core/types/drill-api.d.mts +22 -2
- package/dist/dashboard-documents.d.mts +8 -0
- package/dist/dashboard-documents.mjs +52 -0
- package/dist/drill-access.mjs +40 -3
- package/dist/drill-comparison.mjs +71 -0
- package/dist/drill-crumbs.mjs +21 -2
- package/dist/drill-group-seal.mjs +13 -0
- package/dist/drill-open.mjs +7 -1
- package/dist/drill-seal.mjs +4 -6
- package/dist/drill-views.mjs +5 -13
- package/dist/drill.mjs +28 -58
- package/dist/editing.mjs +1 -1
- package/dist/endpoints/drill.mjs +2 -3
- package/dist/endpoints/index.d.mts +20 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +6 -27
- package/dist/llms.txt +1 -1
- package/dist/react/Cell.mjs +2 -2
- package/dist/react/DashboardList.mjs +3 -3
- package/dist/react/Editing.mjs +3 -3
- package/dist/react/Header.mjs +2 -2
- package/dist/react/History.mjs +3 -3
- package/dist/react/Parts.mjs +2 -2
- package/dist/react/RowBody.d.mts +2 -4
- package/dist/react/RowBody.mjs +14 -39
- package/dist/react/Tile.mjs +4 -5
- package/dist/react/builder/FilterEditor.mjs +2 -2
- package/dist/react/builder/Picker.mjs +3 -3
- package/dist/react/builder/RangeEditor.mjs +3 -3
- package/dist/react/builder/Time.mjs +3 -3
- package/dist/react/builder/Values.mjs +2 -2
- package/dist/react/builder/WidgetBuilder.mjs +2 -2
- package/dist/react/drill/Bars.mjs +34 -38
- package/dist/react/drill/Comparison.mjs +204 -0
- package/dist/react/drill/Controls.mjs +8 -12
- package/dist/react/drill/DrillDrawer.mjs +42 -0
- package/dist/react/drill/DrillPanel.mjs +61 -41
- package/dist/react/drill/Header.mjs +65 -35
- package/dist/react/drill/ItemLink.mjs +40 -0
- package/dist/react/drill/Items.d.mts +2 -1
- package/dist/react/drill/Items.mjs +126 -99
- package/dist/react/drill/ItemsBody.mjs +38 -0
- package/dist/react/drill/ItemsFoot.mjs +24 -19
- package/dist/react/drill/Notes.mjs +23 -13
- package/dist/react/drill/PanelBody.mjs +7 -25
- package/dist/react/drill/RecordRow.mjs +47 -0
- package/dist/react/drill/Trend.mjs +186 -0
- package/dist/react/drill/board.mjs +21 -11
- package/dist/react/drill/drawer-context.mjs +5 -0
- package/dist/react/drill/item-parts.mjs +53 -35
- package/dist/react/drill/item-type.d.mts +2 -2
- package/dist/react/drill/lazy.d.mts +1 -4
- package/dist/react/drill/lazy.mjs +29 -11
- package/dist/react/drill/panel-focus.mjs +18 -7
- package/dist/react/drill/props.d.mts +7 -1
- package/dist/react/drill/props.mjs +39 -8
- package/dist/react/drill/record-page.mjs +61 -0
- package/dist/react/drill/state.mjs +17 -2
- package/dist/react/drill/trend-touch.mjs +33 -0
- package/dist/react/drill/useDrill.d.mts +3 -3
- package/dist/react/drill/useDrill.mjs +35 -15
- package/dist/react/drill/words.d.mts +14 -0
- package/dist/react/drill/words.mjs +19 -7
- package/dist/react/english.d.mts +1 -0
- package/dist/react/english.mjs +1 -0
- package/dist/react/filters/chip.mjs +2 -2
- package/dist/react/filters/menu-search.mjs +5 -5
- package/dist/react/filters/menu.mjs +2 -2
- package/dist/react/filters/number.mjs +2 -2
- package/dist/react/filters/operator.mjs +2 -2
- package/dist/react/filters/phone.mjs +2 -2
- package/dist/react/filters/values.mjs +4 -4
- package/dist/react/format-time.d.mts +1 -0
- package/dist/react/format-time.mjs +39 -33
- package/dist/react/format.mjs +10 -1
- package/dist/react/renderers/list.mjs +8 -10
- package/dist/react/renderers/table-cells.mjs +38 -9
- package/dist/react/renderers/table-measure.mjs +2 -0
- package/dist/react/renderers/table-row.mjs +64 -7
- package/dist/react/renderers/table-sort.mjs +2 -8
- package/dist/react/renderers/table.mjs +16 -15
- package/dist/react/theme-unlayered.css +1 -3148
- package/dist/react/theme.css +1 -3150
- package/dist/recharts/parts.mjs +1 -1
- package/dist/skills/derive-dashboards/SKILL.md +4 -2
- package/dist/store/apply.mjs +2 -2
- package/dist/store/editor.mjs +2 -2
- package/dist/store/writer.mjs +2 -2
- package/package.json +1 -1
|
@@ -80,6 +80,7 @@ const grouped = z.looseObject({
|
|
|
80
80
|
grain: grain.exactOptional(),
|
|
81
81
|
range: range.exactOptional(),
|
|
82
82
|
grains: z.array(grain).exactOptional(),
|
|
83
|
+
throughNow: z.boolean().exactOptional(),
|
|
83
84
|
rankedBy: z.string().exactOptional(),
|
|
84
85
|
change: z.literal(true).exactOptional(),
|
|
85
86
|
searchable: z.literal(true).exactOptional(),
|
|
@@ -165,6 +166,12 @@ const crumbPart = z.looseObject({
|
|
|
165
166
|
previous: z.literal(true).exactOptional()
|
|
166
167
|
});
|
|
167
168
|
const crumb = crumbPart.extend({ parts: z.array(crumbPart).exactOptional() });
|
|
169
|
+
const comparison = z.looseObject({
|
|
170
|
+
by: z.literal("comparison"),
|
|
171
|
+
drill: sealedAnswer,
|
|
172
|
+
thenBy: field.exactOptional(),
|
|
173
|
+
omitted: z.literal(true).exactOptional()
|
|
174
|
+
});
|
|
168
175
|
/** A drill's answer: its summary, breadcrumbs, normalized state and view. */
|
|
169
176
|
const drillAnswerSchema = z.looseObject({
|
|
170
177
|
summary: summary.exactOptional(),
|
|
@@ -173,7 +180,18 @@ const drillAnswerSchema = z.looseObject({
|
|
|
173
180
|
view: z.union([
|
|
174
181
|
grouped,
|
|
175
182
|
items,
|
|
176
|
-
explanation
|
|
183
|
+
explanation,
|
|
184
|
+
comparison.extend({
|
|
185
|
+
foreign: z.never().exactOptional(),
|
|
186
|
+
answer: grouped.shape.answer
|
|
187
|
+
}),
|
|
188
|
+
comparison.extend({
|
|
189
|
+
foreign: z.literal(true),
|
|
190
|
+
answer: grouped.shape.answer.extend({ receipt: receipt.extend({
|
|
191
|
+
queryHash: z.never().exactOptional(),
|
|
192
|
+
filter: z.never().exactOptional()
|
|
193
|
+
}) })
|
|
194
|
+
})
|
|
177
195
|
])
|
|
178
196
|
});
|
|
179
197
|
export { drillAnswerSchema, queryDrill };
|
|
@@ -3,10 +3,14 @@ import { FormulaNode } from "../query/types.mjs";
|
|
|
3
3
|
import "../index.mjs";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
/** What a drill shows. */
|
|
6
|
-
export declare const drillViewSchema: z.
|
|
6
|
+
export declare const drillViewSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
7
7
|
by: z.ZodLiteral<"breakdown">;
|
|
8
8
|
member: z.ZodExactOptional<z.ZodString>;
|
|
9
9
|
search: z.ZodExactOptional<z.ZodString>;
|
|
10
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
11
|
+
by: z.ZodLiteral<"comparison">;
|
|
12
|
+
member: z.ZodString;
|
|
13
|
+
thenBy: z.ZodExactOptional<z.ZodString>;
|
|
10
14
|
}, z.core.$strict>, z.ZodObject<{
|
|
11
15
|
by: z.ZodLiteral<"trend">;
|
|
12
16
|
grain: z.ZodExactOptional<z.ZodEnum<{
|
|
@@ -19,10 +23,11 @@ export declare const drillViewSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
19
23
|
}>>;
|
|
20
24
|
}, z.core.$strict>, z.ZodObject<{
|
|
21
25
|
by: z.ZodLiteral<"items">;
|
|
26
|
+
fields: z.ZodExactOptional<z.ZodLiteral<true>>;
|
|
22
27
|
numerator: z.ZodExactOptional<z.ZodLiteral<true>>;
|
|
23
28
|
}, z.core.$strict>, z.ZodObject<{
|
|
24
29
|
by: z.ZodLiteral<"explanation">;
|
|
25
|
-
}, z.core.$strict>]>;
|
|
30
|
+
}, z.core.$strict>], "by">;
|
|
26
31
|
/** A drill as plain data: its origin, line, sealed execution and path, and the view open. */
|
|
27
32
|
export declare const drillStateSchema: z.ZodObject<{
|
|
28
33
|
origin: z.ZodUnion<readonly [z.ZodObject<{
|
|
@@ -153,10 +158,14 @@ export declare const drillStateSchema: z.ZodObject<{
|
|
|
153
158
|
entry: z.ZodExactOptional<z.ZodString>;
|
|
154
159
|
execution: z.ZodString;
|
|
155
160
|
path: z.ZodReadonly<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodString]>>>;
|
|
156
|
-
view: z.
|
|
161
|
+
view: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
157
162
|
by: z.ZodLiteral<"breakdown">;
|
|
158
163
|
member: z.ZodExactOptional<z.ZodString>;
|
|
159
164
|
search: z.ZodExactOptional<z.ZodString>;
|
|
165
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
166
|
+
by: z.ZodLiteral<"comparison">;
|
|
167
|
+
member: z.ZodString;
|
|
168
|
+
thenBy: z.ZodExactOptional<z.ZodString>;
|
|
160
169
|
}, z.core.$strict>, z.ZodObject<{
|
|
161
170
|
by: z.ZodLiteral<"trend">;
|
|
162
171
|
grain: z.ZodExactOptional<z.ZodEnum<{
|
|
@@ -169,14 +178,19 @@ export declare const drillStateSchema: z.ZodObject<{
|
|
|
169
178
|
}>>;
|
|
170
179
|
}, z.core.$strict>, z.ZodObject<{
|
|
171
180
|
by: z.ZodLiteral<"items">;
|
|
181
|
+
fields: z.ZodExactOptional<z.ZodLiteral<true>>;
|
|
172
182
|
numerator: z.ZodExactOptional<z.ZodLiteral<true>>;
|
|
173
183
|
}, z.core.$strict>, z.ZodObject<{
|
|
174
184
|
by: z.ZodLiteral<"explanation">;
|
|
175
|
-
}, z.core.$strict>]>;
|
|
176
|
-
views: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.
|
|
185
|
+
}, z.core.$strict>], "by">;
|
|
186
|
+
views: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
177
187
|
by: z.ZodLiteral<"breakdown">;
|
|
178
188
|
member: z.ZodExactOptional<z.ZodString>;
|
|
179
189
|
search: z.ZodExactOptional<z.ZodString>;
|
|
190
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
191
|
+
by: z.ZodLiteral<"comparison">;
|
|
192
|
+
member: z.ZodString;
|
|
193
|
+
thenBy: z.ZodExactOptional<z.ZodString>;
|
|
180
194
|
}, z.core.$strict>, z.ZodObject<{
|
|
181
195
|
by: z.ZodLiteral<"trend">;
|
|
182
196
|
grain: z.ZodExactOptional<z.ZodEnum<{
|
|
@@ -189,10 +203,11 @@ export declare const drillStateSchema: z.ZodObject<{
|
|
|
189
203
|
}>>;
|
|
190
204
|
}, z.core.$strict>, z.ZodObject<{
|
|
191
205
|
by: z.ZodLiteral<"items">;
|
|
206
|
+
fields: z.ZodExactOptional<z.ZodLiteral<true>>;
|
|
192
207
|
numerator: z.ZodExactOptional<z.ZodLiteral<true>>;
|
|
193
208
|
}, z.core.$strict>, z.ZodObject<{
|
|
194
209
|
by: z.ZodLiteral<"explanation">;
|
|
195
|
-
}, z.core.$strict>]>>>>;
|
|
210
|
+
}, z.core.$strict>], "by">>>>;
|
|
196
211
|
}, z.core.$strict>;
|
|
197
212
|
/** What a sealed selection opens to, checked again after it opens. */
|
|
198
213
|
export declare const selectionSchema: z.ZodObject<{
|
|
@@ -4,18 +4,24 @@ import { grain, name, primitive, wireQuerySchema } from "./query.mjs";
|
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
// src/schema/drill.ts
|
|
6
6
|
/** What a drill shows. */
|
|
7
|
-
const drillViewSchema = z.
|
|
7
|
+
const drillViewSchema = z.discriminatedUnion("by", [
|
|
8
8
|
z.strictObject({
|
|
9
9
|
by: z.literal("breakdown"),
|
|
10
10
|
member: name.exactOptional(),
|
|
11
11
|
search: z.string().max(200).exactOptional()
|
|
12
12
|
}),
|
|
13
|
+
z.strictObject({
|
|
14
|
+
by: z.literal("comparison"),
|
|
15
|
+
member: name,
|
|
16
|
+
thenBy: name.exactOptional()
|
|
17
|
+
}),
|
|
13
18
|
z.strictObject({
|
|
14
19
|
by: z.literal("trend"),
|
|
15
20
|
grain: grain.exactOptional()
|
|
16
21
|
}),
|
|
17
22
|
z.strictObject({
|
|
18
23
|
by: z.literal("items"),
|
|
24
|
+
fields: z.literal(true).exactOptional(),
|
|
19
25
|
numerator: z.literal(true).exactOptional()
|
|
20
26
|
}),
|
|
21
27
|
z.strictObject({ by: z.literal("explanation") })
|
|
@@ -27,6 +27,19 @@ const OPTION_TYPES = {
|
|
|
27
27
|
type: "array",
|
|
28
28
|
items: { type: "string" }
|
|
29
29
|
},
|
|
30
|
+
comparisons: {
|
|
31
|
+
type: "object",
|
|
32
|
+
additionalProperties: {
|
|
33
|
+
type: "array",
|
|
34
|
+
minItems: 1,
|
|
35
|
+
maxItems: 2,
|
|
36
|
+
uniqueItems: true,
|
|
37
|
+
items: {
|
|
38
|
+
type: "string",
|
|
39
|
+
pattern: "\\S"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
30
43
|
colors: {
|
|
31
44
|
type: "object",
|
|
32
45
|
additionalProperties: { type: "string" }
|
|
@@ -3,6 +3,6 @@ import { comparisonQuery, comparisonSpan, shiftInstant } from "./compare.mjs";
|
|
|
3
3
|
import { MICROS_PER_DAY, MICROS_PER_HOUR, MICROS_PER_SECOND, Micros, formatTextTime, parseDate, parseNaiveTime } from "./instant.mjs";
|
|
4
4
|
import { Span, inSpan, resolveRange } from "./range.mjs";
|
|
5
5
|
import { Moment, isZone, momentMicros } from "./temporal.mjs";
|
|
6
|
-
import { parseTextTime } from "./text-time.mjs";
|
|
6
|
+
import { lastIncludedMillisecond, parseTextTime } from "./text-time.mjs";
|
|
7
7
|
import { NaiveRule, OffsetSegment, offsetSegments, resolveNaive, startOfDate } from "./zone.mjs";
|
|
8
|
-
export { MICROS_PER_DAY, MICROS_PER_HOUR, MICROS_PER_SECOND, type Micros, type Moment, type NaiveRule, type OffsetSegment, type Span, bucketLabel, bucketLabels, bucketStart, comparisonQuery, comparisonSpan, formatTextTime, inSpan, isZone, momentMicros, nextBucketStart, offsetSegments, parseDate, parseNaiveTime, parseTextTime, resolveNaive, resolveRange, shiftBucket, shiftInstant, startOfDate };
|
|
8
|
+
export { MICROS_PER_DAY, MICROS_PER_HOUR, MICROS_PER_SECOND, type Micros, type Moment, type NaiveRule, type OffsetSegment, type Span, bucketLabel, bucketLabels, bucketStart, comparisonQuery, comparisonSpan, formatTextTime, inSpan, isZone, lastIncludedMillisecond, momentMicros, nextBucketStart, offsetSegments, parseDate, parseNaiveTime, parseTextTime, resolveNaive, resolveRange, shiftBucket, shiftInstant, startOfDate };
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { Micros } from "./instant.mjs";
|
|
2
|
-
/**
|
|
3
|
-
export declare function parseTextTime(text: string): Micros | undefined;
|
|
2
|
+
/** A text instant at the engine's numeric precision. */
|
|
3
|
+
export declare function parseTextTime(text: string): Micros | undefined;
|
|
4
|
+
/** The last millisecond containing an included instant, for Intl to format in the viewer's zone.
|
|
5
|
+
* The bounds are already resolved instants. No day arithmetic is involved, even across DST.
|
|
6
|
+
*/
|
|
7
|
+
export declare function lastIncludedMillisecond(range: {
|
|
8
|
+
from: string;
|
|
9
|
+
to: string;
|
|
10
|
+
}): number | undefined;
|
|
@@ -52,7 +52,7 @@ function dayStart(year, month, date) {
|
|
|
52
52
|
return date >= 1 && date <= daysIn(year, month) ? daysFromEpoch(year, month, date) * 864e5 : void 0;
|
|
53
53
|
}
|
|
54
54
|
/** The instant a text time names, or undefined when it does not fit the grammar exactly. */
|
|
55
|
-
function
|
|
55
|
+
function exactMicros(text) {
|
|
56
56
|
const match = matchTime(text, true);
|
|
57
57
|
if (match === void 0) return void 0;
|
|
58
58
|
const n = (i) => Number(match[i] ?? "0");
|
|
@@ -60,6 +60,21 @@ function parseTextTime(text) {
|
|
|
60
60
|
if (start === void 0) return void 0;
|
|
61
61
|
const offset = (match[8]?.startsWith("-") === true ? -1 : 1) * (n(9) * 60 + n(10));
|
|
62
62
|
const millis = start + ((n(4) * 60 + n(5) - offset) * 60 + n(6)) * 1e3;
|
|
63
|
-
return
|
|
63
|
+
return BigInt(millis) * 1000n + BigInt((match[7] ?? "").padEnd(6, "0"));
|
|
64
|
+
}
|
|
65
|
+
/** A text instant at the engine's numeric precision. */
|
|
66
|
+
function parseTextTime(text) {
|
|
67
|
+
const micros = exactMicros(text);
|
|
68
|
+
return micros === void 0 ? void 0 : Number(micros);
|
|
69
|
+
}
|
|
70
|
+
/** The last millisecond containing an included instant, for Intl to format in the viewer's zone.
|
|
71
|
+
* The bounds are already resolved instants. No day arithmetic is involved, even across DST.
|
|
72
|
+
*/
|
|
73
|
+
function lastIncludedMillisecond(range) {
|
|
74
|
+
const from = exactMicros(range.from);
|
|
75
|
+
const until = exactMicros(range.to);
|
|
76
|
+
if (from === void 0 || until === void 0 || from >= until) return void 0;
|
|
77
|
+
const last = until - 1n;
|
|
78
|
+
return Number(last / 1000n) - Number(last % 1000n < 0n);
|
|
64
79
|
}
|
|
65
|
-
export { matchTime, parseTextTime };
|
|
80
|
+
export { lastIncludedMillisecond, matchTime, parseTextTime };
|
|
@@ -344,4 +344,4 @@ export type CoreContract = {
|
|
|
344
344
|
* than reading a shape it does not know. A test recomputes it from the answer schemas, so a
|
|
345
345
|
* change to an answer fails until this is updated.
|
|
346
346
|
*/
|
|
347
|
-
export declare const CONTRACT_VERSION = "
|
|
347
|
+
export declare const CONTRACT_VERSION = "87905292cf669d4a";
|
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 = "87905292cf669d4a";
|
|
9
9
|
export { CONTRACT_VERSION };
|
|
@@ -132,6 +132,8 @@ export type DrillGroupedView = {
|
|
|
132
132
|
/** Over time: the range it draws, and the grains it may be drawn at. */
|
|
133
133
|
range?: ResolvedRange;
|
|
134
134
|
grains?: Grain[];
|
|
135
|
+
/** A rolling trend ends at the reporting cutoff, which can precede the receipt's timestamp. */
|
|
136
|
+
throughNow?: boolean;
|
|
135
137
|
/** A Breakdown of the change: each group now (the line), before (`c1`) and its change (`c2`). */
|
|
136
138
|
change?: true;
|
|
137
139
|
/** The field has more values than a Breakdown draws: a search narrows them. */
|
|
@@ -140,6 +142,24 @@ export type DrillGroupedView = {
|
|
|
140
142
|
/** A Breakdown of a line that does not add up ranks its groups by their rows (`m<n>`). */
|
|
141
143
|
rankedBy?: string;
|
|
142
144
|
};
|
|
145
|
+
/** The tile's measures grouped together within a sealed selection. */
|
|
146
|
+
export type DrillComparisonView = {
|
|
147
|
+
by: "comparison";
|
|
148
|
+
drill: SealedAnswer;
|
|
149
|
+
thenBy?: DrillField;
|
|
150
|
+
omitted?: true;
|
|
151
|
+
} & ({
|
|
152
|
+
foreign?: never;
|
|
153
|
+
answer: Result & {
|
|
154
|
+
unreadable?: true;
|
|
155
|
+
};
|
|
156
|
+
} | {
|
|
157
|
+
foreign: true;
|
|
158
|
+
answer: Omit<Result, "receipt"> & {
|
|
159
|
+
receipt: Omit<Receipt, "queryHash" | "filter">;
|
|
160
|
+
unreadable?: true;
|
|
161
|
+
};
|
|
162
|
+
});
|
|
143
163
|
/** A record column as Items show it: with its number format when the model gives one. */
|
|
144
164
|
export type ItemColumn = RecordColumn & {
|
|
145
165
|
format?: NumberFormat;
|
|
@@ -202,9 +222,9 @@ export type DrillExplanationView = {
|
|
|
202
222
|
};
|
|
203
223
|
/** A drill's answer: its summary, its path as breadcrumbs, its state normalized, and its view. */
|
|
204
224
|
export type DrillAnswer = {
|
|
205
|
-
/** Absent when the request said it already has it (`summary: false`). */
|
|
225
|
+
/** Absent for a group comparison or when the request said it already has it (`summary: false`). */
|
|
206
226
|
summary?: DrillSummary;
|
|
207
227
|
path: DrillCrumb[];
|
|
208
228
|
state: DrillState;
|
|
209
|
-
view: DrillGroupedView | DrillItemsView | DrillExplanationView;
|
|
229
|
+
view: DrillGroupedView | DrillComparisonView | DrillItemsView | DrillExplanationView;
|
|
210
230
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DashOptions, Issue } from "derive-dashboards/core";
|
|
2
|
+
/** A host configuration error raised before the server handles any request. */
|
|
3
|
+
export declare class DashboardDocumentError extends Error {
|
|
4
|
+
readonly dashboardKey: string;
|
|
5
|
+
readonly issues: readonly Issue[];
|
|
6
|
+
readonly code = "DOCUMENT_INVALID";
|
|
7
|
+
constructor(dashboardKey: string, reason: string, issues: readonly Issue[]);
|
|
8
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { displayOf, documentDisplayIssues, resolveDimension } from "derive-dashboards/core";
|
|
2
|
+
import { loadDocument } from "derive-dashboards/core/schema";
|
|
3
|
+
// src/dashboard-documents.ts
|
|
4
|
+
function declaredValues(model, source, member) {
|
|
5
|
+
const dimension = resolveDimension(model, source, member)?.dimension;
|
|
6
|
+
if (dimension?.kind !== "string" || typeof dimension.values === "string") return;
|
|
7
|
+
return dimension.values;
|
|
8
|
+
}
|
|
9
|
+
/** Declared filter choices can catch an authoring typo. Rows may still contain other values. */
|
|
10
|
+
function comparisonKeyHints(doc, model) {
|
|
11
|
+
return Object.entries(doc.widgets).flatMap(([id, widget]) => {
|
|
12
|
+
if (widget.kind !== "table") return [];
|
|
13
|
+
const groups = displayOf("table", widget.display).comparisons;
|
|
14
|
+
const query = widget.queries["main"];
|
|
15
|
+
const member = query?.dimensions?.[0]?.member;
|
|
16
|
+
if (!groups || !query || member === void 0) return [];
|
|
17
|
+
const choices = declaredValues(model, query.source, member);
|
|
18
|
+
if (!choices) return [];
|
|
19
|
+
return Object.keys(groups).filter((key) => !choices.includes(key)).map((key) => `widgets.${id}.display.comparisons: "${key}" is outside the declared choices for "${member}" (${choices.join(", ")}). This action appears only on an exact group value match.`);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/** A host configuration error raised before the server handles any request. */
|
|
23
|
+
var DashboardDocumentError = class extends Error {
|
|
24
|
+
dashboardKey;
|
|
25
|
+
issues;
|
|
26
|
+
code = "DOCUMENT_INVALID";
|
|
27
|
+
constructor(dashboardKey, reason, issues) {
|
|
28
|
+
const problems = issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ");
|
|
29
|
+
super(`The dashboard "${dashboardKey}" ${reason}: ${problems}`);
|
|
30
|
+
this.dashboardKey = dashboardKey;
|
|
31
|
+
this.issues = issues;
|
|
32
|
+
this.name = "DashboardDocumentError";
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Code-defined dashboards are checked when the handler is made, not when a viewer opens one: an
|
|
37
|
+
* invalid document stops the server with every problem named, and a layout is repaired once.
|
|
38
|
+
*/
|
|
39
|
+
function checkedDashboards(options, model) {
|
|
40
|
+
return (options.dashboards ?? []).map((d) => {
|
|
41
|
+
const loaded = loadDocument(d.document);
|
|
42
|
+
if (!loaded.ok) throw new DashboardDocumentError(d.key, "is not a valid document", loaded.issues);
|
|
43
|
+
const wrong = documentDisplayIssues(loaded.doc, model);
|
|
44
|
+
if (wrong.length > 0) throw new DashboardDocumentError(d.key, "has display options to fix", wrong);
|
|
45
|
+
for (const hint of comparisonKeyHints(loaded.doc, model)) console.warn(`Dashboard "${d.key}": ${hint}`);
|
|
46
|
+
return {
|
|
47
|
+
key: d.key,
|
|
48
|
+
document: loaded.doc
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export { DashboardDocumentError, checkedDashboards };
|
package/dist/drill-access.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { execute } from "./execute.mjs";
|
|
2
2
|
import { HttpError } from "./http.mjs";
|
|
3
|
-
import { queryClosure } from "derive-dashboards/core";
|
|
4
|
-
import { drillOwner, stepMembers } from "derive-dashboards/core/engine";
|
|
3
|
+
import { queryClosure, resultColumns } from "derive-dashboards/core";
|
|
4
|
+
import { drillOwner, lineFilter, offeredMembers, pathFields, stepMembers } from "derive-dashboards/core/engine";
|
|
5
5
|
// src/drill-access.ts
|
|
6
6
|
/** Which fields this viewer may see in a drill: never a sensitive one (Rules, section 6). */
|
|
7
7
|
const readableFor = (_x) => (_member, def) => def.sensitive !== true;
|
|
@@ -90,4 +90,41 @@ function mayList(o, source) {
|
|
|
90
90
|
source
|
|
91
91
|
}));
|
|
92
92
|
}
|
|
93
|
-
|
|
93
|
+
/** Label the offered dimensions in the same context as the result columns. */
|
|
94
|
+
function labelledFields(o, kept) {
|
|
95
|
+
const model = o.x.rt.options.model;
|
|
96
|
+
const dimensions = kept.map((member, i) => ({
|
|
97
|
+
id: `d${i + 1}`,
|
|
98
|
+
member
|
|
99
|
+
}));
|
|
100
|
+
const columns = resultColumns(model, {
|
|
101
|
+
...o.x.query,
|
|
102
|
+
dimensions
|
|
103
|
+
});
|
|
104
|
+
return kept.map((id, i) => ({
|
|
105
|
+
id,
|
|
106
|
+
label: columns.find((c) => c.id === `d${i + 1}`)?.label ?? id
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
/** A comparison reads all measures. A single-measure breakdown also excludes fields fixed by that line. */
|
|
110
|
+
function offeredIds(o, set) {
|
|
111
|
+
const model = o.x.rt.options.model;
|
|
112
|
+
const where = set && lineFilter(model, set, o.drill, { operand: false });
|
|
113
|
+
return offeredMembers(model, o.x.query, {
|
|
114
|
+
...pathFields(o.drill.steps),
|
|
115
|
+
where
|
|
116
|
+
}, readableFor(o.x));
|
|
117
|
+
}
|
|
118
|
+
async function readableIds(o, ids) {
|
|
119
|
+
const allowed = await Promise.all(ids.map((id) => mayRead(o, id)));
|
|
120
|
+
return ids.filter((_id, i) => allowed[i] === true);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The fields Breakdown offers this viewer at this step, each labelled as a column of the tile
|
|
124
|
+
* would read it: the model's preferred and small-valued fields the tile, the path and the line's
|
|
125
|
+
* own measure do not fix, the field an Other was cut on first, each one the viewer may read.
|
|
126
|
+
*/
|
|
127
|
+
async function offeredFields(o, set) {
|
|
128
|
+
return labelledFields(o, await readableIds(o, offeredIds(o, set)));
|
|
129
|
+
}
|
|
130
|
+
export { clockOf, drillRead, labelledFields, mayList, mayRead, offeredFields, offeredIds, readableColumns, readableFor, readableIds, running };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { clockOf, drillRead, labelledFields, mayRead, offeredIds, readableFor, readableIds } from "./drill-access.mjs";
|
|
2
|
+
import { crumbs, forOpener, normalizedDrillState } from "./drill-crumbs.mjs";
|
|
3
|
+
import { sealedView } from "./drill-group-seal.mjs";
|
|
4
|
+
import { visibleSelection } from "./drill-open.mjs";
|
|
5
|
+
import { numberOf } from "./drill-totals.mjs";
|
|
6
|
+
import { wire } from "./execute.mjs";
|
|
7
|
+
import { EngineError, breakdownQuery, composeDrill, countQuery } from "derive-dashboards/core/engine";
|
|
8
|
+
// src/drill-comparison.ts
|
|
9
|
+
/** A shared group must contain rows visible to its opener before its name can be shown. */
|
|
10
|
+
function comparisonScope(scope) {
|
|
11
|
+
return visibleSelection(scope, async (o, checkRows) => {
|
|
12
|
+
const set = composeDrill({
|
|
13
|
+
model: o.x.rt.options.model,
|
|
14
|
+
query: o.x.query,
|
|
15
|
+
drill: o.drill,
|
|
16
|
+
comparison: true,
|
|
17
|
+
readable: readableFor(o.x),
|
|
18
|
+
clock: clockOf(o.x)
|
|
19
|
+
});
|
|
20
|
+
const count = checkRows ? await drillRead(o, countQuery(set)) : void 0;
|
|
21
|
+
return {
|
|
22
|
+
value: {
|
|
23
|
+
o,
|
|
24
|
+
set
|
|
25
|
+
},
|
|
26
|
+
empty: (numberOf(count?.rows[0]?.[0]) ?? 0) <= 0
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async function fieldsFor(o, view) {
|
|
31
|
+
const offered = offeredIds(o);
|
|
32
|
+
const check = async (field) => {
|
|
33
|
+
if (offered.includes(field) && await mayRead(o, field)) return;
|
|
34
|
+
const choices = await readableIds(o, offered);
|
|
35
|
+
const hint = choices.length > 0 ? `Available breakdown fields: ${choices.join(", ")}.` : "No breakdown fields are available.";
|
|
36
|
+
throw new EngineError("DRILL_UNSUPPORTED", `Cannot group this selection by "${field}". ${hint}`);
|
|
37
|
+
};
|
|
38
|
+
await check(view.member);
|
|
39
|
+
const id = view.thenBy;
|
|
40
|
+
if (id === void 0) return;
|
|
41
|
+
if (id === view.member) throw new EngineError("DRILL_UNSUPPORTED", "Choose a different field to expand the group.");
|
|
42
|
+
await check(id);
|
|
43
|
+
return labelledFields(o, [id])[0];
|
|
44
|
+
}
|
|
45
|
+
/** Regroup the selected rows. Every measure keeps its own filter and denominator. */
|
|
46
|
+
async function compareGroups(opened, state, requested) {
|
|
47
|
+
const { o, set } = await comparisonScope(opened);
|
|
48
|
+
const thenBy = await fieldsFor(o, requested);
|
|
49
|
+
const view = {
|
|
50
|
+
by: "comparison",
|
|
51
|
+
member: requested.member,
|
|
52
|
+
...thenBy && { thenBy: thenBy.id }
|
|
53
|
+
};
|
|
54
|
+
const query = breakdownQuery(set, view.member, { steps: [] });
|
|
55
|
+
const answer = await drillRead(o, {
|
|
56
|
+
...query,
|
|
57
|
+
total: true
|
|
58
|
+
}, [view.member]);
|
|
59
|
+
return forOpener({
|
|
60
|
+
state: normalizedDrillState(state, o.path, view),
|
|
61
|
+
path: crumbs(o),
|
|
62
|
+
view: {
|
|
63
|
+
by: "comparison",
|
|
64
|
+
answer: wire(answer),
|
|
65
|
+
drill: await sealedView(o, answer, { limited: true }),
|
|
66
|
+
...thenBy && { thenBy },
|
|
67
|
+
...o.omitted && { omitted: true }
|
|
68
|
+
}
|
|
69
|
+
}, o.foreign);
|
|
70
|
+
}
|
|
71
|
+
export { compareGroups };
|
package/dist/drill-crumbs.mjs
CHANGED
|
@@ -108,6 +108,25 @@ function openerReceipts(value) {
|
|
|
108
108
|
* rows and counts are already theirs.
|
|
109
109
|
*/
|
|
110
110
|
function forOpener(answer, foreign) {
|
|
111
|
-
|
|
111
|
+
if (!foreign) return answer;
|
|
112
|
+
const trimmed = openerReceipts(answer);
|
|
113
|
+
return trimmed.view.by === "comparison" ? {
|
|
114
|
+
...trimmed,
|
|
115
|
+
view: {
|
|
116
|
+
...trimmed.view,
|
|
117
|
+
foreign: true
|
|
118
|
+
}
|
|
119
|
+
} : trimmed;
|
|
112
120
|
}
|
|
113
|
-
|
|
121
|
+
/** Keep only the navigation history for the steps this viewer can still open. */
|
|
122
|
+
function normalizedDrillState(state, path, view) {
|
|
123
|
+
const { views, ...rest } = state;
|
|
124
|
+
const kept = views?.slice(0, Math.max(0, path.length - 1));
|
|
125
|
+
return {
|
|
126
|
+
...rest,
|
|
127
|
+
path,
|
|
128
|
+
view,
|
|
129
|
+
...kept !== void 0 && kept.length > 0 && { views: kept }
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export { crumbs, forOpener, normalizedDrillState };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { pathDigest } from "./drill-identity.mjs";
|
|
2
|
+
import { drawnOf, sealAnswer } from "./drill-seal.mjs";
|
|
3
|
+
// src/drill-group-seal.ts
|
|
4
|
+
/** An answer of a view sealed once, under this drill's execution and path. */
|
|
5
|
+
async function sealedView(o, answer, extra) {
|
|
6
|
+
const parent = await pathDigest(o.drill.steps);
|
|
7
|
+
const range = answer.receipt.range;
|
|
8
|
+
return sealAnswer(o.scope, drawnOf(answer, answer.rows, range, extra), {
|
|
9
|
+
exec: o.pinned.id,
|
|
10
|
+
parent
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export { sealedView };
|
package/dist/drill-open.mjs
CHANGED
|
@@ -166,4 +166,10 @@ function cutTo(o, steps) {
|
|
|
166
166
|
omitted: true
|
|
167
167
|
};
|
|
168
168
|
}
|
|
169
|
-
|
|
169
|
+
/** A shared link opens at the deepest selection containing rows visible to its new viewer. */
|
|
170
|
+
async function visibleSelection(scope, read) {
|
|
171
|
+
const checkRows = scope.foreign && scope.selections.length > 0;
|
|
172
|
+
const { value, empty } = await read(scope, checkRows);
|
|
173
|
+
return checkRows && empty ? visibleSelection(cutTo(scope, scope.selections.length - 1), read) : value;
|
|
174
|
+
}
|
|
175
|
+
export { cutTo, openDrill, visibleSelection };
|
package/dist/drill-seal.mjs
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { base64url, seal, unseal } from "./cursor-seal.mjs";
|
|
2
2
|
import { fingerprint, pathDigest, revisionOf } from "./drill-identity.mjs";
|
|
3
3
|
import { warnSecret } from "./drill-secret.mjs";
|
|
4
|
-
import { DRILL_REASONS, parseTextTime } from "derive-dashboards/core";
|
|
4
|
+
import { DRILL_REASONS, MAX_DRILL_ROWS, parseTextTime } from "derive-dashboards/core";
|
|
5
5
|
import { EngineError, rowSelection } from "derive-dashboards/core/engine";
|
|
6
6
|
import { pinnedSchema, selectionSchema } from "derive-dashboards/core/schema";
|
|
7
7
|
// src/drill-seal.ts
|
|
8
|
-
/** An answer drills only when it is small enough to read row by row. */
|
|
9
|
-
const MAX_SELECTIONS = 1e3;
|
|
10
8
|
const bindingOf = (scope, purpose) => ({
|
|
11
9
|
purpose,
|
|
12
10
|
principal: scope.principal,
|
|
@@ -33,7 +31,7 @@ const slim = (c) => ({
|
|
|
33
31
|
/** What a drawn answer's rows open to, and why the others do not. */
|
|
34
32
|
function closedRows(drawn) {
|
|
35
33
|
return drawn.rows.flatMap((row, i) => {
|
|
36
|
-
if (i >=
|
|
34
|
+
if (i >= MAX_DRILL_ROWS) return [];
|
|
37
35
|
const picked = rowSelection(drawn, row);
|
|
38
36
|
return "refused" in picked ? [{
|
|
39
37
|
row: i,
|
|
@@ -48,7 +46,7 @@ async function sealAnswer(scope, drawn, at) {
|
|
|
48
46
|
drawn: {
|
|
49
47
|
...drawn,
|
|
50
48
|
columns: drawn.columns.map((c) => slim(c)),
|
|
51
|
-
rows: drawn.rows.slice(0,
|
|
49
|
+
rows: drawn.rows.slice(0, MAX_DRILL_ROWS)
|
|
52
50
|
},
|
|
53
51
|
...at
|
|
54
52
|
};
|
|
@@ -113,7 +111,7 @@ async function issueDrill(scope, answer, at) {
|
|
|
113
111
|
previous: true
|
|
114
112
|
})
|
|
115
113
|
]);
|
|
116
|
-
const cut = answer.rows.length >
|
|
114
|
+
const cut = answer.rows.length > MAX_DRILL_ROWS;
|
|
117
115
|
return {
|
|
118
116
|
execution,
|
|
119
117
|
...sealed,
|
package/dist/drill-views.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { clockOf, drillRead } from "./drill-access.mjs";
|
|
2
2
|
import { otherChange } from "./drill-change.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import { drawnOf, sealAnswer } from "./drill-seal.mjs";
|
|
3
|
+
import { sealedView } from "./drill-group-seal.mjs";
|
|
5
4
|
import { numberOf } from "./drill-totals.mjs";
|
|
5
|
+
import { compareGroups } from "./drill-comparison.mjs";
|
|
6
6
|
import { isMark, parseTextTime, resolveDimension } from "derive-dashboards/core";
|
|
7
7
|
import { EngineError, breakdownQuery, population, trendQuery } from "derive-dashboards/core/engine";
|
|
8
8
|
// src/drill-views.ts
|
|
@@ -58,15 +58,6 @@ function grainsFor(range) {
|
|
|
58
58
|
["year", 365]
|
|
59
59
|
].filter(([, d]) => days / d >= 2 && days / d <= 400).map(([g]) => g);
|
|
60
60
|
}
|
|
61
|
-
/** An answer of a view sealed once, under this drill's execution and path. */
|
|
62
|
-
async function sealedView(o, answer, extra) {
|
|
63
|
-
const parent = await pathDigest(o.drill.steps);
|
|
64
|
-
const range = answer.receipt.range;
|
|
65
|
-
return sealAnswer(o.scope, drawnOf(answer, answer.rows, range, extra), {
|
|
66
|
-
exec: o.pinned.id,
|
|
67
|
-
parent
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
61
|
/** Over time: the line's population by its time field, at a grain that fits, its range and grains. */
|
|
71
62
|
async function trendView(o, rows, view, offered) {
|
|
72
63
|
const query = trendQuery(o.x.rt.options.model, rows, clockOf(o.x), view.grain);
|
|
@@ -80,7 +71,8 @@ async function trendView(o, rows, view, offered) {
|
|
|
80
71
|
offered,
|
|
81
72
|
...time?.grain === void 0 ? {} : { grain: time.grain },
|
|
82
73
|
...range === void 0 ? {} : { range },
|
|
83
|
-
grains: grainsFor(range)
|
|
74
|
+
grains: grainsFor(range),
|
|
75
|
+
throughNow: time !== void 0 && "last" in time.range && time.range.includeCurrent
|
|
84
76
|
};
|
|
85
77
|
}
|
|
86
78
|
/** A Breakdown or Over time of the line's population, its answer sealed once for its clicks. */
|
|
@@ -172,4 +164,4 @@ async function readBreakdown(o, ask) {
|
|
|
172
164
|
compared: compare !== void 0
|
|
173
165
|
};
|
|
174
166
|
}
|
|
175
|
-
export { chosenView, groupedView };
|
|
167
|
+
export { chosenView, compareGroups, groupedView };
|