not-node 6.3.52 → 6.3.53

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-node",
3
- "version": "6.3.52",
3
+ "version": "6.3.53",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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 (typeof action === "function" && typeof action.run === "function") {
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);
@@ -3,5 +3,6 @@ const ActionsSetsLibrary = require("../actions.lib.js");
3
3
  const ActionsBefore = new ActionsSetsLibrary();
4
4
 
5
5
  ActionsBefore.add("ownage", require("./ownage"));
6
+ ActionsBefore.add("standartQueries", require("./standart.queries.js"));
6
7
 
7
8
  module.exports = ActionsBefore;
@@ -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
+ };
@@ -13,6 +13,10 @@ class ActionsSetsLibrary {
13
13
  }
14
14
  return {};
15
15
  }
16
+
17
+ has(name){
18
+ return this.#lib.has(name);
19
+ }
16
20
  }
17
21
 
18
22
  module.exports = ActionsSetsLibrary;
@@ -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[setName] &&
23
- Object.assign(ACTIONS, actionsSetsLibrary[setName]);
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) => Logic.onBefore(undefined, 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) =>
@@ -11,48 +11,28 @@ const {
11
11
  } = require("../exceptions/logic.js");
12
12
 
13
13
  class LogicProxied {
14
- #afterPipes;
15
- #beforePipes;
14
+ afterPipes;
15
+ beforePipes;
16
16
 
17
- #actions = new Map();
18
- #actionRunner = ActionRunner;
17
+ actions = new Map();
18
+ actionRunner = ActionRunner;
19
19
 
20
- #populateBuilders = {};
21
- #defaultPopulate = [];
20
+ populateBuilders = {};
21
+ defaultPopulate = [];
22
22
 
23
- #MODEL_NAME;
24
- #MODULE_NAME;
25
- #USER_MODEL_NAME = "";
23
+ MODEL_NAME;
24
+ MODULE_NAME;
25
+ USER_MODEL_NAME = "";
26
26
 
27
- #log;
28
- #say;
29
- #phrase;
30
- #config;
31
- #logAction;
32
- #logDebugAction;
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.#MODEL_NAME = MODEL_NAME;
69
- this.#MODULE_NAME = MODULE_NAME;
70
- this.#USER_MODEL_NAME = USER_MODEL_NAME;
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.#defaultPopulate = defaultPopulate);
73
- populateBuilders && (this.#populateBuilders = populateBuilders);
52
+ defaultPopulate && (this.defaultPopulate = defaultPopulate);
53
+ populateBuilders && (this.populateBuilders = populateBuilders);
74
54
 
75
- actionRunner && (this.#actionRunner = actionRunner);
76
- this.#afterPipes = new NamedActionPipes(
55
+ actionRunner && (this.actionRunner = actionRunner);
56
+ this.afterPipes = new NamedActionPipes(
77
57
  NamedActionPipes.PIPE_TYPES.CONSECUTIVE,
78
- this.#actionRunner
58
+ this.actionRunner
79
59
  );
80
- this.#beforePipes = new NamedActionPipes(
60
+ this.beforePipes = new NamedActionPipes(
81
61
  NamedActionPipes.PIPE_TYPES.CONSECUTIVE,
82
- this.#actionRunner
62
+ this.actionRunner
83
63
  );
84
64
 
85
65
  Object.keys(actions).forEach((actionName) => {
86
- this.#actions.set(actionName, actions[actionName]);
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.#actions.has(prop)) {
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.#log = LogInit(
85
+ this.log = LogInit(
106
86
  target,
107
- `${this.#MODULE_NAME}//Logic//${this.#MODEL_NAME}`
87
+ `${this.MODULE_NAME}//Logic//${this.MODEL_NAME}`
108
88
  );
109
- this.#say = sayForModule(this.#MODULE_NAME);
110
- this.#phrase = modulePhrase(this.#MODULE_NAME);
111
- this.#config = configInit.readerForModule(this.#MODULE_NAME);
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.#logAction = (actionName, identity, params = {}) => {
114
- this.#log &&
115
- this.#log.log({
93
+ this.logAction = (actionName, identity, params = {}) => {
94
+ this.log &&
95
+ this.log.log({
116
96
  time: new Date(),
117
- module: this.#MODULE_NAME,
118
- logic: this.#MODEL_NAME,
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.#logDebugAction = (action, identity) => {
125
- this.#log &&
126
- this.#log.debug(
104
+ this.logDebugAction = (action, identity) => {
105
+ this.log &&
106
+ this.log.debug(
127
107
  new Date(),
128
- `${this.#MODULE_NAME}//Logic//${
129
- this.#MODEL_NAME
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.#MODULE_NAME}//${this.#MODEL_NAME}`);
118
+ return getApp().getModel(`${this.MODULE_NAME}//${this.MODEL_NAME}`);
139
119
  }
140
120
 
141
121
  getModelSchema() {
142
122
  return getApp().getModelSchema(
143
- `${this.#MODULE_NAME}//${this.#MODEL_NAME}`
123
+ `${this.MODULE_NAME}//${this.MODEL_NAME}`
144
124
  );
145
125
  }
146
126
 
147
127
  getModelUser() {
148
- return this.#USER_MODEL_NAME
149
- ? getApp().getModel(this.#USER_MODEL_NAME)
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.#populateBuilders &&
156
- objHas(this.#populateBuilders, actionName) &&
157
- isFunc(this.#populateBuilders[actionName])
135
+ this.populateBuilders &&
136
+ objHas(this.populateBuilders, actionName) &&
137
+ isFunc(this.populateBuilders[actionName])
158
138
  ) {
159
139
  return await executeFunctionAsAsync(
160
- this.#populateBuilders[actionName],
140
+ this.populateBuilders[actionName],
161
141
  [prepared]
162
142
  );
163
143
  }
164
- return this.#defaultPopulate;
144
+ return this.defaultPopulate;
165
145
  }
166
146
 
167
147
  #getActionRunner(actionName) {
168
148
  return async (...args) => {
169
149
  try {
170
- const action = this.#actions.get(actionName);
171
- await this.#beforeAction(actionName, [
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.#actionRunner.run(action, [
177
- this,
156
+ const actionResult = await this.actionRunner.run(action, [
157
+ this.#proxy,
178
158
  actionName,
179
159
  ...args,
180
160
  ]);
181
- await this.#afterAction(actionName, [
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.#MODULE_NAME,
191
- this.#MODEL_NAME,
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 #beforeAction(actionName, args) {
200
- await this.#beforePipes.execute(actionName, args);
179
+ async beforeAction(actionName, args) {
180
+ await this.beforePipes.execute(actionName, args);
201
181
  }
202
182
 
203
- async #afterAction(actionName, args) {
204
- await this.#afterPipes.execute(actionName, args);
183
+ async afterAction(actionName, args) {
184
+ await this.afterPipes.execute(actionName, args);
205
185
  }
206
186
 
207
187
  onAfter(name, action) {
208
- this.#afterPipes.add(name, action);
188
+ this.afterPipes.add(name, action);
209
189
  }
210
190
 
211
191
  offAfter(name, action) {
212
- this.#afterPipes.remove(name, action);
192
+ this.afterPipes.remove(name, action);
213
193
  }
214
194
 
215
195
  onBefore(name, action) {
216
- this.#beforePipes.add(name, action);
196
+ this.beforePipes.add(name, action);
217
197
  }
218
198
 
219
199
  offBefore(name, action) {
220
- this.#beforePipes.remove(name, action);
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
- #actionRunner = ActionRunner;
19
+ actionRunner = ActionRunner;
20
20
 
21
21
  constructor(type = CONSECUTIVE, actionRunner = ActionRunner) {
22
22
  this.#type = type;
23
- actionRunner && (this.#actionRunner = actionRunner);
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.#addToPipe(this.#all, action);
32
+ this.addToPipe(this.#all, action);
29
33
  } else {
30
- this.#initNamedPipe(name);
31
- this.#addToPipe(this.#named[name], action);
34
+ this.initNamedPipe(name);
35
+ this.addToPipe(this.#named[name], action);
32
36
  }
33
37
  return this;
34
38
  }
35
39
 
36
- #addToPipe(pipe, action) {
40
+ addToPipe(pipe, action) {
37
41
  if (!pipe.includes(action)) {
38
42
  pipe.push(action);
39
43
  }
40
44
  }
41
45
 
42
- #removeFromPipe(pipe, action) {
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
- #initNamedPipe(name) {
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.#removeFromPipe(this.#all, action);
60
+ this.removeFromPipe(this.#all, action);
57
61
  } else {
58
- this.#initNamedPipe(name);
59
- this.#removeFromPipe(this.#named[name], action);
62
+ this.initNamedPipe(name);
63
+ this.removeFromPipe(this.#named[name], action);
60
64
  }
61
65
  return this;
62
66
  }
63
67
 
64
- #buildPipe(name) {
68
+ buildPipe(name) {
65
69
  const final = [...this.#all];
66
- this.#initNamedPipe(name);
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.#buildPipe(name);
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.#executeConsecutive,
83
- PARALLEL: this.#executeParallel,
86
+ [CONSECUTIVE]: this.executeConsecutive.bind(this),
87
+ [PARALLEL]: this.executeParallel.bind(this),
84
88
  };
85
- return await ways[this.#type](pipe, params);
89
+ return await ways[this.type](pipe, params);
86
90
  }
87
91
 
88
- async #executeConsecutive(pipe, params) {
92
+ async executeConsecutive(pipe, params) {
89
93
  for (let action of pipe) {
90
- await this.#actionRunner.run(action, params);
94
+ await this.actionRunner.run(action, params);
91
95
  }
92
96
  }
93
97
 
94
- async #executeParallel(pipe, params) {
98
+ async executeParallel(pipe, params) {
95
99
  const promisesOfPipe = pipe.map((action) =>
96
- this.#actionRunner.run(action, params)
100
+ this.actionRunner.run(action, params)
97
101
  );
98
102
  await Promise.all(promisesOfPipe);
99
103
  }
@@ -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