@panneau/protocol 5.0.0-alpha.4 → 5.0.0-alpha.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,95 @@
1
+ import { type WidgetPeriod } from './periods.js';
2
+ import { type ListQuery } from './query.js';
3
+ import type { DefinitionInput, OverviewPeriod, ResourceInput, Widget } from './schemas/index.js';
4
+ /** The page whose dashboard is the home page, and the `page` of a widget request without one. */
5
+ export declare const HOME_PAGE = "home";
6
+ /** The component of the built-in dashboard page. */
7
+ export declare const DASHBOARD_COMPONENT = "dashboard";
8
+ /** The parts of a definition that declare dashboards: its pages, and `dashboard`. */
9
+ type DashboardsOf = Pick<DefinitionInput, 'pages' | 'dashboard'>;
10
+ /**
11
+ * The widgets of the dashboard of a page, in order (decisions 0064 and 0084): the `widgets` of a
12
+ * page whose component is the built-in `dashboard`. The home page is the dashboard of `pages.home`,
13
+ * and `definition.dashboard` is its shorthand: its widgets are `pages.home.widgets` when set, else
14
+ * those of `definition.dashboard`. Empty for any other page.
15
+ */
16
+ export declare function getDashboardWidgets(definition: DashboardsOf, page?: string): Widget[];
17
+ /**
18
+ * The pages that have a dashboard of widgets, home first: `home` when its widgets are declared
19
+ * (`pages.home.widgets` or `definition.dashboard`), then each other page whose component is the
20
+ * built-in `dashboard`, in the order of `pages`.
21
+ */
22
+ export declare function getDashboardPages(definition: DashboardsOf): string[];
23
+ /**
24
+ * The period of the dashboard of a page (decision 0084): the `period` of a page whose component is
25
+ * the built-in `dashboard`. For the home page, `pages.home.period` when set, else that of
26
+ * `definition.dashboard`, its shorthand. `undefined` without one.
27
+ */
28
+ export declare function getDashboardPeriod(definition: DashboardsOf, page?: string): OverviewPeriod | undefined;
29
+ /**
30
+ * The id of the list's `date-range` filter that the period of the summary of a resource sets
31
+ * (decision 0084): its `period.filter`, or the first `date-range` filter of the list. `null`
32
+ * without a period, or without such a filter.
33
+ */
34
+ export declare function getSummaryPeriodFilter(resource: Pick<ResourceInput, 'summary' | 'list'>): string | null;
35
+ /** The parts of a definition that declare summaries: its resources. */
36
+ type SummariesOf = Pick<DefinitionInput, 'resources'>;
37
+ /**
38
+ * The widgets of the summary above the list of a resource, in order (decision 0084): its
39
+ * `summary.widgets`. Empty for a resource without a summary, or that doesn't exist.
40
+ */
41
+ export declare function getSummaryWidgets(definition: SummariesOf, resource: string): Widget[];
42
+ /** The ids of the resources that have a summary above their list, in the order of `resources`. */
43
+ export declare function getSummaryResources(definition: SummariesOf): string[];
44
+ /** The query of a list that a widget of its summary gets: its filters and its search. */
45
+ export type WidgetListQuery = Pick<ListQuery, 'filter' | 'q'>;
46
+ /**
47
+ * Where a widget with data of its own is asked for (decisions 0064 and 0084): on a dashboard page,
48
+ * or in the summary of a resource, with the query of its list.
49
+ */
50
+ export interface WidgetDataRequest {
51
+ /** The id of the dashboard page of the widget, in `pages`. Defaults to `home`. */
52
+ page?: string;
53
+ /** The resource whose summary holds the widget. With it, `page` is left out. */
54
+ resource?: string;
55
+ /** In a summary: the filters and the search of the list, when the widget follows it. */
56
+ query?: WidgetListQuery;
57
+ /** The period chosen in the overview, unless the widget has `settings.period: false`. */
58
+ period?: WidgetPeriod;
59
+ }
60
+ /**
61
+ * The query parameters of `GET /dashboard/widgets/{widget}`: `resource` and the filters and search
62
+ * of the list (`filter[…]`, `q`) for a widget of a summary, or `page` for a dashboard page other
63
+ * than home, and the period of the overview (`period[option]`, `period[from]`, `period[to]`). The
64
+ * widgets of the home page are asked for without `page`. The list's sort and paging are never
65
+ * sent: `page` is the dashboard page.
66
+ */
67
+ export declare function toWidgetDataParams(request?: WidgetDataRequest): URLSearchParams;
68
+ /** What `readWidgetDataQuery()` reads: where the widget is, or the errors of its parameters. */
69
+ export type ReadWidgetDataQueryResult = {
70
+ page: string;
71
+ resource?: undefined;
72
+ query?: undefined;
73
+ period: WidgetPeriod | null;
74
+ errors?: undefined;
75
+ } | {
76
+ resource: string;
77
+ query: WidgetListQuery;
78
+ page?: undefined;
79
+ period: WidgetPeriod | null;
80
+ errors?: undefined;
81
+ } | {
82
+ errors: Record<string, string[]>;
83
+ page?: undefined;
84
+ resource?: undefined;
85
+ };
86
+ /**
87
+ * Reads the query parameters of `GET /dashboard/widgets/{widget}` (decision 0084), as a backend
88
+ * does: a widget of the summary of `resource`, with the filters and the search of its list, or of
89
+ * the dashboard page `page`, `home` without it, and the period of the overview, or `null`. `page`
90
+ * and `resource` together, an empty one, or a wrong period are errors keyed by `page`, `resource`
91
+ * or `period`: a `422`.
92
+ */
93
+ export declare function readWidgetDataQuery(params: URLSearchParams): ReadWidgetDataQueryResult;
94
+ export {};
95
+ //# sourceMappingURL=dashboards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dashboards.d.ts","sourceRoot":"","sources":["../src/dashboards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAA2B,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,KAAK,SAAS,EAAoC,MAAM,SAAS,CAAC;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExF,iGAAiG;AACjG,eAAO,MAAM,SAAS,SAAS,CAAC;AAEhC,oDAAoD;AACpD,eAAO,MAAM,mBAAmB,cAAc,CAAC;AAE/C,qFAAqF;AACrF,KAAK,YAAY,GAAG,IAAI,CAAC,eAAe,EAAE,OAAO,GAAG,WAAW,CAAC,CAAC;AAEjE;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,YAAY,EAAE,IAAI,GAAE,MAAkB,GAAG,MAAM,EAAE,CAMhG;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,YAAY,GAAG,MAAM,EAAE,CAWpE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAC9B,UAAU,EAAE,YAAY,EACxB,IAAI,GAAE,MAAkB,GACzB,cAAc,GAAG,SAAS,CAM5B;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAClC,QAAQ,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,MAAM,CAAC,GAClD,MAAM,GAAG,IAAI,CAQf;AAED,uEAAuE;AACvE,KAAK,WAAW,GAAG,IAAI,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;AAEtD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAIrF;AAED,kGAAkG;AAClG,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,WAAW,GAAG,MAAM,EAAE,CAIrE;AAED,yFAAyF;AACzF,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,SAAS,EAAE,QAAQ,GAAG,GAAG,CAAC,CAAC;AAE9D;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAC9B,kFAAkF;IAClF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wFAAwF;IACxF,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,yFAAyF;IACzF,MAAM,CAAC,EAAE,YAAY,CAAC;CACzB;AAYD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,iBAAsB,GAAG,eAAe,CAWnF;AAED,gGAAgG;AAChG,MAAM,MAAM,yBAAyB,GAC/B;IACI,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,MAAM,CAAC,EAAE,SAAS,CAAC;CACtB,GACD;IACI,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,eAAe,CAAC;IACvB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,MAAM,CAAC,EAAE,SAAS,CAAC;CACtB,GACD;IAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAAC,IAAI,CAAC,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAsBnF;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,eAAe,GAAG,yBAAyB,CAyBtF"}
@@ -0,0 +1,140 @@
1
+ import { fromSearchParams, toSearchParams } from "./query.js";
2
+ import { isDay, isOverviewPeriod } from "./periods.js";
3
+ //#region src/dashboards.ts
4
+ /** The page whose dashboard is the home page, and the `page` of a widget request without one. */
5
+ var HOME_PAGE = "home";
6
+ /** The component of the built-in dashboard page. */
7
+ var DASHBOARD_COMPONENT = "dashboard";
8
+ /**
9
+ * The widgets of the dashboard of a page, in order (decisions 0064 and 0084): the `widgets` of a
10
+ * page whose component is the built-in `dashboard`. The home page is the dashboard of `pages.home`,
11
+ * and `definition.dashboard` is its shorthand: its widgets are `pages.home.widgets` when set, else
12
+ * those of `definition.dashboard`. Empty for any other page.
13
+ */
14
+ function getDashboardWidgets(definition, page = HOME_PAGE) {
15
+ const own = definition.pages?.[page];
16
+ if (own?.component === "dashboard" && own.widgets !== void 0) return own.widgets;
17
+ return page === "home" ? definition.dashboard?.widgets ?? [] : [];
18
+ }
19
+ /**
20
+ * The pages that have a dashboard of widgets, home first: `home` when its widgets are declared
21
+ * (`pages.home.widgets` or `definition.dashboard`), then each other page whose component is the
22
+ * built-in `dashboard`, in the order of `pages`.
23
+ */
24
+ function getDashboardPages(definition) {
25
+ const home = definition.pages?.[HOME_PAGE];
26
+ return [...definition.dashboard !== void 0 || home?.component === "dashboard" && home.widgets !== void 0 ? [HOME_PAGE] : [], ...Object.entries(definition.pages ?? {}).filter(([id, page]) => id !== "home" && page.component === "dashboard").map(([id]) => id)];
27
+ }
28
+ /**
29
+ * The period of the dashboard of a page (decision 0084): the `period` of a page whose component is
30
+ * the built-in `dashboard`. For the home page, `pages.home.period` when set, else that of
31
+ * `definition.dashboard`, its shorthand. `undefined` without one.
32
+ */
33
+ function getDashboardPeriod(definition, page = HOME_PAGE) {
34
+ const own = definition.pages?.[page];
35
+ if (own?.component === "dashboard" && own.period !== void 0) return own.period;
36
+ return page === "home" ? definition.dashboard?.period : void 0;
37
+ }
38
+ /**
39
+ * The id of the list's `date-range` filter that the period of the summary of a resource sets
40
+ * (decision 0084): its `period.filter`, or the first `date-range` filter of the list. `null`
41
+ * without a period, or without such a filter.
42
+ */
43
+ function getSummaryPeriodFilter(resource) {
44
+ const period = resource.summary?.period;
45
+ if (period === void 0) return null;
46
+ const filters = (resource.list?.filters ?? []).filter((filter) => filter.type === "date-range");
47
+ const id = period.filter ?? filters[0]?.id;
48
+ return filters.some((filter) => filter.id === id) ? id ?? null : null;
49
+ }
50
+ /**
51
+ * The widgets of the summary above the list of a resource, in order (decision 0084): its
52
+ * `summary.widgets`. Empty for a resource without a summary, or that doesn't exist.
53
+ */
54
+ function getSummaryWidgets(definition, resource) {
55
+ return definition.resources.find((candidate) => candidate.id === resource)?.summary?.widgets ?? [];
56
+ }
57
+ /** The ids of the resources that have a summary above their list, in the order of `resources`. */
58
+ function getSummaryResources(definition) {
59
+ return definition.resources.filter((resource) => resource.summary !== void 0).map((resource) => resource.id);
60
+ }
61
+ /** Writes the period of a widget: `period[option]`, `period[from]` and `period[to]`. */
62
+ function appendPeriod(params, period) {
63
+ if (period !== void 0) {
64
+ params.set("period[option]", period.option);
65
+ params.set("period[from]", period.from);
66
+ params.set("period[to]", period.to);
67
+ }
68
+ return params;
69
+ }
70
+ /**
71
+ * The query parameters of `GET /dashboard/widgets/{widget}`: `resource` and the filters and search
72
+ * of the list (`filter[…]`, `q`) for a widget of a summary, or `page` for a dashboard page other
73
+ * than home, and the period of the overview (`period[option]`, `period[from]`, `period[to]`). The
74
+ * widgets of the home page are asked for without `page`. The list's sort and paging are never
75
+ * sent: `page` is the dashboard page.
76
+ */
77
+ function toWidgetDataParams(request = {}) {
78
+ if (request.resource !== void 0) {
79
+ const params = new URLSearchParams({ resource: request.resource });
80
+ toSearchParams({
81
+ ...request.query?.filter !== void 0 && { filter: request.query.filter },
82
+ ...request.query?.q !== void 0 && { q: request.query.q }
83
+ }).forEach((value, key) => params.append(key, value));
84
+ return appendPeriod(params, request.period);
85
+ }
86
+ const page = request.page ?? "home";
87
+ return appendPeriod(new URLSearchParams(page !== "home" ? { page } : {}), request.period);
88
+ }
89
+ /**
90
+ * The period of a request, from `period[option]`, `period[from]` and `period[to]`: `null` without
91
+ * any, and an error when one is missing or wrong, or when `from` is after `to`.
92
+ */
93
+ function readPeriod(params) {
94
+ const option = params.get("period[option]");
95
+ const from = params.get("period[from]");
96
+ const to = params.get("period[to]");
97
+ if (option === null && from === null && to === null) return null;
98
+ if (!isOverviewPeriod(option)) return "The period must be one of 7d, 30d, 90d, month and year.";
99
+ if (!isDay(from) || !isDay(to) || from > to) return "The period needs its first and last days, from before to.";
100
+ return {
101
+ option,
102
+ from,
103
+ to
104
+ };
105
+ }
106
+ /**
107
+ * Reads the query parameters of `GET /dashboard/widgets/{widget}` (decision 0084), as a backend
108
+ * does: a widget of the summary of `resource`, with the filters and the search of its list, or of
109
+ * the dashboard page `page`, `home` without it, and the period of the overview, or `null`. `page`
110
+ * and `resource` together, an empty one, or a wrong period are errors keyed by `page`, `resource`
111
+ * or `period`: a `422`.
112
+ */
113
+ function readWidgetDataQuery(params) {
114
+ const page = params.get("page");
115
+ const resource = params.get("resource");
116
+ if (resource !== null && page !== null) return { errors: { page: ["A widget is on a page or in a summary, not both."] } };
117
+ if (resource === "") return { errors: { resource: ["The resource must not be empty."] } };
118
+ if (page === "") return { errors: { page: ["The page must not be empty."] } };
119
+ const period = readPeriod(params);
120
+ if (typeof period === "string") return { errors: { period: [period] } };
121
+ if (resource !== null) {
122
+ const { filter, q } = fromSearchParams(params);
123
+ return {
124
+ resource,
125
+ query: {
126
+ ...filter !== void 0 && { filter },
127
+ ...q !== void 0 && { q }
128
+ },
129
+ period
130
+ };
131
+ }
132
+ return {
133
+ page: page ?? "home",
134
+ period
135
+ };
136
+ }
137
+ //#endregion
138
+ export { DASHBOARD_COMPONENT, HOME_PAGE, getDashboardPages, getDashboardPeriod, getDashboardWidgets, getSummaryPeriodFilter, getSummaryResources, getSummaryWidgets, readWidgetDataQuery, toWidgetDataParams };
139
+
140
+ //# sourceMappingURL=dashboards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dashboards.js","names":[],"sources":["../src/dashboards.ts"],"sourcesContent":["import { type WidgetPeriod, isDay, isOverviewPeriod } from './periods';\nimport { type ListQuery, fromSearchParams, toSearchParams } from './query';\nimport type { DefinitionInput, OverviewPeriod, ResourceInput, Widget } from './schemas';\n\n/** The page whose dashboard is the home page, and the `page` of a widget request without one. */\nexport const HOME_PAGE = 'home';\n\n/** The component of the built-in dashboard page. */\nexport const DASHBOARD_COMPONENT = 'dashboard';\n\n/** The parts of a definition that declare dashboards: its pages, and `dashboard`. */\ntype DashboardsOf = Pick<DefinitionInput, 'pages' | 'dashboard'>;\n\n/**\n * The widgets of the dashboard of a page, in order (decisions 0064 and 0084): the `widgets` of a\n * page whose component is the built-in `dashboard`. The home page is the dashboard of `pages.home`,\n * and `definition.dashboard` is its shorthand: its widgets are `pages.home.widgets` when set, else\n * those of `definition.dashboard`. Empty for any other page.\n */\nexport function getDashboardWidgets(definition: DashboardsOf, page: string = HOME_PAGE): Widget[] {\n const own = definition.pages?.[page];\n if (own?.component === DASHBOARD_COMPONENT && own.widgets !== undefined) {\n return own.widgets;\n }\n return page === HOME_PAGE ? (definition.dashboard?.widgets ?? []) : [];\n}\n\n/**\n * The pages that have a dashboard of widgets, home first: `home` when its widgets are declared\n * (`pages.home.widgets` or `definition.dashboard`), then each other page whose component is the\n * built-in `dashboard`, in the order of `pages`.\n */\nexport function getDashboardPages(definition: DashboardsOf): string[] {\n const home = definition.pages?.[HOME_PAGE];\n const hasHome =\n definition.dashboard !== undefined ||\n (home?.component === DASHBOARD_COMPONENT && home.widgets !== undefined);\n return [\n ...(hasHome ? [HOME_PAGE] : []),\n ...Object.entries(definition.pages ?? {})\n .filter(([id, page]) => id !== HOME_PAGE && page.component === DASHBOARD_COMPONENT)\n .map(([id]) => id),\n ];\n}\n\n/**\n * The period of the dashboard of a page (decision 0084): the `period` of a page whose component is\n * the built-in `dashboard`. For the home page, `pages.home.period` when set, else that of\n * `definition.dashboard`, its shorthand. `undefined` without one.\n */\nexport function getDashboardPeriod(\n definition: DashboardsOf,\n page: string = HOME_PAGE,\n): OverviewPeriod | undefined {\n const own = definition.pages?.[page];\n if (own?.component === DASHBOARD_COMPONENT && own.period !== undefined) {\n return own.period;\n }\n return page === HOME_PAGE ? definition.dashboard?.period : undefined;\n}\n\n/**\n * The id of the list's `date-range` filter that the period of the summary of a resource sets\n * (decision 0084): its `period.filter`, or the first `date-range` filter of the list. `null`\n * without a period, or without such a filter.\n */\nexport function getSummaryPeriodFilter(\n resource: Pick<ResourceInput, 'summary' | 'list'>,\n): string | null {\n const period = resource.summary?.period;\n if (period === undefined) {\n return null;\n }\n const filters = (resource.list?.filters ?? []).filter((filter) => filter.type === 'date-range');\n const id = period.filter ?? filters[0]?.id;\n return filters.some((filter) => filter.id === id) ? (id ?? null) : null;\n}\n\n/** The parts of a definition that declare summaries: its resources. */\ntype SummariesOf = Pick<DefinitionInput, 'resources'>;\n\n/**\n * The widgets of the summary above the list of a resource, in order (decision 0084): its\n * `summary.widgets`. Empty for a resource without a summary, or that doesn't exist.\n */\nexport function getSummaryWidgets(definition: SummariesOf, resource: string): Widget[] {\n return (\n definition.resources.find((candidate) => candidate.id === resource)?.summary?.widgets ?? []\n );\n}\n\n/** The ids of the resources that have a summary above their list, in the order of `resources`. */\nexport function getSummaryResources(definition: SummariesOf): string[] {\n return definition.resources\n .filter((resource) => resource.summary !== undefined)\n .map((resource) => resource.id);\n}\n\n/** The query of a list that a widget of its summary gets: its filters and its search. */\nexport type WidgetListQuery = Pick<ListQuery, 'filter' | 'q'>;\n\n/**\n * Where a widget with data of its own is asked for (decisions 0064 and 0084): on a dashboard page,\n * or in the summary of a resource, with the query of its list.\n */\nexport interface WidgetDataRequest {\n /** The id of the dashboard page of the widget, in `pages`. Defaults to `home`. */\n page?: string;\n /** The resource whose summary holds the widget. With it, `page` is left out. */\n resource?: string;\n /** In a summary: the filters and the search of the list, when the widget follows it. */\n query?: WidgetListQuery;\n /** The period chosen in the overview, unless the widget has `settings.period: false`. */\n period?: WidgetPeriod;\n}\n\n/** Writes the period of a widget: `period[option]`, `period[from]` and `period[to]`. */\nfunction appendPeriod(params: URLSearchParams, period: WidgetPeriod | undefined): URLSearchParams {\n if (period !== undefined) {\n params.set('period[option]', period.option);\n params.set('period[from]', period.from);\n params.set('period[to]', period.to);\n }\n return params;\n}\n\n/**\n * The query parameters of `GET /dashboard/widgets/{widget}`: `resource` and the filters and search\n * of the list (`filter[…]`, `q`) for a widget of a summary, or `page` for a dashboard page other\n * than home, and the period of the overview (`period[option]`, `period[from]`, `period[to]`). The\n * widgets of the home page are asked for without `page`. The list's sort and paging are never\n * sent: `page` is the dashboard page.\n */\nexport function toWidgetDataParams(request: WidgetDataRequest = {}): URLSearchParams {\n if (request.resource !== undefined) {\n const params = new URLSearchParams({ resource: request.resource });\n toSearchParams({\n ...(request.query?.filter !== undefined && { filter: request.query.filter }),\n ...(request.query?.q !== undefined && { q: request.query.q }),\n }).forEach((value, key) => params.append(key, value));\n return appendPeriod(params, request.period);\n }\n const page = request.page ?? HOME_PAGE;\n return appendPeriod(new URLSearchParams(page !== HOME_PAGE ? { page } : {}), request.period);\n}\n\n/** What `readWidgetDataQuery()` reads: where the widget is, or the errors of its parameters. */\nexport type ReadWidgetDataQueryResult =\n | {\n page: string;\n resource?: undefined;\n query?: undefined;\n period: WidgetPeriod | null;\n errors?: undefined;\n }\n | {\n resource: string;\n query: WidgetListQuery;\n page?: undefined;\n period: WidgetPeriod | null;\n errors?: undefined;\n }\n | { errors: Record<string, string[]>; page?: undefined; resource?: undefined };\n\n/**\n * The period of a request, from `period[option]`, `period[from]` and `period[to]`: `null` without\n * any, and an error when one is missing or wrong, or when `from` is after `to`.\n */\nfunction readPeriod(params: URLSearchParams): WidgetPeriod | null | string {\n const option = params.get('period[option]');\n const from = params.get('period[from]');\n const to = params.get('period[to]');\n if (option === null && from === null && to === null) {\n return null;\n }\n if (!isOverviewPeriod(option)) {\n return 'The period must be one of 7d, 30d, 90d, month and year.';\n }\n if (!isDay(from) || !isDay(to) || from > to) {\n return 'The period needs its first and last days, from before to.';\n }\n return { option, from, to };\n}\n\n/**\n * Reads the query parameters of `GET /dashboard/widgets/{widget}` (decision 0084), as a backend\n * does: a widget of the summary of `resource`, with the filters and the search of its list, or of\n * the dashboard page `page`, `home` without it, and the period of the overview, or `null`. `page`\n * and `resource` together, an empty one, or a wrong period are errors keyed by `page`, `resource`\n * or `period`: a `422`.\n */\nexport function readWidgetDataQuery(params: URLSearchParams): ReadWidgetDataQueryResult {\n const page = params.get('page');\n const resource = params.get('resource');\n if (resource !== null && page !== null) {\n return { errors: { page: ['A widget is on a page or in a summary, not both.'] } };\n }\n if (resource === '') {\n return { errors: { resource: ['The resource must not be empty.'] } };\n }\n if (page === '') {\n return { errors: { page: ['The page must not be empty.'] } };\n }\n const period = readPeriod(params);\n if (typeof period === 'string') {\n return { errors: { period: [period] } };\n }\n if (resource !== null) {\n const { filter, q } = fromSearchParams(params);\n return {\n resource,\n query: { ...(filter !== undefined && { filter }), ...(q !== undefined && { q }) },\n period,\n };\n }\n return { page: page ?? HOME_PAGE, period };\n}\n"],"mappings":";;;;AAKA,IAAa,YAAY;;AAGzB,IAAa,sBAAsB;;;;;;;AAWnC,SAAgB,oBAAoB,YAA0B,OAAe,WAAqB;CAC9F,MAAM,MAAM,WAAW,QAAQ;CAC/B,IAAI,KAAK,cAAA,eAAqC,IAAI,YAAY,KAAA,GAC1D,OAAO,IAAI;CAEf,OAAO,SAAA,SAAsB,WAAW,WAAW,WAAW,CAAC,IAAK,CAAC;AACzE;;;;;;AAOA,SAAgB,kBAAkB,YAAoC;CAClE,MAAM,OAAO,WAAW,QAAQ;CAIhC,OAAO,CACH,GAHA,WAAW,cAAc,KAAA,KACxB,MAAM,cAAA,eAAqC,KAAK,YAAY,KAAA,IAE/C,CAAC,SAAS,IAAI,CAAC,GAC7B,GAAG,OAAO,QAAQ,WAAW,SAAS,CAAC,CAAC,CAAC,CACpC,QAAQ,CAAC,IAAI,UAAU,OAAA,UAAoB,KAAK,cAAA,WAAiC,CAAC,CAClF,KAAK,CAAC,QAAQ,EAAE,CACzB;AACJ;;;;;;AAOA,SAAgB,mBACZ,YACA,OAAe,WACW;CAC1B,MAAM,MAAM,WAAW,QAAQ;CAC/B,IAAI,KAAK,cAAA,eAAqC,IAAI,WAAW,KAAA,GACzD,OAAO,IAAI;CAEf,OAAO,SAAA,SAAqB,WAAW,WAAW,SAAS,KAAA;AAC/D;;;;;;AAOA,SAAgB,uBACZ,UACa;CACb,MAAM,SAAS,SAAS,SAAS;CACjC,IAAI,WAAW,KAAA,GACX,OAAO;CAEX,MAAM,WAAW,SAAS,MAAM,WAAW,CAAC,EAAA,CAAG,QAAQ,WAAW,OAAO,SAAS,YAAY;CAC9F,MAAM,KAAK,OAAO,UAAU,QAAQ,EAAE,EAAE;CACxC,OAAO,QAAQ,MAAM,WAAW,OAAO,OAAO,EAAE,IAAK,MAAM,OAAQ;AACvE;;;;;AASA,SAAgB,kBAAkB,YAAyB,UAA4B;CACnF,OACI,WAAW,UAAU,MAAM,cAAc,UAAU,OAAO,QAAQ,CAAC,EAAE,SAAS,WAAW,CAAC;AAElG;;AAGA,SAAgB,oBAAoB,YAAmC;CACnE,OAAO,WAAW,UACb,QAAQ,aAAa,SAAS,YAAY,KAAA,CAAS,CAAC,CACpD,KAAK,aAAa,SAAS,EAAE;AACtC;;AAqBA,SAAS,aAAa,QAAyB,QAAmD;CAC9F,IAAI,WAAW,KAAA,GAAW;EACtB,OAAO,IAAI,kBAAkB,OAAO,MAAM;EAC1C,OAAO,IAAI,gBAAgB,OAAO,IAAI;EACtC,OAAO,IAAI,cAAc,OAAO,EAAE;CACtC;CACA,OAAO;AACX;;;;;;;;AASA,SAAgB,mBAAmB,UAA6B,CAAC,GAAoB;CACjF,IAAI,QAAQ,aAAa,KAAA,GAAW;EAChC,MAAM,SAAS,IAAI,gBAAgB,EAAE,UAAU,QAAQ,SAAS,CAAC;EACjE,eAAe;GACX,GAAI,QAAQ,OAAO,WAAW,KAAA,KAAa,EAAE,QAAQ,QAAQ,MAAM,OAAO;GAC1E,GAAI,QAAQ,OAAO,MAAM,KAAA,KAAa,EAAE,GAAG,QAAQ,MAAM,EAAE;EAC/D,CAAC,CAAC,CAAC,SAAS,OAAO,QAAQ,OAAO,OAAO,KAAK,KAAK,CAAC;EACpD,OAAO,aAAa,QAAQ,QAAQ,MAAM;CAC9C;CACA,MAAM,OAAO,QAAQ,QAAA;CACrB,OAAO,aAAa,IAAI,gBAAgB,SAAA,SAAqB,EAAE,KAAK,IAAI,CAAC,CAAC,GAAG,QAAQ,MAAM;AAC/F;;;;;AAwBA,SAAS,WAAW,QAAuD;CACvE,MAAM,SAAS,OAAO,IAAI,gBAAgB;CAC1C,MAAM,OAAO,OAAO,IAAI,cAAc;CACtC,MAAM,KAAK,OAAO,IAAI,YAAY;CAClC,IAAI,WAAW,QAAQ,SAAS,QAAQ,OAAO,MAC3C,OAAO;CAEX,IAAI,CAAC,iBAAiB,MAAM,GACxB,OAAO;CAEX,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE,KAAK,OAAO,IACrC,OAAO;CAEX,OAAO;EAAE;EAAQ;EAAM;CAAG;AAC9B;;;;;;;;AASA,SAAgB,oBAAoB,QAAoD;CACpF,MAAM,OAAO,OAAO,IAAI,MAAM;CAC9B,MAAM,WAAW,OAAO,IAAI,UAAU;CACtC,IAAI,aAAa,QAAQ,SAAS,MAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,kDAAkD,EAAE,EAAE;CAEpF,IAAI,aAAa,IACb,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,iCAAiC,EAAE,EAAE;CAEvE,IAAI,SAAS,IACT,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,6BAA6B,EAAE,EAAE;CAE/D,MAAM,SAAS,WAAW,MAAM;CAChC,IAAI,OAAO,WAAW,UAClB,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,EAAE;CAE1C,IAAI,aAAa,MAAM;EACnB,MAAM,EAAE,QAAQ,MAAM,iBAAiB,MAAM;EAC7C,OAAO;GACH;GACA,OAAO;IAAE,GAAI,WAAW,KAAA,KAAa,EAAE,OAAO;IAAI,GAAI,MAAM,KAAA,KAAa,EAAE,EAAE;GAAG;GAChF;EACJ;CACJ;CACA,OAAO;EAAE,MAAM,QAAA;EAAmB;CAAO;AAC7C"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from './runtime';
2
- export * from './schemas';
3
- export { type ValidationIssue, type ValidationResult, validate, validateBootConfig, validateDefinition, } from './validate';
4
- export { createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createThemeJsonSchema, } from './openapi';
1
+ export * from './runtime/index.js';
2
+ export * from './schemas/index.js';
3
+ export { type ValidationIssue, type ValidationResult, validate, validateBootConfig, validateDefinition, } from './validate.js';
4
+ export { createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createThemeJsonSchema, } from './openapi.js';
5
5
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,23 +1,37 @@
1
1
  import { PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION } from "./version.js";
2
- import { BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LIST_LAYOUTS, PORTABLE_RULES } from "./constants.js";
2
+ import { ADDRESS_PARTS, AUTH_ERROR_CODES, AUTH_ERROR_PARAM, AUTH_PAGE_PATHS, BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_ITEM_ACTIONS, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LINK_ACTIONS, BUILT_IN_LINK_TYPES, BUILT_IN_LIST_LAYOUTS, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, DATE_RANGE_OPEN_BOUNDS, DEFAULT_ADDRESS_REQUIRED_PARTS, DURATION_UNITS, EMAIL_UNVERIFIED_PROBLEM_TYPE, IDS_FILTER, IDS_FILTER_LIMIT, ITEM_ACTION_ABILITIES, PASSWORD_CONFIRMATION_PROBLEM_TYPE, PORTABLE_RULES, RESERVED_ROUTE_SEGMENTS, RICH_TEXT_STYLE_ELEMENTS, TWO_FACTOR_REQUIRED_PROBLEM_TYPE, UNDO_LIMIT, isBuiltInItemAction, isBuiltInLink } from "./constants.js";
3
+ import { CURRENCY_CODES, fromMinorUnits, getCurrencyDigits, isCurrencyCode, toMinorUnits } from "./currencies.js";
4
+ import { POSTAL_CODE_COUNTRIES, getAddressRequiredParts, isAddressPart, isPostalCode, normalizePostalCode } from "./addresses.js";
5
+ import { getNestedShape, isBuiltInFieldType, isCompoundField } from "./compound.js";
3
6
  import { getValue, isFilled } from "./values.js";
4
7
  import { evaluateCondition } from "./conditions.js";
8
+ import { getLinkNewTab, getLinkTypes, isBuiltInLinkType, isExternalUrl, resolveLinkNewTab } from "./links.js";
9
+ import { matchesRatio, parseRatio, renderedCropSize } from "./transforms.js";
5
10
  import { checkRules, checkValues } from "./rules.js";
11
+ import { getImageUrl, getItemImageField, getMediaLibraries } from "./libraries.js";
12
+ import { ITEM_TYPE_KEY, getCreatableTypes, getItemType, getResourceType, getTypeFields, hasResourceTypes } from "./resourceTypes.js";
13
+ import { fromSearchParams, isCursorPage, isFilterRange, matchesFilterRange, toSearchParams } from "./query.js";
14
+ import { BUILT_IN_WIDGET_TYPES, GROUPED_WIDGET_TYPES, RESOURCE_WIDGET_TYPES, WIDGET_BREAKDOWN_MAX_ITEMS, WIDGET_FORMAT_CURRENCY_DISPLAYS, WIDGET_FORMAT_NOTATIONS, WIDGET_FORMAT_SIGN_DISPLAYS, WIDGET_FORMAT_STYLES, WIDGET_FORMAT_UNITS, WIDGET_FORMAT_UNIT_DISPLAYS, WIDGET_GOOD_WHEN, WIDGET_LIST_MAX_ITEMS, WIDGET_METRIC_MAX_PARTS, WIDGET_RESERVED_QUERY_PARAMS, WIDGET_SERIES_MAX_SERIES, WIDGET_SERIES_PERIODS, WIDGET_SOURCES_MAX, WIDGET_TABLE_ALIGNS, WIDGET_TABLE_MAX_COLUMNS, WIDGET_TABLE_MAX_ROWS, checkWidgetData, followsList, followsPeriod, getChangeTone, getWidgetAggregates, getWidgetChange, getWidgetResource, getWidgetSources, isBuiltInWidgetType, isCombinedWidget, isWidgetDataEmpty, isWidgetUnit, readWidgetFormat, readsResources } from "./widgets.js";
15
+ import { AGGREGATE_COUNT, AGGREGATE_MAX_POINTS, aggregateItems, getAggregateWidgetType, getFilterRange, listPeriods, nextPeriod, parseAggregateGroup, parseAggregateMeasure, readAggregateQuery, startOfPeriod, toAggregateParams } from "./aggregates.js";
16
+ import { OVERVIEW_PERIODS, PERIOD_PARAM, findPeriodOption, getDefaultPeriod, getPeriodRange, getPreviousRange, isDay, isOverviewPeriod, localDay, readPeriodOption } from "./periods.js";
17
+ import { DASHBOARD_COMPONENT, HOME_PAGE, getDashboardPages, getDashboardPeriod, getDashboardWidgets, getSummaryPeriodFilter, getSummaryResources, getSummaryWidgets, readWidgetDataQuery, toWidgetDataParams } from "./dashboards.js";
6
18
  import { lintDefinition } from "./lint.js";
7
- import { fromSearchParams, isFilterRange, matchesFilterRange, toSearchParams } from "./query.js";
19
+ import { SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, isSearchableResource, readSearchQuery, toSearchQueryParams } from "./search.js";
20
+ import { contextBefore, formatContextHeader, parseContextHeader } from "./context.js";
8
21
  import { isProblem } from "./problem.js";
9
22
  import { mergeThemes } from "./themes.js";
10
23
  import { Abilities, Condition, Id, Option, RouteReference } from "./schemas/common.js";
11
- import { BlockType, Field, Rule } from "./schemas/field.js";
24
+ import { AddressSettings, BlockType, DateRangeSettings, DurationSettings, Field, LinkSettings, LinkTypeSetting, MoneySettings, RichTextSettings, RichTextStyle, Rule } from "./schemas/field.js";
12
25
  import { LayoutNode } from "./schemas/layout.js";
13
26
  import { Action, ActionConfirm, ActionPlacement, ActionScope } from "./schemas/action.js";
14
- import { Column, Filter, ListDefinition } from "./schemas/list.js";
15
- import { Resource, ResourceFeatures } from "./schemas/resource.js";
27
+ import { Column, Filter, ListAggregates, ListCalendar, ListDefinition } from "./schemas/list.js";
28
+ import { BreakdownWidgetData, BreakdownWidgetItem, ListWidgetData, ListWidgetItem, MetricWidgetData, OverviewPeriod, SeriesPoint, SeriesWidgetData, SeriesWidgetSeries, StatWidgetData, TableWidgetCell, TableWidgetColumn, TableWidgetData, TableWidgetRow, Widget, WidgetAlert, WidgetAlertSettings, WidgetBadge, WidgetNumberFormat, WidgetRowSource, WidgetSeriesSource, WidgetSettings, widgetDataSchemas } from "./schemas/widget.js";
29
+ import { Resource, ResourceFeatures, ResourceSummary, ResourceType, SummaryPeriod } from "./schemas/resource.js";
16
30
  import { DefinitionTheme, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues } from "./schemas/theme.js";
17
- import { Auth, AuthProvider, Definition, MenuItem, Page, Uploads, User, Widget } from "./schemas/definition.js";
18
- import { ActionItemResult, ActionRequest, ActionResult, ActionRun, ActionRunResponse, Item, ItemResponse, ListResponse, MediaInfo, MediaItem, MediaReference, MediaTransform, Pagination, PreviewResponse, Problem, SearchResponse, Selection, Session, StoredFile, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse } from "./schemas/api.js";
31
+ import { Auth, AuthProvider, AuthToken, ContextOption, ContextParam, Definition, DefinitionContext, InterfaceLocale, MenuItem, Page, Uploads, User } from "./schemas/definition.js";
32
+ import { ActionItemResult, ActionRequest, ActionResult, ActionRun, ActionRunResponse, AddressValue, ContextOptionsResponse, CursorPagination, DateRangeValue, EmbedResponse, EmbedValue, FieldCheckRequest, FieldCheckResponse, Item, ItemResponse, LinkValue, ListResponse, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, MoneyValue, Pagination, Passkey, PreviewResponse, Problem, RecoveryCodes, SearchResponse, Selection, Session, StoredFile, TwoFactorChallenge, TwoFactorSetup, TwoFactorStatus, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse, WebAuthnOptions } from "./schemas/api.js";
19
33
  import { BootConfig } from "./schemas/boot.js";
20
34
  import { createSchemaRegistry, namedSchemas } from "./schemas/index.js";
21
35
  import { validate, validateBootConfig, validateDefinition } from "./validate.js";
22
36
  import { createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createThemeJsonSchema } from "./openapi.js";
23
- export { Abilities, Action, ActionConfirm, ActionItemResult, ActionPlacement, ActionRequest, ActionResult, ActionRun, ActionRunResponse, ActionScope, Auth, AuthProvider, BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LIST_LAYOUTS, BlockType, BootConfig, Column, Condition, Definition, DefinitionTheme, Field, Filter, Id, Item, ItemResponse, LayoutNode, ListDefinition, ListResponse, MediaInfo, MediaItem, MediaReference, MediaTransform, MenuItem, Option, PORTABLE_RULES, PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION, Page, Pagination, PreviewResponse, Problem, Resource, ResourceFeatures, RouteReference, Rule, SearchResponse, Selection, Session, StoredFile, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse, Uploads, User, Widget, checkRules, checkValues, createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createSchemaRegistry, createThemeJsonSchema, evaluateCondition, fromSearchParams, getValue, isFilled, isFilterRange, isProblem, lintDefinition, matchesFilterRange, mergeThemes, namedSchemas, toSearchParams, validate, validateBootConfig, validateDefinition };
37
+ export { ADDRESS_PARTS, AGGREGATE_COUNT, AGGREGATE_MAX_POINTS, AUTH_ERROR_CODES, AUTH_ERROR_PARAM, AUTH_PAGE_PATHS, Abilities, Action, ActionConfirm, ActionItemResult, ActionPlacement, ActionRequest, ActionResult, ActionRun, ActionRunResponse, ActionScope, AddressSettings, AddressValue, Auth, AuthProvider, AuthToken, BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_ITEM_ACTIONS, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LINK_ACTIONS, BUILT_IN_LINK_TYPES, BUILT_IN_LIST_LAYOUTS, BUILT_IN_WIDGET_TYPES, BlockType, BootConfig, BreakdownWidgetData, BreakdownWidgetItem, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, CURRENCY_CODES, Column, Condition, ContextOption, ContextOptionsResponse, ContextParam, CursorPagination, DASHBOARD_COMPONENT, DATE_RANGE_OPEN_BOUNDS, DEFAULT_ADDRESS_REQUIRED_PARTS, DURATION_UNITS, DateRangeSettings, DateRangeValue, Definition, DefinitionContext, DefinitionTheme, DurationSettings, EMAIL_UNVERIFIED_PROBLEM_TYPE, EmbedResponse, EmbedValue, Field, FieldCheckRequest, FieldCheckResponse, Filter, GROUPED_WIDGET_TYPES, HOME_PAGE, IDS_FILTER, IDS_FILTER_LIMIT, ITEM_ACTION_ABILITIES, ITEM_TYPE_KEY, Id, InterfaceLocale, Item, ItemResponse, LayoutNode, LinkSettings, LinkTypeSetting, LinkValue, ListAggregates, ListCalendar, ListDefinition, ListResponse, ListWidgetData, ListWidgetItem, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, MenuItem, MetricWidgetData, MoneySettings, MoneyValue, OVERVIEW_PERIODS, Option, OverviewPeriod, PASSWORD_CONFIRMATION_PROBLEM_TYPE, PERIOD_PARAM, PORTABLE_RULES, POSTAL_CODE_COUNTRIES, PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION, Page, Pagination, Passkey, PreviewResponse, Problem, RESERVED_ROUTE_SEGMENTS, RESOURCE_WIDGET_TYPES, RICH_TEXT_STYLE_ELEMENTS, RecoveryCodes, Resource, ResourceFeatures, ResourceSummary, ResourceType, RichTextSettings, RichTextStyle, RouteReference, Rule, SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, SearchResponse, Selection, SeriesPoint, SeriesWidgetData, SeriesWidgetSeries, Session, StatWidgetData, StoredFile, SummaryPeriod, TWO_FACTOR_REQUIRED_PROBLEM_TYPE, TableWidgetCell, TableWidgetColumn, TableWidgetData, TableWidgetRow, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues, TwoFactorChallenge, TwoFactorSetup, TwoFactorStatus, UNDO_LIMIT, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse, Uploads, User, WIDGET_BREAKDOWN_MAX_ITEMS, WIDGET_FORMAT_CURRENCY_DISPLAYS, WIDGET_FORMAT_NOTATIONS, WIDGET_FORMAT_SIGN_DISPLAYS, WIDGET_FORMAT_STYLES, WIDGET_FORMAT_UNITS, WIDGET_FORMAT_UNIT_DISPLAYS, WIDGET_GOOD_WHEN, WIDGET_LIST_MAX_ITEMS, WIDGET_METRIC_MAX_PARTS, WIDGET_RESERVED_QUERY_PARAMS, WIDGET_SERIES_MAX_SERIES, WIDGET_SERIES_PERIODS, WIDGET_SOURCES_MAX, WIDGET_TABLE_ALIGNS, WIDGET_TABLE_MAX_COLUMNS, WIDGET_TABLE_MAX_ROWS, WebAuthnOptions, Widget, WidgetAlert, WidgetAlertSettings, WidgetBadge, WidgetNumberFormat, WidgetRowSource, WidgetSeriesSource, WidgetSettings, aggregateItems, checkRules, checkValues, checkWidgetData, contextBefore, createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createSchemaRegistry, createThemeJsonSchema, evaluateCondition, findPeriodOption, followsList, followsPeriod, formatContextHeader, fromMinorUnits, fromSearchParams, getAddressRequiredParts, getAggregateWidgetType, getChangeTone, getCreatableTypes, getCurrencyDigits, getDashboardPages, getDashboardPeriod, getDashboardWidgets, getDefaultPeriod, getFilterRange, getImageUrl, getItemImageField, getItemType, getLinkNewTab, getLinkTypes, getMediaLibraries, getNestedShape, getPeriodRange, getPreviousRange, getResourceType, getSummaryPeriodFilter, getSummaryResources, getSummaryWidgets, getTypeFields, getValue, getWidgetAggregates, getWidgetChange, getWidgetResource, getWidgetSources, hasResourceTypes, isAddressPart, isBuiltInFieldType, isBuiltInItemAction, isBuiltInLink, isBuiltInLinkType, isBuiltInWidgetType, isCombinedWidget, isCompoundField, isCurrencyCode, isCursorPage, isDay, isExternalUrl, isFilled, isFilterRange, isOverviewPeriod, isPostalCode, isProblem, isSearchableResource, isWidgetDataEmpty, isWidgetUnit, lintDefinition, listPeriods, localDay, matchesFilterRange, matchesRatio, mergeThemes, namedSchemas, nextPeriod, normalizePostalCode, parseAggregateGroup, parseAggregateMeasure, parseContextHeader, parseRatio, readAggregateQuery, readPeriodOption, readSearchQuery, readWidgetDataQuery, readWidgetFormat, readsResources, renderedCropSize, resolveLinkNewTab, startOfPeriod, toAggregateParams, toMinorUnits, toSearchParams, toSearchQueryParams, toWidgetDataParams, validate, validateBootConfig, validateDefinition, widgetDataSchemas };
@@ -0,0 +1,33 @@
1
+ /** What `getMediaLibraries()` reads of a definition. */
2
+ export interface MediaLibrariesDefinition {
3
+ resources: readonly {
4
+ id: string;
5
+ kind?: string | undefined;
6
+ }[];
7
+ }
8
+ /**
9
+ * The ids of the libraries a `media` field allows (decision 0027), in the order of its `resource`:
10
+ * the one it names, the ones it lists, or every resource of kind `media` of the definition when it
11
+ * names none. Ids that aren't libraries are left out: `lintDefinition()` reports them.
12
+ */
13
+ export declare function getMediaLibraries(definition: MediaLibrariesDefinition | null, field: {
14
+ resource?: string | readonly string[] | undefined;
15
+ }): string[];
16
+ /** What `getItemImageField()` reads of a resource. */
17
+ export interface ItemImageResource {
18
+ kind?: string | undefined;
19
+ itemImage?: string | undefined;
20
+ }
21
+ /**
22
+ * The key of an item that holds its image (decision 0061): the resource's `itemImage`, or `media`
23
+ * in a media library, whose items all have one. `undefined` for a resource without an image.
24
+ */
25
+ export declare function getItemImageField(resource: ItemImageResource): string | undefined;
26
+ /**
27
+ * The URL of an image value, such as the `itemImage` of an item (decision 0061): a media reference
28
+ * or a media (its thumbnail, or the URL of an image), a stored file (the URL of an image that
29
+ * browsers show), or a URL, and the first of a list. `null` for anything else, such as a PDF
30
+ * without a thumbnail.
31
+ */
32
+ export declare function getImageUrl(value: unknown): string | null;
33
+ //# sourceMappingURL=libraries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libraries.d.ts","sourceRoot":"","sources":["../src/libraries.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,MAAM,WAAW,wBAAwB;IACrC,SAAS,EAAE,SAAS;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,EAAE,CAAC;CACnE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC7B,UAAU,EAAE,wBAAwB,GAAG,IAAI,EAC3C,KAAK,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,CAAA;CAAE,GAC7D,MAAM,EAAE,CAUV;AAED,sDAAsD;AACtD,MAAM,WAAW,iBAAiB;IAC9B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAEjF;AAgCD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAWzD"}
@@ -0,0 +1,59 @@
1
+ //#region src/libraries.ts
2
+ /**
3
+ * The ids of the libraries a `media` field allows (decision 0027), in the order of its `resource`:
4
+ * the one it names, the ones it lists, or every resource of kind `media` of the definition when it
5
+ * names none. Ids that aren't libraries are left out: `lintDefinition()` reports them.
6
+ */
7
+ function getMediaLibraries(definition, field) {
8
+ const libraries = (definition?.resources ?? []).filter((resource) => resource.kind === "media").map((resource) => resource.id);
9
+ if (field.resource === void 0) return libraries;
10
+ return (typeof field.resource === "string" ? [field.resource] : field.resource).filter((id) => libraries.includes(id));
11
+ }
12
+ /**
13
+ * The key of an item that holds its image (decision 0061): the resource's `itemImage`, or `media`
14
+ * in a media library, whose items all have one. `undefined` for a resource without an image.
15
+ */
16
+ function getItemImageField(resource) {
17
+ return resource.itemImage ?? (resource.kind === "media" ? "media" : void 0);
18
+ }
19
+ function isRecord(value) {
20
+ return typeof value === "object" && value !== null && !Array.isArray(value);
21
+ }
22
+ /** The types of images that browsers show. A HEIC or TIFF original needs a thumbnail. */
23
+ var WEB_IMAGE_TYPES = /* @__PURE__ */ new Set([
24
+ "image/apng",
25
+ "image/avif",
26
+ "image/bmp",
27
+ "image/gif",
28
+ "image/jpeg",
29
+ "image/png",
30
+ "image/svg+xml",
31
+ "image/webp"
32
+ ]);
33
+ /**
34
+ * Whether the URL of a media or a file is an image to show, from its `type` (a media's URL is
35
+ * the file to show) or its `mime` (a file's URL is its original), when it says.
36
+ */
37
+ function isImageSource(source) {
38
+ if (typeof source.type === "string") return source.type === "image";
39
+ if (typeof source.mime === "string") return WEB_IMAGE_TYPES.has(source.mime.toLowerCase());
40
+ return true;
41
+ }
42
+ /**
43
+ * The URL of an image value, such as the `itemImage` of an item (decision 0061): a media reference
44
+ * or a media (its thumbnail, or the URL of an image), a stored file (the URL of an image that
45
+ * browsers show), or a URL, and the first of a list. `null` for anything else, such as a PDF
46
+ * without a thumbnail.
47
+ */
48
+ function getImageUrl(value) {
49
+ const first = Array.isArray(value) ? value[0] : value;
50
+ if (typeof first === "string") return first !== "" ? first : null;
51
+ if (!isRecord(first)) return null;
52
+ const source = isRecord(first.media) ? first.media : first;
53
+ const url = source.thumbnailUrl ?? (isImageSource(source) ? source.url : null);
54
+ return typeof url === "string" && url !== "" ? url : null;
55
+ }
56
+ //#endregion
57
+ export { getImageUrl, getItemImageField, getMediaLibraries };
58
+
59
+ //# sourceMappingURL=libraries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libraries.js","names":[],"sources":["../src/libraries.ts"],"sourcesContent":["/** What `getMediaLibraries()` reads of a definition. */\nexport interface MediaLibrariesDefinition {\n resources: readonly { id: string; kind?: string | undefined }[];\n}\n\n/**\n * The ids of the libraries a `media` field allows (decision 0027), in the order of its `resource`:\n * the one it names, the ones it lists, or every resource of kind `media` of the definition when it\n * names none. Ids that aren't libraries are left out: `lintDefinition()` reports them.\n */\nexport function getMediaLibraries(\n definition: MediaLibrariesDefinition | null,\n field: { resource?: string | readonly string[] | undefined },\n): string[] {\n const libraries = (definition?.resources ?? [])\n .filter((resource) => resource.kind === 'media')\n .map((resource) => resource.id);\n if (field.resource === undefined) {\n return libraries;\n }\n const named: readonly string[] =\n typeof field.resource === 'string' ? [field.resource] : field.resource;\n return named.filter((id) => libraries.includes(id));\n}\n\n/** What `getItemImageField()` reads of a resource. */\nexport interface ItemImageResource {\n kind?: string | undefined;\n itemImage?: string | undefined;\n}\n\n/**\n * The key of an item that holds its image (decision 0061): the resource's `itemImage`, or `media`\n * in a media library, whose items all have one. `undefined` for a resource without an image.\n */\nexport function getItemImageField(resource: ItemImageResource): string | undefined {\n return resource.itemImage ?? (resource.kind === 'media' ? 'media' : undefined);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/** The types of images that browsers show. A HEIC or TIFF original needs a thumbnail. */\nconst WEB_IMAGE_TYPES = new Set([\n 'image/apng',\n 'image/avif',\n 'image/bmp',\n 'image/gif',\n 'image/jpeg',\n 'image/png',\n 'image/svg+xml',\n 'image/webp',\n]);\n\n/**\n * Whether the URL of a media or a file is an image to show, from its `type` (a media's URL is\n * the file to show) or its `mime` (a file's URL is its original), when it says.\n */\nfunction isImageSource(source: Record<string, unknown>): boolean {\n if (typeof source.type === 'string') {\n return source.type === 'image';\n }\n if (typeof source.mime === 'string') {\n return WEB_IMAGE_TYPES.has(source.mime.toLowerCase());\n }\n return true;\n}\n\n/**\n * The URL of an image value, such as the `itemImage` of an item (decision 0061): a media reference\n * or a media (its thumbnail, or the URL of an image), a stored file (the URL of an image that\n * browsers show), or a URL, and the first of a list. `null` for anything else, such as a PDF\n * without a thumbnail.\n */\nexport function getImageUrl(value: unknown): string | null {\n const first: unknown = Array.isArray(value) ? value[0] : value;\n if (typeof first === 'string') {\n return first !== '' ? first : null;\n }\n if (!isRecord(first)) {\n return null;\n }\n const source = isRecord(first.media) ? first.media : first;\n const url = source.thumbnailUrl ?? (isImageSource(source) ? source.url : null);\n return typeof url === 'string' && url !== '' ? url : null;\n}\n"],"mappings":";;;;;;AAUA,SAAgB,kBACZ,YACA,OACQ;CACR,MAAM,aAAa,YAAY,aAAa,CAAC,EAAA,CACxC,QAAQ,aAAa,SAAS,SAAS,OAAO,CAAC,CAC/C,KAAK,aAAa,SAAS,EAAE;CAClC,IAAI,MAAM,aAAa,KAAA,GACnB,OAAO;CAIX,QADI,OAAO,MAAM,aAAa,WAAW,CAAC,MAAM,QAAQ,IAAI,MAAM,SAAA,CACrD,QAAQ,OAAO,UAAU,SAAS,EAAE,CAAC;AACtD;;;;;AAYA,SAAgB,kBAAkB,UAAiD;CAC/E,OAAO,SAAS,cAAc,SAAS,SAAS,UAAU,UAAU,KAAA;AACxE;AAEA,SAAS,SAAS,OAAkD;CAChE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC9E;;AAGA,IAAM,kCAAkB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ,CAAC;;;;;AAMD,SAAS,cAAc,QAA0C;CAC7D,IAAI,OAAO,OAAO,SAAS,UACvB,OAAO,OAAO,SAAS;CAE3B,IAAI,OAAO,OAAO,SAAS,UACvB,OAAO,gBAAgB,IAAI,OAAO,KAAK,YAAY,CAAC;CAExD,OAAO;AACX;;;;;;;AAQA,SAAgB,YAAY,OAA+B;CACvD,MAAM,QAAiB,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK;CACzD,IAAI,OAAO,UAAU,UACjB,OAAO,UAAU,KAAK,QAAQ;CAElC,IAAI,CAAC,SAAS,KAAK,GACf,OAAO;CAEX,MAAM,SAAS,SAAS,MAAM,KAAK,IAAI,MAAM,QAAQ;CACrD,MAAM,MAAM,OAAO,iBAAiB,cAAc,MAAM,IAAI,OAAO,MAAM;CACzE,OAAO,OAAO,QAAQ,YAAY,QAAQ,KAAK,MAAM;AACzD"}
@@ -0,0 +1,38 @@
1
+ import { type BuiltInLinkType } from './constants.js';
2
+ import type { Field } from './schemas/field.js';
3
+ /** A type of a `link` field: a built-in one, or one that a site adds in `settings.types`. */
4
+ export interface LinkType {
5
+ /** `url`, `page`, `email`, `tel`, `file`, or the id of a site's type (`anchor`). */
6
+ id: string;
7
+ /** The name of a site's type. Built-in types are named by the client. */
8
+ label?: string;
9
+ /** A site's type: the pattern its `url` must match. */
10
+ pattern?: string;
11
+ /** A site's type: the placeholder of its input. */
12
+ placeholder?: string;
13
+ }
14
+ /** Which links open in a new tab: as the user chooses, by their type, or none. */
15
+ export type LinkNewTab = 'choose' | 'external' | 'never';
16
+ /** Whether a type of link is built in. */
17
+ export declare function isBuiltInLinkType(type: string): type is BuiltInLinkType;
18
+ /**
19
+ * The types a `link` field offers, in order: those of `settings.types`, or `url`, `email` and
20
+ * `tel`, after `page` when the field has a `resource`. A `page` type without a `resource` is left
21
+ * out, as are entries that aren't a built-in name nor a type with an `id`.
22
+ */
23
+ export declare function getLinkTypes(field: Pick<Field, 'resource' | 'settings'>): LinkType[];
24
+ /** The `newTab` setting of a `link` field: `choose` without one. */
25
+ export declare function getLinkNewTab(field: Pick<Field, 'settings'>): LinkNewTab;
26
+ /** Whether a URL points to another site: `https://…`, `http://…` or `//…`. */
27
+ export declare function isExternalUrl(url: string): boolean;
28
+ /**
29
+ * Whether a link opens in a new tab: the user's choice with `choose`, never with `never`, and with
30
+ * `external`, `true` for `url` and `file` links, `false` for `page`, `email` and `tel` links, and
31
+ * for a site's types, whether their URL points to another site.
32
+ */
33
+ export declare function resolveLinkNewTab(newTab: LinkNewTab, link: {
34
+ type?: unknown;
35
+ url?: unknown;
36
+ newTab?: unknown;
37
+ }): boolean;
38
+ //# sourceMappingURL=links.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAG7C,6FAA6F;AAC7F,MAAM,WAAW,QAAQ;IACrB,oFAAoF;IACpF,EAAE,EAAE,MAAM,CAAC;IACX,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,kFAAkF;AAClF,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;AAEzD,0CAA0C;AAC1C,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,eAAe,CAEvE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAAC,GAAG,QAAQ,EAAE,CA8BpF;AAED,oEAAoE;AACpE,wBAAgB,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,UAAU,CAGxE;AAED,8EAA8E;AAC9E,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC7B,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GAC1D,OAAO,CAkBT"}
package/dist/links.js ADDED
@@ -0,0 +1,65 @@
1
+ import { BUILT_IN_LINK_TYPES } from "./constants.js";
2
+ import { isRecord } from "./values.js";
3
+ //#region src/links.ts
4
+ /** Whether a type of link is built in. */
5
+ function isBuiltInLinkType(type) {
6
+ return BUILT_IN_LINK_TYPES.includes(type);
7
+ }
8
+ /**
9
+ * The types a `link` field offers, in order: those of `settings.types`, or `url`, `email` and
10
+ * `tel`, after `page` when the field has a `resource`. A `page` type without a `resource` is left
11
+ * out, as are entries that aren't a built-in name nor a type with an `id`.
12
+ */
13
+ function getLinkTypes(field) {
14
+ const hasPages = field.resource !== void 0;
15
+ const setting = field.settings?.types;
16
+ const entries = Array.isArray(setting) ? setting : [
17
+ ...hasPages ? ["page"] : [],
18
+ "url",
19
+ "email",
20
+ "tel"
21
+ ];
22
+ const types = [];
23
+ entries.forEach((entry) => {
24
+ let type = null;
25
+ if (typeof entry === "string" && isBuiltInLinkType(entry)) type = { id: entry };
26
+ else if (isRecord(entry) && typeof entry.id === "string" && entry.id !== "") type = {
27
+ id: entry.id,
28
+ ...typeof entry.label === "string" ? { label: entry.label } : {},
29
+ ...typeof entry.pattern === "string" ? { pattern: entry.pattern } : {},
30
+ ...typeof entry.placeholder === "string" ? { placeholder: entry.placeholder } : {}
31
+ };
32
+ if (type !== null && (type.id !== "page" || hasPages) && !types.some((other) => other.id === type.id)) types.push(type);
33
+ });
34
+ return types;
35
+ }
36
+ /** The `newTab` setting of a `link` field: `choose` without one. */
37
+ function getLinkNewTab(field) {
38
+ const setting = field.settings?.newTab;
39
+ return setting === "external" || setting === "never" ? setting : "choose";
40
+ }
41
+ /** Whether a URL points to another site: `https://…`, `http://…` or `//…`. */
42
+ function isExternalUrl(url) {
43
+ return /^(https?:)?\/\//i.test(url.trim());
44
+ }
45
+ /**
46
+ * Whether a link opens in a new tab: the user's choice with `choose`, never with `never`, and with
47
+ * `external`, `true` for `url` and `file` links, `false` for `page`, `email` and `tel` links, and
48
+ * for a site's types, whether their URL points to another site.
49
+ */
50
+ function resolveLinkNewTab(newTab, link) {
51
+ if (newTab === "never") return false;
52
+ if (newTab === "choose") return link.newTab === true;
53
+ switch (link.type) {
54
+ case "url":
55
+ case "file": return true;
56
+ case "page":
57
+ case "email":
58
+ case "tel": return false;
59
+ default: return typeof link.url === "string" && isExternalUrl(link.url);
60
+ }
61
+ }
62
+ //#endregion
63
+ export { getLinkNewTab, getLinkTypes, isBuiltInLinkType, isExternalUrl, resolveLinkNewTab };
64
+
65
+ //# sourceMappingURL=links.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"links.js","names":[],"sources":["../src/links.ts"],"sourcesContent":["// The types of `link` values and their new tabs (decision 0055). This module doesn't import zod.\nimport { BUILT_IN_LINK_TYPES, type BuiltInLinkType } from './constants';\nimport type { Field } from './schemas/field';\nimport { isRecord } from './values';\n\n/** A type of a `link` field: a built-in one, or one that a site adds in `settings.types`. */\nexport interface LinkType {\n /** `url`, `page`, `email`, `tel`, `file`, or the id of a site's type (`anchor`). */\n id: string;\n /** The name of a site's type. Built-in types are named by the client. */\n label?: string;\n /** A site's type: the pattern its `url` must match. */\n pattern?: string;\n /** A site's type: the placeholder of its input. */\n placeholder?: string;\n}\n\n/** Which links open in a new tab: as the user chooses, by their type, or none. */\nexport type LinkNewTab = 'choose' | 'external' | 'never';\n\n/** Whether a type of link is built in. */\nexport function isBuiltInLinkType(type: string): type is BuiltInLinkType {\n return (BUILT_IN_LINK_TYPES as readonly string[]).includes(type);\n}\n\n/**\n * The types a `link` field offers, in order: those of `settings.types`, or `url`, `email` and\n * `tel`, after `page` when the field has a `resource`. A `page` type without a `resource` is left\n * out, as are entries that aren't a built-in name nor a type with an `id`.\n */\nexport function getLinkTypes(field: Pick<Field, 'resource' | 'settings'>): LinkType[] {\n const hasPages = field.resource !== undefined;\n const setting = field.settings?.types;\n const entries: unknown[] = Array.isArray(setting)\n ? setting\n : [...(hasPages ? ['page'] : []), 'url', 'email', 'tel'];\n const types: LinkType[] = [];\n entries.forEach((entry) => {\n let type: LinkType | null = null;\n if (typeof entry === 'string' && isBuiltInLinkType(entry)) {\n type = { id: entry };\n } else if (isRecord(entry) && typeof entry.id === 'string' && entry.id !== '') {\n type = {\n id: entry.id,\n ...(typeof entry.label === 'string' ? { label: entry.label } : {}),\n ...(typeof entry.pattern === 'string' ? { pattern: entry.pattern } : {}),\n ...(typeof entry.placeholder === 'string'\n ? { placeholder: entry.placeholder }\n : {}),\n };\n }\n if (\n type !== null &&\n (type.id !== 'page' || hasPages) &&\n !types.some((other) => other.id === type.id)\n ) {\n types.push(type);\n }\n });\n return types;\n}\n\n/** The `newTab` setting of a `link` field: `choose` without one. */\nexport function getLinkNewTab(field: Pick<Field, 'settings'>): LinkNewTab {\n const setting = field.settings?.newTab;\n return setting === 'external' || setting === 'never' ? setting : 'choose';\n}\n\n/** Whether a URL points to another site: `https://…`, `http://…` or `//…`. */\nexport function isExternalUrl(url: string): boolean {\n return /^(https?:)?\\/\\//i.test(url.trim());\n}\n\n/**\n * Whether a link opens in a new tab: the user's choice with `choose`, never with `never`, and with\n * `external`, `true` for `url` and `file` links, `false` for `page`, `email` and `tel` links, and\n * for a site's types, whether their URL points to another site.\n */\nexport function resolveLinkNewTab(\n newTab: LinkNewTab,\n link: { type?: unknown; url?: unknown; newTab?: unknown },\n): boolean {\n if (newTab === 'never') {\n return false;\n }\n if (newTab === 'choose') {\n return link.newTab === true;\n }\n switch (link.type) {\n case 'url':\n case 'file':\n return true;\n case 'page':\n case 'email':\n case 'tel':\n return false;\n default:\n return typeof link.url === 'string' && isExternalUrl(link.url);\n }\n}\n"],"mappings":";;;;AAqBA,SAAgB,kBAAkB,MAAuC;CACrE,OAAQ,oBAA0C,SAAS,IAAI;AACnE;;;;;;AAOA,SAAgB,aAAa,OAAyD;CAClF,MAAM,WAAW,MAAM,aAAa,KAAA;CACpC,MAAM,UAAU,MAAM,UAAU;CAChC,MAAM,UAAqB,MAAM,QAAQ,OAAO,IAC1C,UACA;EAAC,GAAI,WAAW,CAAC,MAAM,IAAI,CAAC;EAAI;EAAO;EAAS;CAAK;CAC3D,MAAM,QAAoB,CAAC;CAC3B,QAAQ,SAAS,UAAU;EACvB,IAAI,OAAwB;EAC5B,IAAI,OAAO,UAAU,YAAY,kBAAkB,KAAK,GACpD,OAAO,EAAE,IAAI,MAAM;OAChB,IAAI,SAAS,KAAK,KAAK,OAAO,MAAM,OAAO,YAAY,MAAM,OAAO,IACvE,OAAO;GACH,IAAI,MAAM;GACV,GAAI,OAAO,MAAM,UAAU,WAAW,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;GAChE,GAAI,OAAO,MAAM,YAAY,WAAW,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;GACtE,GAAI,OAAO,MAAM,gBAAgB,WAC3B,EAAE,aAAa,MAAM,YAAY,IACjC,CAAC;EACX;EAEJ,IACI,SAAS,SACR,KAAK,OAAO,UAAU,aACvB,CAAC,MAAM,MAAM,UAAU,MAAM,OAAO,KAAK,EAAE,GAE3C,MAAM,KAAK,IAAI;CAEvB,CAAC;CACD,OAAO;AACX;;AAGA,SAAgB,cAAc,OAA4C;CACtE,MAAM,UAAU,MAAM,UAAU;CAChC,OAAO,YAAY,cAAc,YAAY,UAAU,UAAU;AACrE;;AAGA,SAAgB,cAAc,KAAsB;CAChD,OAAO,mBAAmB,KAAK,IAAI,KAAK,CAAC;AAC7C;;;;;;AAOA,SAAgB,kBACZ,QACA,MACO;CACP,IAAI,WAAW,SACX,OAAO;CAEX,IAAI,WAAW,UACX,OAAO,KAAK,WAAW;CAE3B,QAAQ,KAAK,MAAb;EACI,KAAK;EACL,KAAK,QACD,OAAO;EACX,KAAK;EACL,KAAK;EACL,KAAK,OACD,OAAO;EACX,SACI,OAAO,OAAO,KAAK,QAAQ,YAAY,cAAc,KAAK,GAAG;CACrE;AACJ"}
package/dist/lint.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type { DefinitionInput } from './schemas';
2
- import type { ValidationIssue } from './validate';
1
+ import type { DefinitionInput } from './schemas/index.js';
2
+ import type { ValidationIssue } from './validate.js';
3
3
  /**
4
4
  * Checks what the schema can't: references between parts of a definition (layout nodes and
5
- * columns that name existing fields, relations and media fields that name a resource, unique
6
- * names), and the `file` field of `media` resources.
5
+ * columns that name existing fields, relations, `media` and `image` fields that name a resource,
6
+ * unique names), the types of resources, and the `file` field of `media` resources.
7
7
  */
8
8
  export declare function lintDefinition(definition: DefinitionInput): ValidationIssue[];
9
9
  //# sourceMappingURL=lint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAoC,MAAM,WAAW,CAAC;AACnF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA0FlD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,eAAe,GAAG,eAAe,EAAE,CAyC7E"}
1
+ {"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACR,eAAe,EAMlB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAsQlD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,eAAe,GAAG,eAAe,EAAE,CAuF7E"}