@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.
- package/dist/Strapi.d.ts +1 -0
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +23 -2
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +23 -2
- package/dist/Strapi.mjs.map +1 -1
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +6 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +4 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/core-api/controller/index.d.ts.map +1 -1
- package/dist/core-api/controller/index.js +2 -1
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/index.mjs +2 -1
- package/dist/core-api/controller/index.mjs.map +1 -1
- package/dist/core-api/controller/transform.d.ts +3 -2
- package/dist/core-api/controller/transform.d.ts.map +1 -1
- package/dist/core-api/controller/transform.js +13 -3
- package/dist/core-api/controller/transform.js.map +1 -1
- package/dist/core-api/controller/transform.mjs +13 -3
- package/dist/core-api/controller/transform.mjs.map +1 -1
- package/dist/core-api/routes/index.d.ts.map +1 -1
- package/dist/core-api/routes/index.js +28 -9
- package/dist/core-api/routes/index.js.map +1 -1
- package/dist/core-api/routes/index.mjs +1 -1
- package/dist/core-api/routes/index.mjs.map +1 -1
- package/dist/core-api/routes/validation/attributes.d.ts +243 -90
- package/dist/core-api/routes/validation/attributes.d.ts.map +1 -1
- package/dist/core-api/routes/validation/attributes.js +541 -564
- package/dist/core-api/routes/validation/attributes.js.map +1 -1
- package/dist/core-api/routes/validation/attributes.mjs +505 -564
- package/dist/core-api/routes/validation/attributes.mjs.map +1 -1
- package/dist/core-api/routes/validation/common.d.ts +7 -5
- package/dist/core-api/routes/validation/common.d.ts.map +1 -1
- package/dist/core-api/routes/validation/common.js +29 -8
- package/dist/core-api/routes/validation/common.js.map +1 -1
- package/dist/core-api/routes/validation/common.mjs +6 -4
- package/dist/core-api/routes/validation/common.mjs.map +1 -1
- package/dist/core-api/routes/validation/component.d.ts +2 -10
- package/dist/core-api/routes/validation/component.d.ts.map +1 -1
- package/dist/core-api/routes/validation/component.js +3 -17
- package/dist/core-api/routes/validation/component.js.map +1 -1
- package/dist/core-api/routes/validation/component.mjs +3 -17
- package/dist/core-api/routes/validation/component.mjs.map +1 -1
- package/dist/core-api/routes/validation/constants.d.ts +6 -0
- package/dist/core-api/routes/validation/constants.d.ts.map +1 -1
- package/dist/core-api/routes/validation/constants.js +6 -1
- package/dist/core-api/routes/validation/constants.js.map +1 -1
- package/dist/core-api/routes/validation/constants.mjs +6 -1
- package/dist/core-api/routes/validation/constants.mjs.map +1 -1
- package/dist/core-api/routes/validation/content-type.d.ts +28 -71
- package/dist/core-api/routes/validation/content-type.d.ts.map +1 -1
- package/dist/core-api/routes/validation/content-type.js +67 -112
- package/dist/core-api/routes/validation/content-type.js.map +1 -1
- package/dist/core-api/routes/validation/content-type.mjs +36 -100
- package/dist/core-api/routes/validation/content-type.mjs.map +1 -1
- package/dist/core-api/routes/validation/index.d.ts +1 -1
- package/dist/core-api/routes/validation/index.d.ts.map +1 -1
- package/dist/core-api/routes/validation/mappers.d.ts +105 -0
- package/dist/core-api/routes/validation/mappers.d.ts.map +1 -0
- package/dist/core-api/routes/validation/mappers.js +273 -0
- package/dist/core-api/routes/validation/mappers.js.map +1 -0
- package/dist/core-api/routes/validation/mappers.mjs +249 -0
- package/dist/core-api/routes/validation/mappers.mjs.map +1 -0
- package/dist/core-api/routes/validation/utils.d.ts +47 -0
- package/dist/core-api/routes/validation/utils.d.ts.map +1 -0
- package/dist/core-api/routes/validation/utils.js +128 -0
- package/dist/core-api/routes/validation/utils.js.map +1 -0
- package/dist/core-api/routes/validation/utils.mjs +106 -0
- package/dist/core-api/routes/validation/utils.mjs.map +1 -0
- package/dist/domain/content-type/index.d.ts.map +1 -1
- package/dist/domain/content-type/index.js +17 -1
- package/dist/domain/content-type/index.js.map +1 -1
- package/dist/domain/content-type/index.mjs +17 -1
- package/dist/domain/content-type/index.mjs.map +1 -1
- package/dist/ee/index.d.ts +6 -0
- package/dist/ee/index.d.ts.map +1 -1
- package/dist/ee/index.js +29 -3
- package/dist/ee/index.js.map +1 -1
- package/dist/ee/index.mjs +30 -4
- package/dist/ee/index.mjs.map +1 -1
- package/dist/ee/license.d.ts +3 -1
- package/dist/ee/license.d.ts.map +1 -1
- package/dist/ee/license.js +6 -1
- package/dist/ee/license.js.map +1 -1
- package/dist/ee/license.mjs +6 -2
- package/dist/ee/license.mjs.map +1 -1
- package/dist/factories.js +1 -1
- package/dist/factories.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/loaders/plugins/index.js +1 -1
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/loaders/plugins/index.mjs +1 -1
- package/dist/loaders/plugins/index.mjs.map +1 -1
- package/dist/middlewares/cors.d.ts +9 -1
- package/dist/middlewares/cors.d.ts.map +1 -1
- package/dist/middlewares/cors.js +39 -17
- package/dist/middlewares/cors.js.map +1 -1
- package/dist/middlewares/cors.mjs +39 -18
- package/dist/middlewares/cors.mjs.map +1 -1
- package/dist/migrations/first-published-at.d.ts +4 -0
- package/dist/migrations/first-published-at.d.ts.map +1 -0
- package/dist/migrations/first-published-at.js +51 -0
- package/dist/migrations/first-published-at.js.map +1 -0
- package/dist/migrations/first-published-at.mjs +49 -0
- package/dist/migrations/first-published-at.mjs.map +1 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +5 -0
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/index.mjs +5 -0
- package/dist/migrations/index.mjs.map +1 -1
- package/dist/package.json.js +17 -13
- package/dist/package.json.js.map +1 -1
- package/dist/package.json.mjs +17 -13
- package/dist/package.json.mjs.map +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +2 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +2 -0
- package/dist/providers/index.mjs.map +1 -1
- package/dist/providers/session-manager.d.ts +3 -0
- package/dist/providers/session-manager.d.ts.map +1 -0
- package/dist/providers/session-manager.js +23 -0
- package/dist/providers/session-manager.js.map +1 -0
- package/dist/providers/session-manager.mjs +21 -0
- package/dist/providers/session-manager.mjs.map +1 -0
- package/dist/services/content-api/index.d.ts +1 -1
- package/dist/services/content-api/index.d.ts.map +1 -1
- package/dist/services/content-api/index.js +1 -1
- package/dist/services/content-api/index.js.map +1 -1
- package/dist/services/content-api/index.mjs +2 -2
- package/dist/services/content-api/index.mjs.map +1 -1
- package/dist/services/content-source-maps.d.ts +13 -0
- package/dist/services/content-source-maps.d.ts.map +1 -0
- package/dist/services/content-source-maps.js +108 -0
- package/dist/services/content-source-maps.js.map +1 -0
- package/dist/services/content-source-maps.mjs +106 -0
- package/dist/services/content-source-maps.mjs.map +1 -0
- package/dist/services/core-store.d.ts +2 -2
- package/dist/services/core-store.d.ts.map +1 -1
- package/dist/services/core-store.js.map +1 -1
- package/dist/services/core-store.mjs.map +1 -1
- package/dist/services/document-service/components.d.ts +31 -1
- package/dist/services/document-service/components.d.ts.map +1 -1
- package/dist/services/document-service/components.js +109 -0
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/components.mjs +107 -1
- package/dist/services/document-service/components.mjs.map +1 -1
- package/dist/services/document-service/entries.d.ts.map +1 -1
- package/dist/services/document-service/entries.js +42 -0
- package/dist/services/document-service/entries.js.map +1 -1
- package/dist/services/document-service/entries.mjs +43 -1
- package/dist/services/document-service/entries.mjs.map +1 -1
- package/dist/services/document-service/first-published-at.d.ts +7 -0
- package/dist/services/document-service/first-published-at.d.ts.map +1 -0
- package/dist/services/document-service/first-published-at.js +31 -0
- package/dist/services/document-service/first-published-at.js.map +1 -0
- package/dist/services/document-service/first-published-at.mjs +28 -0
- package/dist/services/document-service/first-published-at.mjs.map +1 -0
- package/dist/services/document-service/internationalization.d.ts +6 -1
- package/dist/services/document-service/internationalization.d.ts.map +1 -1
- package/dist/services/document-service/internationalization.js +32 -0
- package/dist/services/document-service/internationalization.js.map +1 -1
- package/dist/services/document-service/internationalization.mjs +32 -1
- package/dist/services/document-service/internationalization.mjs.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +16 -8
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +18 -10
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/utils/clean-component-join-table.d.ts +7 -0
- package/dist/services/document-service/utils/clean-component-join-table.d.ts.map +1 -0
- package/dist/services/document-service/utils/unidirectional-relations.d.ts +19 -2
- package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.js +21 -6
- package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.mjs +21 -6
- package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -1
- package/dist/services/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +9 -0
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs +9 -0
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/entity-validator/validators.d.ts +1 -0
- package/dist/services/entity-validator/validators.d.ts.map +1 -1
- package/dist/services/entity-validator/validators.js +3 -0
- package/dist/services/entity-validator/validators.js.map +1 -1
- package/dist/services/entity-validator/validators.mjs +3 -0
- package/dist/services/entity-validator/validators.mjs.map +1 -1
- package/dist/services/metrics/index.d.ts +1 -1
- package/dist/services/metrics/index.d.ts.map +1 -1
- package/dist/services/metrics/index.js +11 -9
- package/dist/services/metrics/index.js.map +1 -1
- package/dist/services/metrics/index.mjs +11 -9
- package/dist/services/metrics/index.mjs.map +1 -1
- package/dist/services/metrics/middleware.d.ts +2 -1
- package/dist/services/metrics/middleware.d.ts.map +1 -1
- package/dist/services/metrics/middleware.js +2 -2
- package/dist/services/metrics/middleware.js.map +1 -1
- package/dist/services/metrics/middleware.mjs +2 -2
- package/dist/services/metrics/middleware.mjs.map +1 -1
- package/dist/services/metrics/sender.d.ts.map +1 -1
- package/dist/services/metrics/sender.js +4 -3
- package/dist/services/metrics/sender.js.map +1 -1
- package/dist/services/metrics/sender.mjs +4 -3
- package/dist/services/metrics/sender.mjs.map +1 -1
- package/dist/services/session-manager.d.ts +167 -0
- package/dist/services/session-manager.d.ts.map +1 -0
- package/dist/services/session-manager.js +529 -0
- package/dist/services/session-manager.js.map +1 -0
- package/dist/services/session-manager.mjs +526 -0
- package/dist/services/session-manager.mjs.map +1 -0
- package/dist/services/utils/conditional-fields.d.ts +3 -0
- package/dist/services/utils/conditional-fields.d.ts.map +1 -0
- package/dist/services/utils/conditional-fields.js +22 -0
- package/dist/services/utils/conditional-fields.js.map +1 -0
- package/dist/services/utils/conditional-fields.mjs +20 -0
- package/dist/services/utils/conditional-fields.mjs.map +1 -0
- package/dist/utils/fetch.d.ts +5 -1
- package/dist/utils/fetch.d.ts.map +1 -1
- package/dist/utils/fetch.js +8 -4
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/fetch.mjs +8 -4
- package/dist/utils/fetch.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.d.ts +197 -0
- package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
- 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
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
-
* @
|
|
44
|
-
*
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
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
|
-
|
|
560
|
-
|
|
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
|
-
|
|
563
|
-
|
|
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
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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
|
-
|
|
571
|
-
|
|
572
|
-
|
|
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
|
-
|
|
576
|
-
|
|
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 {
|
|
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
|