@strapi/utils 5.12.1 → 5.12.2
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/async.js +28 -0
- package/dist/async.js.map +1 -0
- package/dist/async.mjs +24 -0
- package/dist/async.mjs.map +1 -0
- package/dist/content-types.js +201 -0
- package/dist/content-types.js.map +1 -0
- package/dist/content-types.mjs +167 -0
- package/dist/content-types.mjs.map +1 -0
- package/dist/convert-query-params.js +512 -0
- package/dist/convert-query-params.js.map +1 -0
- package/dist/convert-query-params.mjs +510 -0
- package/dist/convert-query-params.mjs.map +1 -0
- package/dist/env-helper.js +81 -0
- package/dist/env-helper.js.map +1 -0
- package/dist/env-helper.mjs +79 -0
- package/dist/env-helper.mjs.map +1 -0
- package/dist/errors.js +104 -0
- package/dist/errors.js.map +1 -0
- package/dist/errors.mjs +88 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/file.js +57 -0
- package/dist/file.js.map +1 -0
- package/dist/file.mjs +50 -0
- package/dist/file.mjs.map +1 -0
- package/dist/format-yup-error.js +19 -0
- package/dist/format-yup-error.js.map +1 -0
- package/dist/format-yup-error.mjs +17 -0
- package/dist/format-yup-error.mjs.map +1 -0
- package/dist/hooks.js +86 -0
- package/dist/hooks.js.map +1 -0
- package/dist/hooks.mjs +80 -0
- package/dist/hooks.mjs.map +1 -0
- package/dist/import-default.js +9 -0
- package/dist/import-default.js.map +1 -0
- package/dist/import-default.mjs +7 -0
- package/dist/import-default.mjs.map +1 -0
- package/dist/index.js +54 -4358
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -4317
- package/dist/index.mjs.map +1 -1
- package/dist/machine-id.js +17 -0
- package/dist/machine-id.js.map +1 -0
- package/dist/machine-id.mjs +15 -0
- package/dist/machine-id.mjs.map +1 -0
- package/dist/operators.js +79 -0
- package/dist/operators.js.map +1 -0
- package/dist/operators.mjs +76 -0
- package/dist/operators.mjs.map +1 -0
- package/dist/package-manager.js +36 -0
- package/dist/package-manager.js.map +1 -0
- package/dist/package-manager.mjs +33 -0
- package/dist/package-manager.mjs.map +1 -0
- package/dist/pagination.js +163 -0
- package/dist/pagination.js.map +1 -0
- package/dist/pagination.mjs +159 -0
- package/dist/pagination.mjs.map +1 -0
- package/dist/parse-type.js +140 -0
- package/dist/parse-type.js.map +1 -0
- package/dist/parse-type.mjs +118 -0
- package/dist/parse-type.mjs.map +1 -0
- package/dist/policy.js +33 -0
- package/dist/policy.js.map +1 -0
- package/dist/policy.mjs +30 -0
- package/dist/policy.mjs.map +1 -0
- package/dist/primitives/arrays.js +7 -0
- package/dist/primitives/arrays.js.map +1 -0
- package/dist/primitives/arrays.mjs +5 -0
- package/dist/primitives/arrays.mjs.map +1 -0
- package/dist/primitives/dates.js +11 -0
- package/dist/primitives/dates.js.map +1 -0
- package/dist/primitives/dates.mjs +9 -0
- package/dist/primitives/dates.mjs.map +1 -0
- package/dist/primitives/objects.js +13 -0
- package/dist/primitives/objects.js.map +1 -0
- package/dist/primitives/objects.mjs +11 -0
- package/dist/primitives/objects.mjs.map +1 -0
- package/dist/primitives/strings.js +49 -0
- package/dist/primitives/strings.js.map +1 -0
- package/dist/primitives/strings.mjs +38 -0
- package/dist/primitives/strings.mjs.map +1 -0
- package/dist/print-value.js +42 -0
- package/dist/print-value.js.map +1 -0
- package/dist/print-value.mjs +40 -0
- package/dist/print-value.mjs.map +1 -0
- package/dist/provider-factory.js +82 -0
- package/dist/provider-factory.js.map +1 -0
- package/dist/provider-factory.mjs +80 -0
- package/dist/provider-factory.mjs.map +1 -0
- package/dist/relations.js +54 -0
- package/dist/relations.js.map +1 -0
- package/dist/relations.mjs +45 -0
- package/dist/relations.mjs.map +1 -0
- package/dist/sanitize/index.js +195 -0
- package/dist/sanitize/index.js.map +1 -0
- package/dist/sanitize/index.mjs +194 -0
- package/dist/sanitize/index.mjs.map +1 -0
- package/dist/sanitize/sanitizers.js +173 -0
- package/dist/sanitize/sanitizers.js.map +1 -0
- package/dist/sanitize/sanitizers.mjs +166 -0
- package/dist/sanitize/sanitizers.mjs.map +1 -0
- package/dist/sanitize/visitors/expand-wildcard-populate.js +20 -0
- package/dist/sanitize/visitors/expand-wildcard-populate.js.map +1 -0
- package/dist/sanitize/visitors/expand-wildcard-populate.mjs +18 -0
- package/dist/sanitize/visitors/expand-wildcard-populate.mjs.map +1 -0
- package/dist/sanitize/visitors/index.js +22 -0
- package/dist/sanitize/visitors/index.js.map +1 -0
- package/dist/sanitize/visitors/index.mjs +9 -0
- package/dist/sanitize/visitors/index.mjs.map +1 -0
- package/dist/sanitize/visitors/remove-disallowed-fields.js +87 -0
- package/dist/sanitize/visitors/remove-disallowed-fields.js.map +1 -0
- package/dist/sanitize/visitors/remove-disallowed-fields.mjs +85 -0
- package/dist/sanitize/visitors/remove-disallowed-fields.mjs.map +1 -0
- package/dist/sanitize/visitors/remove-dynamic-zones.js +12 -0
- package/dist/sanitize/visitors/remove-dynamic-zones.js.map +1 -0
- package/dist/sanitize/visitors/remove-dynamic-zones.mjs +10 -0
- package/dist/sanitize/visitors/remove-dynamic-zones.mjs.map +1 -0
- package/dist/sanitize/visitors/remove-morph-to-relations.js +12 -0
- package/dist/sanitize/visitors/remove-morph-to-relations.js.map +1 -0
- package/dist/sanitize/visitors/remove-morph-to-relations.mjs +10 -0
- package/dist/sanitize/visitors/remove-morph-to-relations.mjs.map +1 -0
- package/dist/sanitize/visitors/remove-password.js +10 -0
- package/dist/sanitize/visitors/remove-password.js.map +1 -0
- package/dist/sanitize/visitors/remove-password.mjs +8 -0
- package/dist/sanitize/visitors/remove-password.mjs.map +1 -0
- package/dist/sanitize/visitors/remove-private.js +16 -0
- package/dist/sanitize/visitors/remove-private.js.map +1 -0
- package/dist/sanitize/visitors/remove-private.mjs +14 -0
- package/dist/sanitize/visitors/remove-private.mjs.map +1 -0
- package/dist/sanitize/visitors/remove-restricted-fields.js +28 -0
- package/dist/sanitize/visitors/remove-restricted-fields.js.map +1 -0
- package/dist/sanitize/visitors/remove-restricted-fields.mjs +26 -0
- package/dist/sanitize/visitors/remove-restricted-fields.mjs.map +1 -0
- package/dist/sanitize/visitors/remove-restricted-relations.js +116 -0
- package/dist/sanitize/visitors/remove-restricted-relations.js.map +1 -0
- package/dist/sanitize/visitors/remove-restricted-relations.mjs +114 -0
- package/dist/sanitize/visitors/remove-restricted-relations.mjs.map +1 -0
- package/dist/set-creator-fields.js +18 -0
- package/dist/set-creator-fields.js.map +1 -0
- package/dist/set-creator-fields.mjs +16 -0
- package/dist/set-creator-fields.mjs.map +1 -0
- package/dist/template.js +18 -0
- package/dist/template.js.map +1 -0
- package/dist/template.mjs +15 -0
- package/dist/template.mjs.map +1 -0
- package/dist/traverse/factory.js +158 -0
- package/dist/traverse/factory.js.map +1 -0
- package/dist/traverse/factory.mjs +156 -0
- package/dist/traverse/factory.mjs.map +1 -0
- package/dist/traverse/index.js +14 -0
- package/dist/traverse/index.js.map +1 -0
- package/dist/traverse/index.mjs +5 -0
- package/dist/traverse/index.mjs.map +1 -0
- package/dist/traverse/query-fields.js +41 -0
- package/dist/traverse/query-fields.js.map +1 -0
- package/dist/traverse/query-fields.mjs +39 -0
- package/dist/traverse/query-fields.mjs.map +1 -0
- package/dist/traverse/query-filters.js +114 -0
- package/dist/traverse/query-filters.js.map +1 -0
- package/dist/traverse/query-filters.mjs +112 -0
- package/dist/traverse/query-filters.mjs.map +1 -0
- package/dist/traverse/query-populate.js +280 -0
- package/dist/traverse/query-populate.js.map +1 -0
- package/dist/traverse/query-populate.mjs +278 -0
- package/dist/traverse/query-populate.mjs.map +1 -0
- package/dist/traverse/query-sort.js +144 -0
- package/dist/traverse/query-sort.js.map +1 -0
- package/dist/traverse/query-sort.mjs +142 -0
- package/dist/traverse/query-sort.mjs.map +1 -0
- package/dist/traverse-entity.js +170 -0
- package/dist/traverse-entity.js.map +1 -0
- package/dist/traverse-entity.mjs +168 -0
- package/dist/traverse-entity.mjs.map +1 -0
- package/dist/validate/index.js +218 -0
- package/dist/validate/index.js.map +1 -0
- package/dist/validate/index.mjs +217 -0
- package/dist/validate/index.mjs.map +1 -0
- package/dist/validate/utils.js +27 -0
- package/dist/validate/utils.js.map +1 -0
- package/dist/validate/utils.mjs +24 -0
- package/dist/validate/utils.mjs.map +1 -0
- package/dist/validate/validators.js +369 -0
- package/dist/validate/validators.js.map +1 -0
- package/dist/validate/validators.mjs +356 -0
- package/dist/validate/validators.mjs.map +1 -0
- package/dist/validate/visitors/index.js +22 -0
- package/dist/validate/visitors/index.js.map +1 -0
- package/dist/validate/visitors/index.mjs +9 -0
- package/dist/validate/visitors/index.mjs.map +1 -0
- package/dist/validate/visitors/throw-disallowed-fields.js +91 -0
- package/dist/validate/visitors/throw-disallowed-fields.js.map +1 -0
- package/dist/validate/visitors/throw-disallowed-fields.mjs +89 -0
- package/dist/validate/visitors/throw-disallowed-fields.mjs.map +1 -0
- package/dist/validate/visitors/throw-dynamic-zones.js +16 -0
- package/dist/validate/visitors/throw-dynamic-zones.js.map +1 -0
- package/dist/validate/visitors/throw-dynamic-zones.mjs +14 -0
- package/dist/validate/visitors/throw-dynamic-zones.mjs.map +1 -0
- package/dist/validate/visitors/throw-morph-to-relations.js +16 -0
- package/dist/validate/visitors/throw-morph-to-relations.js.map +1 -0
- package/dist/validate/visitors/throw-morph-to-relations.mjs +14 -0
- package/dist/validate/visitors/throw-morph-to-relations.mjs.map +1 -0
- package/dist/validate/visitors/throw-password.js +15 -0
- package/dist/validate/visitors/throw-password.js.map +1 -0
- package/dist/validate/visitors/throw-password.mjs +13 -0
- package/dist/validate/visitors/throw-password.mjs.map +1 -0
- package/dist/validate/visitors/throw-private.js +20 -0
- package/dist/validate/visitors/throw-private.js.map +1 -0
- package/dist/validate/visitors/throw-private.mjs +18 -0
- package/dist/validate/visitors/throw-private.mjs.map +1 -0
- package/dist/validate/visitors/throw-restricted-fields.js +36 -0
- package/dist/validate/visitors/throw-restricted-fields.js.map +1 -0
- package/dist/validate/visitors/throw-restricted-fields.mjs +34 -0
- package/dist/validate/visitors/throw-restricted-fields.mjs.map +1 -0
- package/dist/validate/visitors/throw-restricted-relations.js +125 -0
- package/dist/validate/visitors/throw-restricted-relations.js.map +1 -0
- package/dist/validate/visitors/throw-restricted-relations.mjs +123 -0
- package/dist/validate/visitors/throw-restricted-relations.mjs.map +1 -0
- package/dist/validate/visitors/throw-unrecognized-fields.js +66 -0
- package/dist/validate/visitors/throw-unrecognized-fields.js.map +1 -0
- package/dist/validate/visitors/throw-unrecognized-fields.mjs +64 -0
- package/dist/validate/visitors/throw-unrecognized-fields.mjs.map +1 -0
- package/dist/validators.js +60 -0
- package/dist/validators.js.map +1 -0
- package/dist/validators.mjs +37 -0
- package/dist/validators.mjs.map +1 -0
- package/dist/yup.js +101 -0
- package/dist/yup.js.map +1 -0
- package/dist/yup.mjs +74 -0
- package/dist/yup.mjs.map +1 -0
- package/dist/zod.js +31 -0
- package/dist/zod.js.map +1 -0
- package/dist/zod.mjs +29 -0
- package/dist/zod.mjs.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { constants, isMorphToRelationalAttribute, isComponentSchema, isDynamicZoneAttribute, hasRelationReordering, isRelationalAttribute, isMediaAttribute } from '../../content-types.mjs';
|
|
2
|
+
import { throwInvalidKey } from '../utils.mjs';
|
|
3
|
+
|
|
4
|
+
// TODO these should all be centralized somewhere instead of maintaining a list
|
|
5
|
+
const ID_FIELDS = [
|
|
6
|
+
constants.DOC_ID_ATTRIBUTE,
|
|
7
|
+
constants.DOC_ID_ATTRIBUTE
|
|
8
|
+
];
|
|
9
|
+
const ALLOWED_ROOT_LEVEL_FIELDS = [
|
|
10
|
+
...ID_FIELDS
|
|
11
|
+
];
|
|
12
|
+
const MORPH_TO_ALLOWED_FIELDS = [
|
|
13
|
+
'__type'
|
|
14
|
+
];
|
|
15
|
+
const DYNAMIC_ZONE_ALLOWED_FIELDS = [
|
|
16
|
+
'__component'
|
|
17
|
+
];
|
|
18
|
+
const RELATION_REORDERING_FIELDS = [
|
|
19
|
+
'connect',
|
|
20
|
+
'disconnect',
|
|
21
|
+
'set',
|
|
22
|
+
'options'
|
|
23
|
+
];
|
|
24
|
+
const throwUnrecognizedFields = ({ key, attribute, path, schema, parent })=>{
|
|
25
|
+
// We only look at properties that are not attributes
|
|
26
|
+
if (attribute) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// At root level (path.attribute === null), only accept allowed fields
|
|
30
|
+
if (path.attribute === null) {
|
|
31
|
+
if (ALLOWED_ROOT_LEVEL_FIELDS.includes(key)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
return throwInvalidKey({
|
|
35
|
+
key,
|
|
36
|
+
path: attribute
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
// allow special morphTo keys
|
|
40
|
+
if (isMorphToRelationalAttribute(parent?.attribute) && MORPH_TO_ALLOWED_FIELDS.includes(key)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// allow special dz keys
|
|
44
|
+
if (isComponentSchema(schema) && isDynamicZoneAttribute(parent?.attribute) && DYNAMIC_ZONE_ALLOWED_FIELDS.includes(key)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// allow special relation reordering keys in manyToX and XtoMany relations
|
|
48
|
+
if (hasRelationReordering(parent?.attribute) && RELATION_REORDERING_FIELDS.includes(key)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// allow id fields where it is needed for setting a relational id rather than trying to create with a given id
|
|
52
|
+
const canUseID = isRelationalAttribute(parent?.attribute) || isMediaAttribute(parent?.attribute);
|
|
53
|
+
if (canUseID && !ID_FIELDS.includes(key)) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
// if we couldn't find any reason for it to be here, throw
|
|
57
|
+
throwInvalidKey({
|
|
58
|
+
key,
|
|
59
|
+
path: attribute
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export { throwUnrecognizedFields as default };
|
|
64
|
+
//# sourceMappingURL=throw-unrecognized-fields.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throw-unrecognized-fields.mjs","sources":["../../../src/validate/visitors/throw-unrecognized-fields.ts"],"sourcesContent":["import {\n isDynamicZoneAttribute,\n isMorphToRelationalAttribute,\n isRelationalAttribute,\n constants,\n isComponentSchema,\n isMediaAttribute,\n hasRelationReordering,\n} from '../../content-types';\nimport type { Visitor } from '../../traverse-entity';\nimport { throwInvalidKey } from '../utils';\n\n// TODO these should all be centralized somewhere instead of maintaining a list\nconst ID_FIELDS = [constants.DOC_ID_ATTRIBUTE, constants.DOC_ID_ATTRIBUTE];\nconst ALLOWED_ROOT_LEVEL_FIELDS = [...ID_FIELDS];\nconst MORPH_TO_ALLOWED_FIELDS = ['__type'];\nconst DYNAMIC_ZONE_ALLOWED_FIELDS = ['__component'];\nconst RELATION_REORDERING_FIELDS = ['connect', 'disconnect', 'set', 'options'];\n\nconst throwUnrecognizedFields: Visitor = ({ key, attribute, path, schema, parent }) => {\n // We only look at properties that are not attributes\n if (attribute) {\n return;\n }\n\n // At root level (path.attribute === null), only accept allowed fields\n if (path.attribute === null) {\n if (ALLOWED_ROOT_LEVEL_FIELDS.includes(key)) {\n return;\n }\n\n return throwInvalidKey({ key, path: attribute });\n }\n\n // allow special morphTo keys\n if (isMorphToRelationalAttribute(parent?.attribute) && MORPH_TO_ALLOWED_FIELDS.includes(key)) {\n return;\n }\n\n // allow special dz keys\n if (\n isComponentSchema(schema) &&\n isDynamicZoneAttribute(parent?.attribute) &&\n DYNAMIC_ZONE_ALLOWED_FIELDS.includes(key)\n ) {\n return;\n }\n\n // allow special relation reordering keys in manyToX and XtoMany relations\n if (hasRelationReordering(parent?.attribute) && RELATION_REORDERING_FIELDS.includes(key)) {\n return;\n }\n\n // allow id fields where it is needed for setting a relational id rather than trying to create with a given id\n const canUseID = isRelationalAttribute(parent?.attribute) || isMediaAttribute(parent?.attribute);\n if (canUseID && !ID_FIELDS.includes(key)) {\n return;\n }\n\n // if we couldn't find any reason for it to be here, throw\n throwInvalidKey({ key, path: attribute });\n};\n\nexport default throwUnrecognizedFields;\n"],"names":["ID_FIELDS","constants","DOC_ID_ATTRIBUTE","ALLOWED_ROOT_LEVEL_FIELDS","MORPH_TO_ALLOWED_FIELDS","DYNAMIC_ZONE_ALLOWED_FIELDS","RELATION_REORDERING_FIELDS","throwUnrecognizedFields","key","attribute","path","schema","parent","includes","throwInvalidKey","isMorphToRelationalAttribute","isComponentSchema","isDynamicZoneAttribute","hasRelationReordering","canUseID","isRelationalAttribute","isMediaAttribute"],"mappings":";;;AAYA;AACA,MAAMA,SAAY,GAAA;AAACC,IAAAA,SAAAA,CAAUC,gBAAgB;AAAED,IAAAA,SAAAA,CAAUC;AAAiB,CAAA;AAC1E,MAAMC,yBAA4B,GAAA;AAAIH,IAAAA,GAAAA;AAAU,CAAA;AAChD,MAAMI,uBAA0B,GAAA;AAAC,IAAA;AAAS,CAAA;AAC1C,MAAMC,2BAA8B,GAAA;AAAC,IAAA;AAAc,CAAA;AACnD,MAAMC,0BAA6B,GAAA;AAAC,IAAA,SAAA;AAAW,IAAA,YAAA;AAAc,IAAA,KAAA;AAAO,IAAA;AAAU,CAAA;AAE9E,MAAMC,uBAAmC,GAAA,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,EAAE,GAAA;;AAEhF,IAAA,IAAIH,SAAW,EAAA;AACb,QAAA;AACF;;IAGA,IAAIC,IAAAA,CAAKD,SAAS,KAAK,IAAM,EAAA;QAC3B,IAAIN,yBAAAA,CAA0BU,QAAQ,CAACL,GAAM,CAAA,EAAA;AAC3C,YAAA;AACF;AAEA,QAAA,OAAOM,eAAgB,CAAA;AAAEN,YAAAA,GAAAA;YAAKE,IAAMD,EAAAA;AAAU,SAAA,CAAA;AAChD;;AAGA,IAAA,IAAIM,6BAA6BH,MAAQH,EAAAA,SAAAA,CAAAA,IAAcL,uBAAwBS,CAAAA,QAAQ,CAACL,GAAM,CAAA,EAAA;AAC5F,QAAA;AACF;;IAGA,IACEQ,iBAAAA,CAAkBL,WAClBM,sBAAuBL,CAAAA,MAAAA,EAAQH,cAC/BJ,2BAA4BQ,CAAAA,QAAQ,CAACL,GACrC,CAAA,EAAA;AACA,QAAA;AACF;;AAGA,IAAA,IAAIU,sBAAsBN,MAAQH,EAAAA,SAAAA,CAAAA,IAAcH,0BAA2BO,CAAAA,QAAQ,CAACL,GAAM,CAAA,EAAA;AACxF,QAAA;AACF;;AAGA,IAAA,MAAMW,QAAWC,GAAAA,qBAAAA,CAAsBR,MAAQH,EAAAA,SAAAA,CAAAA,IAAcY,iBAAiBT,MAAQH,EAAAA,SAAAA,CAAAA;AACtF,IAAA,IAAIU,QAAY,IAAA,CAACnB,SAAUa,CAAAA,QAAQ,CAACL,GAAM,CAAA,EAAA;AACxC,QAAA;AACF;;IAGAM,eAAgB,CAAA;AAAEN,QAAAA,GAAAA;QAAKE,IAAMD,EAAAA;AAAU,KAAA,CAAA;AACzC;;;;"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var yup = require('yup');
|
|
4
|
+
var fp = require('lodash/fp');
|
|
5
|
+
var errors = require('./errors.js');
|
|
6
|
+
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var yup__namespace = /*#__PURE__*/_interopNamespaceDefault(yup);
|
|
25
|
+
|
|
26
|
+
const handleYupError = (error, errorMessage)=>{
|
|
27
|
+
throw new errors.YupValidationError(error, errorMessage);
|
|
28
|
+
};
|
|
29
|
+
const defaultValidationParam = {
|
|
30
|
+
strict: true,
|
|
31
|
+
abortEarly: false
|
|
32
|
+
};
|
|
33
|
+
const validateYupSchema = (schema, options = {})=>async (body, errorMessage)=>{
|
|
34
|
+
try {
|
|
35
|
+
const optionsWithDefaults = fp.defaults(defaultValidationParam, options);
|
|
36
|
+
const result = await schema.validate(body, optionsWithDefaults);
|
|
37
|
+
return result;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
if (e instanceof yup__namespace.ValidationError) {
|
|
40
|
+
handleYupError(e, errorMessage);
|
|
41
|
+
}
|
|
42
|
+
throw e;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const validateYupSchemaSync = (schema, options = {})=>(body, errorMessage)=>{
|
|
46
|
+
try {
|
|
47
|
+
const optionsWithDefaults = fp.defaults(defaultValidationParam, options);
|
|
48
|
+
return schema.validateSync(body, optionsWithDefaults);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (e instanceof yup__namespace.ValidationError) {
|
|
51
|
+
handleYupError(e, errorMessage);
|
|
52
|
+
}
|
|
53
|
+
throw e;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
exports.handleYupError = handleYupError;
|
|
58
|
+
exports.validateYupSchema = validateYupSchema;
|
|
59
|
+
exports.validateYupSchemaSync = validateYupSchemaSync;
|
|
60
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sources":["../src/validators.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\n/* eslint-disable no-template-curly-in-string */\nimport * as yup from 'yup';\nimport { defaults } from 'lodash/fp';\nimport { YupValidationError } from './errors';\n\nconst handleYupError = (error: yup.ValidationError, errorMessage?: string) => {\n throw new YupValidationError(error, errorMessage);\n};\n\nconst defaultValidationParam = { strict: true, abortEarly: false };\n\nconst validateYupSchema =\n <TSchema extends yup.AnySchema>(schema: TSchema, options = {}) =>\n async (body: unknown, errorMessage?: string): Promise<yup.InferType<TSchema>> => {\n try {\n const optionsWithDefaults = defaults(defaultValidationParam, options);\n const result = await schema.validate(body, optionsWithDefaults);\n return result;\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n handleYupError(e, errorMessage);\n }\n\n throw e;\n }\n };\n\nconst validateYupSchemaSync =\n <TSchema extends yup.AnySchema>(schema: yup.AnySchema, options = {}) =>\n (body: unknown, errorMessage?: string): yup.InferType<TSchema> => {\n try {\n const optionsWithDefaults = defaults(defaultValidationParam, options);\n return schema.validateSync(body, optionsWithDefaults);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n handleYupError(e, errorMessage);\n }\n\n throw e;\n }\n };\n\nexport { handleYupError, validateYupSchema, validateYupSchemaSync };\n"],"names":["handleYupError","error","errorMessage","YupValidationError","defaultValidationParam","strict","abortEarly","validateYupSchema","schema","options","body","optionsWithDefaults","defaults","result","validate","e","yup","ValidationError","validateYupSchemaSync","validateSync"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAMMA,MAAAA,cAAAA,GAAiB,CAACC,KAA4BC,EAAAA,YAAAA,GAAAA;IAClD,MAAM,IAAIC,0BAAmBF,KAAOC,EAAAA,YAAAA,CAAAA;AACtC;AAEA,MAAME,sBAAyB,GAAA;IAAEC,MAAQ,EAAA,IAAA;IAAMC,UAAY,EAAA;AAAM,CAAA;AAE3DC,MAAAA,iBAAAA,GACJ,CAAgCC,MAAiBC,EAAAA,OAAAA,GAAU,EAAE,GAC7D,OAAOC,IAAeR,EAAAA,YAAAA,GAAAA;QACpB,IAAI;YACF,MAAMS,mBAAAA,GAAsBC,YAASR,sBAAwBK,EAAAA,OAAAA,CAAAA;AAC7D,YAAA,MAAMI,MAAS,GAAA,MAAML,MAAOM,CAAAA,QAAQ,CAACJ,IAAMC,EAAAA,mBAAAA,CAAAA;YAC3C,OAAOE,MAAAA;AACT,SAAA,CAAE,OAAOE,CAAG,EAAA;YACV,IAAIA,CAAAA,YAAaC,cAAIC,CAAAA,eAAe,EAAE;AACpCjB,gBAAAA,cAAAA,CAAee,CAAGb,EAAAA,YAAAA,CAAAA;AACpB;YAEA,MAAMa,CAAAA;AACR;AACF;AAEIG,MAAAA,qBAAAA,GACJ,CAAgCV,MAAuBC,EAAAA,OAAAA,GAAU,EAAE,GACnE,CAACC,IAAeR,EAAAA,YAAAA,GAAAA;QACd,IAAI;YACF,MAAMS,mBAAAA,GAAsBC,YAASR,sBAAwBK,EAAAA,OAAAA,CAAAA;YAC7D,OAAOD,MAAAA,CAAOW,YAAY,CAACT,IAAMC,EAAAA,mBAAAA,CAAAA;AACnC,SAAA,CAAE,OAAOI,CAAG,EAAA;YACV,IAAIA,CAAAA,YAAaC,cAAIC,CAAAA,eAAe,EAAE;AACpCjB,gBAAAA,cAAAA,CAAee,CAAGb,EAAAA,YAAAA,CAAAA;AACpB;YAEA,MAAMa,CAAAA;AACR;AACF;;;;;;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as yup from 'yup';
|
|
2
|
+
import { defaults } from 'lodash/fp';
|
|
3
|
+
import { YupValidationError } from './errors.mjs';
|
|
4
|
+
|
|
5
|
+
const handleYupError = (error, errorMessage)=>{
|
|
6
|
+
throw new YupValidationError(error, errorMessage);
|
|
7
|
+
};
|
|
8
|
+
const defaultValidationParam = {
|
|
9
|
+
strict: true,
|
|
10
|
+
abortEarly: false
|
|
11
|
+
};
|
|
12
|
+
const validateYupSchema = (schema, options = {})=>async (body, errorMessage)=>{
|
|
13
|
+
try {
|
|
14
|
+
const optionsWithDefaults = defaults(defaultValidationParam, options);
|
|
15
|
+
const result = await schema.validate(body, optionsWithDefaults);
|
|
16
|
+
return result;
|
|
17
|
+
} catch (e) {
|
|
18
|
+
if (e instanceof yup.ValidationError) {
|
|
19
|
+
handleYupError(e, errorMessage);
|
|
20
|
+
}
|
|
21
|
+
throw e;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const validateYupSchemaSync = (schema, options = {})=>(body, errorMessage)=>{
|
|
25
|
+
try {
|
|
26
|
+
const optionsWithDefaults = defaults(defaultValidationParam, options);
|
|
27
|
+
return schema.validateSync(body, optionsWithDefaults);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
if (e instanceof yup.ValidationError) {
|
|
30
|
+
handleYupError(e, errorMessage);
|
|
31
|
+
}
|
|
32
|
+
throw e;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { handleYupError, validateYupSchema, validateYupSchemaSync };
|
|
37
|
+
//# sourceMappingURL=validators.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.mjs","sources":["../src/validators.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\n/* eslint-disable no-template-curly-in-string */\nimport * as yup from 'yup';\nimport { defaults } from 'lodash/fp';\nimport { YupValidationError } from './errors';\n\nconst handleYupError = (error: yup.ValidationError, errorMessage?: string) => {\n throw new YupValidationError(error, errorMessage);\n};\n\nconst defaultValidationParam = { strict: true, abortEarly: false };\n\nconst validateYupSchema =\n <TSchema extends yup.AnySchema>(schema: TSchema, options = {}) =>\n async (body: unknown, errorMessage?: string): Promise<yup.InferType<TSchema>> => {\n try {\n const optionsWithDefaults = defaults(defaultValidationParam, options);\n const result = await schema.validate(body, optionsWithDefaults);\n return result;\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n handleYupError(e, errorMessage);\n }\n\n throw e;\n }\n };\n\nconst validateYupSchemaSync =\n <TSchema extends yup.AnySchema>(schema: yup.AnySchema, options = {}) =>\n (body: unknown, errorMessage?: string): yup.InferType<TSchema> => {\n try {\n const optionsWithDefaults = defaults(defaultValidationParam, options);\n return schema.validateSync(body, optionsWithDefaults);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n handleYupError(e, errorMessage);\n }\n\n throw e;\n }\n };\n\nexport { handleYupError, validateYupSchema, validateYupSchemaSync };\n"],"names":["handleYupError","error","errorMessage","YupValidationError","defaultValidationParam","strict","abortEarly","validateYupSchema","schema","options","body","optionsWithDefaults","defaults","result","validate","e","yup","ValidationError","validateYupSchemaSync","validateSync"],"mappings":";;;;AAMMA,MAAAA,cAAAA,GAAiB,CAACC,KAA4BC,EAAAA,YAAAA,GAAAA;IAClD,MAAM,IAAIC,mBAAmBF,KAAOC,EAAAA,YAAAA,CAAAA;AACtC;AAEA,MAAME,sBAAyB,GAAA;IAAEC,MAAQ,EAAA,IAAA;IAAMC,UAAY,EAAA;AAAM,CAAA;AAE3DC,MAAAA,iBAAAA,GACJ,CAAgCC,MAAiBC,EAAAA,OAAAA,GAAU,EAAE,GAC7D,OAAOC,IAAeR,EAAAA,YAAAA,GAAAA;QACpB,IAAI;YACF,MAAMS,mBAAAA,GAAsBC,SAASR,sBAAwBK,EAAAA,OAAAA,CAAAA;AAC7D,YAAA,MAAMI,MAAS,GAAA,MAAML,MAAOM,CAAAA,QAAQ,CAACJ,IAAMC,EAAAA,mBAAAA,CAAAA;YAC3C,OAAOE,MAAAA;AACT,SAAA,CAAE,OAAOE,CAAG,EAAA;YACV,IAAIA,CAAAA,YAAaC,GAAIC,CAAAA,eAAe,EAAE;AACpCjB,gBAAAA,cAAAA,CAAee,CAAGb,EAAAA,YAAAA,CAAAA;AACpB;YAEA,MAAMa,CAAAA;AACR;AACF;AAEIG,MAAAA,qBAAAA,GACJ,CAAgCV,MAAuBC,EAAAA,OAAAA,GAAU,EAAE,GACnE,CAACC,IAAeR,EAAAA,YAAAA,GAAAA;QACd,IAAI;YACF,MAAMS,mBAAAA,GAAsBC,SAASR,sBAAwBK,EAAAA,OAAAA,CAAAA;YAC7D,OAAOD,MAAAA,CAAOW,YAAY,CAACT,IAAMC,EAAAA,mBAAAA,CAAAA;AACnC,SAAA,CAAE,OAAOI,CAAG,EAAA;YACV,IAAIA,CAAAA,YAAaC,GAAIC,CAAAA,eAAe,EAAE;AACpCjB,gBAAAA,cAAAA,CAAee,CAAGb,EAAAA,YAAAA,CAAAA;AACpB;YAEA,MAAMa,CAAAA;AACR;AACF;;;;"}
|
package/dist/yup.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var yup = require('yup');
|
|
4
|
+
var _ = require('lodash');
|
|
5
|
+
var fp = require('lodash/fp');
|
|
6
|
+
var strings = require('./primitives/strings.js');
|
|
7
|
+
var printValue = require('./print-value.js');
|
|
8
|
+
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var yup__namespace = /*#__PURE__*/_interopNamespaceDefault(yup);
|
|
27
|
+
|
|
28
|
+
const strapiID = ()=>new StrapiIDSchema();
|
|
29
|
+
const isNotNilTest = (value)=>!_.isNil(value);
|
|
30
|
+
const isNotNullTest = (value)=>!_.isNull(value);
|
|
31
|
+
yup__namespace.addMethod(yup__namespace.mixed, 'notNil', function isNotNill(msg = '${path} must be defined.') {
|
|
32
|
+
return this.test('defined', msg, isNotNilTest);
|
|
33
|
+
});
|
|
34
|
+
yup__namespace.addMethod(yup__namespace.mixed, 'notNull', function isNotNull(msg = '${path} cannot be null.') {
|
|
35
|
+
return this.test('defined', msg, isNotNullTest);
|
|
36
|
+
});
|
|
37
|
+
yup__namespace.addMethod(yup__namespace.mixed, 'isFunction', function isFunction(message = '${path} is not a function') {
|
|
38
|
+
return this.test('is a function', message, (value)=>_.isUndefined(value) || _.isFunction(value));
|
|
39
|
+
});
|
|
40
|
+
yup__namespace.addMethod(yup__namespace.string, 'isCamelCase', function isCamelCase(message = '${path} is not in camel case (anExampleOfCamelCase)') {
|
|
41
|
+
return this.test('is in camelCase', message, (value)=>value ? strings.isCamelCase(value) : true);
|
|
42
|
+
});
|
|
43
|
+
yup__namespace.addMethod(yup__namespace.string, 'isKebabCase', function isKebabCase(message = '${path} is not in kebab case (an-example-of-kebab-case)') {
|
|
44
|
+
return this.test('is in kebab-case', message, (value)=>value ? strings.isKebabCase(value) : true);
|
|
45
|
+
});
|
|
46
|
+
yup__namespace.addMethod(yup__namespace.object, 'onlyContainsFunctions', function onlyContainsFunctions(message = '${path} contains values that are not functions') {
|
|
47
|
+
return this.test('only contains functions', message, (value)=>_.isUndefined(value) || value && Object.values(value).every(_.isFunction));
|
|
48
|
+
});
|
|
49
|
+
yup__namespace.addMethod(yup__namespace.array, 'uniqueProperty', function uniqueProperty(propertyName, message) {
|
|
50
|
+
return this.test('unique', message, function unique(list) {
|
|
51
|
+
const errors = [];
|
|
52
|
+
list?.forEach((element, index)=>{
|
|
53
|
+
const sameElements = list.filter((e)=>fp.get(propertyName, e) === fp.get(propertyName, element));
|
|
54
|
+
if (sameElements.length > 1) {
|
|
55
|
+
errors.push(this.createError({
|
|
56
|
+
path: `${this.path}[${index}].${propertyName}`,
|
|
57
|
+
message
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
if (errors.length) {
|
|
62
|
+
throw new yup__namespace.ValidationError(errors);
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
class StrapiIDSchema extends yup__namespace.MixedSchema {
|
|
68
|
+
_typeCheck(value) {
|
|
69
|
+
return typeof value === 'string' || fp.isNumber(value) && fp.isInteger(value) && value >= 0;
|
|
70
|
+
}
|
|
71
|
+
constructor(){
|
|
72
|
+
super({
|
|
73
|
+
type: 'strapiID'
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// Temporary fix of this issue : https://github.com/jquense/yup/issues/616
|
|
78
|
+
yup__namespace.setLocale({
|
|
79
|
+
mixed: {
|
|
80
|
+
notType (options) {
|
|
81
|
+
const { path, type, value, originalValue } = options;
|
|
82
|
+
const isCast = originalValue != null && originalValue !== value;
|
|
83
|
+
const msg = `${path} must be a \`${type}\` type, ` + `but the final value was: \`${printValue.printValue(value, true)}\`${isCast ? ` (cast from the value \`${printValue.printValue(originalValue, true)}\`).` : '.'}`;
|
|
84
|
+
/* Remove comment that is not supposed to be seen by the enduser
|
|
85
|
+
if (value === null) {
|
|
86
|
+
msg += `\n If "null" is intended as an empty value be sure to mark the schema as \`.nullable()\``;
|
|
87
|
+
}
|
|
88
|
+
*/ return msg;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
exports.StrapiIDSchema = StrapiIDSchema;
|
|
94
|
+
exports.strapiID = strapiID;
|
|
95
|
+
Object.keys(yup).forEach(function (k) {
|
|
96
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
get: function () { return yup[k]; }
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
//# sourceMappingURL=yup.js.map
|
package/dist/yup.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yup.js","sources":["../src/yup.ts"],"sourcesContent":["/* eslint-disable no-template-curly-in-string */\n/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport * as yup from 'yup';\nimport _ from 'lodash';\nimport { isNumber, isInteger, get } from 'lodash/fp';\nimport { strings } from './primitives';\nimport { printValue } from './print-value';\n\nexport * from 'yup';\n\nexport const strapiID = (): InstanceType<typeof StrapiIDSchema> => new StrapiIDSchema();\n\nconst isNotNilTest = (value: unknown) => !_.isNil(value);\n\nconst isNotNullTest = (value: unknown) => !_.isNull(value);\n\nyup.addMethod(yup.mixed, 'notNil', function isNotNill(msg = '${path} must be defined.') {\n return this.test('defined', msg, isNotNilTest);\n});\n\nyup.addMethod(yup.mixed, 'notNull', function isNotNull(msg = '${path} cannot be null.') {\n return this.test('defined', msg, isNotNullTest);\n});\n\nyup.addMethod(yup.mixed, 'isFunction', function isFunction(message = '${path} is not a function') {\n return this.test(\n 'is a function',\n message,\n (value) => _.isUndefined(value) || _.isFunction(value)\n );\n});\n\nyup.addMethod(\n yup.string,\n 'isCamelCase',\n function isCamelCase(message = '${path} is not in camel case (anExampleOfCamelCase)') {\n return this.test('is in camelCase', message, (value) =>\n value ? strings.isCamelCase(value) : true\n );\n }\n);\n\nyup.addMethod(\n yup.string,\n 'isKebabCase',\n function isKebabCase(message = '${path} is not in kebab case (an-example-of-kebab-case)') {\n return this.test('is in kebab-case', message, (value) =>\n value ? strings.isKebabCase(value) : true\n );\n }\n);\n\nyup.addMethod(\n yup.object,\n 'onlyContainsFunctions',\n function onlyContainsFunctions(message = '${path} contains values that are not functions') {\n return this.test(\n 'only contains functions',\n message,\n (value) => _.isUndefined(value) || (value && Object.values(value).every(_.isFunction))\n );\n }\n);\n\nyup.addMethod(\n yup.array,\n 'uniqueProperty',\n function uniqueProperty(propertyName: string, message: string) {\n return this.test('unique', message, function unique(list) {\n const errors: yup.ValidationError[] = [];\n\n list?.forEach((element, index) => {\n const sameElements = list.filter(\n (e) => get(propertyName, e) === get(propertyName, element)\n );\n if (sameElements.length > 1) {\n errors.push(\n this.createError({\n path: `${this.path}[${index}].${propertyName}`,\n message,\n })\n );\n }\n });\n\n if (errors.length) {\n throw new yup.ValidationError(errors);\n }\n return true;\n });\n }\n);\n\nexport class StrapiIDSchema extends yup.MixedSchema {\n constructor() {\n super({ type: 'strapiID' });\n }\n\n _typeCheck(value: unknown): value is string | number {\n return typeof value === 'string' || (isNumber(value) && isInteger(value) && value >= 0);\n }\n}\n\ndeclare module 'yup' {\n // const strapiID: () => InstanceType<typeof StrapiIDSchema>;\n\n export interface BaseSchema {\n isFunction(message?: string): this;\n notNil(message?: string): this;\n notNull(message?: string): this;\n }\n\n export interface StringSchema {\n isCamelCase(message?: string): this;\n isKebabCase(message?: string): this;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n export interface ObjectSchema<TShape> {\n onlyContainsFunctions(message?: string): this;\n }\n}\n\ninterface NoTypeOptions {\n path: string;\n type: string;\n value: unknown;\n originalValue: unknown;\n}\n\n// Temporary fix of this issue : https://github.com/jquense/yup/issues/616\nyup.setLocale({\n mixed: {\n notType(options: NoTypeOptions) {\n const { path, type, value, originalValue } = options;\n const isCast = originalValue != null && originalValue !== value;\n const msg =\n `${path} must be a \\`${type}\\` type, ` +\n `but the final value was: \\`${printValue(value, true)}\\`${\n isCast ? ` (cast from the value \\`${printValue(originalValue, true)}\\`).` : '.'\n }`;\n\n /* Remove comment that is not supposed to be seen by the enduser\n if (value === null) {\n msg += `\\n If \"null\" is intended as an empty value be sure to mark the schema as \\`.nullable()\\``;\n }\n */\n return msg;\n },\n },\n});\n"],"names":["strapiID","StrapiIDSchema","isNotNilTest","value","_","isNil","isNotNullTest","isNull","yup","addMethod","mixed","isNotNill","msg","test","isNotNull","isFunction","message","isUndefined","string","isCamelCase","strings","isKebabCase","object","onlyContainsFunctions","Object","values","every","array","uniqueProperty","propertyName","unique","list","errors","forEach","element","index","sameElements","filter","e","get","length","push","createError","path","ValidationError","MixedSchema","_typeCheck","isNumber","isInteger","constructor","type","setLocale","notType","options","originalValue","isCast","printValue"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAUaA,MAAAA,QAAAA,GAAW,IAA2C,IAAIC,cAAiB;AAExF,MAAMC,eAAe,CAACC,KAAAA,GAAmB,CAACC,CAAAA,CAAEC,KAA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}
|
package/dist/yup.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as yup from 'yup';
|
|
2
|
+
export * from 'yup';
|
|
3
|
+
import ___default from 'lodash';
|
|
4
|
+
import { get, isNumber, isInteger } from 'lodash/fp';
|
|
5
|
+
import { isCamelCase, isKebabCase } from './primitives/strings.mjs';
|
|
6
|
+
import { printValue } from './print-value.mjs';
|
|
7
|
+
|
|
8
|
+
const strapiID = ()=>new StrapiIDSchema();
|
|
9
|
+
const isNotNilTest = (value)=>!___default.isNil(value);
|
|
10
|
+
const isNotNullTest = (value)=>!___default.isNull(value);
|
|
11
|
+
yup.addMethod(yup.mixed, 'notNil', function isNotNill(msg = '${path} must be defined.') {
|
|
12
|
+
return this.test('defined', msg, isNotNilTest);
|
|
13
|
+
});
|
|
14
|
+
yup.addMethod(yup.mixed, 'notNull', function isNotNull(msg = '${path} cannot be null.') {
|
|
15
|
+
return this.test('defined', msg, isNotNullTest);
|
|
16
|
+
});
|
|
17
|
+
yup.addMethod(yup.mixed, 'isFunction', function isFunction(message = '${path} is not a function') {
|
|
18
|
+
return this.test('is a function', message, (value)=>___default.isUndefined(value) || ___default.isFunction(value));
|
|
19
|
+
});
|
|
20
|
+
yup.addMethod(yup.string, 'isCamelCase', function isCamelCase$1(message = '${path} is not in camel case (anExampleOfCamelCase)') {
|
|
21
|
+
return this.test('is in camelCase', message, (value)=>value ? isCamelCase(value) : true);
|
|
22
|
+
});
|
|
23
|
+
yup.addMethod(yup.string, 'isKebabCase', function isKebabCase$1(message = '${path} is not in kebab case (an-example-of-kebab-case)') {
|
|
24
|
+
return this.test('is in kebab-case', message, (value)=>value ? isKebabCase(value) : true);
|
|
25
|
+
});
|
|
26
|
+
yup.addMethod(yup.object, 'onlyContainsFunctions', function onlyContainsFunctions(message = '${path} contains values that are not functions') {
|
|
27
|
+
return this.test('only contains functions', message, (value)=>___default.isUndefined(value) || value && Object.values(value).every(___default.isFunction));
|
|
28
|
+
});
|
|
29
|
+
yup.addMethod(yup.array, 'uniqueProperty', function uniqueProperty(propertyName, message) {
|
|
30
|
+
return this.test('unique', message, function unique(list) {
|
|
31
|
+
const errors = [];
|
|
32
|
+
list?.forEach((element, index)=>{
|
|
33
|
+
const sameElements = list.filter((e)=>get(propertyName, e) === get(propertyName, element));
|
|
34
|
+
if (sameElements.length > 1) {
|
|
35
|
+
errors.push(this.createError({
|
|
36
|
+
path: `${this.path}[${index}].${propertyName}`,
|
|
37
|
+
message
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (errors.length) {
|
|
42
|
+
throw new yup.ValidationError(errors);
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
class StrapiIDSchema extends yup.MixedSchema {
|
|
48
|
+
_typeCheck(value) {
|
|
49
|
+
return typeof value === 'string' || isNumber(value) && isInteger(value) && value >= 0;
|
|
50
|
+
}
|
|
51
|
+
constructor(){
|
|
52
|
+
super({
|
|
53
|
+
type: 'strapiID'
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Temporary fix of this issue : https://github.com/jquense/yup/issues/616
|
|
58
|
+
yup.setLocale({
|
|
59
|
+
mixed: {
|
|
60
|
+
notType (options) {
|
|
61
|
+
const { path, type, value, originalValue } = options;
|
|
62
|
+
const isCast = originalValue != null && originalValue !== value;
|
|
63
|
+
const msg = `${path} must be a \`${type}\` type, ` + `but the final value was: \`${printValue(value, true)}\`${isCast ? ` (cast from the value \`${printValue(originalValue, true)}\`).` : '.'}`;
|
|
64
|
+
/* Remove comment that is not supposed to be seen by the enduser
|
|
65
|
+
if (value === null) {
|
|
66
|
+
msg += `\n If "null" is intended as an empty value be sure to mark the schema as \`.nullable()\``;
|
|
67
|
+
}
|
|
68
|
+
*/ return msg;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export { StrapiIDSchema, strapiID };
|
|
74
|
+
//# sourceMappingURL=yup.mjs.map
|
package/dist/yup.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yup.mjs","sources":["../src/yup.ts"],"sourcesContent":["/* eslint-disable no-template-curly-in-string */\n/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport * as yup from 'yup';\nimport _ from 'lodash';\nimport { isNumber, isInteger, get } from 'lodash/fp';\nimport { strings } from './primitives';\nimport { printValue } from './print-value';\n\nexport * from 'yup';\n\nexport const strapiID = (): InstanceType<typeof StrapiIDSchema> => new StrapiIDSchema();\n\nconst isNotNilTest = (value: unknown) => !_.isNil(value);\n\nconst isNotNullTest = (value: unknown) => !_.isNull(value);\n\nyup.addMethod(yup.mixed, 'notNil', function isNotNill(msg = '${path} must be defined.') {\n return this.test('defined', msg, isNotNilTest);\n});\n\nyup.addMethod(yup.mixed, 'notNull', function isNotNull(msg = '${path} cannot be null.') {\n return this.test('defined', msg, isNotNullTest);\n});\n\nyup.addMethod(yup.mixed, 'isFunction', function isFunction(message = '${path} is not a function') {\n return this.test(\n 'is a function',\n message,\n (value) => _.isUndefined(value) || _.isFunction(value)\n );\n});\n\nyup.addMethod(\n yup.string,\n 'isCamelCase',\n function isCamelCase(message = '${path} is not in camel case (anExampleOfCamelCase)') {\n return this.test('is in camelCase', message, (value) =>\n value ? strings.isCamelCase(value) : true\n );\n }\n);\n\nyup.addMethod(\n yup.string,\n 'isKebabCase',\n function isKebabCase(message = '${path} is not in kebab case (an-example-of-kebab-case)') {\n return this.test('is in kebab-case', message, (value) =>\n value ? strings.isKebabCase(value) : true\n );\n }\n);\n\nyup.addMethod(\n yup.object,\n 'onlyContainsFunctions',\n function onlyContainsFunctions(message = '${path} contains values that are not functions') {\n return this.test(\n 'only contains functions',\n message,\n (value) => _.isUndefined(value) || (value && Object.values(value).every(_.isFunction))\n );\n }\n);\n\nyup.addMethod(\n yup.array,\n 'uniqueProperty',\n function uniqueProperty(propertyName: string, message: string) {\n return this.test('unique', message, function unique(list) {\n const errors: yup.ValidationError[] = [];\n\n list?.forEach((element, index) => {\n const sameElements = list.filter(\n (e) => get(propertyName, e) === get(propertyName, element)\n );\n if (sameElements.length > 1) {\n errors.push(\n this.createError({\n path: `${this.path}[${index}].${propertyName}`,\n message,\n })\n );\n }\n });\n\n if (errors.length) {\n throw new yup.ValidationError(errors);\n }\n return true;\n });\n }\n);\n\nexport class StrapiIDSchema extends yup.MixedSchema {\n constructor() {\n super({ type: 'strapiID' });\n }\n\n _typeCheck(value: unknown): value is string | number {\n return typeof value === 'string' || (isNumber(value) && isInteger(value) && value >= 0);\n }\n}\n\ndeclare module 'yup' {\n // const strapiID: () => InstanceType<typeof StrapiIDSchema>;\n\n export interface BaseSchema {\n isFunction(message?: string): this;\n notNil(message?: string): this;\n notNull(message?: string): this;\n }\n\n export interface StringSchema {\n isCamelCase(message?: string): this;\n isKebabCase(message?: string): this;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n export interface ObjectSchema<TShape> {\n onlyContainsFunctions(message?: string): this;\n }\n}\n\ninterface NoTypeOptions {\n path: string;\n type: string;\n value: unknown;\n originalValue: unknown;\n}\n\n// Temporary fix of this issue : https://github.com/jquense/yup/issues/616\nyup.setLocale({\n mixed: {\n notType(options: NoTypeOptions) {\n const { path, type, value, originalValue } = options;\n const isCast = originalValue != null && originalValue !== value;\n const msg =\n `${path} must be a \\`${type}\\` type, ` +\n `but the final value was: \\`${printValue(value, true)}\\`${\n isCast ? ` (cast from the value \\`${printValue(originalValue, true)}\\`).` : '.'\n }`;\n\n /* Remove comment that is not supposed to be seen by the enduser\n if (value === null) {\n msg += `\\n If \"null\" is intended as an empty value be sure to mark the schema as \\`.nullable()\\``;\n }\n */\n return msg;\n },\n },\n});\n"],"names":["strapiID","StrapiIDSchema","isNotNilTest","value","_","isNil","isNotNullTest","isNull","yup","addMethod","mixed","isNotNill","msg","test","isNotNull","isFunction","message","isUndefined","string","isCamelCase","strings","isKebabCase","object","onlyContainsFunctions","Object","values","every","array","uniqueProperty","propertyName","unique","list","errors","forEach","element","index","sameElements","filter","e","get","length","push","createError","path","ValidationError","MixedSchema","_typeCheck","isNumber","isInteger","constructor","type","setLocale","notType","options","originalValue","isCast","printValue"],"mappings":";;;;;;;AAUaA,MAAAA,QAAAA,GAAW,IAA2C,IAAIC,cAAiB;AAExF,MAAMC,eAAe,CAACC,KAAAA,GAAmB,CAACC,UAAAA,CAAEC,KAAK,CAACF,KAAAA,CAAAA;AAElD,MAAMG,gBAAgB,CAACH,KAAAA,GAAmB,CAACC,UAAAA,CAAEG,MAAM,CAACJ,KAAAA,CAAAA;AAEpDK,GAAIC,CAAAA,SAAS,CAACD,GAAIE,CAAAA,KAAK,EAAE,QAAU,EAAA,SAASC,SAAUC,CAAAA,GAAAA,GAAM,0BAA0B,EAAA;AACpF,IAAA,OAAO,IAAI,CAACC,IAAI,CAAC,WAAWD,GAAKV,EAAAA,YAAAA,CAAAA;AACnC,CAAA,CAAA;AAEAM,GAAIC,CAAAA,SAAS,CAACD,GAAIE,CAAAA,KAAK,EAAE,SAAW,EAAA,SAASI,SAAUF,CAAAA,GAAAA,GAAM,yBAAyB,EAAA;AACpF,IAAA,OAAO,IAAI,CAACC,IAAI,CAAC,WAAWD,GAAKN,EAAAA,aAAAA,CAAAA;AACnC,CAAA,CAAA;AAEAE,GAAIC,CAAAA,SAAS,CAACD,GAAIE,CAAAA,KAAK,EAAE,YAAc,EAAA,SAASK,UAAWC,CAAAA,OAAAA,GAAU,2BAA2B,EAAA;AAC9F,IAAA,OAAO,IAAI,CAACH,IAAI,CACd,iBACAG,OACA,EAAA,CAACb,KAAUC,GAAAA,UAAAA,CAAEa,WAAW,CAACd,KAAUC,CAAAA,IAAAA,UAAAA,CAAEW,UAAU,CAACZ,KAAAA,CAAAA,CAAAA;AAEpD,CAAA,CAAA;AAEAK,GAAIC,CAAAA,SAAS,CACXD,GAAIU,CAAAA,MAAM,EACV,aACA,EAAA,SAASC,aAAYH,C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C,GACtC,CAAC,2BAA2B,EAAEM,UAAAA,CAAWrD,KAAO,EAAA,IAAA,CAAA,CAAM,EAAE,EACtDoD,MAAS,GAAA,CAAC,wBAAwB,EAAEC,UAAWF,CAAAA,aAAAA,EAAe,IAAM,CAAA,CAAA,IAAI,CAAC,GAAG,IAC7E,CAAC;AAEJ;;;;AAIA,SACA,OAAO1C,GAAAA;AACT;AACF;AACF,CAAA,CAAA;;;;"}
|
package/dist/zod.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
var errors = require('./errors.js');
|
|
5
|
+
|
|
6
|
+
const validateZod = (schema)=>(data)=>{
|
|
7
|
+
try {
|
|
8
|
+
return schema.parse(data);
|
|
9
|
+
} catch (error) {
|
|
10
|
+
if (error instanceof zod.z.ZodError) {
|
|
11
|
+
const { message, errors: errors$1 } = formatZodErrors(error);
|
|
12
|
+
throw new errors.ValidationError(message, {
|
|
13
|
+
errors: errors$1
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const formatZodErrors = (zodError)=>({
|
|
20
|
+
errors: zodError.errors.map((error)=>{
|
|
21
|
+
return {
|
|
22
|
+
path: error.path,
|
|
23
|
+
message: error.message,
|
|
24
|
+
name: 'ValidationError'
|
|
25
|
+
};
|
|
26
|
+
}),
|
|
27
|
+
message: 'Validation error'
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
exports.validateZod = validateZod;
|
|
31
|
+
//# sourceMappingURL=zod.js.map
|
package/dist/zod.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod.js","sources":["../src/zod.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { ValidationError } from './errors';\n\nexport const validateZod =\n <T extends z.ZodTypeAny>(schema: T) =>\n (data: unknown): z.TypeOf<T> => {\n try {\n return schema.parse(data);\n } catch (error) {\n if (error instanceof z.ZodError) {\n const { message, errors } = formatZodErrors(error);\n throw new ValidationError(message, { errors });\n }\n\n throw error;\n }\n };\n\nconst formatZodErrors = (zodError: z.ZodError) => ({\n errors: zodError.errors.map((error) => {\n return {\n path: error.path,\n message: error.message,\n name: 'ValidationError',\n };\n }),\n message: 'Validation error',\n});\n"],"names":["validateZod","schema","data","parse","error","z","ZodError","message","errors","formatZodErrors","ValidationError","zodError","map","path","name"],"mappings":";;;;;AAIaA,MAAAA,WAAAA,GACX,CAAyBC,MAAAA,GACzB,CAACC,IAAAA,GAAAA;QACC,IAAI;YACF,OAAOD,MAAAA,CAAOE,KAAK,CAACD,IAAAA,CAAAA;AACtB,SAAA,CAAE,OAAOE,KAAO,EAAA;YACd,IAAIA,KAAAA,YAAiBC,KAAEC,CAAAA,QAAQ,EAAE;AAC/B,gBAAA,MAAM,EAAEC,OAAO,UAAEC,QAAM,EAAE,GAAGC,eAAgBL,CAAAA,KAAAA,CAAAA;gBAC5C,MAAM,IAAIM,uBAAgBH,OAAS,EAAA;AAAEC,4BAAAA;AAAO,iBAAA,CAAA;AAC9C;YAEA,MAAMJ,KAAAA;AACR;;AAGJ,MAAMK,eAAAA,GAAkB,CAACE,QAAAA,IAA0B;AACjDH,QAAAA,MAAAA,EAAQG,QAASH,CAAAA,MAAM,CAACI,GAAG,CAAC,CAACR,KAAAA,GAAAA;YAC3B,OAAO;AACLS,gBAAAA,IAAAA,EAAMT,MAAMS,IAAI;AAChBN,gBAAAA,OAAAA,EAASH,MAAMG,OAAO;gBACtBO,IAAM,EAAA;AACR,aAAA;AACF,SAAA,CAAA;QACAP,OAAS,EAAA;KACX,CAAA;;;;"}
|
package/dist/zod.mjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ValidationError } from './errors.mjs';
|
|
3
|
+
|
|
4
|
+
const validateZod = (schema)=>(data)=>{
|
|
5
|
+
try {
|
|
6
|
+
return schema.parse(data);
|
|
7
|
+
} catch (error) {
|
|
8
|
+
if (error instanceof z.ZodError) {
|
|
9
|
+
const { message, errors } = formatZodErrors(error);
|
|
10
|
+
throw new ValidationError(message, {
|
|
11
|
+
errors
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const formatZodErrors = (zodError)=>({
|
|
18
|
+
errors: zodError.errors.map((error)=>{
|
|
19
|
+
return {
|
|
20
|
+
path: error.path,
|
|
21
|
+
message: error.message,
|
|
22
|
+
name: 'ValidationError'
|
|
23
|
+
};
|
|
24
|
+
}),
|
|
25
|
+
message: 'Validation error'
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export { validateZod };
|
|
29
|
+
//# sourceMappingURL=zod.mjs.map
|
package/dist/zod.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zod.mjs","sources":["../src/zod.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { ValidationError } from './errors';\n\nexport const validateZod =\n <T extends z.ZodTypeAny>(schema: T) =>\n (data: unknown): z.TypeOf<T> => {\n try {\n return schema.parse(data);\n } catch (error) {\n if (error instanceof z.ZodError) {\n const { message, errors } = formatZodErrors(error);\n throw new ValidationError(message, { errors });\n }\n\n throw error;\n }\n };\n\nconst formatZodErrors = (zodError: z.ZodError) => ({\n errors: zodError.errors.map((error) => {\n return {\n path: error.path,\n message: error.message,\n name: 'ValidationError',\n };\n }),\n message: 'Validation error',\n});\n"],"names":["validateZod","schema","data","parse","error","z","ZodError","message","errors","formatZodErrors","ValidationError","zodError","map","path","name"],"mappings":";;;AAIaA,MAAAA,WAAAA,GACX,CAAyBC,MAAAA,GACzB,CAACC,IAAAA,GAAAA;QACC,IAAI;YACF,OAAOD,MAAAA,CAAOE,KAAK,CAACD,IAAAA,CAAAA;AACtB,SAAA,CAAE,OAAOE,KAAO,EAAA;YACd,IAAIA,KAAAA,YAAiBC,CAAEC,CAAAA,QAAQ,EAAE;AAC/B,gBAAA,MAAM,EAAEC,OAAO,EAAEC,MAAM,EAAE,GAAGC,eAAgBL,CAAAA,KAAAA,CAAAA;gBAC5C,MAAM,IAAIM,gBAAgBH,OAAS,EAAA;AAAEC,oBAAAA;AAAO,iBAAA,CAAA;AAC9C;YAEA,MAAMJ,KAAAA;AACR;;AAGJ,MAAMK,eAAAA,GAAkB,CAACE,QAAAA,IAA0B;AACjDH,QAAAA,MAAAA,EAAQG,QAASH,CAAAA,MAAM,CAACI,GAAG,CAAC,CAACR,KAAAA,GAAAA;YAC3B,OAAO;AACLS,gBAAAA,IAAAA,EAAMT,MAAMS,IAAI;AAChBN,gBAAAA,OAAAA,EAASH,MAAMG,OAAO;gBACtBO,IAAM,EAAA;AACR,aAAA;AACF,SAAA,CAAA;QACAP,OAAS,EAAA;KACX,CAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/utils",
|
|
3
|
-
"version": "5.12.
|
|
3
|
+
"version": "5.12.2",
|
|
4
4
|
"description": "Shared utilities for the Strapi packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -61,10 +61,10 @@
|
|
|
61
61
|
"@types/http-errors": "2.0.4",
|
|
62
62
|
"@types/koa": "2.13.4",
|
|
63
63
|
"@types/node": "18.19.24",
|
|
64
|
-
"eslint-config-custom": "5.12.
|
|
64
|
+
"eslint-config-custom": "5.12.2",
|
|
65
65
|
"koa": "2.15.4",
|
|
66
66
|
"koa-body": "6.0.1",
|
|
67
|
-
"tsconfig": "5.12.
|
|
67
|
+
"tsconfig": "5.12.2"
|
|
68
68
|
},
|
|
69
69
|
"engines": {
|
|
70
70
|
"node": ">=18.0.0 <=22.x.x",
|