@panneau/protocol 5.0.0-alpha.4 → 5.0.0-alpha.41
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/addresses.d.ts +23 -0
- package/dist/addresses.d.ts.map +1 -0
- package/dist/addresses.js +52 -0
- package/dist/addresses.js.map +1 -0
- package/dist/aggregates.d.ts +135 -0
- package/dist/aggregates.d.ts.map +1 -0
- package/dist/aggregates.js +236 -0
- package/dist/aggregates.js.map +1 -0
- package/dist/compound.d.ts +20 -0
- package/dist/compound.d.ts.map +1 -0
- package/dist/compound.js +27 -0
- package/dist/compound.js.map +1 -0
- package/dist/conditions.d.ts +1 -1
- package/dist/conformance/index.d.ts +6 -0
- package/dist/conformance/index.d.ts.map +1 -1
- package/dist/conformance/index.js +970 -11
- package/dist/conformance/index.js.map +1 -1
- package/dist/constants.d.ts +108 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +181 -3
- package/dist/constants.js.map +1 -1
- package/dist/context.d.ts +15 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +34 -0
- package/dist/context.js.map +1 -0
- package/dist/currencies.d.ts +22 -0
- package/dist/currencies.d.ts.map +1 -0
- package/dist/currencies.js +231 -0
- package/dist/currencies.js.map +1 -0
- package/dist/dashboards.d.ts +95 -0
- package/dist/dashboards.d.ts.map +1 -0
- package/dist/dashboards.js +140 -0
- package/dist/dashboards.js.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +22 -8
- package/dist/libraries.d.ts +33 -0
- package/dist/libraries.d.ts.map +1 -0
- package/dist/libraries.js +59 -0
- package/dist/libraries.js.map +1 -0
- package/dist/links.d.ts +38 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +65 -0
- package/dist/links.js.map +1 -0
- package/dist/lint.d.ts +4 -4
- package/dist/lint.d.ts.map +1 -1
- package/dist/lint.js +540 -15
- package/dist/lint.js.map +1 -1
- package/dist/mock/auth.d.ts +71 -0
- package/dist/mock/auth.d.ts.map +1 -0
- package/dist/mock/auth.js +346 -0
- package/dist/mock/auth.js.map +1 -0
- package/dist/mock/example.d.ts +1 -1
- package/dist/mock/example.d.ts.map +1 -1
- package/dist/mock/example.js +49 -28
- package/dist/mock/example.js.map +1 -1
- package/dist/mock/index.d.ts +96 -5
- package/dist/mock/index.d.ts.map +1 -1
- package/dist/mock/index.js +505 -44
- package/dist/mock/index.js.map +1 -1
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +462 -50
- package/dist/openapi.js.map +1 -1
- package/dist/periods.d.ts +61 -0
- package/dist/periods.d.ts.map +1 -0
- package/dist/periods.js +130 -0
- package/dist/periods.js.map +1 -0
- package/dist/problem.d.ts +1 -1
- package/dist/query.d.ts +18 -0
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +34 -8
- package/dist/query.js.map +1 -1
- package/dist/resourceTypes.d.ts +39 -0
- package/dist/resourceTypes.d.ts.map +1 -0
- package/dist/resourceTypes.js +34 -0
- package/dist/resourceTypes.js.map +1 -0
- package/dist/rules.d.ts +18 -5
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +233 -15
- package/dist/rules.js.map +1 -1
- package/dist/runtime/index.d.ts +23 -10
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +16 -3
- package/dist/schemas/action.d.ts +119 -10
- package/dist/schemas/action.d.ts.map +1 -1
- package/dist/schemas/action.js +20 -3
- package/dist/schemas/action.js.map +1 -1
- package/dist/schemas/api.d.ts +266 -5
- package/dist/schemas/api.d.ts.map +1 -1
- package/dist/schemas/api.js +134 -16
- package/dist/schemas/api.js.map +1 -1
- package/dist/schemas/boot.d.ts +25 -1
- package/dist/schemas/boot.d.ts.map +1 -1
- package/dist/schemas/boot.js +2 -1
- package/dist/schemas/boot.js.map +1 -1
- package/dist/schemas/common.d.ts +1 -0
- package/dist/schemas/common.d.ts.map +1 -1
- package/dist/schemas/common.js +2 -1
- package/dist/schemas/common.js.map +1 -1
- package/dist/schemas/definition.d.ts +1414 -30
- package/dist/schemas/definition.d.ts.map +1 -1
- package/dist/schemas/definition.js +77 -17
- package/dist/schemas/definition.js.map +1 -1
- package/dist/schemas/field.d.ts +358 -2
- package/dist/schemas/field.d.ts.map +1 -1
- package/dist/schemas/field.js +161 -20
- package/dist/schemas/field.js.map +1 -1
- package/dist/schemas/index.d.ts +5820 -46
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +69 -7
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/jsonRules.d.ts +83 -0
- package/dist/schemas/jsonRules.d.ts.map +1 -0
- package/dist/schemas/jsonRules.js +46 -0
- package/dist/schemas/jsonRules.js.map +1 -0
- package/dist/schemas/layout.d.ts +2 -1
- package/dist/schemas/layout.d.ts.map +1 -1
- package/dist/schemas/layout.js +2 -1
- package/dist/schemas/layout.js.map +1 -1
- package/dist/schemas/list.d.ts +34 -2
- package/dist/schemas/list.d.ts.map +1 -1
- package/dist/schemas/list.js +21 -6
- package/dist/schemas/list.js.map +1 -1
- package/dist/schemas/resource.d.ts +826 -17
- package/dist/schemas/resource.d.ts.map +1 -1
- package/dist/schemas/resource.js +26 -4
- package/dist/schemas/resource.js.map +1 -1
- package/dist/schemas/theme.d.ts +6 -2
- package/dist/schemas/theme.d.ts.map +1 -1
- package/dist/schemas/theme.js +1 -0
- package/dist/schemas/theme.js.map +1 -1
- package/dist/schemas/widget.d.ts +4379 -0
- package/dist/schemas/widget.d.ts.map +1 -0
- package/dist/schemas/widget.js +269 -0
- package/dist/schemas/widget.js.map +1 -0
- package/dist/search.d.ts +51 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +53 -0
- package/dist/search.js.map +1 -0
- package/dist/themes.d.ts +1 -1
- package/dist/transforms.d.ts +17 -0
- package/dist/transforms.d.ts.map +1 -0
- package/dist/transforms.js +34 -0
- package/dist/transforms.js.map +1 -0
- package/dist/validate.d.ts +5 -3
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +36 -2
- package/dist/validate.js.map +1 -1
- package/dist/values.d.ts +5 -1
- package/dist/values.d.ts.map +1 -1
- package/dist/values.js +16 -2
- package/dist/values.js.map +1 -1
- package/dist/widgets.d.ts +232 -0
- package/dist/widgets.d.ts.map +1 -0
- package/dist/widgets.js +630 -0
- package/dist/widgets.js.map +1 -0
- package/package.json +6 -3
- package/schema/boot.schema.json +1461 -104
- package/schema/definition.schema.json +1459 -105
- package/schema/openapi.json +7176 -2000
package/dist/widgets.js
ADDED
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
import { isCurrencyCode } from "./currencies.js";
|
|
2
|
+
import { isRecord } from "./values.js";
|
|
3
|
+
import { fromSearchParams } from "./query.js";
|
|
4
|
+
//#region src/widgets.ts
|
|
5
|
+
/**
|
|
6
|
+
* The widget types that every client draws (decisions 0064 and 0084). Other types are widgets of
|
|
7
|
+
* plugins.
|
|
8
|
+
*/
|
|
9
|
+
var BUILT_IN_WIDGET_TYPES = [
|
|
10
|
+
"stat",
|
|
11
|
+
"series",
|
|
12
|
+
"list",
|
|
13
|
+
"breakdown",
|
|
14
|
+
"metric",
|
|
15
|
+
"table"
|
|
16
|
+
];
|
|
17
|
+
/** The periods of the points of a `series` widget. */
|
|
18
|
+
var WIDGET_SERIES_PERIODS = [
|
|
19
|
+
"day",
|
|
20
|
+
"week",
|
|
21
|
+
"month"
|
|
22
|
+
];
|
|
23
|
+
/** The most items a `list` widget shows: the backend sends the most useful first. */
|
|
24
|
+
var WIDGET_LIST_MAX_ITEMS = 5;
|
|
25
|
+
/** The most items of a `breakdown` widget: the rest is its `other`. */
|
|
26
|
+
var WIDGET_BREAKDOWN_MAX_ITEMS = 10;
|
|
27
|
+
/** The parts of a `metric` that clients draw as bars: the rest goes in "Other" (decision 0089). */
|
|
28
|
+
var WIDGET_METRIC_MAX_PARTS = 5;
|
|
29
|
+
/** The most lines of a `series` (decision 0089): 5 values of a field, and the rest. */
|
|
30
|
+
var WIDGET_SERIES_MAX_SERIES = 6;
|
|
31
|
+
/**
|
|
32
|
+
* The most lines a `series` on resources reads (decision 0089): its `sources`, or the values of
|
|
33
|
+
* its `split`, past which the rest is one line, "Other".
|
|
34
|
+
*/
|
|
35
|
+
var WIDGET_SOURCES_MAX = 5;
|
|
36
|
+
/** The most rows of a `table` widget, and of its `rows` on resources (decision 0089). */
|
|
37
|
+
var WIDGET_TABLE_MAX_ROWS = 8;
|
|
38
|
+
/** The most columns of numbers of a `table` widget, after the column of the labels. */
|
|
39
|
+
var WIDGET_TABLE_MAX_COLUMNS = 6;
|
|
40
|
+
/** How the columns of a `table` align their numbers: `end` by default. */
|
|
41
|
+
var WIDGET_TABLE_ALIGNS = ["start", "end"];
|
|
42
|
+
/** Whether a rise or a fall of a `metric` or a `table` is good news (`settings.goodWhen`). */
|
|
43
|
+
var WIDGET_GOOD_WHEN = ["up", "down"];
|
|
44
|
+
/** The options of `Intl.NumberFormat` that a widget's `format` takes (decision 0089). */
|
|
45
|
+
var WIDGET_FORMAT_STYLES = [
|
|
46
|
+
"decimal",
|
|
47
|
+
"percent",
|
|
48
|
+
"currency",
|
|
49
|
+
"unit"
|
|
50
|
+
];
|
|
51
|
+
var WIDGET_FORMAT_CURRENCY_DISPLAYS = [
|
|
52
|
+
"symbol",
|
|
53
|
+
"narrowSymbol",
|
|
54
|
+
"code",
|
|
55
|
+
"name"
|
|
56
|
+
];
|
|
57
|
+
var WIDGET_FORMAT_UNIT_DISPLAYS = [
|
|
58
|
+
"short",
|
|
59
|
+
"narrow",
|
|
60
|
+
"long"
|
|
61
|
+
];
|
|
62
|
+
var WIDGET_FORMAT_NOTATIONS = ["standard", "compact"];
|
|
63
|
+
var WIDGET_FORMAT_SIGN_DISPLAYS = [
|
|
64
|
+
"auto",
|
|
65
|
+
"always",
|
|
66
|
+
"exceptZero",
|
|
67
|
+
"never"
|
|
68
|
+
];
|
|
69
|
+
/**
|
|
70
|
+
* The units of `Intl.NumberFormat` (the sanctioned units of ECMA-402): a widget's `format` takes
|
|
71
|
+
* one, or two joined by `-per-` (`kilometer-per-hour`).
|
|
72
|
+
*/
|
|
73
|
+
var WIDGET_FORMAT_UNITS = [
|
|
74
|
+
"acre",
|
|
75
|
+
"bit",
|
|
76
|
+
"byte",
|
|
77
|
+
"celsius",
|
|
78
|
+
"centimeter",
|
|
79
|
+
"day",
|
|
80
|
+
"degree",
|
|
81
|
+
"fahrenheit",
|
|
82
|
+
"fluid-ounce",
|
|
83
|
+
"foot",
|
|
84
|
+
"gallon",
|
|
85
|
+
"gigabit",
|
|
86
|
+
"gigabyte",
|
|
87
|
+
"gram",
|
|
88
|
+
"hectare",
|
|
89
|
+
"hour",
|
|
90
|
+
"inch",
|
|
91
|
+
"kilobit",
|
|
92
|
+
"kilobyte",
|
|
93
|
+
"kilogram",
|
|
94
|
+
"kilometer",
|
|
95
|
+
"liter",
|
|
96
|
+
"megabit",
|
|
97
|
+
"megabyte",
|
|
98
|
+
"meter",
|
|
99
|
+
"microsecond",
|
|
100
|
+
"mile",
|
|
101
|
+
"mile-scandinavian",
|
|
102
|
+
"milliliter",
|
|
103
|
+
"millimeter",
|
|
104
|
+
"millisecond",
|
|
105
|
+
"minute",
|
|
106
|
+
"month",
|
|
107
|
+
"nanosecond",
|
|
108
|
+
"ounce",
|
|
109
|
+
"percent",
|
|
110
|
+
"petabyte",
|
|
111
|
+
"pound",
|
|
112
|
+
"second",
|
|
113
|
+
"stone",
|
|
114
|
+
"terabit",
|
|
115
|
+
"terabyte",
|
|
116
|
+
"week",
|
|
117
|
+
"yard",
|
|
118
|
+
"year"
|
|
119
|
+
];
|
|
120
|
+
/** Whether a string is a unit of `Intl.NumberFormat`, or two joined by `-per-`. */
|
|
121
|
+
function isWidgetUnit(value) {
|
|
122
|
+
if (typeof value !== "string") return false;
|
|
123
|
+
const parts = value.split("-per-");
|
|
124
|
+
return parts.length <= 2 && parts.every((part) => WIDGET_FORMAT_UNITS.includes(part));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The built-in types that can read a resource (`settings.resource`): `stat` and `list` read its
|
|
128
|
+
* list, `series`, `breakdown` and `metric` its aggregates, and a `stat` with a `sum:` measure too.
|
|
129
|
+
*/
|
|
130
|
+
var RESOURCE_WIDGET_TYPES = [
|
|
131
|
+
"stat",
|
|
132
|
+
"series",
|
|
133
|
+
"list",
|
|
134
|
+
"breakdown",
|
|
135
|
+
"metric"
|
|
136
|
+
];
|
|
137
|
+
/** The built-in types that read the aggregates of a resource, grouped by `settings.group`. */
|
|
138
|
+
var GROUPED_WIDGET_TYPES = ["series", "breakdown"];
|
|
139
|
+
/** Query parameters that the client sets on the list of a widget on a resource, never `query`. */
|
|
140
|
+
var WIDGET_RESERVED_QUERY_PARAMS = [
|
|
141
|
+
"page",
|
|
142
|
+
"perPage",
|
|
143
|
+
"cursor"
|
|
144
|
+
];
|
|
145
|
+
function isBuiltInWidgetType(type) {
|
|
146
|
+
return BUILT_IN_WIDGET_TYPES.includes(type);
|
|
147
|
+
}
|
|
148
|
+
/** The measure of a widget on a resource that reads its aggregates, or `null` for its list. */
|
|
149
|
+
function aggregateOf(widget) {
|
|
150
|
+
const measure = widget.settings?.measure;
|
|
151
|
+
const group = widget.settings?.group;
|
|
152
|
+
const grouped = GROUPED_WIDGET_TYPES.includes(widget.type);
|
|
153
|
+
const sums = typeof measure === "string" && measure.startsWith("sum:");
|
|
154
|
+
if (!grouped && !(widget.type === "stat" && sums) && widget.type !== "metric") return null;
|
|
155
|
+
return {
|
|
156
|
+
measure: typeof measure === "string" && measure !== "" ? measure : "count",
|
|
157
|
+
group: grouped && typeof group === "string" && group !== "" ? group : null
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The resource that feeds a built-in widget, its query, and the aggregates it reads: `null` for a
|
|
162
|
+
* widget with data of its own at `GET /dashboard/widgets/{widget}`, and for widgets of plugins.
|
|
163
|
+
*/
|
|
164
|
+
function getWidgetResource(widget) {
|
|
165
|
+
const resource = widget.settings?.resource;
|
|
166
|
+
if (!RESOURCE_WIDGET_TYPES.includes(widget.type) || typeof resource !== "string" || resource === "") return null;
|
|
167
|
+
const params = paramsOf(widget.settings?.query);
|
|
168
|
+
return {
|
|
169
|
+
resource,
|
|
170
|
+
params,
|
|
171
|
+
query: fromSearchParams(params),
|
|
172
|
+
aggregate: aggregateOf(widget)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/** The query of a widget or of a source, as query parameters, without the client's own. */
|
|
176
|
+
function paramsOf(query, into = new URLSearchParams()) {
|
|
177
|
+
if (isRecord(query)) Object.entries(query).forEach(([key, value]) => {
|
|
178
|
+
if (WIDGET_RESERVED_QUERY_PARAMS.includes(key)) return;
|
|
179
|
+
into.delete(key);
|
|
180
|
+
(Array.isArray(value) ? value : [value]).forEach((entry) => {
|
|
181
|
+
if (typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean") into.append(key, String(entry));
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
return into;
|
|
185
|
+
}
|
|
186
|
+
var stringOr = (value, fallback) => typeof value === "string" && value !== "" ? value : fallback;
|
|
187
|
+
/**
|
|
188
|
+
* The sources of a widget on several resources (decision 0089): the `sources` of a `series`, at
|
|
189
|
+
* most `WIDGET_SOURCES_MAX`, or the `rows` of a `table`, at most `WIDGET_TABLE_MAX_ROWS`. Each one
|
|
190
|
+
* takes the `group` (`points` for a row) and the `period` of the widget when it has none. Empty for
|
|
191
|
+
* other widgets.
|
|
192
|
+
*/
|
|
193
|
+
function getWidgetSources(widget) {
|
|
194
|
+
const settings = widget.settings ?? {};
|
|
195
|
+
const isSeries = widget.type === "series" && Array.isArray(settings.sources);
|
|
196
|
+
const isTable = widget.type === "table" && Array.isArray(settings.rows);
|
|
197
|
+
if (!isSeries && !isTable) return [];
|
|
198
|
+
const entries = isSeries ? settings.sources : settings.rows;
|
|
199
|
+
const fallbackGroup = stringOr(isSeries ? settings.group : settings.points, null);
|
|
200
|
+
const fallbackPeriod = settings.period === false ? false : stringOr(settings.period, null);
|
|
201
|
+
return entries.slice(0, isSeries ? 5 : 8).flatMap((entry) => {
|
|
202
|
+
if (!isRecord(entry) || typeof entry.resource !== "string" || entry.resource === "") return [];
|
|
203
|
+
const params = paramsOf(entry.query);
|
|
204
|
+
const alert = isRecord(entry.alert) ? entry.alert : null;
|
|
205
|
+
const alertParams = alert !== null ? paramsOf(alert.query, new URLSearchParams(params)) : null;
|
|
206
|
+
return [{
|
|
207
|
+
resource: entry.resource,
|
|
208
|
+
label: stringOr(entry.label, entry.resource),
|
|
209
|
+
params,
|
|
210
|
+
query: fromSearchParams(params),
|
|
211
|
+
measure: stringOr(entry.measure, "count"),
|
|
212
|
+
group: stringOr(isSeries ? entry.group : entry.points, fallbackGroup),
|
|
213
|
+
period: entry.period === false ? false : stringOr(entry.period, fallbackPeriod),
|
|
214
|
+
help: stringOr(entry.help, null),
|
|
215
|
+
tone: stringOr(entry.tone, null),
|
|
216
|
+
alert: alert !== null && alertParams !== null ? {
|
|
217
|
+
params: alertParams,
|
|
218
|
+
query: fromSearchParams(alertParams),
|
|
219
|
+
label: stringOr(alert.label, ""),
|
|
220
|
+
tone: stringOr(alert.tone, "danger")
|
|
221
|
+
} : null
|
|
222
|
+
}];
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Whether a built-in widget reads resources rather than data of its own at
|
|
227
|
+
* `GET /dashboard/widgets/{widget}`: `settings.resource`, or the `sources` of a `series` or the
|
|
228
|
+
* `rows` of a `table` (decision 0089).
|
|
229
|
+
*/
|
|
230
|
+
function readsResources(widget) {
|
|
231
|
+
const settings = widget.settings ?? {};
|
|
232
|
+
return getWidgetResource(widget) !== null || widget.type === "series" && Array.isArray(settings.sources) || widget.type === "table" && Array.isArray(settings.rows);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Whether a widget combines several reads of the aggregates of resources into one card (decision
|
|
236
|
+
* 0089): a `metric` on a resource, a `series` with `split` or `sources`, a `table` with `rows`.
|
|
237
|
+
*/
|
|
238
|
+
function isCombinedWidget(widget) {
|
|
239
|
+
const settings = widget.settings ?? {};
|
|
240
|
+
if (widget.type === "metric") return getWidgetResource(widget) !== null;
|
|
241
|
+
if (widget.type === "series") return Array.isArray(settings.sources) || getWidgetResource(widget) !== null && stringOr(settings.split, null) !== null;
|
|
242
|
+
return widget.type === "table" && Array.isArray(settings.rows);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* The reads of the aggregates that a combined widget makes, whatever the period (decision 0089).
|
|
246
|
+
* A client adds, with a period, the `value` of each source over the previous period, and for a
|
|
247
|
+
* `split`, a line per value of its `parts`, filtered by it.
|
|
248
|
+
*
|
|
249
|
+
* - `metric`: its `value`, its `points` with `settings.points`, its `parts` with `settings.by`.
|
|
250
|
+
* - `series` with `split`: its total line (`points`), and the `parts` of the field it splits by.
|
|
251
|
+
* - `series` with `sources`: a line per source (`points`), and the count of its alert.
|
|
252
|
+
* - `table` with `rows`: per row, its `value`, its `points`, and the count of its alert.
|
|
253
|
+
*/
|
|
254
|
+
function getWidgetAggregates(widget) {
|
|
255
|
+
if (!isCombinedWidget(widget)) return [];
|
|
256
|
+
const settings = widget.settings ?? {};
|
|
257
|
+
const own = getWidgetResource(widget);
|
|
258
|
+
const ownPeriod = settings.period === false ? false : stringOr(settings.period, null);
|
|
259
|
+
if (own !== null && own.aggregate !== null) {
|
|
260
|
+
const base = {
|
|
261
|
+
source: null,
|
|
262
|
+
resource: own.resource,
|
|
263
|
+
query: own.query,
|
|
264
|
+
measure: own.aggregate.measure,
|
|
265
|
+
period: ownPeriod
|
|
266
|
+
};
|
|
267
|
+
if (widget.type === "metric") {
|
|
268
|
+
const points = stringOr(settings.points, null);
|
|
269
|
+
const by = stringOr(settings.by, null);
|
|
270
|
+
return [
|
|
271
|
+
{
|
|
272
|
+
...base,
|
|
273
|
+
role: "value",
|
|
274
|
+
group: null
|
|
275
|
+
},
|
|
276
|
+
...points !== null ? [{
|
|
277
|
+
...base,
|
|
278
|
+
role: "points",
|
|
279
|
+
group: points
|
|
280
|
+
}] : [],
|
|
281
|
+
...by !== null ? [{
|
|
282
|
+
...base,
|
|
283
|
+
role: "parts",
|
|
284
|
+
group: by
|
|
285
|
+
}] : []
|
|
286
|
+
];
|
|
287
|
+
}
|
|
288
|
+
return [{
|
|
289
|
+
...base,
|
|
290
|
+
role: "points",
|
|
291
|
+
group: own.aggregate.group
|
|
292
|
+
}, {
|
|
293
|
+
...base,
|
|
294
|
+
role: "parts",
|
|
295
|
+
group: stringOr(settings.split, null)
|
|
296
|
+
}];
|
|
297
|
+
}
|
|
298
|
+
return getWidgetSources(widget).flatMap((source, index) => {
|
|
299
|
+
const base = {
|
|
300
|
+
source: index,
|
|
301
|
+
resource: source.resource,
|
|
302
|
+
query: source.query,
|
|
303
|
+
measure: source.measure,
|
|
304
|
+
period: source.period
|
|
305
|
+
};
|
|
306
|
+
const alert = source.alert !== null ? [{
|
|
307
|
+
...base,
|
|
308
|
+
role: "alert",
|
|
309
|
+
query: source.alert.query,
|
|
310
|
+
measure: "count",
|
|
311
|
+
group: null
|
|
312
|
+
}] : [];
|
|
313
|
+
if (widget.type === "series") return [{
|
|
314
|
+
...base,
|
|
315
|
+
role: "points",
|
|
316
|
+
group: source.group
|
|
317
|
+
}, ...alert];
|
|
318
|
+
return [
|
|
319
|
+
{
|
|
320
|
+
...base,
|
|
321
|
+
role: "value",
|
|
322
|
+
group: null
|
|
323
|
+
},
|
|
324
|
+
...source.group !== null ? [{
|
|
325
|
+
...base,
|
|
326
|
+
role: "points",
|
|
327
|
+
group: source.group
|
|
328
|
+
}] : [],
|
|
329
|
+
...alert
|
|
330
|
+
];
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Whether a widget of the summary of a resource follows its list (decision 0084), and gets its
|
|
335
|
+
* current filters and search: a widget on that resource, or with data of its own, unless its
|
|
336
|
+
* `settings.followsList` is `false`. A widget on another resource doesn't.
|
|
337
|
+
*/
|
|
338
|
+
function followsList(widget, resource) {
|
|
339
|
+
if (widget.settings?.followsList === false) return false;
|
|
340
|
+
if (!readsResources(widget)) return true;
|
|
341
|
+
return getWidgetResource(widget)?.resource === resource || getWidgetSources(widget).some((source) => source.resource === resource);
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Whether a widget follows the period of its overview (decision 0084): a built-in widget on a
|
|
345
|
+
* resource with `settings.period`, the list's `date-range` filter that gets its days; in the
|
|
346
|
+
* summary of `summaryOf`, a widget that follows its list, whose `date-range` filter the period is;
|
|
347
|
+
* and a widget with data of its own, which gets the period, unless `settings.period` is `false`.
|
|
348
|
+
*/
|
|
349
|
+
function followsPeriod(widget, summaryOf) {
|
|
350
|
+
const period = widget.settings?.period;
|
|
351
|
+
if (period === false) return false;
|
|
352
|
+
return !readsResources(widget) || typeof period === "string" && period !== "" || getWidgetSources(widget).some((source) => typeof source.period === "string") || summaryOf !== void 0 && followsList(widget, summaryOf);
|
|
353
|
+
}
|
|
354
|
+
var DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
355
|
+
var TONE = /^[a-z0-9-]+$/;
|
|
356
|
+
var isNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
357
|
+
/** Whether a key is missing, `null`, or passes the check. */
|
|
358
|
+
function optional(data, key, check) {
|
|
359
|
+
return data[key] === void 0 || data[key] === null || check(data[key]);
|
|
360
|
+
}
|
|
361
|
+
var isString = (value) => typeof value === "string";
|
|
362
|
+
var isTone = (value) => isString(value) && TONE.test(value);
|
|
363
|
+
var isKey = (value) => isString(value) || isNumber(value) || typeof value === "boolean";
|
|
364
|
+
var ENUM_FORMAT_KEYS = {
|
|
365
|
+
style: WIDGET_FORMAT_STYLES,
|
|
366
|
+
currencyDisplay: WIDGET_FORMAT_CURRENCY_DISPLAYS,
|
|
367
|
+
unitDisplay: WIDGET_FORMAT_UNIT_DISPLAYS,
|
|
368
|
+
notation: WIDGET_FORMAT_NOTATIONS,
|
|
369
|
+
signDisplay: WIDGET_FORMAT_SIGN_DISPLAYS
|
|
370
|
+
};
|
|
371
|
+
var isDigits = (value) => typeof value === "number" && Number.isInteger(value) && value >= 0 && value <= 20;
|
|
372
|
+
/** The keys of a format that are wrong: an option out of its values, a style without its unit. */
|
|
373
|
+
function formatErrors(value) {
|
|
374
|
+
if (!isRecord(value)) return [""];
|
|
375
|
+
const wrong = Object.entries(ENUM_FORMAT_KEYS).filter(([key, values]) => !optional(value, key, (entry) => values.includes(entry))).map(([key]) => key);
|
|
376
|
+
if (!optional(value, "currency", isCurrencyCode)) wrong.push("currency");
|
|
377
|
+
if (!optional(value, "unit", isWidgetUnit)) wrong.push("unit");
|
|
378
|
+
["minimumFractionDigits", "maximumFractionDigits"].forEach((key) => {
|
|
379
|
+
if (!optional(value, key, isDigits)) wrong.push(key);
|
|
380
|
+
});
|
|
381
|
+
if (value.style === "currency" && !isCurrencyCode(value.currency)) wrong.push("currency");
|
|
382
|
+
if (value.style === "unit" && !isWidgetUnit(value.unit)) wrong.push("unit");
|
|
383
|
+
if (isDigits(value.minimumFractionDigits) && isDigits(value.maximumFractionDigits) && value.minimumFractionDigits > value.maximumFractionDigits) wrong.push("minimumFractionDigits");
|
|
384
|
+
return [...new Set(wrong)];
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* The format of the numbers of a widget (decision 0089): the options of `Intl.NumberFormat` among
|
|
388
|
+
* those a widget takes, with valid values, or `undefined` without any. A style without its
|
|
389
|
+
* `currency` or its `unit` is left out, as an unknown key. The `format` of the data, then the
|
|
390
|
+
* `format` of the settings over it, key by key: `readWidgetFormat(data.format, settings.format)`.
|
|
391
|
+
*/
|
|
392
|
+
function readWidgetFormat(...formats) {
|
|
393
|
+
const merged = {};
|
|
394
|
+
formats.forEach((format) => {
|
|
395
|
+
if (isRecord(format)) Object.assign(merged, format);
|
|
396
|
+
});
|
|
397
|
+
const wrong = new Set(formatErrors(merged));
|
|
398
|
+
const format = {};
|
|
399
|
+
[
|
|
400
|
+
...Object.keys(ENUM_FORMAT_KEYS),
|
|
401
|
+
"currency",
|
|
402
|
+
"unit",
|
|
403
|
+
"minimumFractionDigits",
|
|
404
|
+
"maximumFractionDigits"
|
|
405
|
+
].forEach((key) => {
|
|
406
|
+
if (merged[key] !== void 0 && merged[key] !== null && !wrong.has(key)) format[key] = merged[key];
|
|
407
|
+
});
|
|
408
|
+
if (format.style === "currency" && format.currency === void 0 || format.style === "unit" && format.unit === void 0) delete format.style;
|
|
409
|
+
if (wrong.has("minimumFractionDigits")) delete format.maximumFractionDigits;
|
|
410
|
+
return Object.keys(format).length > 0 ? format : void 0;
|
|
411
|
+
}
|
|
412
|
+
function checkFormat(data, path = "format") {
|
|
413
|
+
return data[path] === void 0 || data[path] === null ? [] : formatErrors(data[path]).map((key) => key === "" ? path : `${path}.${key}`);
|
|
414
|
+
}
|
|
415
|
+
/** The paths of the wrong points of a line: a date that doesn't go up, a value that isn't a number. */
|
|
416
|
+
function checkPoints(points, path) {
|
|
417
|
+
if (!Array.isArray(points)) return [path];
|
|
418
|
+
const wrong = [];
|
|
419
|
+
let previous = "";
|
|
420
|
+
points.forEach((point, index) => {
|
|
421
|
+
if (!isRecord(point)) {
|
|
422
|
+
wrong.push(`${path}.${index}`);
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
if (!isString(point.date) || !DATE.test(point.date) || point.date <= previous) wrong.push(`${path}.${index}.date`);
|
|
426
|
+
else previous = point.date;
|
|
427
|
+
if (!isNumber(point.value)) wrong.push(`${path}.${index}.value`);
|
|
428
|
+
});
|
|
429
|
+
return wrong;
|
|
430
|
+
}
|
|
431
|
+
function checkStat(data) {
|
|
432
|
+
const wrong = [];
|
|
433
|
+
if (!isNumber(data.value)) wrong.push("value");
|
|
434
|
+
if (!optional(data, "help", isString)) wrong.push("help");
|
|
435
|
+
if (!optional(data, "tone", isTone)) wrong.push("tone");
|
|
436
|
+
if (!optional(data, "url", isString)) wrong.push("url");
|
|
437
|
+
if (!optional(data, "target", (value) => isNumber(value) && value > 0)) wrong.push("target");
|
|
438
|
+
return [...wrong, ...checkFormat(data)];
|
|
439
|
+
}
|
|
440
|
+
function checkAlert(alert, path) {
|
|
441
|
+
if (alert === void 0 || alert === null) return [];
|
|
442
|
+
if (!isRecord(alert)) return [path];
|
|
443
|
+
return [
|
|
444
|
+
...!isNumber(alert.value) ? [`${path}.value`] : [],
|
|
445
|
+
...!isString(alert.label) ? [`${path}.label`] : [],
|
|
446
|
+
...!optional(alert, "tone", isTone) ? [`${path}.tone`] : []
|
|
447
|
+
];
|
|
448
|
+
}
|
|
449
|
+
function checkSeries(data) {
|
|
450
|
+
const wrong = [];
|
|
451
|
+
if (!WIDGET_SERIES_PERIODS.includes(data.period)) wrong.push("period");
|
|
452
|
+
wrong.push(...checkPoints(data.points, "points"));
|
|
453
|
+
if (data.series !== void 0) {
|
|
454
|
+
if (!Array.isArray(data.series) || data.series.length > 6) wrong.push("series");
|
|
455
|
+
else data.series.forEach((series, index) => {
|
|
456
|
+
const path = `series.${index}`;
|
|
457
|
+
if (!isRecord(series)) {
|
|
458
|
+
wrong.push(path);
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
if (!isString(series.label)) wrong.push(`${path}.label`);
|
|
462
|
+
wrong.push(...checkPoints(series.points, `${path}.points`));
|
|
463
|
+
if (!optional(series, "total", isNumber)) wrong.push(`${path}.total`);
|
|
464
|
+
if (!optional(series, "tone", isTone)) wrong.push(`${path}.tone`);
|
|
465
|
+
["url", "help"].forEach((key) => {
|
|
466
|
+
if (!optional(series, key, isString)) wrong.push(`${path}.${key}`);
|
|
467
|
+
});
|
|
468
|
+
if (!optional(series, "key", isKey)) wrong.push(`${path}.key`);
|
|
469
|
+
wrong.push(...checkAlert(series.alert, `${path}.alert`));
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
if (!optional(data, "total", isNumber)) wrong.push("total");
|
|
473
|
+
return [...wrong, ...checkFormat(data)];
|
|
474
|
+
}
|
|
475
|
+
function checkList(data) {
|
|
476
|
+
const wrong = [];
|
|
477
|
+
if (!Array.isArray(data.items) || data.items.length > 5) wrong.push("items");
|
|
478
|
+
else data.items.forEach((item, index) => {
|
|
479
|
+
if (!isRecord(item)) {
|
|
480
|
+
wrong.push(`items.${index}`);
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
if (!isString(item.title)) wrong.push(`items.${index}.title`);
|
|
484
|
+
[
|
|
485
|
+
"description",
|
|
486
|
+
"meta",
|
|
487
|
+
"url"
|
|
488
|
+
].forEach((key) => {
|
|
489
|
+
if (!optional(item, key, isString)) wrong.push(`items.${index}.${key}`);
|
|
490
|
+
});
|
|
491
|
+
const badge = item.badge;
|
|
492
|
+
if (badge !== void 0 && badge !== null) {
|
|
493
|
+
if (!isRecord(badge) || !isString(badge.label)) wrong.push(`items.${index}.badge`);
|
|
494
|
+
else if (!optional(badge, "tone", isTone)) wrong.push(`items.${index}.badge.tone`);
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
if (!optional(data, "empty", isString)) wrong.push("empty");
|
|
498
|
+
if (!optional(data, "url", isString)) wrong.push("url");
|
|
499
|
+
return wrong;
|
|
500
|
+
}
|
|
501
|
+
/** The parts of a `breakdown` (`items`) or of a `metric` (`parts`). */
|
|
502
|
+
function checkParts(parts, path) {
|
|
503
|
+
if (!Array.isArray(parts) || parts.length > 10) return [path];
|
|
504
|
+
const wrong = [];
|
|
505
|
+
parts.forEach((item, index) => {
|
|
506
|
+
if (!isRecord(item)) {
|
|
507
|
+
wrong.push(`${path}.${index}`);
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
if (!isString(item.label)) wrong.push(`${path}.${index}.label`);
|
|
511
|
+
if (!isNumber(item.value)) wrong.push(`${path}.${index}.value`);
|
|
512
|
+
if (!optional(item, "tone", isTone)) wrong.push(`${path}.${index}.tone`);
|
|
513
|
+
if (!optional(item, "url", isString)) wrong.push(`${path}.${index}.url`);
|
|
514
|
+
if (!optional(item, "key", isKey)) wrong.push(`${path}.${index}.key`);
|
|
515
|
+
});
|
|
516
|
+
return wrong;
|
|
517
|
+
}
|
|
518
|
+
function checkBreakdown(data) {
|
|
519
|
+
const wrong = checkParts(data.items, "items");
|
|
520
|
+
if (!optional(data, "total", isNumber)) wrong.push("total");
|
|
521
|
+
if (!optional(data, "other", isNumber)) wrong.push("other");
|
|
522
|
+
return [...wrong, ...checkFormat(data)];
|
|
523
|
+
}
|
|
524
|
+
function checkMetric(data) {
|
|
525
|
+
const wrong = checkStat(data);
|
|
526
|
+
if (!optional(data, "previous", isNumber)) wrong.push("previous");
|
|
527
|
+
if (data.points !== void 0 && data.points !== null) wrong.push(...checkPoints(data.points, "points"));
|
|
528
|
+
if (!optional(data, "period", (value) => WIDGET_SERIES_PERIODS.includes(value))) wrong.push("period");
|
|
529
|
+
if (data.parts !== void 0 && data.parts !== null) wrong.push(...checkParts(data.parts, "parts"));
|
|
530
|
+
if (!optional(data, "other", isNumber)) wrong.push("other");
|
|
531
|
+
return wrong;
|
|
532
|
+
}
|
|
533
|
+
var isCell = (cell) => cell === null || isNumber(cell) || isRecord(cell) && (cell.value === null || isNumber(cell.value)) && optional(cell, "tone", isTone) && optional(cell, "help", isString) && checkFormat(cell).length === 0;
|
|
534
|
+
function checkTable(data) {
|
|
535
|
+
const wrong = [];
|
|
536
|
+
if (!Array.isArray(data.columns) || data.columns.length === 0 || data.columns.length > 6) wrong.push("columns");
|
|
537
|
+
else {
|
|
538
|
+
const keys = /* @__PURE__ */ new Set();
|
|
539
|
+
data.columns.forEach((column, index) => {
|
|
540
|
+
const path = `columns.${index}`;
|
|
541
|
+
if (!isRecord(column)) {
|
|
542
|
+
wrong.push(path);
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
if (!isString(column.key) || column.key === "" || keys.has(column.key)) wrong.push(`${path}.key`);
|
|
546
|
+
else keys.add(column.key);
|
|
547
|
+
if (!isString(column.label)) wrong.push(`${path}.label`);
|
|
548
|
+
if (!optional(column, "align", (value) => WIDGET_TABLE_ALIGNS.includes(value))) wrong.push(`${path}.align`);
|
|
549
|
+
wrong.push(...checkFormat(column).map((key) => `${path}.${key}`));
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
if (!Array.isArray(data.rows) || data.rows.length > 8) wrong.push("rows");
|
|
553
|
+
else data.rows.forEach((row, index) => {
|
|
554
|
+
const path = `rows.${index}`;
|
|
555
|
+
if (!isRecord(row)) {
|
|
556
|
+
wrong.push(path);
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
if (!isString(row.label)) wrong.push(`${path}.label`);
|
|
560
|
+
if (!optional(row, "url", isString)) wrong.push(`${path}.url`);
|
|
561
|
+
if (!isRecord(row.cells)) wrong.push(`${path}.cells`);
|
|
562
|
+
else Object.entries(row.cells).forEach(([key, cell]) => {
|
|
563
|
+
if (!isCell(cell)) wrong.push(`${path}.cells.${key}`);
|
|
564
|
+
});
|
|
565
|
+
if (row.points !== void 0 && row.points !== null) wrong.push(...checkPoints(row.points, `${path}.points`));
|
|
566
|
+
});
|
|
567
|
+
if (!optional(data, "period", (value) => WIDGET_SERIES_PERIODS.includes(value))) wrong.push("period");
|
|
568
|
+
["empty", "url"].forEach((key) => {
|
|
569
|
+
if (!optional(data, key, isString)) wrong.push(key);
|
|
570
|
+
});
|
|
571
|
+
return [...wrong, ...checkFormat(data)];
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Checks the data of a widget against the shape of its type (decisions 0064, 0084 and 0089),
|
|
575
|
+
* without the schemas: the paths of the wrong keys (`value`, `points.2.date`), empty when it is
|
|
576
|
+
* right. The data of a widget of a plugin only has to be an object. The dates of a series must go
|
|
577
|
+
* up, one point per period.
|
|
578
|
+
*/
|
|
579
|
+
function checkWidgetData(type, data) {
|
|
580
|
+
if (!isRecord(data)) return [""];
|
|
581
|
+
switch (type) {
|
|
582
|
+
case "stat": return checkStat(data);
|
|
583
|
+
case "series": return checkSeries(data);
|
|
584
|
+
case "list": return checkList(data);
|
|
585
|
+
case "breakdown": return checkBreakdown(data);
|
|
586
|
+
case "metric": return checkMetric(data);
|
|
587
|
+
case "table": return checkTable(data);
|
|
588
|
+
default: return [];
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
var allZero = (points) => !Array.isArray(points) || points.every((point) => !isRecord(point) || point.value === 0);
|
|
592
|
+
/**
|
|
593
|
+
* Whether the data of a built-in widget has nothing to show (decision 0089), for
|
|
594
|
+
* `settings.hideEmpty`: a `stat` at 0, a `metric` at 0 that was at 0 or has no previous value, a
|
|
595
|
+
* `series` whose points are all 0, a `breakdown` whose parts and rest are all 0, a `list` without
|
|
596
|
+
* items, a `table` without rows. Data of plugins is never empty.
|
|
597
|
+
*/
|
|
598
|
+
function isWidgetDataEmpty(type, data) {
|
|
599
|
+
if (!isRecord(data)) return false;
|
|
600
|
+
switch (type) {
|
|
601
|
+
case "stat": return data.value === 0;
|
|
602
|
+
case "metric": return data.value === 0 && (data.previous ?? 0) === 0;
|
|
603
|
+
case "series": return Array.isArray(data.series) ? data.series.every((series) => !isRecord(series) || allZero(series.points)) : allZero(data.points);
|
|
604
|
+
case "breakdown": return allZero(data.items) && (data.other ?? 0) === 0;
|
|
605
|
+
case "list": return Array.isArray(data.items) && data.items.length === 0;
|
|
606
|
+
case "table": return Array.isArray(data.rows) && data.rows.length === 0;
|
|
607
|
+
default: return false;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
/** The change of a number from its value over the previous period (decision 0089). */
|
|
611
|
+
function getWidgetChange(value, previous) {
|
|
612
|
+
const difference = value - previous;
|
|
613
|
+
return {
|
|
614
|
+
difference,
|
|
615
|
+
ratio: previous !== 0 ? difference / Math.abs(previous) : null,
|
|
616
|
+
direction: difference > 0 ? "up" : difference < 0 ? "down" : "none"
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* The tone of a change (decision 0089): `success` when it goes the way `goodWhen` says is good,
|
|
621
|
+
* `danger` the other way, and none without `goodWhen` or without a change.
|
|
622
|
+
*/
|
|
623
|
+
function getChangeTone(direction, goodWhen) {
|
|
624
|
+
if (direction === "none" || goodWhen !== "up" && goodWhen !== "down") return null;
|
|
625
|
+
return direction === goodWhen ? "success" : "danger";
|
|
626
|
+
}
|
|
627
|
+
//#endregion
|
|
628
|
+
export { BUILT_IN_WIDGET_TYPES, GROUPED_WIDGET_TYPES, RESOURCE_WIDGET_TYPES, WIDGET_BREAKDOWN_MAX_ITEMS, WIDGET_FORMAT_CURRENCY_DISPLAYS, WIDGET_FORMAT_NOTATIONS, WIDGET_FORMAT_SIGN_DISPLAYS, WIDGET_FORMAT_STYLES, WIDGET_FORMAT_UNITS, WIDGET_FORMAT_UNIT_DISPLAYS, WIDGET_GOOD_WHEN, WIDGET_LIST_MAX_ITEMS, WIDGET_METRIC_MAX_PARTS, WIDGET_RESERVED_QUERY_PARAMS, WIDGET_SERIES_MAX_SERIES, WIDGET_SERIES_PERIODS, WIDGET_SOURCES_MAX, WIDGET_TABLE_ALIGNS, WIDGET_TABLE_MAX_COLUMNS, WIDGET_TABLE_MAX_ROWS, checkWidgetData, followsList, followsPeriod, getChangeTone, getWidgetAggregates, getWidgetChange, getWidgetResource, getWidgetSources, isBuiltInWidgetType, isCombinedWidget, isWidgetDataEmpty, isWidgetUnit, readWidgetFormat, readsResources };
|
|
629
|
+
|
|
630
|
+
//# sourceMappingURL=widgets.js.map
|