@panneau/protocol 5.0.0-alpha.1 → 5.0.0-alpha.10

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 (114) hide show
  1. package/README.md +10 -9
  2. package/dist/conditions.d.ts +1 -1
  3. package/dist/conformance/index.d.ts.map +1 -1
  4. package/dist/conformance/index.js +288 -9
  5. package/dist/conformance/index.js.map +1 -1
  6. package/dist/constants.d.ts +25 -2
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/constants.js +58 -3
  9. package/dist/constants.js.map +1 -1
  10. package/dist/index.d.ts +4 -4
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +12 -7
  13. package/dist/libraries.d.ts +16 -0
  14. package/dist/libraries.d.ts.map +1 -0
  15. package/dist/libraries.js +15 -0
  16. package/dist/libraries.js.map +1 -0
  17. package/dist/lint.d.ts +4 -3
  18. package/dist/lint.d.ts.map +1 -1
  19. package/dist/lint.js +34 -2
  20. package/dist/lint.js.map +1 -1
  21. package/dist/mock/example.d.ts +3 -2
  22. package/dist/mock/example.d.ts.map +1 -1
  23. package/dist/mock/example.js +223 -142
  24. package/dist/mock/example.js.map +1 -1
  25. package/dist/mock/index.d.ts +19 -5
  26. package/dist/mock/index.d.ts.map +1 -1
  27. package/dist/mock/index.js +378 -18
  28. package/dist/mock/index.js.map +1 -1
  29. package/dist/openapi.d.ts +2 -0
  30. package/dist/openapi.d.ts.map +1 -1
  31. package/dist/openapi.js +112 -108
  32. package/dist/openapi.js.map +1 -1
  33. package/dist/problem.d.ts +1 -1
  34. package/dist/query.d.ts +14 -0
  35. package/dist/query.d.ts.map +1 -1
  36. package/dist/query.js +11 -1
  37. package/dist/query.js.map +1 -1
  38. package/dist/rules.d.ts +6 -3
  39. package/dist/rules.d.ts.map +1 -1
  40. package/dist/rules.js +50 -8
  41. package/dist/rules.js.map +1 -1
  42. package/dist/runtime/index.d.ts +13 -9
  43. package/dist/runtime/index.d.ts.map +1 -1
  44. package/dist/runtime/index.js +7 -3
  45. package/dist/schemas/action.d.ts +69 -10
  46. package/dist/schemas/action.d.ts.map +1 -1
  47. package/dist/schemas/action.js +20 -3
  48. package/dist/schemas/action.js.map +1 -1
  49. package/dist/schemas/api.d.ts +224 -39
  50. package/dist/schemas/api.d.ts.map +1 -1
  51. package/dist/schemas/api.js +124 -30
  52. package/dist/schemas/api.js.map +1 -1
  53. package/dist/schemas/boot.d.ts +24 -1
  54. package/dist/schemas/boot.d.ts.map +1 -1
  55. package/dist/schemas/boot.js +2 -1
  56. package/dist/schemas/boot.js.map +1 -1
  57. package/dist/schemas/common.d.ts +1 -0
  58. package/dist/schemas/common.d.ts.map +1 -1
  59. package/dist/schemas/common.js +2 -1
  60. package/dist/schemas/common.js.map +1 -1
  61. package/dist/schemas/definition.d.ts +222 -20
  62. package/dist/schemas/definition.d.ts.map +1 -1
  63. package/dist/schemas/definition.js +16 -11
  64. package/dist/schemas/definition.js.map +1 -1
  65. package/dist/schemas/field.d.ts +162 -2
  66. package/dist/schemas/field.d.ts.map +1 -1
  67. package/dist/schemas/field.js +69 -16
  68. package/dist/schemas/field.js.map +1 -1
  69. package/dist/schemas/index.d.ts +955 -63
  70. package/dist/schemas/index.d.ts.map +1 -1
  71. package/dist/schemas/index.js +37 -8
  72. package/dist/schemas/index.js.map +1 -1
  73. package/dist/schemas/jsonRules.d.ts +83 -0
  74. package/dist/schemas/jsonRules.d.ts.map +1 -0
  75. package/dist/schemas/jsonRules.js +46 -0
  76. package/dist/schemas/jsonRules.js.map +1 -0
  77. package/dist/schemas/layout.d.ts +1 -1
  78. package/dist/schemas/list.d.ts +6 -0
  79. package/dist/schemas/list.d.ts.map +1 -1
  80. package/dist/schemas/list.js +1 -0
  81. package/dist/schemas/list.js.map +1 -1
  82. package/dist/schemas/resource.d.ts +144 -14
  83. package/dist/schemas/resource.d.ts.map +1 -1
  84. package/dist/schemas/resource.js +6 -1
  85. package/dist/schemas/resource.js.map +1 -1
  86. package/dist/schemas/theme.d.ts +179 -0
  87. package/dist/schemas/theme.d.ts.map +1 -0
  88. package/dist/schemas/theme.js +66 -0
  89. package/dist/schemas/theme.js.map +1 -0
  90. package/dist/search.d.ts +51 -0
  91. package/dist/search.d.ts.map +1 -0
  92. package/dist/search.js +53 -0
  93. package/dist/search.js.map +1 -0
  94. package/dist/themes.d.ts +11 -0
  95. package/dist/themes.d.ts.map +1 -0
  96. package/dist/themes.js +80 -0
  97. package/dist/themes.js.map +1 -0
  98. package/dist/transforms.d.ts +17 -0
  99. package/dist/transforms.d.ts.map +1 -0
  100. package/dist/transforms.js +34 -0
  101. package/dist/transforms.js.map +1 -0
  102. package/dist/validate.d.ts +4 -3
  103. package/dist/validate.d.ts.map +1 -1
  104. package/dist/validate.js +22 -2
  105. package/dist/validate.js.map +1 -1
  106. package/dist/values.d.ts +5 -1
  107. package/dist/values.d.ts.map +1 -1
  108. package/dist/values.js +16 -2
  109. package/dist/values.js.map +1 -1
  110. package/package.json +7 -3
  111. package/schema/boot.schema.json +580 -16
  112. package/schema/definition.schema.json +577 -16
  113. package/schema/openapi.json +1815 -541
  114. package/schema/theme.schema.json +234 -0
@@ -1,11 +1,30 @@
1
1
  /** Built-in action ids. */
2
2
  export declare const BUILT_IN_ACTIONS: readonly ["show", "edit", "duplicate", "delete", "restore", "export", "import"];
3
3
  export type BuiltInAction = (typeof BUILT_IN_ACTIONS)[number];
4
+ /**
5
+ * Built-in `link` actions (decision 0040). Without a `url` or a `route`, the client resolves them
6
+ * to its own routes, and labels them itself when they have no `label`.
7
+ */
8
+ export declare const BUILT_IN_LINK_ACTIONS: readonly ["show", "edit"];
9
+ export type BuiltInLinkAction = (typeof BUILT_IN_LINK_ACTIONS)[number];
10
+ /** Whether an action id is one of the built-in links, `show` and `edit`. */
11
+ export declare function isBuiltInLink(id: string): id is BuiltInLinkAction;
12
+ /**
13
+ * Built-in item actions, in their default order (decision 0040). Every resource has them without
14
+ * declaring them, and clients show each one on the items whose abilities allow it
15
+ * (`ITEM_ACTION_ABILITIES`). A resource's `itemActions` picks some of them, in its order.
16
+ */
17
+ export declare const BUILT_IN_ITEM_ACTIONS: readonly ["show", "edit", "duplicate", "delete"];
18
+ export type BuiltInItemAction = (typeof BUILT_IN_ITEM_ACTIONS)[number];
19
+ /** The ability of an item that each built-in item action needs: `true`, or the action is hidden. */
20
+ export declare const ITEM_ACTION_ABILITIES: Readonly<Record<BuiltInItemAction, string>>;
21
+ /** Whether an action id is one of the built-in item actions. */
22
+ export declare function isBuiltInItemAction(id: string): id is BuiltInItemAction;
4
23
  /** Field types every Panneau frontend renders. Plugins add others. */
5
- export declare const BUILT_IN_FIELD_TYPES: readonly ["text", "textarea", "richtext", "number", "boolean", "date", "datetime", "time", "select", "email", "url", "color", "media", "relation", "group", "repeater", "slug"];
24
+ export declare const BUILT_IN_FIELD_TYPES: readonly ["text", "textarea", "richtext", "number", "boolean", "date", "datetime", "time", "select", "email", "url", "color", "media", "image", "relation", "group", "repeater", "slug", "tel", "range", "duration", "json", "tags", "embed", "location"];
6
25
  export type BuiltInFieldType = (typeof BUILT_IN_FIELD_TYPES)[number];
7
26
  /** Validation rules that both frontends and backends check. */
8
- export declare const PORTABLE_RULES: readonly ["required", "min", "max", "pattern", "email", "url", "in", "accept", "maxSize", "before", "after"];
27
+ export declare const PORTABLE_RULES: readonly ["required", "min", "max", "pattern", "email", "url", "json", "in", "accept", "maxSize", "before", "after", "crop"];
9
28
  export type PortableRule = (typeof PORTABLE_RULES)[number];
10
29
  /** Layout node types every Panneau frontend renders. */
11
30
  export declare const BUILT_IN_LAYOUT_NODE_TYPES: readonly ["row", "column", "section", "tabs", "tab", "sidebar", "field", "text", "component"];
@@ -18,4 +37,8 @@ export type BuiltInListLayout = (typeof BUILT_IN_LIST_LAYOUTS)[number];
18
37
  * `<script type="application/json" id="panneau-boot">` element whose text is the JSON object.
19
38
  */
20
39
  export declare const BOOT_CONFIG_ELEMENT_ID = "panneau-boot";
40
+ /** The elements a block style of a `richtext` field can apply to. */
41
+ export declare const RICH_TEXT_STYLE_ELEMENTS: readonly ["p", "h1", "h2", "h3", "h4", "h5", "h6", "blockquote", "ul", "ol", "li"];
42
+ /** An element a block style of a `richtext` field can apply to. */
43
+ export type RichTextStyleElement = (typeof RICH_TEXT_STYLE_ELEMENTS)[number];
21
44
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAGA,2BAA2B;AAC3B,eAAO,MAAM,gBAAgB,iFAQnB,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9D,sEAAsE;AACtE,eAAO,MAAM,oBAAoB,iLAkBvB,CAAC;AACX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,+DAA+D;AAC/D,eAAO,MAAM,cAAc,8GAYjB,CAAC;AACX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3D,wDAAwD;AACxD,eAAO,MAAM,0BAA0B,+FAU7B,CAAC;AACX,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhF,uEAAuE;AACvE,eAAO,MAAM,qBAAqB,oDAAqD,CAAC;AACxF,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEvE;;;GAGG;AACH,eAAO,MAAM,sBAAsB,iBAAiB,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAGA,2BAA2B;AAC3B,eAAO,MAAM,gBAAgB,iFAQnB,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MA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AAwB,oFAY3B,CAAC;AAEX,mEAAmE;AACnE,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC"}
package/dist/constants.js CHANGED
@@ -9,6 +9,37 @@ var BUILT_IN_ACTIONS = [
9
9
  "export",
10
10
  "import"
11
11
  ];
12
+ /**
13
+ * Built-in `link` actions (decision 0040). Without a `url` or a `route`, the client resolves them
14
+ * to its own routes, and labels them itself when they have no `label`.
15
+ */
16
+ var BUILT_IN_LINK_ACTIONS = ["show", "edit"];
17
+ /** Whether an action id is one of the built-in links, `show` and `edit`. */
18
+ function isBuiltInLink(id) {
19
+ return BUILT_IN_LINK_ACTIONS.includes(id);
20
+ }
21
+ /**
22
+ * Built-in item actions, in their default order (decision 0040). Every resource has them without
23
+ * declaring them, and clients show each one on the items whose abilities allow it
24
+ * (`ITEM_ACTION_ABILITIES`). A resource's `itemActions` picks some of them, in its order.
25
+ */
26
+ var BUILT_IN_ITEM_ACTIONS = [
27
+ "show",
28
+ "edit",
29
+ "duplicate",
30
+ "delete"
31
+ ];
32
+ /** The ability of an item that each built-in item action needs: `true`, or the action is hidden. */
33
+ var ITEM_ACTION_ABILITIES = {
34
+ show: "view",
35
+ edit: "update",
36
+ duplicate: "duplicate",
37
+ delete: "delete"
38
+ };
39
+ /** Whether an action id is one of the built-in item actions. */
40
+ function isBuiltInItemAction(id) {
41
+ return BUILT_IN_ITEM_ACTIONS.includes(id);
42
+ }
12
43
  /** Field types every Panneau frontend renders. Plugins add others. */
13
44
  var BUILT_IN_FIELD_TYPES = [
14
45
  "text",
@@ -24,10 +55,18 @@ var BUILT_IN_FIELD_TYPES = [
24
55
  "url",
25
56
  "color",
26
57
  "media",
58
+ "image",
27
59
  "relation",
28
60
  "group",
29
61
  "repeater",
30
- "slug"
62
+ "slug",
63
+ "tel",
64
+ "range",
65
+ "duration",
66
+ "json",
67
+ "tags",
68
+ "embed",
69
+ "location"
31
70
  ];
32
71
  /** Validation rules that both frontends and backends check. */
33
72
  var PORTABLE_RULES = [
@@ -37,11 +76,13 @@ var PORTABLE_RULES = [
37
76
  "pattern",
38
77
  "email",
39
78
  "url",
79
+ "json",
40
80
  "in",
41
81
  "accept",
42
82
  "maxSize",
43
83
  "before",
44
- "after"
84
+ "after",
85
+ "crop"
45
86
  ];
46
87
  /** Layout node types every Panneau frontend renders. */
47
88
  var BUILT_IN_LAYOUT_NODE_TYPES = [
@@ -67,7 +108,21 @@ var BUILT_IN_LIST_LAYOUTS = [
67
108
  * `<script type="application/json" id="panneau-boot">` element whose text is the JSON object.
68
109
  */
69
110
  var BOOT_CONFIG_ELEMENT_ID = "panneau-boot";
111
+ /** The elements a block style of a `richtext` field can apply to. */
112
+ var RICH_TEXT_STYLE_ELEMENTS = [
113
+ "p",
114
+ "h1",
115
+ "h2",
116
+ "h3",
117
+ "h4",
118
+ "h5",
119
+ "h6",
120
+ "blockquote",
121
+ "ul",
122
+ "ol",
123
+ "li"
124
+ ];
70
125
  //#endregion
71
- export { BOOT_CONFIG_ELEMENT_ID, BUILT_IN_ACTIONS, BUILT_IN_FIELD_TYPES, BUILT_IN_LAYOUT_NODE_TYPES, BUILT_IN_LIST_LAYOUTS, PORTABLE_RULES };
126
+ export { 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_LIST_LAYOUTS, ITEM_ACTION_ABILITIES, PORTABLE_RULES, RICH_TEXT_STYLE_ELEMENTS, isBuiltInItemAction, isBuiltInLink };
72
127
 
73
128
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["// Constants of the protocol. This module doesn't import zod, so that the main entry point stays\n// light: see `src/index.ts`.\n\n/** Built-in action ids. */\nexport const BUILT_IN_ACTIONS = [\n 'show',\n 'edit',\n 'duplicate',\n 'delete',\n 'restore',\n 'export',\n 'import',\n] as const;\nexport type BuiltInAction = (typeof BUILT_IN_ACTIONS)[number];\n\n/** Field types every Panneau frontend renders. Plugins add others. */\nexport const BUILT_IN_FIELD_TYPES = [\n 'text',\n 'textarea',\n 'richtext',\n 'number',\n 'boolean',\n 'date',\n 'datetime',\n 'time',\n 'select',\n 'email',\n 'url',\n 'color',\n 'media',\n 'relation',\n 'group',\n 'repeater',\n 'slug',\n] as const;\nexport type BuiltInFieldType = (typeof BUILT_IN_FIELD_TYPES)[number];\n\n/** Validation rules that both frontends and backends check. */\nexport const PORTABLE_RULES = [\n 'required',\n 'min',\n 'max',\n 'pattern',\n 'email',\n 'url',\n 'in',\n 'accept',\n 'maxSize',\n 'before',\n 'after',\n] as const;\nexport type PortableRule = (typeof PORTABLE_RULES)[number];\n\n/** Layout node types every Panneau frontend renders. */\nexport const BUILT_IN_LAYOUT_NODE_TYPES = [\n 'row',\n 'column',\n 'section',\n 'tabs',\n 'tab',\n 'sidebar',\n 'field',\n 'text',\n 'component',\n] as const;\nexport type BuiltInLayoutNodeType = (typeof BUILT_IN_LAYOUT_NODE_TYPES)[number];\n\n/** List layouts every Panneau frontend renders. Plugins add others. */\nexport const BUILT_IN_LIST_LAYOUTS = ['table', 'cards', 'gallery', 'calendar'] as const;\nexport type BuiltInListLayout = (typeof BUILT_IN_LIST_LAYOUTS)[number];\n\n/**\n * Id of the element that holds the boot config in the page: a\n * `<script type=\"application/json\" id=\"panneau-boot\">` element whose text is the JSON object.\n */\nexport const BOOT_CONFIG_ELEMENT_ID = 'panneau-boot';\n"],"mappings":";;AAIA,IAAa,mBAAmB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,uBAAuB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,iBAAiB;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,6BAA6B;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,wBAAwB;CAAC;CAAS;CAAS;CAAW;AAAU;;;;;AAO7E,IAAa,yBAAyB"}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["// Constants of the protocol. This module doesn't import zod, so that the main entry point stays\n// light: see `src/index.ts`.\n\n/** Built-in action ids. */\nexport const BUILT_IN_ACTIONS = [\n 'show',\n 'edit',\n 'duplicate',\n 'delete',\n 'restore',\n 'export',\n 'import',\n] as const;\nexport type BuiltInAction = (typeof BUILT_IN_ACTIONS)[number];\n\n/**\n * Built-in `link` actions (decision 0040). Without a `url` or a `route`, the client resolves them\n * to its own routes, and labels them itself when they have no `label`.\n */\nexport const BUILT_IN_LINK_ACTIONS = ['show', 'edit'] as const;\nexport type BuiltInLinkAction = (typeof BUILT_IN_LINK_ACTIONS)[number];\n\n/** Whether an action id is one of the built-in links, `show` and `edit`. */\nexport function isBuiltInLink(id: string): id is BuiltInLinkAction {\n return (BUILT_IN_LINK_ACTIONS as readonly string[]).includes(id);\n}\n\n/**\n * Built-in item actions, in their default order (decision 0040). Every resource has them without\n * declaring them, and clients show each one on the items whose abilities allow it\n * (`ITEM_ACTION_ABILITIES`). A resource's `itemActions` picks some of them, in its order.\n */\nexport const BUILT_IN_ITEM_ACTIONS = ['show', 'edit', 'duplicate', 'delete'] as const;\nexport type BuiltInItemAction = (typeof BUILT_IN_ITEM_ACTIONS)[number];\n\n/** The ability of an item that each built-in item action needs: `true`, or the action is hidden. */\nexport const ITEM_ACTION_ABILITIES: Readonly<Record<BuiltInItemAction, string>> = {\n show: 'view',\n edit: 'update',\n duplicate: 'duplicate',\n delete: 'delete',\n};\n\n/** Whether an action id is one of the built-in item actions. */\nexport function isBuiltInItemAction(id: string): id is BuiltInItemAction {\n return (BUILT_IN_ITEM_ACTIONS as readonly string[]).includes(id);\n}\n\n/** Field types every Panneau frontend renders. Plugins add others. */\nexport const BUILT_IN_FIELD_TYPES = [\n 'text',\n 'textarea',\n 'richtext',\n 'number',\n 'boolean',\n 'date',\n 'datetime',\n 'time',\n 'select',\n 'email',\n 'url',\n 'color',\n 'media',\n 'image',\n 'relation',\n 'group',\n 'repeater',\n 'slug',\n 'tel',\n 'range',\n 'duration',\n 'json',\n 'tags',\n 'embed',\n 'location',\n] as const;\nexport type BuiltInFieldType = (typeof BUILT_IN_FIELD_TYPES)[number];\n\n/** Validation rules that both frontends and backends check. */\nexport const PORTABLE_RULES = [\n 'required',\n 'min',\n 'max',\n 'pattern',\n 'email',\n 'url',\n 'json',\n 'in',\n 'accept',\n 'maxSize',\n 'before',\n 'after',\n 'crop',\n] as const;\nexport type PortableRule = (typeof PORTABLE_RULES)[number];\n\n/** Layout node types every Panneau frontend renders. */\nexport const BUILT_IN_LAYOUT_NODE_TYPES = [\n 'row',\n 'column',\n 'section',\n 'tabs',\n 'tab',\n 'sidebar',\n 'field',\n 'text',\n 'component',\n] as const;\nexport type BuiltInLayoutNodeType = (typeof BUILT_IN_LAYOUT_NODE_TYPES)[number];\n\n/** List layouts every Panneau frontend renders. Plugins add others. */\nexport const BUILT_IN_LIST_LAYOUTS = ['table', 'cards', 'gallery', 'calendar'] as const;\nexport type BuiltInListLayout = (typeof BUILT_IN_LIST_LAYOUTS)[number];\n\n/**\n * Id of the element that holds the boot config in the page: a\n * `<script type=\"application/json\" id=\"panneau-boot\">` element whose text is the JSON object.\n */\nexport const BOOT_CONFIG_ELEMENT_ID = 'panneau-boot';\n\n/** The elements a block style of a `richtext` field can apply to. */\nexport const RICH_TEXT_STYLE_ELEMENTS = [\n 'p',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'blockquote',\n 'ul',\n 'ol',\n 'li',\n] as const;\n\n/** An element a block style of a `richtext` field can apply to. */\nexport type RichTextStyleElement = (typeof RICH_TEXT_STYLE_ELEMENTS)[number];\n"],"mappings":";;AAIA,IAAa,mBAAmB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;;;;AAOA,IAAa,wBAAwB,CAAC,QAAQ,MAAM;;AAIpD,SAAgB,cAAc,IAAqC;CAC/D,OAAQ,sBAA4C,SAAS,EAAE;AACnE;;;;;;AAOA,IAAa,wBAAwB;CAAC;CAAQ;CAAQ;CAAa;AAAQ;;AAI3E,IAAa,wBAAqE;CAC9E,MAAM;CACN,MAAM;CACN,WAAW;CACX,QAAQ;AACZ;;AAGA,SAAgB,oBAAoB,IAAqC;CACrE,OAAQ,sBAA4C,SAAS,EAAE;AACnE;;AAGA,IAAa,uBAAuB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,iBAAiB;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,6BAA6B;CACtC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAIA,IAAa,wBAAwB;CAAC;CAAS;CAAS;CAAW;AAAU;;;;;AAO7E,IAAa,yBAAyB;;AAGtC,IAAa,2BAA2B;CACpC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ"}
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, } 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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,OAAO,EACH,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,QAAQ,EACR,kBAAkB,EAClB,kBAAkB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EACH,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,EAC1B,qBAAqB,GACxB,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,OAAO,EACH,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,QAAQ,EACR,kBAAkB,EAClB,kBAAkB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EACH,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,EAC1B,qBAAqB,EACrB,qBAAqB,GACxB,MAAM,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,21 +1,26 @@
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 { 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_LIST_LAYOUTS, ITEM_ACTION_ABILITIES, PORTABLE_RULES, RICH_TEXT_STYLE_ELEMENTS, isBuiltInItemAction, isBuiltInLink } from "./constants.js";
3
3
  import { getValue, isFilled } from "./values.js";
4
4
  import { evaluateCondition } from "./conditions.js";
5
+ import { matchesRatio, parseRatio, renderedCropSize } from "./transforms.js";
5
6
  import { checkRules, checkValues } from "./rules.js";
7
+ import { getMediaLibraries } from "./libraries.js";
6
8
  import { lintDefinition } from "./lint.js";
7
- import { fromSearchParams, isFilterRange, matchesFilterRange, toSearchParams } from "./query.js";
9
+ import { fromSearchParams, isCursorPage, isFilterRange, matchesFilterRange, toSearchParams } from "./query.js";
10
+ import { SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, isSearchableResource, readSearchQuery, toSearchQueryParams } from "./search.js";
8
11
  import { isProblem } from "./problem.js";
12
+ import { mergeThemes } from "./themes.js";
9
13
  import { Abilities, Condition, Id, Option, RouteReference } from "./schemas/common.js";
10
- import { BlockType, Field, Rule } from "./schemas/field.js";
14
+ import { BlockType, Field, RichTextSettings, RichTextStyle, Rule } from "./schemas/field.js";
11
15
  import { LayoutNode } from "./schemas/layout.js";
12
16
  import { Action, ActionConfirm, ActionPlacement, ActionScope } from "./schemas/action.js";
13
17
  import { Column, Filter, ListDefinition } from "./schemas/list.js";
14
18
  import { Resource, ResourceFeatures } from "./schemas/resource.js";
15
- import { Auth, AuthProvider, Definition, MenuItem, Page, Uploads, User, Widget } from "./schemas/definition.js";
16
- import { ActionItemResult, ActionRequest, ActionResult, ActionRun, ActionRunResponse, Item, ItemResponse, ListResponse, Media, MediaListResponse, MediaResponse, MediaTransform, Pagination, PreviewResponse, Problem, SearchResponse, Selection, Session } from "./schemas/api.js";
19
+ import { DefinitionTheme, Theme, ThemeFont, ThemeFontFace, ThemeFontStylesheet, ThemeTokens, ToneInput, ToneValues } from "./schemas/theme.js";
20
+ import { Auth, AuthProvider, AuthToken, Definition, MenuItem, Page, Uploads, User, Widget } from "./schemas/definition.js";
21
+ import { ActionItemResult, ActionRequest, ActionResult, ActionRun, ActionRunResponse, CursorPagination, EmbedResponse, EmbedValue, FieldCheckRequest, FieldCheckResponse, Item, ItemResponse, ListResponse, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, Pagination, PreviewResponse, Problem, SearchResponse, Selection, Session, StoredFile, Upload, UploadReference, UploadResponse, UploadSignRequest, UploadSignResponse } from "./schemas/api.js";
17
22
  import { BootConfig } from "./schemas/boot.js";
18
23
  import { createSchemaRegistry, namedSchemas } from "./schemas/index.js";
19
24
  import { validate, validateBootConfig, validateDefinition } from "./validate.js";
20
- import { createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument } from "./openapi.js";
21
- 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, 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, Uploads, User, Widget, checkRules, checkValues, createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createSchemaRegistry, evaluateCondition, fromSearchParams, getValue, isFilled, isFilterRange, isProblem, lintDefinition, matchesFilterRange, namedSchemas, toSearchParams, validate, validateBootConfig, validateDefinition };
25
+ import { createBootConfigJsonSchema, createComponentSchemas, createDefinitionJsonSchema, createOpenApiDocument, createThemeJsonSchema } from "./openapi.js";
26
+ export { Abilities, Action, ActionConfirm, ActionItemResult, ActionPlacement, ActionRequest, ActionResult, ActionRun, ActionRunResponse, ActionScope, 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_LIST_LAYOUTS, BlockType, BootConfig, Column, Condition, CursorPagination, Definition, DefinitionTheme, EmbedResponse, EmbedValue, Field, FieldCheckRequest, FieldCheckResponse, Filter, ITEM_ACTION_ABILITIES, Id, Item, ItemResponse, LayoutNode, ListDefinition, ListResponse, LocationValue, MediaInfo, MediaItem, MediaReference, MediaTransform, MenuItem, Option, PORTABLE_RULES, PROBLEM_CONTENT_TYPE, PROTOCOL_VERSION, Page, Pagination, PreviewResponse, Problem, RICH_TEXT_STYLE_ELEMENTS, Resource, ResourceFeatures, RichTextSettings, RichTextStyle, RouteReference, Rule, SEARCH_DEFAULT_LIMIT, SEARCH_MAX_LENGTH, SEARCH_MAX_LIMIT, SEARCH_MIN_LENGTH, 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, getMediaLibraries, getValue, isBuiltInItemAction, isBuiltInLink, isCursorPage, isFilled, isFilterRange, isProblem, isSearchableResource, lintDefinition, matchesFilterRange, matchesRatio, mergeThemes, namedSchemas, parseRatio, readSearchQuery, renderedCropSize, toSearchParams, toSearchQueryParams, validate, validateBootConfig, validateDefinition };
@@ -0,0 +1,16 @@
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
+ //# 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"}
@@ -0,0 +1,15 @@
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
+ //#endregion
13
+ export { getMediaLibraries };
14
+
15
+ //# 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"],"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"}
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), 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":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAoC,MAAM,WAAW,CAAC;AACnF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA+FlD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,eAAe,GAAG,eAAe,EAAE,CAgD7E"}
package/dist/lint.js CHANGED
@@ -42,27 +42,59 @@ function checkResource(resource, path, issues) {
42
42
  (resource.actions ?? []).forEach((action, index) => {
43
43
  if (action.layout !== void 0) checkLayout(action.layout, fieldNames(action.fields ?? []), `${path}.actions.${index}.layout`, issues);
44
44
  });
45
+ if (resource.kind === "media") {
46
+ const file = resource.fields.findIndex((field) => field.name === "file");
47
+ const field = resource.fields[file];
48
+ if (field === void 0) issues.push({
49
+ path: `${path}.fields`,
50
+ message: "A resource of kind `media` needs a `file` field."
51
+ });
52
+ else if (field.type !== "file" || field.multiple === true) issues.push({
53
+ path: `${path}.fields.${file}`,
54
+ message: "The `file` field of a `media` resource must be a single `file`."
55
+ });
56
+ }
45
57
  resource.fields.forEach((field, index) => {
46
58
  if (field.type === "relation" && field.resource === void 0) issues.push({
47
59
  path: `${path}.fields.${index}.resource`,
48
60
  message: "A `relation` field needs a `resource`."
49
61
  });
62
+ else if (field.type === "relation" && Array.isArray(field.resource)) issues.push({
63
+ path: `${path}.fields.${index}.resource`,
64
+ message: "A `relation` field names one resource."
65
+ });
50
66
  });
51
67
  }
52
68
  /**
53
69
  * 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).
70
+ * columns that name existing fields, relations, `media` and `image` fields that name a resource,
71
+ * unique names), and the `file` field of `media` resources.
55
72
  */
56
73
  function lintDefinition(definition) {
57
74
  const issues = [];
58
75
  const resourceIds = new Set(definition.resources.map((resource) => resource.id));
76
+ const libraries = definition.resources.filter((resource) => resource.kind === "media").map((resource) => resource.id);
59
77
  definition.resources.forEach((resource, index) => {
60
78
  checkResource(resource, `resources.${index}`, issues);
61
79
  resource.fields.forEach((field, fieldIndex) => {
62
- if (field.type === "relation" && field.resource !== void 0 && !resourceIds.has(field.resource)) issues.push({
80
+ if (field.type === "relation" && typeof field.resource === "string" && !resourceIds.has(field.resource)) issues.push({
63
81
  path: `resources.${index}.fields.${fieldIndex}.resource`,
64
82
  message: `No resource \`${field.resource}\`.`
65
83
  });
84
+ if (field.type === "media" || field.type === "image") {
85
+ const fieldPath = `resources.${index}.fields.${fieldIndex}.resource`;
86
+ if (field.resource === void 0) {
87
+ if (libraries.length === 0) issues.push({
88
+ path: fieldPath,
89
+ message: `${field.type === "image" ? "An" : "A"} \`${field.type}\` field needs a resource of kind \`media\`.`
90
+ });
91
+ } else (typeof field.resource === "string" ? [field.resource] : field.resource).forEach((id, idIndex) => {
92
+ if (!libraries.includes(id)) issues.push({
93
+ path: typeof field.resource === "string" ? fieldPath : `${fieldPath}.${String(idIndex)}`,
94
+ message: `No resource of kind \`media\` named \`${id}\`.`
95
+ });
96
+ });
97
+ }
66
98
  });
67
99
  });
68
100
  return issues;
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;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;AAEA,SAAS,cAAc,UAAyB,MAAc,QAA2B;CACrF,MAAM,QAAQ,WAAW,SAAS,MAAM;CACxC,IAAI,MAAM,SAAS,SAAS,OAAO,QAC/B,OAAO,KAAK;EAAE,MAAM,GAAG,KAAK;EAAU,SAAS;CAA8B,CAAC;CAElF,IAAI,SAAS,MAAM,WAAW,KAAA,GAC1B,YAAY,SAAS,KAAK,QAAQ,OAAO,GAAG,KAAK,eAAe,MAAM;CAE1E,CAAC,SAAS,MAAM,WAAW,CAAC,EAAA,CAAG,SAAS,QAAQ,UAAU;EACtD,IAAI,OAAO,UAAU,KAAA,KAAa,CAAC,MAAM,IAAI,OAAO,KAAK,GACrD,OAAO,KAAK;GACR,MAAM,GAAG,KAAK,gBAAgB,MAAM;GACpC,SAAS,oBAAoB,OAAO,MAAM;EAC9C,CAAC;CAET,CAAC;CACD,CAAC,SAAS,WAAW,CAAC,EAAA,CAAG,SAAS,QAAQ,UAAU;EAChD,IAAI,OAAO,WAAW,KAAA,GAClB,YACI,OAAO,QACP,WAAW,OAAO,UAAU,CAAC,CAAC,GAC9B,GAAG,KAAK,WAAW,MAAM,UACzB,MACJ;CAER,CAAC;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 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 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 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 } else if (field.type === 'relation' && Array.isArray(field.resource)) {\n issues.push({\n path: `${path}.fields.${index}.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), 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 resource.fields.forEach((field, fieldIndex) => {\n if (\n field.type === 'relation' &&\n typeof field.resource === 'string' &&\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 if (field.type === 'media' || field.type === 'image') {\n const fieldPath = `resources.${index}.fields.${fieldIndex}.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 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,Q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,MAAM,aAAa,MAAM,UAAU,WAAW;IAC9C,SAAS,iBAAiB,MAAM,SAAS;GAC7C,CAAC;GAEL,IAAI,MAAM,SAAS,WAAW,MAAM,SAAS,SAAS;IAClD,MAAM,YAAY,aAAa,MAAM,UAAU,WAAW;IAC1D,IAAI,MAAM,aAAa,KAAA,GAEf;SAAA,UAAU,WAAW,GACrB,OAAO,KAAK;MACR,MAAM;MACN,SAAS,GAAG,MAAM,SAAS,UAAU,OAAO,IAAI,KAAK,MAAM,KAAK;KACpE,CAAC;IAAA,OAKL,CADI,OAAO,MAAM,aAAa,WAAW,CAAC,MAAM,QAAQ,IAAI,MAAM,SAAA,CAC5D,SAAS,IAAI,YAAY;KAC3B,IAAI,CAAC,UAAU,SAAS,EAAE,GACtB,OAAO,KAAK;MACR,MACI,OAAO,MAAM,aAAa,WACpB,YACA,GAAG,UAAU,GAAG,OAAO,OAAO;MACxC,SAAS,yCAAyC,GAAG;KACzD,CAAC;IAET,CAAC;GAET;EACJ,CAAC;CACL,CAAC;CACD,OAAO;AACX"}
@@ -1,7 +1,8 @@
1
- import type { DefinitionInput } from '../schemas';
1
+ import type { DefinitionInput } from '../schemas/index.js';
2
2
  /**
3
3
  * A small but complete definition: pages with localized titles, a status, a publication date shown
4
- * for published pages, an author and typed blocks, in tabs and a sidebar, plus authors. For tests
4
+ * for published pages, an author, an attachment and typed blocks, in tabs and a sidebar, plus
5
+ * authors with a photo, and a media library. For tests
5
6
  * and stories, with `createMockBackend()`.
6
7
  */
7
8
  export declare function createExampleDefinition(): DefinitionInput;
@@ -1 +1 @@
1
- {"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../../src/mock/example.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,eAAe,CA0IzD"}
1
+ {"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../../src/mock/example.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;GAKG;AACH,wBAAgB,uBAAuB,IAAI,eAAe,CA+LzD"}