@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.
Files changed (159) 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/aggregates.d.ts +135 -0
  6. package/dist/aggregates.d.ts.map +1 -0
  7. package/dist/aggregates.js +236 -0
  8. package/dist/aggregates.js.map +1 -0
  9. package/dist/compound.d.ts +20 -0
  10. package/dist/compound.d.ts.map +1 -0
  11. package/dist/compound.js +27 -0
  12. package/dist/compound.js.map +1 -0
  13. package/dist/conditions.d.ts +1 -1
  14. package/dist/conformance/index.d.ts +6 -0
  15. package/dist/conformance/index.d.ts.map +1 -1
  16. package/dist/conformance/index.js +970 -11
  17. package/dist/conformance/index.js.map +1 -1
  18. package/dist/constants.d.ts +108 -2
  19. package/dist/constants.d.ts.map +1 -1
  20. package/dist/constants.js +181 -3
  21. package/dist/constants.js.map +1 -1
  22. package/dist/context.d.ts +15 -0
  23. package/dist/context.d.ts.map +1 -0
  24. package/dist/context.js +34 -0
  25. package/dist/context.js.map +1 -0
  26. package/dist/currencies.d.ts +22 -0
  27. package/dist/currencies.d.ts.map +1 -0
  28. package/dist/currencies.js +231 -0
  29. package/dist/currencies.js.map +1 -0
  30. package/dist/dashboards.d.ts +95 -0
  31. package/dist/dashboards.d.ts.map +1 -0
  32. package/dist/dashboards.js +140 -0
  33. package/dist/dashboards.js.map +1 -0
  34. package/dist/index.d.ts +4 -4
  35. package/dist/index.js +22 -8
  36. package/dist/libraries.d.ts +33 -0
  37. package/dist/libraries.d.ts.map +1 -0
  38. package/dist/libraries.js +59 -0
  39. package/dist/libraries.js.map +1 -0
  40. package/dist/links.d.ts +38 -0
  41. package/dist/links.d.ts.map +1 -0
  42. package/dist/links.js +65 -0
  43. package/dist/links.js.map +1 -0
  44. package/dist/lint.d.ts +4 -4
  45. package/dist/lint.d.ts.map +1 -1
  46. package/dist/lint.js +540 -15
  47. package/dist/lint.js.map +1 -1
  48. package/dist/mock/auth.d.ts +71 -0
  49. package/dist/mock/auth.d.ts.map +1 -0
  50. package/dist/mock/auth.js +346 -0
  51. package/dist/mock/auth.js.map +1 -0
  52. package/dist/mock/example.d.ts +1 -1
  53. package/dist/mock/example.d.ts.map +1 -1
  54. package/dist/mock/example.js +49 -28
  55. package/dist/mock/example.js.map +1 -1
  56. package/dist/mock/index.d.ts +96 -5
  57. package/dist/mock/index.d.ts.map +1 -1
  58. package/dist/mock/index.js +505 -44
  59. package/dist/mock/index.js.map +1 -1
  60. package/dist/openapi.d.ts.map +1 -1
  61. package/dist/openapi.js +462 -50
  62. package/dist/openapi.js.map +1 -1
  63. package/dist/periods.d.ts +61 -0
  64. package/dist/periods.d.ts.map +1 -0
  65. package/dist/periods.js +130 -0
  66. package/dist/periods.js.map +1 -0
  67. package/dist/problem.d.ts +1 -1
  68. package/dist/query.d.ts +18 -0
  69. package/dist/query.d.ts.map +1 -1
  70. package/dist/query.js +34 -8
  71. package/dist/query.js.map +1 -1
  72. package/dist/resourceTypes.d.ts +39 -0
  73. package/dist/resourceTypes.d.ts.map +1 -0
  74. package/dist/resourceTypes.js +34 -0
  75. package/dist/resourceTypes.js.map +1 -0
  76. package/dist/rules.d.ts +18 -5
  77. package/dist/rules.d.ts.map +1 -1
  78. package/dist/rules.js +233 -15
  79. package/dist/rules.js.map +1 -1
  80. package/dist/runtime/index.d.ts +23 -10
  81. package/dist/runtime/index.d.ts.map +1 -1
  82. package/dist/runtime/index.js +16 -3
  83. package/dist/schemas/action.d.ts +119 -10
  84. package/dist/schemas/action.d.ts.map +1 -1
  85. package/dist/schemas/action.js +20 -3
  86. package/dist/schemas/action.js.map +1 -1
  87. package/dist/schemas/api.d.ts +266 -5
  88. package/dist/schemas/api.d.ts.map +1 -1
  89. package/dist/schemas/api.js +134 -16
  90. package/dist/schemas/api.js.map +1 -1
  91. package/dist/schemas/boot.d.ts +25 -1
  92. package/dist/schemas/boot.d.ts.map +1 -1
  93. package/dist/schemas/boot.js +2 -1
  94. package/dist/schemas/boot.js.map +1 -1
  95. package/dist/schemas/common.d.ts +1 -0
  96. package/dist/schemas/common.d.ts.map +1 -1
  97. package/dist/schemas/common.js +2 -1
  98. package/dist/schemas/common.js.map +1 -1
  99. package/dist/schemas/definition.d.ts +1414 -30
  100. package/dist/schemas/definition.d.ts.map +1 -1
  101. package/dist/schemas/definition.js +77 -17
  102. package/dist/schemas/definition.js.map +1 -1
  103. package/dist/schemas/field.d.ts +358 -2
  104. package/dist/schemas/field.d.ts.map +1 -1
  105. package/dist/schemas/field.js +161 -20
  106. package/dist/schemas/field.js.map +1 -1
  107. package/dist/schemas/index.d.ts +5820 -46
  108. package/dist/schemas/index.d.ts.map +1 -1
  109. package/dist/schemas/index.js +69 -7
  110. package/dist/schemas/index.js.map +1 -1
  111. package/dist/schemas/jsonRules.d.ts +83 -0
  112. package/dist/schemas/jsonRules.d.ts.map +1 -0
  113. package/dist/schemas/jsonRules.js +46 -0
  114. package/dist/schemas/jsonRules.js.map +1 -0
  115. package/dist/schemas/layout.d.ts +2 -1
  116. package/dist/schemas/layout.d.ts.map +1 -1
  117. package/dist/schemas/layout.js +2 -1
  118. package/dist/schemas/layout.js.map +1 -1
  119. package/dist/schemas/list.d.ts +34 -2
  120. package/dist/schemas/list.d.ts.map +1 -1
  121. package/dist/schemas/list.js +21 -6
  122. package/dist/schemas/list.js.map +1 -1
  123. package/dist/schemas/resource.d.ts +826 -17
  124. package/dist/schemas/resource.d.ts.map +1 -1
  125. package/dist/schemas/resource.js +26 -4
  126. package/dist/schemas/resource.js.map +1 -1
  127. package/dist/schemas/theme.d.ts +6 -2
  128. package/dist/schemas/theme.d.ts.map +1 -1
  129. package/dist/schemas/theme.js +1 -0
  130. package/dist/schemas/theme.js.map +1 -1
  131. package/dist/schemas/widget.d.ts +4379 -0
  132. package/dist/schemas/widget.d.ts.map +1 -0
  133. package/dist/schemas/widget.js +269 -0
  134. package/dist/schemas/widget.js.map +1 -0
  135. package/dist/search.d.ts +51 -0
  136. package/dist/search.d.ts.map +1 -0
  137. package/dist/search.js +53 -0
  138. package/dist/search.js.map +1 -0
  139. package/dist/themes.d.ts +1 -1
  140. package/dist/transforms.d.ts +17 -0
  141. package/dist/transforms.d.ts.map +1 -0
  142. package/dist/transforms.js +34 -0
  143. package/dist/transforms.js.map +1 -0
  144. package/dist/validate.d.ts +5 -3
  145. package/dist/validate.d.ts.map +1 -1
  146. package/dist/validate.js +36 -2
  147. package/dist/validate.js.map +1 -1
  148. package/dist/values.d.ts +5 -1
  149. package/dist/values.d.ts.map +1 -1
  150. package/dist/values.js +16 -2
  151. package/dist/values.js.map +1 -1
  152. package/dist/widgets.d.ts +232 -0
  153. package/dist/widgets.d.ts.map +1 -0
  154. package/dist/widgets.js +630 -0
  155. package/dist/widgets.js.map +1 -0
  156. package/package.json +6 -3
  157. package/schema/boot.schema.json +1461 -104
  158. package/schema/definition.schema.json +1459 -105
  159. package/schema/openapi.json +7176 -2000
@@ -0,0 +1,23 @@
1
+ import { type AddressPart } from './constants.js';
2
+ import type { Field } from './schemas/field.js';
3
+ /** The countries whose postal codes the `postalCode` rule checks: Canada and the United States. */
4
+ export declare const POSTAL_CODE_COUNTRIES: readonly string[];
5
+ /**
6
+ * A postal code in the format of its country: `H2X 1Y4` for Canada (`h2x1y4`), `12345-6789` for
7
+ * the United States (`123456789`). Elsewhere, or when it doesn't read as one of its country, the
8
+ * code in capitals, its spaces collapsed.
9
+ */
10
+ export declare function normalizePostalCode(code: string, country?: string | null): string;
11
+ /**
12
+ * Whether a postal code is one of its country, once normalized. Postal codes of countries whose
13
+ * format Panneau doesn't check (`POSTAL_CODE_COUNTRIES`), or without a country, pass.
14
+ */
15
+ export declare function isPostalCode(code: string, country?: string | null): boolean;
16
+ /** Whether a value is one of the parts of an address. */
17
+ export declare function isAddressPart(value: unknown): value is AddressPart;
18
+ /**
19
+ * The parts a filled address of a field must have: those of `settings.required`, or `street`,
20
+ * `city` and `country`.
21
+ */
22
+ export declare function getAddressRequiredParts(field: Pick<Field, 'settings'>): AddressPart[];
23
+ //# sourceMappingURL=addresses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addresses.d.ts","sourceRoot":"","sources":["../src/addresses.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,KAAK,WAAW,EAAkC,MAAM,aAAa,CAAC;AAC9F,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAS7C,mGAAmG;AACnG,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAAyB,CAAC;AAO7E;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAiBjF;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAI3E;AAED,yDAAyD;AACzD,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,WAAW,EAAE,CAKrF"}
@@ -0,0 +1,52 @@
1
+ import { ADDRESS_PARTS, DEFAULT_ADDRESS_REQUIRED_PARTS } from "./constants.js";
2
+ //#region src/addresses.ts
3
+ /** The formats of normalized postal codes, for the countries whose postal codes are checked. */
4
+ var FORMATS = {
5
+ CA: /^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z] \d[ABCEGHJ-NPRSTV-Z]\d$/,
6
+ US: /^\d{5}(-\d{4})?$/
7
+ };
8
+ /** The countries whose postal codes the `postalCode` rule checks: Canada and the United States. */
9
+ var POSTAL_CODE_COUNTRIES = Object.keys(FORMATS);
10
+ /** Capitals, with the spaces trimmed and collapsed: the postal codes of other countries. */
11
+ function normalizeText(code) {
12
+ return code.trim().replace(/\s+/g, " ").toUpperCase();
13
+ }
14
+ /**
15
+ * A postal code in the format of its country: `H2X 1Y4` for Canada (`h2x1y4`), `12345-6789` for
16
+ * the United States (`123456789`). Elsewhere, or when it doesn't read as one of its country, the
17
+ * code in capitals, its spaces collapsed.
18
+ */
19
+ function normalizePostalCode(code, country) {
20
+ const compact = code.replace(/[\s-]+/g, "").toUpperCase();
21
+ switch (country?.toUpperCase()) {
22
+ case "CA": return /^[A-Z]\d[A-Z]\d[A-Z]\d$/.test(compact) ? `${compact.slice(0, 3)} ${compact.slice(3)}` : normalizeText(code);
23
+ case "US":
24
+ if (/^\d{5}$/.test(compact)) return compact;
25
+ return /^\d{9}$/.test(compact) ? `${compact.slice(0, 5)}-${compact.slice(5)}` : normalizeText(code);
26
+ default: return normalizeText(code);
27
+ }
28
+ }
29
+ /**
30
+ * Whether a postal code is one of its country, once normalized. Postal codes of countries whose
31
+ * format Panneau doesn't check (`POSTAL_CODE_COUNTRIES`), or without a country, pass.
32
+ */
33
+ function isPostalCode(code, country) {
34
+ const format = country !== void 0 && country !== null ? FORMATS[country.toUpperCase()] : void 0;
35
+ return format === void 0 || format.test(normalizePostalCode(code, country));
36
+ }
37
+ /** Whether a value is one of the parts of an address. */
38
+ function isAddressPart(value) {
39
+ return typeof value === "string" && ADDRESS_PARTS.includes(value);
40
+ }
41
+ /**
42
+ * The parts a filled address of a field must have: those of `settings.required`, or `street`,
43
+ * `city` and `country`.
44
+ */
45
+ function getAddressRequiredParts(field) {
46
+ const setting = field.settings?.required;
47
+ return Array.isArray(setting) ? setting.filter(isAddressPart) : [...DEFAULT_ADDRESS_REQUIRED_PARTS];
48
+ }
49
+ //#endregion
50
+ export { POSTAL_CODE_COUNTRIES, getAddressRequiredParts, isAddressPart, isPostalCode, normalizePostalCode };
51
+
52
+ //# sourceMappingURL=addresses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addresses.js","names":[],"sources":["../src/addresses.ts"],"sourcesContent":["// Addresses (decision 0054): their required parts, and postal codes by country, which clients and\n// backends normalize, and whose formats the `postalCode` rule checks. This module doesn't import\n// zod.\nimport { ADDRESS_PARTS, type AddressPart, DEFAULT_ADDRESS_REQUIRED_PARTS } from './constants';\nimport type { Field } from './schemas/field';\n\n/** The formats of normalized postal codes, for the countries whose postal codes are checked. */\nconst FORMATS: Readonly<Record<string, RegExp>> = {\n // Letters that Canada Post doesn't use (D, F, I, O, Q, U, and W or Z first) are refused\n CA: /^[ABCEGHJ-NPRSTVXY]\\d[ABCEGHJ-NPRSTV-Z] \\d[ABCEGHJ-NPRSTV-Z]\\d$/,\n US: /^\\d{5}(-\\d{4})?$/,\n};\n\n/** The countries whose postal codes the `postalCode` rule checks: Canada and the United States. */\nexport const POSTAL_CODE_COUNTRIES: readonly string[] = Object.keys(FORMATS);\n\n/** Capitals, with the spaces trimmed and collapsed: the postal codes of other countries. */\nfunction normalizeText(code: string): string {\n return code.trim().replace(/\\s+/g, ' ').toUpperCase();\n}\n\n/**\n * A postal code in the format of its country: `H2X 1Y4` for Canada (`h2x1y4`), `12345-6789` for\n * the United States (`123456789`). Elsewhere, or when it doesn't read as one of its country, the\n * code in capitals, its spaces collapsed.\n */\nexport function normalizePostalCode(code: string, country?: string | null): string {\n const compact = code.replace(/[\\s-]+/g, '').toUpperCase();\n switch (country?.toUpperCase()) {\n case 'CA':\n return /^[A-Z]\\d[A-Z]\\d[A-Z]\\d$/.test(compact)\n ? `${compact.slice(0, 3)} ${compact.slice(3)}`\n : normalizeText(code);\n case 'US':\n if (/^\\d{5}$/.test(compact)) {\n return compact;\n }\n return /^\\d{9}$/.test(compact)\n ? `${compact.slice(0, 5)}-${compact.slice(5)}`\n : normalizeText(code);\n default:\n return normalizeText(code);\n }\n}\n\n/**\n * Whether a postal code is one of its country, once normalized. Postal codes of countries whose\n * format Panneau doesn't check (`POSTAL_CODE_COUNTRIES`), or without a country, pass.\n */\nexport function isPostalCode(code: string, country?: string | null): boolean {\n const format =\n country !== undefined && country !== null ? FORMATS[country.toUpperCase()] : undefined;\n return format === undefined || format.test(normalizePostalCode(code, country));\n}\n\n/** Whether a value is one of the parts of an address. */\nexport function isAddressPart(value: unknown): value is AddressPart {\n return typeof value === 'string' && (ADDRESS_PARTS as readonly string[]).includes(value);\n}\n\n/**\n * The parts a filled address of a field must have: those of `settings.required`, or `street`,\n * `city` and `country`.\n */\nexport function getAddressRequiredParts(field: Pick<Field, 'settings'>): AddressPart[] {\n const setting = field.settings?.required;\n return Array.isArray(setting)\n ? setting.filter(isAddressPart)\n : [...DEFAULT_ADDRESS_REQUIRED_PARTS];\n}\n"],"mappings":";;;AAOA,IAAM,UAA4C;CAE9C,IAAI;CACJ,IAAI;AACR;;AAGA,IAAa,wBAA2C,OAAO,KAAK,OAAO;;AAG3E,SAAS,cAAc,MAAsB;CACzC,OAAO,KAAK,KAAK,CAAC,CAAC,QAAQ,QAAQ,GAAG,CAAC,CAAC,YAAY;AACxD;;;;;;AAOA,SAAgB,oBAAoB,MAAc,SAAiC;CAC/E,MAAM,UAAU,KAAK,QAAQ,WAAW,EAAE,CAAC,CAAC,YAAY;CACxD,QAAQ,SAAS,YAAY,GAA7B;EACI,KAAK,MACD,OAAO,0BAA0B,KAAK,OAAO,IACvC,GAAG,QAAQ,MAAM,GAAG,CAAC,EAAE,GAAG,QAAQ,MAAM,CAAC,MACzC,cAAc,IAAI;EAC5B,KAAK;GACD,IAAI,UAAU,KAAK,OAAO,GACtB,OAAO;GAEX,OAAO,UAAU,KAAK,OAAO,IACvB,GAAG,QAAQ,MAAM,GAAG,CAAC,EAAE,GAAG,QAAQ,MAAM,CAAC,MACzC,cAAc,IAAI;EAC5B,SACI,OAAO,cAAc,IAAI;CACjC;AACJ;;;;;AAMA,SAAgB,aAAa,MAAc,SAAkC;CACzE,MAAM,SACF,YAAY,KAAA,KAAa,YAAY,OAAO,QAAQ,QAAQ,YAAY,KAAK,KAAA;CACjF,OAAO,WAAW,KAAA,KAAa,OAAO,KAAK,oBAAoB,MAAM,OAAO,CAAC;AACjF;;AAGA,SAAgB,cAAc,OAAsC;CAChE,OAAO,OAAO,UAAU,YAAa,cAAoC,SAAS,KAAK;AAC3F;;;;;AAMA,SAAgB,wBAAwB,OAA+C;CACnF,MAAM,UAAU,MAAM,UAAU;CAChC,OAAO,MAAM,QAAQ,OAAO,IACtB,QAAQ,OAAO,aAAa,IAC5B,CAAC,GAAG,8BAA8B;AAC5C"}
@@ -0,0 +1,135 @@
1
+ import { type FilterRange, type ListQuery } from './query.js';
2
+ import type { BreakdownWidgetData, SeriesWidgetData, StatWidgetData } from './schemas/index.js';
3
+ import { type WidgetSeriesPeriod } from './widgets.js';
4
+ /**
5
+ * The most points of a `series` that `GET /resources/{resource}/aggregate` answers: a year of
6
+ * days. A longer range keeps its latest periods.
7
+ */
8
+ export declare const AGGREGATE_MAX_POINTS = 366;
9
+ /** The measure that counts the items, the default one. */
10
+ export declare const AGGREGATE_COUNT = "count";
11
+ /** The aggregates a list declares (`list.aggregates`, decision 0084): nothing else is aggregated. */
12
+ export interface ListAggregatesLike {
13
+ /** Fields that can be summed. */
14
+ sum?: readonly string[] | undefined;
15
+ /** Fields whose values the items can be grouped by. */
16
+ groupBy?: readonly string[] | undefined;
17
+ /** Date fields whose periods the items can be grouped by. */
18
+ dates?: readonly string[] | undefined;
19
+ }
20
+ /** What is measured of the items: how many they are, or the sum of a field. */
21
+ export type AggregateMeasure = {
22
+ type: 'count';
23
+ } | {
24
+ type: 'sum';
25
+ field: string;
26
+ };
27
+ /** How the items are grouped: by the period of a date, or by the values of a field. */
28
+ export type AggregateGroup = {
29
+ type: 'period';
30
+ period: WidgetSeriesPeriod;
31
+ field: string;
32
+ } | {
33
+ type: 'field';
34
+ field: string;
35
+ };
36
+ /** A query of the aggregate endpoint, read: its measure, and its group if it has one. */
37
+ export interface AggregateQuery {
38
+ measure: AggregateMeasure;
39
+ group: AggregateGroup | null;
40
+ }
41
+ /**
42
+ * A request of `GET /resources/{resource}/aggregate`: the filters and the search of the list,
43
+ * the `measure` (`count` by default) and the `group`.
44
+ */
45
+ export interface AggregateRequest {
46
+ filter?: ListQuery['filter'];
47
+ q?: string | undefined;
48
+ /** `count`, or `sum:{field}`. Defaults to `count`. */
49
+ measure?: string | undefined;
50
+ /** `{day|week|month}:{date field}`, or a field of `groupBy`. */
51
+ group?: string | null | undefined;
52
+ }
53
+ /** The built-in widget type of an answer of the aggregate endpoint. */
54
+ export type AggregateWidgetType = 'stat' | 'series' | 'breakdown';
55
+ /** Reads a measure: `count`, or `sum:{field}`. `null` when it is neither. */
56
+ export declare function parseAggregateMeasure(value: string): AggregateMeasure | null;
57
+ /**
58
+ * Reads a group: `{period}:{date field}`, where the period is `day`, `week` or `month`, or the
59
+ * name of a field. `null` when it is neither.
60
+ */
61
+ export declare function parseAggregateGroup(value: string): AggregateGroup | null;
62
+ /** The shape of the answer to a group: a `stat` without one, a `series` or a `breakdown`. */
63
+ export declare function getAggregateWidgetType(group: AggregateGroup | null): AggregateWidgetType;
64
+ /** Serializes a request of the aggregate endpoint: the filters and the search, then its own. */
65
+ export declare function toAggregateParams(request: AggregateRequest): URLSearchParams;
66
+ /** An aggregate query as a backend reads it: valid, or the messages of its invalid parameters. */
67
+ export type ReadAggregateQueryResult = {
68
+ query: AggregateQuery;
69
+ errors?: undefined;
70
+ } | {
71
+ query?: undefined;
72
+ errors: Record<string, string[]>;
73
+ };
74
+ /**
75
+ * Reads `measure` and `group` of `GET /resources/{resource}/aggregate` against the aggregates of
76
+ * the list: the reference of how a backend validates them. `measure` defaults to `count`; a
77
+ * `sum:` names a field of `sum`, a period names a field of `dates`, and another group a field of
78
+ * `groupBy`. Invalid parameters are a `422`, with `errors` keyed by parameter. The filters and the
79
+ * search are read as the list reads them.
80
+ */
81
+ export declare function readAggregateQuery(params: URLSearchParams, aggregates: ListAggregatesLike): ReadAggregateQueryResult;
82
+ /**
83
+ * The first day of the period of a day: the day itself, the Monday of its week (ISO 8601), or the
84
+ * first day of its month. `2026-10-08` is in the week of `2026-10-05`.
85
+ */
86
+ export declare function startOfPeriod(day: string, period: WidgetSeriesPeriod): string;
87
+ /** The first day of the period after the one that starts on `start`. */
88
+ export declare function nextPeriod(start: string, period: WidgetSeriesPeriod): string;
89
+ /**
90
+ * The first days of the periods from the one of `from` to the one of `to`, both included: at most
91
+ * `max` of them, the latest. Empty when `to` is before `from`.
92
+ */
93
+ export declare function listPeriods(from: string, to: string, period: WidgetSeriesPeriod, max?: number): string[];
94
+ /** The fields an aggregate reads, as the definition declares them. */
95
+ export interface AggregateField {
96
+ name: string;
97
+ type: string;
98
+ options?: readonly {
99
+ value: unknown;
100
+ label: string;
101
+ tone?: string | undefined;
102
+ }[] | undefined;
103
+ }
104
+ export interface AggregateItemsOptions {
105
+ /** The fields of the resource: the options of a `select` give the labels and the tones. */
106
+ fields: readonly AggregateField[];
107
+ /**
108
+ * The bounds of the `date-range` filter of the query on the date of a period group, whose id is
109
+ * the name of that field: the range of the series. Without a bound, the series starts on the
110
+ * period of the first item, or ends on the period of the last.
111
+ */
112
+ range?: FilterRange | undefined;
113
+ /** The label of the part of the items without a value. Defaults to `None`. */
114
+ emptyLabel?: string;
115
+ }
116
+ /**
117
+ * Aggregates items that a list query already filtered: the reference of what
118
+ * `GET /resources/{resource}/aggregate` answers (decision 0084).
119
+ *
120
+ * - Without a group: a `stat`, the count or the sum of the items.
121
+ * - By a period: a `series`, one point per period from its range, 0 for the periods without items.
122
+ * The range is the bounds of the `date-range` filter on the date (`range`), and without a bound,
123
+ * the period of the first or the last item; at most `AGGREGATE_MAX_POINTS` periods, the latest.
124
+ * Items without a date are left out. `total` is the sum of the points.
125
+ * - By a field: a `breakdown`, a part per value, the largest first, at most
126
+ * `WIDGET_BREAKDOWN_MAX_ITEMS`, the rest in `other`. An item with several values counts in each
127
+ * of their parts, once in `total`; one without a value counts in the part of `key: null`. The
128
+ * options of a `select` give their labels and tones, a reference its `label`.
129
+ *
130
+ * A sum of `money` values adds their amounts, in minor units.
131
+ */
132
+ export declare function aggregateItems(items: readonly Record<string, unknown>[], query: AggregateQuery, options: AggregateItemsOptions): StatWidgetData | SeriesWidgetData | BreakdownWidgetData;
133
+ /** The bounds of the `date-range` filter on a field in a list query, if it has them. */
134
+ export declare function getFilterRange(query: Pick<ListQuery, 'filter'>, field: string): FilterRange | undefined;
135
+ //# sourceMappingURL=aggregates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aggregates.d.ts","sourceRoot":"","sources":["../src/aggregates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAiC,MAAM,SAAS,CAAC;AAC1F,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEvF,OAAO,EAGH,KAAK,kBAAkB,EAC1B,MAAM,WAAW,CAAC;AAEnB;;;GAGG;AACH,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,0DAA0D;AAC1D,eAAO,MAAM,eAAe,UAAU,CAAC;AAEvC,qGAAqG;AACrG,MAAM,WAAW,kBAAkB;IAC/B,iCAAiC;IACjC,GAAG,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACpC,uDAAuD;IACvD,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACxC,6DAA6D;IAC7D,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;CACzC;AAED,+EAA+E;AAC/E,MAAM,MAAM,gBAAgB,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAElF,uFAAuF;AACvF,MAAM,MAAM,cAAc,GACpB;IAAE,IAAI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AgB,cAAc,CAC1B,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,EAChC,KAAK,EAAE,MAAM,GACd,WAAW,GAAG,SAAS,CAGzB"}
@@ -0,0 +1,236 @@
1
+ import { isRecord } from "./values.js";
2
+ import { isFilterRange, toSearchParams } from "./query.js";
3
+ import { WIDGET_SERIES_PERIODS } from "./widgets.js";
4
+ //#region src/aggregates.ts
5
+ /**
6
+ * The most points of a `series` that `GET /resources/{resource}/aggregate` answers: a year of
7
+ * days. A longer range keeps its latest periods.
8
+ */
9
+ var AGGREGATE_MAX_POINTS = 366;
10
+ /** The measure that counts the items, the default one. */
11
+ var AGGREGATE_COUNT = "count";
12
+ /** Reads a measure: `count`, or `sum:{field}`. `null` when it is neither. */
13
+ function parseAggregateMeasure(value) {
14
+ if (value === "count") return { type: "count" };
15
+ const field = /^sum:(.+)$/.exec(value)?.[1];
16
+ return field !== void 0 ? {
17
+ type: "sum",
18
+ field
19
+ } : null;
20
+ }
21
+ /**
22
+ * Reads a group: `{period}:{date field}`, where the period is `day`, `week` or `month`, or the
23
+ * name of a field. `null` when it is neither.
24
+ */
25
+ function parseAggregateGroup(value) {
26
+ const match = /^([^:]*):(.*)$/.exec(value);
27
+ if (match === null) return value !== "" ? {
28
+ type: "field",
29
+ field: value
30
+ } : null;
31
+ const [, period = "", field = ""] = match;
32
+ return WIDGET_SERIES_PERIODS.includes(period) && field !== "" ? {
33
+ type: "period",
34
+ period,
35
+ field
36
+ } : null;
37
+ }
38
+ /** The shape of the answer to a group: a `stat` without one, a `series` or a `breakdown`. */
39
+ function getAggregateWidgetType(group) {
40
+ if (group === null) return "stat";
41
+ return group.type === "period" ? "series" : "breakdown";
42
+ }
43
+ /** Serializes a request of the aggregate endpoint: the filters and the search, then its own. */
44
+ function toAggregateParams(request) {
45
+ const params = toSearchParams({
46
+ ...request.filter !== void 0 && { filter: request.filter },
47
+ ...request.q !== void 0 && { q: request.q }
48
+ });
49
+ params.set("measure", request.measure ?? "count");
50
+ if (request.group !== void 0 && request.group !== null && request.group !== "") params.set("group", request.group);
51
+ return params;
52
+ }
53
+ /**
54
+ * Reads `measure` and `group` of `GET /resources/{resource}/aggregate` against the aggregates of
55
+ * the list: the reference of how a backend validates them. `measure` defaults to `count`; a
56
+ * `sum:` names a field of `sum`, a period names a field of `dates`, and another group a field of
57
+ * `groupBy`. Invalid parameters are a `422`, with `errors` keyed by parameter. The filters and the
58
+ * search are read as the list reads them.
59
+ */
60
+ function readAggregateQuery(params, aggregates) {
61
+ const errors = {};
62
+ const measure = parseAggregateMeasure(params.get("measure") ?? "count");
63
+ if (measure === null) errors.measure = ["The measure must be `count` or `sum:{field}`."];
64
+ else if (measure.type === "sum" && !(aggregates.sum ?? []).includes(measure.field)) errors.measure = [`The field \`${measure.field}\` can't be summed.`];
65
+ const rawGroup = params.get("group");
66
+ let group = null;
67
+ if (rawGroup !== null) {
68
+ group = parseAggregateGroup(rawGroup);
69
+ if (group === null) errors.group = ["The group must be `{day|week|month}:{date field}` or a field."];
70
+ else if (group.type === "period" && !(aggregates.dates ?? []).includes(group.field)) errors.group = [`The field \`${group.field}\` isn't a date that can be grouped.`];
71
+ else if (group.type === "field" && !(aggregates.groupBy ?? []).includes(group.field)) errors.group = [`The items can't be grouped by the field \`${group.field}\`.`];
72
+ }
73
+ if (Object.keys(errors).length > 0 || measure === null) return { errors };
74
+ return { query: {
75
+ measure,
76
+ group
77
+ } };
78
+ }
79
+ var DAY = /^\d{4}-\d{2}-\d{2}/;
80
+ /** The day of a `date` or `datetime` value, as the backend writes it: `null` without one. */
81
+ function dayOf(value) {
82
+ return typeof value === "string" && DAY.test(value) ? value.slice(0, 10) : null;
83
+ }
84
+ function toUtc(day) {
85
+ return /* @__PURE__ */ new Date(`${day.slice(0, 10)}T00:00:00Z`);
86
+ }
87
+ function fromUtc(date) {
88
+ return date.toISOString().slice(0, 10);
89
+ }
90
+ /**
91
+ * The first day of the period of a day: the day itself, the Monday of its week (ISO 8601), or the
92
+ * first day of its month. `2026-10-08` is in the week of `2026-10-05`.
93
+ */
94
+ function startOfPeriod(day, period) {
95
+ const date = toUtc(day);
96
+ if (period === "week") date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 6) % 7);
97
+ else if (period === "month") date.setUTCDate(1);
98
+ return fromUtc(date);
99
+ }
100
+ /** The first day of the period after the one that starts on `start`. */
101
+ function nextPeriod(start, period) {
102
+ const date = toUtc(start);
103
+ if (period === "month") date.setUTCMonth(date.getUTCMonth() + 1, 1);
104
+ else date.setUTCDate(date.getUTCDate() + (period === "week" ? 7 : 1));
105
+ return fromUtc(date);
106
+ }
107
+ /**
108
+ * The first days of the periods from the one of `from` to the one of `to`, both included: at most
109
+ * `max` of them, the latest. Empty when `to` is before `from`.
110
+ */
111
+ function listPeriods(from, to, period, max = 366) {
112
+ const last = startOfPeriod(to, period);
113
+ const periods = [];
114
+ for (let start = startOfPeriod(from, period); start <= last; start = nextPeriod(start, period)) {
115
+ periods.push(start);
116
+ if (periods.length > max) periods.shift();
117
+ }
118
+ return periods;
119
+ }
120
+ /** The value of an item, as a key of a part: the id of a reference, `null` when it is empty. */
121
+ function keysOf(value) {
122
+ if (Array.isArray(value)) {
123
+ const keys = value.flatMap((entry) => keysOf(entry).filter(({ key }) => key !== null));
124
+ return keys.length > 0 ? keys : [{ key: null }];
125
+ }
126
+ if (typeof value === "string") return [{ key: value === "" ? null : value }];
127
+ if (typeof value === "number" || typeof value === "boolean") return [{ key: value }];
128
+ if (isRecord(value) && (typeof value.id === "string" || typeof value.id === "number")) return [{
129
+ key: value.id,
130
+ ...typeof value.label === "string" && { label: value.label }
131
+ }];
132
+ return [{ key: null }];
133
+ }
134
+ /** The amount of a value that is summed: a number, or the amount of a `money` value. */
135
+ function amountOf(value) {
136
+ if (typeof value === "number" && Number.isFinite(value)) return value;
137
+ if (isRecord(value) && typeof value.amount === "number" && Number.isFinite(value.amount)) return value.amount;
138
+ return 0;
139
+ }
140
+ /**
141
+ * Aggregates items that a list query already filtered: the reference of what
142
+ * `GET /resources/{resource}/aggregate` answers (decision 0084).
143
+ *
144
+ * - Without a group: a `stat`, the count or the sum of the items.
145
+ * - By a period: a `series`, one point per period from its range, 0 for the periods without items.
146
+ * The range is the bounds of the `date-range` filter on the date (`range`), and without a bound,
147
+ * the period of the first or the last item; at most `AGGREGATE_MAX_POINTS` periods, the latest.
148
+ * Items without a date are left out. `total` is the sum of the points.
149
+ * - By a field: a `breakdown`, a part per value, the largest first, at most
150
+ * `WIDGET_BREAKDOWN_MAX_ITEMS`, the rest in `other`. An item with several values counts in each
151
+ * of their parts, once in `total`; one without a value counts in the part of `key: null`. The
152
+ * options of a `select` give their labels and tones, a reference its `label`.
153
+ *
154
+ * A sum of `money` values adds their amounts, in minor units.
155
+ */
156
+ function aggregateItems(items, query, options) {
157
+ const { measure, group } = query;
158
+ const measureOf = (item) => measure.type === "count" ? 1 : amountOf(item[measure.field]);
159
+ const total = items.reduce((sum, item) => sum + measureOf(item), 0);
160
+ if (group === null) return { value: total };
161
+ if (group.type === "period") {
162
+ const values = /* @__PURE__ */ new Map();
163
+ const days = [];
164
+ items.forEach((item) => {
165
+ const day = dayOf(item[group.field]);
166
+ if (day === null) return;
167
+ days.push(day);
168
+ const start = startOfPeriod(day, group.period);
169
+ values.set(start, (values.get(start) ?? 0) + measureOf(item));
170
+ });
171
+ days.sort();
172
+ const bound = (key) => {
173
+ const value = options.range?.[key];
174
+ return value !== void 0 && value !== "" ? dayOf(String(value)) : null;
175
+ };
176
+ const from = bound("from") ?? days[0] ?? bound("to");
177
+ const to = bound("to") ?? days.at(-1) ?? bound("from");
178
+ const points = from !== null && to !== null ? listPeriods(from, to, group.period).map((date) => ({
179
+ date,
180
+ value: values.get(date) ?? 0
181
+ })) : [];
182
+ return {
183
+ period: group.period,
184
+ points,
185
+ total: points.reduce((sum, point) => sum + point.value, 0)
186
+ };
187
+ }
188
+ const field = options.fields.find((candidate) => candidate.name === group.field);
189
+ const parts = /* @__PURE__ */ new Map();
190
+ items.forEach((item) => {
191
+ const amount = measureOf(item);
192
+ const seen = /* @__PURE__ */ new Set();
193
+ keysOf(item[group.field]).forEach(({ key, label }) => {
194
+ const id = JSON.stringify(key);
195
+ if (seen.has(id)) return;
196
+ seen.add(id);
197
+ const part = parts.get(id) ?? {
198
+ key,
199
+ label: key === null ? options.emptyLabel ?? "None" : label ?? String(key),
200
+ value: 0
201
+ };
202
+ part.value += amount;
203
+ parts.set(id, part);
204
+ });
205
+ });
206
+ const optionOf = (key) => field?.type === "select" ? field.options?.find((option) => String(option.value) === String(key)) : void 0;
207
+ const order = (key) => {
208
+ const index = field?.options?.findIndex((option) => String(option.value) === String(key));
209
+ return index === void 0 || index === -1 ? Infinity : index;
210
+ };
211
+ const sorted = [...parts.values()].sort((a, b) => b.value - a.value || order(a.key) - order(b.key) || a.label.localeCompare(b.label));
212
+ const shown = sorted.slice(0, 10);
213
+ const rest = sorted.slice(10);
214
+ return {
215
+ items: shown.map(({ key, label, value }) => {
216
+ const option = key !== null ? optionOf(key) : void 0;
217
+ return {
218
+ label: option?.label ?? label,
219
+ value,
220
+ key,
221
+ ...option?.tone !== void 0 && { tone: option.tone }
222
+ };
223
+ }),
224
+ total,
225
+ ...rest.length > 0 && { other: rest.reduce((sum, part) => sum + part.value, 0) }
226
+ };
227
+ }
228
+ /** The bounds of the `date-range` filter on a field in a list query, if it has them. */
229
+ function getFilterRange(query, field) {
230
+ const value = query.filter?.[field];
231
+ return isFilterRange(value) ? value : void 0;
232
+ }
233
+ //#endregion
234
+ export { AGGREGATE_COUNT, AGGREGATE_MAX_POINTS, aggregateItems, getAggregateWidgetType, getFilterRange, listPeriods, nextPeriod, parseAggregateGroup, parseAggregateMeasure, readAggregateQuery, startOfPeriod, toAggregateParams };
235
+
236
+ //# sourceMappingURL=aggregates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aggregates.js","names":[],"sources":["../src/aggregates.ts"],"sourcesContent":["import { type FilterRange, type ListQuery, isFilterRange, toSearchParams } from './query';\nimport type { BreakdownWidgetData, SeriesWidgetData, StatWidgetData } from './schemas';\nimport { isRecord } from './values';\nimport {\n WIDGET_BREAKDOWN_MAX_ITEMS,\n WIDGET_SERIES_PERIODS,\n type WidgetSeriesPeriod,\n} from './widgets';\n\n/**\n * The most points of a `series` that `GET /resources/{resource}/aggregate` answers: a year of\n * days. A longer range keeps its latest periods.\n */\nexport const AGGREGATE_MAX_POINTS = 366;\n\n/** The measure that counts the items, the default one. */\nexport const AGGREGATE_COUNT = 'count';\n\n/** The aggregates a list declares (`list.aggregates`, decision 0084): nothing else is aggregated. */\nexport interface ListAggregatesLike {\n /** Fields that can be summed. */\n sum?: readonly string[] | undefined;\n /** Fields whose values the items can be grouped by. */\n groupBy?: readonly string[] | undefined;\n /** Date fields whose periods the items can be grouped by. */\n dates?: readonly string[] | undefined;\n}\n\n/** What is measured of the items: how many they are, or the sum of a field. */\nexport type AggregateMeasure = { type: 'count' } | { type: 'sum'; field: string };\n\n/** How the items are grouped: by the period of a date, or by the values of a field. */\nexport type AggregateGroup =\n | { type: 'period'; period: WidgetSeriesPeriod; field: string }\n | { type: 'field'; field: string };\n\n/** A query of the aggregate endpoint, read: its measure, and its group if it has one. */\nexport interface AggregateQuery {\n measure: AggregateMeasure;\n group: AggregateGroup | null;\n}\n\n/**\n * A request of `GET /resources/{resource}/aggregate`: the filters and the search of the list,\n * the `measure` (`count` by default) and the `group`.\n */\nexport interface AggregateRequest {\n filter?: ListQuery['filter'];\n q?: string | undefined;\n /** `count`, or `sum:{field}`. Defaults to `count`. */\n measure?: string | undefined;\n /** `{day|week|month}:{date field}`, or a field of `groupBy`. */\n group?: string | null | undefined;\n}\n\n/** The built-in widget type of an answer of the aggregate endpoint. */\nexport type AggregateWidgetType = 'stat' | 'series' | 'breakdown';\n\n/** Reads a measure: `count`, or `sum:{field}`. `null` when it is neither. */\nexport function parseAggregateMeasure(value: string): AggregateMeasure | null {\n if (value === AGGREGATE_COUNT) {\n return { type: 'count' };\n }\n const field = /^sum:(.+)$/.exec(value)?.[1];\n return field !== undefined ? { type: 'sum', field } : null;\n}\n\n/**\n * Reads a group: `{period}:{date field}`, where the period is `day`, `week` or `month`, or the\n * name of a field. `null` when it is neither.\n */\nexport function parseAggregateGroup(value: string): AggregateGroup | null {\n const match = /^([^:]*):(.*)$/.exec(value);\n if (match === null) {\n return value !== '' ? { type: 'field', field: value } : null;\n }\n const [, period = '', field = ''] = match;\n return (WIDGET_SERIES_PERIODS as readonly string[]).includes(period) && field !== ''\n ? { type: 'period', period: period as WidgetSeriesPeriod, field }\n : null;\n}\n\n/** The shape of the answer to a group: a `stat` without one, a `series` or a `breakdown`. */\nexport function getAggregateWidgetType(group: AggregateGroup | null): AggregateWidgetType {\n if (group === null) {\n return 'stat';\n }\n return group.type === 'period' ? 'series' : 'breakdown';\n}\n\n/** Serializes a request of the aggregate endpoint: the filters and the search, then its own. */\nexport function toAggregateParams(request: AggregateRequest): URLSearchParams {\n const params = toSearchParams({\n ...(request.filter !== undefined && { filter: request.filter }),\n ...(request.q !== undefined && { q: request.q }),\n });\n params.set('measure', request.measure ?? AGGREGATE_COUNT);\n if (request.group !== undefined && request.group !== null && request.group !== '') {\n params.set('group', request.group);\n }\n return params;\n}\n\n/** An aggregate query as a backend reads it: valid, or the messages of its invalid parameters. */\nexport type ReadAggregateQueryResult =\n | { query: AggregateQuery; errors?: undefined }\n | { query?: undefined; errors: Record<string, string[]> };\n\n/**\n * Reads `measure` and `group` of `GET /resources/{resource}/aggregate` against the aggregates of\n * the list: the reference of how a backend validates them. `measure` defaults to `count`; a\n * `sum:` names a field of `sum`, a period names a field of `dates`, and another group a field of\n * `groupBy`. Invalid parameters are a `422`, with `errors` keyed by parameter. The filters and the\n * search are read as the list reads them.\n */\nexport function readAggregateQuery(\n params: URLSearchParams,\n aggregates: ListAggregatesLike,\n): ReadAggregateQueryResult {\n const errors: Record<string, string[]> = {};\n const rawMeasure = params.get('measure') ?? AGGREGATE_COUNT;\n const measure = parseAggregateMeasure(rawMeasure);\n if (measure === null) {\n errors.measure = ['The measure must be `count` or `sum:{field}`.'];\n } else if (measure.type === 'sum' && !(aggregates.sum ?? []).includes(measure.field)) {\n errors.measure = [`The field \\`${measure.field}\\` can't be summed.`];\n }\n\n const rawGroup = params.get('group');\n let group: AggregateGroup | null = null;\n if (rawGroup !== null) {\n group = parseAggregateGroup(rawGroup);\n if (group === null) {\n errors.group = ['The group must be `{day|week|month}:{date field}` or a field.'];\n } else if (group.type === 'period' && !(aggregates.dates ?? []).includes(group.field)) {\n errors.group = [`The field \\`${group.field}\\` isn't a date that can be grouped.`];\n } else if (group.type === 'field' && !(aggregates.groupBy ?? []).includes(group.field)) {\n errors.group = [`The items can't be grouped by the field \\`${group.field}\\`.`];\n }\n }\n\n if (Object.keys(errors).length > 0 || measure === null) {\n return { errors };\n }\n return { query: { measure, group } };\n}\n\nconst DAY = /^\\d{4}-\\d{2}-\\d{2}/;\n\n/** The day of a `date` or `datetime` value, as the backend writes it: `null` without one. */\nfunction dayOf(value: unknown): string | null {\n return typeof value === 'string' && DAY.test(value) ? value.slice(0, 10) : null;\n}\n\nfunction toUtc(day: string): Date {\n return new Date(`${day.slice(0, 10)}T00:00:00Z`);\n}\n\nfunction fromUtc(date: Date): string {\n return date.toISOString().slice(0, 10);\n}\n\n/**\n * The first day of the period of a day: the day itself, the Monday of its week (ISO 8601), or the\n * first day of its month. `2026-10-08` is in the week of `2026-10-05`.\n */\nexport function startOfPeriod(day: string, period: WidgetSeriesPeriod): string {\n const date = toUtc(day);\n if (period === 'week') {\n date.setUTCDate(date.getUTCDate() - ((date.getUTCDay() + 6) % 7));\n } else if (period === 'month') {\n date.setUTCDate(1);\n }\n return fromUtc(date);\n}\n\n/** The first day of the period after the one that starts on `start`. */\nexport function nextPeriod(start: string, period: WidgetSeriesPeriod): string {\n const date = toUtc(start);\n if (period === 'month') {\n date.setUTCMonth(date.getUTCMonth() + 1, 1);\n } else {\n date.setUTCDate(date.getUTCDate() + (period === 'week' ? 7 : 1));\n }\n return fromUtc(date);\n}\n\n/**\n * The first days of the periods from the one of `from` to the one of `to`, both included: at most\n * `max` of them, the latest. Empty when `to` is before `from`.\n */\nexport function listPeriods(\n from: string,\n to: string,\n period: WidgetSeriesPeriod,\n max: number = AGGREGATE_MAX_POINTS,\n): string[] {\n const last = startOfPeriod(to, period);\n const periods: string[] = [];\n for (\n let start = startOfPeriod(from, period);\n start <= last;\n start = nextPeriod(start, period)\n ) {\n periods.push(start);\n if (periods.length > max) {\n periods.shift();\n }\n }\n return periods;\n}\n\n/** The fields an aggregate reads, as the definition declares them. */\nexport interface AggregateField {\n name: string;\n type: string;\n options?: readonly { value: unknown; label: string; tone?: string | undefined }[] | undefined;\n}\n\nexport interface AggregateItemsOptions {\n /** The fields of the resource: the options of a `select` give the labels and the tones. */\n fields: readonly AggregateField[];\n /**\n * The bounds of the `date-range` filter of the query on the date of a period group, whose id is\n * the name of that field: the range of the series. Without a bound, the series starts on the\n * period of the first item, or ends on the period of the last.\n */\n range?: FilterRange | undefined;\n /** The label of the part of the items without a value. Defaults to `None`. */\n emptyLabel?: string;\n}\n\n/** The value of an item, as a key of a part: the id of a reference, `null` when it is empty. */\nfunction keysOf(value: unknown): { key: string | number | boolean | null; label?: string }[] {\n if (Array.isArray(value)) {\n const keys = value.flatMap((entry) => keysOf(entry).filter(({ key }) => key !== null));\n return keys.length > 0 ? keys : [{ key: null }];\n }\n if (typeof value === 'string') {\n return [{ key: value === '' ? null : value }];\n }\n if (typeof value === 'number' || typeof value === 'boolean') {\n return [{ key: value }];\n }\n // A reference to an item, of a `relation` (`{ \"id\", \"label\" }`)\n if (isRecord(value) && (typeof value.id === 'string' || typeof value.id === 'number')) {\n return [\n {\n key: value.id,\n ...(typeof value.label === 'string' && { label: value.label }),\n },\n ];\n }\n return [{ key: null }];\n}\n\n/** The amount of a value that is summed: a number, or the amount of a `money` value. */\nfunction amountOf(value: unknown): number {\n if (typeof value === 'number' && Number.isFinite(value)) {\n return value;\n }\n if (isRecord(value) && typeof value.amount === 'number' && Number.isFinite(value.amount)) {\n return value.amount;\n }\n return 0;\n}\n\n/**\n * Aggregates items that a list query already filtered: the reference of what\n * `GET /resources/{resource}/aggregate` answers (decision 0084).\n *\n * - Without a group: a `stat`, the count or the sum of the items.\n * - By a period: a `series`, one point per period from its range, 0 for the periods without items.\n * The range is the bounds of the `date-range` filter on the date (`range`), and without a bound,\n * the period of the first or the last item; at most `AGGREGATE_MAX_POINTS` periods, the latest.\n * Items without a date are left out. `total` is the sum of the points.\n * - By a field: a `breakdown`, a part per value, the largest first, at most\n * `WIDGET_BREAKDOWN_MAX_ITEMS`, the rest in `other`. An item with several values counts in each\n * of their parts, once in `total`; one without a value counts in the part of `key: null`. The\n * options of a `select` give their labels and tones, a reference its `label`.\n *\n * A sum of `money` values adds their amounts, in minor units.\n */\nexport function aggregateItems(\n items: readonly Record<string, unknown>[],\n query: AggregateQuery,\n options: AggregateItemsOptions,\n): StatWidgetData | SeriesWidgetData | BreakdownWidgetData {\n const { measure, group } = query;\n const measureOf = (item: Record<string, unknown>): number =>\n measure.type === 'count' ? 1 : amountOf(item[measure.field]);\n const total = items.reduce((sum, item) => sum + measureOf(item), 0);\n if (group === null) {\n return { value: total };\n }\n if (group.type === 'period') {\n const values = new Map<string, number>();\n const days: string[] = [];\n items.forEach((item) => {\n const day = dayOf(item[group.field]);\n if (day === null) {\n return;\n }\n days.push(day);\n const start = startOfPeriod(day, group.period);\n values.set(start, (values.get(start) ?? 0) + measureOf(item));\n });\n days.sort();\n const bound = (key: 'from' | 'to') => {\n const value = options.range?.[key];\n return value !== undefined && value !== '' ? dayOf(String(value)) : null;\n };\n const from = bound('from') ?? days[0] ?? bound('to');\n const to = bound('to') ?? days.at(-1) ?? bound('from');\n const points =\n from !== null && to !== null\n ? listPeriods(from, to, group.period).map((date) => ({\n date,\n value: values.get(date) ?? 0,\n }))\n : [];\n return {\n period: group.period,\n points,\n total: points.reduce((sum, point) => sum + point.value, 0),\n };\n }\n const field = options.fields.find((candidate) => candidate.name === group.field);\n const parts = new Map<\n string,\n { key: string | number | boolean | null; label: string; value: number }\n >();\n items.forEach((item) => {\n const amount = measureOf(item);\n const seen = new Set<string>();\n keysOf(item[group.field]).forEach(({ key, label }) => {\n const id = JSON.stringify(key);\n if (seen.has(id)) {\n return;\n }\n seen.add(id);\n const part = parts.get(id) ?? {\n key,\n label: key === null ? (options.emptyLabel ?? 'None') : (label ?? String(key)),\n value: 0,\n };\n part.value += amount;\n parts.set(id, part);\n });\n });\n const optionOf = (key: unknown) =>\n field?.type === 'select'\n ? field.options?.find((option) => String(option.value) === String(key))\n : undefined;\n const order = (key: unknown) => {\n const index = field?.options?.findIndex((option) => String(option.value) === String(key));\n return index === undefined || index === -1 ? Infinity : index;\n };\n // The largest first; equal parts in the order of the options, then of their labels\n const sorted = [...parts.values()].sort(\n (a, b) =>\n b.value - a.value || order(a.key) - order(b.key) || a.label.localeCompare(b.label),\n );\n const shown = sorted.slice(0, WIDGET_BREAKDOWN_MAX_ITEMS);\n const rest = sorted.slice(WIDGET_BREAKDOWN_MAX_ITEMS);\n return {\n items: shown.map(({ key, label, value }) => {\n const option = key !== null ? optionOf(key) : undefined;\n return {\n label: option?.label ?? label,\n value,\n key,\n ...(option?.tone !== undefined && { tone: option.tone }),\n };\n }),\n total,\n ...(rest.length > 0 && { other: rest.reduce((sum, part) => sum + part.value, 0) }),\n };\n}\n\n/** The bounds of the `date-range` filter on a field in a list query, if it has them. */\nexport function getFilterRange(\n query: Pick<ListQuery, 'filter'>,\n field: string,\n): FilterRange | undefined {\n const value = query.filter?.[field];\n return isFilterRange(value) ? value : undefined;\n}\n"],"mappings":";;;;;;;;AAaA,IAAa,uBAAuB;;AAGpC,IAAa,kBAAkB;;AA2C/B,SAAgB,sBAAsB,OAAwC;CAC1E,IAAI,UAAA,SACA,OAAO,EAAE,MAAM,QAAQ;CAE3B,MAAM,QAAQ,aAAa,KAAK,KAAK,CAAC,GAAG;CACzC,OAAO,UAA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AO,KAAK,QAAQ,KAAK,SAAS,MAAM,KAAK,OAAO,CAAC,EAAE;CACpF;AACJ;;AAGA,SAAgB,eACZ,OACA,OACuB;CACvB,MAAM,QAAQ,MAAM,SAAS;CAC7B,OAAO,cAAc,KAAK,IAAI,QAAQ,KAAA;AAC1C"}
@@ -0,0 +1,20 @@
1
+ import type { Field } from './schemas/field.js';
2
+ /**
3
+ * The shape of a value made of nested fields: an object of its `fields` (`group`), or a list of
4
+ * them (`repeater`).
5
+ */
6
+ export type NestedShape = 'group' | 'repeater';
7
+ /** Whether a field type is built in. */
8
+ export declare function isBuiltInFieldType(type: string): boolean;
9
+ /**
10
+ * Whether a field is a compound field (decision 0065): a type that isn't built in, provided by a
11
+ * plugin, that carries its sub-fields in `fields`.
12
+ */
13
+ export declare function isCompoundField(field: Pick<Field, 'type' | 'fields'>): boolean;
14
+ /**
15
+ * The shape of a field's value when it is made of nested fields: `group` and `repeater` fields,
16
+ * and compound fields, an object of their `fields`, or a list of them with `multiple`
17
+ * (decision 0065). Other fields return `null`.
18
+ */
19
+ export declare function getNestedShape(field: Pick<Field, 'type' | 'fields' | 'multiple'>): NestedShape | null;
20
+ //# sourceMappingURL=compound.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compound.d.ts","sourceRoot":"","sources":["../src/compound.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,UAAU,CAAC;AAE/C,wCAAwC;AACxC,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAExD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,GAAG,OAAO,CAE9E;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC1B,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,CAAC,GACnD,WAAW,GAAG,IAAI,CAQpB"}
@@ -0,0 +1,27 @@
1
+ import { BUILT_IN_FIELD_TYPES } from "./constants.js";
2
+ //#region src/compound.ts
3
+ /** Whether a field type is built in. */
4
+ function isBuiltInFieldType(type) {
5
+ return BUILT_IN_FIELD_TYPES.includes(type);
6
+ }
7
+ /**
8
+ * Whether a field is a compound field (decision 0065): a type that isn't built in, provided by a
9
+ * plugin, that carries its sub-fields in `fields`.
10
+ */
11
+ function isCompoundField(field) {
12
+ return field.fields !== void 0 && !isBuiltInFieldType(field.type);
13
+ }
14
+ /**
15
+ * The shape of a field's value when it is made of nested fields: `group` and `repeater` fields,
16
+ * and compound fields, an object of their `fields`, or a list of them with `multiple`
17
+ * (decision 0065). Other fields return `null`.
18
+ */
19
+ function getNestedShape(field) {
20
+ if (field.type === "group" || field.type === "repeater") return field.type;
21
+ if (isCompoundField(field)) return field.multiple === true ? "repeater" : "group";
22
+ return null;
23
+ }
24
+ //#endregion
25
+ export { getNestedShape, isBuiltInFieldType, isCompoundField };
26
+
27
+ //# sourceMappingURL=compound.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compound.js","names":[],"sources":["../src/compound.ts"],"sourcesContent":["// Fields made of other fields: `group`, `repeater`, and the compound fields of plugins\n// (decision 0065). This module doesn't import zod.\nimport { BUILT_IN_FIELD_TYPES } from './constants';\nimport type { Field } from './schemas/field';\n\n/**\n * The shape of a value made of nested fields: an object of its `fields` (`group`), or a list of\n * them (`repeater`).\n */\nexport type NestedShape = 'group' | 'repeater';\n\n/** Whether a field type is built in. */\nexport function isBuiltInFieldType(type: string): boolean {\n return (BUILT_IN_FIELD_TYPES as readonly string[]).includes(type);\n}\n\n/**\n * Whether a field is a compound field (decision 0065): a type that isn't built in, provided by a\n * plugin, that carries its sub-fields in `fields`.\n */\nexport function isCompoundField(field: Pick<Field, 'type' | 'fields'>): boolean {\n return field.fields !== undefined && !isBuiltInFieldType(field.type);\n}\n\n/**\n * The shape of a field's value when it is made of nested fields: `group` and `repeater` fields,\n * and compound fields, an object of their `fields`, or a list of them with `multiple`\n * (decision 0065). Other fields return `null`.\n */\nexport function getNestedShape(\n field: Pick<Field, 'type' | 'fields' | 'multiple'>,\n): NestedShape | null {\n if (field.type === 'group' || field.type === 'repeater') {\n return field.type;\n }\n if (isCompoundField(field)) {\n return field.multiple === true ? 'repeater' : 'group';\n }\n return null;\n}\n"],"mappings":";;;AAYA,SAAgB,mBAAmB,MAAuB;CACtD,OAAQ,qBAA2C,SAAS,IAAI;AACpE;;;;;AAMA,SAAgB,gBAAgB,OAAgD;CAC5E,OAAO,MAAM,WAAW,KAAA,KAAa,CAAC,mBAAmB,MAAM,IAAI;AACvE;;;;;;AAOA,SAAgB,eACZ,OACkB;CAClB,IAAI,MAAM,SAAS,WAAW,MAAM,SAAS,YACzC,OAAO,MAAM;CAEjB,IAAI,gBAAgB,KAAK,GACrB,OAAO,MAAM,aAAa,OAAO,aAAa;CAElD,OAAO;AACX"}
@@ -1,4 +1,4 @@
1
- import type { Condition } from './schemas/common';
1
+ import type { Condition } from './schemas/common.js';
2
2
  /**
3
3
  * Evaluates a `visibleWhen` condition against form values. An empty condition is true. Paths are
4
4
  * relative to `values`.
@@ -7,6 +7,12 @@ export interface ConformanceOptions {
7
7
  init?: RequestInit;
8
8
  /** Resource to test. Defaults to the first resource of the definition. */
9
9
  resource?: string;
10
+ /**
11
+ * Values of the context (decision 0045), sent in `Panneau-Context` with every request: for a
12
+ * backend whose resources need a value of a required param. The checks of the context use
13
+ * them too, and the first choice of each param without one.
14
+ */
15
+ context?: Record<string, string>;
10
16
  /**
11
17
  * Enables the checks that write data, on the tested resource. Use a test database: these
12
18
  * checks create, update and delete an item.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/conformance/index.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,kBAAkB;IAC/B,sFAAsF;IACtF,OAAO,E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