@panneau/protocol 5.0.0-alpha.2 → 5.0.0-alpha.20

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.
Files changed (136) hide show
  1. package/dist/addresses.d.ts +23 -0
  2. package/dist/addresses.d.ts.map +1 -0
  3. package/dist/addresses.js +52 -0
  4. package/dist/addresses.js.map +1 -0
  5. package/dist/compound.d.ts +20 -0
  6. package/dist/compound.d.ts.map +1 -0
  7. package/dist/compound.js +27 -0
  8. package/dist/compound.js.map +1 -0
  9. package/dist/conditions.d.ts +1 -1
  10. package/dist/conformance/index.d.ts +6 -0
  11. package/dist/conformance/index.d.ts.map +1 -1
  12. package/dist/conformance/index.js +787 -11
  13. package/dist/conformance/index.js.map +1 -1
  14. package/dist/constants.d.ts +101 -2
  15. package/dist/constants.d.ts.map +1 -1
  16. package/dist/constants.js +174 -3
  17. package/dist/constants.js.map +1 -1
  18. package/dist/context.d.ts +15 -0
  19. package/dist/context.d.ts.map +1 -0
  20. package/dist/context.js +34 -0
  21. package/dist/context.js.map +1 -0
  22. package/dist/currencies.d.ts +22 -0
  23. package/dist/currencies.d.ts.map +1 -0
  24. package/dist/currencies.js +231 -0
  25. package/dist/currencies.js.map +1 -0
  26. package/dist/index.d.ts +4 -4
  27. package/dist/index.js +17 -7
  28. package/dist/libraries.d.ts +26 -0
  29. package/dist/libraries.d.ts.map +1 -0
  30. package/dist/libraries.js +22 -0
  31. package/dist/libraries.js.map +1 -0
  32. package/dist/links.d.ts +38 -0
  33. package/dist/links.d.ts.map +1 -0
  34. package/dist/links.js +65 -0
  35. package/dist/links.js.map +1 -0
  36. package/dist/lint.d.ts +4 -3
  37. package/dist/lint.d.ts.map +1 -1
  38. package/dist/lint.js +114 -2
  39. package/dist/lint.js.map +1 -1
  40. package/dist/mock/auth.d.ts +71 -0
  41. package/dist/mock/auth.d.ts.map +1 -0
  42. package/dist/mock/auth.js +346 -0
  43. package/dist/mock/auth.js.map +1 -0
  44. package/dist/mock/example.d.ts +3 -2
  45. package/dist/mock/example.d.ts.map +1 -1
  46. package/dist/mock/example.js +223 -142
  47. package/dist/mock/example.js.map +1 -1
  48. package/dist/mock/index.d.ts +77 -7
  49. package/dist/mock/index.d.ts.map +1 -1
  50. package/dist/mock/index.js +577 -34
  51. package/dist/mock/index.js.map +1 -1
  52. package/dist/openapi.d.ts.map +1 -1
  53. package/dist/openapi.js +394 -145
  54. package/dist/openapi.js.map +1 -1
  55. package/dist/problem.d.ts +1 -1
  56. package/dist/query.d.ts +18 -0
  57. package/dist/query.d.ts.map +1 -1
  58. package/dist/query.js +34 -8
  59. package/dist/query.js.map +1 -1
  60. package/dist/rules.d.ts +16 -4
  61. package/dist/rules.d.ts.map +1 -1
  62. package/dist/rules.js +230 -13
  63. package/dist/rules.js.map +1 -1
  64. package/dist/runtime/index.d.ts +19 -10
  65. package/dist/runtime/index.d.ts.map +1 -1
  66. package/dist/runtime/index.js +12 -3
  67. package/dist/schemas/action.d.ts +117 -10
  68. package/dist/schemas/action.d.ts.map +1 -1
  69. package/dist/schemas/action.js +21 -3
  70. package/dist/schemas/action.js.map +1 -1
  71. package/dist/schemas/api.d.ts +326 -42
  72. package/dist/schemas/api.d.ts.map +1 -1
  73. package/dist/schemas/api.js +192 -34
  74. package/dist/schemas/api.js.map +1 -1
  75. package/dist/schemas/boot.d.ts +25 -1
  76. package/dist/schemas/boot.d.ts.map +1 -1
  77. package/dist/schemas/boot.js +2 -1
  78. package/dist/schemas/boot.js.map +1 -1
  79. package/dist/schemas/common.d.ts +1 -0
  80. package/dist/schemas/common.d.ts.map +1 -1
  81. package/dist/schemas/common.js +2 -1
  82. package/dist/schemas/common.js.map +1 -1
  83. package/dist/schemas/definition.d.ts +332 -28
  84. package/dist/schemas/definition.d.ts.map +1 -1
  85. package/dist/schemas/definition.js +65 -19
  86. package/dist/schemas/definition.js.map +1 -1
  87. package/dist/schemas/field.d.ts +356 -2
  88. package/dist/schemas/field.d.ts.map +1 -1
  89. package/dist/schemas/field.js +159 -20
  90. package/dist/schemas/field.js.map +1 -1
  91. package/dist/schemas/index.d.ts +1384 -72
  92. package/dist/schemas/index.d.ts.map +1 -1
  93. package/dist/schemas/index.js +58 -9
  94. package/dist/schemas/index.js.map +1 -1
  95. package/dist/schemas/jsonRules.d.ts +83 -0
  96. package/dist/schemas/jsonRules.d.ts.map +1 -0
  97. package/dist/schemas/jsonRules.js +46 -0
  98. package/dist/schemas/jsonRules.js.map +1 -0
  99. package/dist/schemas/layout.d.ts +1 -1
  100. package/dist/schemas/list.d.ts +23 -2
  101. package/dist/schemas/list.d.ts.map +1 -1
  102. package/dist/schemas/list.js +14 -5
  103. package/dist/schemas/list.js.map +1 -1
  104. package/dist/schemas/resource.d.ts +247 -15
  105. package/dist/schemas/resource.d.ts.map +1 -1
  106. package/dist/schemas/resource.js +6 -1
  107. package/dist/schemas/resource.js.map +1 -1
  108. package/dist/schemas/widget.d.ts +109 -0
  109. package/dist/schemas/widget.d.ts.map +1 -0
  110. package/dist/schemas/widget.js +74 -0
  111. package/dist/schemas/widget.js.map +1 -0
  112. package/dist/search.d.ts +51 -0
  113. package/dist/search.d.ts.map +1 -0
  114. package/dist/search.js +53 -0
  115. package/dist/search.js.map +1 -0
  116. package/dist/themes.d.ts +1 -1
  117. package/dist/transforms.d.ts +17 -0
  118. package/dist/transforms.d.ts.map +1 -0
  119. package/dist/transforms.js +34 -0
  120. package/dist/transforms.js.map +1 -0
  121. package/dist/validate.d.ts +5 -3
  122. package/dist/validate.d.ts.map +1 -1
  123. package/dist/validate.js +36 -2
  124. package/dist/validate.js.map +1 -1
  125. package/dist/values.d.ts +5 -1
  126. package/dist/values.d.ts.map +1 -1
  127. package/dist/values.js +16 -2
  128. package/dist/values.js.map +1 -1
  129. package/dist/widgets.d.ts +42 -0
  130. package/dist/widgets.d.ts.map +1 -0
  131. package/dist/widgets.js +130 -0
  132. package/dist/widgets.js.map +1 -0
  133. package/package.json +6 -3
  134. package/schema/boot.schema.json +666 -18
  135. package/schema/definition.schema.json +663 -18
  136. package/schema/openapi.json +5694 -2328
@@ -0,0 +1,74 @@
1
+ import { WIDGET_SERIES_PERIODS } from "../widgets.js";
2
+ import { z } from "zod";
3
+ //#region src/schemas/widget.ts
4
+ var ToneName = z.string().regex(/^[a-z0-9-]+$/);
5
+ var QueryValue = z.union([
6
+ z.string(),
7
+ z.number(),
8
+ z.boolean()
9
+ ]);
10
+ var WidgetSettings = z.looseObject({
11
+ resource: z.string().min(1).optional().meta({ description: "Built-in `stat` and `list`: the resource whose list feeds the widget. The client reads `GET /resources/{resource}` with `query`: a `stat` counts its items (`meta.total`), a `list` shows its first items. Such a widget has no data at `GET /dashboard/widgets/{widget}`." }),
12
+ 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`." })
13
+ }).meta({ description: "The settings of a widget: `resource` and `query` for the built-in `stat` and `list` on a resource, anything else for widgets of plugins." });
14
+ var Widget = z.looseObject({
15
+ id: z.string().min(1).meta({ description: "Unique in the dashboard: the `{widget}` of its route." }),
16
+ type: z.string().min(1).meta({ description: "Built-in: `stat` (a number), `series` (a line over days, weeks or months) and `list` (a few items). Other types are widgets of plugins." }),
17
+ label: z.string().optional(),
18
+ 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." }),
19
+ settings: WidgetSettings.optional()
20
+ });
21
+ var WidgetBadge = z.looseObject({
22
+ label: z.string(),
23
+ tone: ToneName.optional()
24
+ }).meta({ description: "A badge: a word, in a tone of the theme." });
25
+ var StatWidgetData = z.looseObject({
26
+ value: z.number().meta({ description: "The number, in large type." }),
27
+ help: z.string().nullable().optional().meta({ description: "A line under the number, translated: `3 more than last week`." }),
28
+ 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." }),
29
+ url: z.string().nullable().optional().meta({ description: "Where the widget links: the list of what it counts." })
30
+ }).meta({ description: "The data of a `stat` widget: a number (decision 0064)." });
31
+ var SeriesPoint = z.looseObject({
32
+ date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).meta({ description: "The first day of the period: `2026-10-05`." }),
33
+ value: z.number()
34
+ });
35
+ var SeriesWidgetData = z.looseObject({
36
+ period: z.enum(WIDGET_SERIES_PERIODS).meta({ description: "The period of each point." }),
37
+ points: z.array(SeriesPoint).meta({ description: "One point per period, the dates going up. Periods without a value are points at 0." }),
38
+ total: z.number().nullable().optional().meta({ description: "The total over the points, shown with the line." })
39
+ }).superRefine((data, context) => {
40
+ data.points.forEach((point, index) => {
41
+ const previous = data.points[index - 1];
42
+ if (previous !== void 0 && point.date <= previous.date) context.addIssue({
43
+ code: "custom",
44
+ message: "The dates of the points must go up.",
45
+ path: [
46
+ "points",
47
+ index,
48
+ "date"
49
+ ]
50
+ });
51
+ });
52
+ }).meta({ description: "The data of a `series` widget: a line of values per period (decision 0064)." });
53
+ var ListWidgetItem = z.looseObject({
54
+ title: z.string(),
55
+ description: z.string().nullable().optional(),
56
+ meta: z.string().nullable().optional().meta({ description: "A short fact at the end of the item: `12 answers`." }),
57
+ url: z.string().nullable().optional(),
58
+ badge: WidgetBadge.nullable().optional()
59
+ });
60
+ var ListWidgetData = z.looseObject({
61
+ items: z.array(ListWidgetItem).max(5).meta({ description: `At most 5 items, the most useful first.` }),
62
+ empty: z.string().nullable().optional().meta({ description: "The message without items, translated: `No open contests.`" }),
63
+ url: z.string().nullable().optional().meta({ description: "Where \"See all\" links, under the items." })
64
+ }).meta({ description: "The data of a `list` widget: a few items (decision 0064)." });
65
+ /** The schema of the data of each built-in widget type. */
66
+ var widgetDataSchemas = {
67
+ stat: StatWidgetData,
68
+ series: SeriesWidgetData,
69
+ list: ListWidgetData
70
+ };
71
+ //#endregion
72
+ export { ListWidgetData, ListWidgetItem, SeriesPoint, SeriesWidgetData, StatWidgetData, Widget, WidgetBadge, WidgetSettings, widgetDataSchemas };
73
+
74
+ //# 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 { WIDGET_LIST_MAX_ITEMS, WIDGET_SERIES_PERIODS } from '../widgets';\n\nconst ToneName = z.string().regex(/^[a-z0-9-]+$/);\n\nconst QueryValue = z.union([z.string(), z.number(), z.boolean()]);\n\nexport const WidgetSettings = z\n .looseObject({\n resource: z.string().min(1).optional().meta({\n description:\n 'Built-in `stat` and `list`: the resource whose list feeds the widget. The client reads `GET /resources/{resource}` with `query`: a `stat` counts its items (`meta.total`), a `list` shows its first items. 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 })\n .meta({\n description:\n 'The settings of a widget: `resource` and `query` for the built-in `stat` and `list` on a resource, anything else for widgets of plugins.',\n });\n\nexport const Widget = z.looseObject({\n id: z\n .string()\n .min(1)\n .meta({ description: 'Unique in the dashboard: the `{widget}` of its route.' }),\n type: z.string().min(1).meta({\n description:\n 'Built-in: `stat` (a number), `series` (a line over days, weeks or months) and `list` (a few items). 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 })\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\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.',\n }),\n total: z.number().nullable().optional().meta({\n description: 'The total over the points, shown with the line.',\n }),\n })\n .superRefine((data, context) => {\n data.points.forEach((point, index) => {\n const previous = data.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: ['points', index, 'date'],\n });\n }\n });\n })\n .meta({\n description: 'The data of a `series` widget: a line of values per period (decision 0064).',\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\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} as const;\n\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>;\n"],"mappings":";;;AAIA,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,IAAa,iBAAiB,EACzB,YAAY;CACT,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EACxC,aACI,6QACR,CAAC;CACD,OAAO,EACF,OAAO,EAAE,OAAO,GAAG,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,UAAU,CAAC,CAAC,CAAC,CAAC,CAC9D,SAAS,CAAC,CACV,KAAK,EACF,aACI,oNACR,CAAC;AACT,CAAC,CAAC,CACD,KAAK,EACF,aACI,2IACR,CAAC;AAEL,IAAa,SAAS,EAAE,YAAY;CAChC,IAAI,EACC,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,KAAK,EAAE,aAAa,wDAAwD,CAAC;CAClF,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EACzB,aACI,0IACR,CAAC;CACD,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS;CAC3B,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,C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EAClC,MAAM,WAAW,KAAK,OAAO,QAAQ;EACrC,IAAI,aAAa,KAAA,KAAa,MAAM,QAAQ,SAAS,MACjD,QAAQ,SAAS;GACb,MAAM;GACN,SAAS;GACT,MAAM;IAAC;IAAU;IAAO;GAAM;EAClC,CAAC;CAET,CAAC;AACL,CAAC,CAAC,CACD,KAAK,EACF,aAAa,8EACjB,CAAC;AAEL,IAAa,iBAAiB,EAAE,YAAY;CACxC,OAAO,EAAE,OAAO;CAChB,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CAC5C,MAAM,EACD,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,CAAC,CACV,KAAK,EAAE,aAAa,qDAAqD,CAAC;CAC/E,KAAK,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CACpC,OAAO,YAAY,SAAS,CAAC,CAAC,SAAS;AAC3C,CAAC;AAED,IAAa,iBAAiB,EACzB,YAAY;CACT,OAAO,EACF,MAAM,cAAc,CAAC,CACrB,IAAA,CAAyB,CAAC,CAC1B,KAAK,EACF,aAAa,0CACjB,CAAC;CACL,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EACzC,aAAa,6DACjB,CAAC;CACD,KAAK,EACA,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,CAAC,CACV,KAAK,EAAE,aAAa,4CAA0C,CAAC;AACxE,CAAC,CAAC,CACD,KAAK,EAAE,aAAa,4DAA4D,CAAC;;AAGtF,IAAa,oBAAoB;CAC7B,MAAM;CACN,QAAQ;CACR,MAAM;AACV"}
@@ -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,MAA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+ //#region src/search.ts
2
+ /** Shortest search, in characters once trimmed: shorter is a `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)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,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
@@ -1,4 +1,4 @@
1
- import type { Theme } from './schemas/theme';
1
+ import type { Theme } from './schemas/theme.js';
2
2
  /** A theme to merge: `tokens` can be left out, as in the theme of a definition. */
3
3
  export type PartialTheme = Partial<Theme>;
4
4
  /**
@@ -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"}
@@ -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
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,WAAW,eAAe;IAC5B,uFAAuF;IACvF,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAC1B;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,eAAe,EAAE,CAAA;CAAE,CAAC;AAE/E,+DAA+D;AAC/D,wBAAgB,QAAQ,CAAC,CAA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gB,CAAC,UAAU,CAAC,CAU/E"}
package/dist/validate.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { lintDefinition } from "./lint.js";
2
+ import { AddressSettings, DateRangeSettings, DurationSettings, LinkSettings, MoneySettings, RichTextSettings } from "./schemas/field.js";
2
3
  import { Definition } from "./schemas/definition.js";
3
4
  import { BootConfig } from "./schemas/boot.js";
4
5
  //#region src/validate.ts
@@ -17,14 +18,47 @@ function validate(schema, input) {
17
18
  }))
18
19
  };
19
20
  }
21
+ /** The schemas of the settings of the types that the protocol describes. */
22
+ var SETTINGS = {
23
+ richtext: RichTextSettings,
24
+ duration: DurationSettings,
25
+ daterange: DateRangeSettings,
26
+ money: MoneySettings,
27
+ link: LinkSettings,
28
+ address: AddressSettings
29
+ };
30
+ /**
31
+ * Checks the settings of the fields whose type the protocol describes the settings of (`richtext`,
32
+ * `duration`, `daterange`, `money`, `link`, `address`), nested ones included.
33
+ */
34
+ function checkFieldSettings(fields, path) {
35
+ return fields.flatMap((field, index) => {
36
+ const fieldPath = `${path}.${String(index)}`;
37
+ const schema = SETTINGS[field.type];
38
+ return [
39
+ ...schema !== void 0 && field.settings !== void 0 ? (schema.safeParse(field.settings).error?.issues ?? []).map((issue) => ({
40
+ path: [`${fieldPath}.settings`, ...issue.path.map(String)].join("."),
41
+ message: issue.message
42
+ })) : [],
43
+ ...checkFieldSettings(field.fields ?? [], `${fieldPath}.fields`),
44
+ ...(field.types ?? []).flatMap((type, typeIndex) => checkFieldSettings(type.fields, `${fieldPath}.types.${String(typeIndex)}.fields`))
45
+ ];
46
+ });
47
+ }
20
48
  /**
21
49
  * Validates a definition, as returned by `GET /definition`: against the schema, then the
22
- * references between its parts (see `lintDefinition()`).
50
+ * references between its parts (see `lintDefinition()`), and the settings of field types that
51
+ * the protocol describes (`RichTextSettings`, `DurationSettings`, `DateRangeSettings`,
52
+ * `MoneySettings`, `LinkSettings`, `AddressSettings`).
23
53
  */
24
54
  function validateDefinition(input) {
25
55
  const result = validate(Definition, input);
26
56
  if (!result.success) return result;
27
- const issues = lintDefinition(result.data);
57
+ const issues = [...lintDefinition(result.data), ...result.data.resources.flatMap((resource, index) => [
58
+ ...checkFieldSettings(resource.fields, `resources.${String(index)}.fields`),
59
+ ...(resource.types ?? []).flatMap((type, typeIndex) => checkFieldSettings(type.fields, `resources.${String(index)}.types.${String(typeIndex)}.fields`)),
60
+ ...(resource.actions ?? []).flatMap((action, actionIndex) => checkFieldSettings(action.fields ?? [], `resources.${String(index)}.actions.${String(actionIndex)}.fields`))
61
+ ])];
28
62
  return issues.length > 0 ? {
29
63
  success: false,
30
64
  issues
@@ -1 +1 @@
1
- {"version":3,"file":"validate.js","names":[],"sources":["../src/validate.ts"],"sourcesContent":["import type { z } from 'zod';\n\nimport { lintDefinition } from './lint';\nimport { BootConfig } from './schemas/boot';\nimport { Definition } from './schemas/definition';\n\nexport interface ValidationIssue {\n /** Dot path of the invalid value (`resources.0.fields.2.type`), empty for the root. */\n path: string;\n message: string;\n}\n\nexport type ValidationResult<T> =\n { success: true; data: T } | { success: false; issues: ValidationIssue[] };\n\n/** Validates a value against one of the protocol's schemas. */\nexport function validate<T extends z.ZodType>(\n schema: T,\n input: unknown,\n): ValidationResult<z.infer<T>> {\n const result = schema.safeParse(input);\n if (result.success) {\n return { success: true, data: result.data };\n }\n return {\n success: false,\n issues: result.error.issues.map((issue) => ({\n path: issue.path.map(String).join('.'),\n message: issue.message,\n })),\n };\n}\n\n/**\n * Validates a definition, as returned by `GET /definition`: against the schema, then the\n * references between its parts (see `lintDefinition()`).\n */\nexport function validateDefinition(input: unknown): ValidationResult<Definition> {\n const result = validate(Definition, input);\n if (!result.success) {\n return result;\n }\n const issues = lintDefinition(result.data);\n return issues.length > 0 ? { success: false, issues } : result;\n}\n\n/**\n * Validates a boot config, as a server writes it in the page: against the schema, then the\n * references between the parts of its inlined definition, if any.\n */\nexport function validateBootConfig(input: unknown): ValidationResult<BootConfig> {\n const result = validate(BootConfig, input);\n if (!result.success || result.data.definition === undefined) {\n return result;\n }\n const issues = lintDefinition(result.data.definition).map((issue) => ({\n ...issue,\n path: issue.path === '' ? 'definition' : `definition.${issue.path}`,\n }));\n return issues.length > 0 ? { success: false, issues } : result;\n}\n"],"mappings":";;;;;AAgBA,SAAgB,SACZ,QACA,OAC4B;CAC5B,MAAM,SAAS,OAAO,UAAU,KAAK;CACrC,IAAI,OAAO,SACP,OAAO;EAAE,SAAS;EAAM,MAAM,OAAO;CAAK;CAE9C,OAAO;EACH,SAAS;EACT,QAAQ,OAAO,MAAM,OAAO,KAAK,WAAW;GACxC,MAAM,MAAM,KAAK,IAAI,MAAM,CAAC,CAAC,KAAK,GAAG;GACrC,SAAS,MAAM;EACnB,EAAE;CACN;AACJ;;;;;AAMA,SAAgB,mBAAmB,OAA8C;CAC7E,MAAM,SAAS,SAAS,YAAY,KAAK;CACzC,IAAI,CAAC,OAAO,SACR,OAAO;CAEX,MAAM,SAAS,eAAe,OAAO,IAAI;CACzC,OAAO,OAAO,SAAS,IAAI;EAAE,SAAS;EAAO;CAAO,IAAI;AAC5D;;;;;AAMA,SAAgB,mBAAmB,OAA8C;CAC7E,MAAM,SAAS,SAAS,YAAY,KAAK;CACzC,IAAI,CAAC,OAAO,WAAW,OAAO,KAAK,eAAe,KAAA,GAC9C,OAAO;CAEX,MAAM,SAAS,eAAe,OAAO,KAAK,UAAU,CAAC,CAAC,KAAK,WAAW;EAClE,GAAG;EACH,MAAM,MAAM,SAAS,KAAK,eAAe,cAAc,MAAM;CACjE,EAAE;CACF,OAAO,OAAO,SAAS,IAAI;EAAE,SAAS;EAAO;CAAO,IAAI;AAC5D"}
1
+ {"version":3,"file":"validate.js","names":[],"sources":["../src/validate.ts"],"sourcesContent":["import type { z } from 'zod';\n\nimport { lintDefinition } from './lint';\nimport { BootConfig } from './schemas/boot';\nimport { Definition } from './schemas/definition';\nimport {\n AddressSettings,\n DateRangeSettings,\n DurationSettings,\n type Field,\n LinkSettings,\n MoneySettings,\n RichTextSettings,\n} from './schemas/field';\n\nexport interface ValidationIssue {\n /** Dot path of the invalid value (`resources.0.fields.2.type`), empty for the root. */\n path: string;\n message: string;\n}\n\nexport type ValidationResult<T> =\n { success: true; data: T } | { success: false; issues: ValidationIssue[] };\n\n/** Validates a value against one of the protocol's schemas. */\nexport function validate<T extends z.ZodType>(\n schema: T,\n input: unknown,\n): ValidationResult<z.infer<T>> {\n const result = schema.safeParse(input);\n if (result.success) {\n return { success: true, data: result.data };\n }\n return {\n success: false,\n issues: result.error.issues.map((issue) => ({\n path: issue.path.map(String).join('.'),\n message: issue.message,\n })),\n };\n}\n\n/** The schemas of the settings of the types that the protocol describes. */\nconst SETTINGS: Readonly<Record<string, z.ZodType>> = {\n richtext: RichTextSettings,\n duration: DurationSettings,\n daterange: DateRangeSettings,\n money: MoneySettings,\n link: LinkSettings,\n address: AddressSettings,\n};\n\n/**\n * Checks the settings of the fields whose type the protocol describes the settings of (`richtext`,\n * `duration`, `daterange`, `money`, `link`, `address`), nested ones included.\n */\nfunction checkFieldSettings(fields: readonly Field[], path: string): ValidationIssue[] {\n return fields.flatMap((field, index) => {\n const fieldPath = `${path}.${String(index)}`;\n const schema = SETTINGS[field.type];\n const own =\n schema !== undefined && field.settings !== undefined\n ? (schema.safeParse(field.settings).error?.issues ?? []).map((issue) => ({\n path: [`${fieldPath}.settings`, ...issue.path.map(String)].join('.'),\n message: issue.message,\n }))\n : [];\n return [\n ...own,\n ...checkFieldSettings(field.fields ?? [], `${fieldPath}.fields`),\n ...(field.types ?? []).flatMap((type, typeIndex) =>\n checkFieldSettings(type.fields, `${fieldPath}.types.${String(typeIndex)}.fields`),\n ),\n ];\n });\n}\n\n/**\n * Validates a definition, as returned by `GET /definition`: against the schema, then the\n * references between its parts (see `lintDefinition()`), and the settings of field types that\n * the protocol describes (`RichTextSettings`, `DurationSettings`, `DateRangeSettings`,\n * `MoneySettings`, `LinkSettings`, `AddressSettings`).\n */\nexport function validateDefinition(input: unknown): ValidationResult<Definition> {\n const result = validate(Definition, input);\n if (!result.success) {\n return result;\n }\n const issues = [\n ...lintDefinition(result.data),\n ...result.data.resources.flatMap((resource, index) => [\n ...checkFieldSettings(resource.fields, `resources.${String(index)}.fields`),\n ...(resource.types ?? []).flatMap((type, typeIndex) =>\n checkFieldSettings(\n type.fields,\n `resources.${String(index)}.types.${String(typeIndex)}.fields`,\n ),\n ),\n ...(resource.actions ?? []).flatMap((action, actionIndex) =>\n checkFieldSettings(\n action.fields ?? [],\n `resources.${String(index)}.actions.${String(actionIndex)}.fields`,\n ),\n ),\n ]),\n ];\n return issues.length > 0 ? { success: false, issues } : result;\n}\n\n/**\n * Validates a boot config, as a server writes it in the page: against the schema, then the\n * references between the parts of its inlined definition, if any.\n */\nexport function validateBootConfig(input: unknown): ValidationResult<BootConfig> {\n const result = validate(BootConfig, input);\n if (!result.success || result.data.definition === undefined) {\n return result;\n }\n const issues = lintDefinition(result.data.definition).map((issue) => ({\n ...issue,\n path: issue.path === '' ? 'definition' : `definition.${issue.path}`,\n }));\n return issues.length > 0 ? { success: false, issues } : result;\n}\n"],"mappings":";;;;;;AAyBA,SAAgB,SACZ,QACA,OAC4B;CAC5B,MAAM,SAAS,OAAO,UAAU,KAAK;CACrC,IAAI,OAAO,SACP,OAAO;EAAE,SAAS;EAAM,MAAM,OAAO;CAAK;CAE9C,OAAO;EACH,SAAS;EACT,QAAQ,OAAO,MAAM,OAAO,KAAK,WAAW;GACxC,MAAM,MAAM,KAAK,IAAI,MAAM,CAAC,CAAC,KAAK,GAAG;GACrC,SAAS,MAAM;EACnB,EAAE;CACN;AACJ;;AAGA,IAAM,WAAgD;CAClD,UAAU;CACV,UAAU;CACV,WAAW;CACX,OAAO;CACP,MAAM;CACN,SAAS;AACb;;;;;AAMA,SAAS,mBAAmB,QAA0B,MAAiC;CACnF,OAAO,OAAO,SAAS,OAAO,UAAU;EACpC,MAAM,YAAY,GAAG,KAAK,GAAG,OAAO,KAAK;EACzC,MAAM,SAAS,SAAS,MAAM;EAQ9B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AO,WAAW,OAAO,KAAK,eAAe,KAAA,GAC9C,OAAO;CAEX,MAAM,SAAS,eAAe,OAAO,KAAK,UAAU,CAAC,CAAC,KAAK,WAAW;EAClE,GAAG;EACH,MAAM,MAAM,SAAS,KAAK,eAAe,cAAc,MAAM;CACjE,EAAE;CACF,OAAO,OAAO,SAAS,IAAI;EAAE,SAAS;EAAO;CAAO,IAAI;AAC5D"}
package/dist/values.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  /** Reads a value at a dot path (`blocks.2.title.fr`). */
2
2
  export declare function getValue(values: unknown, path: string): unknown;
3
- /** Whether a value counts as filled: not null, not an empty or blank string, not an empty array or object. */
3
+ /**
4
+ * Whether a value counts as filled: not null, not an empty or blank string, not an empty array or
5
+ * plain object. A file (`Blob`, `File`, even empty) is filled. Other collections count by their
6
+ * `length` or `size` (an empty `FileList`, `Map` or `Set` isn't filled); other objects are filled.
7
+ */
4
8
  export declare function isFilled(value: unknown): boolean;
5
9
  export declare function isRecord(value: unknown): value is Record<string, unknown>;
6
10
  export declare function isEqual(a: unknown, b: unknown): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../src/values.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAU/D;AAED,8GAA8G;AAC9G,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAchD;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAQvD"}
1
+ {"version":3,"file":"values.d.ts","sourceRoot":"","sources":["../src/values.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAU/D;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAyBhD;AAOD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAQvD"}
package/dist/values.js CHANGED
@@ -7,14 +7,28 @@ function getValue(values, path) {
7
7
  return current[key];
8
8
  }, values);
9
9
  }
10
- /** Whether a value counts as filled: not null, not an empty or blank string, not an empty array or object. */
10
+ /**
11
+ * Whether a value counts as filled: not null, not an empty or blank string, not an empty array or
12
+ * plain object. A file (`Blob`, `File`, even empty) is filled. Other collections count by their
13
+ * `length` or `size` (an empty `FileList`, `Map` or `Set` isn't filled); other objects are filled.
14
+ */
11
15
  function isFilled(value) {
12
16
  if (value === null || value === void 0) return false;
13
17
  if (typeof value === "string") return value.trim() !== "";
14
18
  if (Array.isArray(value)) return value.length > 0;
15
- if (typeof value === "object") return Object.keys(value).length > 0;
19
+ if (typeof value === "object") {
20
+ if (typeof Blob !== "undefined" && value instanceof Blob) return true;
21
+ if (isPlainObject(value)) return Object.keys(value).length > 0;
22
+ const { length, size } = value;
23
+ if (typeof length === "number") return length > 0;
24
+ return typeof size === "number" ? size > 0 : true;
25
+ }
16
26
  return true;
17
27
  }
28
+ function isPlainObject(value) {
29
+ const prototype = Object.getPrototypeOf(value);
30
+ return prototype === Object.prototype || prototype === null;
31
+ }
18
32
  function isRecord(value) {
19
33
  return value !== null && typeof value === "object" && !Array.isArray(value);
20
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"values.js","names":[],"sources":["../src/values.ts"],"sourcesContent":["/** Reads a value at a dot path (`blocks.2.title.fr`). */\nexport function getValue(values: unknown, path: string): unknown {\n if (path === '') {\n return values;\n }\n return path.split('.').reduce<unknown>((current, key) => {\n if (current === null || typeof current !== 'object') {\n return undefined;\n }\n return (current as Record<string, unknown>)[key];\n }, values);\n}\n\n/** Whether a value counts as filled: not null, not an empty or blank string, not an empty array or object. */\nexport function isFilled(value: unknown): boolean {\n if (value === null || value === undefined) {\n return false;\n }\n if (typeof value === 'string') {\n return value.trim() !== '';\n }\n if (Array.isArray(value)) {\n return value.length > 0;\n }\n if (typeof value === 'object') {\n return Object.keys(value).length > 0;\n }\n return true;\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nexport function isEqual(a: unknown, b: unknown): boolean {\n if (a === b) {\n return true;\n }\n if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) {\n return false;\n }\n return JSON.stringify(a) === JSON.stringify(b);\n}\n"],"mappings":";;AACA,SAAgB,SAAS,QAAiB,MAAuB;CAC7D,IAAI,SAAS,IACT,OAAO;CAEX,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,QAAiB,SAAS,QAAQ;EACrD,IAAI,YAAY,QAAQ,OAAO,YAAY,UACvC;EAEJ,OAAQ,QAAoC;CAChD,GAAG,MAAM;AACb;;AAGA,SAAgB,SAAS,OAAyB;CAC9C,IAAI,UAAU,QAAQ,UAAU,KAAA,GAC5B,OAAO;CAEX,IAAI,OAAO,UAAU,UACjB,OAAO,MAAM,KAAK,MAAM;CAE5B,IAAI,MAAM,QAAQ,KAAK,GACnB,OAAO,MAAM,SAAS;CAE1B,IAAI,OAAO,UAAU,UACjB,OAAO,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS;CAEvC,OAAO;AACX;AAEA,SAAgB,SAAS,OAAkD;CACvE,OAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC9E;AAEA,SAAgB,QAAQ,GAAY,GAAqB;CACrD,IAAI,MAAM,GACN,OAAO;CAEX,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,MAAM,QAAQ,MAAM,MACtE,OAAO;CAEX,OAAO,KAAK,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC;AACjD"}
1
+ {"version":3,"file":"values.js","names":[],"sources":["../src/values.ts"],"sourcesContent":["/** Reads a value at a dot path (`blocks.2.title.fr`). */\nexport function getValue(values: unknown, path: string): unknown {\n if (path === '') {\n return values;\n }\n return path.split('.').reduce<unknown>((current, key) => {\n if (current === null || typeof current !== 'object') {\n return undefined;\n }\n return (current as Record<string, unknown>)[key];\n }, values);\n}\n\n/**\n * Whether a value counts as filled: not null, not an empty or blank string, not an empty array or\n * plain object. A file (`Blob`, `File`, even empty) is filled. Other collections count by their\n * `length` or `size` (an empty `FileList`, `Map` or `Set` isn't filled); other objects are filled.\n */\nexport function isFilled(value: unknown): boolean {\n if (value === null || value === undefined) {\n return false;\n }\n if (typeof value === 'string') {\n return value.trim() !== '';\n }\n if (Array.isArray(value)) {\n return value.length > 0;\n }\n if (typeof value === 'object') {\n if (typeof Blob !== 'undefined' && value instanceof Blob) {\n return true;\n }\n // A chosen file has no own keys: only plain objects are empty without them.\n if (isPlainObject(value)) {\n return Object.keys(value).length > 0;\n }\n const { length, size } = value as { length?: unknown; size?: unknown };\n if (typeof length === 'number') {\n return length > 0;\n }\n return typeof size === 'number' ? size > 0 : true;\n }\n return true;\n}\n\nfunction isPlainObject(value: object): boolean {\n const prototype: unknown = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nexport function isEqual(a: unknown, b: unknown): boolean {\n if (a === b) {\n return true;\n }\n if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) {\n return false;\n }\n return JSON.stringify(a) === JSON.stringify(b);\n}\n"],"mappings":";;AACA,SAAgB,SAAS,QAAiB,MAAuB;CAC7D,IAAI,SAAS,IACT,OAAO;CAEX,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,QAAiB,SAAS,QAAQ;EACrD,IAAI,YAAY,QAAQ,OAAO,YAAY,UACvC;EAEJ,OAAQ,QAAoC;CAChD,GAAG,MAAM;AACb;;;;;;AAOA,SAAgB,SAAS,OAAyB;CAC9C,IAAI,UAAU,QAAQ,UAAU,KAAA,GAC5B,OAAO;CAEX,IAAI,OAAO,UAAU,UACjB,OAAO,MAAM,KAAK,MAAM;CAE5B,IAAI,MAAM,QAAQ,KAAK,GACnB,OAAO,MAAM,SAAS;CAE1B,IAAI,OAAO,UAAU,UAAU;EAC3B,IAAI,OAAO,SAAS,eAAe,iBAAiB,MAChD,OAAO;EAGX,IAAI,cAAc,KAAK,GACnB,OAAO,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS;EAEvC,MAAM,EAAE,QAAQ,SAAS;EACzB,IAAI,OAAO,WAAW,UAClB,OAAO,SAAS;EAEpB,OAAO,OAAO,SAAS,WAAW,OAAO,IAAI;CACjD;CACA,OAAO;AACX;AAEA,SAAS,cAAc,OAAwB;CAC3C,MAAM,YAAqB,OAAO,eAAe,KAAK;CACtD,OAAO,cAAc,OAAO,aAAa,cAAc;AAC3D;AAEA,SAAgB,SAAS,OAAkD;CACvE,OAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC9E;AAEA,SAAgB,QAAQ,GAAY,GAAqB;CACrD,IAAI,MAAM,GACN,OAAO;CAEX,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,YAAY,MAAM,QAAQ,MAAM,MACtE,OAAO;CAEX,OAAO,KAAK,UAAU,CAAC,MAAM,KAAK,UAAU,CAAC;AACjD"}
@@ -0,0 +1,42 @@
1
+ import { type ListQuery } from './query.js';
2
+ /** The widget types that every client draws (decision 0064). Other types are widgets of plugins. */
3
+ export declare const BUILT_IN_WIDGET_TYPES: readonly ["stat", "series", "list"];
4
+ export type BuiltInWidgetType = (typeof BUILT_IN_WIDGET_TYPES)[number];
5
+ /** The periods of the points of a `series` widget. */
6
+ export declare const WIDGET_SERIES_PERIODS: readonly ["day", "week", "month"];
7
+ export type WidgetSeriesPeriod = (typeof WIDGET_SERIES_PERIODS)[number];
8
+ /** The most items a `list` widget shows: the backend sends the most useful first. */
9
+ export declare const WIDGET_LIST_MAX_ITEMS = 5;
10
+ /** The built-in types that can read the list of a resource (`settings.resource`). */
11
+ export declare const RESOURCE_WIDGET_TYPES: readonly ["stat", "list"];
12
+ /** Query parameters that the client sets on the list of a widget on a resource, never `query`. */
13
+ export declare const WIDGET_RESERVED_QUERY_PARAMS: readonly ["page", "perPage", "cursor"];
14
+ export declare function isBuiltInWidgetType(type: string): type is BuiltInWidgetType;
15
+ /** A widget as the helpers read it: the `Widget` of the definition, or one a backend writes. */
16
+ interface WidgetLike {
17
+ type: string;
18
+ settings?: Record<string, unknown> | undefined;
19
+ }
20
+ /** A built-in widget that reads the list of a resource, with no data of its own (decision 0064). */
21
+ export interface WidgetResource {
22
+ /** The id of the resource. */
23
+ resource: string;
24
+ /** The `query` of the widget, as query parameters, without `page`, `perPage` and `cursor`. */
25
+ params: URLSearchParams;
26
+ /** The same query, parsed: the query of the list request, and of the link to the list. */
27
+ query: ListQuery;
28
+ }
29
+ /**
30
+ * The resource whose list feeds a built-in `stat` or `list` widget, and its query: `null` for a
31
+ * widget with data of its own at `GET /dashboard/widgets/{widget}`, and for widgets of plugins.
32
+ */
33
+ export declare function getWidgetResource(widget: WidgetLike): WidgetResource | null;
34
+ /**
35
+ * Checks the data of a widget against the shape of its type (decision 0064), without the schemas:
36
+ * the paths of the wrong keys (`value`, `points.2.date`), empty when it is right. The data of a
37
+ * widget of a plugin only has to be an object. The dates of a series must go up, one point per
38
+ * period.
39
+ */
40
+ export declare function checkWidgetData(type: string, data: unknown): string[];
41
+ export {};
42
+ //# sourceMappingURL=widgets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widgets.d.ts","sourceRoot":"","sources":["../src/widg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