@strapi/utils 4.4.0-beta.1 → 4.4.0-beta.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/lib/hooks.js +12 -19
- package/lib/provider-factory.js +17 -1
- package/package.json +2 -2
package/lib/hooks.js
CHANGED
|
@@ -2,8 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
const { eq, remove, cloneDeep } = require('lodash/fp');
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @typedef Hook
|
|
7
|
+
* @property {Array<Function>} _handlers - A registry of handler used by the hook
|
|
8
|
+
* @property {function(Function):Hook} register - Register a new handler into the hook's registry
|
|
9
|
+
* @property {function(Function):Hook} delete- Delete the given handler from the hook's registry
|
|
10
|
+
* @property {Function} call - Not implemented by default, can be replaced by any implementation.
|
|
11
|
+
*/
|
|
12
|
+
|
|
5
13
|
/**
|
|
6
14
|
* Create a default Strapi hook
|
|
15
|
+
* @return {Hook}
|
|
7
16
|
*/
|
|
8
17
|
const createHook = () => {
|
|
9
18
|
const state = {
|
|
@@ -36,6 +45,7 @@ const createHook = () => {
|
|
|
36
45
|
/**
|
|
37
46
|
* Create an async series hook.
|
|
38
47
|
* Upon execution, it will execute every handler in order with the same context
|
|
48
|
+
* @return {Hook}
|
|
39
49
|
*/
|
|
40
50
|
const createAsyncSeriesHook = () => ({
|
|
41
51
|
...createHook(),
|
|
@@ -50,6 +60,7 @@ const createAsyncSeriesHook = () => ({
|
|
|
50
60
|
/**
|
|
51
61
|
* Create an async series waterfall hook.
|
|
52
62
|
* Upon execution, it will execute every handler in order and pass the return value of the last handler to the next one
|
|
63
|
+
* @return {Hook}
|
|
53
64
|
*/
|
|
54
65
|
const createAsyncSeriesWaterfallHook = () => ({
|
|
55
66
|
...createHook(),
|
|
@@ -68,6 +79,7 @@ const createAsyncSeriesWaterfallHook = () => ({
|
|
|
68
79
|
/**
|
|
69
80
|
* Create an async parallel hook.
|
|
70
81
|
* Upon execution, it will execute every registered handler in band.
|
|
82
|
+
* @return {Hook}
|
|
71
83
|
*/
|
|
72
84
|
const createAsyncParallelHook = () => ({
|
|
73
85
|
...createHook(),
|
|
@@ -79,24 +91,6 @@ const createAsyncParallelHook = () => ({
|
|
|
79
91
|
},
|
|
80
92
|
});
|
|
81
93
|
|
|
82
|
-
/**
|
|
83
|
-
* Create an async parallel hook.
|
|
84
|
-
* Upon execution, it will execute every registered handler in serie and return the first result found.
|
|
85
|
-
*/
|
|
86
|
-
const createAsyncBailHook = () => ({
|
|
87
|
-
...createHook(),
|
|
88
|
-
|
|
89
|
-
async call(context) {
|
|
90
|
-
for (const handler of this.getHandlers()) {
|
|
91
|
-
const result = await handler(context);
|
|
92
|
-
|
|
93
|
-
if (result !== undefined) {
|
|
94
|
-
return result;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
|
|
100
94
|
module.exports = {
|
|
101
95
|
// Internal utils
|
|
102
96
|
internals: {
|
|
@@ -106,5 +100,4 @@ module.exports = {
|
|
|
106
100
|
createAsyncSeriesHook,
|
|
107
101
|
createAsyncSeriesWaterfallHook,
|
|
108
102
|
createAsyncParallelHook,
|
|
109
|
-
createAsyncBailHook,
|
|
110
103
|
};
|
package/lib/provider-factory.js
CHANGED
|
@@ -25,9 +25,25 @@ const createProviderHooksMap = () => ({
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* A
|
|
28
|
+
* A customizable item provider enhanced with register/delete hooks
|
|
29
|
+
* @typedef {Object} Provider
|
|
30
|
+
* @property hooks
|
|
31
|
+
* @property register
|
|
32
|
+
* @property delete
|
|
33
|
+
* @property get
|
|
34
|
+
* @property getWhere
|
|
35
|
+
* @property values
|
|
36
|
+
* @property keys
|
|
37
|
+
* @property has
|
|
38
|
+
* @property size
|
|
39
|
+
* @property clear
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A {@link Provider} factory
|
|
29
44
|
* @param {Object} [options] - The factory options
|
|
30
45
|
* @param {boolean = true} options.throwOnDuplicates - Specify the wanted behaviour when encountering a duplicate key on register
|
|
46
|
+
* @return {Provider}
|
|
31
47
|
*/
|
|
32
48
|
const providerFactory = (options = {}) => {
|
|
33
49
|
const { throwOnDuplicates = true } = options;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/utils",
|
|
3
|
-
"version": "4.4.0-beta.
|
|
3
|
+
"version": "4.4.0-beta.2",
|
|
4
4
|
"description": "Shared utilities for the Strapi packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"node": ">=14.19.1 <=18.x.x",
|
|
46
46
|
"npm": ">=6.0.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "baad89e67844d972ef53a6f1b0839a361bf968c0"
|
|
49
49
|
}
|