@strapi/utils 4.2.0-beta.1 → 4.2.0-beta.4
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/lib/hooks.js +6 -4
- package/lib/index.js +2 -0
- package/lib/sanitize/index.js +10 -0
- package/lib/string-formatting.js +4 -0
- package/lib/validators.js +1 -1
- package/package.json +3 -3
package/lib/hooks.js
CHANGED
|
@@ -20,17 +20,19 @@ const createHook = () => {
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
return {
|
|
23
|
-
|
|
23
|
+
getHandlers() {
|
|
24
24
|
return state.handlers;
|
|
25
25
|
},
|
|
26
26
|
|
|
27
27
|
register(handler) {
|
|
28
28
|
state.handlers.push(handler);
|
|
29
|
+
|
|
29
30
|
return this;
|
|
30
31
|
},
|
|
31
32
|
|
|
32
33
|
delete(handler) {
|
|
33
34
|
state.handlers = remove(eq(handler), state.handlers);
|
|
35
|
+
|
|
34
36
|
return this;
|
|
35
37
|
},
|
|
36
38
|
|
|
@@ -49,7 +51,7 @@ const createAsyncSeriesHook = () => ({
|
|
|
49
51
|
...createHook(),
|
|
50
52
|
|
|
51
53
|
async call(context) {
|
|
52
|
-
for (const handler of this.
|
|
54
|
+
for (const handler of this.getHandlers()) {
|
|
53
55
|
await handler(context);
|
|
54
56
|
}
|
|
55
57
|
},
|
|
@@ -66,7 +68,7 @@ const createAsyncSeriesWaterfallHook = () => ({
|
|
|
66
68
|
async call(param) {
|
|
67
69
|
let res = param;
|
|
68
70
|
|
|
69
|
-
for (const handler of this.
|
|
71
|
+
for (const handler of this.getHandlers()) {
|
|
70
72
|
res = await handler(res);
|
|
71
73
|
}
|
|
72
74
|
|
|
@@ -83,7 +85,7 @@ const createAsyncParallelHook = () => ({
|
|
|
83
85
|
...createHook(),
|
|
84
86
|
|
|
85
87
|
async call(context) {
|
|
86
|
-
const promises = this.
|
|
88
|
+
const promises = this.getHandlers().map(handler => handler(cloneDeep(context)));
|
|
87
89
|
|
|
88
90
|
return Promise.all(promises);
|
|
89
91
|
},
|
package/lib/index.js
CHANGED
|
@@ -22,6 +22,7 @@ const {
|
|
|
22
22
|
toRegressedEnumValue,
|
|
23
23
|
startsWithANumber,
|
|
24
24
|
joinBy,
|
|
25
|
+
toKebabCase,
|
|
25
26
|
} = require('./string-formatting');
|
|
26
27
|
const { removeUndefined } = require('./object-formatting');
|
|
27
28
|
const { getConfigUrls, getAbsoluteAdminUrl, getAbsoluteServerUrl } = require('./config');
|
|
@@ -65,6 +66,7 @@ module.exports = {
|
|
|
65
66
|
stringEquals,
|
|
66
67
|
isKebabCase,
|
|
67
68
|
isCamelCase,
|
|
69
|
+
toKebabCase,
|
|
68
70
|
contentTypes,
|
|
69
71
|
webhook,
|
|
70
72
|
env,
|
package/lib/sanitize/index.js
CHANGED
|
@@ -28,6 +28,11 @@ module.exports = {
|
|
|
28
28
|
transforms.push(traverseEntity(visitors.removeRestrictedRelations(auth), { schema }));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
// Apply sanitizers from registry if exists
|
|
32
|
+
strapi.sanitizers
|
|
33
|
+
.get('content-api.input')
|
|
34
|
+
.forEach(sanitizer => transforms.push(sanitizer(schema)));
|
|
35
|
+
|
|
31
36
|
return pipeAsync(...transforms)(data);
|
|
32
37
|
},
|
|
33
38
|
|
|
@@ -42,6 +47,11 @@ module.exports = {
|
|
|
42
47
|
transforms.push(traverseEntity(visitors.removeRestrictedRelations(auth), { schema }));
|
|
43
48
|
}
|
|
44
49
|
|
|
50
|
+
// Apply sanitizers from registry if exists
|
|
51
|
+
strapi.sanitizers
|
|
52
|
+
.get('content-api.output')
|
|
53
|
+
.forEach(sanitizer => transforms.push(sanitizer(schema)));
|
|
54
|
+
|
|
45
55
|
return pipeAsync(...transforms)(data);
|
|
46
56
|
},
|
|
47
57
|
},
|
package/lib/string-formatting.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const _ = require('lodash');
|
|
3
3
|
const { trimChars, trimCharsEnd, trimCharsStart } = require('lodash/fp');
|
|
4
4
|
const slugify = require('@sindresorhus/slugify');
|
|
5
|
+
const { kebabCase } = require('lodash');
|
|
5
6
|
|
|
6
7
|
const nameToSlug = (name, options = { separator: '-' }) => slugify(name, options);
|
|
7
8
|
|
|
@@ -58,6 +59,8 @@ const joinBy = (joint, ...args) => {
|
|
|
58
59
|
}, '');
|
|
59
60
|
};
|
|
60
61
|
|
|
62
|
+
const toKebabCase = value => kebabCase(value);
|
|
63
|
+
|
|
61
64
|
module.exports = {
|
|
62
65
|
nameToSlug,
|
|
63
66
|
nameToCollectionName,
|
|
@@ -68,6 +71,7 @@ module.exports = {
|
|
|
68
71
|
stringEquals,
|
|
69
72
|
isCamelCase,
|
|
70
73
|
isKebabCase,
|
|
74
|
+
toKebabCase,
|
|
71
75
|
toRegressedEnumValue,
|
|
72
76
|
startsWithANumber,
|
|
73
77
|
joinBy,
|
package/lib/validators.js
CHANGED
|
@@ -7,7 +7,7 @@ const utils = require('./string-formatting');
|
|
|
7
7
|
const { YupValidationError } = require('./errors');
|
|
8
8
|
const printValue = require('./print-value');
|
|
9
9
|
|
|
10
|
-
const MixedSchemaType = yup.
|
|
10
|
+
const MixedSchemaType = yup.MixedSchema;
|
|
11
11
|
|
|
12
12
|
const isNotNilTest = value => !_.isNil(value);
|
|
13
13
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/utils",
|
|
3
|
-
"version": "4.2.0-beta.
|
|
3
|
+
"version": "4.2.0-beta.4",
|
|
4
4
|
"description": "Shared utilities for the Strapi packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"yup": "0.32.9"
|
|
43
43
|
},
|
|
44
44
|
"engines": {
|
|
45
|
-
"node": ">=
|
|
45
|
+
"node": ">=14.19.1 <=16.x.x",
|
|
46
46
|
"npm": ">=6.0.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "5caff35a30e33b7a660eb946299f9e3d2d35b2b8"
|
|
49
49
|
}
|