@panneau/protocol 5.0.0-alpha.3 → 5.0.0-alpha.31

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 (147) hide show
  1. package/dist/addresses.d.ts +23 -0
  2. package/dist/addresses.d.ts.map +1 -0
  3. package/dist/addresses.js +52 -0
  4. package/dist/addresses.js.map +1 -0
  5. package/dist/compound.d.ts +20 -0
  6. package/dist/compound.d.ts.map +1 -0
  7. package/dist/compound.js +27 -0
  8. package/dist/compound.js.map +1 -0
  9. package/dist/conditions.d.ts +1 -1
  10. package/dist/conformance/index.d.ts +6 -0
  11. package/dist/conformance/index.d.ts.map +1 -1
  12. package/dist/conformance/index.js +801 -11
  13. package/dist/conformance/index.js.map +1 -1
  14. package/dist/constants.d.ts +108 -2
  15. package/dist/constants.d.ts.map +1 -1
  16. package/dist/constants.js +181 -3
  17. package/dist/constants.js.map +1 -1
  18. package/dist/context.d.ts +15 -0
  19. package/dist/context.d.ts.map +1 -0
  20. package/dist/context.js +34 -0
  21. package/dist/context.js.map +1 -0
  22. package/dist/currencies.d.ts +22 -0
  23. package/dist/currencies.d.ts.map +1 -0
  24. package/dist/currencies.js +231 -0
  25. package/dist/currencies.js.map +1 -0
  26. package/dist/index.d.ts +4 -4
  27. package/dist/index.js +19 -8
  28. package/dist/libraries.d.ts +33 -0
  29. package/dist/libraries.d.ts.map +1 -0
  30. package/dist/libraries.js +59 -0
  31. package/dist/libraries.js.map +1 -0
  32. package/dist/links.d.ts +38 -0
  33. package/dist/links.d.ts.map +1 -0
  34. package/dist/links.js +65 -0
  35. package/dist/links.js.map +1 -0
  36. package/dist/lint.d.ts +4 -3
  37. package/dist/lint.d.ts.map +1 -1
  38. package/dist/lint.js +168 -7
  39. package/dist/lint.js.map +1 -1
  40. package/dist/mock/auth.d.ts +71 -0
  41. package/dist/mock/auth.d.ts.map +1 -0
  42. package/dist/mock/auth.js +346 -0
  43. package/dist/mock/auth.js.map +1 -0
  44. package/dist/mock/example.d.ts +3 -2
  45. package/dist/mock/example.d.ts.map +1 -1
  46. package/dist/mock/example.js +241 -144
  47. package/dist/mock/example.js.map +1 -1
  48. package/dist/mock/index.d.ts +79 -7
  49. package/dist/mock/index.d.ts.map +1 -1
  50. package/dist/mock/index.js +603 -38
  51. package/dist/mock/index.js.map +1 -1
  52. package/dist/openapi.d.ts.map +1 -1
  53. package/dist/openapi.js +392 -144
  54. package/dist/openapi.js.map +1 -1
  55. package/dist/problem.d.ts +1 -1
  56. package/dist/query.d.ts +18 -0
  57. package/dist/query.d.ts.map +1 -1
  58. package/dist/query.js +34 -8
  59. package/dist/query.js.map +1 -1
  60. package/dist/resourceTypes.d.ts +39 -0
  61. package/dist/resourceTypes.d.ts.map +1 -0
  62. package/dist/resourceTypes.js +34 -0
  63. package/dist/resourceTypes.js.map +1 -0
  64. package/dist/rules.d.ts +18 -5
  65. package/dist/rules.d.ts.map +1 -1
  66. package/dist/rules.js +233 -15
  67. package/dist/rules.js.map +1 -1
  68. package/dist/runtime/index.d.ts +20 -10
  69. package/dist/runtime/index.d.ts.map +1 -1
  70. package/dist/runtime/index.js +13 -3
  71. package/dist/schemas/action.d.ts +118 -10
  72. package/dist/schemas/action.d.ts.map +1 -1
  73. package/dist/schemas/action.js +20 -3
  74. package/dist/schemas/action.js.map +1 -1
  75. package/dist/schemas/api.d.ts +334 -42
  76. package/dist/schemas/api.d.ts.map +1 -1
  77. package/dist/schemas/api.js +194 -34
  78. package/dist/schemas/api.js.map +1 -1
  79. package/dist/schemas/boot.d.ts +25 -1
  80. package/dist/schemas/boot.d.ts.map +1 -1
  81. package/dist/schemas/boot.js +2 -1
  82. package/dist/schemas/boot.js.map +1 -1
  83. package/dist/schemas/common.d.ts +1 -0
  84. package/dist/schemas/common.d.ts.map +1 -1
  85. package/dist/schemas/common.js +2 -1
  86. package/dist/schemas/common.js.map +1 -1
  87. package/dist/schemas/definition.d.ts +341 -28
  88. package/dist/schemas/definition.d.ts.map +1 -1
  89. package/dist/schemas/definition.js +65 -19
  90. package/dist/schemas/definition.js.map +1 -1
  91. package/dist/schemas/field.d.ts +357 -2
  92. package/dist/schemas/field.d.ts.map +1 -1
  93. package/dist/schemas/field.js +160 -20
  94. package/dist/schemas/field.js.map +1 -1
  95. package/dist/schemas/index.d.ts +1429 -80
  96. package/dist/schemas/index.d.ts.map +1 -1
  97. package/dist/schemas/index.js +60 -10
  98. package/dist/schemas/index.js.map +1 -1
  99. package/dist/schemas/jsonRules.d.ts +83 -0
  100. package/dist/schemas/jsonRules.d.ts.map +1 -0
  101. package/dist/schemas/jsonRules.js +46 -0
  102. package/dist/schemas/jsonRules.js.map +1 -0
  103. package/dist/schemas/layout.d.ts +2 -1
  104. package/dist/schemas/layout.d.ts.map +1 -1
  105. package/dist/schemas/layout.js +2 -1
  106. package/dist/schemas/layout.js.map +1 -1
  107. package/dist/schemas/list.d.ts +23 -2
  108. package/dist/schemas/list.d.ts.map +1 -1
  109. package/dist/schemas/list.js +15 -6
  110. package/dist/schemas/list.js.map +1 -1
  111. package/dist/schemas/resource.d.ts +263 -17
  112. package/dist/schemas/resource.d.ts.map +1 -1
  113. package/dist/schemas/resource.js +19 -4
  114. package/dist/schemas/resource.js.map +1 -1
  115. package/dist/schemas/theme.d.ts +4 -0
  116. package/dist/schemas/theme.d.ts.map +1 -1
  117. package/dist/schemas/theme.js +1 -0
  118. package/dist/schemas/theme.js.map +1 -1
  119. package/dist/schemas/widget.d.ts +109 -0
  120. package/dist/schemas/widget.d.ts.map +1 -0
  121. package/dist/schemas/widget.js +74 -0
  122. package/dist/schemas/widget.js.map +1 -0
  123. package/dist/search.d.ts +51 -0
  124. package/dist/search.d.ts.map +1 -0
  125. package/dist/search.js +53 -0
  126. package/dist/search.js.map +1 -0
  127. package/dist/themes.d.ts +1 -1
  128. package/dist/transforms.d.ts +17 -0
  129. package/dist/transforms.d.ts.map +1 -0
  130. package/dist/transforms.js +34 -0
  131. package/dist/transforms.js.map +1 -0
  132. package/dist/validate.d.ts +5 -3
  133. package/dist/validate.d.ts.map +1 -1
  134. package/dist/validate.js +36 -2
  135. package/dist/validate.js.map +1 -1
  136. package/dist/values.d.ts +5 -1
  137. package/dist/values.d.ts.map +1 -1
  138. package/dist/values.js +16 -2
  139. package/dist/values.js.map +1 -1
  140. package/dist/widgets.d.ts +42 -0
  141. package/dist/widgets.d.ts.map +1 -0
  142. package/dist/widgets.js +130 -0
  143. package/dist/widgets.js.map +1 -0
  144. package/package.json +6 -3
  145. package/schema/boot.schema.json +713 -20
  146. package/schema/definition.schema.json +710 -20
  147. package/schema/openapi.json +5656 -2229
package/dist/index.js CHANGED
@@ -1,23 +1,34 @@
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, RESOURCE_WIDGET_TYPES, WIDGET_LIST_MAX_ITEMS, WIDGET_RESERVED_QUERY_PARAMS, WIDGET_SERIES_PERIODS, checkWidgetData, getWidgetResource, isBuiltInWidgetType } from "./widgets.js";
6
15
  import { lintDefinition } from "./lint.js";
7
- import { fromSearchParams, isFilterRange, matchesFilterRange, toSearchParams } from "./query.js";
16
+ import { SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, isSearchableResource, readSearchQuery, toSearchQueryParams } from "./search.js";
17
+ import { contextBefore, formatContextHeader, parseContextHeader } from "./context.js";
8
18
  import { isProblem } from "./problem.js";
9
19
  import { mergeThemes } from "./themes.js";
10
20
  import { Abilities, Condition, Id, Option, RouteReference } from "./schemas/common.js";
11
- import { BlockType, Field, Rule } from "./schemas/field.js";
21
+ import { AddressSettings, BlockType, DateRangeSettings, DurationSettings, Field, LinkSettings, LinkTypeSetting, MoneySettings, RichTextSettings, RichTextStyle, Rule } from "./schemas/field.js";
12
22
  import { LayoutNode } from "./schemas/layout.js";
13
23
  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";
24
+ import { Column, Filter, ListCalendar, ListDefinition } from "./schemas/list.js";
25
+ import { Resource, ResourceFeatures, ResourceType } from "./schemas/resource.js";
16
26
  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, Media, MediaListResponse, MediaResponse, MediaTransform, Pagination, PreviewResponse, Problem, SearchResponse, Selection, Session } from "./schemas/api.js";
27
+ import { ListWidgetData, ListWidgetItem, SeriesPoint, SeriesWidgetData, StatWidgetData, Widget, WidgetBadge, WidgetSettings, widgetDataSchemas } from "./schemas/widget.js";
28
+ import { Auth, AuthProvider, AuthToken, ContextOption, ContextParam, Definition, DefinitionContext, MenuItem, Page, Uploads, User } from "./schemas/definition.js";
29
+ 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
30
  import { BootConfig } from "./schemas/boot.js";
20
31
  import { createSchemaRegistry, namedSchemas } from "./schemas/index.js";
21
32
  import { validate, validateBootConfig, validateDefinition } from "./validate.js";
22
33
  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, Media, MediaListResponse, MediaResponse, MediaTransform, MenuItem, Option, PORTABLE_RULES, PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION, Page, Pagination, PreviewResponse, Problem, Resource, ResourceFeatures, RouteReference, Rule, SearchResponse, Selection, Session, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues, 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 };
34
+ export { ADDRESS_PARTS, 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, CONTEXT_HEADER, CONTEXT_PROBLEM_TYPE, CURRENCY_CODES, Column, Condition, ContextOption, ContextOptionsResponse, ContextParam, CursorPagination, 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, IDS_FILTER, IDS_FILTER_LIMIT, ITEM_ACTION_ABILITIES, ITEM_TYPE_KEY, Id, Item, ItemResponse, LayoutNode, LinkSettings, LinkTypeSetting, LinkValue, ListCalendar, ListDefinition, ListResponse, ListWidgetData, ListWidgetItem, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, MenuItem, MoneySettings, MoneyValue, Option, PASSWORD_CONFIRMATION_PROBLEM_TYPE, 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, ResourceType, RichTextSettings, RichTextStyle, RouteReference, Rule, SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, SearchResponse, Selection, SeriesPoint, SeriesWidgetData, Session, StatWidgetData, StoredFile, TWO_FACTOR_REQUIRED_PROBLEM_TYPE, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues, TwoFactorChallenge, TwoFactorSetup, TwoFactorStatus, UNDO_LIMIT, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse, Uploads, User, WIDGET_LIST_MAX_ITEMS, WIDGET_RESERVED_QUERY_PARAMS, WIDGET_SERIES_PERIODS, WebAuthnOptions, Widget, WidgetBadge, WidgetSettings, checkRules, checkValues, checkWidgetData, contextBefore, createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createSchemaRegistry, createThemeJsonSchema, evaluateCondition, formatContextHeader, fromMinorUnits, fromSearchParams, getAddressRequiredParts, getCreatableTypes, getCurrencyDigits, getImageUrl, getItemImageField, getItemType, getLinkNewTab, getLinkTypes, getMediaLibraries, getNestedShape, getResourceType, getTypeFields, getValue, getWidgetResource, hasResourceTypes, isAddressPart, isBuiltInFieldType, isBuiltInItemAction, isBuiltInLink, isBuiltInLinkType, isBuiltInWidgetType, isCompoundField, isCurrencyCode, isCursorPage, isExternalUrl, isFilled, isFilterRange, isPostalCode, isProblem, isSearchableResource, lintDefinition, matchesFilterRange, matchesRatio, mergeThemes, namedSchemas, normalizePostalCode, parseContextHeader, parseRatio, readSearchQuery, renderedCropSize, resolveLinkNewTab, toMinorUnits, toSearchParams, toSearchQueryParams, 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,MA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AAK;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,8 +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 that name a resource, unique names).
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.
6
7
  */
7
8
  export declare function lintDefinition(definition: DefinitionInput): ValidationIssue[];
8
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;AA2ElD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,eAAe,GAAG,eAAe,EAAE,CAmB7E"}
1
+ {"version":3,"file":"lint.d.ts","sourceRoot":"","sources":["../src/lint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAoC,MAAM,WAAW,CAAC;AACnF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA+LlD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,eAAe,GAAG,eAAe,EAAE,CAiD7E"}
package/dist/lint.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { ITEM_TYPE_KEY } from "./resourceTypes.js";
2
+ import { RESOURCE_WIDGET_TYPES, WIDGET_RESERVED_QUERY_PARAMS, isBuiltInWidgetType } from "./widgets.js";
1
3
  //#region src/lint.ts
2
4
  function fieldNames(fields) {
3
5
  return new Set(fields.map((field) => field.name));
@@ -26,47 +28,206 @@ function checkLayout(nodes, names, path, issues) {
26
28
  if (node.children !== void 0) checkLayout(node.children, names, `${nodePath}.children`, issues);
27
29
  });
28
30
  }
31
+ /**
32
+ * The types of a resource (decision 0077): unique ids, fields named apart from those of the
33
+ * resource, and no field `type` in the form, which holds the item's type.
34
+ */
35
+ function checkTypes(resource, names, path, issues) {
36
+ const ids = /* @__PURE__ */ new Set();
37
+ (resource.types ?? []).forEach((type, index) => {
38
+ const typePath = `${path}.types.${index}`;
39
+ if (ids.has(type.id)) issues.push({
40
+ path: `${typePath}.id`,
41
+ message: `Duplicate type id \`${type.id}\`.`
42
+ });
43
+ ids.add(type.id);
44
+ if (fieldNames(type.fields).size !== type.fields.length) issues.push({
45
+ path: `${typePath}.fields`,
46
+ message: "Field names must be unique."
47
+ });
48
+ type.fields.forEach((field, fieldIndex) => {
49
+ if (names.has(field.name)) issues.push({
50
+ path: `${typePath}.fields.${fieldIndex}.name`,
51
+ message: `The resource already has a field named \`${field.name}\`.`
52
+ });
53
+ else if (field.name === "type") issues.push({
54
+ path: `${typePath}.fields.${fieldIndex}.name`,
55
+ message: `\`${ITEM_TYPE_KEY}\` holds the type of the item.`
56
+ });
57
+ });
58
+ });
59
+ const typeField = resource.fields.findIndex((field) => field.name === ITEM_TYPE_KEY);
60
+ if (ids.size > 0 && typeField !== -1 && resource.fields[typeField]?.notInForm !== true) issues.push({
61
+ path: `${path}.fields.${typeField}`,
62
+ message: `\`${ITEM_TYPE_KEY}\` holds the type of the item, set when it is created: its field must be \`notInForm\`.`
63
+ });
64
+ }
65
+ /** The fields of a resource and of its types, with their paths. */
66
+ function allFields(resource, path) {
67
+ return [...resource.fields.map((field, index) => ({
68
+ field,
69
+ path: `${path}.fields.${index}`
70
+ })), ...(resource.types ?? []).flatMap((type, typeIndex) => type.fields.map((field, index) => ({
71
+ field,
72
+ path: `${path}.types.${typeIndex}.fields.${index}`
73
+ })))];
74
+ }
29
75
  function checkResource(resource, path, issues) {
30
76
  const names = fieldNames(resource.fields);
31
77
  if (names.size !== resource.fields.length) issues.push({
32
78
  path: `${path}.fields`,
33
79
  message: "Field names must be unique."
34
80
  });
35
- if (resource.form?.layout !== void 0) checkLayout(resource.form.layout, names, `${path}.form.layout`, issues);
81
+ checkTypes(resource, names, path, issues);
82
+ if (resource.form?.layout !== void 0) {
83
+ const typeNames = (resource.types ?? []).flatMap((type) => [...fieldNames(type.fields)]);
84
+ checkLayout(resource.form.layout, /* @__PURE__ */ new Set([...names, ...typeNames]), `${path}.form.layout`, issues);
85
+ }
36
86
  (resource.list?.columns ?? []).forEach((column, index) => {
37
87
  if (column.field !== void 0 && !names.has(column.field)) issues.push({
38
88
  path: `${path}.list.columns.${index}.field`,
39
89
  message: `No field named \`${column.field}\`.`
40
90
  });
41
91
  });
92
+ const calendar = resource.list?.calendar;
93
+ if (calendar !== void 0) {
94
+ const field = resource.fields.find((candidate) => candidate.name === calendar.field);
95
+ const filter = calendar.filter ?? calendar.field;
96
+ if (field === void 0) issues.push({
97
+ path: `${path}.list.calendar.field`,
98
+ message: `No field named \`${calendar.field}\`.`
99
+ });
100
+ else if (![
101
+ "date",
102
+ "datetime",
103
+ "daterange"
104
+ ].includes(field.type)) issues.push({
105
+ path: `${path}.list.calendar.field`,
106
+ message: "The field of a calendar must be a `date`, a `datetime` or a `daterange`."
107
+ });
108
+ if (!(resource.list?.filters ?? []).some((candidate) => candidate.id === filter && candidate.type === "date-range")) issues.push({
109
+ path: `${path}.list.calendar`,
110
+ message: `The calendar needs a \`date-range\` filter \`${filter}\` in the list.`
111
+ });
112
+ }
42
113
  (resource.actions ?? []).forEach((action, index) => {
43
114
  if (action.layout !== void 0) checkLayout(action.layout, fieldNames(action.fields ?? []), `${path}.actions.${index}.layout`, issues);
44
115
  });
45
- resource.fields.forEach((field, index) => {
116
+ if (resource.kind === "media") {
117
+ const file = resource.fields.findIndex((field) => field.name === "file");
118
+ const field = resource.fields[file];
119
+ if (field === void 0) issues.push({
120
+ path: `${path}.fields`,
121
+ message: "A resource of kind `media` needs a `file` field."
122
+ });
123
+ else if (field.type !== "file" || field.multiple === true) issues.push({
124
+ path: `${path}.fields.${file}`,
125
+ message: "The `file` field of a `media` resource must be a single `file`."
126
+ });
127
+ }
128
+ allFields(resource, path).forEach(({ field, path: fieldPath }) => {
46
129
  if (field.type === "relation" && field.resource === void 0) issues.push({
47
- path: `${path}.fields.${index}.resource`,
130
+ path: `${fieldPath}.resource`,
48
131
  message: "A `relation` field needs a `resource`."
49
132
  });
133
+ else if (field.type === "relation" && Array.isArray(field.resource)) issues.push({
134
+ path: `${fieldPath}.resource`,
135
+ message: "A `relation` field names one resource."
136
+ });
50
137
  });
51
138
  }
52
139
  /**
53
140
  * Checks what the schema can't: references between parts of a definition (layout nodes and
54
- * columns that name existing fields, relations that name a resource, unique names).
141
+ * columns that name existing fields, relations, `media` and `image` fields that name a resource,
142
+ * unique names), the types of resources, and the `file` field of `media` resources.
55
143
  */
56
144
  function lintDefinition(definition) {
57
145
  const issues = [];
58
146
  const resourceIds = new Set(definition.resources.map((resource) => resource.id));
147
+ const libraries = definition.resources.filter((resource) => resource.kind === "media").map((resource) => resource.id);
59
148
  definition.resources.forEach((resource, index) => {
60
149
  checkResource(resource, `resources.${index}`, issues);
61
- resource.fields.forEach((field, fieldIndex) => {
62
- if (field.type === "relation" && field.resource !== void 0 && !resourceIds.has(field.resource)) issues.push({
63
- path: `resources.${index}.fields.${fieldIndex}.resource`,
150
+ allFields(resource, `resources.${index}`).forEach(({ field, path }) => {
151
+ if (field.type === "relation" && typeof field.resource === "string" && !resourceIds.has(field.resource)) issues.push({
152
+ path: `${path}.resource`,
64
153
  message: `No resource \`${field.resource}\`.`
65
154
  });
155
+ if (field.type === "media" || field.type === "image") {
156
+ const fieldPath = `${path}.resource`;
157
+ if (field.resource === void 0) {
158
+ if (libraries.length === 0) issues.push({
159
+ path: fieldPath,
160
+ message: `${field.type === "image" ? "An" : "A"} \`${field.type}\` field needs a resource of kind \`media\`.`
161
+ });
162
+ } else (typeof field.resource === "string" ? [field.resource] : field.resource).forEach((id, idIndex) => {
163
+ if (!libraries.includes(id)) issues.push({
164
+ path: typeof field.resource === "string" ? fieldPath : `${fieldPath}.${String(idIndex)}`,
165
+ message: `No resource of kind \`media\` named \`${id}\`.`
166
+ });
167
+ });
168
+ }
66
169
  });
67
170
  });
171
+ checkWidgets(definition, issues);
68
172
  return issues;
69
173
  }
174
+ var FILTER_PARAM = /^filter\[([^\]]+)\]/;
175
+ /**
176
+ * The widgets of the dashboard (decision 0064): unique ids, and the built-in `stat` and `list` on
177
+ * a resource that exists, with filters of its list. A `stat` counts the items of the list, so the
178
+ * list can't be paged with cursors, which give no total.
179
+ */
180
+ function checkWidgets(definition, issues) {
181
+ const ids = /* @__PURE__ */ new Set();
182
+ (definition.dashboard?.widgets ?? []).forEach((widget, index) => {
183
+ const path = `dashboard.widgets.${index}`;
184
+ if (ids.has(widget.id)) issues.push({
185
+ path: `${path}.id`,
186
+ message: `Duplicate widget id \`${widget.id}\`.`
187
+ });
188
+ ids.add(widget.id);
189
+ if (!isBuiltInWidgetType(widget.type)) return;
190
+ const settings = widget.settings ?? {};
191
+ if (!(typeof settings.resource === "string")) {
192
+ if (settings.query !== void 0) issues.push({
193
+ path: `${path}.settings.query`,
194
+ message: "`query` goes with a `resource`."
195
+ });
196
+ return;
197
+ }
198
+ if (!RESOURCE_WIDGET_TYPES.includes(widget.type)) {
199
+ issues.push({
200
+ path: `${path}.settings.resource`,
201
+ message: `A \`${widget.type}\` widget has data of its own: only \`stat\` and \`list\` read a resource.`
202
+ });
203
+ return;
204
+ }
205
+ const resource = definition.resources.find((candidate) => candidate.id === settings.resource);
206
+ if (resource === void 0) {
207
+ issues.push({
208
+ path: `${path}.settings.resource`,
209
+ message: `No resource \`${String(settings.resource)}\`.`
210
+ });
211
+ return;
212
+ }
213
+ if (widget.type === "stat" && resource.list?.pagination === "cursor") issues.push({
214
+ path: `${path}.settings.resource`,
215
+ message: `The list of \`${resource.id}\` is paged with cursors and has no total: it can't feed a \`stat\`.`
216
+ });
217
+ const filters = new Set((resource.list?.filters ?? []).map((filter) => filter.id));
218
+ Object.keys(settings.query ?? {}).forEach((key) => {
219
+ const filter = FILTER_PARAM.exec(key)?.[1];
220
+ if (WIDGET_RESERVED_QUERY_PARAMS.includes(key)) issues.push({
221
+ path: `${path}.settings.query.${key}`,
222
+ message: `The client sets \`${key}\`.`
223
+ });
224
+ else if (filter !== void 0 && !filters.has(filter)) issues.push({
225
+ path: `${path}.settings.query.${key}`,
226
+ message: `The list of \`${resource.id}\` has no filter \`${filter}\`.`
227
+ });
228
+ });
229
+ });
230
+ }
70
231
  //#endregion
71
232
  export { lintDefinition };
72
233
 
package/dist/lint.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lint.js","names":[],"sources":["../src/lint.ts"],"sourcesContent":["import type { DefinitionInput, Field, LayoutNode, ResourceInput } from './schemas';\nimport type { ValidationIssue } from './validate';\n\nfunction fieldNames(fields: Field[]): Set<string> {\n return new Set(fields.map((field) => field.name));\n}\n\nfunction checkLayout(\n nodes: LayoutNode[],\n names: Set<string>,\n path: string,\n issues: ValidationIssue[],\n) {\n nodes.forEach((node, index) => {\n const nodePath = `${path}.${index}`;\n if (node.type === 'field') {\n if (node.name === undefined) {\n issues.push({ path: nodePath, message: 'A `field` node needs a `name`.' });\n } else if (!names.has(node.name)) {\n issues.push({\n path: `${nodePath}.name`,\n message: `No field named \\`${node.name}\\`.`,\n });\n }\n }\n if (node.type === 'component' && node.component === undefined) {\n issues.push({ path: nodePath, message: 'A `component` node needs a `component`.' });\n }\n if (node.type === 'tabs' && node.children?.some((child) => child.type !== 'tab')) {\n issues.push({\n path: `${nodePath}.children`,\n message: 'The children of `tabs` must be `tab` nodes.',\n });\n }\n if (node.children !== undefined) {\n checkLayout(node.children, names, `${nodePath}.children`, issues);\n }\n });\n}\n\nfunction checkResource(resource: ResourceInput, path: string, issues: ValidationIssue[]) {\n const names = fieldNames(resource.fields);\n if (names.size !== resource.fields.length) {\n issues.push({ path: `${path}.fields`, message: 'Field names must be unique.' });\n }\n if (resource.form?.layout !== undefined) {\n checkLayout(resource.form.layout, names, `${path}.form.layout`, issues);\n }\n (resource.list?.columns ?? []).forEach((column, index) => {\n if (column.field !== undefined && !names.has(column.field)) {\n issues.push({\n path: `${path}.list.columns.${index}.field`,\n message: `No field named \\`${column.field}\\`.`,\n });\n }\n });\n (resource.actions ?? []).forEach((action, index) => {\n if (action.layout !== undefined) {\n checkLayout(\n action.layout,\n fieldNames(action.fields ?? []),\n `${path}.actions.${index}.layout`,\n issues,\n );\n }\n });\n resource.fields.forEach((field, index) => {\n if (field.type === 'relation' && field.resource === undefined) {\n issues.push({\n path: `${path}.fields.${index}.resource`,\n message: 'A `relation` field needs a `resource`.',\n });\n }\n });\n}\n\n/**\n * Checks what the schema can't: references between parts of a definition (layout nodes and\n * columns that name existing fields, relations that name a resource, unique names).\n */\nexport function lintDefinition(definition: DefinitionInput): ValidationIssue[] {\n const issues: ValidationIssue[] = [];\n const resourceIds = new Set(definition.resources.map((resource) => resource.id));\n definition.resources.forEach((resource, index) => {\n checkResource(resource, `resources.${index}`, issues);\n resource.fields.forEach((field, fieldIndex) => {\n if (\n field.type === 'relation' &&\n field.resource !== undefined &&\n !resourceIds.has(field.resource)\n ) {\n issues.push({\n path: `resources.${index}.fields.${fieldIndex}.resource`,\n message: `No resource \\`${field.resource}\\`.`,\n });\n }\n });\n });\n return issues;\n}\n"],"mappings":";AAGA,SAAS,WAAW,QAA8B;CAC9C,OAAO,IAAI,IAAI,OAAO,KAAK,UAAU,MAAM,IAAI,CAAC;AACpD;AAEA,SAAS,YACL,OACA,OACA,MACA,QACF;CACE,MAAM,SAAS,MAAM,UAAU;EAC3B,MAAM,WAAW,GAAG,KAAK,GAAG;EAC5B,IAAI,KAAK,SAAS,SAAS;GACvB,IAAI,KAAK,SAAS,KAAA,GACd,OAAO,KAAK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AAC;CACD,SAAS,OAAO,SAAS,OAAO,UAAU;EACtC,IAAI,MAAM,SAAS,cAAc,MAAM,aAAa,KAAA,GAChD,OAAO,KAAK;GACR,MAAM,GAAG,KAAK,UAAU,MAAM;GAC9B,SAAS;EACb,CAAC;CAET,CAAC;AACL;;;;;AAMA,SAAgB,eAAe,YAAgD;CAC3E,MAAM,SAA4B,CAAC;CACnC,MAAM,cAAc,IAAI,IAAI,WAAW,UAAU,KAAK,aAAa,SAAS,EAAE,CAAC;CAC/E,WAAW,UAAU,SAAS,UAAU,UAAU;EAC9C,cAAc,UAAU,aAAa,SAAS,MAAM;EACpD,SAAS,OAAO,SAAS,OAAO,eAAe;GAC3C,IACI,MAAM,SAAS,cACf,MAAM,aAAa,KAAA,KACnB,CAAC,YAAY,IAAI,MAAM,QAAQ,GAE/B,OAAO,KAAK;IACR,MAAM,aAAa,MAAM,UAAU,WAAW;IAC9C,SAAS,iBAAiB,MAAM,SAAS;GAC7C,CAAC;EAET,CAAC;CACL,CAAC;CACD,OAAO;AACX"}
1
+ {"version":3,"file":"lint.js","names":[],"sources":["../src/lint.ts"],"sourcesContent":["import { ITEM_TYPE_KEY } from './resourceTypes';\nimport type { DefinitionInput, Field, LayoutNode, ResourceInput } from './schemas';\nimport type { ValidationIssue } from './validate';\nimport {\n RESOURCE_WIDGET_TYPES,\n WIDGET_RESERVED_QUERY_PARAMS,\n isBuiltInWidgetType,\n} from './widgets';\n\nfunction fieldNames(fields: Field[]): Set<string> {\n return new Set(fields.map((field) => field.name));\n}\n\nfunction checkLayout(\n nodes: LayoutNode[],\n names: Set<string>,\n path: string,\n issues: ValidationIssue[],\n) {\n nodes.forEach((node, index) => {\n const nodePath = `${path}.${index}`;\n if (node.type === 'field') {\n if (node.name === undefined) {\n issues.push({ path: nodePath, message: 'A `field` node needs a `name`.' });\n } else if (!names.has(node.name)) {\n issues.push({\n path: `${nodePath}.name`,\n message: `No field named \\`${node.name}\\`.`,\n });\n }\n }\n if (node.type === 'component' && node.component === undefined) {\n issues.push({ path: nodePath, message: 'A `component` node needs a `component`.' });\n }\n if (node.type === 'tabs' && node.children?.some((child) => child.type !== 'tab')) {\n issues.push({\n path: `${nodePath}.children`,\n message: 'The children of `tabs` must be `tab` nodes.',\n });\n }\n if (node.children !== undefined) {\n checkLayout(node.children, names, `${nodePath}.children`, issues);\n }\n });\n}\n\n/**\n * The types of a resource (decision 0077): unique ids, fields named apart from those of the\n * resource, and no field `type` in the form, which holds the item's type.\n */\nfunction checkTypes(\n resource: ResourceInput,\n names: Set<string>,\n path: string,\n issues: ValidationIssue[],\n) {\n const ids = new Set<string>();\n (resource.types ?? []).forEach((type, index) => {\n const typePath = `${path}.types.${index}`;\n if (ids.has(type.id)) {\n issues.push({ path: `${typePath}.id`, message: `Duplicate type id \\`${type.id}\\`.` });\n }\n ids.add(type.id);\n const own = fieldNames(type.fields);\n if (own.size !== type.fields.length) {\n issues.push({ path: `${typePath}.fields`, message: 'Field names must be unique.' });\n }\n type.fields.forEach((field, fieldIndex) => {\n if (names.has(field.name)) {\n issues.push({\n path: `${typePath}.fields.${fieldIndex}.name`,\n message: `The resource already has a field named \\`${field.name}\\`.`,\n });\n } else if (field.name === ITEM_TYPE_KEY) {\n issues.push({\n path: `${typePath}.fields.${fieldIndex}.name`,\n message: `\\`${ITEM_TYPE_KEY}\\` holds the type of the item.`,\n });\n }\n });\n });\n const typeField = resource.fields.findIndex((field) => field.name === ITEM_TYPE_KEY);\n if (ids.size > 0 && typeField !== -1 && resource.fields[typeField]?.notInForm !== true) {\n issues.push({\n path: `${path}.fields.${typeField}`,\n message: `\\`${ITEM_TYPE_KEY}\\` holds the type of the item, set when it is created: its field must be \\`notInForm\\`.`,\n });\n }\n}\n\n/** The fields of a resource and of its types, with their paths. */\nfunction allFields(resource: ResourceInput, path: string): { field: Field; path: string }[] {\n return [\n ...resource.fields.map((field, index) => ({ field, path: `${path}.fields.${index}` })),\n ...(resource.types ?? []).flatMap((type, typeIndex) =>\n type.fields.map((field, index) => ({\n field,\n path: `${path}.types.${typeIndex}.fields.${index}`,\n })),\n ),\n ];\n}\n\nfunction checkResource(resource: ResourceInput, path: string, issues: ValidationIssue[]) {\n const names = fieldNames(resource.fields);\n if (names.size !== resource.fields.length) {\n issues.push({ path: `${path}.fields`, message: 'Field names must be unique.' });\n }\n checkTypes(resource, names, path, issues);\n if (resource.form?.layout !== undefined) {\n // The layout can name the fields of the types: the forms of the other types leave them out.\n const typeNames = (resource.types ?? []).flatMap((type) => [...fieldNames(type.fields)]);\n checkLayout(\n resource.form.layout,\n new Set([...names, ...typeNames]),\n `${path}.form.layout`,\n issues,\n );\n }\n (resource.list?.columns ?? []).forEach((column, index) => {\n if (column.field !== undefined && !names.has(column.field)) {\n issues.push({\n path: `${path}.list.columns.${index}.field`,\n message: `No field named \\`${column.field}\\`.`,\n });\n }\n });\n const calendar = resource.list?.calendar;\n if (calendar !== undefined) {\n const field = resource.fields.find((candidate) => candidate.name === calendar.field);\n const filter = calendar.filter ?? calendar.field;\n if (field === undefined) {\n issues.push({\n path: `${path}.list.calendar.field`,\n message: `No field named \\`${calendar.field}\\`.`,\n });\n } else if (!['date', 'datetime', 'daterange'].includes(field.type)) {\n issues.push({\n path: `${path}.list.calendar.field`,\n message: 'The field of a calendar must be a `date`, a `datetime` or a `daterange`.',\n });\n }\n if (\n !(resource.list?.filters ?? []).some(\n (candidate) => candidate.id === filter && candidate.type === 'date-range',\n )\n ) {\n issues.push({\n path: `${path}.list.calendar`,\n message: `The calendar needs a \\`date-range\\` filter \\`${filter}\\` in the list.`,\n });\n }\n }\n (resource.actions ?? []).forEach((action, index) => {\n if (action.layout !== undefined) {\n checkLayout(\n action.layout,\n fieldNames(action.fields ?? []),\n `${path}.actions.${index}.layout`,\n issues,\n );\n }\n });\n if (resource.kind === 'media') {\n const file = resource.fields.findIndex((field) => field.name === 'file');\n const field = resource.fields[file];\n if (field === undefined) {\n issues.push({\n path: `${path}.fields`,\n message: 'A resource of kind `media` needs a `file` field.',\n });\n } else if (field.type !== 'file' || field.multiple === true) {\n issues.push({\n path: `${path}.fields.${file}`,\n message: 'The `file` field of a `media` resource must be a single `file`.',\n });\n }\n }\n allFields(resource, path).forEach(({ field, path: fieldPath }) => {\n if (field.type === 'relation' && field.resource === undefined) {\n issues.push({\n path: `${fieldPath}.resource`,\n message: 'A `relation` field needs a `resource`.',\n });\n } else if (field.type === 'relation' && Array.isArray(field.resource)) {\n issues.push({\n path: `${fieldPath}.resource`,\n message: 'A `relation` field names one resource.',\n });\n }\n });\n}\n\n/**\n * Checks what the schema can't: references between parts of a definition (layout nodes and\n * columns that name existing fields, relations, `media` and `image` fields that name a resource,\n * unique names), the types of resources, and the `file` field of `media` resources.\n */\nexport function lintDefinition(definition: DefinitionInput): ValidationIssue[] {\n const issues: ValidationIssue[] = [];\n const resourceIds = new Set(definition.resources.map((resource) => resource.id));\n const libraries = definition.resources\n .filter((resource) => resource.kind === 'media')\n .map((resource) => resource.id);\n definition.resources.forEach((resource, index) => {\n checkResource(resource, `resources.${index}`, issues);\n allFields(resource, `resources.${index}`).forEach(({ field, path }) => {\n if (\n field.type === 'relation' &&\n typeof field.resource === 'string' &&\n !resourceIds.has(field.resource)\n ) {\n issues.push({\n path: `${path}.resource`,\n message: `No resource \\`${field.resource}\\`.`,\n });\n }\n if (field.type === 'media' || field.type === 'image') {\n const fieldPath = `${path}.resource`;\n if (field.resource === undefined) {\n // Every library of the definition (decision 0027).\n if (libraries.length === 0) {\n issues.push({\n path: fieldPath,\n message: `${field.type === 'image' ? 'An' : 'A'} \\`${field.type}\\` field needs a resource of kind \\`media\\`.`,\n });\n }\n } else {\n const named =\n typeof field.resource === 'string' ? [field.resource] : field.resource;\n named.forEach((id, idIndex) => {\n if (!libraries.includes(id)) {\n issues.push({\n path:\n typeof field.resource === 'string'\n ? fieldPath\n : `${fieldPath}.${String(idIndex)}`,\n message: `No resource of kind \\`media\\` named \\`${id}\\`.`,\n });\n }\n });\n }\n }\n });\n });\n checkWidgets(definition, issues);\n return issues;\n}\n\nconst FILTER_PARAM = /^filter\\[([^\\]]+)\\]/;\n\n/**\n * The widgets of the dashboard (decision 0064): unique ids, and the built-in `stat` and `list` on\n * a resource that exists, with filters of its list. A `stat` counts the items of the list, so the\n * list can't be paged with cursors, which give no total.\n */\nfunction checkWidgets(definition: DefinitionInput, issues: ValidationIssue[]) {\n const ids = new Set<string>();\n (definition.dashboard?.widgets ?? []).forEach((widget, index) => {\n const path = `dashboard.widgets.${index}`;\n if (ids.has(widget.id)) {\n issues.push({ path: `${path}.id`, message: `Duplicate widget id \\`${widget.id}\\`.` });\n }\n ids.add(widget.id);\n if (!isBuiltInWidgetType(widget.type)) {\n return;\n }\n const settings = widget.settings ?? {};\n const onResource = typeof settings.resource === 'string';\n if (!onResource) {\n if (settings.query !== undefined) {\n issues.push({\n path: `${path}.settings.query`,\n message: '`query` goes with a `resource`.',\n });\n }\n return;\n }\n if (!(RESOURCE_WIDGET_TYPES as readonly string[]).includes(widget.type)) {\n issues.push({\n path: `${path}.settings.resource`,\n message: `A \\`${widget.type}\\` widget has data of its own: only \\`stat\\` and \\`list\\` read a resource.`,\n });\n return;\n }\n const resource = definition.resources.find(\n (candidate) => candidate.id === settings.resource,\n );\n if (resource === undefined) {\n issues.push({\n path: `${path}.settings.resource`,\n message: `No resource \\`${String(settings.resource)}\\`.`,\n });\n return;\n }\n if (widget.type === 'stat' && resource.list?.pagination === 'cursor') {\n issues.push({\n path: `${path}.settings.resource`,\n message: `The list of \\`${resource.id}\\` is paged with cursors and has no total: it can't feed a \\`stat\\`.`,\n });\n }\n const filters = new Set((resource.list?.filters ?? []).map((filter) => filter.id));\n Object.keys(settings.query ?? {}).forEach((key) => {\n const filter = FILTER_PARAM.exec(key)?.[1];\n if ((WIDGET_RESERVED_QUERY_PARAMS as readonly string[]).includes(key)) {\n issues.push({\n path: `${path}.settings.query.${key}`,\n message: `The client sets \\`${key}\\`.`,\n });\n } else if (filter !== undefined && !filters.has(filter)) {\n issues.push({\n path: `${path}.settings.query.${key}`,\n message: `The list of \\`${resource.id}\\` has no filter \\`${filter}\\`.`,\n });\n }\n });\n });\n}\n"],"mappings":";;;AASA,SAAS,WAAW,QAA8B;CAC9C,OAAO,IAAI,IAAI,OAAO,KAAK,UAAU,MAAM,IAAI,CAAC;AACpD;AAEA,SAAS,YACL,OACA,OACA,MACA,QACF;CACE,MAAM,SAAS,MAAM,UAAU;EAC3B,MAAM,WAAW,GAAG,KAAK,GAAG;EAC5B,IAAI,KAAK,SAAS,SAAS;GACvB,IAAI,KAAK,SAAS,KAAA,GACd,OAAO,KAAK;IAAE,MAAM;IAAU,SAAS;GAAiC,CAAC;QACtE,IAAI,CAAC,MAAM,IAAI,KAAK,IAAI,GAC3B,OAAO,KAAK;IACR,MAAM,GAAG,SAAS;IAClB,SAAS,oBAAoB,KAAK,KAAK;GAC3C,CAAC;EAET;EACA,IAAI,KAAK,SAAS,eAAe,KAAK,cAAc,KAAA,GAChD,OAAO,KAAK;GAAE,MAAM;GAAU,SAAS;EAA0C,CAAC;EAEtF,IAAI,KAAK,SAAS,UAAU,KAAK,UAAU,MAAM,UAAU,MAAM,SAAS,KAAK,GAC3E,OAAO,KAAK;GACR,MAAM,GAAG,SAAS;GAClB,SAAS;EACb,CAAC;EAEL,IAAI,KAAK,aAAa,KAAA,GAClB,YAAY,KAAK,UAAU,OAAO,GAAG,SAAS,YAAY,MAAM;CAExE,CAAC;AACL;;;;;AAMA,SAAS,WACL,UACA,OACA,MACA,QACF;CACE,MAAM,sBAAM,IAAI,IAAY;CAC5B,CAAC,SAAS,SAAS,CAAC,EAAA,CAAG,SAAS,MAAM,UAAU;EAC5C,MAAM,WAAW,GAAG,KAAK,SAAS;EAClC,IAAI,IAAI,IAAI,KAAK,EAAE,GACf,OAAO,KAAK;GAAE,MAAM,GAAG,SAAS;GAAM,SAAS,uBAAuB,KAAK,GAAG;EAAK,CAAC;EAExF,IAAI,IAAI,KAAK,EAAE;EAEf,IADY,WAAW,KAAK,MACxB,C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