@panneau/protocol 5.0.0-alpha.4 → 5.0.0-alpha.42
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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../../src/schemas/widget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA8BxB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2DzB,CAAC;AAEP,eAAO,MAAM,mBAAmB;;;;iBAgB1B,CAAC;AAIP,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;iBAwBzB,CAAC;AAEP,eAAO,MAAM,eAAe;;;;;;;;;;;;iBAqBtB,CAAC;AAEP,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsFrB,CAAC;AAEP,eAAO,MAAM,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ABLE_ALIGNS, isWidgetUnit } from "../widgets.js";
|
|
3
|
+
import { OVERVIEW_PERIODS } from "../periods.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
//#region src/schemas/widget.ts
|
|
6
|
+
var ToneName = z.string().regex(/^[a-z0-9-]+$/);
|
|
7
|
+
var QueryValue = z.union([
|
|
8
|
+
z.string(),
|
|
9
|
+
z.number(),
|
|
10
|
+
z.boolean()
|
|
11
|
+
]);
|
|
12
|
+
var WidgetQuery = z.record(z.string(), z.union([QueryValue, z.array(QueryValue)]));
|
|
13
|
+
var FractionDigits = z.number().int().min(0).max(20);
|
|
14
|
+
var WidgetNumberFormat = z.looseObject({
|
|
15
|
+
style: z.enum(WIDGET_FORMAT_STYLES).optional().meta({ description: "`decimal` (the default), `percent` (`0.12` is `12%`), `currency` (with `currency`) or `unit` (with `unit`)." }),
|
|
16
|
+
currency: z.enum(CURRENCY_CODES).optional().meta({ description: "With `style: \"currency\"`: an ISO 4217 code, `USD`." }),
|
|
17
|
+
currencyDisplay: z.enum(WIDGET_FORMAT_CURRENCY_DISPLAYS).optional(),
|
|
18
|
+
unit: z.string().refine(isWidgetUnit, { message: "A unit of `Intl.NumberFormat`: `byte`, `megabyte`, `kilometer-per-hour`." }).optional().meta({ description: "With `style: \"unit\"`: a unit of `Intl.NumberFormat` (`byte`, `kilobyte`, `megabyte`, `gigabyte`, `second`, `minute`, `hour`…), or two of them joined by `-per-`." }),
|
|
19
|
+
unitDisplay: z.enum(WIDGET_FORMAT_UNIT_DISPLAYS).optional(),
|
|
20
|
+
minimumFractionDigits: FractionDigits.optional(),
|
|
21
|
+
maximumFractionDigits: FractionDigits.optional(),
|
|
22
|
+
notation: z.enum(WIDGET_FORMAT_NOTATIONS).optional().meta({ description: "`compact` writes `1.2K` and `3.4M`." }),
|
|
23
|
+
signDisplay: z.enum(WIDGET_FORMAT_SIGN_DISPLAYS).optional()
|
|
24
|
+
}).superRefine((format, context) => {
|
|
25
|
+
if (format.style === "currency" && format.currency === void 0) context.addIssue({
|
|
26
|
+
code: "custom",
|
|
27
|
+
message: "A `currency` style needs a `currency`.",
|
|
28
|
+
path: ["currency"]
|
|
29
|
+
});
|
|
30
|
+
if (format.style === "unit" && format.unit === void 0) context.addIssue({
|
|
31
|
+
code: "custom",
|
|
32
|
+
message: "A `unit` style needs a `unit`.",
|
|
33
|
+
path: ["unit"]
|
|
34
|
+
});
|
|
35
|
+
if (format.minimumFractionDigits !== void 0 && format.maximumFractionDigits !== void 0 && format.minimumFractionDigits > format.maximumFractionDigits) context.addIssue({
|
|
36
|
+
code: "custom",
|
|
37
|
+
message: "`minimumFractionDigits` is above `maximumFractionDigits`.",
|
|
38
|
+
path: ["minimumFractionDigits"]
|
|
39
|
+
});
|
|
40
|
+
}).meta({ description: "How the numbers of a widget are written: options of `Intl.NumberFormat`, for the locale of the user (decision 0089). `{ \"style\": \"currency\", \"currency\": \"USD\" }` writes `9.08` as `$9.08`, `{ \"style\": \"unit\", \"unit\": \"megabyte\" }` as `9.08 MB`." });
|
|
41
|
+
var WidgetAlertSettings = z.looseObject({
|
|
42
|
+
query: WidgetQuery.meta({ description: "The filters of the items to count, as query parameters, on top of those of their source: `{ \"filter[status]\": \"failed\" }`." }),
|
|
43
|
+
label: z.string().min(1).meta({ description: "What they are, written after their count, translated: `failed`." }),
|
|
44
|
+
tone: ToneName.optional().meta({ description: "The tone of the count, when it is above 0. `danger` by default." })
|
|
45
|
+
}).meta({ description: "Items of a source that call for attention (decision 0089): counted with the same query and period, and shown as `4 failed` when there are some." });
|
|
46
|
+
var SourcePeriod = z.union([z.string().min(1), z.literal(false)]);
|
|
47
|
+
var WidgetSeriesSource = z.looseObject({
|
|
48
|
+
resource: z.string().min(1).meta({ description: "The resource it counts or sums." }),
|
|
49
|
+
label: z.string().min(1).meta({ description: "The name of its line, in the legend." }),
|
|
50
|
+
query: WidgetQuery.optional(),
|
|
51
|
+
measure: z.string().min(1).optional().meta({ description: "`count` (the default), or `sum:{field}`." }),
|
|
52
|
+
group: z.string().min(1).optional().meta({ description: "`{period}:{date field}`: `settings.group` of the widget by default." }),
|
|
53
|
+
period: SourcePeriod.optional().meta({ description: "The `date-range` filter of its list that gets the period of the overview: `settings.period` of the widget by default. `false`: it doesn't follow the period." }),
|
|
54
|
+
help: z.string().optional().meta({ description: "A line under its label in the legend." }),
|
|
55
|
+
tone: ToneName.optional().meta({ description: "The tone of its line, instead of a categorical color." }),
|
|
56
|
+
alert: WidgetAlertSettings.optional()
|
|
57
|
+
}).meta({ description: "A line of a `series` on resources (decision 0089): the count or the sum of a resource per period." });
|
|
58
|
+
var WidgetRowSource = z.looseObject({
|
|
59
|
+
resource: z.string().min(1).meta({ description: "The resource it counts or sums." }),
|
|
60
|
+
label: z.string().min(1).meta({ description: "The name of the row." }),
|
|
61
|
+
query: WidgetQuery.optional(),
|
|
62
|
+
measure: z.string().min(1).optional().meta({ description: "`count` (the default), or `sum:{field}`." }),
|
|
63
|
+
points: z.string().min(1).optional().meta({ description: "`{period}:{date field}`: the points of its trend. `settings.points` of the widget by default." }),
|
|
64
|
+
period: SourcePeriod.optional().meta({ description: "The `date-range` filter of its list that gets the period of the overview, and the previous one for its change: `settings.period` of the widget by default." }),
|
|
65
|
+
alert: WidgetAlertSettings.optional()
|
|
66
|
+
}).meta({ description: "A row of a `table` on resources (decision 0089): one subject, counted or summed over the period." });
|
|
67
|
+
var WidgetSettings = z.looseObject({
|
|
68
|
+
resource: z.string().min(1).optional().meta({ description: "Built-in types: the resource that feeds the widget. A `stat` counts the items of its list (`meta.total`), a `list` shows its first items, and a `series`, a `breakdown` and a `stat` with a `sum:` measure read `GET /resources/{resource}/aggregate` (decision 0084). Such a widget has no data at `GET /dashboard/widgets/{widget}`." }),
|
|
69
|
+
query: z.record(z.string(), z.union([QueryValue, z.array(QueryValue)])).optional().meta({ description: "With `resource`: the query of the list, as its query parameters (`{ \"filter[status]\": \"to-judge\", \"sort\": \"-created_at\" }`), and of the link to the list. The client sets `page`, `perPage` and `cursor`." }),
|
|
70
|
+
measure: z.string().min(1).optional().meta({ description: "With `resource`, for a `stat`, a `series` and a `breakdown`: `count` (the default), or `sum:{field}` of a field of the `sum` of the aggregates of the list." }),
|
|
71
|
+
group: z.string().min(1).optional().meta({ description: "With `resource`: for a `series`, `{period}:{date field}` (`day`, `week` or `month`, and a field of `dates` of the aggregates of the list); for a `breakdown`, a field of their `groupBy`." }),
|
|
72
|
+
target: z.number().positive().optional().meta({ description: "With `resource`, for a `stat`: its `target` (a budget, a quota), in the unit of the value: minor units for a sum of `money`." }),
|
|
73
|
+
period: z.union([z.string().min(1), z.literal(false)]).optional().meta({ description: "In an overview with a `period` (decision 0084). With `resource`: the id of the list's `date-range` filter that gets the days of the chosen period. `false`: the widget doesn't follow the period; a widget with data of its own then gets no `period` parameters." }),
|
|
74
|
+
followsList: z.boolean().optional().meta({ description: "In the summary of a resource (decision 0084): `false` keeps the widget on the whole resource, without the list's current filters and search. Widgets on that resource, and widgets with data of their own, follow the list by default." }),
|
|
75
|
+
format: WidgetNumberFormat.optional().meta({ description: "Built-in types: how their numbers are written (decision 0089). It wins over the `format` of their data, key by key. A sum of `money` is written in its currency without it." }),
|
|
76
|
+
hideEmpty: z.boolean().optional().meta({ description: "Built-in types: `true` hides the widget when its data has nothing to show (a value of 0, no items, no rows), and the grid closes the gap (decision 0089)." }),
|
|
77
|
+
goodWhen: z.enum(WIDGET_GOOD_WHEN).optional().meta({ description: "A `metric` or a `table`: whether a rise (`up`) or a fall (`down`) is good news, so that its change from the previous period is colored `success` or `danger`. Neutral without it." }),
|
|
78
|
+
points: z.string().min(1).optional().meta({ description: "With `resource`, for a `metric`: `{period}:{date field}`, the points of its trend line. For a `table`, the default of its rows." }),
|
|
79
|
+
by: z.string().min(1).optional().meta({ description: "With `resource`, for a `metric`: a field of the `groupBy` of the aggregates of the list, whose largest parts are drawn under the number." }),
|
|
80
|
+
split: z.string().min(1).optional().meta({ description: `With \`resource\` and a \`group\` on a period, for a \`series\`: a field of the \`groupBy\` of the aggregates of the list with a filter of its own. A line per value, for the 5 largest, and the rest as "Other".` }),
|
|
81
|
+
sources: z.array(WidgetSeriesSource).min(1).max(5).optional().meta({ description: `A \`series\` without \`resource\`: a line per source, at most 5, each from a resource.` }),
|
|
82
|
+
stacked: z.boolean().optional().meta({ description: "A `series` with several lines: stacks them, as areas." }),
|
|
83
|
+
rows: z.array(WidgetRowSource).min(1).max(8).optional().meta({ description: `A \`table\` on resources: its rows, at most 8, each a count or a sum of a resource.` })
|
|
84
|
+
}).meta({ description: "The settings of a widget: `resource`, `query`, `measure`, `group`, `target`, `points`, `by` and `split` for the built-in types on a resource, `sources` and `rows` for those on several, `period` in an overview with a period, `followsList` in a summary, `format`, `hideEmpty` and `goodWhen` for how they are drawn, anything else for widgets of plugins." });
|
|
85
|
+
var OverviewPeriod = z.looseObject({
|
|
86
|
+
options: z.array(z.enum(OVERVIEW_PERIODS)).min(1).meta({ description: "The periods the user chooses from, in order: `7d`, `30d` and `90d`, the 7, 30 or 90 days ending today; `month`, the current calendar month, from its first day to today; `year`, the last 12 months, from the first day of the month 11 months ago to today. Days are those of the time zone of the browser." }),
|
|
87
|
+
default: z.enum(OVERVIEW_PERIODS).optional().meta({ description: "The period the overview opens on, among `options`. Defaults to the first." })
|
|
88
|
+
}).meta({ description: "One period for the widgets of a dashboard page or a summary, chosen in its header and kept in the URL (`?period=30d`, decision 0084)." });
|
|
89
|
+
var Widget = z.looseObject({
|
|
90
|
+
id: z.string().min(1).meta({ description: "Unique in its dashboard: the `{widget}` of its route." }),
|
|
91
|
+
type: z.string().min(1).meta({ description: "Built-in: `stat` (a number), `series` (lines over days, weeks or months), `list` (a few items), `breakdown` (the parts of a total), `metric` (a number with its change, its trend and its parts) and `table` (rows of numbers). Other types are widgets of plugins." }),
|
|
92
|
+
label: z.string().optional(),
|
|
93
|
+
width: z.number().int().min(1).max(12).optional().meta({ description: "Columns of a grid of 12. Defaults to 3 for a `stat`, 6 for others. One column on a phone." }),
|
|
94
|
+
settings: WidgetSettings.optional()
|
|
95
|
+
});
|
|
96
|
+
var WidgetBadge = z.looseObject({
|
|
97
|
+
label: z.string(),
|
|
98
|
+
tone: ToneName.optional()
|
|
99
|
+
}).meta({ description: "A badge: a word, in a tone of the theme." });
|
|
100
|
+
var StatWidgetData = z.looseObject({
|
|
101
|
+
value: z.number().meta({ description: "The number, in large type." }),
|
|
102
|
+
help: z.string().nullable().optional().meta({ description: "A line under the number, translated: `3 more than last week`." }),
|
|
103
|
+
tone: ToneName.nullable().optional().meta({ description: "A tone of the theme, only when the number calls for attention (`warning`, `danger`): neutral otherwise, and at 0." }),
|
|
104
|
+
url: z.string().nullable().optional().meta({ description: "Where the widget links: the list of what it counts." }),
|
|
105
|
+
target: z.number().positive().nullable().optional().meta({ description: "A target for the number (a budget, a quota), drawn as a meter under it. Past it, the meter takes `tone`, or `danger` without one (decision 0084)." }),
|
|
106
|
+
format: WidgetNumberFormat.nullable().optional()
|
|
107
|
+
}).meta({ description: "The data of a `stat` widget: a number (decision 0064)." });
|
|
108
|
+
var SeriesPoint = z.looseObject({
|
|
109
|
+
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).meta({ description: "The first day of the period: `2026-10-05`." }),
|
|
110
|
+
value: z.number()
|
|
111
|
+
});
|
|
112
|
+
/** The dates of points must go up: one point per period. */
|
|
113
|
+
function checkPointDates(points, path, context) {
|
|
114
|
+
(points ?? []).forEach((point, index) => {
|
|
115
|
+
const previous = points?.[index - 1];
|
|
116
|
+
if (previous !== void 0 && point.date <= previous.date) context.addIssue({
|
|
117
|
+
code: "custom",
|
|
118
|
+
message: "The dates of the points must go up.",
|
|
119
|
+
path: [
|
|
120
|
+
...path,
|
|
121
|
+
index,
|
|
122
|
+
"date"
|
|
123
|
+
]
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
var WidgetAlert = z.looseObject({
|
|
128
|
+
value: z.number().meta({ description: "How many items call for attention." }),
|
|
129
|
+
label: z.string().meta({ description: "What they are, written after their count, translated: `failed`." }),
|
|
130
|
+
tone: ToneName.nullable().optional().meta({ description: "The tone of the count, above 0. `danger` by default." })
|
|
131
|
+
}).meta({ description: "A count that calls for attention (decision 0089): `4 failed`, in its tone, shown when it is above 0." });
|
|
132
|
+
var SeriesWidgetSeries = z.looseObject({
|
|
133
|
+
key: z.union([
|
|
134
|
+
z.string(),
|
|
135
|
+
z.number(),
|
|
136
|
+
z.boolean()
|
|
137
|
+
]).nullable().optional().meta({ description: "The value it is the line of, for a line per value of a field." }),
|
|
138
|
+
label: z.string().meta({ description: "Its name, in the legend." }),
|
|
139
|
+
points: z.array(SeriesPoint).meta({ description: "One point per period, the dates going up. A date missing is 0." }),
|
|
140
|
+
total: z.number().nullable().optional().meta({ description: "Its total over the points, in the legend." }),
|
|
141
|
+
tone: ToneName.nullable().optional().meta({ description: "The tone of its line, instead of a categorical color." }),
|
|
142
|
+
url: z.string().nullable().optional().meta({ description: "Where its legend links." }),
|
|
143
|
+
help: z.string().nullable().optional().meta({ description: "A line under its label in the legend." }),
|
|
144
|
+
alert: WidgetAlert.nullable().optional()
|
|
145
|
+
}).meta({ description: "A line of a `series` with several (decision 0089)." });
|
|
146
|
+
var SeriesWidgetData = z.looseObject({
|
|
147
|
+
period: z.enum(WIDGET_SERIES_PERIODS).meta({ description: "The period of each point." }),
|
|
148
|
+
points: z.array(SeriesPoint).meta({ description: "One point per period, the dates going up. Periods without a value are points at 0. With `series`, the total of the lines per period, or none (`[]`): clients that only draw one line draw it." }),
|
|
149
|
+
series: z.array(SeriesWidgetSeries).max(6).optional().meta({ description: `Several lines, at most 6, instead of \`points\` (decision 0089): one chart, with a legend of their labels, totals and help.` }),
|
|
150
|
+
total: z.number().nullable().optional().meta({ description: "The total over the points, shown with the line." }),
|
|
151
|
+
format: WidgetNumberFormat.nullable().optional()
|
|
152
|
+
}).superRefine((data, context) => {
|
|
153
|
+
checkPointDates(data.points, ["points"], context);
|
|
154
|
+
data.series?.forEach((series, index) => {
|
|
155
|
+
checkPointDates(series.points, [
|
|
156
|
+
"series",
|
|
157
|
+
index,
|
|
158
|
+
"points"
|
|
159
|
+
], context);
|
|
160
|
+
});
|
|
161
|
+
}).meta({ description: "The data of a `series` widget: a line of values per period (decision 0064), or several (decision 0089)." });
|
|
162
|
+
var ListWidgetItem = z.looseObject({
|
|
163
|
+
title: z.string(),
|
|
164
|
+
description: z.string().nullable().optional(),
|
|
165
|
+
meta: z.string().nullable().optional().meta({ description: "A short fact at the end of the item: `12 answers`." }),
|
|
166
|
+
url: z.string().nullable().optional(),
|
|
167
|
+
badge: WidgetBadge.nullable().optional()
|
|
168
|
+
});
|
|
169
|
+
var ListWidgetData = z.looseObject({
|
|
170
|
+
items: z.array(ListWidgetItem).max(5).meta({ description: `At most 5 items, the most useful first.` }),
|
|
171
|
+
empty: z.string().nullable().optional().meta({ description: "The message without items, translated: `No open contests.`" }),
|
|
172
|
+
url: z.string().nullable().optional().meta({ description: "Where \"See all\" links, under the items." })
|
|
173
|
+
}).meta({ description: "The data of a `list` widget: a few items (decision 0064)." });
|
|
174
|
+
var BreakdownWidgetItem = z.looseObject({
|
|
175
|
+
label: z.string().meta({ description: "What the part is, translated: `Failed`." }),
|
|
176
|
+
value: z.number().meta({ description: "The count or the sum of the part." }),
|
|
177
|
+
tone: ToneName.nullable().optional().meta({ description: "A tone of the theme for its bar: the tone of an option of a `select`." }),
|
|
178
|
+
url: z.string().nullable().optional().meta({ description: "Where the bar links: the list of what it counts." }),
|
|
179
|
+
key: z.union([
|
|
180
|
+
z.string(),
|
|
181
|
+
z.number(),
|
|
182
|
+
z.boolean()
|
|
183
|
+
]).nullable().optional().meta({ description: "From `GET /resources/{resource}/aggregate`: the value of the field it groups, `null` for the items without one. The client links the bar to the list filtered by it." })
|
|
184
|
+
});
|
|
185
|
+
var BreakdownWidgetData = z.looseObject({
|
|
186
|
+
items: z.array(BreakdownWidgetItem).max(10).meta({ description: `The parts, at most 10: clients draw the largest first.` }),
|
|
187
|
+
total: z.number().nullable().optional().meta({ description: "The total the parts are of. Items with several values count in each of their parts, and once in the total." }),
|
|
188
|
+
other: z.number().nullable().optional().meta({ description: "The rest of the total, past the items: drawn last, as \"Other\"." }),
|
|
189
|
+
format: WidgetNumberFormat.nullable().optional()
|
|
190
|
+
}).meta({ description: "The data of a `breakdown` widget: the parts of a total, as horizontal bars (decision 0084)." });
|
|
191
|
+
var MetricWidgetData = z.looseObject({
|
|
192
|
+
value: z.number().meta({ description: "The number, in large type." }),
|
|
193
|
+
previous: z.number().nullable().optional().meta({ description: "The same number over the previous period, of the same length (`getPreviousRange()`): the change from it is written under the number." }),
|
|
194
|
+
help: z.string().nullable().optional().meta({ description: "A line under the number, translated." }),
|
|
195
|
+
tone: ToneName.nullable().optional().meta({ description: "A tone of the theme, only when the number calls for attention." }),
|
|
196
|
+
url: z.string().nullable().optional().meta({ description: "Where the number links: the list of what it counts." }),
|
|
197
|
+
target: z.number().positive().nullable().optional().meta({ description: "A target for the number, drawn as a meter under it, as for a `stat`." }),
|
|
198
|
+
points: z.array(SeriesPoint).nullable().optional().meta({ description: "Its trend: one point per period, the dates going up, drawn as a small line." }),
|
|
199
|
+
period: z.enum(WIDGET_SERIES_PERIODS).nullable().optional().meta({ description: "The period of each point." }),
|
|
200
|
+
parts: z.array(BreakdownWidgetItem).max(10).nullable().optional().meta({ description: `Its largest parts, at most 10: clients draw the 5 largest as bars, and the rest with \`other\`.` }),
|
|
201
|
+
other: z.number().nullable().optional().meta({ description: "The rest of the value, past the parts: drawn last, as \"Other\"." }),
|
|
202
|
+
format: WidgetNumberFormat.nullable().optional()
|
|
203
|
+
}).superRefine((data, context) => {
|
|
204
|
+
checkPointDates(data.points, ["points"], context);
|
|
205
|
+
}).meta({ description: "The data of a `metric` widget: one subject in one card, its number, its change from the previous period, its trend and its parts (decision 0089)." });
|
|
206
|
+
var TableWidgetColumn = z.looseObject({
|
|
207
|
+
key: z.string().min(1).meta({ description: "The key of its cells in each row." }),
|
|
208
|
+
label: z.string().meta({ description: "Its header, translated." }),
|
|
209
|
+
align: z.enum(WIDGET_TABLE_ALIGNS).optional().meta({ description: "`end` (the default) for numbers, or `start`." }),
|
|
210
|
+
format: WidgetNumberFormat.nullable().optional().meta({ description: "How its numbers are written: the `format` of the widget by default." })
|
|
211
|
+
}).meta({ description: "A column of a `table` widget." });
|
|
212
|
+
var TableWidgetCell = z.union([
|
|
213
|
+
z.number(),
|
|
214
|
+
z.null(),
|
|
215
|
+
z.looseObject({
|
|
216
|
+
value: z.number().nullable().meta({ description: "The number, `null` for none." }),
|
|
217
|
+
tone: ToneName.nullable().optional().meta({ description: "A tone, only when the number calls for attention." }),
|
|
218
|
+
help: z.string().nullable().optional().meta({ description: "A word after the number, translated: `rejected` in `6 rejected`." }),
|
|
219
|
+
format: WidgetNumberFormat.nullable().optional().meta({ description: "How this number is written, instead of the format of its column." })
|
|
220
|
+
})
|
|
221
|
+
]).meta({ description: "A cell of a `table` widget: a number, `null` for none, or a number with a tone and a word." });
|
|
222
|
+
var TableWidgetRow = z.looseObject({
|
|
223
|
+
label: z.string().meta({ description: "What the row is about, in its first column." }),
|
|
224
|
+
url: z.string().nullable().optional().meta({ description: "Where its label links." }),
|
|
225
|
+
cells: z.record(z.string(), TableWidgetCell).meta({ description: "Its cells, by the `key` of their column. A cell missing is empty." }),
|
|
226
|
+
points: z.array(SeriesPoint).nullable().optional().meta({ description: "Its trend, drawn as a small line in a last column: the dates going up." })
|
|
227
|
+
}).meta({ description: "A row of a `table` widget: one subject." });
|
|
228
|
+
var TableWidgetData = z.looseObject({
|
|
229
|
+
columns: z.array(TableWidgetColumn).min(1).max(6).meta({ description: `Its columns of numbers, at most 6, after the column of the labels.` }),
|
|
230
|
+
rows: z.array(TableWidgetRow).max(8).meta({ description: `Its rows, at most 8.` }),
|
|
231
|
+
period: z.enum(WIDGET_SERIES_PERIODS).nullable().optional().meta({ description: "The period of the points of the rows." }),
|
|
232
|
+
empty: z.string().nullable().optional().meta({ description: "The message without rows, translated." }),
|
|
233
|
+
url: z.string().nullable().optional().meta({ description: "Where \"See all\" links." }),
|
|
234
|
+
format: WidgetNumberFormat.nullable().optional()
|
|
235
|
+
}).superRefine((data, context) => {
|
|
236
|
+
const keys = /* @__PURE__ */ new Set();
|
|
237
|
+
data.columns.forEach((column, index) => {
|
|
238
|
+
if (keys.has(column.key)) context.addIssue({
|
|
239
|
+
code: "custom",
|
|
240
|
+
message: `Duplicate column key \`${column.key}\`.`,
|
|
241
|
+
path: [
|
|
242
|
+
"columns",
|
|
243
|
+
index,
|
|
244
|
+
"key"
|
|
245
|
+
]
|
|
246
|
+
});
|
|
247
|
+
keys.add(column.key);
|
|
248
|
+
});
|
|
249
|
+
data.rows.forEach((row, index) => {
|
|
250
|
+
checkPointDates(row.points, [
|
|
251
|
+
"rows",
|
|
252
|
+
index,
|
|
253
|
+
"points"
|
|
254
|
+
], context);
|
|
255
|
+
});
|
|
256
|
+
}).meta({ description: "The data of a `table` widget: rows of numbers, one per subject, with an optional trend (decision 0089)." });
|
|
257
|
+
/** The schema of the data of each built-in widget type. */
|
|
258
|
+
var widgetDataSchemas = {
|
|
259
|
+
stat: StatWidgetData,
|
|
260
|
+
series: SeriesWidgetData,
|
|
261
|
+
list: ListWidgetData,
|
|
262
|
+
breakdown: BreakdownWidgetData,
|
|
263
|
+
metric: MetricWidgetData,
|
|
264
|
+
table: TableWidgetData
|
|
265
|
+
};
|
|
266
|
+
//#endregion
|
|
267
|
+
export { BreakdownWidgetData, BreakdownWidgetItem, ListWidgetData, ListWidgetItem, MetricWidgetData, OverviewPeriod, SeriesPoint, SeriesWidgetData, SeriesWidgetSeries, StatWidgetData, TableWidgetCell, TableWidgetColumn, TableWidgetData, TableWidgetRow, Widget, WidgetAlert, WidgetAlertSettings, WidgetBadge, WidgetNumberFormat, WidgetRowSource, WidgetSeriesSource, WidgetSettings, widgetDataSchemas };
|
|
268
|
+
|
|
269
|
+
//# sourceMappingURL=widget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.js","names":[],"sources":["../../src/schemas/widget.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { CURRENCY_CODES } from '../currencies';\nimport { OVERVIEW_PERIODS } from '../periods';\nimport {\n WIDGET_BREAKDOWN_MAX_ITEMS,\n WIDGET_FORMAT_CURRENCY_DISPLAYS,\n WIDGET_FORMAT_NOTATIONS,\n WIDGET_FORMAT_SIGN_DISPLAYS,\n WIDGET_FORMAT_STYLES,\n WIDGET_FORMAT_UNIT_DISPLAYS,\n WIDGET_GOOD_WHEN,\n WIDGET_LIST_MAX_ITEMS,\n WIDGET_SERIES_MAX_SERIES,\n WIDGET_SERIES_PERIODS,\n WIDGET_SOURCES_MAX,\n WIDGET_TABLE_ALIGNS,\n WIDGET_TABLE_MAX_COLUMNS,\n WIDGET_TABLE_MAX_ROWS,\n isWidgetUnit,\n} from '../widgets';\n\nconst ToneName = z.string().regex(/^[a-z0-9-]+$/);\n\nconst QueryValue = z.union([z.string(), z.number(), z.boolean()]);\n\nconst WidgetQuery = z.record(z.string(), z.union([QueryValue, z.array(QueryValue)]));\n\nconst FractionDigits = z.number().int().min(0).max(20);\n\nexport const WidgetNumberFormat = z\n .looseObject({\n style: z.enum(WIDGET_FORMAT_STYLES).optional().meta({\n description:\n '`decimal` (the default), `percent` (`0.12` is `12%`), `currency` (with `currency`) or `unit` (with `unit`).',\n }),\n currency: z\n .enum(CURRENCY_CODES)\n .optional()\n .meta({ description: 'With `style: \"currency\"`: an ISO 4217 code, `USD`.' }),\n currencyDisplay: z.enum(WIDGET_FORMAT_CURRENCY_DISPLAYS).optional(),\n unit: z\n .string()\n .refine(isWidgetUnit, {\n message: 'A unit of `Intl.NumberFormat`: `byte`, `megabyte`, `kilometer-per-hour`.',\n })\n .optional()\n .meta({\n description:\n 'With `style: \"unit\"`: a unit of `Intl.NumberFormat` (`byte`, `kilobyte`, `megabyte`, `gigabyte`, `second`, `minute`, `hour`…), or two of them joined by `-per-`.',\n }),\n unitDisplay: z.enum(WIDGET_FORMAT_UNIT_DISPLAYS).optional(),\n minimumFractionDigits: FractionDigits.optional(),\n maximumFractionDigits: FractionDigits.optional(),\n notation: z.enum(WIDGET_FORMAT_NOTATIONS).optional().meta({\n description: '`compact` writes `1.2K` and `3.4M`.',\n }),\n signDisplay: z.enum(WIDGET_FORMAT_SIGN_DISPLAYS).optional(),\n })\n .superRefine((format, context) => {\n if (format.style === 'currency' && format.currency === undefined) {\n context.addIssue({\n code: 'custom',\n message: 'A `currency` style needs a `currency`.',\n path: ['currency'],\n });\n }\n if (format.style === 'unit' && format.unit === undefined) {\n context.addIssue({\n code: 'custom',\n message: 'A `unit` style needs a `unit`.',\n path: ['unit'],\n });\n }\n if (\n format.minimumFractionDigits !== undefined &&\n format.maximumFractionDigits !== undefined &&\n format.minimumFractionDigits > format.maximumFractionDigits\n ) {\n context.addIssue({\n code: 'custom',\n message: '`minimumFractionDigits` is above `maximumFractionDigits`.',\n path: ['minimumFractionDigits'],\n });\n }\n })\n .meta({\n description:\n 'How the numbers of a widget are written: options of `Intl.NumberFormat`, for the locale of the user (decision 0089). `{ \"style\": \"currency\", \"currency\": \"USD\" }` writes `9.08` as `$9.08`, `{ \"style\": \"unit\", \"unit\": \"megabyte\" }` as `9.08 MB`.',\n });\n\nexport const WidgetAlertSettings = z\n .looseObject({\n query: WidgetQuery.meta({\n description:\n 'The filters of the items to count, as query parameters, on top of those of their source: `{ \"filter[status]\": \"failed\" }`.',\n }),\n label: z.string().min(1).meta({\n description: 'What they are, written after their count, translated: `failed`.',\n }),\n tone: ToneName.optional().meta({\n description: 'The tone of the count, when it is above 0. `danger` by default.',\n }),\n })\n .meta({\n description:\n 'Items of a source that call for attention (decision 0089): counted with the same query and period, and shown as `4 failed` when there are some.',\n });\n\nconst SourcePeriod = z.union([z.string().min(1), z.literal(false)]);\n\nexport const WidgetSeriesSource = z\n .looseObject({\n resource: z.string().min(1).meta({ description: 'The resource it counts or sums.' }),\n label: z.string().min(1).meta({ description: 'The name of its line, in the legend.' }),\n query: WidgetQuery.optional(),\n measure: z.string().min(1).optional().meta({\n description: '`count` (the default), or `sum:{field}`.',\n }),\n group: z.string().min(1).optional().meta({\n description: '`{period}:{date field}`: `settings.group` of the widget by default.',\n }),\n period: SourcePeriod.optional().meta({\n description:\n \"The `date-range` filter of its list that gets the period of the overview: `settings.period` of the widget by default. `false`: it doesn't follow the period.\",\n }),\n help: z.string().optional().meta({ description: 'A line under its label in the legend.' }),\n tone: ToneName.optional().meta({\n description: 'The tone of its line, instead of a categorical color.',\n }),\n alert: WidgetAlertSettings.optional(),\n })\n .meta({\n description:\n 'A line of a `series` on resources (decision 0089): the count or the sum of a resource per period.',\n });\n\nexport const WidgetRowSource = z\n .looseObject({\n resource: z.string().min(1).meta({ description: 'The resource it counts or sums.' }),\n label: z.string().min(1).meta({ description: 'The name of the row.' }),\n query: WidgetQuery.optional(),\n measure: z.string().min(1).optional().meta({\n description: '`count` (the default), or `sum:{field}`.',\n }),\n points: z.string().min(1).optional().meta({\n description:\n '`{period}:{date field}`: the points of its trend. `settings.points` of the widget by default.',\n }),\n period: SourcePeriod.optional().meta({\n description:\n 'The `date-range` filter of its list that gets the period of the overview, and the previous one for its change: `settings.period` of the widget by default.',\n }),\n alert: WidgetAlertSettings.optional(),\n })\n .meta({\n description:\n 'A row of a `table` on resources (decision 0089): one subject, counted or summed over the period.',\n });\n\nexport const WidgetSettings = z\n .looseObject({\n resource: z.string().min(1).optional().meta({\n description:\n 'Built-in types: the resource that feeds the widget. A `stat` counts the items of its list (`meta.total`), a `list` shows its first items, and a `series`, a `breakdown` and a `stat` with a `sum:` measure read `GET /resources/{resource}/aggregate` (decision 0084). Such a widget has no data at `GET /dashboard/widgets/{widget}`.',\n }),\n query: z\n .record(z.string(), z.union([QueryValue, z.array(QueryValue)]))\n .optional()\n .meta({\n description:\n 'With `resource`: the query of the list, as its query parameters (`{ \"filter[status]\": \"to-judge\", \"sort\": \"-created_at\" }`), and of the link to the list. The client sets `page`, `perPage` and `cursor`.',\n }),\n measure: z.string().min(1).optional().meta({\n description:\n 'With `resource`, for a `stat`, a `series` and a `breakdown`: `count` (the default), or `sum:{field}` of a field of the `sum` of the aggregates of the list.',\n }),\n group: z.string().min(1).optional().meta({\n description:\n 'With `resource`: for a `series`, `{period}:{date field}` (`day`, `week` or `month`, and a field of `dates` of the aggregates of the list); for a `breakdown`, a field of their `groupBy`.',\n }),\n target: z.number().positive().optional().meta({\n description:\n 'With `resource`, for a `stat`: its `target` (a budget, a quota), in the unit of the value: minor units for a sum of `money`.',\n }),\n period: z\n .union([z.string().min(1), z.literal(false)])\n .optional()\n .meta({\n description:\n \"In an overview with a `period` (decision 0084). With `resource`: the id of the list's `date-range` filter that gets the days of the chosen period. `false`: the widget doesn't follow the period; a widget with data of its own then gets no `period` parameters.\",\n }),\n followsList: z.boolean().optional().meta({\n description:\n \"In the summary of a resource (decision 0084): `false` keeps the widget on the whole resource, without the list's current filters and search. Widgets on that resource, and widgets with data of their own, follow the list by default.\",\n }),\n format: WidgetNumberFormat.optional().meta({\n description:\n 'Built-in types: how their numbers are written (decision 0089). It wins over the `format` of their data, key by key. A sum of `money` is written in its currency without it.',\n }),\n hideEmpty: z.boolean().optional().meta({\n description:\n 'Built-in types: `true` hides the widget when its data has nothing to show (a value of 0, no items, no rows), and the grid closes the gap (decision 0089).',\n }),\n goodWhen: z.enum(WIDGET_GOOD_WHEN).optional().meta({\n description:\n 'A `metric` or a `table`: whether a rise (`up`) or a fall (`down`) is good news, so that its change from the previous period is colored `success` or `danger`. Neutral without it.',\n }),\n points: z.string().min(1).optional().meta({\n description:\n 'With `resource`, for a `metric`: `{period}:{date field}`, the points of its trend line. For a `table`, the default of its rows.',\n }),\n by: z.string().min(1).optional().meta({\n description:\n 'With `resource`, for a `metric`: a field of the `groupBy` of the aggregates of the list, whose largest parts are drawn under the number.',\n }),\n split: z\n .string()\n .min(1)\n .optional()\n .meta({\n description: `With \\`resource\\` and a \\`group\\` on a period, for a \\`series\\`: a field of the \\`groupBy\\` of the aggregates of the list with a filter of its own. A line per value, for the ${WIDGET_SOURCES_MAX} largest, and the rest as \"Other\".`,\n }),\n sources: z\n .array(WidgetSeriesSource)\n .min(1)\n .max(WIDGET_SOURCES_MAX)\n .optional()\n .meta({\n description: `A \\`series\\` without \\`resource\\`: a line per source, at most ${WIDGET_SOURCES_MAX}, each from a resource.`,\n }),\n stacked: z.boolean().optional().meta({\n description: 'A `series` with several lines: stacks them, as areas.',\n }),\n rows: z\n .array(WidgetRowSource)\n .min(1)\n .max(WIDGET_TABLE_MAX_ROWS)\n .optional()\n .meta({\n description: `A \\`table\\` on resources: its rows, at most ${WIDGET_TABLE_MAX_ROWS}, each a count or a sum of a resource.`,\n }),\n })\n .meta({\n description:\n 'The settings of a widget: `resource`, `query`, `measure`, `group`, `target`, `points`, `by` and `split` for the built-in types on a resource, `sources` and `rows` for those on several, `period` in an overview with a period, `followsList` in a summary, `format`, `hideEmpty` and `goodWhen` for how they are drawn, anything else for widgets of plugins.',\n });\n\nexport const OverviewPeriod = z\n .looseObject({\n options: z.array(z.enum(OVERVIEW_PERIODS)).min(1).meta({\n description:\n 'The periods the user chooses from, in order: `7d`, `30d` and `90d`, the 7, 30 or 90 days ending today; `month`, the current calendar month, from its first day to today; `year`, the last 12 months, from the first day of the month 11 months ago to today. Days are those of the time zone of the browser.',\n }),\n default: z.enum(OVERVIEW_PERIODS).optional().meta({\n description:\n 'The period the overview opens on, among `options`. Defaults to the first.',\n }),\n })\n .meta({\n description:\n 'One period for the widgets of a dashboard page or a summary, chosen in its header and kept in the URL (`?period=30d`, decision 0084).',\n });\n\nexport const Widget = z.looseObject({\n id: z\n .string()\n .min(1)\n .meta({ description: 'Unique in its dashboard: the `{widget}` of its route.' }),\n type: z.string().min(1).meta({\n description:\n 'Built-in: `stat` (a number), `series` (lines over days, weeks or months), `list` (a few items), `breakdown` (the parts of a total), `metric` (a number with its change, its trend and its parts) and `table` (rows of numbers). Other types are widgets of plugins.',\n }),\n label: z.string().optional(),\n width: z.number().int().min(1).max(12).optional().meta({\n description:\n 'Columns of a grid of 12. Defaults to 3 for a `stat`, 6 for others. One column on a phone.',\n }),\n settings: WidgetSettings.optional(),\n});\n\nexport const WidgetBadge = z\n .looseObject({ label: z.string(), tone: ToneName.optional() })\n .meta({ description: 'A badge: a word, in a tone of the theme.' });\n\nexport const StatWidgetData = z\n .looseObject({\n value: z.number().meta({ description: 'The number, in large type.' }),\n help: z.string().nullable().optional().meta({\n description: 'A line under the number, translated: `3 more than last week`.',\n }),\n tone: ToneName.nullable().optional().meta({\n description:\n 'A tone of the theme, only when the number calls for attention (`warning`, `danger`): neutral otherwise, and at 0.',\n }),\n url: z\n .string()\n .nullable()\n .optional()\n .meta({ description: 'Where the widget links: the list of what it counts.' }),\n target: z.number().positive().nullable().optional().meta({\n description:\n 'A target for the number (a budget, a quota), drawn as a meter under it. Past it, the meter takes `tone`, or `danger` without one (decision 0084).',\n }),\n format: WidgetNumberFormat.nullable().optional(),\n })\n .meta({ description: 'The data of a `stat` widget: a number (decision 0064).' });\n\nexport const SeriesPoint = z.looseObject({\n date: z\n .string()\n .regex(/^\\d{4}-\\d{2}-\\d{2}$/)\n .meta({ description: 'The first day of the period: `2026-10-05`.' }),\n value: z.number(),\n});\n\n/** The dates of points must go up: one point per period. */\nfunction checkPointDates(\n points: readonly SeriesPoint[] | null | undefined,\n path: (string | number)[],\n context: z.RefinementCtx,\n) {\n (points ?? []).forEach((point, index) => {\n const previous = points?.[index - 1];\n if (previous !== undefined && point.date <= previous.date) {\n context.addIssue({\n code: 'custom',\n message: 'The dates of the points must go up.',\n path: [...path, index, 'date'],\n });\n }\n });\n}\n\nexport const WidgetAlert = z\n .looseObject({\n value: z.number().meta({ description: 'How many items call for attention.' }),\n label: z.string().meta({\n description: 'What they are, written after their count, translated: `failed`.',\n }),\n tone: ToneName.nullable().optional().meta({\n description: 'The tone of the count, above 0. `danger` by default.',\n }),\n })\n .meta({\n description:\n 'A count that calls for attention (decision 0089): `4 failed`, in its tone, shown when it is above 0.',\n });\n\nexport const SeriesWidgetSeries = z\n .looseObject({\n key: z.union([z.string(), z.number(), z.boolean()]).nullable().optional().meta({\n description: 'The value it is the line of, for a line per value of a field.',\n }),\n label: z.string().meta({ description: 'Its name, in the legend.' }),\n points: z.array(SeriesPoint).meta({\n description: 'One point per period, the dates going up. A date missing is 0.',\n }),\n total: z.number().nullable().optional().meta({\n description: 'Its total over the points, in the legend.',\n }),\n tone: ToneName.nullable().optional().meta({\n description: 'The tone of its line, instead of a categorical color.',\n }),\n url: z.string().nullable().optional().meta({ description: 'Where its legend links.' }),\n help: z.string().nullable().optional().meta({\n description: 'A line under its label in the legend.',\n }),\n alert: WidgetAlert.nullable().optional(),\n })\n .meta({ description: 'A line of a `series` with several (decision 0089).' });\n\nexport const SeriesWidgetData = z\n .looseObject({\n period: z.enum(WIDGET_SERIES_PERIODS).meta({ description: 'The period of each point.' }),\n points: z.array(SeriesPoint).meta({\n description:\n 'One point per period, the dates going up. Periods without a value are points at 0. With `series`, the total of the lines per period, or none (`[]`): clients that only draw one line draw it.',\n }),\n series: z\n .array(SeriesWidgetSeries)\n .max(WIDGET_SERIES_MAX_SERIES)\n .optional()\n .meta({\n description: `Several lines, at most ${WIDGET_SERIES_MAX_SERIES}, instead of \\`points\\` (decision 0089): one chart, with a legend of their labels, totals and help.`,\n }),\n total: z.number().nullable().optional().meta({\n description: 'The total over the points, shown with the line.',\n }),\n format: WidgetNumberFormat.nullable().optional(),\n })\n .superRefine((data, context) => {\n checkPointDates(data.points, ['points'], context);\n data.series?.forEach((series, index) => {\n checkPointDates(series.points, ['series', index, 'points'], context);\n });\n })\n .meta({\n description:\n 'The data of a `series` widget: a line of values per period (decision 0064), or several (decision 0089).',\n });\n\nexport const ListWidgetItem = z.looseObject({\n title: z.string(),\n description: z.string().nullable().optional(),\n meta: z\n .string()\n .nullable()\n .optional()\n .meta({ description: 'A short fact at the end of the item: `12 answers`.' }),\n url: z.string().nullable().optional(),\n badge: WidgetBadge.nullable().optional(),\n});\n\nexport const ListWidgetData = z\n .looseObject({\n items: z\n .array(ListWidgetItem)\n .max(WIDGET_LIST_MAX_ITEMS)\n .meta({\n description: `At most ${WIDGET_LIST_MAX_ITEMS} items, the most useful first.`,\n }),\n empty: z.string().nullable().optional().meta({\n description: 'The message without items, translated: `No open contests.`',\n }),\n url: z\n .string()\n .nullable()\n .optional()\n .meta({ description: 'Where \"See all\" links, under the items.' }),\n })\n .meta({ description: 'The data of a `list` widget: a few items (decision 0064).' });\n\nexport const BreakdownWidgetItem = z.looseObject({\n label: z.string().meta({ description: 'What the part is, translated: `Failed`.' }),\n value: z.number().meta({ description: 'The count or the sum of the part.' }),\n tone: ToneName.nullable().optional().meta({\n description: 'A tone of the theme for its bar: the tone of an option of a `select`.',\n }),\n url: z\n .string()\n .nullable()\n .optional()\n .meta({ description: 'Where the bar links: the list of what it counts.' }),\n key: z.union([z.string(), z.number(), z.boolean()]).nullable().optional().meta({\n description:\n 'From `GET /resources/{resource}/aggregate`: the value of the field it groups, `null` for the items without one. The client links the bar to the list filtered by it.',\n }),\n});\n\nexport const BreakdownWidgetData = z\n .looseObject({\n items: z\n .array(BreakdownWidgetItem)\n .max(WIDGET_BREAKDOWN_MAX_ITEMS)\n .meta({\n description: `The parts, at most ${WIDGET_BREAKDOWN_MAX_ITEMS}: clients draw the largest first.`,\n }),\n total: z.number().nullable().optional().meta({\n description:\n 'The total the parts are of. Items with several values count in each of their parts, and once in the total.',\n }),\n other: z.number().nullable().optional().meta({\n description: 'The rest of the total, past the items: drawn last, as \"Other\".',\n }),\n format: WidgetNumberFormat.nullable().optional(),\n })\n .meta({\n description:\n 'The data of a `breakdown` widget: the parts of a total, as horizontal bars (decision 0084).',\n });\n\nexport const MetricWidgetData = z\n .looseObject({\n value: z.number().meta({ description: 'The number, in large type.' }),\n previous: z.number().nullable().optional().meta({\n description:\n 'The same number over the previous period, of the same length (`getPreviousRange()`): the change from it is written under the number.',\n }),\n help: z.string().nullable().optional().meta({\n description: 'A line under the number, translated.',\n }),\n tone: ToneName.nullable().optional().meta({\n description: 'A tone of the theme, only when the number calls for attention.',\n }),\n url: z.string().nullable().optional().meta({\n description: 'Where the number links: the list of what it counts.',\n }),\n target: z.number().positive().nullable().optional().meta({\n description: 'A target for the number, drawn as a meter under it, as for a `stat`.',\n }),\n points: z.array(SeriesPoint).nullable().optional().meta({\n description:\n 'Its trend: one point per period, the dates going up, drawn as a small line.',\n }),\n period: z.enum(WIDGET_SERIES_PERIODS).nullable().optional().meta({\n description: 'The period of each point.',\n }),\n parts: z\n .array(BreakdownWidgetItem)\n .max(WIDGET_BREAKDOWN_MAX_ITEMS)\n .nullable()\n .optional()\n .meta({\n description: `Its largest parts, at most ${WIDGET_BREAKDOWN_MAX_ITEMS}: clients draw the 5 largest as bars, and the rest with \\`other\\`.`,\n }),\n other: z.number().nullable().optional().meta({\n description: 'The rest of the value, past the parts: drawn last, as \"Other\".',\n }),\n format: WidgetNumberFormat.nullable().optional(),\n })\n .superRefine((data, context) => {\n checkPointDates(data.points, ['points'], context);\n })\n .meta({\n description:\n 'The data of a `metric` widget: one subject in one card, its number, its change from the previous period, its trend and its parts (decision 0089).',\n });\n\nexport const TableWidgetColumn = z\n .looseObject({\n key: z.string().min(1).meta({ description: 'The key of its cells in each row.' }),\n label: z.string().meta({ description: 'Its header, translated.' }),\n align: z.enum(WIDGET_TABLE_ALIGNS).optional().meta({\n description: '`end` (the default) for numbers, or `start`.',\n }),\n format: WidgetNumberFormat.nullable().optional().meta({\n description: 'How its numbers are written: the `format` of the widget by default.',\n }),\n })\n .meta({ description: 'A column of a `table` widget.' });\n\nexport const TableWidgetCell = z\n .union([\n z.number(),\n z.null(),\n z.looseObject({\n value: z.number().nullable().meta({ description: 'The number, `null` for none.' }),\n tone: ToneName.nullable().optional().meta({\n description: 'A tone, only when the number calls for attention.',\n }),\n help: z.string().nullable().optional().meta({\n description: 'A word after the number, translated: `rejected` in `6 rejected`.',\n }),\n format: WidgetNumberFormat.nullable().optional().meta({\n description: 'How this number is written, instead of the format of its column.',\n }),\n }),\n ])\n .meta({\n description:\n 'A cell of a `table` widget: a number, `null` for none, or a number with a tone and a word.',\n });\n\nexport const TableWidgetRow = z\n .looseObject({\n label: z.string().meta({ description: 'What the row is about, in its first column.' }),\n url: z.string().nullable().optional().meta({ description: 'Where its label links.' }),\n cells: z.record(z.string(), TableWidgetCell).meta({\n description: 'Its cells, by the `key` of their column. A cell missing is empty.',\n }),\n points: z.array(SeriesPoint).nullable().optional().meta({\n description: 'Its trend, drawn as a small line in a last column: the dates going up.',\n }),\n })\n .meta({ description: 'A row of a `table` widget: one subject.' });\n\nexport const TableWidgetData = z\n .looseObject({\n columns: z\n .array(TableWidgetColumn)\n .min(1)\n .max(WIDGET_TABLE_MAX_COLUMNS)\n .meta({\n description: `Its columns of numbers, at most ${WIDGET_TABLE_MAX_COLUMNS}, after the column of the labels.`,\n }),\n rows: z\n .array(TableWidgetRow)\n .max(WIDGET_TABLE_MAX_ROWS)\n .meta({ description: `Its rows, at most ${WIDGET_TABLE_MAX_ROWS}.` }),\n period: z.enum(WIDGET_SERIES_PERIODS).nullable().optional().meta({\n description: 'The period of the points of the rows.',\n }),\n empty: z.string().nullable().optional().meta({\n description: 'The message without rows, translated.',\n }),\n url: z.string().nullable().optional().meta({ description: 'Where \"See all\" links.' }),\n format: WidgetNumberFormat.nullable().optional(),\n })\n .superRefine((data, context) => {\n const keys = new Set<string>();\n data.columns.forEach((column, index) => {\n if (keys.has(column.key)) {\n context.addIssue({\n code: 'custom',\n message: `Duplicate column key \\`${column.key}\\`.`,\n path: ['columns', index, 'key'],\n });\n }\n keys.add(column.key);\n });\n data.rows.forEach((row, index) => {\n checkPointDates(row.points, ['rows', index, 'points'], context);\n });\n })\n .meta({\n description:\n 'The data of a `table` widget: rows of numbers, one per subject, with an optional trend (decision 0089).',\n });\n\n/** The schema of the data of each built-in widget type. */\nexport const widgetDataSchemas = {\n stat: StatWidgetData,\n series: SeriesWidgetData,\n list: ListWidgetData,\n breakdown: BreakdownWidgetData,\n metric: MetricWidgetData,\n table: TableWidgetData,\n} as const;\n\nexport type OverviewPeriod = z.infer<typeof OverviewPeriod>;\nexport type WidgetSettings = z.infer<typeof WidgetSettings>;\nexport type Widget = z.infer<typeof Widget>;\nexport type WidgetBadge = z.infer<typeof WidgetBadge>;\nexport type StatWidgetData = z.infer<typeof StatWidgetData>;\nexport type SeriesPoint = z.infer<typeof SeriesPoint>;\nexport type SeriesWidgetData = z.infer<typeof SeriesWidgetData>;\nexport type ListWidgetItem = z.infer<typeof ListWidgetItem>;\nexport type ListWidgetData = z.infer<typeof ListWidgetData>;\nexport type BreakdownWidgetItem = z.infer<typeof BreakdownWidgetItem>;\nexport type BreakdownWidgetData = z.infer<typeof BreakdownWidgetData>;\nexport type WidgetNumberFormat = z.infer<typeof WidgetNumberFormat>;\nexport type WidgetAlertSettings = z.infer<typeof WidgetAlertSettings>;\nexport type WidgetSeriesSource = z.infer<typeof WidgetSeriesSource>;\nexport type WidgetRowSource = z.infer<typeof WidgetRowSource>;\nexport type WidgetAlert = z.infer<typeof WidgetAlert>;\nexport type SeriesWidgetSeries = z.infer<typeof SeriesWidgetSeries>;\nexport type MetricWidgetData = z.infer<typeof MetricWidgetData>;\nexport type TableWidgetColumn = z.infer<typeof TableWidgetColumn>;\nexport type TableWidgetCell = z.infer<typeof TableWidgetCell>;\nexport type TableWidgetRow = z.infer<typeof TableWidgetRow>;\nexport type TableWidgetData = z.infer<typeof TableWidgetData>;\n"],"mappings":";;;;;AAsBA,IAAM,WAAW,EAAE,OAAO,CAAC,CAAC,MAAM,cAAc;AAEhD,IAAM,aAAa,EAAE,MAAM;CAAC,EAAE,OAAO;CAAG,EAAE,OAAO;CAAG,EAAE,QAAQ;AAAC,CAAC;AAEhE,IAAM,cAAc,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,UAAU,CAAC,CAAC,CAAC;AAEnF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Aa,MAAM,YAAY;CAC5B,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAAK,QAAQ,SAAS,QAAQ,UAAU;EACpC,IAAI,KAAK,IAAI,OAAO,GAAG,GACnB,QAAQ,SAAS;GACb,MAAM;GACN,SAAS,0BAA0B,OAAO,IAAI;GAC9C,MAAM;IAAC;IAAW;IAAO;GAAK;EAClC,CAAC;EAEL,KAAK,IAAI,OAAO,GAAG;CACvB,CAAC;CACD,KAAK,KAAK,SAAS,KAAK,UAAU;EAC9B,gBAAgB,IAAI,QAAQ;GAAC;GAAQ;GAAO;EAAQ,GAAG,OAAO;CAClE,CAAC;AACL,CAAC,CAAC,CACD,KAAK,EACF,aACI,0GACR,CAAC;;AAGL,IAAa,oBAAoB;CAC7B,MAAM;CACN,QAAQ;CACR,MAAM;CACN,WAAW;CACX,QAAQ;CACR,OAAO;AACX"}
|
package/dist/search.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Shortest search, in characters once trimmed: shorter is a `422`. */
|
|
2
|
+
export declare const SEARCH_MIN_LENGTH = 2;
|
|
3
|
+
/** Longest search, in characters. */
|
|
4
|
+
export declare const SEARCH_MAX_LENGTH = 255;
|
|
5
|
+
/** Items per resource without a `limit`. */
|
|
6
|
+
export declare const SEARCH_DEFAULT_LIMIT = 5;
|
|
7
|
+
/** Highest `limit`, and most items of a response, every resource together. */
|
|
8
|
+
export declare const SEARCH_MAX_LIMIT = 20;
|
|
9
|
+
/** What the global search reads of a resource. */
|
|
10
|
+
export interface SearchableResource {
|
|
11
|
+
id: string;
|
|
12
|
+
features?: {
|
|
13
|
+
search?: boolean | undefined;
|
|
14
|
+
} | undefined;
|
|
15
|
+
list?: {
|
|
16
|
+
search?: boolean | undefined;
|
|
17
|
+
} | undefined;
|
|
18
|
+
}
|
|
19
|
+
/** Query of the global search (`GET /search`). */
|
|
20
|
+
export interface SearchQuery {
|
|
21
|
+
q: string;
|
|
22
|
+
/** Items per resource, from 1 to 20. Defaults to 5. */
|
|
23
|
+
limit?: number;
|
|
24
|
+
/** Ids of the searchable resources to search. Defaults to every one. */
|
|
25
|
+
resources?: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Whether a resource is in the global search: its `features.search`, or, without it, whether its
|
|
29
|
+
* list has a search (`list.search`), so one setting serves both (decision 0029).
|
|
30
|
+
*/
|
|
31
|
+
export declare function isSearchableResource(resource: Omit<SearchableResource, 'id'>): boolean;
|
|
32
|
+
/** Serializes a search query: `q=été&limit=20&resources=pages,articles`. */
|
|
33
|
+
export declare function toSearchQueryParams(query: SearchQuery): URLSearchParams;
|
|
34
|
+
/** A search query as a backend reads it: valid, or the messages of its invalid parameters. */
|
|
35
|
+
export type ReadSearchQueryResult = {
|
|
36
|
+
query: Required<SearchQuery>;
|
|
37
|
+
errors?: undefined;
|
|
38
|
+
} | {
|
|
39
|
+
query?: undefined;
|
|
40
|
+
errors: Record<string, string[]>;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Reads the query string of `GET /search`: the reference of how a backend validates it. `q` is
|
|
44
|
+
* trimmed and needs 2 characters; `limit` is an integer from 1 to 20; `resources` lists searchable
|
|
45
|
+
* resources of the definition. Invalid parameters are a `422`, with `errors` keyed by parameter.
|
|
46
|
+
* Without `resources`, every searchable resource is searched, in the order of the definition.
|
|
47
|
+
*/
|
|
48
|
+
export declare function readSearchQuery(params: URLSearchParams, definition: {
|
|
49
|
+
resources: readonly SearchableResource[];
|
|
50
|
+
}): ReadSearchQueryResult;
|
|
51
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,eAAO,MAAM,iBAAiB,IAAI,CAAC;AACnC,qCAAqC;AACrC,eAAO,MAAM,iBAAiB,MAAM,CAAC;AACrC,4CAA4C;AAC5C,eAAO,MAAM,oBAAoB,IAAI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422`. */
|
|
3
|
+
var SEARCH_MIN_LENGTH = 2;
|
|
4
|
+
/** Longest search, in characters. */
|
|
5
|
+
var SEARCH_MAX_LENGTH = 255;
|
|
6
|
+
/** Items per resource without a `limit`. */
|
|
7
|
+
var SEARCH_DEFAULT_LIMIT = 5;
|
|
8
|
+
/** Highest `limit`, and most items of a response, every resource together. */
|
|
9
|
+
var SEARCH_MAX_LIMIT = 20;
|
|
10
|
+
/**
|
|
11
|
+
* Whether a resource is in the global search: its `features.search`, or, without it, whether its
|
|
12
|
+
* list has a search (`list.search`), so one setting serves both (decision 0029).
|
|
13
|
+
*/
|
|
14
|
+
function isSearchableResource(resource) {
|
|
15
|
+
return resource.features?.search ?? resource.list?.search ?? false;
|
|
16
|
+
}
|
|
17
|
+
/** Serializes a search query: `q=été&limit=20&resources=pages,articles`. */
|
|
18
|
+
function toSearchQueryParams(query) {
|
|
19
|
+
const params = new URLSearchParams({ q: query.q });
|
|
20
|
+
if (query.limit !== void 0) params.set("limit", String(query.limit));
|
|
21
|
+
if (query.resources !== void 0 && query.resources.length > 0) params.set("resources", query.resources.join(","));
|
|
22
|
+
return params;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Reads the query string of `GET /search`: the reference of how a backend validates it. `q` is
|
|
26
|
+
* trimmed and needs 2 characters; `limit` is an integer from 1 to 20; `resources` lists searchable
|
|
27
|
+
* resources of the definition. Invalid parameters are a `422`, with `errors` keyed by parameter.
|
|
28
|
+
* Without `resources`, every searchable resource is searched, in the order of the definition.
|
|
29
|
+
*/
|
|
30
|
+
function readSearchQuery(params, definition) {
|
|
31
|
+
const errors = {};
|
|
32
|
+
const q = (params.get("q") ?? "").trim();
|
|
33
|
+
if (q.length < 2) errors.q = [`The search must have at least 2 characters.`];
|
|
34
|
+
else if (q.length > 255) errors.q = [`The search must have at most 255 characters.`];
|
|
35
|
+
const rawLimit = params.get("limit");
|
|
36
|
+
const limit = rawLimit === null ? 5 : Number(rawLimit);
|
|
37
|
+
if (rawLimit !== null && (!/^\d+$/.test(rawLimit) || limit < 1 || limit > 20)) errors.limit = [`The limit must be an integer from 1 to 20.`];
|
|
38
|
+
const searchable = definition.resources.filter(isSearchableResource).map((resource) => resource.id);
|
|
39
|
+
const rawResources = params.get("resources");
|
|
40
|
+
const asked = rawResources === null ? searchable : rawResources.split(",").map((id) => id.trim()).filter((id) => id !== "");
|
|
41
|
+
const unknown = asked.filter((id) => !searchable.includes(id));
|
|
42
|
+
if (rawResources !== null && (asked.length === 0 || unknown.length > 0)) errors.resources = [unknown.length > 0 ? `These resources are not searchable: ${unknown.join(", ")}.` : "List at least one resource."];
|
|
43
|
+
if (Object.keys(errors).length > 0) return { errors };
|
|
44
|
+
return { query: {
|
|
45
|
+
q,
|
|
46
|
+
limit,
|
|
47
|
+
resources: searchable.filter((id) => asked.includes(id))
|
|
48
|
+
} };
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, isSearchableResource, readSearchQuery, toSearchQueryParams };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","names":[],"sources":["../src/search.ts"],"sourcesContent":["/** Shortest search, in characters once trimmed: shorter is a `422`. */\nexport const SEARCH_MIN_LENGTH = 2;\n/** Longest search, in characters. */\nexport const SEARCH_MAX_LENGTH = 255;\n/** Items per resource without a `limit`. */\nexport const SEARCH_DEFAULT_LIMIT = 5;\n/** Highest `limit`, and most items of a response, every resource together. */\nexport const SEARCH_MAX_LIMIT = 20;\n\n/** What the global search reads of a resource. */\nexport interface SearchableResource {\n id: string;\n features?: { search?: boolean | undefined } | undefined;\n list?: { search?: boolean | undefined } | undefined;\n}\n\n/** Query of the global search (`GET /search`). */\nexport interface SearchQuery {\n q: string;\n /** Items per resource, from 1 to 20. Defaults to 5. */\n limit?: number;\n /** Ids of the searchable resources to search. Defaults to every one. */\n resources?: readonly string[];\n}\n\n/**\n * Whether a resource is in the global search: its `features.search`, or, without it, whether its\n * list has a search (`list.search`), so one setting serves both (decision 0029).\n */\nexport function isSearchableResource(resource: Omit<SearchableResource, 'id'>): boolean {\n return resource.features?.search ?? resource.list?.search ?? false;\n}\n\n/** Serializes a search query: `q=été&limit=20&resources=pages,articles`. */\nexport function toSearchQueryParams(query: SearchQuery): URLSearchParams {\n const params = new URLSearchParams({ q: query.q });\n if (query.limit !== undefined) {\n params.set('limit', String(query.limit));\n }\n if (query.resources !== undefined && query.resources.length > 0) {\n params.set('resources', query.resources.join(','));\n }\n return params;\n}\n\n/** A search query as a backend reads it: valid, or the messages of its invalid parameters. */\nexport type ReadSearchQueryResult =\n | { query: Required<SearchQuery>; errors?: undefined }\n | { query?: undefined; errors: Record<string, string[]> };\n\n/**\n * Reads the query string of `GET /search`: the reference of how a backend validates it. `q` is\n * trimmed and needs 2 characters; `limit` is an integer from 1 to 20; `resources` lists searchable\n * resources of the definition. Invalid parameters are a `422`, with `errors` keyed by parameter.\n * Without `resources`, every searchable resource is searched, in the order of the definition.\n */\nexport function readSearchQuery(\n params: URLSearchParams,\n definition: { resources: readonly SearchableResource[] },\n): ReadSearchQueryResult {\n const errors: Record<string, string[]> = {};\n const q = (params.get('q') ?? '').trim();\n if (q.length < SEARCH_MIN_LENGTH) {\n errors.q = [`The search must have at least ${SEARCH_MIN_LENGTH} characters.`];\n } else if (q.length > SEARCH_MAX_LENGTH) {\n errors.q = [`The search must have at most ${SEARCH_MAX_LENGTH} characters.`];\n }\n\n const rawLimit = params.get('limit');\n const limit = rawLimit === null ? SEARCH_DEFAULT_LIMIT : Number(rawLimit);\n if (rawLimit !== null && (!/^\\d+$/.test(rawLimit) || limit < 1 || limit > SEARCH_MAX_LIMIT)) {\n errors.limit = [`The limit must be an integer from 1 to ${SEARCH_MAX_LIMIT}.`];\n }\n\n const searchable = definition.resources\n .filter(isSearchableResource)\n .map((resource) => resource.id);\n const rawResources = params.get('resources');\n const asked =\n rawResources === null\n ? searchable\n : rawResources\n .split(',')\n .map((id) => id.trim())\n .filter((id) => id !== '');\n const unknown = asked.filter((id) => !searchable.includes(id));\n if (rawResources !== null && (asked.length === 0 || unknown.length > 0)) {\n errors.resources = [\n unknown.length > 0\n ? `These resources are not searchable: ${unknown.join(', ')}.`\n : 'List at least one resource.',\n ];\n }\n\n if (Object.keys(errors).length > 0) {\n return { errors };\n }\n // The order of the definition, without duplicates\n const resources = searchable.filter((id) => asked.includes(id));\n return { query: { q, limit, resources } };\n}\n"],"mappings":";;AACA,IAAa,oBAAoB;;AAEjC,IAAa,oBAAoB;;AAEjC,IAAa,uBAAuB;;AAEpC,IAAa,mBAAmB;;;;;AAsBhC,SAAgB,qBAAqB,UAAmD;CACpF,OAAO,SAAS,UAAU,UAAU,SAAS,MAAM,UAAU;AACjE;;AAGA,SAAgB,oBAAoB,OAAqC;CACrE,MAAM,SAAS,IAAI,gBAAgB,EAAE,GAAG,MAAM,EAAE,CAAC;CACjD,IAAI,MAAM,UAAU,KAAA,GAChB,OAAO,IAAI,SAAS,OAAO,MAAM,KAAK,CAAC;CAE3C,IAAI,MAAM,cAAc,KAAA,KAAa,MAAM,UAAU,SAAS,GAC1D,OAAO,IAAI,aAAa,MAAM,UAAU,KAAK,GAAG,CAAC;CAErD,OAAO;AACX;;;;;;;AAaA,SAAgB,gBACZ,QACA,YACqB;CACrB,MAAM,SAAmC,CAAC;CAC1C,MAAM,KAAK,OAAO,IAAI,GAAG,KAAK,GAAA,CAAI,KAAK;CACvC,IAAI,EAAE,SAAA,GACF,OAAO,IAAI,CAAC,6CAAgE;MACzE,IAAI,EAAE,SAAA,KACT,OAAO,IAAI,CAAC,8CAA+D;CAG/E,MAAM,WAAW,OAAO,IAAI,OAAO;CACnC,MAAM,QAAQ,aAAa,OAAA,IAA8B,OAAO,QAAQ;CACxE,IAAI,aAAa,SAAS,CAAC,QAAQ,KAAK,QAAQ,KAAK,QAAQ,KAAK,QAAA,KAC9D,OAAO,QAAQ,CAAC,4CAA6D;CAGjF,MAAM,aAAa,WAAW,UACzB,OAAO,oBAAoB,CAAC,CAC5B,KAAK,aAAa,SAAS,EAAE;CAClC,MAAM,eAAe,OAAO,IAAI,WAAW;CAC3C,MAAM,QACF,iBAAiB,OACX,aACA,aACK,MAAM,GAAG,CAAC,CACV,KAAK,OAAO,GAAG,KAAK,CAAC,CAAC,CACtB,QAAQ,OAAO,OAAO,EAAE;CACvC,MAAM,UAAU,MAAM,QAAQ,OAAO,CAAC,WAAW,SAAS,EAAE,CAAC;CAC7D,IAAI,iBAAiB,SAAS,MAAM,WAAW,KAAK,QAAQ,SAAS,IACjE,OAAO,YAAY,CACf,QAAQ,SAAS,IACX,uCAAuC,QAAQ,KAAK,IAAI,EAAE,KAC1D,6BACV;CAGJ,IAAI,OAAO,KAAK,MAAM,CAAC,CAAC,SAAS,GAC7B,OAAO,EAAE,OAAO;CAIpB,OAAO,EAAE,OAAO;EAAE;EAAG;EAAO,WADV,WAAW,QAAQ,OAAO,MAAM,SAAS,EAAE,CACjC;CAAU,EAAE;AAC5C"}
|
package/dist/themes.d.ts
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MediaTransform } from './schemas/api.js';
|
|
2
|
+
/** The ratio of `width:height` (`16:9` gives 1.777…), or null when it isn't one. */
|
|
3
|
+
export declare function parseRatio(ratio: string): number | null;
|
|
4
|
+
/**
|
|
5
|
+
* Whether a size has a ratio (decision 0031): its height is within one pixel of its width divided
|
|
6
|
+
* by the ratio, since crops are in whole pixels.
|
|
7
|
+
*/
|
|
8
|
+
export declare function matchesRatio(width: number, height: number, ratio: number | string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The size of the crop of a transform as it is rendered: a quarter turn swaps its width and its
|
|
11
|
+
* height. Null without a crop.
|
|
12
|
+
*/
|
|
13
|
+
export declare function renderedCropSize(transform: Pick<MediaTransform, 'crop' | 'rotate'>): {
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
} | null;
|
|
17
|
+
//# sourceMappingURL=transforms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transforms.d.ts","sourceRoot":"","sources":["../src/transforms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpD,oFAAoF;AACpF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGvD;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAG3F;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC5B,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,QAAQ,CAAC,GACnD;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAQ1C"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isRecord } from "./values.js";
|
|
2
|
+
//#region src/transforms.ts
|
|
3
|
+
/** The ratio of `width:height` (`16:9` gives 1.777…), or null when it isn't one. */
|
|
4
|
+
function parseRatio(ratio) {
|
|
5
|
+
const match = /^([1-9][0-9]*):([1-9][0-9]*)$/.exec(ratio);
|
|
6
|
+
return match === null ? null : Number(match[1]) / Number(match[2]);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Whether a size has a ratio (decision 0031): its height is within one pixel of its width divided
|
|
10
|
+
* by the ratio, since crops are in whole pixels.
|
|
11
|
+
*/
|
|
12
|
+
function matchesRatio(width, height, ratio) {
|
|
13
|
+
const value = typeof ratio === "number" ? ratio : parseRatio(ratio);
|
|
14
|
+
return value !== null && value > 0 && Math.abs(width / value - height) <= 1;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The size of the crop of a transform as it is rendered: a quarter turn swaps its width and its
|
|
18
|
+
* height. Null without a crop.
|
|
19
|
+
*/
|
|
20
|
+
function renderedCropSize(transform) {
|
|
21
|
+
const crop = transform.crop;
|
|
22
|
+
if (!isRecord(crop) || typeof crop.width !== "number" || typeof crop.height !== "number") return null;
|
|
23
|
+
return transform.rotate === 90 || transform.rotate === 270 ? {
|
|
24
|
+
width: crop.height,
|
|
25
|
+
height: crop.width
|
|
26
|
+
} : {
|
|
27
|
+
width: crop.width,
|
|
28
|
+
height: crop.height
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { matchesRatio, parseRatio, renderedCropSize };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=transforms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transforms.js","names":[],"sources":["../src/transforms.ts"],"sourcesContent":["import type { MediaTransform } from './schemas/api';\nimport { isRecord } from './values';\n\n/** The ratio of `width:height` (`16:9` gives 1.777…), or null when it isn't one. */\nexport function parseRatio(ratio: string): number | null {\n const match = /^([1-9][0-9]*):([1-9][0-9]*)$/.exec(ratio);\n return match === null ? null : Number(match[1]) / Number(match[2]);\n}\n\n/**\n * Whether a size has a ratio (decision 0031): its height is within one pixel of its width divided\n * by the ratio, since crops are in whole pixels.\n */\nexport function matchesRatio(width: number, height: number, ratio: number | string): boolean {\n const value = typeof ratio === 'number' ? ratio : parseRatio(ratio);\n return value !== null && value > 0 && Math.abs(width / value - height) <= 1;\n}\n\n/**\n * The size of the crop of a transform as it is rendered: a quarter turn swaps its width and its\n * height. Null without a crop.\n */\nexport function renderedCropSize(\n transform: Pick<MediaTransform, 'crop' | 'rotate'>,\n): { width: number; height: number } | null {\n const crop = transform.crop;\n if (!isRecord(crop) || typeof crop.width !== 'number' || typeof crop.height !== 'number') {\n return null;\n }\n return transform.rotate === 90 || transform.rotate === 270\n ? { width: crop.height, height: crop.width }\n : { width: crop.width, height: crop.height };\n}\n"],"mappings":";;;AAIA,SAAgB,WAAW,OAA8B;CACrD,MAAM,QAAQ,gCAAgC,KAAK,KAAK;CACxD,OAAO,UAAU,OAAO,OAAO,OAAO,MAAM,EAAE,IAAI,OAAO,MAAM,EAAE;AACrE;;;;;AAMA,SAAgB,aAAa,OAAe,QAAgB,OAAiC;CACzF,MAAM,QAAQ,OAAO,UAAU,WAAW,QAAQ,WAAW,KAAK;CAClE,OAAO,UAAU,QAAQ,QAAQ,KAAK,KAAK,IAAI,QAAQ,QAAQ,MAAM,KAAK;AAC9E;;;;;AAMA,SAAgB,iBACZ,WACwC;CACxC,MAAM,OAAO,UAAU;CACvB,IAAI,CAAC,SAAS,IAAI,KAAK,OAAO,KAAK,UAAU,YAAY,OAAO,KAAK,WAAW,UAC5E,OAAO;CAEX,OAAO,UAAU,WAAW,MAAM,UAAU,WAAW,MACjD;EAAE,OAAO,KAAK;EAAQ,QAAQ,KAAK;CAAM,IACzC;EAAE,OAAO,KAAK;EAAO,QAAQ,KAAK;CAAO;AACnD"}
|
package/dist/validate.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
|
-
import { BootConfig } from './schemas/boot';
|
|
3
|
-
import { Definition } from './schemas/definition';
|
|
2
|
+
import { BootConfig } from './schemas/boot.js';
|
|
3
|
+
import { Definition } from './schemas/definition.js';
|
|
4
4
|
export interface ValidationIssue {
|
|
5
5
|
/** Dot path of the invalid value (`resources.0.fields.2.type`), empty for the root. */
|
|
6
6
|
path: string;
|
|
@@ -17,7 +17,9 @@ export type ValidationResult<T> = {
|
|
|
17
17
|
export declare function validate<T extends z.ZodType>(schema: T, input: unknown): ValidationResult<z.infer<T>>;
|
|
18
18
|
/**
|
|
19
19
|
* Validates a definition, as returned by `GET /definition`: against the schema, then the
|
|
20
|
-
* references between its parts (see `lintDefinition()`)
|
|
20
|
+
* references between its parts (see `lintDefinition()`), and the settings of field types that
|
|
21
|
+
* the protocol describes (`RichTextSettings`, `DurationSettings`, `DateRangeSettings`,
|
|
22
|
+
* `MoneySettings`, `LinkSettings`, `AddressSettings`).
|
|
21
23
|
*/
|
|
22
24
|
export declare function validateDefinition(input: unknown): ValidationResult<Definition>;
|
|
23
25
|
/**
|