not-node 6.3.52 → 6.3.54
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/package.json +1 -1
- package/src/identity/providers/session.js +1 -1
- package/src/identity/providers/token.js +49 -13
- package/src/logic/action.runner.js +1 -1
- package/src/logic/actions.before/index.js +1 -0
- package/src/logic/actions.before/standart.queries.js +28 -0
- package/src/logic/actions.lib.js +4 -0
- package/src/logic/generic.js +6 -4
- package/src/logic/logic.js +71 -91
- package/src/logic/named.actions.pipes.js +25 -21
- package/src/model/default.js +4 -0
package/package.json
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const Log = require("not-log")(module, "Identity//Token");
|
|
2
|
+
const notRequestError = require("not-error/src/request.error.node.cjs");
|
|
3
|
+
const notCommon = require("../../common");
|
|
4
|
+
const Request = require("http").IncomingMessage;
|
|
5
|
+
|
|
3
6
|
const CONST = require("../../auth/const");
|
|
4
7
|
const ROLES = require("../../auth/roles");
|
|
5
8
|
const { objHas } = require("../../common");
|
|
@@ -7,14 +10,22 @@ const phrase = require("not-locale").modulePhrase("not-node");
|
|
|
7
10
|
|
|
8
11
|
const JWT = require("jsonwebtoken");
|
|
9
12
|
|
|
13
|
+
const TOKEN_OBJECT_REQUIRED_PROPERTIES = ["_id", "role", "active", "username"];
|
|
14
|
+
|
|
10
15
|
module.exports = class IdentityProviderToken {
|
|
16
|
+
/**
|
|
17
|
+
* @type {null|object}
|
|
18
|
+
*/
|
|
11
19
|
#tokenContent = null;
|
|
20
|
+
/**
|
|
21
|
+
* @type {null|string}
|
|
22
|
+
*/
|
|
12
23
|
#token = null;
|
|
13
24
|
|
|
14
25
|
static #options = {};
|
|
15
26
|
|
|
16
27
|
static setOptions(options = {}) {
|
|
17
|
-
this.#options = options;
|
|
28
|
+
this.#options = { ...this.#options, ...options };
|
|
18
29
|
}
|
|
19
30
|
|
|
20
31
|
static #getOptions() {
|
|
@@ -30,9 +41,12 @@ module.exports = class IdentityProviderToken {
|
|
|
30
41
|
}
|
|
31
42
|
|
|
32
43
|
constructor(req) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
if (IdentityProviderToken.sourceIsRequest(req)) {
|
|
45
|
+
this.#extractToken(req);
|
|
46
|
+
this.#extractTokenContent();
|
|
47
|
+
} else if (IdentityProviderToken.sourceIsTokenContent(req)) {
|
|
48
|
+
this.#tokenContent = IdentityProviderToken.copyTokenContent(req);
|
|
49
|
+
}
|
|
36
50
|
return this;
|
|
37
51
|
}
|
|
38
52
|
|
|
@@ -70,20 +84,20 @@ module.exports = class IdentityProviderToken {
|
|
|
70
84
|
}
|
|
71
85
|
return null;
|
|
72
86
|
} catch (e) {
|
|
73
|
-
error(e.message);
|
|
87
|
+
Log && Log.error(e.message);
|
|
74
88
|
return null;
|
|
75
89
|
}
|
|
76
90
|
}
|
|
77
91
|
|
|
78
92
|
#encodeTokenContent() {
|
|
79
93
|
try {
|
|
80
|
-
if (this.#token) {
|
|
94
|
+
if (this.#token && this.#tokenContent) {
|
|
81
95
|
const secret = IdentityProviderToken.#getOptions().secret;
|
|
82
96
|
return JWT.sign(this.#tokenContent, secret);
|
|
83
97
|
}
|
|
84
98
|
return null;
|
|
85
99
|
} catch (e) {
|
|
86
|
-
error(e.message);
|
|
100
|
+
Log && Log.error(e.message);
|
|
87
101
|
return null;
|
|
88
102
|
}
|
|
89
103
|
}
|
|
@@ -119,7 +133,7 @@ module.exports = class IdentityProviderToken {
|
|
|
119
133
|
|
|
120
134
|
static #validateTTLForToken(tokenTTL) {
|
|
121
135
|
if (tokenTTL <= 0 || isNaN(tokenTTL)) {
|
|
122
|
-
log(phrase("user_token_ttl_not_set"));
|
|
136
|
+
Log && Log.log(phrase("user_token_ttl_not_set"));
|
|
123
137
|
tokenTTL = CONST.TOKEN_TTL;
|
|
124
138
|
}
|
|
125
139
|
return tokenTTL;
|
|
@@ -193,7 +207,7 @@ module.exports = class IdentityProviderToken {
|
|
|
193
207
|
const roles = this.getRole();
|
|
194
208
|
for (let role of roles) {
|
|
195
209
|
if (
|
|
196
|
-
IdentityProviderToken.#getOptions()
|
|
210
|
+
IdentityProviderToken.#getOptions()?.primaryRoles.includes(role)
|
|
197
211
|
) {
|
|
198
212
|
return role;
|
|
199
213
|
}
|
|
@@ -298,7 +312,29 @@ module.exports = class IdentityProviderToken {
|
|
|
298
312
|
this.setGuest();
|
|
299
313
|
}
|
|
300
314
|
|
|
301
|
-
static test(
|
|
302
|
-
|
|
315
|
+
static test(some) {
|
|
316
|
+
if (this.sourceIsRequest(some)) {
|
|
317
|
+
return !!this.getTokenFromRequest(some);
|
|
318
|
+
} else if (this.sourceIsTokenContent(some)) {
|
|
319
|
+
return !!this.copyTokenContent(some);
|
|
320
|
+
}
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
static sourceIsRequest(some) {
|
|
325
|
+
return some instanceof Request;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
static sourceIsTokenContent(some) {
|
|
329
|
+
return (
|
|
330
|
+
typeof some === "object" &&
|
|
331
|
+
notCommon.objHas(some, TOKEN_OBJECT_REQUIRED_PROPERTIES)
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
static copyTokenContent(obj) {
|
|
336
|
+
return {
|
|
337
|
+
...obj,
|
|
338
|
+
};
|
|
303
339
|
}
|
|
304
340
|
};
|
|
@@ -3,7 +3,7 @@ const { ActionExceptionWrongType } = require("../exceptions/action.js");
|
|
|
3
3
|
class ActionRunner {
|
|
4
4
|
static async run(action, params) {
|
|
5
5
|
//any static class with static run method
|
|
6
|
-
if (
|
|
6
|
+
if (action && typeof action.run === "function") {
|
|
7
7
|
return await action.run(...params);
|
|
8
8
|
} else if (typeof action === "function") {
|
|
9
9
|
return await action(...params);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const ModelRoutine = require("../../model/routine.js");
|
|
2
|
+
|
|
3
|
+
//adds to args object few basic queries
|
|
4
|
+
module.exports = class StandartQueriesBeforeAction {
|
|
5
|
+
static async run(logic, actionName, args) {
|
|
6
|
+
try {
|
|
7
|
+
const { targetId, targetID } = args;
|
|
8
|
+
args.defaultQueryById = {
|
|
9
|
+
_id: targetId,
|
|
10
|
+
};
|
|
11
|
+
const Model = logic.getModel();
|
|
12
|
+
const incFieldName = ModelRoutine.incremental(Model);
|
|
13
|
+
if (
|
|
14
|
+
incFieldName &&
|
|
15
|
+
typeof targetID === "number" &&
|
|
16
|
+
!isNaN(targetID) &&
|
|
17
|
+
targetID
|
|
18
|
+
) {
|
|
19
|
+
args.defaultQueryByID = {
|
|
20
|
+
[incFieldName]: targetID,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
args.defaultQueryMany = {};
|
|
24
|
+
} catch (e) {
|
|
25
|
+
logic.log.error(e);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
package/src/logic/actions.lib.js
CHANGED
package/src/logic/generic.js
CHANGED
|
@@ -11,7 +11,7 @@ module.exports = ({
|
|
|
11
11
|
actionsSets = ["standart"],
|
|
12
12
|
actions = {},
|
|
13
13
|
beforeActions = {},
|
|
14
|
-
beforeActionsAll = [],
|
|
14
|
+
beforeActionsAll = [require('./actions.before/standart.queries.js')],
|
|
15
15
|
afterActions = {},
|
|
16
16
|
afterActionsAll = [],
|
|
17
17
|
}) => {
|
|
@@ -19,8 +19,8 @@ module.exports = ({
|
|
|
19
19
|
const ACTIONS = {};
|
|
20
20
|
//add all from actions sets library
|
|
21
21
|
actionsSets.forEach((setName) => {
|
|
22
|
-
actionsSetsLibrary
|
|
23
|
-
Object.assign(ACTIONS, actionsSetsLibrary
|
|
22
|
+
actionsSetsLibrary.has(setName) &&
|
|
23
|
+
Object.assign(ACTIONS, actionsSetsLibrary.get(setName));
|
|
24
24
|
});
|
|
25
25
|
//add user defined
|
|
26
26
|
Object.assign(ACTIONS, actions);
|
|
@@ -32,7 +32,9 @@ module.exports = ({
|
|
|
32
32
|
USER_MODEL_NAME,
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
beforeActionsAll.forEach((action) =>
|
|
35
|
+
beforeActionsAll.forEach((action) => {
|
|
36
|
+
Logic.onBefore(undefined, action);
|
|
37
|
+
});
|
|
36
38
|
afterActionsAll.forEach((action) => Logic.onAfter(undefined, action));
|
|
37
39
|
|
|
38
40
|
Object.keys(beforeActions).forEach((actionName) =>
|
package/src/logic/logic.js
CHANGED
|
@@ -11,48 +11,28 @@ const {
|
|
|
11
11
|
} = require("../exceptions/logic.js");
|
|
12
12
|
|
|
13
13
|
class LogicProxied {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
afterPipes;
|
|
15
|
+
beforePipes;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
actions = new Map();
|
|
18
|
+
actionRunner = ActionRunner;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
populateBuilders = {};
|
|
21
|
+
defaultPopulate = [];
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
MODEL_NAME;
|
|
24
|
+
MODULE_NAME;
|
|
25
|
+
USER_MODEL_NAME = "";
|
|
26
26
|
|
|
27
|
-
#
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
get log() {
|
|
35
|
-
return this.#log;
|
|
36
|
-
}
|
|
37
|
-
get say() {
|
|
38
|
-
return this.#say;
|
|
39
|
-
}
|
|
40
|
-
get phrase() {
|
|
41
|
-
return this.#phrase;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
get config() {
|
|
45
|
-
return this.#config;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
get logAction() {
|
|
49
|
-
return this.#logAction;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
get logDebugAction() {
|
|
53
|
-
return this.#logDebugAction;
|
|
54
|
-
}
|
|
27
|
+
#proxy;
|
|
28
|
+
log;
|
|
29
|
+
say;
|
|
30
|
+
phrase;
|
|
31
|
+
config;
|
|
32
|
+
logAction;
|
|
33
|
+
logDebugAction;
|
|
55
34
|
|
|
35
|
+
|
|
56
36
|
constructor(
|
|
57
37
|
actions = {},
|
|
58
38
|
actionRunner = ActionRunner,
|
|
@@ -65,34 +45,34 @@ class LogicProxied {
|
|
|
65
45
|
USER_MODEL_NAME = "not-user//User",
|
|
66
46
|
}
|
|
67
47
|
) {
|
|
68
|
-
this
|
|
69
|
-
this
|
|
70
|
-
this
|
|
48
|
+
this.MODEL_NAME = MODEL_NAME;
|
|
49
|
+
this.MODULE_NAME = MODULE_NAME;
|
|
50
|
+
this.USER_MODEL_NAME = USER_MODEL_NAME;
|
|
71
51
|
|
|
72
|
-
defaultPopulate && (this
|
|
73
|
-
populateBuilders && (this
|
|
52
|
+
defaultPopulate && (this.defaultPopulate = defaultPopulate);
|
|
53
|
+
populateBuilders && (this.populateBuilders = populateBuilders);
|
|
74
54
|
|
|
75
|
-
actionRunner && (this
|
|
76
|
-
this
|
|
55
|
+
actionRunner && (this.actionRunner = actionRunner);
|
|
56
|
+
this.afterPipes = new NamedActionPipes(
|
|
77
57
|
NamedActionPipes.PIPE_TYPES.CONSECUTIVE,
|
|
78
|
-
this
|
|
58
|
+
this.actionRunner
|
|
79
59
|
);
|
|
80
|
-
this
|
|
60
|
+
this.beforePipes = new NamedActionPipes(
|
|
81
61
|
NamedActionPipes.PIPE_TYPES.CONSECUTIVE,
|
|
82
|
-
this
|
|
62
|
+
this.actionRunner
|
|
83
63
|
);
|
|
84
64
|
|
|
85
65
|
Object.keys(actions).forEach((actionName) => {
|
|
86
|
-
this
|
|
66
|
+
this.actions.set(actionName, actions[actionName]);
|
|
87
67
|
});
|
|
88
68
|
|
|
89
69
|
this.#initTools(target);
|
|
90
70
|
|
|
91
71
|
// proxy logic, do something before each call of all methods inside class
|
|
92
72
|
// like if arg passed is 3, print something additionally
|
|
93
|
-
return new Proxy(this, {
|
|
73
|
+
return this.#proxy = new Proxy(this, {
|
|
94
74
|
get(target, prop) {
|
|
95
|
-
if (target
|
|
75
|
+
if (target.actions.has(prop)) {
|
|
96
76
|
return target.#getActionRunner(prop);
|
|
97
77
|
} else {
|
|
98
78
|
return target[prop];
|
|
@@ -102,31 +82,31 @@ class LogicProxied {
|
|
|
102
82
|
}
|
|
103
83
|
|
|
104
84
|
#initTools(target) {
|
|
105
|
-
this
|
|
85
|
+
this.log = LogInit(
|
|
106
86
|
target,
|
|
107
|
-
`${this
|
|
87
|
+
`${this.MODULE_NAME}//Logic//${this.MODEL_NAME}`
|
|
108
88
|
);
|
|
109
|
-
this
|
|
110
|
-
this
|
|
111
|
-
this
|
|
89
|
+
this.say = sayForModule(this.MODULE_NAME);
|
|
90
|
+
this.phrase = modulePhrase(this.MODULE_NAME);
|
|
91
|
+
this.config = configInit.readerForModule(this.MODULE_NAME);
|
|
112
92
|
|
|
113
|
-
this
|
|
114
|
-
this
|
|
115
|
-
this
|
|
93
|
+
this.logAction = (actionName, identity, params = {}) => {
|
|
94
|
+
this.log &&
|
|
95
|
+
this.log.log({
|
|
116
96
|
time: new Date(),
|
|
117
|
-
module: this
|
|
118
|
-
logic: this
|
|
97
|
+
module: this.MODULE_NAME,
|
|
98
|
+
logic: this.MODEL_NAME,
|
|
119
99
|
action: actionName,
|
|
120
100
|
...identity,
|
|
121
101
|
params,
|
|
122
102
|
});
|
|
123
103
|
};
|
|
124
|
-
this
|
|
125
|
-
this
|
|
126
|
-
this
|
|
104
|
+
this.logDebugAction = (action, identity) => {
|
|
105
|
+
this.log &&
|
|
106
|
+
this.log.debug(
|
|
127
107
|
new Date(),
|
|
128
|
-
`${this
|
|
129
|
-
this
|
|
108
|
+
`${this.MODULE_NAME}//Logic//${
|
|
109
|
+
this.MODEL_NAME
|
|
130
110
|
}//${action}`,
|
|
131
111
|
identity?.ip,
|
|
132
112
|
identity?.root
|
|
@@ -135,51 +115,51 @@ class LogicProxied {
|
|
|
135
115
|
}
|
|
136
116
|
|
|
137
117
|
getModel() {
|
|
138
|
-
return getApp().getModel(`${this
|
|
118
|
+
return getApp().getModel(`${this.MODULE_NAME}//${this.MODEL_NAME}`);
|
|
139
119
|
}
|
|
140
120
|
|
|
141
121
|
getModelSchema() {
|
|
142
122
|
return getApp().getModelSchema(
|
|
143
|
-
`${this
|
|
123
|
+
`${this.MODULE_NAME}//${this.MODEL_NAME}`
|
|
144
124
|
);
|
|
145
125
|
}
|
|
146
126
|
|
|
147
127
|
getModelUser() {
|
|
148
|
-
return this
|
|
149
|
-
? getApp().getModel(this
|
|
128
|
+
return this.USER_MODEL_NAME
|
|
129
|
+
? getApp().getModel(this.USER_MODEL_NAME)
|
|
150
130
|
: undefined;
|
|
151
131
|
}
|
|
152
132
|
|
|
153
133
|
async getPopulate(actionName, prepared) {
|
|
154
134
|
if (
|
|
155
|
-
this
|
|
156
|
-
objHas(this
|
|
157
|
-
isFunc(this
|
|
135
|
+
this.populateBuilders &&
|
|
136
|
+
objHas(this.populateBuilders, actionName) &&
|
|
137
|
+
isFunc(this.populateBuilders[actionName])
|
|
158
138
|
) {
|
|
159
139
|
return await executeFunctionAsAsync(
|
|
160
|
-
this
|
|
140
|
+
this.populateBuilders[actionName],
|
|
161
141
|
[prepared]
|
|
162
142
|
);
|
|
163
143
|
}
|
|
164
|
-
return this
|
|
144
|
+
return this.defaultPopulate;
|
|
165
145
|
}
|
|
166
146
|
|
|
167
147
|
#getActionRunner(actionName) {
|
|
168
148
|
return async (...args) => {
|
|
169
149
|
try {
|
|
170
|
-
const action = this
|
|
171
|
-
await this
|
|
172
|
-
this,
|
|
150
|
+
const action = this.actions.get(actionName);
|
|
151
|
+
await this.beforeAction(actionName, [
|
|
152
|
+
this.#proxy,
|
|
173
153
|
actionName,
|
|
174
154
|
...args,
|
|
175
155
|
]);
|
|
176
|
-
const actionResult = await this
|
|
177
|
-
this,
|
|
156
|
+
const actionResult = await this.actionRunner.run(action, [
|
|
157
|
+
this.#proxy,
|
|
178
158
|
actionName,
|
|
179
159
|
...args,
|
|
180
160
|
]);
|
|
181
|
-
await this
|
|
182
|
-
this,
|
|
161
|
+
await this.afterAction(actionName, [
|
|
162
|
+
this.#proxy,
|
|
183
163
|
actionName,
|
|
184
164
|
actionResult,
|
|
185
165
|
...args,
|
|
@@ -187,8 +167,8 @@ class LogicProxied {
|
|
|
187
167
|
return actionResult;
|
|
188
168
|
} catch (e) {
|
|
189
169
|
throw new LogicExceptionActionExecutionError(
|
|
190
|
-
this
|
|
191
|
-
this
|
|
170
|
+
this.MODULE_NAME,
|
|
171
|
+
this.MODEL_NAME,
|
|
192
172
|
actionName,
|
|
193
173
|
e
|
|
194
174
|
);
|
|
@@ -196,28 +176,28 @@ class LogicProxied {
|
|
|
196
176
|
};
|
|
197
177
|
}
|
|
198
178
|
|
|
199
|
-
async
|
|
200
|
-
await this
|
|
179
|
+
async beforeAction(actionName, args) {
|
|
180
|
+
await this.beforePipes.execute(actionName, args);
|
|
201
181
|
}
|
|
202
182
|
|
|
203
|
-
async
|
|
204
|
-
await this
|
|
183
|
+
async afterAction(actionName, args) {
|
|
184
|
+
await this.afterPipes.execute(actionName, args);
|
|
205
185
|
}
|
|
206
186
|
|
|
207
187
|
onAfter(name, action) {
|
|
208
|
-
this
|
|
188
|
+
this.afterPipes.add(name, action);
|
|
209
189
|
}
|
|
210
190
|
|
|
211
191
|
offAfter(name, action) {
|
|
212
|
-
this
|
|
192
|
+
this.afterPipes.remove(name, action);
|
|
213
193
|
}
|
|
214
194
|
|
|
215
195
|
onBefore(name, action) {
|
|
216
|
-
this
|
|
196
|
+
this.beforePipes.add(name, action);
|
|
217
197
|
}
|
|
218
198
|
|
|
219
199
|
offBefore(name, action) {
|
|
220
|
-
this
|
|
200
|
+
this.beforePipes.remove(name, action);
|
|
221
201
|
}
|
|
222
202
|
}
|
|
223
203
|
|
|
@@ -16,36 +16,40 @@ class NamedActionPipes {
|
|
|
16
16
|
#type = CONSECUTIVE;
|
|
17
17
|
#all = [];
|
|
18
18
|
#named = {};
|
|
19
|
-
|
|
19
|
+
actionRunner = ActionRunner;
|
|
20
20
|
|
|
21
21
|
constructor(type = CONSECUTIVE, actionRunner = ActionRunner) {
|
|
22
22
|
this.#type = type;
|
|
23
|
-
actionRunner && (this
|
|
23
|
+
actionRunner && (this.actionRunner = actionRunner);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get type(){
|
|
27
|
+
return this.#type;
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
add(name, action) {
|
|
27
31
|
if (typeof name === "undefined") {
|
|
28
|
-
this
|
|
32
|
+
this.addToPipe(this.#all, action);
|
|
29
33
|
} else {
|
|
30
|
-
this
|
|
31
|
-
this
|
|
34
|
+
this.initNamedPipe(name);
|
|
35
|
+
this.addToPipe(this.#named[name], action);
|
|
32
36
|
}
|
|
33
37
|
return this;
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
addToPipe(pipe, action) {
|
|
37
41
|
if (!pipe.includes(action)) {
|
|
38
42
|
pipe.push(action);
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
|
|
46
|
+
removeFromPipe(pipe, action) {
|
|
43
47
|
if (pipe.includes(action)) {
|
|
44
48
|
pipe.splice(pipe.indexOf(action), 1);
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
initNamedPipe(name) {
|
|
49
53
|
if (!objHas(this.#named, name) || !Array.isArray(this.#named[name])) {
|
|
50
54
|
this.#named[name] = [];
|
|
51
55
|
}
|
|
@@ -53,24 +57,24 @@ class NamedActionPipes {
|
|
|
53
57
|
|
|
54
58
|
remove(name, action) {
|
|
55
59
|
if (typeof name === "undefined") {
|
|
56
|
-
this
|
|
60
|
+
this.removeFromPipe(this.#all, action);
|
|
57
61
|
} else {
|
|
58
|
-
this
|
|
59
|
-
this
|
|
62
|
+
this.initNamedPipe(name);
|
|
63
|
+
this.removeFromPipe(this.#named[name], action);
|
|
60
64
|
}
|
|
61
65
|
return this;
|
|
62
66
|
}
|
|
63
67
|
|
|
64
|
-
|
|
68
|
+
buildPipe(name) {
|
|
65
69
|
const final = [...this.#all];
|
|
66
|
-
this
|
|
70
|
+
this.initNamedPipe(name);
|
|
67
71
|
final.push(...this.#named[name]);
|
|
68
72
|
return final;
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
async execute(name, params) {
|
|
72
76
|
try {
|
|
73
|
-
const pipe = this
|
|
77
|
+
const pipe = this.buildPipe(name);
|
|
74
78
|
return await this.#execute(pipe, params);
|
|
75
79
|
} catch (e) {
|
|
76
80
|
throw new ActionExceptionPipeExecutionError({ cause: e });
|
|
@@ -79,21 +83,21 @@ class NamedActionPipes {
|
|
|
79
83
|
|
|
80
84
|
async #execute(pipe, params) {
|
|
81
85
|
const ways = {
|
|
82
|
-
CONSECUTIVE: this
|
|
83
|
-
PARALLEL: this
|
|
86
|
+
[CONSECUTIVE]: this.executeConsecutive.bind(this),
|
|
87
|
+
[PARALLEL]: this.executeParallel.bind(this),
|
|
84
88
|
};
|
|
85
|
-
return await ways[this
|
|
89
|
+
return await ways[this.type](pipe, params);
|
|
86
90
|
}
|
|
87
91
|
|
|
88
|
-
async
|
|
92
|
+
async executeConsecutive(pipe, params) {
|
|
89
93
|
for (let action of pipe) {
|
|
90
|
-
await this
|
|
94
|
+
await this.actionRunner.run(action, params);
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
97
|
|
|
94
|
-
async
|
|
98
|
+
async executeParallel(pipe, params) {
|
|
95
99
|
const promisesOfPipe = pipe.map((action) =>
|
|
96
|
-
this
|
|
100
|
+
this.actionRunner.run(action, params)
|
|
97
101
|
);
|
|
98
102
|
await Promise.all(promisesOfPipe);
|
|
99
103
|
}
|
package/src/model/default.js
CHANGED
|
@@ -357,11 +357,13 @@ async function removeOne(filter) {
|
|
|
357
357
|
if (!updateResponseSuccess(res, 1)) {
|
|
358
358
|
throw new DBExceptionDeleteWasNotSuccessful(res);
|
|
359
359
|
}
|
|
360
|
+
return res;
|
|
360
361
|
} else {
|
|
361
362
|
const res = await this.deleteOne(filter);
|
|
362
363
|
if (!deleteResponseSuccess(res, 1)) {
|
|
363
364
|
throw new DBExceptionDeleteWasNotSuccessful(res);
|
|
364
365
|
}
|
|
366
|
+
return res;
|
|
365
367
|
}
|
|
366
368
|
}
|
|
367
369
|
|
|
@@ -371,11 +373,13 @@ async function removeMany(filter) {
|
|
|
371
373
|
if (!updateResponseSuccess(res, 0)) {
|
|
372
374
|
throw new DBExceptionDeleteWasNotSuccessful(res);
|
|
373
375
|
}
|
|
376
|
+
return res;
|
|
374
377
|
} else {
|
|
375
378
|
const res = await this.deleteMany(filter);
|
|
376
379
|
if (!deleteResponseSuccess(res, 0)) {
|
|
377
380
|
throw new DBExceptionDeleteWasNotSuccessful(res);
|
|
378
381
|
}
|
|
382
|
+
return res;
|
|
379
383
|
}
|
|
380
384
|
}
|
|
381
385
|
|