@strapi/utils 5.0.0-beta.6 → 5.0.0-beta.8
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.
- package/dist/content-types.d.ts +15 -6
- package/dist/content-types.d.ts.map +1 -1
- package/dist/file.d.ts +0 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/index.js +183 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +183 -39
- package/dist/index.mjs.map +1 -1
- package/dist/pagination.d.ts +34 -4
- package/dist/pagination.d.ts.map +1 -1
- package/dist/traverse/factory.d.ts +1 -1
- package/dist/traverse/factory.d.ts.map +1 -1
- package/dist/traverse-entity.d.ts +10 -2
- package/dist/traverse-entity.d.ts.map +1 -1
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/utils.d.ts +1 -1
- package/dist/validate/utils.d.ts.map +1 -1
- package/dist/validate/visitors/index.d.ts +1 -0
- package/dist/validate/visitors/index.d.ts.map +1 -1
- package/dist/validate/visitors/throw-unrecognized-fields.d.ts +4 -0
- package/dist/validate/visitors/throw-unrecognized-fields.d.ts.map +1 -0
- package/package.json +4 -4
package/dist/content-types.d.ts
CHANGED
|
@@ -28,6 +28,13 @@ declare const getOptions: (model: Model) => {
|
|
|
28
28
|
});
|
|
29
29
|
declare const hasDraftAndPublish: (model: Model) => boolean;
|
|
30
30
|
declare const isDraft: <T extends object>(data: T, model: Model) => boolean;
|
|
31
|
+
declare const isSchema: (data: unknown) => data is Model;
|
|
32
|
+
declare const isComponentSchema: (data: unknown) => data is Model & {
|
|
33
|
+
modelType: 'component';
|
|
34
|
+
};
|
|
35
|
+
declare const isContentTypeSchema: (data: unknown) => data is Model & {
|
|
36
|
+
modelType: 'contentType';
|
|
37
|
+
};
|
|
31
38
|
declare const isSingleType: ({ kind }: {
|
|
32
39
|
kind?: string | undefined;
|
|
33
40
|
}) => boolean;
|
|
@@ -37,12 +44,14 @@ declare const isCollectionType: ({ kind }: {
|
|
|
37
44
|
declare const isKind: (kind: Kind) => (model: Model) => boolean;
|
|
38
45
|
declare const getPrivateAttributes: (model: Model) => string[];
|
|
39
46
|
declare const isPrivateAttribute: (model: Model, attributeName: string) => boolean;
|
|
40
|
-
declare const isScalarAttribute: (attribute
|
|
41
|
-
declare const
|
|
42
|
-
declare const
|
|
47
|
+
declare const isScalarAttribute: (attribute?: Attribute) => boolean | undefined;
|
|
48
|
+
declare const getDoesAttributeRequireValidation: (attribute: Attribute) => any;
|
|
49
|
+
declare const isMediaAttribute: (attribute?: Attribute) => boolean;
|
|
50
|
+
declare const isRelationalAttribute: (attribute?: Attribute) => attribute is RelationalAttribute;
|
|
51
|
+
declare const hasRelationReordering: (attribute?: Attribute) => boolean;
|
|
43
52
|
declare const isComponentAttribute: (attribute: Attribute) => attribute is ComponentAttribute | DynamicZoneAttribute;
|
|
44
|
-
declare const isDynamicZoneAttribute: (attribute
|
|
45
|
-
declare const isMorphToRelationalAttribute: (attribute
|
|
53
|
+
declare const isDynamicZoneAttribute: (attribute?: Attribute) => attribute is DynamicZoneAttribute;
|
|
54
|
+
declare const isMorphToRelationalAttribute: (attribute?: Attribute) => boolean;
|
|
46
55
|
declare const getComponentAttributes: (schema: Model) => string[];
|
|
47
56
|
declare const getScalarAttributes: (schema: Model) => string[];
|
|
48
57
|
declare const getRelationalAttributes: (schema: Model) => string[];
|
|
@@ -58,5 +67,5 @@ declare const isTypedAttribute: (attribute: Attribute, type: string) => boolean;
|
|
|
58
67
|
* @returns {string}
|
|
59
68
|
*/
|
|
60
69
|
declare const getContentTypeRoutePrefix: (contentType: WithRequired<Model, 'info'>) => string;
|
|
61
|
-
export { isScalarAttribute, isMediaAttribute, isRelationalAttribute, isComponentAttribute, isDynamicZoneAttribute, isMorphToRelationalAttribute, isTypedAttribute, getPrivateAttributes, isPrivateAttribute, constants, getNonWritableAttributes, getComponentAttributes, getScalarAttributes, getRelationalAttributes, getWritableAttributes, isWritableAttribute, getNonVisibleAttributes, getVisibleAttributes, getTimestamps, getCreatorFields, isVisibleAttribute, getOptions, isDraft, hasDraftAndPublish, isSingleType, isCollectionType, isKind, getContentTypeRoutePrefix, };
|
|
70
|
+
export { isSchema, isContentTypeSchema, isComponentSchema, isScalarAttribute, isMediaAttribute, isRelationalAttribute, hasRelationReordering, isComponentAttribute, isDynamicZoneAttribute, isMorphToRelationalAttribute, isTypedAttribute, getPrivateAttributes, isPrivateAttribute, constants, getNonWritableAttributes, getComponentAttributes, getScalarAttributes, getRelationalAttributes, getWritableAttributes, isWritableAttribute, getNonVisibleAttributes, getVisibleAttributes, getTimestamps, getCreatorFields, isVisibleAttribute, getOptions, isDraft, hasDraftAndPublish, isSingleType, isCollectionType, isKind, getContentTypeRoutePrefix, getDoesAttributeRequireValidation, };
|
|
62
71
|
//# sourceMappingURL=content-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-types.d.ts","sourceRoot":"","sources":["../src/content-types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,KAAK,EACL,IAAI,EACJ,SAAS,EACT,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACb,MAAM,SAAS,CAAC;AAejB,QAAA,MAAM,SAAS;;;;;;;;;;CAUd,CAAC;AAEF,QAAA,MAAM,aAAa,UAAW,KAAK,aAYlC,CAAC;AAEF,QAAA,MAAM,gBAAgB,UAAW,KAAK,aAYrC,CAAC;AAEF,QAAA,MAAM,wBAAwB,UAAW,KAAK,aAe7C,CAAC;AAEF,QAAA,MAAM,qBAAqB,UAAW,KAAK,aAI1C,CAAC;AAEF,QAAA,MAAM,mBAAmB,UAAW,KAAK,iBAAiB,MAAM,YAE/D,CAAC;AAEF,QAAA,MAAM,uBAAuB,UAAW,KAAK,aAQ5C,CAAC;AAEF,QAAA,MAAM,oBAAoB,UAAW,KAAK,aAEzC,CAAC;AAEF,QAAA,MAAM,kBAAkB,UAAW,KAAK,iBAAiB,MAAM,YAE9D,CAAC;AAEF,QAAA,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yB,gBAAiB,aAAa,KAAK,EAAE,MAAM,CAAC,WAI1E,CAAC;AAEF,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,4BAA4B,EAC5B,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,SAAS,EACT,wBAAwB,EACxB,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACvB,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,OAAO,EACP,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,MAAM,EACN,yBAAyB,EACzB,iCAAiC,GAClC,CAAC"}
|
package/dist/file.d.ts
CHANGED
package/dist/file.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":";;;;;;AAAA;;GAEG;AACH,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAExD,QAAA,MAAM,aAAa,WAAY,MAAM,WAAkB,CAAC;AACxD,QAAA,MAAM,aAAa,UAAW,MAAM,WAA2C,CAAC;AAChF,QAAA,MAAM,oBAAoB,UAAW,MAAM,WAK1C,CAAC;AAEF,QAAA,MAAM,cAAc,WAAY,qBAAqB,KAAG,QAAQ,MAAM,CAUlE,CAAC;AAEL,QAAA,MAAM,aAAa,WAAY,qBAAqB,qBAShD,CAAC;AAEL;;;GAGG;AACH,iBAAS,qBAAqB,CAAC,OAAO,CAAC,EAAE,eAAe,YAOvD;AAED,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,aAAa,EACb,qBAAqB,GACtB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -310,6 +310,15 @@ const isVisibleAttribute = (model, attributeName) => {
|
|
|
310
310
|
const getOptions = (model) => ___namespace.default.assign({ draftAndPublish: false }, ___namespace.default.get(model, "options", {}));
|
|
311
311
|
const hasDraftAndPublish = (model) => ___namespace.default.get(model, "options.draftAndPublish", false) === true;
|
|
312
312
|
const isDraft = (data, model) => hasDraftAndPublish(model) && ___namespace.default.get(data, PUBLISHED_AT_ATTRIBUTE$1) === null;
|
|
313
|
+
const isSchema = (data) => {
|
|
314
|
+
return typeof data === "object" && data !== null && "modelType" in data && typeof data.modelType === "string" && ["component", "contentType"].includes(data.modelType);
|
|
315
|
+
};
|
|
316
|
+
const isComponentSchema = (data) => {
|
|
317
|
+
return isSchema(data) && data.modelType === "component";
|
|
318
|
+
};
|
|
319
|
+
const isContentTypeSchema = (data) => {
|
|
320
|
+
return isSchema(data) && data.modelType === "contentType";
|
|
321
|
+
};
|
|
313
322
|
const isSingleType = ({ kind = COLLECTION_TYPE }) => kind === SINGLE_TYPE;
|
|
314
323
|
const isCollectionType = ({ kind = COLLECTION_TYPE }) => kind === COLLECTION_TYPE;
|
|
315
324
|
const isKind = (kind) => (model) => model.kind === kind;
|
|
@@ -330,14 +339,19 @@ const isPrivateAttribute = (model, attributeName) => {
|
|
|
330
339
|
return getStoredPrivateAttributes(model).includes(attributeName);
|
|
331
340
|
};
|
|
332
341
|
const isScalarAttribute = (attribute) => {
|
|
333
|
-
return !["media", "component", "relation", "dynamiczone"].includes(attribute
|
|
342
|
+
return attribute && !["media", "component", "relation", "dynamiczone"].includes(attribute.type);
|
|
343
|
+
};
|
|
344
|
+
const getDoesAttributeRequireValidation = (attribute) => {
|
|
345
|
+
return attribute.required || attribute.unique || Object.prototype.hasOwnProperty.call(attribute, "max") || Object.prototype.hasOwnProperty.call(attribute, "min") || Object.prototype.hasOwnProperty.call(attribute, "maxLength") || Object.prototype.hasOwnProperty.call(attribute, "minLength");
|
|
334
346
|
};
|
|
335
347
|
const isMediaAttribute = (attribute) => attribute?.type === "media";
|
|
336
348
|
const isRelationalAttribute = (attribute) => attribute?.type === "relation";
|
|
349
|
+
const HAS_RELATION_REORDERING = ["manyToMany", "manyToOne", "oneToMany"];
|
|
350
|
+
const hasRelationReordering = (attribute) => isRelationalAttribute(attribute) && HAS_RELATION_REORDERING.includes(attribute.relation);
|
|
337
351
|
const isComponentAttribute = (attribute) => ["component", "dynamiczone"].includes(attribute?.type);
|
|
338
|
-
const isDynamicZoneAttribute = (attribute) => attribute
|
|
352
|
+
const isDynamicZoneAttribute = (attribute) => !!attribute && attribute.type === "dynamiczone";
|
|
339
353
|
const isMorphToRelationalAttribute = (attribute) => {
|
|
340
|
-
return isRelationalAttribute(attribute) && attribute
|
|
354
|
+
return !!attribute && isRelationalAttribute(attribute) && attribute.relation?.startsWith?.("morphTo");
|
|
341
355
|
};
|
|
342
356
|
const getComponentAttributes = (schema) => {
|
|
343
357
|
return ___namespace.default.reduce(
|
|
@@ -384,6 +398,7 @@ const contentTypes = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.define
|
|
|
384
398
|
getComponentAttributes,
|
|
385
399
|
getContentTypeRoutePrefix,
|
|
386
400
|
getCreatorFields,
|
|
401
|
+
getDoesAttributeRequireValidation,
|
|
387
402
|
getNonVisibleAttributes,
|
|
388
403
|
getNonWritableAttributes,
|
|
389
404
|
getOptions,
|
|
@@ -394,8 +409,11 @@ const contentTypes = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.define
|
|
|
394
409
|
getVisibleAttributes,
|
|
395
410
|
getWritableAttributes,
|
|
396
411
|
hasDraftAndPublish,
|
|
412
|
+
hasRelationReordering,
|
|
397
413
|
isCollectionType,
|
|
398
414
|
isComponentAttribute,
|
|
415
|
+
isComponentSchema,
|
|
416
|
+
isContentTypeSchema,
|
|
399
417
|
isDraft,
|
|
400
418
|
isDynamicZoneAttribute,
|
|
401
419
|
isKind,
|
|
@@ -404,6 +422,7 @@ const contentTypes = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.define
|
|
|
404
422
|
isPrivateAttribute,
|
|
405
423
|
isRelationalAttribute,
|
|
406
424
|
isScalarAttribute,
|
|
425
|
+
isSchema,
|
|
407
426
|
isSingleType,
|
|
408
427
|
isTypedAttribute,
|
|
409
428
|
isVisibleAttribute,
|
|
@@ -558,28 +577,29 @@ const providerFactory = (options = {}) => {
|
|
|
558
577
|
};
|
|
559
578
|
const traverseEntity = async (visitor2, options, entity) => {
|
|
560
579
|
const { path = { raw: null, attribute: null }, schema, getModel } = options;
|
|
580
|
+
let parent = options.parent;
|
|
561
581
|
const traverseMorphRelationTarget = async (visitor22, path2, entry) => {
|
|
562
582
|
const targetSchema = getModel(entry.__type);
|
|
563
|
-
const traverseOptions = { schema: targetSchema, path: path2, getModel };
|
|
583
|
+
const traverseOptions = { schema: targetSchema, path: path2, getModel, parent };
|
|
564
584
|
return traverseEntity(visitor22, traverseOptions, entry);
|
|
565
585
|
};
|
|
566
586
|
const traverseRelationTarget = (schema2) => async (visitor22, path2, entry) => {
|
|
567
|
-
const traverseOptions = { schema: schema2, path: path2, getModel };
|
|
587
|
+
const traverseOptions = { schema: schema2, path: path2, getModel, parent };
|
|
568
588
|
return traverseEntity(visitor22, traverseOptions, entry);
|
|
569
589
|
};
|
|
570
590
|
const traverseMediaTarget = async (visitor22, path2, entry) => {
|
|
571
591
|
const targetSchemaUID = "plugin::upload.file";
|
|
572
592
|
const targetSchema = getModel(targetSchemaUID);
|
|
573
|
-
const traverseOptions = { schema: targetSchema, path: path2, getModel };
|
|
593
|
+
const traverseOptions = { schema: targetSchema, path: path2, getModel, parent };
|
|
574
594
|
return traverseEntity(visitor22, traverseOptions, entry);
|
|
575
595
|
};
|
|
576
596
|
const traverseComponent = async (visitor22, path2, schema2, entry) => {
|
|
577
|
-
const traverseOptions = { schema: schema2, path: path2, getModel };
|
|
597
|
+
const traverseOptions = { schema: schema2, path: path2, getModel, parent };
|
|
578
598
|
return traverseEntity(visitor22, traverseOptions, entry);
|
|
579
599
|
};
|
|
580
600
|
const visitDynamicZoneEntry = async (visitor22, path2, entry) => {
|
|
581
601
|
const targetSchema = getModel(entry.__component);
|
|
582
|
-
const traverseOptions = { schema: targetSchema, path: path2, getModel };
|
|
602
|
+
const traverseOptions = { schema: targetSchema, path: path2, getModel, parent };
|
|
583
603
|
return traverseEntity(visitor22, traverseOptions, entry);
|
|
584
604
|
};
|
|
585
605
|
if (!fp.isObject(entity) || fp.isNil(schema)) {
|
|
@@ -591,9 +611,6 @@ const traverseEntity = async (visitor2, options, entity) => {
|
|
|
591
611
|
for (let i = 0; i < keys.length; i += 1) {
|
|
592
612
|
const key = keys[i];
|
|
593
613
|
const attribute = schema.attributes[key];
|
|
594
|
-
if (fp.isNil(attribute)) {
|
|
595
|
-
continue;
|
|
596
|
-
}
|
|
597
614
|
const newPath = { ...path };
|
|
598
615
|
newPath.raw = fp.isNil(path.raw) ? key : `${path.raw}.${key}`;
|
|
599
616
|
if (!fp.isNil(attribute)) {
|
|
@@ -606,13 +623,15 @@ const traverseEntity = async (visitor2, options, entity) => {
|
|
|
606
623
|
value: copy[key],
|
|
607
624
|
attribute,
|
|
608
625
|
path: newPath,
|
|
609
|
-
getModel
|
|
626
|
+
getModel,
|
|
627
|
+
parent
|
|
610
628
|
};
|
|
611
629
|
await visitor2(visitorOptions, visitorUtils);
|
|
612
630
|
const value = copy[key];
|
|
613
|
-
if (fp.isNil(value)) {
|
|
631
|
+
if (fp.isNil(value) || fp.isNil(attribute)) {
|
|
614
632
|
continue;
|
|
615
633
|
}
|
|
634
|
+
parent = { schema, key, attribute, path: newPath };
|
|
616
635
|
if (isRelationalAttribute(attribute)) {
|
|
617
636
|
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
|
618
637
|
const method = isMorphRelation ? traverseMorphRelationTarget : traverseRelationTarget(getModel(attribute.target));
|
|
@@ -2180,13 +2199,16 @@ const index$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
2180
2199
|
sanitizers,
|
|
2181
2200
|
visitors: index$4
|
|
2182
2201
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
2183
|
-
const
|
|
2184
|
-
const msg = path && path !== key ? `Invalid
|
|
2185
|
-
throw new ValidationError(msg
|
|
2202
|
+
const throwInvalidKey = ({ key, path }) => {
|
|
2203
|
+
const msg = path && path !== key ? `Invalid key ${key} at ${path}` : `Invalid key ${key}`;
|
|
2204
|
+
throw new ValidationError(msg, {
|
|
2205
|
+
key,
|
|
2206
|
+
path
|
|
2207
|
+
});
|
|
2186
2208
|
};
|
|
2187
2209
|
const visitor$3 = ({ key, attribute, path }) => {
|
|
2188
2210
|
if (attribute?.type === "password") {
|
|
2189
|
-
|
|
2211
|
+
throwInvalidKey({ key, path: path.attribute });
|
|
2190
2212
|
}
|
|
2191
2213
|
};
|
|
2192
2214
|
const visitor$2 = ({ schema, key, attribute, path }) => {
|
|
@@ -2195,7 +2217,7 @@ const visitor$2 = ({ schema, key, attribute, path }) => {
|
|
|
2195
2217
|
}
|
|
2196
2218
|
const isPrivate = attribute.private === true || isPrivateAttribute(schema, key);
|
|
2197
2219
|
if (isPrivate) {
|
|
2198
|
-
|
|
2220
|
+
throwInvalidKey({ key, path: path.attribute });
|
|
2199
2221
|
}
|
|
2200
2222
|
};
|
|
2201
2223
|
const ACTIONS_TO_VERIFY = ["find"];
|
|
@@ -2213,7 +2235,7 @@ const throwRestrictedRelations = (auth) => async ({ data, key, attribute, schema
|
|
|
2213
2235
|
const scopes = ACTIONS_TO_VERIFY.map((action) => `${element.__type}.${action}`);
|
|
2214
2236
|
const isAllowed = await hasAccessToSomeScopes(scopes, auth);
|
|
2215
2237
|
if (!isAllowed) {
|
|
2216
|
-
|
|
2238
|
+
throwInvalidKey({ key, path: path.attribute });
|
|
2217
2239
|
}
|
|
2218
2240
|
}
|
|
2219
2241
|
};
|
|
@@ -2221,7 +2243,7 @@ const throwRestrictedRelations = (auth) => async ({ data, key, attribute, schema
|
|
|
2221
2243
|
const scopes = ACTIONS_TO_VERIFY.map((action) => `${attribute.target}.${action}`);
|
|
2222
2244
|
const isAllowed = await hasAccessToSomeScopes(scopes, auth);
|
|
2223
2245
|
if (!isAllowed) {
|
|
2224
|
-
|
|
2246
|
+
throwInvalidKey({ key, path: path.attribute });
|
|
2225
2247
|
}
|
|
2226
2248
|
};
|
|
2227
2249
|
const isCreatorRelation = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(key);
|
|
@@ -2247,12 +2269,12 @@ const hasAccessToSomeScopes = async (scopes, auth) => {
|
|
|
2247
2269
|
};
|
|
2248
2270
|
const visitor$1 = ({ key, attribute, path }) => {
|
|
2249
2271
|
if (isMorphToRelationalAttribute(attribute)) {
|
|
2250
|
-
|
|
2272
|
+
throwInvalidKey({ key, path: path.attribute });
|
|
2251
2273
|
}
|
|
2252
2274
|
};
|
|
2253
2275
|
const visitor = ({ key, attribute, path }) => {
|
|
2254
2276
|
if (isDynamicZoneAttribute(attribute)) {
|
|
2255
|
-
|
|
2277
|
+
throwInvalidKey({ key, path: path.attribute });
|
|
2256
2278
|
}
|
|
2257
2279
|
};
|
|
2258
2280
|
const throwDisallowedFields = (allowedFields = null) => ({ key, path: { attribute: path } }) => {
|
|
@@ -2274,7 +2296,7 @@ const throwDisallowedFields = (allowedFields = null) => ({ key, path: { attribut
|
|
|
2274
2296
|
if (isPathAllowed) {
|
|
2275
2297
|
return;
|
|
2276
2298
|
}
|
|
2277
|
-
|
|
2299
|
+
throwInvalidKey({ key, path });
|
|
2278
2300
|
};
|
|
2279
2301
|
const getContainedPaths = (path) => {
|
|
2280
2302
|
const parts = fp.toPath(path);
|
|
@@ -2284,7 +2306,7 @@ const getContainedPaths = (path) => {
|
|
|
2284
2306
|
};
|
|
2285
2307
|
const throwRestrictedFields = (restrictedFields = null) => ({ key, path: { attribute: path } }) => {
|
|
2286
2308
|
if (restrictedFields === null) {
|
|
2287
|
-
|
|
2309
|
+
throwInvalidKey({ key, path });
|
|
2288
2310
|
}
|
|
2289
2311
|
if (!(fp.isArray(restrictedFields) && restrictedFields.every(fp.isString))) {
|
|
2290
2312
|
throw new TypeError(
|
|
@@ -2292,15 +2314,45 @@ const throwRestrictedFields = (restrictedFields = null) => ({ key, path: { attri
|
|
|
2292
2314
|
);
|
|
2293
2315
|
}
|
|
2294
2316
|
if (restrictedFields.includes(path)) {
|
|
2295
|
-
|
|
2317
|
+
throwInvalidKey({ key, path });
|
|
2296
2318
|
}
|
|
2297
2319
|
const isRestrictedNested = restrictedFields.some(
|
|
2298
2320
|
(allowedPath) => path?.toString().startsWith(`${allowedPath}.`)
|
|
2299
2321
|
);
|
|
2300
2322
|
if (isRestrictedNested) {
|
|
2301
|
-
|
|
2323
|
+
throwInvalidKey({ key, path });
|
|
2302
2324
|
}
|
|
2303
2325
|
};
|
|
2326
|
+
const ID_FIELDS = [constants$1.DOC_ID_ATTRIBUTE, constants$1.DOC_ID_ATTRIBUTE];
|
|
2327
|
+
const ALLOWED_ROOT_LEVEL_FIELDS = [...ID_FIELDS];
|
|
2328
|
+
const MORPH_TO_ALLOWED_FIELDS = ["__type"];
|
|
2329
|
+
const DYNAMIC_ZONE_ALLOWED_FIELDS = ["__component"];
|
|
2330
|
+
const RELATION_REORDERING_FIELDS = ["connect", "disconnect", "set", "options"];
|
|
2331
|
+
const throwUnrecognizedFields = ({ key, attribute, path, schema, parent }) => {
|
|
2332
|
+
if (attribute) {
|
|
2333
|
+
return;
|
|
2334
|
+
}
|
|
2335
|
+
if (path.attribute === null) {
|
|
2336
|
+
if (ALLOWED_ROOT_LEVEL_FIELDS.includes(key)) {
|
|
2337
|
+
return;
|
|
2338
|
+
}
|
|
2339
|
+
return throwInvalidKey({ key, path: attribute });
|
|
2340
|
+
}
|
|
2341
|
+
if (isMorphToRelationalAttribute(parent?.attribute) && MORPH_TO_ALLOWED_FIELDS.includes(key)) {
|
|
2342
|
+
return;
|
|
2343
|
+
}
|
|
2344
|
+
if (isComponentSchema(schema) && isDynamicZoneAttribute(parent?.attribute) && DYNAMIC_ZONE_ALLOWED_FIELDS.includes(key)) {
|
|
2345
|
+
return;
|
|
2346
|
+
}
|
|
2347
|
+
if (hasRelationReordering(parent?.attribute) && RELATION_REORDERING_FIELDS.includes(key)) {
|
|
2348
|
+
return;
|
|
2349
|
+
}
|
|
2350
|
+
const canUseID = isRelationalAttribute(parent?.attribute) || isMediaAttribute(parent?.attribute);
|
|
2351
|
+
if (canUseID && !ID_FIELDS.includes(key)) {
|
|
2352
|
+
return;
|
|
2353
|
+
}
|
|
2354
|
+
throwInvalidKey({ key, path: attribute });
|
|
2355
|
+
};
|
|
2304
2356
|
const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2305
2357
|
__proto__: null,
|
|
2306
2358
|
throwDisallowedFields,
|
|
@@ -2309,7 +2361,8 @@ const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
2309
2361
|
throwPassword: visitor$3,
|
|
2310
2362
|
throwPrivate: visitor$2,
|
|
2311
2363
|
throwRestrictedFields,
|
|
2312
|
-
throwRestrictedRelations
|
|
2364
|
+
throwRestrictedRelations,
|
|
2365
|
+
throwUnrecognizedFields
|
|
2313
2366
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
2314
2367
|
const { ID_ATTRIBUTE: ID_ATTRIBUTE$1, DOC_ID_ATTRIBUTE: DOC_ID_ATTRIBUTE$1 } = constants$1;
|
|
2315
2368
|
const throwPasswords = (ctx) => async (entity) => {
|
|
@@ -2330,7 +2383,7 @@ const defaultValidateFilters = fp.curry((ctx, filters2) => {
|
|
|
2330
2383
|
}
|
|
2331
2384
|
const isAttribute = !!attribute;
|
|
2332
2385
|
if (!isAttribute && !isOperator(key)) {
|
|
2333
|
-
|
|
2386
|
+
throwInvalidKey({ key, path: path.attribute });
|
|
2334
2387
|
}
|
|
2335
2388
|
}, ctx),
|
|
2336
2389
|
// dynamic zones from filters
|
|
@@ -2355,7 +2408,7 @@ const defaultValidateSort = fp.curry((ctx, sort2) => {
|
|
|
2355
2408
|
return;
|
|
2356
2409
|
}
|
|
2357
2410
|
if (!attribute) {
|
|
2358
|
-
|
|
2411
|
+
throwInvalidKey({ key, path: path.attribute });
|
|
2359
2412
|
}
|
|
2360
2413
|
}, ctx),
|
|
2361
2414
|
// dynamic zones from sort
|
|
@@ -2372,7 +2425,7 @@ const defaultValidateSort = fp.curry((ctx, sort2) => {
|
|
|
2372
2425
|
return;
|
|
2373
2426
|
}
|
|
2374
2427
|
if (!isScalarAttribute(attribute) && fp.isEmpty(value)) {
|
|
2375
|
-
|
|
2428
|
+
throwInvalidKey({ key, path: path.attribute });
|
|
2376
2429
|
}
|
|
2377
2430
|
}, ctx)
|
|
2378
2431
|
)(sort2);
|
|
@@ -2388,7 +2441,7 @@ const defaultValidateFields = fp.curry((ctx, fields2) => {
|
|
|
2388
2441
|
return;
|
|
2389
2442
|
}
|
|
2390
2443
|
if (fp.isNil(attribute) || !isScalarAttribute(attribute)) {
|
|
2391
|
-
|
|
2444
|
+
throwInvalidKey({ key, path: path.attribute });
|
|
2392
2445
|
}
|
|
2393
2446
|
}, ctx),
|
|
2394
2447
|
// private fields
|
|
@@ -2483,15 +2536,18 @@ const createAPIValidators = (opts) => {
|
|
|
2483
2536
|
(data2) => {
|
|
2484
2537
|
if (fp.isObject(data2)) {
|
|
2485
2538
|
if (ID_ATTRIBUTE in data2) {
|
|
2486
|
-
|
|
2539
|
+
throwInvalidKey({ key: ID_ATTRIBUTE });
|
|
2487
2540
|
}
|
|
2488
2541
|
if (DOC_ID_ATTRIBUTE in data2) {
|
|
2489
|
-
|
|
2542
|
+
throwInvalidKey({ key: DOC_ID_ATTRIBUTE });
|
|
2490
2543
|
}
|
|
2491
2544
|
}
|
|
2545
|
+
return data2;
|
|
2492
2546
|
},
|
|
2493
2547
|
// non-writable attributes
|
|
2494
|
-
traverseEntity$1(throwRestrictedFields(nonWritableAttributes), { schema, getModel })
|
|
2548
|
+
traverseEntity$1(throwRestrictedFields(nonWritableAttributes), { schema, getModel }),
|
|
2549
|
+
// unrecognized attributes
|
|
2550
|
+
traverseEntity$1(throwUnrecognizedFields, { schema, getModel })
|
|
2495
2551
|
];
|
|
2496
2552
|
if (auth) {
|
|
2497
2553
|
transforms.push(
|
|
@@ -2502,7 +2558,14 @@ const createAPIValidators = (opts) => {
|
|
|
2502
2558
|
);
|
|
2503
2559
|
}
|
|
2504
2560
|
opts?.validators?.input?.forEach((validator) => transforms.push(validator(schema)));
|
|
2505
|
-
|
|
2561
|
+
try {
|
|
2562
|
+
await pipe(...transforms)(data);
|
|
2563
|
+
} catch (e) {
|
|
2564
|
+
if (e instanceof ValidationError) {
|
|
2565
|
+
e.details.source = "body";
|
|
2566
|
+
}
|
|
2567
|
+
throw e;
|
|
2568
|
+
}
|
|
2506
2569
|
};
|
|
2507
2570
|
const validateQuery = async (query, schema, { auth } = {}) => {
|
|
2508
2571
|
if (!schema) {
|
|
@@ -2539,7 +2602,15 @@ const createAPIValidators = (opts) => {
|
|
|
2539
2602
|
})
|
|
2540
2603
|
);
|
|
2541
2604
|
}
|
|
2542
|
-
|
|
2605
|
+
try {
|
|
2606
|
+
await pipe(...transforms)(filters2);
|
|
2607
|
+
} catch (e) {
|
|
2608
|
+
if (e instanceof ValidationError) {
|
|
2609
|
+
e.details.source = "query";
|
|
2610
|
+
e.details.param = "filters";
|
|
2611
|
+
}
|
|
2612
|
+
throw e;
|
|
2613
|
+
}
|
|
2543
2614
|
};
|
|
2544
2615
|
const validateSort = async (sort2, schema, { auth } = {}) => {
|
|
2545
2616
|
if (!schema) {
|
|
@@ -2554,14 +2625,30 @@ const createAPIValidators = (opts) => {
|
|
|
2554
2625
|
})
|
|
2555
2626
|
);
|
|
2556
2627
|
}
|
|
2557
|
-
|
|
2628
|
+
try {
|
|
2629
|
+
await pipe(...transforms)(sort2);
|
|
2630
|
+
} catch (e) {
|
|
2631
|
+
if (e instanceof ValidationError) {
|
|
2632
|
+
e.details.source = "query";
|
|
2633
|
+
e.details.param = "sort";
|
|
2634
|
+
}
|
|
2635
|
+
throw e;
|
|
2636
|
+
}
|
|
2558
2637
|
};
|
|
2559
2638
|
const validateFields = async (fields2, schema) => {
|
|
2560
2639
|
if (!schema) {
|
|
2561
2640
|
throw new Error("Missing schema in validateFields");
|
|
2562
2641
|
}
|
|
2563
2642
|
const transforms = [defaultValidateFields({ schema, getModel })];
|
|
2564
|
-
|
|
2643
|
+
try {
|
|
2644
|
+
await pipe(...transforms)(fields2);
|
|
2645
|
+
} catch (e) {
|
|
2646
|
+
if (e instanceof ValidationError) {
|
|
2647
|
+
e.details.source = "query";
|
|
2648
|
+
e.details.param = "fields";
|
|
2649
|
+
}
|
|
2650
|
+
throw e;
|
|
2651
|
+
}
|
|
2565
2652
|
};
|
|
2566
2653
|
const validatePopulate = async (populate2, schema, { auth } = {}) => {
|
|
2567
2654
|
if (!schema) {
|
|
@@ -2576,7 +2663,15 @@ const createAPIValidators = (opts) => {
|
|
|
2576
2663
|
})
|
|
2577
2664
|
);
|
|
2578
2665
|
}
|
|
2579
|
-
|
|
2666
|
+
try {
|
|
2667
|
+
await pipe(...transforms)(populate2);
|
|
2668
|
+
} catch (e) {
|
|
2669
|
+
if (e instanceof ValidationError) {
|
|
2670
|
+
e.details.source = "query";
|
|
2671
|
+
e.details.param = "populate";
|
|
2672
|
+
}
|
|
2673
|
+
throw e;
|
|
2674
|
+
}
|
|
2580
2675
|
};
|
|
2581
2676
|
return {
|
|
2582
2677
|
input: validateInput,
|
|
@@ -2660,8 +2755,57 @@ const withDefaultPagination = (args, { defaults = {}, maxLimit = -1 } = {}) => {
|
|
|
2660
2755
|
);
|
|
2661
2756
|
return replacePaginationAttributes(args);
|
|
2662
2757
|
};
|
|
2758
|
+
const transformPagedPaginationInfo = (paginationInfo, total) => {
|
|
2759
|
+
if (!fp.isNil(paginationInfo.page)) {
|
|
2760
|
+
const page = paginationInfo.page;
|
|
2761
|
+
const pageSize = paginationInfo.pageSize ?? total;
|
|
2762
|
+
return {
|
|
2763
|
+
page,
|
|
2764
|
+
pageSize,
|
|
2765
|
+
pageCount: pageSize > 0 ? Math.ceil(total / pageSize) : 0,
|
|
2766
|
+
total
|
|
2767
|
+
};
|
|
2768
|
+
}
|
|
2769
|
+
if (!fp.isNil(paginationInfo.start)) {
|
|
2770
|
+
const start = paginationInfo.start;
|
|
2771
|
+
const limit = paginationInfo.limit ?? total;
|
|
2772
|
+
return {
|
|
2773
|
+
page: Math.floor(start / limit) + 1,
|
|
2774
|
+
pageSize: limit,
|
|
2775
|
+
pageCount: limit > 0 ? Math.ceil(total / limit) : 0,
|
|
2776
|
+
total
|
|
2777
|
+
};
|
|
2778
|
+
}
|
|
2779
|
+
return {
|
|
2780
|
+
...paginationInfo,
|
|
2781
|
+
page: 1,
|
|
2782
|
+
pageSize: 10,
|
|
2783
|
+
pageCount: 1,
|
|
2784
|
+
total
|
|
2785
|
+
};
|
|
2786
|
+
};
|
|
2787
|
+
const transformOffsetPaginationInfo = (paginationInfo, total) => {
|
|
2788
|
+
if (!fp.isNil(paginationInfo.page)) {
|
|
2789
|
+
const limit = paginationInfo.pageSize ?? total;
|
|
2790
|
+
const start = (paginationInfo.page - 1) * limit;
|
|
2791
|
+
return { start, limit, total };
|
|
2792
|
+
}
|
|
2793
|
+
if (!fp.isNil(paginationInfo.start)) {
|
|
2794
|
+
const start = paginationInfo.start;
|
|
2795
|
+
const limit = paginationInfo.limit ?? total;
|
|
2796
|
+
return { start, limit, total };
|
|
2797
|
+
}
|
|
2798
|
+
return {
|
|
2799
|
+
...paginationInfo,
|
|
2800
|
+
start: 0,
|
|
2801
|
+
limit: 10,
|
|
2802
|
+
total
|
|
2803
|
+
};
|
|
2804
|
+
};
|
|
2663
2805
|
const pagination = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2664
2806
|
__proto__: null,
|
|
2807
|
+
transformOffsetPaginationInfo,
|
|
2808
|
+
transformPagedPaginationInfo,
|
|
2665
2809
|
withDefaultPagination
|
|
2666
2810
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
2667
2811
|
const SUPPORTED_PACKAGE_MANAGERS = ["npm", "yarn"];
|