@strapi/core 0.0.0-experimental.1e4c115f717b021ca11c139584d4519db28ba786 → 0.0.0-experimental.1f56e9319665c8cc385eb5e4178ceb6741c6d490

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.

Potentially problematic release.


This version of @strapi/core might be problematic. Click here for more details.

Files changed (230) hide show
  1. package/dist/Strapi.d.ts +1 -0
  2. package/dist/Strapi.d.ts.map +1 -1
  3. package/dist/Strapi.js +23 -2
  4. package/dist/Strapi.js.map +1 -1
  5. package/dist/Strapi.mjs +23 -2
  6. package/dist/Strapi.mjs.map +1 -1
  7. package/dist/constants.d.ts +3 -0
  8. package/dist/constants.d.ts.map +1 -0
  9. package/dist/constants.js +6 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/constants.mjs +4 -0
  12. package/dist/constants.mjs.map +1 -0
  13. package/dist/core-api/controller/index.d.ts.map +1 -1
  14. package/dist/core-api/controller/index.js +2 -1
  15. package/dist/core-api/controller/index.js.map +1 -1
  16. package/dist/core-api/controller/index.mjs +2 -1
  17. package/dist/core-api/controller/index.mjs.map +1 -1
  18. package/dist/core-api/controller/transform.d.ts +3 -2
  19. package/dist/core-api/controller/transform.d.ts.map +1 -1
  20. package/dist/core-api/controller/transform.js +13 -3
  21. package/dist/core-api/controller/transform.js.map +1 -1
  22. package/dist/core-api/controller/transform.mjs +13 -3
  23. package/dist/core-api/controller/transform.mjs.map +1 -1
  24. package/dist/core-api/routes/index.d.ts.map +1 -1
  25. package/dist/core-api/routes/index.js +28 -9
  26. package/dist/core-api/routes/index.js.map +1 -1
  27. package/dist/core-api/routes/index.mjs +1 -1
  28. package/dist/core-api/routes/index.mjs.map +1 -1
  29. package/dist/core-api/routes/validation/attributes.d.ts +243 -90
  30. package/dist/core-api/routes/validation/attributes.d.ts.map +1 -1
  31. package/dist/core-api/routes/validation/attributes.js +541 -564
  32. package/dist/core-api/routes/validation/attributes.js.map +1 -1
  33. package/dist/core-api/routes/validation/attributes.mjs +505 -564
  34. package/dist/core-api/routes/validation/attributes.mjs.map +1 -1
  35. package/dist/core-api/routes/validation/common.d.ts +7 -5
  36. package/dist/core-api/routes/validation/common.d.ts.map +1 -1
  37. package/dist/core-api/routes/validation/common.js +29 -8
  38. package/dist/core-api/routes/validation/common.js.map +1 -1
  39. package/dist/core-api/routes/validation/common.mjs +6 -4
  40. package/dist/core-api/routes/validation/common.mjs.map +1 -1
  41. package/dist/core-api/routes/validation/component.d.ts +2 -10
  42. package/dist/core-api/routes/validation/component.d.ts.map +1 -1
  43. package/dist/core-api/routes/validation/component.js +3 -17
  44. package/dist/core-api/routes/validation/component.js.map +1 -1
  45. package/dist/core-api/routes/validation/component.mjs +3 -17
  46. package/dist/core-api/routes/validation/component.mjs.map +1 -1
  47. package/dist/core-api/routes/validation/constants.d.ts +6 -0
  48. package/dist/core-api/routes/validation/constants.d.ts.map +1 -1
  49. package/dist/core-api/routes/validation/constants.js +6 -1
  50. package/dist/core-api/routes/validation/constants.js.map +1 -1
  51. package/dist/core-api/routes/validation/constants.mjs +6 -1
  52. package/dist/core-api/routes/validation/constants.mjs.map +1 -1
  53. package/dist/core-api/routes/validation/content-type.d.ts +28 -71
  54. package/dist/core-api/routes/validation/content-type.d.ts.map +1 -1
  55. package/dist/core-api/routes/validation/content-type.js +67 -112
  56. package/dist/core-api/routes/validation/content-type.js.map +1 -1
  57. package/dist/core-api/routes/validation/content-type.mjs +36 -100
  58. package/dist/core-api/routes/validation/content-type.mjs.map +1 -1
  59. package/dist/core-api/routes/validation/index.d.ts +1 -1
  60. package/dist/core-api/routes/validation/index.d.ts.map +1 -1
  61. package/dist/core-api/routes/validation/mappers.d.ts +105 -0
  62. package/dist/core-api/routes/validation/mappers.d.ts.map +1 -0
  63. package/dist/core-api/routes/validation/mappers.js +273 -0
  64. package/dist/core-api/routes/validation/mappers.js.map +1 -0
  65. package/dist/core-api/routes/validation/mappers.mjs +249 -0
  66. package/dist/core-api/routes/validation/mappers.mjs.map +1 -0
  67. package/dist/core-api/routes/validation/utils.d.ts +47 -0
  68. package/dist/core-api/routes/validation/utils.d.ts.map +1 -0
  69. package/dist/core-api/routes/validation/utils.js +128 -0
  70. package/dist/core-api/routes/validation/utils.js.map +1 -0
  71. package/dist/core-api/routes/validation/utils.mjs +106 -0
  72. package/dist/core-api/routes/validation/utils.mjs.map +1 -0
  73. package/dist/domain/content-type/index.d.ts.map +1 -1
  74. package/dist/domain/content-type/index.js +17 -1
  75. package/dist/domain/content-type/index.js.map +1 -1
  76. package/dist/domain/content-type/index.mjs +17 -1
  77. package/dist/domain/content-type/index.mjs.map +1 -1
  78. package/dist/ee/index.d.ts +6 -0
  79. package/dist/ee/index.d.ts.map +1 -1
  80. package/dist/ee/index.js +29 -3
  81. package/dist/ee/index.js.map +1 -1
  82. package/dist/ee/index.mjs +30 -4
  83. package/dist/ee/index.mjs.map +1 -1
  84. package/dist/ee/license.d.ts +3 -1
  85. package/dist/ee/license.d.ts.map +1 -1
  86. package/dist/ee/license.js +6 -1
  87. package/dist/ee/license.js.map +1 -1
  88. package/dist/ee/license.mjs +6 -2
  89. package/dist/ee/license.mjs.map +1 -1
  90. package/dist/factories.js +1 -1
  91. package/dist/factories.mjs +1 -1
  92. package/dist/index.js +1 -1
  93. package/dist/index.mjs +1 -1
  94. package/dist/loaders/plugins/index.js +1 -1
  95. package/dist/loaders/plugins/index.js.map +1 -1
  96. package/dist/loaders/plugins/index.mjs +1 -1
  97. package/dist/loaders/plugins/index.mjs.map +1 -1
  98. package/dist/middlewares/cors.d.ts +9 -1
  99. package/dist/middlewares/cors.d.ts.map +1 -1
  100. package/dist/middlewares/cors.js +39 -17
  101. package/dist/middlewares/cors.js.map +1 -1
  102. package/dist/middlewares/cors.mjs +39 -18
  103. package/dist/middlewares/cors.mjs.map +1 -1
  104. package/dist/migrations/first-published-at.d.ts +4 -0
  105. package/dist/migrations/first-published-at.d.ts.map +1 -0
  106. package/dist/migrations/first-published-at.js +51 -0
  107. package/dist/migrations/first-published-at.js.map +1 -0
  108. package/dist/migrations/first-published-at.mjs +49 -0
  109. package/dist/migrations/first-published-at.mjs.map +1 -0
  110. package/dist/migrations/index.d.ts.map +1 -1
  111. package/dist/migrations/index.js +5 -0
  112. package/dist/migrations/index.js.map +1 -1
  113. package/dist/migrations/index.mjs +5 -0
  114. package/dist/migrations/index.mjs.map +1 -1
  115. package/dist/package.json.js +17 -13
  116. package/dist/package.json.js.map +1 -1
  117. package/dist/package.json.mjs +17 -13
  118. package/dist/package.json.mjs.map +1 -1
  119. package/dist/providers/index.d.ts.map +1 -1
  120. package/dist/providers/index.js +2 -0
  121. package/dist/providers/index.js.map +1 -1
  122. package/dist/providers/index.mjs +2 -0
  123. package/dist/providers/index.mjs.map +1 -1
  124. package/dist/providers/session-manager.d.ts +3 -0
  125. package/dist/providers/session-manager.d.ts.map +1 -0
  126. package/dist/providers/session-manager.js +23 -0
  127. package/dist/providers/session-manager.js.map +1 -0
  128. package/dist/providers/session-manager.mjs +21 -0
  129. package/dist/providers/session-manager.mjs.map +1 -0
  130. package/dist/services/content-api/index.d.ts +1 -1
  131. package/dist/services/content-api/index.d.ts.map +1 -1
  132. package/dist/services/content-api/index.js +1 -1
  133. package/dist/services/content-api/index.js.map +1 -1
  134. package/dist/services/content-api/index.mjs +2 -2
  135. package/dist/services/content-api/index.mjs.map +1 -1
  136. package/dist/services/content-source-maps.d.ts +13 -0
  137. package/dist/services/content-source-maps.d.ts.map +1 -0
  138. package/dist/services/content-source-maps.js +108 -0
  139. package/dist/services/content-source-maps.js.map +1 -0
  140. package/dist/services/content-source-maps.mjs +106 -0
  141. package/dist/services/content-source-maps.mjs.map +1 -0
  142. package/dist/services/core-store.d.ts +2 -2
  143. package/dist/services/core-store.d.ts.map +1 -1
  144. package/dist/services/core-store.js.map +1 -1
  145. package/dist/services/core-store.mjs.map +1 -1
  146. package/dist/services/document-service/components.d.ts +31 -1
  147. package/dist/services/document-service/components.d.ts.map +1 -1
  148. package/dist/services/document-service/components.js +109 -0
  149. package/dist/services/document-service/components.js.map +1 -1
  150. package/dist/services/document-service/components.mjs +107 -1
  151. package/dist/services/document-service/components.mjs.map +1 -1
  152. package/dist/services/document-service/entries.d.ts.map +1 -1
  153. package/dist/services/document-service/entries.js +42 -0
  154. package/dist/services/document-service/entries.js.map +1 -1
  155. package/dist/services/document-service/entries.mjs +43 -1
  156. package/dist/services/document-service/entries.mjs.map +1 -1
  157. package/dist/services/document-service/first-published-at.d.ts +7 -0
  158. package/dist/services/document-service/first-published-at.d.ts.map +1 -0
  159. package/dist/services/document-service/first-published-at.js +31 -0
  160. package/dist/services/document-service/first-published-at.js.map +1 -0
  161. package/dist/services/document-service/first-published-at.mjs +28 -0
  162. package/dist/services/document-service/first-published-at.mjs.map +1 -0
  163. package/dist/services/document-service/internationalization.d.ts +6 -1
  164. package/dist/services/document-service/internationalization.d.ts.map +1 -1
  165. package/dist/services/document-service/internationalization.js +32 -0
  166. package/dist/services/document-service/internationalization.js.map +1 -1
  167. package/dist/services/document-service/internationalization.mjs +32 -1
  168. package/dist/services/document-service/internationalization.mjs.map +1 -1
  169. package/dist/services/document-service/repository.d.ts.map +1 -1
  170. package/dist/services/document-service/repository.js +16 -8
  171. package/dist/services/document-service/repository.js.map +1 -1
  172. package/dist/services/document-service/repository.mjs +18 -10
  173. package/dist/services/document-service/repository.mjs.map +1 -1
  174. package/dist/services/document-service/utils/clean-component-join-table.d.ts +7 -0
  175. package/dist/services/document-service/utils/clean-component-join-table.d.ts.map +1 -0
  176. package/dist/services/document-service/utils/unidirectional-relations.d.ts +19 -2
  177. package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -1
  178. package/dist/services/document-service/utils/unidirectional-relations.js +21 -6
  179. package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -1
  180. package/dist/services/document-service/utils/unidirectional-relations.mjs +21 -6
  181. package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -1
  182. package/dist/services/entity-validator/index.d.ts.map +1 -1
  183. package/dist/services/entity-validator/index.js +9 -0
  184. package/dist/services/entity-validator/index.js.map +1 -1
  185. package/dist/services/entity-validator/index.mjs +9 -0
  186. package/dist/services/entity-validator/index.mjs.map +1 -1
  187. package/dist/services/entity-validator/validators.d.ts +1 -0
  188. package/dist/services/entity-validator/validators.d.ts.map +1 -1
  189. package/dist/services/entity-validator/validators.js +3 -0
  190. package/dist/services/entity-validator/validators.js.map +1 -1
  191. package/dist/services/entity-validator/validators.mjs +3 -0
  192. package/dist/services/entity-validator/validators.mjs.map +1 -1
  193. package/dist/services/metrics/index.d.ts +1 -1
  194. package/dist/services/metrics/index.d.ts.map +1 -1
  195. package/dist/services/metrics/index.js +11 -9
  196. package/dist/services/metrics/index.js.map +1 -1
  197. package/dist/services/metrics/index.mjs +11 -9
  198. package/dist/services/metrics/index.mjs.map +1 -1
  199. package/dist/services/metrics/middleware.d.ts +2 -1
  200. package/dist/services/metrics/middleware.d.ts.map +1 -1
  201. package/dist/services/metrics/middleware.js +2 -2
  202. package/dist/services/metrics/middleware.js.map +1 -1
  203. package/dist/services/metrics/middleware.mjs +2 -2
  204. package/dist/services/metrics/middleware.mjs.map +1 -1
  205. package/dist/services/metrics/sender.d.ts.map +1 -1
  206. package/dist/services/metrics/sender.js +4 -3
  207. package/dist/services/metrics/sender.js.map +1 -1
  208. package/dist/services/metrics/sender.mjs +4 -3
  209. package/dist/services/metrics/sender.mjs.map +1 -1
  210. package/dist/services/session-manager.d.ts +167 -0
  211. package/dist/services/session-manager.d.ts.map +1 -0
  212. package/dist/services/session-manager.js +529 -0
  213. package/dist/services/session-manager.js.map +1 -0
  214. package/dist/services/session-manager.mjs +526 -0
  215. package/dist/services/session-manager.mjs.map +1 -0
  216. package/dist/services/utils/conditional-fields.d.ts +3 -0
  217. package/dist/services/utils/conditional-fields.d.ts.map +1 -0
  218. package/dist/services/utils/conditional-fields.js +22 -0
  219. package/dist/services/utils/conditional-fields.js.map +1 -0
  220. package/dist/services/utils/conditional-fields.mjs +20 -0
  221. package/dist/services/utils/conditional-fields.mjs.map +1 -0
  222. package/dist/utils/fetch.d.ts +5 -1
  223. package/dist/utils/fetch.d.ts.map +1 -1
  224. package/dist/utils/fetch.js +8 -4
  225. package/dist/utils/fetch.js.map +1 -1
  226. package/dist/utils/fetch.mjs +8 -4
  227. package/dist/utils/fetch.mjs.map +1 -1
  228. package/dist/utils/transform-content-types-to-models.d.ts +197 -0
  229. package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
  230. package/package.json +17 -13
@@ -1,580 +1,521 @@
1
- import { relations } from '@strapi/utils';
2
- import { z } from 'zod';
1
+ import { augmentSchema, maybeRequired, maybeWithDefault, maybeReadonly, maybeWithMinMax, relations } from '@strapi/utils';
2
+ import { z } from 'zod/v4';
3
3
  import { BOOLEAN_LITERAL_VALUES } from './constants.mjs';
4
4
  import { CoreComponentRouteValidator } from './component.mjs';
5
5
  import { CoreContentTypeRouteValidator } from './content-type.mjs';
6
+ import { safeSchemaCreation } from './utils.mjs';
6
7
 
7
8
  /**
8
- * Maps a Strapi attribute definition to a corresponding Zod validation schema.
9
- * This function handles various Strapi attribute types and converts them into
10
- * appropriate Zod validation schemas with their respective constraints.
11
- *
12
- * @param attribute - The Strapi attribute configuration object. Contains type information
13
- * and validation rules for the attribute.
14
- *
15
- * @returns A Zod schema that corresponds to the input attribute's type and validation rules
16
- *
17
- * @example
18
- * ```typescript
19
- * // String attribute with constraints
20
- * const stringAttribute = {
21
- * type: 'string',
22
- * minLength: 3,
23
- * maxLength: 50,
24
- * required: true
25
- * };
26
- * const stringSchema = mapAttributeToSchema(stringAttribute);
27
- *
28
- * // Enumeration attribute
29
- * const enumAttribute = {
30
- * type: 'enumeration',
31
- * enum: ['draft', 'published', 'archived']
32
- * };
33
- * const enumSchema = mapAttributeToSchema(enumAttribute);
34
- *
35
- * // Media attribute with multiple files
36
- * const mediaAttribute = {
37
- * type: 'media',
38
- * multiple: true
39
- * };
40
- * const mediaSchema = mapAttributeToSchema(mediaAttribute);
41
- * ```
42
- *
43
- * @throws {Error} Throws an error if an unsupported attribute type is provided
44
- *
45
- * @remarks
46
- * - Complex types (component, relation, dynamic zone) use placeholder schemas
47
- *
48
- * @todo: Move to @strapi/utils if needed for other validation
49
- */ const mapAttributeToSchema = (attribute)=>{
50
- switch(attribute.type){
51
- case 'biginteger':
52
- {
53
- const { writable, required, min, max, default: defaultValue } = attribute;
54
- const schema = augmentSchema(z.string(), [
55
- (schema)=>min !== undefined ? schema.min(min) : schema,
56
- (schema)=>max !== undefined ? schema.max(max) : schema,
57
- maybeRequired(required),
58
- maybeWithDefault(defaultValue),
59
- maybeReadonly(writable)
60
- ]);
61
- return schema.describe('A biginteger field');
62
- }
63
- case 'blocks':
64
- {
65
- // TODO: better support blocks data structure
66
- return z.array(z.any()).describe('A blocks field');
67
- }
68
- case 'boolean':
69
- {
70
- const { writable, required, default: defaultValue } = attribute;
71
- const schema = augmentSchema(z.boolean(), [
72
- maybeRequired(required),
73
- maybeWithDefault(defaultValue),
74
- maybeReadonly(writable)
75
- ]);
76
- return schema.describe('A boolean field');
77
- }
78
- case 'component':
79
- {
80
- const { _idmap } = z.globalRegistry;
81
- const set = (id, schema)=>{
82
- if (_idmap.has(id)) {
83
- _idmap.delete(id);
84
- }
85
- z.globalRegistry.add(schema, {
86
- id
87
- });
88
- };
89
- const { writable, required, min, max, component, repeatable } = attribute;
90
- const existsInGlobalRegistry = _idmap.has(component);
91
- let componentSchema;
92
- if (existsInGlobalRegistry) {
93
- componentSchema = _idmap.get(component);
94
- } else {
95
- set(component, z.any());
96
- const validator = new CoreComponentRouteValidator(strapi, component);
97
- const schema = validator.entry;
98
- set(component, schema);
99
- componentSchema = schema;
100
- }
101
- const baseSchema = repeatable ? z.array(componentSchema) : componentSchema;
102
- const schema = augmentSchema(baseSchema, [
103
- (schema)=>min !== undefined && schema instanceof z.ZodArray ? schema.min(min) : schema,
104
- (schema)=>max !== undefined && schema instanceof z.ZodArray ? schema.max(max) : schema,
105
- maybeRequired(required),
106
- maybeReadonly(writable)
107
- ]);
108
- return schema.describe('A component field');
109
- }
110
- case 'date':
111
- {
112
- const { writable, required, default: defaultValue } = attribute;
113
- const schema = augmentSchema(z.string(), [
114
- maybeRequired(required),
115
- maybeWithDefault(defaultValue),
116
- maybeReadonly(writable)
117
- ]);
118
- return schema.describe('A date field');
119
- }
120
- case 'datetime':
121
- {
122
- const { writable, required, default: defaultValue } = attribute;
123
- const baseSchema = z.string();
124
- const schema = augmentSchema(baseSchema, [
125
- maybeRequired(required),
126
- maybeWithDefault(defaultValue),
127
- maybeReadonly(writable)
128
- ]);
129
- return schema.describe('A datetime field');
130
- }
131
- case 'decimal':
132
- {
133
- const { writable, required, min, max, default: defaultValue } = attribute;
134
- const schema = augmentSchema(z.number(), [
135
- maybeWithMinMax(min, max),
136
- maybeRequired(required),
137
- maybeWithDefault(defaultValue),
138
- maybeReadonly(writable)
139
- ]);
140
- return schema.describe('A decimal field');
141
- }
142
- // TODO(zodV4): use the components' reference type instead of z.any
143
- // TODO(zodV4): use discriminated unions to handle the different types of components
144
- case 'dynamiczone':
145
- {
146
- const { writable, required, min, max } = attribute;
147
- const baseSchema = z.array(z.any());
148
- const schema = augmentSchema(baseSchema, [
149
- maybeWithMinMax(min, max),
150
- maybeRequired(required),
151
- maybeReadonly(writable)
152
- ]);
153
- return schema.describe('A dynamic zone field');
154
- }
155
- case 'email':
156
- {
157
- const { writable, required, default: defaultValue, minLength, maxLength } = attribute;
158
- const baseSchema = z.string().email();
159
- const schema = augmentSchema(baseSchema, [
160
- maybeWithMinMax(minLength, maxLength),
161
- maybeRequired(required),
162
- maybeWithDefault(defaultValue),
163
- maybeReadonly(writable)
164
- ]);
165
- return schema.describe('An email field');
166
- }
167
- case 'enumeration':
168
- {
169
- const { writable, required, default: defaultValue, enum: enumValues } = attribute;
170
- const baseSchema = z.enum(enumValues);
171
- const schema = augmentSchema(baseSchema, [
172
- maybeRequired(required),
173
- maybeWithDefault(defaultValue),
174
- maybeReadonly(writable)
175
- ]);
176
- return schema.describe('An enum field');
177
- }
178
- case 'float':
179
- {
180
- const { writable, required, min, max, default: defaultValue } = attribute;
181
- const schema = augmentSchema(z.number(), [
182
- maybeWithMinMax(min, max),
183
- maybeRequired(required),
184
- maybeReadonly(writable),
185
- maybeWithDefault(defaultValue)
186
- ]);
187
- return schema.describe('A float field');
188
- }
189
- case 'integer':
190
- {
191
- const { writable, required, min, max, default: defaultValue } = attribute;
192
- const baseSchema = z.number().int();
193
- const schema = augmentSchema(baseSchema, [
194
- maybeWithMinMax(min, max),
195
- maybeRequired(required),
196
- maybeReadonly(writable),
197
- maybeWithDefault(defaultValue)
198
- ]);
199
- return schema.describe('A float field');
200
- }
201
- // TODO(zodV4): use reference to create fake cyclical JSON values
202
- // see https://zod.dev/?id=json-type for more info
203
- case 'json':
204
- {
205
- const { writable, required, default: defaultValue } = attribute;
206
- const schema = augmentSchema(z.any(), [
207
- maybeRequired(required),
208
- maybeWithDefault(defaultValue),
209
- maybeReadonly(writable)
210
- ]);
211
- return schema.describe('A JSON field');
212
- }
213
- case 'media':
214
- {
215
- const { writable, required, multiple } = attribute;
216
- const baseSchema = multiple ? z.array(z.any()) : z.any();
217
- const schema = augmentSchema(baseSchema, [
218
- maybeRequired(required),
219
- maybeReadonly(writable)
220
- ]);
221
- return schema.describe('A media field');
222
- }
223
- // TODO(zodV4): handle polymorphic relations using discriminated unions
224
- case 'relation':
225
- {
226
- // Extract writable and required flags from the attribute
227
- if (!('target' in attribute)) {
228
- return z.any();
229
- }
230
- const { _idmap } = z.globalRegistry;
231
- const set = (id, schema)=>{
232
- if (_idmap.has(id)) {
233
- _idmap.delete(id);
234
- }
235
- z.globalRegistry.add(schema, {
236
- id
237
- });
238
- };
239
- const { writable, required, target } = attribute;
240
- const existsInGlobalRegistry = _idmap.has(target);
241
- let targetSchema;
242
- if (existsInGlobalRegistry) {
243
- targetSchema = _idmap.get(target);
244
- } else {
245
- set(target, z.any());
246
- const validator = new CoreContentTypeRouteValidator(strapi, target);
247
- const schema = validator.document;
248
- set(target, schema);
249
- targetSchema = schema;
250
- }
251
- const baseSchema = relations.isAnyToMany(attribute) ? z.array(targetSchema) : targetSchema;
252
- // Add required and readonly constraints based on attribute flags
253
- const schema = augmentSchema(baseSchema, [
254
- maybeRequired(required),
255
- maybeReadonly(writable)
256
- ]);
257
- return schema.describe('A relational field');
258
- }
259
- case 'password':
260
- case 'text':
261
- case 'richtext':
262
- case 'string':
263
- {
264
- const { writable, required, default: defaultValue, minLength, maxLength } = attribute;
265
- const schema = augmentSchema(z.string(), [
266
- maybeWithMinMax(minLength, maxLength),
267
- maybeRequired(required),
268
- maybeWithDefault(defaultValue),
269
- maybeReadonly(writable)
270
- ]);
271
- return schema.describe(`A ${attribute.type} field`);
272
- }
273
- case 'time':
274
- {
275
- const { writable, required, default: defaultValue } = attribute;
276
- const schema = augmentSchema(z.string(), [
277
- maybeRequired(required),
278
- maybeWithDefault(defaultValue),
279
- maybeReadonly(writable)
280
- ]);
281
- return schema.describe('A time field');
282
- }
283
- case 'timestamp':
284
- {
285
- const { writable, required, default: defaultValue } = attribute;
286
- const baseSchema = z.union([
287
- z.string(),
288
- z.number()
289
- ]);
290
- const schema = augmentSchema(baseSchema, [
291
- maybeRequired(required),
292
- maybeWithDefault(defaultValue),
293
- maybeReadonly(writable)
294
- ]);
295
- return schema.describe('A timestamp field');
296
- }
297
- case 'uid':
298
- {
299
- const { writable, required, default: defaultValue, minLength, maxLength } = attribute;
300
- const schema = augmentSchema(z.string(), [
301
- maybeWithMinMax(minLength, maxLength),
302
- maybeRequired(required),
303
- maybeWithDefault(defaultValue),
304
- maybeReadonly(writable)
305
- ]);
306
- return schema.describe('A UID field');
307
- }
308
- default:
309
- throw new Error(`Unsupported attribute type: ${attribute.type}`);
310
- }
9
+ * Converts a BigInteger attribute to a Zod schema.
10
+ * @param attribute - The BigInteger attribute object from the Strapi schema.
11
+ * @returns A Zod schema representing the BigInteger field.
12
+ */ const bigIntegerToSchema = (attribute)=>{
13
+ const { writable, required, min, max, default: defaultValue } = attribute;
14
+ const schema = augmentSchema(z.string(), [
15
+ (schema)=>min !== undefined ? schema.min(min) : schema,
16
+ (schema)=>max !== undefined ? schema.max(max) : schema,
17
+ maybeRequired(required),
18
+ maybeWithDefault(defaultValue),
19
+ maybeReadonly(writable)
20
+ ]);
21
+ return schema.describe('A biginteger field');
22
+ };
23
+ /**
24
+ * Converts a blocks attribute to a Zod schema.
25
+ * @returns A Zod schema representing the blocks field.
26
+ */ const blocksToSchema = ()=>{
27
+ return z.array(z.any()).describe('A blocks field');
28
+ };
29
+ /**
30
+ * Converts a boolean attribute to a Zod schema.
31
+ * @param attribute - The Boolean attribute object from the Strapi schema.
32
+ * @returns A Zod schema representing the boolean field.
33
+ */ const booleanToSchema = (attribute)=>{
34
+ const { writable, required, default: defaultValue } = attribute;
35
+ const schema = augmentSchema(z.boolean(), [
36
+ maybeRequired(required),
37
+ maybeWithDefault(defaultValue),
38
+ maybeReadonly(writable)
39
+ ]);
40
+ return schema.describe('A boolean field');
41
+ };
42
+ /**
43
+ * Converts a component attribute to a Zod schema.
44
+ * @param attribute - The Component attribute object from the Strapi schema.
45
+ * @returns A Zod schema representing the component field.
46
+ */ const componentToSchema = (attribute)=>{
47
+ const { writable, required, min, max, component, repeatable } = attribute;
48
+ const componentSchema = safeSchemaCreation(component, ()=>new CoreComponentRouteValidator(strapi, component).entry);
49
+ const baseSchema = repeatable ? z.array(componentSchema) : componentSchema;
50
+ const schema = augmentSchema(baseSchema, [
51
+ (schema)=>min !== undefined && schema instanceof z.ZodArray ? schema.min(min) : schema,
52
+ (schema)=>max !== undefined && schema instanceof z.ZodArray ? schema.max(max) : schema,
53
+ maybeRequired(required),
54
+ maybeReadonly(writable)
55
+ ]);
56
+ return schema.describe('A component field');
57
+ };
58
+ /**
59
+ * Converts a date attribute to a Zod schema.
60
+ * @param attribute - The Date attribute object from the Strapi schema.
61
+ * @returns A Zod schema representing the date field.
62
+ */ const dateToSchema = (attribute)=>{
63
+ const { writable, required, default: defaultValue } = attribute;
64
+ const schema = augmentSchema(z.string(), [
65
+ maybeRequired(required),
66
+ maybeWithDefault(defaultValue),
67
+ maybeReadonly(writable)
68
+ ]);
69
+ return schema.describe('A date field');
70
+ };
71
+ /**
72
+ * Converts a datetime attribute to a Zod schema.
73
+ * @param attribute - The DateTime attribute object from the Strapi schema.
74
+ * @returns A Zod schema representing the datetime field.
75
+ */ const datetimeToSchema = (attribute)=>{
76
+ const { writable, required, default: defaultValue } = attribute;
77
+ const schema = augmentSchema(z.string(), [
78
+ maybeRequired(required),
79
+ maybeWithDefault(defaultValue),
80
+ maybeReadonly(writable)
81
+ ]);
82
+ return schema.describe('A datetime field');
83
+ };
84
+ /**
85
+ * Converts a decimal attribute to a Zod schema.
86
+ * @param attribute - The Decimal attribute object from the Strapi schema.
87
+ * @returns A Zod schema representing the decimal field.
88
+ */ const decimalToSchema = (attribute)=>{
89
+ const { writable, required, min, max, default: defaultValue } = attribute;
90
+ const schema = augmentSchema(z.number(), [
91
+ maybeWithMinMax(min, max),
92
+ maybeRequired(required),
93
+ maybeWithDefault(defaultValue),
94
+ maybeReadonly(writable)
95
+ ]);
96
+ return schema.describe('A decimal field');
97
+ };
98
+ /**
99
+ * Converts a dynamic zone attribute to a Zod schema.
100
+ * @param attribute - The DynamicZone attribute object from the Strapi schema.
101
+ * @returns A Zod schema representing the dynamic zone field.
102
+ */ const dynamicZoneToSchema = (attribute)=>{
103
+ const { writable, required, min, max } = attribute;
104
+ const baseSchema = z.array(z.any());
105
+ const schema = augmentSchema(baseSchema, [
106
+ maybeWithMinMax(min, max),
107
+ maybeRequired(required),
108
+ maybeReadonly(writable)
109
+ ]);
110
+ return schema.describe('A dynamic zone field');
111
+ };
112
+ /**
113
+ * Converts an email attribute to a Zod schema.
114
+ * @param attribute - The Email attribute object from the Strapi schema.
115
+ * @returns A Zod schema representing the email field.
116
+ */ const emailToSchema = (attribute)=>{
117
+ const { writable, required, default: defaultValue, minLength, maxLength } = attribute;
118
+ const baseSchema = z.email();
119
+ const schema = augmentSchema(baseSchema, [
120
+ maybeWithMinMax(minLength, maxLength),
121
+ maybeRequired(required),
122
+ maybeWithDefault(defaultValue),
123
+ maybeReadonly(writable)
124
+ ]);
125
+ return schema.describe('An email field');
311
126
  };
312
127
  /**
313
- * Maps a Strapi attribute definition to a corresponding Zod validation schema.
314
- * This function handles various Strapi attribute types and converts them into
315
- * appropriate Zod validation schemas with their respective constraints.
316
- *
317
- * @param attribute - The Strapi attribute configuration object. Contains type information
318
- * and validation rules for the attribute.
319
- *
320
- * @returns A Zod schema that corresponds to the input attribute's type and validation rules
321
- *
322
- * @example
323
- * ```typescript
324
- * // String attribute with constraints
325
- * const stringAttribute = {
326
- * type: 'string',
327
- * minLength: 3,
328
- * maxLength: 50,
329
- * required: true
330
- * };
331
- * const stringSchema = mapAttributeToInputSchema(stringAttribute);
332
- *
333
- * // Enumeration attribute
334
- * const enumAttribute = {
335
- * type: 'enumeration',
336
- * enum: ['draft', 'published', 'archived']
337
- * };
338
- * const enumSchema = mapAttributeToInputSchema(enumAttribute);
339
- *
340
- * // Media attribute with multiple files
341
- * const mediaAttribute = {
342
- * type: 'media',
343
- * multiple: true
344
- * };
345
- * const mediaSchema = mapAttributeToInputSchema(mediaAttribute);
346
- * ```
347
- *
348
- * @throws {Error} Throws an error if an unsupported attribute type is provided
349
- *
350
- * @remarks
351
- * - Complex types (component, relation, dynamic zone) use placeholder schemas
352
- *
353
- * @todo: Move to @strapi/utils if needed for other validation
354
- */ const mapAttributeToInputSchema = (attribute)=>{
355
- switch(attribute.type){
356
- case 'biginteger':
357
- {
358
- const { required, min, max, default: defaultValue } = attribute;
359
- const schema = augmentSchema(z.string(), [
360
- (schema)=>min !== undefined ? schema.min(min) : schema,
361
- (schema)=>max !== undefined ? schema.max(max) : schema,
362
- maybeRequired(required),
363
- maybeWithDefault(defaultValue)
364
- ]);
365
- return schema.describe('A biginteger field');
366
- }
367
- case 'blocks':
368
- {
369
- // TODO: better support blocks data structure
370
- return z.array(z.any()).describe('A blocks field');
371
- }
372
- case 'boolean':
373
- {
374
- const { required, default: defaultValue } = attribute;
375
- const baseSchema = z.enum(BOOLEAN_LITERAL_VALUES);
376
- const schema = augmentSchema(baseSchema, [
377
- maybeRequired(required),
378
- maybeWithDefault(defaultValue)
379
- ]);
380
- return schema.describe('A boolean field');
381
- }
382
- // TODO(zodV4): use the component reference type instead of z.any
383
- case 'component':
384
- {
385
- const { required, repeatable, min, max } = attribute;
386
- const baseSchema = repeatable ? z.array(z.any()) : z.any();
387
- const schema = augmentSchema(baseSchema, [
388
- (schema)=>min !== undefined && schema instanceof z.ZodArray ? schema.min(min) : schema,
389
- (schema)=>max !== undefined && schema instanceof z.ZodArray ? schema.max(max) : schema,
390
- maybeRequired(required)
391
- ]);
392
- return schema.describe('A component field');
393
- }
394
- case 'date':
395
- {
396
- const { required, default: defaultValue } = attribute;
397
- const schema = augmentSchema(z.string(), [
398
- maybeRequired(required),
399
- maybeWithDefault(defaultValue)
400
- ]);
401
- return schema.describe('A date field');
402
- }
403
- case 'datetime':
404
- {
405
- const { required, default: defaultValue } = attribute;
406
- const schema = augmentSchema(z.string(), [
407
- maybeRequired(required),
408
- maybeWithDefault(defaultValue)
409
- ]);
410
- return schema.describe('A datetime field');
411
- }
412
- case 'decimal':
413
- {
414
- const { required, min, max, default: defaultValue } = attribute;
415
- const schema = augmentSchema(z.number(), [
416
- maybeWithMinMax(min, max),
417
- maybeRequired(required),
418
- maybeWithDefault(defaultValue)
419
- ]);
420
- return schema.describe('A decimal field');
421
- }
422
- // TODO(zodV4): use the components' reference type instead of z.any
423
- // TODO(zodV4): use discriminated unions to handle the different types of components
424
- case 'dynamiczone':
425
- {
426
- const { required, min, max } = attribute;
427
- const baseSchema = z.array(z.any());
428
- const schema = augmentSchema(baseSchema, [
429
- maybeWithMinMax(min, max),
430
- maybeRequired(required)
431
- ]);
432
- return schema.describe('A dynamic zone field');
433
- }
434
- case 'email':
435
- {
436
- const { required, default: defaultValue, minLength, maxLength } = attribute;
437
- const baseSchema = z.string().email();
438
- const schema = augmentSchema(baseSchema, [
439
- maybeWithMinMax(minLength, maxLength),
440
- maybeRequired(required),
441
- maybeWithDefault(defaultValue)
442
- ]);
443
- return schema.describe('An email field');
444
- }
445
- case 'enumeration':
446
- {
447
- const { required, default: defaultValue, enum: enumValues } = attribute;
448
- const baseSchema = z.enum(enumValues);
449
- const schema = augmentSchema(baseSchema, [
450
- maybeRequired(required),
451
- maybeWithDefault(defaultValue)
452
- ]);
453
- return schema.describe('An enum field');
454
- }
455
- case 'float':
456
- {
457
- const { required, min, max, default: defaultValue } = attribute;
458
- const schema = augmentSchema(z.number(), [
459
- maybeWithMinMax(min, max),
460
- maybeRequired(required),
461
- maybeWithDefault(defaultValue)
462
- ]);
463
- return schema.describe('A float field');
464
- }
465
- case 'integer':
466
- {
467
- const { required, min, max, default: defaultValue } = attribute;
468
- const baseSchema = z.number().int();
469
- const schema = augmentSchema(baseSchema, [
470
- maybeWithMinMax(min, max),
471
- maybeRequired(required),
472
- maybeWithDefault(defaultValue)
473
- ]);
474
- return schema.describe('A float field');
475
- }
476
- // TODO(zodV4): use reference to create fake cyclical JSON values
477
- // see https://zod.dev/?id=json-type for more info
478
- case 'json':
479
- {
480
- const { required, default: defaultValue } = attribute;
481
- const schema = augmentSchema(z.any(), [
482
- maybeRequired(required),
483
- maybeWithDefault(defaultValue)
484
- ]);
485
- return schema.describe('A JSON field');
486
- }
487
- case 'media':
488
- {
489
- const { required, multiple } = attribute;
490
- const baseSchema = multiple ? z.array(z.any()) : z.any();
491
- const schema = augmentSchema(baseSchema, [
492
- maybeRequired(required)
493
- ]);
494
- return schema.describe('A media field');
495
- }
496
- // TODO(zodV4): use reference for relations types
497
- // TODO(zodV4): handle polymorphic relations using discriminated unions
498
- // TODO(zodv4): add the relation ordering API https://docs.strapi.io/cms/api/rest/relations
499
- case 'relation':
500
- {
501
- const { required } = attribute;
502
- const isToMany = relations.isAnyToMany(attribute);
503
- const uuid = z.string().uuid();
504
- const baseSchema = isToMany ? z.array(uuid) : uuid;
505
- const schema = augmentSchema(baseSchema, [
506
- maybeRequired(required)
507
- ]);
508
- return schema.describe('A relational field');
509
- }
510
- case 'password':
511
- case 'text':
512
- case 'richtext':
513
- case 'string':
514
- {
515
- const { required, default: defaultValue, minLength, maxLength } = attribute;
516
- const schema = augmentSchema(z.string(), [
517
- maybeWithMinMax(minLength, maxLength),
518
- maybeRequired(required),
519
- maybeWithDefault(defaultValue)
520
- ]);
521
- return schema.describe(`A ${attribute.type} field`);
522
- }
523
- case 'time':
524
- {
525
- const { required, default: defaultValue } = attribute;
526
- const schema = augmentSchema(z.string(), [
527
- maybeRequired(required),
528
- maybeWithDefault(defaultValue)
529
- ]);
530
- return schema.describe('A time field');
531
- }
532
- case 'timestamp':
533
- {
534
- const { required, default: defaultValue } = attribute;
535
- const baseSchema = z.union([
536
- z.string(),
537
- z.number()
538
- ]);
539
- const schema = augmentSchema(baseSchema, [
540
- maybeRequired(required),
541
- maybeWithDefault(defaultValue)
542
- ]);
543
- return schema.describe('A timestamp field');
544
- }
545
- case 'uid':
546
- {
547
- const { required, default: defaultValue, minLength, maxLength } = attribute;
548
- const schema = augmentSchema(z.string(), [
549
- maybeWithMinMax(minLength, maxLength),
550
- maybeRequired(required),
551
- maybeWithDefault(defaultValue)
552
- ]);
553
- return schema.describe('A UID field');
554
- }
555
- default:
556
- throw new Error(`Unsupported attribute type: ${attribute.type}`);
128
+ * Converts an enumeration attribute to a Zod schema.
129
+ * @param attribute - The Enumeration attribute object from the Strapi schema.
130
+ * @returns A Zod schema representing the enumeration field.
131
+ */ const enumToSchema = (attribute)=>{
132
+ const { writable, required, default: defaultValue, enum: enumValues } = attribute;
133
+ const baseSchema = z.enum(enumValues);
134
+ const schema = augmentSchema(baseSchema, [
135
+ maybeRequired(required),
136
+ maybeWithDefault(defaultValue),
137
+ maybeReadonly(writable)
138
+ ]);
139
+ return schema.describe('An enum field');
140
+ };
141
+ /**
142
+ * Converts a float attribute to a Zod schema.
143
+ * @param attribute - The Float attribute object from the Strapi schema.
144
+ * @returns A Zod schema representing the float field.
145
+ */ const floatToSchema = (attribute)=>{
146
+ const { writable, required, min, max, default: defaultValue } = attribute;
147
+ const schema = augmentSchema(z.number(), [
148
+ maybeWithMinMax(min, max),
149
+ maybeRequired(required),
150
+ maybeReadonly(writable),
151
+ maybeWithDefault(defaultValue)
152
+ ]);
153
+ return schema.describe('A float field');
154
+ };
155
+ /**
156
+ * Converts an integer attribute to a Zod schema.
157
+ * @param attribute - The Integer attribute object from the Strapi schema.
158
+ * @returns A Zod schema representing the integer field.
159
+ */ const integerToSchema = (attribute)=>{
160
+ const { writable, required, min, max, default: defaultValue } = attribute;
161
+ const baseSchema = z.number().int();
162
+ const schema = augmentSchema(baseSchema, [
163
+ maybeWithMinMax(min, max),
164
+ maybeRequired(required),
165
+ maybeReadonly(writable),
166
+ maybeWithDefault(defaultValue)
167
+ ]);
168
+ return schema.describe('An integer field');
169
+ };
170
+ /**
171
+ * Converts a JSON attribute to a Zod schema.
172
+ * @param attribute - The JSON attribute object from the Strapi schema.
173
+ * @returns A Zod schema representing the JSON field.
174
+ */ const jsonToSchema = (attribute)=>{
175
+ const { writable, required, default: defaultValue } = attribute;
176
+ const schema = augmentSchema(z.any(), [
177
+ maybeRequired(required),
178
+ maybeWithDefault(defaultValue),
179
+ maybeReadonly(writable)
180
+ ]);
181
+ return schema.describe('A JSON field');
182
+ };
183
+ /**
184
+ * Converts a media attribute to a Zod schema.
185
+ * @param attribute - The Media attribute object from the Strapi schema.
186
+ * @returns A Zod schema representing the media field.
187
+ */ const mediaToSchema = (attribute)=>{
188
+ const { writable, required, multiple } = attribute;
189
+ const uploadPlugin = strapi.plugin('upload');
190
+ // @ts-expect-error there is a mismatch between a raw module and a loader module
191
+ const fileSchema = uploadPlugin.contentTypes.file;
192
+ const mediaSchema = safeSchemaCreation(fileSchema.uid, ()=>new CoreContentTypeRouteValidator(strapi, fileSchema.uid).document);
193
+ const baseSchema = multiple ? z.array(mediaSchema) : mediaSchema;
194
+ const schema = augmentSchema(baseSchema, [
195
+ maybeRequired(required),
196
+ maybeReadonly(writable)
197
+ ]);
198
+ return schema.describe('A media field');
199
+ };
200
+ /**
201
+ * Converts a relation attribute to a Zod schema.
202
+ * @param attribute - The Relation attribute object from the Strapi schema.
203
+ * @returns A Zod schema representing the relational field.
204
+ */ const relationToSchema = (attribute)=>{
205
+ if (!('target' in attribute)) {
206
+ return z.any();
557
207
  }
208
+ const { writable, required, target } = attribute;
209
+ const targetSchema = safeSchemaCreation(target, ()=>new CoreContentTypeRouteValidator(strapi, target).document);
210
+ const baseSchema = relations.isAnyToMany(attribute) ? z.array(targetSchema) : targetSchema;
211
+ const schema = augmentSchema(baseSchema, [
212
+ maybeRequired(required),
213
+ maybeReadonly(writable)
214
+ ]);
215
+ return schema.describe('A relational field');
216
+ };
217
+ /**
218
+ * Converts a string, text, rich text, or password attribute to a Zod schema.
219
+ * @param attribute - The String, Text, RichText, or Password attribute object from the Strapi schema.
220
+ * @returns A Zod schema representing the field.
221
+ */ const stringToSchema = (attribute)=>{
222
+ const { writable, required, default: defaultValue, minLength, maxLength } = attribute;
223
+ const schema = augmentSchema(z.string(), [
224
+ maybeWithMinMax(minLength, maxLength),
225
+ maybeRequired(required),
226
+ maybeWithDefault(defaultValue),
227
+ maybeReadonly(writable)
228
+ ]);
229
+ return schema.describe(`A ${attribute.type} field`);
230
+ };
231
+ /**
232
+ * Converts a time attribute to a Zod schema.
233
+ * @param attribute - The Time attribute object from the Strapi schema.
234
+ * @returns A Zod schema representing the time field.
235
+ */ const timeToSchema = (attribute)=>{
236
+ const { writable, required, default: defaultValue } = attribute;
237
+ const schema = augmentSchema(z.string(), [
238
+ maybeRequired(required),
239
+ maybeWithDefault(defaultValue),
240
+ maybeReadonly(writable)
241
+ ]);
242
+ return schema.describe('A time field');
243
+ };
244
+ /**
245
+ * Converts a timestamp attribute to a Zod schema.
246
+ * @param attribute - The Timestamp attribute object from the Strapi schema.
247
+ * @returns A Zod schema representing the timestamp field.
248
+ */ const timestampToSchema = (attribute)=>{
249
+ const { writable, required, default: defaultValue } = attribute;
250
+ const baseSchema = z.union([
251
+ z.string(),
252
+ z.number()
253
+ ]);
254
+ const schema = augmentSchema(baseSchema, [
255
+ maybeRequired(required),
256
+ maybeWithDefault(defaultValue),
257
+ maybeReadonly(writable)
258
+ ]);
259
+ return schema.describe('A timestamp field');
260
+ };
261
+ /**
262
+ * Converts a UID attribute to a Zod schema.
263
+ * @param attribute - The UID attribute object from the Strapi schema.
264
+ * @returns A Zod schema representing the UID field.
265
+ */ const uidToSchema = (attribute)=>{
266
+ const { writable, required, default: defaultValue, minLength, maxLength } = attribute;
267
+ const schema = augmentSchema(z.string(), [
268
+ maybeWithMinMax(minLength, maxLength),
269
+ maybeRequired(required),
270
+ maybeWithDefault(defaultValue),
271
+ maybeReadonly(writable)
272
+ ]);
273
+ return schema.describe('A UID field');
274
+ };
275
+ /**
276
+ * Converts a BigInteger attribute to a Zod schema for input validation.
277
+ * @param attribute - The BigInteger attribute object from the Strapi schema.
278
+ * @returns A Zod schema for input validation of the BigInteger field.
279
+ */ const bigIntegerToInputSchema = (attribute)=>{
280
+ const { required, min, max, default: defaultValue } = attribute;
281
+ const schema = augmentSchema(z.string(), [
282
+ (schema)=>min !== undefined ? schema.min(min) : schema,
283
+ (schema)=>max !== undefined ? schema.max(max) : schema,
284
+ maybeRequired(required),
285
+ maybeWithDefault(defaultValue)
286
+ ]);
287
+ return schema.describe('A biginteger field');
288
+ };
289
+ /**
290
+ * Converts a blocks attribute to a Zod schema for input validation.
291
+ * @returns A Zod schema for input validation of the blocks field.
292
+ */ const blocksToInputSchema = ()=>{
293
+ // TODO: better support blocks data structure
294
+ return z.array(z.any()).describe('A blocks field');
295
+ };
296
+ /**
297
+ * Converts a boolean attribute to a Zod schema for input validation.
298
+ * @param attribute - The Boolean attribute object from the Strapi schema.
299
+ * @returns A Zod schema for input validation of the boolean field.
300
+ */ const booleanToInputSchema = (attribute)=>{
301
+ const { required, default: defaultValue } = attribute;
302
+ const baseSchema = z.enum(BOOLEAN_LITERAL_VALUES);
303
+ const schema = augmentSchema(baseSchema, [
304
+ maybeRequired(required),
305
+ maybeWithDefault(defaultValue)
306
+ ]);
307
+ return schema.describe('A boolean field');
308
+ };
309
+ /**
310
+ * Converts a component attribute to a Zod schema for input validation.
311
+ * @param attribute - The Component attribute object from the Strapi schema.
312
+ * @returns A Zod schema for input validation of the component field.
313
+ */ const componentToInputSchema = (attribute)=>{
314
+ const { required, repeatable, min, max } = attribute;
315
+ const baseSchema = repeatable ? z.array(z.any()) : z.any();
316
+ const schema = augmentSchema(baseSchema, [
317
+ (schema)=>min !== undefined && schema instanceof z.ZodArray ? schema.min(min) : schema,
318
+ (schema)=>max !== undefined && schema instanceof z.ZodArray ? schema.max(max) : schema,
319
+ maybeRequired(required)
320
+ ]);
321
+ return schema.describe('A component field');
322
+ };
323
+ /**
324
+ * Converts a date attribute to a Zod schema for input validation.
325
+ * @param attribute - The Date attribute object from the Strapi schema.
326
+ * @returns A Zod schema for input validation of the date field.
327
+ */ const dateToInputSchema = (attribute)=>{
328
+ const { required, default: defaultValue } = attribute;
329
+ const schema = augmentSchema(z.string(), [
330
+ maybeRequired(required),
331
+ maybeWithDefault(defaultValue)
332
+ ]);
333
+ return schema.describe('A date field');
334
+ };
335
+ /**
336
+ * Converts a datetime attribute to a Zod schema for input validation.
337
+ * @param attribute - The DateTime attribute object from the Strapi schema.
338
+ * @returns A Zod schema for input validation of the datetime field.
339
+ */ const datetimeToInputSchema = (attribute)=>{
340
+ const { required, default: defaultValue } = attribute;
341
+ const schema = augmentSchema(z.string(), [
342
+ maybeRequired(required),
343
+ maybeWithDefault(defaultValue)
344
+ ]);
345
+ return schema.describe('A datetime field');
346
+ };
347
+ /**
348
+ * Converts a decimal attribute to a Zod schema for input validation.
349
+ * @param attribute - The Decimal attribute object from the Strapi schema.
350
+ * @returns A Zod schema for input validation of the decimal field.
351
+ */ const decimalToInputSchema = (attribute)=>{
352
+ const { required, min, max, default: defaultValue } = attribute;
353
+ const schema = augmentSchema(z.number(), [
354
+ maybeWithMinMax(min, max),
355
+ maybeRequired(required),
356
+ maybeWithDefault(defaultValue)
357
+ ]);
358
+ return schema.describe('A decimal field');
359
+ };
360
+ /**
361
+ * Converts a dynamic zone attribute to a Zod schema for input validation.
362
+ * @param attribute - The DynamicZone attribute object from the Strapi schema.
363
+ * @returns A Zod schema for input validation of the dynamic zone field.
364
+ */ const dynamicZoneToInputSchema = (attribute)=>{
365
+ const { required, min, max } = attribute;
366
+ const baseSchema = z.array(z.any());
367
+ const schema = augmentSchema(baseSchema, [
368
+ maybeWithMinMax(min, max),
369
+ maybeRequired(required)
370
+ ]);
371
+ return schema.describe('A dynamic zone field');
558
372
  };
559
- const maybeRequired = (required)=>{
560
- return (schema)=>required !== true ? schema.optional() : schema;
373
+ /**
374
+ * Converts an email attribute to a Zod schema for input validation.
375
+ * @param attribute - The Email attribute object from the Strapi schema.
376
+ * @returns A Zod schema for input validation of the email field.
377
+ */ const emailToInputSchema = (attribute)=>{
378
+ const { required, default: defaultValue, minLength, maxLength } = attribute;
379
+ const baseSchema = z.email();
380
+ const schema = augmentSchema(baseSchema, [
381
+ maybeWithMinMax(minLength, maxLength),
382
+ maybeRequired(required),
383
+ maybeWithDefault(defaultValue)
384
+ ]);
385
+ return schema.describe('An email field');
561
386
  };
562
- const maybeReadonly = (writable)=>{
563
- return (schema)=>writable !== false ? schema : schema.readonly();
387
+ /**
388
+ * Converts an enumeration attribute to a Zod schema for input validation.
389
+ * @param attribute - The Enumeration attribute object from the Strapi schema.
390
+ * @returns A Zod schema for input validation of the enumeration field.
391
+ */ const enumerationToInputSchema = (attribute)=>{
392
+ const { required, default: defaultValue, enum: enumValues } = attribute;
393
+ const baseSchema = z.enum(enumValues);
394
+ const schema = augmentSchema(baseSchema, [
395
+ maybeRequired(required),
396
+ maybeWithDefault(defaultValue)
397
+ ]);
398
+ return schema.describe('An enum field');
564
399
  };
565
- const maybeWithDefault = (defaultValue)=>{
566
- return (schema)=>{
567
- return defaultValue !== undefined ? schema.default(typeof defaultValue === 'function' ? defaultValue() : defaultValue) : schema;
568
- };
400
+ /**
401
+ * Converts a float attribute to a Zod schema for input validation.
402
+ * @param attribute - The Float attribute object from the Strapi schema.
403
+ * @returns A Zod schema for input validation of the float field.
404
+ */ const floatToInputSchema = (attribute)=>{
405
+ const { required, min, max, default: defaultValue } = attribute;
406
+ const schema = augmentSchema(z.number(), [
407
+ maybeWithMinMax(min, max),
408
+ maybeRequired(required),
409
+ maybeWithDefault(defaultValue)
410
+ ]);
411
+ return schema.describe('A float field');
569
412
  };
570
- const maybeWithMinMax = (min, max)=>{
571
- return (schema)=>{
572
- return min !== undefined && max !== undefined ? schema.min(min).max(max) : schema;
573
- };
413
+ /**
414
+ * Converts an integer attribute to a Zod schema for input validation.
415
+ * @param attribute - The Integer attribute object from the Strapi schema.
416
+ * @returns A Zod schema for input validation of the integer field.
417
+ */ const integerToInputSchema = (attribute)=>{
418
+ const { required, min, max, default: defaultValue } = attribute;
419
+ const baseSchema = z.number().int();
420
+ const schema = augmentSchema(baseSchema, [
421
+ maybeWithMinMax(min, max),
422
+ maybeRequired(required),
423
+ maybeWithDefault(defaultValue)
424
+ ]);
425
+ return schema.describe('A float field');
574
426
  };
575
- const augmentSchema = (schema, modifiers)=>{
576
- return modifiers.reduce((acc, modifier)=>modifier(acc), schema);
427
+ /**
428
+ * Converts a JSON attribute to a Zod schema for input validation.
429
+ * @param attribute - The JSON attribute object from the Strapi schema.
430
+ * @returns A Zod schema for input validation of the JSON field.
431
+ */ const jsonToInputSchema = (attribute)=>{
432
+ const { required, default: defaultValue } = attribute;
433
+ const schema = augmentSchema(z.any(), [
434
+ maybeRequired(required),
435
+ maybeWithDefault(defaultValue)
436
+ ]);
437
+ return schema.describe('A JSON field');
438
+ };
439
+ /**
440
+ * Converts a media attribute to a Zod schema for input validation.
441
+ * @param attribute - The Media attribute object from the Strapi schema.
442
+ * @returns A Zod schema for input validation of the media field.
443
+ */ const mediaToInputSchema = (attribute)=>{
444
+ const { required, multiple } = attribute;
445
+ const baseSchema = multiple ? z.array(z.any()) : z.any();
446
+ const schema = augmentSchema(baseSchema, [
447
+ maybeRequired(required)
448
+ ]);
449
+ return schema.describe('A media field');
450
+ };
451
+ /**
452
+ * Converts a relation attribute to a Zod schema for input validation.
453
+ * @param attribute - The Relation attribute object from the Strapi schema.
454
+ * @returns A Zod schema for input validation of the relational field.
455
+ */ const relationToInputSchema = (attribute)=>{
456
+ const { required } = attribute;
457
+ const isToMany = relations.isAnyToMany(attribute);
458
+ const uuid = z.string().uuid();
459
+ const baseSchema = isToMany ? z.array(uuid) : uuid;
460
+ const schema = augmentSchema(baseSchema, [
461
+ maybeRequired(required)
462
+ ]);
463
+ return schema.describe('A relational field');
464
+ };
465
+ /**
466
+ * Converts a string, text, rich text, or password attribute to a Zod schema for input validation.
467
+ * @param attribute - The String, Text, RichText, or Password attribute object from the Strapi schema.
468
+ * @returns A Zod schema for input validation of the field.
469
+ */ const textToInputSchema = (attribute)=>{
470
+ const { required, default: defaultValue, minLength, maxLength } = attribute;
471
+ const schema = augmentSchema(z.string(), [
472
+ maybeWithMinMax(minLength, maxLength),
473
+ maybeRequired(required),
474
+ maybeWithDefault(defaultValue)
475
+ ]);
476
+ return schema.describe(`A ${attribute.type} field`);
477
+ };
478
+ /**
479
+ * Converts a time attribute to a Zod schema for input validation.
480
+ * @param attribute - The Time attribute object from the Strapi schema.
481
+ * @returns A Zod schema for input validation of the time field.
482
+ */ const timeToInputSchema = (attribute)=>{
483
+ const { required, default: defaultValue } = attribute;
484
+ const schema = augmentSchema(z.string(), [
485
+ maybeRequired(required),
486
+ maybeWithDefault(defaultValue)
487
+ ]);
488
+ return schema.describe('A time field');
489
+ };
490
+ /**
491
+ * Converts a timestamp attribute to a Zod schema for input validation.
492
+ * @param attribute - The Timestamp attribute object from the Strapi schema.
493
+ * @returns A Zod schema for input validation of the timestamp field.
494
+ */ const timestampToInputSchema = (attribute)=>{
495
+ const { required, default: defaultValue } = attribute;
496
+ const baseSchema = z.union([
497
+ z.string(),
498
+ z.number()
499
+ ]);
500
+ const schema = augmentSchema(baseSchema, [
501
+ maybeRequired(required),
502
+ maybeWithDefault(defaultValue)
503
+ ]);
504
+ return schema.describe('A timestamp field');
505
+ };
506
+ /**
507
+ * Converts a UID attribute to a Zod schema for input validation.
508
+ * @param attribute - The UID attribute object from the Strapi schema.
509
+ * @returns A Zod schema for input validation of the UID field.
510
+ */ const uidToInputSchema = (attribute)=>{
511
+ const { required, default: defaultValue, minLength, maxLength } = attribute;
512
+ const schema = augmentSchema(z.string(), [
513
+ maybeWithMinMax(minLength, maxLength),
514
+ maybeRequired(required),
515
+ maybeWithDefault(defaultValue)
516
+ ]);
517
+ return schema.describe('A UID field');
577
518
  };
578
519
 
579
- export { mapAttributeToInputSchema, mapAttributeToSchema };
520
+ export { bigIntegerToInputSchema, bigIntegerToSchema, blocksToInputSchema, blocksToSchema, booleanToInputSchema, booleanToSchema, componentToInputSchema, componentToSchema, dateToInputSchema, dateToSchema, datetimeToInputSchema, datetimeToSchema, decimalToInputSchema, decimalToSchema, dynamicZoneToInputSchema, dynamicZoneToSchema, emailToInputSchema, emailToSchema, enumToSchema, enumerationToInputSchema, floatToInputSchema, floatToSchema, integerToInputSchema, integerToSchema, jsonToInputSchema, jsonToSchema, mediaToInputSchema, mediaToSchema, relationToInputSchema, relationToSchema, stringToSchema, textToInputSchema, timeToInputSchema, timeToSchema, timestampToInputSchema, timestampToSchema, uidToInputSchema, uidToSchema };
580
521
  //# sourceMappingURL=attributes.mjs.map