@strapi/utils 4.11.3 → 4.12.0-beta.0
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.d.ts +10 -0
- package/dist/async.js +33 -0
- package/dist/async.js.map +1 -0
- package/dist/code-generator.d.ts +2 -0
- package/dist/code-generator.js +11 -0
- package/dist/code-generator.js.map +1 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.js +79 -0
- package/dist/config.js.map +1 -0
- package/dist/content-types.d.ts +60 -0
- package/dist/content-types.js +151 -0
- package/dist/content-types.js.map +1 -0
- package/dist/convert-query-params.d.ts +75 -0
- package/dist/convert-query-params.js +476 -0
- package/dist/convert-query-params.js.map +1 -0
- package/dist/env-helper.d.ts +18 -0
- package/dist/env-helper.js +84 -0
- package/dist/env-helper.js.map +1 -0
- package/dist/errors.d.ts +37 -0
- package/dist/errors.js +100 -0
- package/dist/errors.js.map +1 -0
- package/dist/file.d.ts +16 -0
- package/dist/file.js +54 -0
- package/dist/file.js.map +1 -0
- package/dist/format-yup-error.d.ts +10 -0
- package/dist/format-yup-error.js +17 -0
- package/dist/format-yup-error.js.map +1 -0
- package/dist/hooks.d.ts +63 -0
- package/dist/hooks.js +89 -0
- package/dist/hooks.js.map +1 -0
- package/dist/import-default.d.ts +1 -0
- package/dist/import-default.js +9 -0
- package/dist/import-default.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +99 -0
- package/dist/index.js.map +1 -0
- package/dist/object-formatting.d.ts +3 -0
- package/dist/object-formatting.js +14 -0
- package/dist/object-formatting.js.map +1 -0
- package/dist/operators.d.ts +2 -0
- package/dist/operators.js +70 -0
- package/dist/operators.js.map +1 -0
- package/dist/pagination.d.ts +14 -0
- package/dist/pagination.js +80 -0
- package/dist/pagination.js.map +1 -0
- package/dist/parse-multipart.d.ts +8 -0
- package/dist/parse-multipart.js +36 -0
- package/dist/parse-multipart.js.map +1 -0
- package/dist/parse-type.d.ts +21 -0
- package/dist/parse-type.js +108 -0
- package/dist/parse-type.js.map +1 -0
- package/dist/policy.d.ts +41 -0
- package/dist/policy.js +109 -0
- package/dist/policy.js.map +1 -0
- package/dist/print-value.d.ts +2 -0
- package/dist/print-value.js +50 -0
- package/dist/print-value.js.map +1 -0
- package/dist/provider-factory.d.ts +29 -0
- package/dist/provider-factory.js +80 -0
- package/dist/provider-factory.js.map +1 -0
- package/dist/relations.d.ts +10 -0
- package/dist/relations.js +23 -0
- package/dist/relations.js.map +1 -0
- package/dist/sanitize/index.d.ts +23 -0
- package/dist/sanitize/index.js +135 -0
- package/dist/sanitize/index.js.map +1 -0
- package/dist/sanitize/sanitizers.d.ts +10 -0
- package/dist/sanitize/sanitizers.js +114 -0
- package/dist/sanitize/sanitizers.js.map +1 -0
- package/dist/sanitize/visitors/allowed-fields.d.ts +3 -0
- package/{lib → dist}/sanitize/visitors/allowed-fields.js +17 -32
- package/dist/sanitize/visitors/allowed-fields.js.map +1 -0
- package/dist/sanitize/visitors/index.d.ts +7 -0
- package/dist/sanitize/visitors/index.js +21 -0
- package/dist/sanitize/visitors/index.js.map +1 -0
- package/dist/sanitize/visitors/remove-dynamic-zones.d.ts +3 -0
- package/dist/sanitize/visitors/remove-dynamic-zones.js +10 -0
- package/dist/sanitize/visitors/remove-dynamic-zones.js.map +1 -0
- package/dist/sanitize/visitors/remove-morph-to-relations.d.ts +3 -0
- package/dist/sanitize/visitors/remove-morph-to-relations.js +10 -0
- package/dist/sanitize/visitors/remove-morph-to-relations.js.map +1 -0
- package/dist/sanitize/visitors/remove-password.d.ts +3 -0
- package/dist/sanitize/visitors/remove-password.js +9 -0
- package/dist/sanitize/visitors/remove-password.js.map +1 -0
- package/dist/sanitize/visitors/remove-private.d.ts +3 -0
- package/dist/sanitize/visitors/remove-private.js +14 -0
- package/dist/sanitize/visitors/remove-private.js.map +1 -0
- package/dist/sanitize/visitors/remove-restricted-relations.d.ts +3 -0
- package/dist/sanitize/visitors/remove-restricted-relations.js +88 -0
- package/dist/sanitize/visitors/remove-restricted-relations.js.map +1 -0
- package/dist/sanitize/visitors/restricted-fields.d.ts +3 -0
- package/dist/sanitize/visitors/restricted-fields.js +25 -0
- package/dist/sanitize/visitors/restricted-fields.js.map +1 -0
- package/dist/set-creator-fields.d.ts +9 -0
- package/dist/set-creator-fields.js +39 -0
- package/dist/set-creator-fields.js.map +1 -0
- package/dist/string-formatting.d.ts +15 -0
- package/dist/string-formatting.js +85 -0
- package/dist/string-formatting.js.map +1 -0
- package/dist/template-configuration.d.ts +5 -0
- package/dist/template-configuration.js +30 -0
- package/dist/template-configuration.js.map +1 -0
- package/dist/template.d.ts +9 -0
- package/dist/template.js +20 -0
- package/dist/template.js.map +1 -0
- package/dist/traverse/factory.d.ts +78 -0
- package/dist/traverse/factory.js +127 -0
- package/dist/traverse/factory.js.map +1 -0
- package/dist/traverse/index.d.ts +5 -0
- package/dist/traverse/index.js +17 -0
- package/dist/traverse/index.js.map +1 -0
- package/dist/traverse/query-fields.d.ts +3 -0
- package/dist/traverse/query-fields.js +35 -0
- package/dist/traverse/query-fields.js.map +1 -0
- package/dist/traverse/query-filters.d.ts +3 -0
- package/dist/traverse/query-filters.js +75 -0
- package/dist/traverse/query-filters.js.map +1 -0
- package/dist/traverse/query-populate.d.ts +3 -0
- package/dist/traverse/query-populate.js +144 -0
- package/dist/traverse/query-populate.js.map +1 -0
- package/dist/traverse/query-sort.d.ts +3 -0
- package/dist/traverse/query-sort.js +116 -0
- package/dist/traverse/query-sort.js.map +1 -0
- package/dist/traverse-entity.d.ts +31 -0
- package/dist/traverse-entity.js +134 -0
- package/dist/traverse-entity.js.map +1 -0
- package/dist/types.d.ts +65 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/validators.d.ts +13 -0
- package/dist/validators.js +120 -0
- package/dist/validators.js.map +1 -0
- package/dist/webhook.d.ts +5 -0
- package/dist/webhook.js +27 -0
- package/dist/webhook.js.map +1 -0
- package/package.json +19 -4
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -4
- package/index.d.ts +0 -5
- package/lib/async.d.ts +0 -21
- package/lib/async.js +0 -45
- package/lib/build-query.js +0 -208
- package/lib/code-generator.js +0 -13
- package/lib/config.js +0 -88
- package/lib/content-types.js +0 -196
- package/lib/convert-query-params.js +0 -586
- package/lib/env-helper.js +0 -98
- package/lib/errors.js +0 -113
- package/lib/file.js +0 -60
- package/lib/format-yup-error.js +0 -20
- package/lib/hooks.js +0 -110
- package/lib/import-default.js +0 -10
- package/lib/index.js +0 -99
- package/lib/object-formatting.js +0 -15
- package/lib/operators.js +0 -74
- package/lib/pagination.js +0 -99
- package/lib/parse-multipart.js +0 -44
- package/lib/parse-type.js +0 -100
- package/lib/policy.js +0 -129
- package/lib/print-value.js +0 -52
- package/lib/provider-factory.js +0 -116
- package/lib/relations.js +0 -31
- package/lib/sanitize/index.js +0 -143
- package/lib/sanitize/sanitizers.js +0 -163
- package/lib/sanitize/visitors/index.js +0 -11
- package/lib/sanitize/visitors/remove-dynamic-zones.js +0 -9
- package/lib/sanitize/visitors/remove-morph-to-relations.js +0 -9
- package/lib/sanitize/visitors/remove-password.js +0 -7
- package/lib/sanitize/visitors/remove-private.js +0 -15
- package/lib/sanitize/visitors/remove-restricted-relations.js +0 -81
- package/lib/sanitize/visitors/restricted-fields.js +0 -32
- package/lib/set-creator-fields.js +0 -17
- package/lib/string-formatting.js +0 -79
- package/lib/template-configuration.js +0 -32
- package/lib/template.js +0 -28
- package/lib/traverse/factory.js +0 -157
- package/lib/traverse/index.js +0 -16
- package/lib/traverse/query-fields.js +0 -39
- package/lib/traverse/query-filters.js +0 -97
- package/lib/traverse/query-populate.js +0 -191
- package/lib/traverse/query-sort.js +0 -171
- package/lib/traverse-entity.js +0 -166
- package/lib/validators.js +0 -120
- package/lib/webhook.js +0 -30
package/lib/validators.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const yup = require('yup');
|
|
4
|
-
const _ = require('lodash');
|
|
5
|
-
const { defaults } = require('lodash/fp');
|
|
6
|
-
const utils = require('./string-formatting');
|
|
7
|
-
const { YupValidationError } = require('./errors');
|
|
8
|
-
const printValue = require('./print-value');
|
|
9
|
-
|
|
10
|
-
const MixedSchemaType = yup.MixedSchema;
|
|
11
|
-
|
|
12
|
-
const isNotNilTest = (value) => !_.isNil(value);
|
|
13
|
-
|
|
14
|
-
function isNotNill(msg = '${path} must be defined.') {
|
|
15
|
-
return this.test('defined', msg, isNotNilTest);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const isNotNullTest = (value) => !_.isNull(value);
|
|
19
|
-
function isNotNull(msg = '${path} cannot be null.') {
|
|
20
|
-
return this.test('defined', msg, isNotNullTest);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function isFunction(message = '${path} is not a function') {
|
|
24
|
-
return this.test(
|
|
25
|
-
'is a function',
|
|
26
|
-
message,
|
|
27
|
-
(value) => _.isUndefined(value) || _.isFunction(value)
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function isCamelCase(message = '${path} is not in camel case (anExampleOfCamelCase)') {
|
|
32
|
-
return this.test('is in camelCase', message, (value) => utils.isCamelCase(value));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function isKebabCase(message = '${path} is not in kebab case (an-example-of-kebab-case)') {
|
|
36
|
-
return this.test('is in kebab-case', message, (value) => utils.isKebabCase(value));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function onlyContainsFunctions(message = '${path} contains values that are not functions') {
|
|
40
|
-
return this.test(
|
|
41
|
-
'only contains functions',
|
|
42
|
-
message,
|
|
43
|
-
(value) => _.isUndefined(value) || (value && Object.values(value).every(_.isFunction))
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
yup.addMethod(yup.mixed, 'notNil', isNotNill);
|
|
48
|
-
yup.addMethod(yup.mixed, 'notNull', isNotNull);
|
|
49
|
-
yup.addMethod(yup.mixed, 'isFunction', isFunction);
|
|
50
|
-
yup.addMethod(yup.string, 'isCamelCase', isCamelCase);
|
|
51
|
-
yup.addMethod(yup.string, 'isKebabCase', isKebabCase);
|
|
52
|
-
yup.addMethod(yup.object, 'onlyContainsFunctions', onlyContainsFunctions);
|
|
53
|
-
|
|
54
|
-
class StrapiIDSchema extends MixedSchemaType {
|
|
55
|
-
constructor() {
|
|
56
|
-
super({ type: 'strapiID' });
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
_typeCheck(value) {
|
|
60
|
-
return typeof value === 'string' || (Number.isInteger(value) && value >= 0);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
yup.strapiID = () => new StrapiIDSchema();
|
|
65
|
-
|
|
66
|
-
const handleYupError = (error, errorMessage) => {
|
|
67
|
-
throw new YupValidationError(error, errorMessage);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const defaultValidationParam = { strict: true, abortEarly: false };
|
|
71
|
-
|
|
72
|
-
const validateYupSchema =
|
|
73
|
-
(schema, options = {}) =>
|
|
74
|
-
async (body, errorMessage) => {
|
|
75
|
-
try {
|
|
76
|
-
const optionsWithDefaults = defaults(defaultValidationParam, options);
|
|
77
|
-
return await schema.validate(body, optionsWithDefaults);
|
|
78
|
-
} catch (e) {
|
|
79
|
-
handleYupError(e, errorMessage);
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const validateYupSchemaSync =
|
|
84
|
-
(schema, options = {}) =>
|
|
85
|
-
(body, errorMessage) => {
|
|
86
|
-
try {
|
|
87
|
-
const optionsWithDefaults = defaults(defaultValidationParam, options);
|
|
88
|
-
return schema.validateSync(body, optionsWithDefaults);
|
|
89
|
-
} catch (e) {
|
|
90
|
-
handleYupError(e, errorMessage);
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
// Temporary fix of this issue : https://github.com/jquense/yup/issues/616
|
|
95
|
-
yup.setLocale({
|
|
96
|
-
mixed: {
|
|
97
|
-
notType({ path, type, value, originalValue }) {
|
|
98
|
-
const isCast = originalValue != null && originalValue !== value;
|
|
99
|
-
const msg =
|
|
100
|
-
`${path} must be a \`${type}\` type, ` +
|
|
101
|
-
`but the final value was: \`${printValue(value, true)}\`${
|
|
102
|
-
isCast ? ` (cast from the value \`${printValue(originalValue, true)}\`).` : '.'
|
|
103
|
-
}`;
|
|
104
|
-
|
|
105
|
-
/* Remove comment that is not supposed to be seen by the enduser
|
|
106
|
-
if (value === null) {
|
|
107
|
-
msg += `\n If "null" is intended as an empty value be sure to mark the schema as \`.nullable()\``;
|
|
108
|
-
}
|
|
109
|
-
*/
|
|
110
|
-
return msg;
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
module.exports = {
|
|
116
|
-
yup,
|
|
117
|
-
handleYupError,
|
|
118
|
-
validateYupSchema,
|
|
119
|
-
validateYupSchemaSync,
|
|
120
|
-
};
|
package/lib/webhook.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const webhookEvents = {
|
|
4
|
-
ENTRY_CREATE: 'entry.create',
|
|
5
|
-
ENTRY_UPDATE: 'entry.update',
|
|
6
|
-
ENTRY_DELETE: 'entry.delete',
|
|
7
|
-
ENTRY_PUBLISH: 'entry.publish',
|
|
8
|
-
ENTRY_UNPUBLISH: 'entry.unpublish',
|
|
9
|
-
MEDIA_CREATE: 'media.create',
|
|
10
|
-
MEDIA_UPDATE: 'media.update',
|
|
11
|
-
MEDIA_DELETE: 'media.delete',
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* TODO V5: remove this file
|
|
16
|
-
* @deprecated
|
|
17
|
-
*/
|
|
18
|
-
const deprecatedWebhookEvents = new Proxy(webhookEvents, {
|
|
19
|
-
get(target, prop) {
|
|
20
|
-
console.warn(
|
|
21
|
-
'[deprecated] @strapi/utils/webhook will no longer exist in the next major release of Strapi. ' +
|
|
22
|
-
'Instead, the webhookEvents object can be retrieved from strapi.webhookStore.allowedEvents'
|
|
23
|
-
);
|
|
24
|
-
return target[prop];
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
module.exports = {
|
|
29
|
-
webhookEvents: deprecatedWebhookEvents,
|
|
30
|
-
};
|