@strapi/core 5.50.2 → 5.51.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -1
  2. package/dist/migrations/database/5.0.0-discard-drafts.js +77 -7
  3. package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
  4. package/dist/migrations/database/5.0.0-discard-drafts.mjs +77 -7
  5. package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
  6. package/dist/package.json.js +14 -14
  7. package/dist/package.json.mjs +14 -14
  8. package/dist/services/document-service/entries.d.ts.map +1 -1
  9. package/dist/services/document-service/entries.js +16 -2
  10. package/dist/services/document-service/entries.js.map +1 -1
  11. package/dist/services/document-service/entries.mjs +16 -2
  12. package/dist/services/document-service/entries.mjs.map +1 -1
  13. package/dist/services/document-service/first-published-at.d.ts.map +1 -1
  14. package/dist/services/document-service/first-published-at.js +9 -2
  15. package/dist/services/document-service/first-published-at.js.map +1 -1
  16. package/dist/services/document-service/first-published-at.mjs +9 -2
  17. package/dist/services/document-service/first-published-at.mjs.map +1 -1
  18. package/dist/services/entity-validator/index.d.ts +1 -0
  19. package/dist/services/entity-validator/index.d.ts.map +1 -1
  20. package/dist/services/entity-validator/index.js +152 -25
  21. package/dist/services/entity-validator/index.js.map +1 -1
  22. package/dist/services/entity-validator/index.mjs +152 -25
  23. package/dist/services/entity-validator/index.mjs.map +1 -1
  24. package/dist/services/entity-validator/validators.d.ts.map +1 -1
  25. package/dist/services/entity-validator/validators.js +6 -0
  26. package/dist/services/entity-validator/validators.js.map +1 -1
  27. package/dist/services/entity-validator/validators.mjs +6 -0
  28. package/dist/services/entity-validator/validators.mjs.map +1 -1
  29. package/package.json +14 -14
@@ -13,6 +13,7 @@ var strapiUtils__default = /*#__PURE__*/_interopDefault(strapiUtils);
13
13
 
14
14
  const { yup, validateYupSchema } = strapiUtils__default.default;
15
15
  const { isMediaAttribute, isScalarAttribute, getWritableAttributes } = strapiUtils__default.default.contentTypes;
16
+ const { isAnyToOne } = strapiUtils__default.default.relations;
16
17
  const { ValidationError } = strapiUtils__default.default.errors;
17
18
  const isInteger = (value)=>Number.isInteger(value);
18
19
  const addMinMax = (validator, { attr, updatedAttribute })=>{
@@ -56,7 +57,7 @@ const addDefault = (createOrUpdate)=>{
56
57
  };
57
58
  };
58
59
  const preventCast = (validator)=>validator.transform((val, originalVal)=>originalVal);
59
- const createComponentValidator = (createOrUpdate)=>({ attr, updatedAttribute, componentContext }, { isDraft })=>{
60
+ const createComponentValidator = (createOrUpdate)=>({ attr, updatedAttribute, componentContext }, options)=>{
60
61
  const model = strapi.getModel(attr.component);
61
62
  if (!model) {
62
63
  throw new Error('Validation failed: Model not found');
@@ -67,16 +68,14 @@ const createComponentValidator = (createOrUpdate)=>({ attr, updatedAttribute, co
67
68
  componentContext,
68
69
  model,
69
70
  data: item
70
- }, {
71
- isDraft
72
- }).notNull()));
71
+ }, options).notNull()));
73
72
  validator = addRequiredValidation(createOrUpdate)(validator, {
74
73
  attr: {
75
74
  required: true
76
75
  },
77
76
  updatedAttribute
78
77
  });
79
- if (!isDraft) {
78
+ if (!options.isDraft) {
80
79
  validator = addMinMax(validator, {
81
80
  attr,
82
81
  updatedAttribute
@@ -88,18 +87,16 @@ const createComponentValidator = (createOrUpdate)=>({ attr, updatedAttribute, co
88
87
  model,
89
88
  data: updatedAttribute.value,
90
89
  componentContext
91
- }, {
92
- isDraft
93
- });
90
+ }, options);
94
91
  validator = addRequiredValidation(createOrUpdate)(validator, {
95
92
  attr: {
96
- required: !isDraft && attr.required
93
+ required: !options.isDraft && attr.required
97
94
  },
98
95
  updatedAttribute
99
96
  });
100
97
  return validator;
101
98
  };
102
- const createDzValidator = (createOrUpdate)=>({ attr, updatedAttribute, componentContext }, { isDraft })=>{
99
+ const createDzValidator = (createOrUpdate)=>({ attr, updatedAttribute, componentContext }, options)=>{
103
100
  let validator;
104
101
  validator = yup.array().of(yup.lazy((item)=>{
105
102
  const model = strapi.getModel(fp.prop('__component', item));
@@ -110,9 +107,7 @@ const createDzValidator = (createOrUpdate)=>({ attr, updatedAttribute, component
110
107
  model,
111
108
  data: item,
112
109
  componentContext
113
- }, {
114
- isDraft
115
- })) : schema;
110
+ }, options)) : schema;
116
111
  }));
117
112
  validator = addRequiredValidation(createOrUpdate)(validator, {
118
113
  attr: {
@@ -120,7 +115,7 @@ const createDzValidator = (createOrUpdate)=>({ attr, updatedAttribute, component
120
115
  },
121
116
  updatedAttribute
122
117
  });
123
- if (!isDraft) {
118
+ if (!options.isDraft) {
124
119
  validator = addMinMax(validator, {
125
120
  attr,
126
121
  updatedAttribute
@@ -128,15 +123,143 @@ const createDzValidator = (createOrUpdate)=>({ attr, updatedAttribute, component
128
123
  }
129
124
  return validator;
130
125
  };
131
- const createRelationValidator = ({ updatedAttribute })=>{
132
- let validator;
133
- if (Array.isArray(updatedAttribute.value)) {
134
- validator = yup.array().of(yup.mixed());
135
- } else {
136
- validator = yup.mixed();
126
+ /**
127
+ * A relation/media value can be supplied in several shapes: a bare id, an array of ids,
128
+ * or a connect/set object (`{ connect: [...] }` / `{ set: [...] }`). This normalises all
129
+ * of them to "does this attach at least one entry?" so required validation is consistent
130
+ * regardless of the input shape (mirrors `buildRelationsStore`'s source extraction).
131
+ */ const hasRelationValue = (value)=>{
132
+ if (_.isNil(value)) {
133
+ return false;
134
+ }
135
+ if (Array.isArray(value)) {
136
+ return value.length > 0;
137
+ }
138
+ if (fp.isObject(value)) {
139
+ const connect = value.connect;
140
+ const set = value.set;
141
+ if (!_.isNil(connect)) {
142
+ return Array.isArray(connect) ? connect.length > 0 : true;
143
+ }
144
+ if (!_.isNil(set)) {
145
+ return Array.isArray(set) ? set.length > 0 : true;
146
+ }
147
+ // Any other object shape (e.g. a bare `{ id }`) counts as a value.
148
+ return true;
149
+ }
150
+ return true;
151
+ };
152
+ /**
153
+ * A disconnect-only update payload removes entries without adding or replacing any:
154
+ * actual removals in `disconnect`, no `set`, and no effective additions in `connect`.
155
+ * `connect` counts as "no additions" when absent OR an empty array — the Content Manager
156
+ * initializes every relation as `{ connect: [], disconnect: [] }` and keeps `connect: []`
157
+ * in place when the user only removes entries, so `{ connect: [], disconnect: [id] }`
158
+ * is the shape real admin saves produce. A payload with empty `disconnect` (nothing
159
+ * removed) is NOT disconnect-only — it's the CM's untouched-relation no-op.
160
+ */ const isDisconnectOnly = (value)=>{
161
+ if (!fp.isObject(value)) {
162
+ return false;
163
+ }
164
+ const { connect, set, disconnect } = value;
165
+ if (!_.isNil(set)) {
166
+ return false;
167
+ }
168
+ const hasAdditions = !_.isNil(connect) && (!Array.isArray(connect) || connect.length > 0);
169
+ if (hasAdditions) {
170
+ return false;
171
+ }
172
+ return !_.isNil(disconnect) && (!Array.isArray(disconnect) || disconnect.length > 0);
173
+ };
174
+ /**
175
+ * Decides whether a required media/relation value should be rejected as empty,
176
+ * mirroring the scalar `required` semantics:
177
+ *
178
+ * - creation (`notNil` analogue): an absent key is a failure — the field must be
179
+ * populated, so anything without a value (`undefined`/`null`/`[]`/empty `set`/`connect`)
180
+ * is rejected.
181
+ * - update (`notNull` analogue): an absent key keeps the existing value, so it passes.
182
+ * Only reject when the request is present AND leaves the field empty. A bare
183
+ * `{ connect: [] }` (no `set`) neither adds nor removes anything → treated as a no-op
184
+ * that passes; `{ set: [] }` / `null` / `[]` explicitly empty the field → rejected.
185
+ *
186
+ * `isToOne` marks a to-one relation / single media, which can hold at most one entry.
187
+ * For those, a disconnect-only update (`{ disconnect: [...] }` with no `connect`/`set`)
188
+ * always leaves the field empty — no DB read needed — so it is rejected on non-draft
189
+ * updates. To-many fields can still hold other entries after a disconnect, so their
190
+ * resulting state can't be known without a DB read and they fall through to a pass
191
+ * (publish re-validates the populated draft for D&P types; documented limitation for
192
+ * non-D&P, tied to the null→[] follow-up).
193
+ *
194
+ * On creation there are no existing rows, so a disconnect-only payload attaches nothing
195
+ * and always leaves the field empty — for both to-one and to-many — so it is rejected
196
+ * regardless of `isToOne`.
197
+ */ const relationRequiredFails = (createOrUpdate, value, isToOne)=>{
198
+ if (createOrUpdate === 'creation') {
199
+ // No existing rows on create, so a disconnect attaches nothing and the field stays
200
+ // empty for both to-one and to-many — reject it before the generic value check, which
201
+ // would otherwise treat the bare `{ disconnect: [...] }` object as a present value.
202
+ if (isDisconnectOnly(value)) {
203
+ return true;
204
+ }
205
+ }
206
+ if (createOrUpdate === 'update') {
207
+ // Absent key on update = keep the existing value.
208
+ if (value === undefined) {
209
+ return false;
210
+ }
211
+ if (isDisconnectOnly(value)) {
212
+ // A disconnect on a to-one/single field deterministically empties it; on a to-many
213
+ // field the resulting state depends on the current DB rows, so we can't reject here.
214
+ return isToOne;
215
+ }
216
+ // A connect-only empty is a no-op, not an emptying operation.
217
+ if (fp.isObject(value) && !_.isNil(value.connect)) {
218
+ const connect = value.connect;
219
+ const hasSet = !_.isNil(value.set);
220
+ if (!hasSet && Array.isArray(connect) && connect.length === 0) {
221
+ return false;
222
+ }
223
+ }
137
224
  }
138
- return validator;
225
+ return !hasRelationValue(value);
139
226
  };
227
+ const createMediaAttributeValidator = (createOrUpdate)=>({ attr, updatedAttribute }, options)=>{
228
+ // Media values arrive in several shapes (a bare id, an array of ids, or a
229
+ // `{ connect }` / `{ set }` object on update). `yup.mixed()` accepts all of them;
230
+ // coercing `multiple` media to `yup.array()` would reject the connect/set object
231
+ // syntax that update requests legitimately send. Required-ness is asserted below
232
+ // via `relationRequiredFails`, which understands every shape.
233
+ let validator = yup.mixed();
234
+ // Relational required constraints are only enforced under the strictRelations flag,
235
+ // and never for drafts (mirrors scalar `required` handling via `!isDraft`).
236
+ if (options.strictRelations && !options.isDraft && attr.required) {
237
+ // A media value can arrive as an id, an array, or a connect/set object, so a simple
238
+ // `.notNil()`/`.min()` is not enough — normalise the shape before asserting.
239
+ // Single media holds at most one file, so a disconnect-only update always empties it.
240
+ const isToOne = !attr.multiple;
241
+ validator = validator.test('required-media', `${updatedAttribute.name} must be defined.`, ()=>!relationRequiredFails(createOrUpdate, updatedAttribute.value, isToOne));
242
+ }
243
+ return validator;
244
+ };
245
+ const createRelationValidator = (createOrUpdate)=>({ attr, updatedAttribute }, options)=>{
246
+ let validator;
247
+ if (Array.isArray(updatedAttribute.value)) {
248
+ validator = yup.array().of(yup.mixed());
249
+ } else {
250
+ validator = yup.mixed();
251
+ }
252
+ // Relational required constraints are only enforced under the strictRelations flag,
253
+ // and never for drafts (mirrors scalar `required` handling via `!isDraft`).
254
+ if (options.strictRelations && !options.isDraft && attr.required) {
255
+ // A relation value can arrive as an id, an array, or a connect/set object, so a
256
+ // simple `.notNil()`/`.min()` is not enough — normalise the shape before asserting.
257
+ // A to-one relation holds at most one target, so a disconnect-only update always empties it.
258
+ const isToOne = isAnyToOne(attr);
259
+ validator = validator.test('required-relation', `${updatedAttribute.name} must be defined.`, ()=>!relationRequiredFails(createOrUpdate, updatedAttribute.value, isToOne));
260
+ }
261
+ return validator;
262
+ };
140
263
  const createScalarAttributeValidator = (createOrUpdate)=>(metas, options)=>{
141
264
  let validator;
142
265
  if (fp.has(metas.attr.type, validators.Validators)) {
@@ -163,7 +286,10 @@ const createAttributeValidator = (createOrUpdate)=>(metas, options)=>{
163
286
  }
164
287
  }
165
288
  if (isMediaAttribute(metas.attr)) {
166
- validator = yup.mixed();
289
+ validator = createMediaAttributeValidator(createOrUpdate)({
290
+ attr: metas.attr,
291
+ updatedAttribute: metas.updatedAttribute
292
+ }, options);
167
293
  } else if (isScalarAttribute(metas.attr)) {
168
294
  validator = createScalarAttributeValidator(createOrUpdate)(metas, options);
169
295
  } else {
@@ -204,10 +330,10 @@ const createAttributeValidator = (createOrUpdate)=>(metas, options)=>{
204
330
  });
205
331
  validator = createDzValidator(createOrUpdate)(metas, options);
206
332
  } else if (metas.attr.type === 'relation') {
207
- validator = createRelationValidator({
333
+ validator = createRelationValidator(createOrUpdate)({
208
334
  attr: metas.attr,
209
335
  updatedAttribute: metas.updatedAttribute
210
- });
336
+ }, options);
211
337
  }
212
338
  validator = preventCast(validator);
213
339
  }
@@ -258,7 +384,8 @@ const createValidateEntity = (createOrUpdate)=>{
258
384
  }
259
385
  }, {
260
386
  isDraft: options?.isDraft ?? false,
261
- locale: options?.locale ?? null
387
+ locale: options?.locale ?? null,
388
+ strictRelations: options?.strictRelations ?? false
262
389
  }).test('relations-test', 'check that all relations exist', async function relationsValidation(data) {
263
390
  try {
264
391
  await checkRelationsExist(buildRelationsStore({
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/services/entity-validator/index.ts"],"sourcesContent":["/**\n * Entity validator\n * Module that will validate input data for entity creation or edition\n */\n\nimport { uniqBy, castArray, isNil, isArray, mergeWith } from 'lodash';\nimport { has, prop, isObject, isEmpty } from 'lodash/fp';\nimport jsonLogic from 'json-logic-js';\nimport strapiUtils from '@strapi/utils';\nimport type { Modules, UID, Struct, Schema } from '@strapi/types';\nimport { Validators, ValidatorMetas } from './validators';\n\ntype CreateOrUpdate = 'creation' | 'update';\n\nconst { yup, validateYupSchema } = strapiUtils;\nconst { isMediaAttribute, isScalarAttribute, getWritableAttributes } = strapiUtils.contentTypes;\nconst { ValidationError } = strapiUtils.errors;\n\ntype ID = { id: string | number };\n\ntype RelationSource = string | number | ID;\n\nexport type ComponentContext = {\n parentContent: {\n // The model of the parent content type that contains the current component.\n model: Struct.Schema;\n // The numeric id of the parent entity that contains the component.\n id?: number;\n // The options passed to the entity validator. From which we can extract\n // entity dimensions such as locale and publication state.\n options?: ValidatorContext;\n };\n // The path to the component within the parent content type schema.\n pathToComponent: string[];\n // If working with a repeatable component this contains the\n // full data of the repeatable component in the current entity.\n repeatableData: Modules.EntityValidator.Entity[];\n fullDynamicZoneContent?: Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\n};\n\ninterface WithComponentContext {\n componentContext?: ComponentContext;\n}\n\ninterface ValidatorMeta<TAttribute = Schema.Attribute.AnyAttribute> extends WithComponentContext {\n attr: TAttribute;\n updatedAttribute: { name: string; value: any };\n}\n\ninterface ValidatorContext {\n isDraft?: boolean;\n locale?: string | null;\n}\n\ninterface ModelValidatorMetas extends WithComponentContext {\n model: Struct.Schema;\n data: Record<string, unknown>;\n entity?: Modules.EntityValidator.Entity;\n}\n\nconst isInteger = (value: unknown): value is number => Number.isInteger(value);\n\nconst addMinMax = <\n T extends {\n min(value: number): T;\n max(value: number): T;\n },\n>(\n validator: T,\n {\n attr,\n updatedAttribute,\n }: ValidatorMeta<Schema.Attribute.AnyAttribute & Schema.Attribute.MinMaxOption<string | number>>\n): T => {\n let nextValidator: T = validator;\n\n if (\n isInteger(attr.min) &&\n (('required' in attr && attr.required) ||\n (Array.isArray(updatedAttribute.value) && updatedAttribute.value.length > 0))\n ) {\n nextValidator = nextValidator.min(attr.min);\n }\n if (isInteger(attr.max)) {\n nextValidator = nextValidator.max(attr.max);\n }\n return nextValidator;\n};\n\nconst addRequiredValidation = (createOrUpdate: CreateOrUpdate) => {\n return <T extends strapiUtils.yup.AnySchema>(\n validator: T,\n {\n attr: { required },\n }: ValidatorMeta<Partial<Schema.Attribute.AnyAttribute & Schema.Attribute.RequiredOption>>\n ): T => {\n let nextValidator = validator;\n\n if (required) {\n if (createOrUpdate === 'creation') {\n nextValidator = nextValidator.notNil();\n } else if (createOrUpdate === 'update') {\n nextValidator = nextValidator.notNull();\n }\n } else {\n nextValidator = nextValidator.nullable();\n }\n return nextValidator;\n };\n};\n\nconst addDefault = (createOrUpdate: CreateOrUpdate) => {\n return (\n validator: strapiUtils.yup.BaseSchema,\n { attr }: ValidatorMeta<Schema.Attribute.AnyAttribute & Schema.Attribute.DefaultOption<unknown>>\n ) => {\n let nextValidator = validator;\n\n if (createOrUpdate === 'creation') {\n if (\n ((attr.type === 'component' && attr.repeatable) || attr.type === 'dynamiczone') &&\n !attr.required\n ) {\n nextValidator = nextValidator.default([]);\n } else {\n nextValidator = nextValidator.default(attr.default);\n }\n } else {\n nextValidator = nextValidator.default(undefined);\n }\n\n return nextValidator;\n };\n};\n\nconst preventCast = (validator: strapiUtils.yup.AnySchema) =>\n validator.transform((val, originalVal) => originalVal);\n\nconst createComponentValidator =\n (createOrUpdate: CreateOrUpdate) =>\n (\n {\n attr,\n updatedAttribute,\n componentContext,\n }: ValidatorMeta<Schema.Attribute.Component<UID.Component, boolean>>,\n { isDraft }: ValidatorContext\n ): strapiUtils.yup.AnySchema => {\n const model = strapi.getModel(attr.component);\n if (!model) {\n throw new Error('Validation failed: Model not found');\n }\n\n if (attr?.repeatable) {\n // FIXME: yup v1\n\n let validator = yup\n .array()\n .of(\n yup.lazy((item) =>\n createModelValidator(createOrUpdate)(\n { componentContext, model, data: item },\n { isDraft }\n ).notNull()\n ) as any\n );\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: true },\n updatedAttribute,\n });\n\n if (!isDraft) {\n validator = addMinMax(validator, { attr, updatedAttribute });\n }\n\n return validator;\n }\n\n let validator = createModelValidator(createOrUpdate)(\n {\n model,\n data: updatedAttribute.value,\n componentContext,\n },\n { isDraft }\n );\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: !isDraft && attr.required },\n updatedAttribute,\n });\n\n return validator;\n };\n\nconst createDzValidator =\n (createOrUpdate: CreateOrUpdate) =>\n (\n { attr, updatedAttribute, componentContext }: ValidatorMeta,\n { isDraft }: ValidatorContext\n ): strapiUtils.yup.AnySchema => {\n let validator;\n\n validator = yup.array().of(\n yup.lazy((item) => {\n const model = strapi.getModel(prop('__component', item));\n const schema = yup\n .object()\n .shape({\n __component: yup.string().required().oneOf(Object.keys(strapi.components)),\n })\n .notNull();\n\n return model\n ? schema.concat(\n createModelValidator(createOrUpdate)(\n { model, data: item, componentContext },\n { isDraft }\n )\n )\n : schema;\n }) as any // FIXME: yup v1\n );\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: true },\n updatedAttribute,\n });\n\n if (!isDraft) {\n validator = addMinMax(validator, { attr, updatedAttribute });\n }\n\n return validator;\n };\n\nconst createRelationValidator = ({\n updatedAttribute,\n}: ValidatorMeta<Schema.Attribute.Relation>) => {\n let validator;\n\n if (Array.isArray(updatedAttribute.value)) {\n validator = yup.array().of(yup.mixed());\n } else {\n validator = yup.mixed();\n }\n\n return validator;\n};\n\nconst createScalarAttributeValidator =\n (createOrUpdate: CreateOrUpdate) => (metas: ValidatorMeta, options: ValidatorContext) => {\n let validator;\n\n if (has(metas.attr.type, Validators)) {\n validator = (Validators as any)[metas.attr.type](metas, options);\n } else {\n // No validators specified - fall back to mixed\n validator = yup.mixed();\n }\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: !options.isDraft && metas.attr.required },\n updatedAttribute: metas.updatedAttribute,\n });\n\n return validator;\n };\n\nconst createAttributeValidator =\n (createOrUpdate: CreateOrUpdate) =>\n (metas: ValidatorMetas, options: ValidatorContext): strapiUtils.yup.AnySchema => {\n let validator = yup.mixed();\n\n // If field is conditionally invisible, skip all validation for it\n if (metas.attr.conditions?.visible) {\n const isVisible = jsonLogic.apply(metas.attr.conditions.visible, metas.data);\n\n if (!isVisible) {\n return yup.mixed().notRequired(); // Completely skip validation\n }\n }\n\n if (isMediaAttribute(metas.attr)) {\n validator = yup.mixed();\n } else if (isScalarAttribute(metas.attr)) {\n validator = createScalarAttributeValidator(createOrUpdate)(metas, options);\n } else {\n if (metas.attr.type === 'component' && metas.componentContext) {\n // Build the path to the component within the parent content type schema.\n const pathToComponent = [\n ...(metas?.componentContext?.pathToComponent ?? []),\n metas.updatedAttribute.name,\n ];\n\n // If working with a repeatable component, determine the repeatable data\n // based on the component's path.\n\n // In order to validate the repeatable within this entity we need\n // access to the full repeatable data. In case we are validating a\n // nested component within a repeatable.\n // Hence why we set this up when the path to the component is only one level deep.\n const repeatableData = (\n metas.attr.repeatable && pathToComponent.length === 1\n ? metas.updatedAttribute.value\n : metas.componentContext?.repeatableData\n ) as Modules.EntityValidator.Entity[];\n\n const newComponentContext: ComponentContext = {\n ...metas.componentContext,\n pathToComponent,\n repeatableData,\n };\n\n validator = createComponentValidator(createOrUpdate)(\n {\n componentContext: newComponentContext,\n attr: metas.attr,\n updatedAttribute: metas.updatedAttribute,\n },\n options\n );\n } else if (metas.attr.type === 'dynamiczone' && metas.componentContext) {\n const newComponentContext: ComponentContext = {\n ...metas.componentContext,\n fullDynamicZoneContent: metas.updatedAttribute.value,\n pathToComponent: [...metas.componentContext.pathToComponent, metas.updatedAttribute.name],\n };\n\n Object.assign(metas, { componentContext: newComponentContext });\n\n validator = createDzValidator(createOrUpdate)(metas, options);\n } else if (metas.attr.type === 'relation') {\n validator = createRelationValidator({\n attr: metas.attr,\n updatedAttribute: metas.updatedAttribute,\n });\n }\n\n validator = preventCast(validator);\n }\n\n validator = addDefault(createOrUpdate)(validator, metas);\n\n return validator;\n };\n\nconst createModelValidator =\n (createOrUpdate: CreateOrUpdate) =>\n (\n { componentContext, model, data, entity }: ModelValidatorMetas,\n options: ValidatorContext\n ): strapiUtils.yup.AnyObjectSchema => {\n const writableAttributes = model ? getWritableAttributes(model as any) : [];\n\n const schema = writableAttributes.reduce(\n (validators, attributeName) => {\n const metas = {\n attr: model.attributes[attributeName],\n updatedAttribute: { name: attributeName, value: prop(attributeName, data) },\n data,\n model,\n entity,\n componentContext,\n };\n\n const validator = createAttributeValidator(createOrUpdate)(metas, options);\n\n validators[attributeName] = validator;\n\n return validators;\n },\n {} as Record<string, strapiUtils.yup.BaseSchema>\n );\n\n return yup.object().shape(schema);\n };\n\nconst createValidateEntity = (createOrUpdate: CreateOrUpdate) => {\n return async <\n TUID extends UID.ContentType,\n TData extends Modules.EntityService.Params.Data.Input<TUID>,\n >(\n model: Schema.ContentType<TUID>,\n data: TData | Partial<TData> | undefined,\n options?: ValidatorContext,\n entity?: Modules.EntityValidator.Entity\n ): Promise<TData> => {\n if (!isObject(data)) {\n const { displayName } = model.info;\n\n throw new ValidationError(\n `Invalid payload submitted for the ${createOrUpdate} of an entity of type ${displayName}. Expected an object, but got ${typeof data}`\n );\n }\n\n const validator = createModelValidator(createOrUpdate)(\n {\n model,\n data,\n entity,\n componentContext: {\n // Set up the initial component context.\n // Keeping track of parent content type context in which a component will be used.\n // This is necessary to validate component field constraints such as uniqueness.\n parentContent: {\n id: entity?.id,\n model,\n options,\n },\n pathToComponent: [],\n repeatableData: [],\n },\n },\n {\n isDraft: options?.isDraft ?? false,\n locale: options?.locale ?? null,\n }\n )\n .test(\n 'relations-test',\n 'check that all relations exist',\n async function relationsValidation(data) {\n try {\n await checkRelationsExist(buildRelationsStore({ uid: model.uid, data }));\n } catch (e) {\n return this.createError({\n path: this.path,\n message: (e instanceof ValidationError && e.message) || 'Invalid relations',\n });\n }\n return true;\n }\n )\n .required();\n\n return validateYupSchema(validator, {\n strict: false,\n abortEarly: false,\n })(data);\n };\n};\n\n/**\n * Builds an object containing all the media and relations being associated with an entity\n */\nconst buildRelationsStore = <TUID extends UID.Schema>({\n uid,\n data,\n}: {\n uid: TUID;\n data: Record<string, unknown> | null;\n}): Record<string, ID[]> => {\n if (!uid) {\n throw new ValidationError(`Cannot build relations store: \"uid\" is undefined`);\n }\n\n if (isEmpty(data)) {\n return {};\n }\n\n const currentModel = strapi.getModel(uid);\n\n return Object.keys(currentModel.attributes).reduce(\n (result, attributeName: string) => {\n const attribute = currentModel.attributes[attributeName];\n const value = data[attributeName];\n\n if (isNil(value)) {\n return result;\n }\n\n switch (attribute.type) {\n case 'relation':\n case 'media': {\n if (\n attribute.type === 'relation' &&\n (attribute.relation === 'morphToMany' || attribute.relation === 'morphToOne')\n ) {\n // TODO: handle polymorphic relations\n break;\n }\n\n const target =\n // eslint-disable-next-line no-nested-ternary\n attribute.type === 'media' ? 'plugin::upload.file' : attribute.target;\n // As there are multiple formats supported for associating relations\n // with an entity, the value here can be an: array, object or number.\n let source: RelationSource[];\n if (Array.isArray(value)) {\n source = value;\n } else if (isObject(value)) {\n if ('connect' in value && !isNil(value.connect)) {\n source = value.connect as RelationSource[];\n } else if ('set' in value && !isNil(value.set)) {\n source = value.set as RelationSource[];\n } else {\n source = [];\n }\n } else {\n source = castArray(value as RelationSource);\n }\n const idArray = source.map((v) => ({\n id: typeof v === 'object' ? v.id : v,\n }));\n\n // Update the relationStore to keep track of all associations being made\n // with relations and media.\n result[target] = result[target] || [];\n result[target].push(...idArray);\n break;\n }\n case 'component': {\n return castArray(value).reduce((relationsStore, componentValue) => {\n if (!attribute.component) {\n throw new ValidationError(\n `Cannot build relations store from component, component identifier is undefined`\n );\n }\n\n return mergeWith(\n relationsStore,\n buildRelationsStore({\n uid: attribute.component,\n data: componentValue as Record<string, unknown>,\n }),\n (objValue, srcValue) => {\n if (isArray(objValue)) {\n return objValue.concat(srcValue);\n }\n }\n );\n }, result) as Record<string, ID[]>;\n }\n case 'dynamiczone': {\n return castArray(value).reduce((relationsStore, dzValue) => {\n const value = dzValue as Record<string, unknown>;\n if (!value.__component) {\n throw new ValidationError(\n `Cannot build relations store from dynamiczone, component identifier is undefined`\n );\n }\n\n return mergeWith(\n relationsStore,\n buildRelationsStore({\n uid: value.__component as UID.Component,\n data: value,\n }),\n (objValue, srcValue) => {\n if (isArray(objValue)) {\n return objValue.concat(srcValue);\n }\n }\n );\n }, result) as Record<string, ID[]>;\n }\n default:\n break;\n }\n\n return result;\n },\n {} as Record<string, ID[]>\n );\n};\n\n/**\n * Iterate through the relations store and validates that every relation or media\n * mentioned exists\n */\nconst checkRelationsExist = async (relationsStore: Record<string, ID[]> = {}) => {\n const promises: Promise<void>[] = [];\n\n for (const [key, value] of Object.entries(relationsStore)) {\n const evaluate = async () => {\n const uniqueValues = uniqBy(value, `id`);\n const count = await strapi.db.query(key as UID.Schema).count({\n where: {\n id: {\n $in: uniqueValues.map((v) => v.id),\n },\n },\n });\n\n if (count !== uniqueValues.length) {\n throw new ValidationError(\n `${\n uniqueValues.length - count\n } relation(s) of type ${key} associated with this entity do not exist`\n );\n }\n };\n promises.push(evaluate());\n }\n\n return Promise.all(promises);\n};\n\nconst entityValidator: Modules.EntityValidator.EntityValidator = {\n validateEntityCreation: createValidateEntity('creation'),\n validateEntityUpdate: createValidateEntity('update'),\n};\n\nexport default entityValidator;\n"],"names":["yup","validateYupSchema","strapiUtils","isMediaAttribute","isScalarAttribute","getWritableAttributes","contentTypes","ValidationError","errors","isInteger","value","Number","addMinMax","validator","attr","updatedAttribute","nextValidator","min","required","Array","isArray","length","max","addRequiredValidation","createOrUpdate","notNil","notNull","nullable","addDefault","type","repeatable","default","undefined","preventCast","transform","val","originalVal","createComponentValidator","componentContext","isDraft","model","strapi","getModel","component","Error","array","of","lazy","item","createModelValidator","data","createDzValidator","prop","schema","object","shape","__component","string","oneOf","Object","keys","components","concat","createRelationValidator","mixed","createScalarAttributeValidator","metas","options","has","Validators","createAttributeValidator","conditions","visible","isVisible","jsonLogic","apply","notRequired","pathToComponent","name","repeatableData","newComponentContext","fullDynamicZoneContent","assign","entity","writableAttributes","reduce","validators","attributeName","attributes","createValidateEntity","isObject","displayName","info","parentContent","id","locale","test","relationsValidation","checkRelationsExist","buildRelationsStore","uid","e","createError","path","message","strict","abortEarly","isEmpty","currentModel","result","attribute","isNil","relation","target","source","connect","set","castArray","idArray","map","v","push","relationsStore","componentValue","mergeWith","objValue","srcValue","dzValue","promises","key","entries","evaluate","uniqueValues","uniqBy","count","db","query","where","$in","Promise","all","entityValidator","validateEntityCreation","validateEntityUpdate"],"mappings":";;;;;;;;;;;;;AAcA,MAAM,EAAEA,GAAG,EAAEC,iBAAiB,EAAE,GAAGC,4BAAAA;AACnC,MAAM,EAAEC,gBAAgB,EAAEC,iBAAiB,EAAEC,qBAAqB,EAAE,GAAGH,4BAAAA,CAAYI,YAAY;AAC/F,MAAM,EAAEC,eAAe,EAAE,GAAGL,6BAAYM,MAAM;AA4C9C,MAAMC,SAAAA,GAAY,CAACC,KAAAA,GAAoCC,MAAAA,CAAOF,SAAS,CAACC,KAAAA,CAAAA;AAExE,MAAME,YAAY,CAMhBC,SAAAA,EACA,EACEC,IAAI,EACJC,gBAAgB,EAC8E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IwC,KAAAA,KAAUF,YAAAA,CAAa/G,MAAM,EAAE;gBACjC,MAAM,IAAId,eAAAA,CACR,CAAA,EACE6H,YAAAA,CAAa/G,MAAM,GAAGiH,KAAAA,CACvB,qBAAqB,EAAEL,GAAAA,CAAI,yCAAyC,CAAC,CAAA;AAE1E,YAAA;AACF,QAAA,CAAA;AACAD,QAAAA,QAAAA,CAASP,IAAI,CAACU,QAAAA,EAAAA,CAAAA;AAChB,IAAA;IAEA,OAAOQ,OAAAA,CAAQC,GAAG,CAACZ,QAAAA,CAAAA;AACrB,CAAA;AAEA,MAAMa,eAAAA,GAA2D;AAC/DC,IAAAA,sBAAAA,EAAwBrD,oBAAAA,CAAqB,UAAA,CAAA;AAC7CsD,IAAAA,oBAAAA,EAAsBtD,oBAAAA,CAAqB,QAAA;AAC7C;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/services/entity-validator/index.ts"],"sourcesContent":["/**\n * Entity validator\n * Module that will validate input data for entity creation or edition\n */\n\nimport { uniqBy, castArray, isNil, isArray, mergeWith } from 'lodash';\nimport { has, prop, isObject, isEmpty } from 'lodash/fp';\nimport jsonLogic from 'json-logic-js';\nimport strapiUtils from '@strapi/utils';\nimport type { Modules, UID, Struct, Schema } from '@strapi/types';\nimport { Validators, ValidatorMetas } from './validators';\n\ntype CreateOrUpdate = 'creation' | 'update';\n\nconst { yup, validateYupSchema } = strapiUtils;\nconst { isMediaAttribute, isScalarAttribute, getWritableAttributes } = strapiUtils.contentTypes;\nconst { isAnyToOne } = strapiUtils.relations;\nconst { ValidationError } = strapiUtils.errors;\n\ntype ID = { id: string | number };\n\ntype RelationSource = string | number | ID;\n\nexport type ComponentContext = {\n parentContent: {\n // The model of the parent content type that contains the current component.\n model: Struct.Schema;\n // The numeric id of the parent entity that contains the component.\n id?: number;\n // The options passed to the entity validator. From which we can extract\n // entity dimensions such as locale and publication state.\n options?: ValidatorContext;\n };\n // The path to the component within the parent content type schema.\n pathToComponent: string[];\n // If working with a repeatable component this contains the\n // full data of the repeatable component in the current entity.\n repeatableData: Modules.EntityValidator.Entity[];\n fullDynamicZoneContent?: Schema.Attribute.Value<Schema.Attribute.DynamicZone>;\n};\n\ninterface WithComponentContext {\n componentContext?: ComponentContext;\n}\n\ninterface ValidatorMeta<TAttribute = Schema.Attribute.AnyAttribute> extends WithComponentContext {\n attr: TAttribute;\n updatedAttribute: { name: string; value: any };\n}\n\ninterface ValidatorContext {\n isDraft?: boolean;\n locale?: string | null;\n strictRelations?: boolean;\n}\n\ninterface ModelValidatorMetas extends WithComponentContext {\n model: Struct.Schema;\n data: Record<string, unknown>;\n entity?: Modules.EntityValidator.Entity;\n}\n\nconst isInteger = (value: unknown): value is number => Number.isInteger(value);\n\nconst addMinMax = <\n T extends {\n min(value: number): T;\n max(value: number): T;\n },\n>(\n validator: T,\n {\n attr,\n updatedAttribute,\n }: ValidatorMeta<Schema.Attribute.AnyAttribute & Schema.Attribute.MinMaxOption<string | number>>\n): T => {\n let nextValidator: T = validator;\n\n if (\n isInteger(attr.min) &&\n (('required' in attr && attr.required) ||\n (Array.isArray(updatedAttribute.value) && updatedAttribute.value.length > 0))\n ) {\n nextValidator = nextValidator.min(attr.min);\n }\n if (isInteger(attr.max)) {\n nextValidator = nextValidator.max(attr.max);\n }\n return nextValidator;\n};\n\nconst addRequiredValidation = (createOrUpdate: CreateOrUpdate) => {\n return <T extends strapiUtils.yup.AnySchema>(\n validator: T,\n {\n attr: { required },\n }: ValidatorMeta<Partial<Schema.Attribute.AnyAttribute & Schema.Attribute.RequiredOption>>\n ): T => {\n let nextValidator = validator;\n\n if (required) {\n if (createOrUpdate === 'creation') {\n nextValidator = nextValidator.notNil();\n } else if (createOrUpdate === 'update') {\n nextValidator = nextValidator.notNull();\n }\n } else {\n nextValidator = nextValidator.nullable();\n }\n return nextValidator;\n };\n};\n\nconst addDefault = (createOrUpdate: CreateOrUpdate) => {\n return (\n validator: strapiUtils.yup.BaseSchema,\n { attr }: ValidatorMeta<Schema.Attribute.AnyAttribute & Schema.Attribute.DefaultOption<unknown>>\n ) => {\n let nextValidator = validator;\n\n if (createOrUpdate === 'creation') {\n if (\n ((attr.type === 'component' && attr.repeatable) || attr.type === 'dynamiczone') &&\n !attr.required\n ) {\n nextValidator = nextValidator.default([]);\n } else {\n nextValidator = nextValidator.default(attr.default);\n }\n } else {\n nextValidator = nextValidator.default(undefined);\n }\n\n return nextValidator;\n };\n};\n\nconst preventCast = (validator: strapiUtils.yup.AnySchema) =>\n validator.transform((val, originalVal) => originalVal);\n\nconst createComponentValidator =\n (createOrUpdate: CreateOrUpdate) =>\n (\n {\n attr,\n updatedAttribute,\n componentContext,\n }: ValidatorMeta<Schema.Attribute.Component<UID.Component, boolean>>,\n options: ValidatorContext\n ): strapiUtils.yup.AnySchema => {\n const model = strapi.getModel(attr.component);\n if (!model) {\n throw new Error('Validation failed: Model not found');\n }\n\n if (attr?.repeatable) {\n // FIXME: yup v1\n\n let validator = yup\n .array()\n .of(\n yup.lazy((item) =>\n createModelValidator(createOrUpdate)(\n { componentContext, model, data: item },\n options\n ).notNull()\n ) as any\n );\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: true },\n updatedAttribute,\n });\n\n if (!options.isDraft) {\n validator = addMinMax(validator, { attr, updatedAttribute });\n }\n\n return validator;\n }\n\n let validator = createModelValidator(createOrUpdate)(\n {\n model,\n data: updatedAttribute.value,\n componentContext,\n },\n options\n );\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: !options.isDraft && attr.required },\n updatedAttribute,\n });\n\n return validator;\n };\n\nconst createDzValidator =\n (createOrUpdate: CreateOrUpdate) =>\n (\n { attr, updatedAttribute, componentContext }: ValidatorMeta,\n options: ValidatorContext\n ): strapiUtils.yup.AnySchema => {\n let validator;\n\n validator = yup.array().of(\n yup.lazy((item) => {\n const model = strapi.getModel(prop('__component', item));\n const schema = yup\n .object()\n .shape({\n __component: yup.string().required().oneOf(Object.keys(strapi.components)),\n })\n .notNull();\n\n return model\n ? schema.concat(\n createModelValidator(createOrUpdate)({ model, data: item, componentContext }, options)\n )\n : schema;\n }) as any // FIXME: yup v1\n );\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: true },\n updatedAttribute,\n });\n\n if (!options.isDraft) {\n validator = addMinMax(validator, { attr, updatedAttribute });\n }\n\n return validator;\n };\n\n/**\n * A relation/media value can be supplied in several shapes: a bare id, an array of ids,\n * or a connect/set object (`{ connect: [...] }` / `{ set: [...] }`). This normalises all\n * of them to \"does this attach at least one entry?\" so required validation is consistent\n * regardless of the input shape (mirrors `buildRelationsStore`'s source extraction).\n */\nconst hasRelationValue = (value: unknown): boolean => {\n if (isNil(value)) {\n return false;\n }\n\n if (Array.isArray(value)) {\n return value.length > 0;\n }\n\n if (isObject(value)) {\n const connect = (value as { connect?: unknown }).connect;\n const set = (value as { set?: unknown }).set;\n\n if (!isNil(connect)) {\n return Array.isArray(connect) ? connect.length > 0 : true;\n }\n if (!isNil(set)) {\n return Array.isArray(set) ? set.length > 0 : true;\n }\n\n // Any other object shape (e.g. a bare `{ id }`) counts as a value.\n return true;\n }\n\n return true;\n};\n\n/**\n * A disconnect-only update payload removes entries without adding or replacing any:\n * actual removals in `disconnect`, no `set`, and no effective additions in `connect`.\n * `connect` counts as \"no additions\" when absent OR an empty array — the Content Manager\n * initializes every relation as `{ connect: [], disconnect: [] }` and keeps `connect: []`\n * in place when the user only removes entries, so `{ connect: [], disconnect: [id] }`\n * is the shape real admin saves produce. A payload with empty `disconnect` (nothing\n * removed) is NOT disconnect-only — it's the CM's untouched-relation no-op.\n */\nconst isDisconnectOnly = (value: unknown): boolean => {\n if (!isObject(value)) {\n return false;\n }\n\n const { connect, set, disconnect } = value as {\n connect?: unknown;\n set?: unknown;\n disconnect?: unknown;\n };\n\n if (!isNil(set)) {\n return false;\n }\n\n const hasAdditions = !isNil(connect) && (!Array.isArray(connect) || connect.length > 0);\n if (hasAdditions) {\n return false;\n }\n\n return !isNil(disconnect) && (!Array.isArray(disconnect) || disconnect.length > 0);\n};\n\n/**\n * Decides whether a required media/relation value should be rejected as empty,\n * mirroring the scalar `required` semantics:\n *\n * - creation (`notNil` analogue): an absent key is a failure — the field must be\n * populated, so anything without a value (`undefined`/`null`/`[]`/empty `set`/`connect`)\n * is rejected.\n * - update (`notNull` analogue): an absent key keeps the existing value, so it passes.\n * Only reject when the request is present AND leaves the field empty. A bare\n * `{ connect: [] }` (no `set`) neither adds nor removes anything → treated as a no-op\n * that passes; `{ set: [] }` / `null` / `[]` explicitly empty the field → rejected.\n *\n * `isToOne` marks a to-one relation / single media, which can hold at most one entry.\n * For those, a disconnect-only update (`{ disconnect: [...] }` with no `connect`/`set`)\n * always leaves the field empty — no DB read needed — so it is rejected on non-draft\n * updates. To-many fields can still hold other entries after a disconnect, so their\n * resulting state can't be known without a DB read and they fall through to a pass\n * (publish re-validates the populated draft for D&P types; documented limitation for\n * non-D&P, tied to the null→[] follow-up).\n *\n * On creation there are no existing rows, so a disconnect-only payload attaches nothing\n * and always leaves the field empty — for both to-one and to-many — so it is rejected\n * regardless of `isToOne`.\n */\nconst relationRequiredFails = (\n createOrUpdate: CreateOrUpdate,\n value: unknown,\n isToOne: boolean\n): boolean => {\n if (createOrUpdate === 'creation') {\n // No existing rows on create, so a disconnect attaches nothing and the field stays\n // empty for both to-one and to-many — reject it before the generic value check, which\n // would otherwise treat the bare `{ disconnect: [...] }` object as a present value.\n if (isDisconnectOnly(value)) {\n return true;\n }\n }\n\n if (createOrUpdate === 'update') {\n // Absent key on update = keep the existing value.\n if (value === undefined) {\n return false;\n }\n\n if (isDisconnectOnly(value)) {\n // A disconnect on a to-one/single field deterministically empties it; on a to-many\n // field the resulting state depends on the current DB rows, so we can't reject here.\n return isToOne;\n }\n\n // A connect-only empty is a no-op, not an emptying operation.\n if (isObject(value) && !isNil((value as { connect?: unknown }).connect)) {\n const connect = (value as { connect?: unknown }).connect;\n const hasSet = !isNil((value as { set?: unknown }).set);\n if (!hasSet && Array.isArray(connect) && connect.length === 0) {\n return false;\n }\n }\n }\n\n return !hasRelationValue(value);\n};\n\nconst createMediaAttributeValidator =\n (createOrUpdate: CreateOrUpdate) =>\n (\n { attr, updatedAttribute }: ValidatorMeta<Schema.Attribute.Media>,\n options: ValidatorContext\n ): strapiUtils.yup.AnySchema => {\n // Media values arrive in several shapes (a bare id, an array of ids, or a\n // `{ connect }` / `{ set }` object on update). `yup.mixed()` accepts all of them;\n // coercing `multiple` media to `yup.array()` would reject the connect/set object\n // syntax that update requests legitimately send. Required-ness is asserted below\n // via `relationRequiredFails`, which understands every shape.\n let validator: strapiUtils.yup.AnySchema = yup.mixed();\n\n // Relational required constraints are only enforced under the strictRelations flag,\n // and never for drafts (mirrors scalar `required` handling via `!isDraft`).\n if (options.strictRelations && !options.isDraft && attr.required) {\n // A media value can arrive as an id, an array, or a connect/set object, so a simple\n // `.notNil()`/`.min()` is not enough — normalise the shape before asserting.\n // Single media holds at most one file, so a disconnect-only update always empties it.\n const isToOne = !attr.multiple;\n validator = validator.test(\n 'required-media',\n `${updatedAttribute.name} must be defined.`,\n () => !relationRequiredFails(createOrUpdate, updatedAttribute.value, isToOne)\n );\n }\n\n return validator;\n };\n\nconst createRelationValidator =\n (createOrUpdate: CreateOrUpdate) =>\n (\n { attr, updatedAttribute }: ValidatorMeta<Schema.Attribute.Relation>,\n options: ValidatorContext\n ): strapiUtils.yup.AnySchema => {\n let validator: strapiUtils.yup.AnySchema;\n\n if (Array.isArray(updatedAttribute.value)) {\n validator = yup.array().of(yup.mixed());\n } else {\n validator = yup.mixed();\n }\n\n // Relational required constraints are only enforced under the strictRelations flag,\n // and never for drafts (mirrors scalar `required` handling via `!isDraft`).\n if (options.strictRelations && !options.isDraft && attr.required) {\n // A relation value can arrive as an id, an array, or a connect/set object, so a\n // simple `.notNil()`/`.min()` is not enough — normalise the shape before asserting.\n // A to-one relation holds at most one target, so a disconnect-only update always empties it.\n const isToOne = isAnyToOne(attr);\n validator = validator.test(\n 'required-relation',\n `${updatedAttribute.name} must be defined.`,\n () => !relationRequiredFails(createOrUpdate, updatedAttribute.value, isToOne)\n );\n }\n\n return validator;\n };\n\nconst createScalarAttributeValidator =\n (createOrUpdate: CreateOrUpdate) => (metas: ValidatorMeta, options: ValidatorContext) => {\n let validator;\n\n if (has(metas.attr.type, Validators)) {\n validator = (Validators as any)[metas.attr.type](metas, options);\n } else {\n // No validators specified - fall back to mixed\n validator = yup.mixed();\n }\n\n validator = addRequiredValidation(createOrUpdate)(validator, {\n attr: { required: !options.isDraft && metas.attr.required },\n updatedAttribute: metas.updatedAttribute,\n });\n\n return validator;\n };\n\nconst createAttributeValidator =\n (createOrUpdate: CreateOrUpdate) =>\n (metas: ValidatorMetas, options: ValidatorContext): strapiUtils.yup.AnySchema => {\n let validator = yup.mixed();\n\n // If field is conditionally invisible, skip all validation for it\n if (metas.attr.conditions?.visible) {\n const isVisible = jsonLogic.apply(metas.attr.conditions.visible, metas.data);\n\n if (!isVisible) {\n return yup.mixed().notRequired(); // Completely skip validation\n }\n }\n\n if (isMediaAttribute(metas.attr)) {\n validator = createMediaAttributeValidator(createOrUpdate)(\n {\n attr: metas.attr as Schema.Attribute.Media,\n updatedAttribute: metas.updatedAttribute,\n },\n options\n );\n } else if (isScalarAttribute(metas.attr)) {\n validator = createScalarAttributeValidator(createOrUpdate)(metas, options);\n } else {\n if (metas.attr.type === 'component' && metas.componentContext) {\n // Build the path to the component within the parent content type schema.\n const pathToComponent = [\n ...(metas?.componentContext?.pathToComponent ?? []),\n metas.updatedAttribute.name,\n ];\n\n // If working with a repeatable component, determine the repeatable data\n // based on the component's path.\n\n // In order to validate the repeatable within this entity we need\n // access to the full repeatable data. In case we are validating a\n // nested component within a repeatable.\n // Hence why we set this up when the path to the component is only one level deep.\n const repeatableData = (\n metas.attr.repeatable && pathToComponent.length === 1\n ? metas.updatedAttribute.value\n : metas.componentContext?.repeatableData\n ) as Modules.EntityValidator.Entity[];\n\n const newComponentContext: ComponentContext = {\n ...metas.componentContext,\n pathToComponent,\n repeatableData,\n };\n\n validator = createComponentValidator(createOrUpdate)(\n {\n componentContext: newComponentContext,\n attr: metas.attr,\n updatedAttribute: metas.updatedAttribute,\n },\n options\n );\n } else if (metas.attr.type === 'dynamiczone' && metas.componentContext) {\n const newComponentContext: ComponentContext = {\n ...metas.componentContext,\n fullDynamicZoneContent: metas.updatedAttribute.value,\n pathToComponent: [...metas.componentContext.pathToComponent, metas.updatedAttribute.name],\n };\n\n Object.assign(metas, { componentContext: newComponentContext });\n\n validator = createDzValidator(createOrUpdate)(metas, options);\n } else if (metas.attr.type === 'relation') {\n validator = createRelationValidator(createOrUpdate)(\n {\n attr: metas.attr,\n updatedAttribute: metas.updatedAttribute,\n },\n options\n );\n }\n\n validator = preventCast(validator);\n }\n\n validator = addDefault(createOrUpdate)(validator, metas);\n\n return validator;\n };\n\nconst createModelValidator =\n (createOrUpdate: CreateOrUpdate) =>\n (\n { componentContext, model, data, entity }: ModelValidatorMetas,\n options: ValidatorContext\n ): strapiUtils.yup.AnyObjectSchema => {\n const writableAttributes = model ? getWritableAttributes(model as any) : [];\n\n const schema = writableAttributes.reduce(\n (validators, attributeName) => {\n const metas = {\n attr: model.attributes[attributeName],\n updatedAttribute: { name: attributeName, value: prop(attributeName, data) },\n data,\n model,\n entity,\n componentContext,\n };\n\n const validator = createAttributeValidator(createOrUpdate)(metas, options);\n\n validators[attributeName] = validator;\n\n return validators;\n },\n {} as Record<string, strapiUtils.yup.BaseSchema>\n );\n\n return yup.object().shape(schema);\n };\n\nconst createValidateEntity = (createOrUpdate: CreateOrUpdate) => {\n return async <\n TUID extends UID.ContentType,\n TData extends Modules.EntityService.Params.Data.Input<TUID>,\n >(\n model: Schema.ContentType<TUID>,\n data: TData | Partial<TData> | undefined,\n options?: ValidatorContext,\n entity?: Modules.EntityValidator.Entity\n ): Promise<TData> => {\n if (!isObject(data)) {\n const { displayName } = model.info;\n\n throw new ValidationError(\n `Invalid payload submitted for the ${createOrUpdate} of an entity of type ${displayName}. Expected an object, but got ${typeof data}`\n );\n }\n\n const validator = createModelValidator(createOrUpdate)(\n {\n model,\n data,\n entity,\n componentContext: {\n // Set up the initial component context.\n // Keeping track of parent content type context in which a component will be used.\n // This is necessary to validate component field constraints such as uniqueness.\n parentContent: {\n id: entity?.id,\n model,\n options,\n },\n pathToComponent: [],\n repeatableData: [],\n },\n },\n {\n isDraft: options?.isDraft ?? false,\n locale: options?.locale ?? null,\n strictRelations: options?.strictRelations ?? false,\n }\n )\n .test(\n 'relations-test',\n 'check that all relations exist',\n async function relationsValidation(data) {\n try {\n await checkRelationsExist(buildRelationsStore({ uid: model.uid, data }));\n } catch (e) {\n return this.createError({\n path: this.path,\n message: (e instanceof ValidationError && e.message) || 'Invalid relations',\n });\n }\n return true;\n }\n )\n .required();\n\n return validateYupSchema(validator, {\n strict: false,\n abortEarly: false,\n })(data);\n };\n};\n\n/**\n * Builds an object containing all the media and relations being associated with an entity\n */\nconst buildRelationsStore = <TUID extends UID.Schema>({\n uid,\n data,\n}: {\n uid: TUID;\n data: Record<string, unknown> | null;\n}): Record<string, ID[]> => {\n if (!uid) {\n throw new ValidationError(`Cannot build relations store: \"uid\" is undefined`);\n }\n\n if (isEmpty(data)) {\n return {};\n }\n\n const currentModel = strapi.getModel(uid);\n\n return Object.keys(currentModel.attributes).reduce(\n (result, attributeName: string) => {\n const attribute = currentModel.attributes[attributeName];\n const value = data[attributeName];\n\n if (isNil(value)) {\n return result;\n }\n\n switch (attribute.type) {\n case 'relation':\n case 'media': {\n if (\n attribute.type === 'relation' &&\n (attribute.relation === 'morphToMany' || attribute.relation === 'morphToOne')\n ) {\n // TODO: handle polymorphic relations\n break;\n }\n\n const target =\n // eslint-disable-next-line no-nested-ternary\n attribute.type === 'media' ? 'plugin::upload.file' : attribute.target;\n // As there are multiple formats supported for associating relations\n // with an entity, the value here can be an: array, object or number.\n let source: RelationSource[];\n if (Array.isArray(value)) {\n source = value;\n } else if (isObject(value)) {\n if ('connect' in value && !isNil(value.connect)) {\n source = value.connect as RelationSource[];\n } else if ('set' in value && !isNil(value.set)) {\n source = value.set as RelationSource[];\n } else {\n source = [];\n }\n } else {\n source = castArray(value as RelationSource);\n }\n const idArray = source.map((v) => ({\n id: typeof v === 'object' ? v.id : v,\n }));\n\n // Update the relationStore to keep track of all associations being made\n // with relations and media.\n result[target] = result[target] || [];\n result[target].push(...idArray);\n break;\n }\n case 'component': {\n return castArray(value).reduce((relationsStore, componentValue) => {\n if (!attribute.component) {\n throw new ValidationError(\n `Cannot build relations store from component, component identifier is undefined`\n );\n }\n\n return mergeWith(\n relationsStore,\n buildRelationsStore({\n uid: attribute.component,\n data: componentValue as Record<string, unknown>,\n }),\n (objValue, srcValue) => {\n if (isArray(objValue)) {\n return objValue.concat(srcValue);\n }\n }\n );\n }, result) as Record<string, ID[]>;\n }\n case 'dynamiczone': {\n return castArray(value).reduce((relationsStore, dzValue) => {\n const value = dzValue as Record<string, unknown>;\n if (!value.__component) {\n throw new ValidationError(\n `Cannot build relations store from dynamiczone, component identifier is undefined`\n );\n }\n\n return mergeWith(\n relationsStore,\n buildRelationsStore({\n uid: value.__component as UID.Component,\n data: value,\n }),\n (objValue, srcValue) => {\n if (isArray(objValue)) {\n return objValue.concat(srcValue);\n }\n }\n );\n }, result) as Record<string, ID[]>;\n }\n default:\n break;\n }\n\n return result;\n },\n {} as Record<string, ID[]>\n );\n};\n\n/**\n * Iterate through the relations store and validates that every relation or media\n * mentioned exists\n */\nconst checkRelationsExist = async (relationsStore: Record<string, ID[]> = {}) => {\n const promises: Promise<void>[] = [];\n\n for (const [key, value] of Object.entries(relationsStore)) {\n const evaluate = async () => {\n const uniqueValues = uniqBy(value, `id`);\n const count = await strapi.db.query(key as UID.Schema).count({\n where: {\n id: {\n $in: uniqueValues.map((v) => v.id),\n },\n },\n });\n\n if (count !== uniqueValues.length) {\n throw new ValidationError(\n `${\n uniqueValues.length - count\n } relation(s) of type ${key} associated with this entity do not exist`\n );\n }\n };\n promises.push(evaluate());\n }\n\n return Promise.all(promises);\n};\n\nconst entityValidator: Modules.EntityValidator.EntityValidator = {\n validateEntityCreation: createValidateEntity('creation'),\n validateEntityUpdate: createValidateEntity('update'),\n};\n\nexport default entityValidator;\n"],"names":["yup","validateYupSchema","strapiUtils","isMediaAttribute","isScalarAttribute","getWritableAttributes","contentTypes","isAnyToOne","relations","ValidationError","errors","isInteger","value","Number","addMinMax","validator","attr","updatedAttribute","nextValidator","min","required","Array","isArray","length","max","addRequiredValidation","createOrUpdate","notNil","notNull","nullable","addDefault","type","repeatable","default","undefined","preventCast","transform","val","originalVal","createComponentValidator","componentContext","options","model","strapi","getModel","component","Error","array","of","lazy","item","createModelValidator","data","isDraft","createDzValidator","prop","schema","object","shape","__component","string","oneOf","Object","keys","components","concat","hasRelationValue","isNil","isObject","connect","set","isDisconnectOnly","disconnect","hasAdditions","relationRequiredFails","isToOne","hasSet","createMediaAttributeValidator","mixed","strictRelations","multiple","test","name","createRelationValidator","createScalarAttributeValidator","metas","has","Validators","createAttributeValidator","conditions","visible","isVisible","jsonLogic","apply","notRequired","pathToComponent","repeatableData","newComponentContext","fullDynamicZoneContent","assign","entity","writableAttributes","reduce","validators","attributeName","attributes","createValidateEntity","displayName","info","parentContent","id","locale","relationsValidation","checkRelationsExist","buildRelationsStore","uid","e","createError","path","message","strict","abortEarly","isEmpty","currentModel","result","attribute","relation","target","source","castArray","idArray","map","v","push","relationsStore","componentValue","mergeWith","objValue","srcValue","dzValue","promises","key","entries","evaluate","uniqueValues","uniqBy","count","db","query","where","$in","Promise","all","entityValidator","validateEntityCreation","validateEntityUpdate"],"mappings":";;;;;;;;;;;;;AAcA,MAAM,EAAEA,GAAG,EAAEC,iBAAiB,EAAE,GAAGC,4BAAAA;AACnC,MAAM,EAAEC,gBAAgB,EAAEC,iBAAiB,EAAEC,qBAAqB,EAAE,GAAGH,4BAAAA,CAAYI,YAAY;AAC/F,MAAM,EAAEC,UAAU,EAAE,GAAGL,6BAAYM,SAAS;AAC5C,MA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