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