not-node 5.0.22 → 5.1.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.
Files changed (126) hide show
  1. package/.eslintrc.json +1 -1
  2. package/bin/not-deploy.js +52 -0
  3. package/index.js +21 -19
  4. package/package.json +1 -1
  5. package/src/app.js +61 -58
  6. package/src/auth/abstract.js +17 -19
  7. package/src/auth/const.js +8 -12
  8. package/src/auth/fields.js +143 -124
  9. package/src/auth/index.js +14 -14
  10. package/src/auth/roles.js +64 -63
  11. package/src/auth/routes.js +89 -54
  12. package/src/auth/rules.js +63 -63
  13. package/src/auth/session.js +60 -62
  14. package/src/bootstrap/form.js +13 -13
  15. package/src/bootstrap/logic.js +45 -41
  16. package/src/bootstrap/model.js +14 -17
  17. package/src/bootstrap/route.js +132 -53
  18. package/src/common.js +86 -79
  19. package/src/core/fields/ID.js +6 -6
  20. package/src/core/fields/__closed.js +3 -3
  21. package/src/core/fields/__latest.js +3 -3
  22. package/src/core/fields/__version.js +3 -3
  23. package/src/core/fields/__versions.js +3 -3
  24. package/src/core/fields/_id.js +6 -6
  25. package/src/core/fields/active.js +9 -9
  26. package/src/core/fields/codeName.js +9 -9
  27. package/src/core/fields/createdAt.js +17 -17
  28. package/src/core/fields/default.js +9 -9
  29. package/src/core/fields/description.js +11 -11
  30. package/src/core/fields/email.js +9 -9
  31. package/src/core/fields/enabled.js +9 -9
  32. package/src/core/fields/expiredAt.js +16 -16
  33. package/src/core/fields/height.js +11 -11
  34. package/src/core/fields/ip.js +10 -10
  35. package/src/core/fields/objectId.js +10 -10
  36. package/src/core/fields/owner.js +13 -13
  37. package/src/core/fields/ownerModel.js +11 -11
  38. package/src/core/fields/price.js +11 -11
  39. package/src/core/fields/requiredObject.js +10 -10
  40. package/src/core/fields/session.js +10 -10
  41. package/src/core/fields/size.js +11 -11
  42. package/src/core/fields/telephone.js +9 -9
  43. package/src/core/fields/title.js +15 -15
  44. package/src/core/fields/updatedAt.js +17 -17
  45. package/src/core/fields/userId.js +11 -12
  46. package/src/core/fields/uuid.js +11 -11
  47. package/src/core/fields/validators/email.js +6 -4
  48. package/src/core/fields/validators/owner.js +6 -4
  49. package/src/core/fields/width.js +11 -11
  50. package/src/domain.js +435 -431
  51. package/src/env.js +23 -23
  52. package/src/error.js +20 -23
  53. package/src/exceptions/db.js +23 -0
  54. package/src/exceptions/http.js +43 -0
  55. package/src/fields/index.js +106 -111
  56. package/src/form/fabric.js +19 -24
  57. package/src/form/form.js +195 -186
  58. package/src/form/index.js +2 -2
  59. package/src/generic/index.js +2 -0
  60. package/src/generic/logic.js +595 -0
  61. package/src/generic/route.js +76 -0
  62. package/src/init/additional.js +7 -7
  63. package/src/init/app.js +75 -68
  64. package/src/init/bodyparser.js +14 -14
  65. package/src/init/compression.js +6 -7
  66. package/src/init/core.js +12 -12
  67. package/src/init/cors.js +22 -24
  68. package/src/init/db/index.js +41 -43
  69. package/src/init/db/ioredis.js +28 -20
  70. package/src/init/db/mongoose.js +42 -32
  71. package/src/init/db/redis.js +59 -48
  72. package/src/init/env.js +44 -36
  73. package/src/init/express.js +18 -21
  74. package/src/init/fileupload.js +8 -10
  75. package/src/init/http.js +65 -47
  76. package/src/init/index.js +141 -148
  77. package/src/init/informer.js +7 -9
  78. package/src/init/methodoverride.js +4 -6
  79. package/src/init/middleware.js +23 -26
  80. package/src/init/modules.js +4 -4
  81. package/src/init/monitoring.js +8 -8
  82. package/src/init/rateLimiter.js +53 -45
  83. package/src/init/routes.js +67 -69
  84. package/src/init/security.js +37 -33
  85. package/src/init/sequence.js +111 -107
  86. package/src/init/sequence.standart.js +54 -56
  87. package/src/init/sessions/index.js +21 -21
  88. package/src/init/sessions/mongoose.js +49 -36
  89. package/src/init/sessions/redis.js +28 -27
  90. package/src/init/static.js +53 -40
  91. package/src/init/template.js +17 -17
  92. package/src/lib.js +230 -200
  93. package/src/manifest/batchRunner.js +26 -25
  94. package/src/manifest/initializator/forms.js +24 -24
  95. package/src/manifest/initializator/index.js +8 -10
  96. package/src/manifest/initializator/manifests.js +45 -42
  97. package/src/manifest/initializator/models.js +37 -34
  98. package/src/manifest/manifest.filter.js +130 -97
  99. package/src/manifest/manifest.js +103 -77
  100. package/src/manifest/module.js +350 -360
  101. package/src/manifest/registrator/fields.js +90 -85
  102. package/src/manifest/registrator/forms.js +47 -47
  103. package/src/manifest/registrator/index.js +14 -16
  104. package/src/manifest/registrator/locales.js +17 -16
  105. package/src/manifest/registrator/logics.js +66 -64
  106. package/src/manifest/registrator/models.js +64 -62
  107. package/src/manifest/registrator/routes.js +171 -132
  108. package/src/manifest/registrator/routes.ws.js +109 -103
  109. package/src/manifest/route.js +216 -161
  110. package/src/model/buildValidator.js +53 -42
  111. package/src/model/default.js +304 -286
  112. package/src/model/enrich.js +69 -61
  113. package/src/model/increment.js +124 -137
  114. package/src/model/proto.js +179 -148
  115. package/src/model/routine.js +85 -76
  116. package/src/model/utils.js +33 -0
  117. package/src/model/versioning.js +148 -130
  118. package/src/obsolete.js +12 -8
  119. package/src/parser.js +29 -22
  120. package/src/repos.js +29 -31
  121. package/src/rollup.js +75 -65
  122. package/src/shell.helpers.js +28 -28
  123. package/static.js +31 -0
  124. package/src/generic/router.js +0 -16
  125. package/src/manifest/module.models.js +0 -0
  126. package/src/manifest/module.status.js +0 -0
package/src/domain.js CHANGED
@@ -3,14 +3,13 @@
3
3
  * But can be used for hosting modules and models.
4
4
  *
5
5
  */
6
- const EventEmitter = require('events');
7
- const {isFunc,isAsync, objHas, firstLetterToUpper} = require('./common');
8
- const {error} = require('not-log')(module, 'domain');
9
- const Env = require('./env');
10
- const
11
- notModule = require('./manifest/module'),
12
- path = require('path'),
13
- fs = require('fs');
6
+ const EventEmitter = require("events");
7
+ const { isFunc, isAsync, objHas, firstLetterToUpper } = require("./common");
8
+ const { error } = require("not-log")(module, "domain");
9
+ const Env = require("./env");
10
+ const notModule = require("./manifest/module"),
11
+ path = require("path"),
12
+ fs = require("fs");
14
13
 
15
14
  const OPT_DEFAULT_SHUTDOWN_TIMEOUT = 5000;
16
15
 
@@ -40,434 +39,439 @@ const OPT_DEFAULT_SHUTDOWN_TIMEOUT = 5000;
40
39
  * .importModule(require('notModule'), 'notModule');
41
40
  **/
42
41
  class notDomain extends EventEmitter {
43
- static OPT_DEFAULT_SHUTDOWN_TIMEOUT = OPT_DEFAULT_SHUTDOWN_TIMEOUT;
44
- //named array of notModules wrappers for notModule format modules
45
- #modules = {};
46
- #options = {};
47
-
48
- #logger = null;
49
- #reporter = null;
50
- #informer = null;
51
- //named ws servers
52
- #wss = {};
53
- //named ws clients
54
- #wsc = {};
55
-
56
- constructor(options) {
57
- super();
58
- this.#options = options;
59
-
60
- return this;
61
- }
62
-
63
- getOptions(){
64
- return this.#options;
65
- }
66
-
67
- /**
68
- * Cycles throu all imported modules, passes name, module, and itself
69
- * to argument function
70
- * @param {function} func function to perfom some action with module
71
- **/
72
- forEachMod(func){
73
- if (this.#modules) {
74
- for (let t of Object.keys(this.#modules)) {
75
- let mod = this.#modules[t];
76
- if (mod) {
77
- func(t, mod, this);
42
+ static OPT_DEFAULT_SHUTDOWN_TIMEOUT = OPT_DEFAULT_SHUTDOWN_TIMEOUT;
43
+ //named array of notModules wrappers for notModule format modules
44
+ #modules = {};
45
+ #options = {};
46
+
47
+ #logger = null;
48
+ #reporter = null;
49
+ #informer = null;
50
+ //named ws servers
51
+ #wss = {};
52
+ //named ws clients
53
+ #wsc = {};
54
+
55
+ constructor(options) {
56
+ super();
57
+ this.#options = options;
58
+
59
+ return this;
60
+ }
61
+
62
+ getOptions() {
63
+ return this.#options;
64
+ }
65
+
66
+ /**
67
+ * Cycles throu all imported modules, passes name, module, and itself
68
+ * to argument function
69
+ * @param {function} func function to perfom some action with module
70
+ **/
71
+ forEachMod(func) {
72
+ if (this.#modules) {
73
+ for (let t of Object.keys(this.#modules)) {
74
+ let mod = this.#modules[t];
75
+ if (mod) {
76
+ func(t, mod, this);
77
+ }
78
+ }
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Importing modules from directory. Chainable.
84
+ * @param {string} modulesPath path to container directory
85
+ * @return {object} notDomain
86
+ **/
87
+ importModulesFrom(modulesPath) {
88
+ fs.readdirSync(modulesPath).forEach((file) => {
89
+ this.importModuleFrom(path.join(modulesPath, file), file);
90
+ });
91
+ return this;
92
+ }
93
+
94
+ /**
95
+ * Import single module from module dir. Chainable.
96
+ * @param {string} modulePath path to module directory
97
+ * @param {string} moduleName name under witch module will be registered
98
+ * @return {object} notDomain
99
+ */
100
+ importModuleFrom(modulePath, moduleName) {
101
+ let mod = new notModule({
102
+ modPath: modulePath,
103
+ modObject: null,
104
+ mongoose: this.#options.mongoose,
105
+ notApp: this,
106
+ fields: this.#options.fields,
107
+ });
108
+ this.importModule(mod, moduleName || mod.getName());
109
+ return this;
110
+ }
111
+
112
+ /**
113
+ * Import module object. Chainable.
114
+ * @param {object} mod notModule instance
115
+ * @param {string} moduleName name under witch module will be registered
116
+ * @return {object} notDomain
117
+ **/
118
+ importModule(mod, moduleName) {
119
+ this.#modules[moduleName] = mod;
120
+ return this;
121
+ }
122
+
123
+ /**
124
+ * Returns route
125
+ * @param {string} name 'moduleName//routeName//functionName' ('not-user//user//add')
126
+ * @return {function} route
127
+ **/
128
+ getRoute(name) {
129
+ if (name.indexOf("//") > 0) {
130
+ let [moduleName, routeName, routeFunctionName] = name.split("//");
131
+ if (this.#modules && objHas(this.#modules, moduleName)) {
132
+ let route = this.#modules[moduleName].getRoute(routeName);
133
+ if (objHas(route, routeFunctionName)) {
134
+ return route[routeFunctionName];
135
+ }
136
+ }
137
+ }
138
+ return null;
139
+ }
140
+
141
+ /**
142
+ * Returns form
143
+ * @param {string} name 'formName' or 'moduleName//formName'
144
+ * ('login', 'not-user//login')
145
+ * @return {object} form
146
+ **/
147
+ getForm(name) {
148
+ const type = "form";
149
+ return this.getByPath(name, type);
150
+ }
151
+
152
+ /**
153
+ * Returns field description
154
+ * @param {string} name 'fieldName' or 'moduleName//fieldName'
155
+ * ('username', 'not-user//username')
156
+ * @return {object} field
157
+ **/
158
+ getField(name) {
159
+ const type = "field";
160
+ return this.getByPath(name, type);
161
+ }
162
+
163
+ /**
164
+ * Returns model
165
+ * @param {string} name 'modelName' or 'moduleName//modelName'
166
+ * ('User', 'moduleName//User')
167
+ * @return {object} model
168
+ **/
169
+ getModel(name) {
170
+ const type = "model";
171
+ return this.getByPath(name, type);
172
+ }
173
+
174
+ getByFullPath(name, type) {
175
+ let [moduleName, resourceName] = name.split("//");
176
+ if (this.#modules && objHas(this.#modules, moduleName)) {
177
+ return this.#modules[moduleName][`get${firstLetterToUpper(type)}`](
178
+ resourceName
179
+ );
180
+ } else {
181
+ error(`resource not found ${type}:${name}`);
182
+ return null;
183
+ }
184
+ }
185
+
186
+ getByShortPath(resourceName, type) {
187
+ for (let moduleName of Object.keys(this.#modules)) {
188
+ const res =
189
+ this.#modules[moduleName][`get${firstLetterToUpper(type)}`](
190
+ resourceName
191
+ );
192
+ if (res) {
193
+ return res;
194
+ }
195
+ }
196
+ error(`resource not found ${type}:${resourceName}`);
197
+ return null;
198
+ }
199
+
200
+ /**
201
+ * Returns file with model declarations
202
+ * @param {string} name 'modelName' or 'moduleName//modelName'
203
+ * @return {object} CommonJS module object
204
+ **/
205
+ getModelFile(name) {
206
+ const type = "modelFile";
207
+ return this.getByPath(name, type);
208
+ }
209
+
210
+ /**
211
+ * Returns specified by name or 'moduleName//modelName' model Schema
212
+ * @param {string} name 'modelName' or 'moduleName//modelName'
213
+ * @return {object} model schema
214
+ **/
215
+
216
+ getModelSchema(name) {
217
+ const type = "modelSchema";
218
+ return this.getByPath(name, type);
219
+ }
220
+
221
+ /**
222
+ * Returns logic
223
+ * @param {string} name 'logicName' or 'moduleName//logicName'
224
+ * ('User', 'moduleName//User')
225
+ * @return {object} logic
226
+ **/
227
+ getLogic(name) {
228
+ const type = "logic";
229
+ return this.getByPath(name, type);
230
+ }
231
+
232
+ /**
233
+ * Returns file with logic declarations
234
+ * @param {string} name 'logicName' or 'moduleName//logicName'
235
+ * @return {object} CommonJS module object
236
+ **/
237
+ getLogicFile(name) {
238
+ const type = "logicFile";
239
+ return this.getByPath(name, type);
240
+ }
241
+
242
+ getByPath(name, type) {
243
+ if (name.indexOf("//") > 0) {
244
+ return this.getByFullPath(name, type);
245
+ } else {
246
+ return this.getByShortPath(name, type);
247
+ }
248
+ }
249
+
250
+ /**
251
+ * Return module by specified module name
252
+ * @param {string} moduleName 'moduleName'
253
+ * @return {object} module
254
+ **/
255
+ getModule(moduleName) {
256
+ if (this.#modules && objHas(this.#modules, moduleName)) {
257
+ return this.#modules[moduleName];
258
+ } else {
259
+ for (let t in this.#modules) {
260
+ if (this.#modules[t].getName() === moduleName) {
261
+ return this.#modules[t];
262
+ }
263
+ }
264
+ return null;
265
+ }
266
+ }
267
+
268
+ /**
269
+ * Execute method in modules
270
+ * @param {string} methodName name of the method to execute
271
+ **/
272
+ async execInModules(methodName) {
273
+ for (let mod of Object.values(this.#modules)) {
274
+ try {
275
+ if (isFunc(mod.exec)) {
276
+ if (isAsync(mod.exec)) {
277
+ await mod.exec(methodName);
278
+ } else {
279
+ mod.exec(methodName);
280
+ }
281
+ }
282
+ } catch (e) {
283
+ this.report(e);
284
+ }
285
+ }
286
+ }
287
+
288
+ /**
289
+ * Execute fabricateModels methods on all registered modules
290
+ * Create mongoose models.
291
+ **/
292
+ fabricate() {
293
+ for (let mod of Object.values(this.#modules)) {
294
+ mod.fabricateModels && mod.fabricateModels();
78
295
  }
79
- }
80
- }
81
- }
82
-
83
- /**
84
- * Importing modules from directory. Chainable.
85
- * @param {string} modulesPath path to container directory
86
- * @return {object} notDomain
87
- **/
88
- importModulesFrom(modulesPath) {
89
- fs.readdirSync(modulesPath).forEach((file) => {
90
- this.importModuleFrom(path.join(modulesPath, file), file);
91
- });
92
- return this;
93
- }
94
-
95
- /**
96
- * Import single module from module dir. Chainable.
97
- * @param {string} modulePath path to module directory
98
- * @param {string} moduleName name under witch module will be registered
99
- * @return {object} notDomain
100
- */
101
- importModuleFrom(modulePath, moduleName) {
102
- let mod = new notModule({
103
- modPath: modulePath,
104
- modObject: null,
105
- mongoose: this.#options.mongoose,
106
- notApp: this,
107
- fields: this.#options.fields
108
- });
109
- this.importModule(mod, moduleName || mod.getName());
110
- return this;
111
- }
112
-
113
- /**
114
- * Import module object. Chainable.
115
- * @param {object} mod notModule instance
116
- * @param {string} moduleName name under witch module will be registered
117
- * @return {object} notDomain
118
- **/
119
- importModule(mod, moduleName) {
120
- this.#modules[moduleName] = mod;
121
- return this;
122
- }
123
-
124
- /**
125
- * Returns route
126
- * @param {string} name 'moduleName//routeName//functionName' ('not-user//user//add')
127
- * @return {function} route
128
- **/
129
- getRoute(name) {
130
- if (name.indexOf('//') > 0) {
131
- let [moduleName, routeName, routeFunctionName] = name.split('//');
132
- if (this.#modules && objHas(this.#modules, moduleName)) {
133
- let route = this.#modules[moduleName].getRoute(routeName);
134
- if (objHas(route, routeFunctionName)) {
135
- return route[routeFunctionName];
296
+ }
297
+
298
+ /**
299
+ * logger
300
+ */
301
+ set logger(logger) {
302
+ this.#logger = logger;
303
+ }
304
+
305
+ get logger() {
306
+ if (typeof this.#logger !== "undefined" && this.#logger !== null) {
307
+ return this.#logger;
308
+ } else {
309
+ return console;
310
+ }
311
+ }
312
+
313
+ log() {
314
+ this.logger.log(...arguments);
315
+ return this;
316
+ }
317
+
318
+ /**
319
+ * reporter - errors
320
+ */
321
+
322
+ get DEFAULT_REPORTER() {
323
+ return {
324
+ async report(...params) {
325
+ console.error(params);
326
+ },
327
+ };
328
+ }
329
+
330
+ set reporter(reporter) {
331
+ this.#reporter = reporter;
332
+ }
333
+
334
+ get reporter() {
335
+ return this.#reporter || this.DEFAULT_REPORTER;
336
+ }
337
+
338
+ report(err) {
339
+ this.reporter.report(err).catch(this.logger.error);
340
+ }
341
+
342
+ /**
343
+ * informer - messages
344
+ */
345
+ get DEFAULT_INFORMER() {
346
+ return {
347
+ now: console.info,
348
+ };
349
+ }
350
+
351
+ set informer(informer /* not-informer.Informer */) {
352
+ this.#informer = informer;
353
+ }
354
+
355
+ get informer() {
356
+ return this.#informer || this.DEFAULT_INFORMER;
357
+ }
358
+
359
+ inform(data /* look for not-informer.Informer.now */) {
360
+ this.informer.now(data);
361
+ }
362
+
363
+ addWSServer(name, wss) {
364
+ this.#wss[name] = wss;
365
+ }
366
+
367
+ WSServer(name = "main") {
368
+ if (objHas(this.#wss, name)) {
369
+ return this.#wss[name];
370
+ } else {
371
+ return undefined;
136
372
  }
137
- }
138
- }
139
- return null;
140
- }
141
-
142
- /**
143
- * Returns form
144
- * @param {string} name 'formName' or 'moduleName//formName'
145
- * ('login', 'not-user//login')
146
- * @return {object} form
147
- **/
148
- getForm(name) {
149
- const type = 'form';
150
- return this.getByPath(name, type);
151
- }
152
-
153
- /**
154
- * Returns field description
155
- * @param {string} name 'fieldName' or 'moduleName//fieldName'
156
- * ('username', 'not-user//username')
157
- * @return {object} field
158
- **/
159
- getField(name) {
160
- const type = 'field';
161
- return this.getByPath(name, type);
162
- }
163
-
164
- /**
165
- * Returns model
166
- * @param {string} name 'modelName' or 'moduleName//modelName'
167
- * ('User', 'moduleName//User')
168
- * @return {object} model
169
- **/
170
- getModel(name) {
171
- const type = 'model';
172
- return this.getByPath(name, type);
173
- }
174
-
175
- getByFullPath(name, type){
176
- let [moduleName, resourceName] = name.split('//');
177
- if (this.#modules && objHas(this.#modules, moduleName)) {
178
- return this.#modules[moduleName][`get${firstLetterToUpper(type)}`](resourceName);
179
- } else {
180
- error(`resource not found ${type}:${name}`);
181
- return null;
182
- }
183
- }
184
-
185
- getByShortPath(resourceName, type){
186
- for (let moduleName of Object.keys(this.#modules)) {
187
- const res = this.#modules[moduleName][`get${firstLetterToUpper(type)}`](resourceName);
188
- if(res){
189
- return res;
190
- }
191
- }
192
- error(`resource not found ${type}:${resourceName}`);
193
- return null;
194
- }
195
-
196
- /**
197
- * Returns file with model declarations
198
- * @param {string} name 'modelName' or 'moduleName//modelName'
199
- * @return {object} CommonJS module object
200
- **/
201
- getModelFile(name) {
202
- const type = 'modelFile';
203
- return this.getByPath(name, type);
204
- }
205
-
206
- /**
207
- * Returns specified by name or 'moduleName//modelName' model Schema
208
- * @param {string} name 'modelName' or 'moduleName//modelName'
209
- * @return {object} model schema
210
- **/
211
-
212
- getModelSchema(name) {
213
- const type = 'modelSchema';
214
- return this.getByPath(name, type);
215
- }
216
-
217
- /**
218
- * Returns logic
219
- * @param {string} name 'logicName' or 'moduleName//logicName'
220
- * ('User', 'moduleName//User')
221
- * @return {object} logic
222
- **/
223
- getLogic(name) {
224
- const type = 'logic';
225
- return this.getByPath(name, type);
226
- }
227
-
228
-
229
- /**
230
- * Returns file with logic declarations
231
- * @param {string} name 'logicName' or 'moduleName//logicName'
232
- * @return {object} CommonJS module object
233
- **/
234
- getLogicFile(name) {
235
- const type = 'logicFile';
236
- return this.getByPath(name, type);
237
- }
238
-
239
- getByPath(name, type){
240
- if (name.indexOf('//') > 0) {
241
- return this.getByFullPath(name, type);
242
- } else {
243
- return this.getByShortPath(name, type);
244
- }
245
- }
246
-
247
- /**
248
- * Return module by specified module name
249
- * @param {string} moduleName 'moduleName'
250
- * @return {object} module
251
- **/
252
- getModule(moduleName) {
253
- if (this.#modules && objHas(this.#modules,moduleName)) {
254
- return this.#modules[moduleName];
255
- } else {
256
- for (let t in this.#modules) {
257
- if (this.#modules[t].getName() === moduleName) {
258
- return this.#modules[t];
373
+ }
374
+
375
+ addWSClient(name, wsc) {
376
+ this.#wsc[name] = wsc;
377
+ }
378
+
379
+ WSClient(name) {
380
+ if (objHas(this.#wsc, name)) {
381
+ return this.#wsc[name];
382
+ } else {
383
+ return undefined;
259
384
  }
260
- }
261
- return null;
262
- }
263
- }
264
-
265
- /**
266
- * Execute method in modules
267
- * @param {string} methodName name of the method to execute
268
- **/
269
- async execInModules(methodName) {
270
- for (let mod of Object.values(this.#modules)) {
271
- try{
272
- if(isFunc(mod.exec)){
273
- if(isAsync(mod.exec)){
274
- await mod.exec(methodName);
275
- }else{
276
- mod.exec(methodName);
277
- }
385
+ }
386
+
387
+ /**
388
+ *
389
+ * Logging message about shutdown.
390
+ * Emits event app:shutdown
391
+ * Exits from process after timeout
392
+ * @param {number} timeout=OPT_DEFAULT_SHUTDOWN_TIMEOUT time in ms before exit
393
+ **/
394
+ shutdown(timeout = OPT_DEFAULT_SHUTDOWN_TIMEOUT) {
395
+ this.log(`Перезагрузка сервиса через ${timeout}мс...`);
396
+ this.emit("app:shutdown");
397
+ setTimeout(process.exit, timeout);
398
+ }
399
+
400
+ /**
401
+ * Returns info about whole system.
402
+ * Modules - total count, list, content
403
+ * Routes - total count, list
404
+ * Models - total count, list
405
+ * Actions - total count, list
406
+ * Roles - total count, list
407
+ * @return {Object} complex object with results
408
+ **/
409
+ getStatus() {
410
+ const mods = Object.keys(this.#modules);
411
+ let stats = {
412
+ modules: {
413
+ count: mods.length,
414
+ list: mods,
415
+ content: {},
416
+ },
417
+ routes: {
418
+ count: 0,
419
+ list: [],
420
+ },
421
+ models: {
422
+ count: 0,
423
+ list: [],
424
+ },
425
+ forms: {
426
+ count: 0,
427
+ list: [],
428
+ },
429
+ actions: {
430
+ count: 0,
431
+ list: [],
432
+ },
433
+ roles: {
434
+ count: 0,
435
+ list: [],
436
+ },
437
+ };
438
+ for (let modName in this.#modules) {
439
+ const mod = this.#modules[modName];
440
+ let modStatus = mod.getStatus();
441
+ stats.modules.content[modName] = modStatus;
442
+ stats.routes.count += modStatus.routes.count;
443
+ stats.models.count += modStatus.models.count;
444
+ stats.forms.count += modStatus.forms.count;
445
+ stats.actions.count += modStatus.actions.count;
446
+ for (let t of ["routes", "models", "actions", "forms"]) {
447
+ stats[t].list.push(
448
+ ...modStatus[t].list.map(
449
+ (itmName) => `${modName}//${itmName}`
450
+ )
451
+ );
452
+ }
278
453
  }
279
- }catch(e){
280
- this.report(e);
281
- }
282
- }
283
- }
284
-
285
- /**
286
- * Execute fabricateModels methods on all registered modules
287
- * Create mongoose models.
288
- **/
289
- fabricate() {
290
- for (let mod of Object.values(this.#modules)) {
291
- mod.fabricateModels && mod.fabricateModels();
292
- }
293
- }
294
-
295
- /**
296
- * logger
297
- */
298
- set logger(logger) {
299
- this.#logger = logger;
300
- }
301
-
302
- get logger() {
303
- if (typeof this.#logger !== 'undefined' && this.#logger !== null) {
304
- return this.#logger;
305
- } else {
306
- return console;
307
- }
308
- }
309
-
310
- log() {
311
- this.logger.log(...arguments);
312
- return this;
313
- }
314
-
315
- /**
316
- * reporter - errors
317
- */
318
-
319
- get DEFAULT_REPORTER() {
320
- return {
321
- async report(...params) {
322
- console.error(params);
323
- }
324
- };
325
- }
326
-
327
- set reporter(reporter) {
328
- this.#reporter = reporter;
329
- }
330
-
331
- get reporter() {
332
- return this.#reporter || this.DEFAULT_REPORTER;
333
- }
334
-
335
- report(err) {
336
- this.reporter.report(err).catch(this.logger.error);
337
- }
338
-
339
- /**
340
- * informer - messages
341
- */
342
- get DEFAULT_INFORMER() {
343
- return {
344
- now: console.info
345
- };
346
- }
347
-
348
- set informer(informer /* not-informer.Informer */ ) {
349
- this.#informer = informer;
350
- }
351
-
352
- get informer() {
353
- return this.#informer || this.DEFAULT_INFORMER;
354
- }
355
-
356
- inform(data /* look for not-informer.Informer.now */ ) {
357
- this.informer.now(data);
358
- }
359
-
360
- addWSServer(name, wss) {
361
- this.#wss[name] = wss;
362
- }
363
-
364
- WSServer(name = 'main') {
365
- if (objHas(this.#wss, name)) {
366
- return this.#wss[name];
367
- } else {
368
- return undefined;
369
- }
370
- }
371
-
372
- addWSClient(name, wsc) {
373
- this.#wsc[name] = wsc;
374
- }
375
-
376
- WSClient(name) {
377
- if (objHas(this.#wsc, name)) {
378
- return this.#wsc[name];
379
- } else {
380
- return undefined;
381
- }
382
- }
383
-
384
-
385
- /**
386
- *
387
- * Logging message about shutdown.
388
- * Emits event app:shutdown
389
- * Exits from process after timeout
390
- * @param {number} timeout=OPT_DEFAULT_SHUTDOWN_TIMEOUT time in ms before exit
391
- **/
392
- shutdown(timeout = OPT_DEFAULT_SHUTDOWN_TIMEOUT) {
393
- this.log(`Перезагрузка сервиса через ${timeout}мс...`);
394
- this.emit('app:shutdown');
395
- setTimeout(process.exit, timeout);
396
- }
397
-
398
-
399
- /**
400
- * Returns info about whole system.
401
- * Modules - total count, list, content
402
- * Routes - total count, list
403
- * Models - total count, list
404
- * Actions - total count, list
405
- * Roles - total count, list
406
- * @return {Object} complex object with results
407
- **/
408
- getStatus() {
409
- const mods = Object.keys(this.#modules);
410
- let stats = {
411
- modules: {
412
- count: mods.length,
413
- list: mods,
414
- content: {}
415
- },
416
- routes: {
417
- count: 0,
418
- list: []
419
- },
420
- models: {
421
- count: 0,
422
- list: []
423
- },
424
- forms: {
425
- count: 0,
426
- list: []
427
- },
428
- actions: {
429
- count: 0,
430
- list: []
431
- },
432
- roles: {
433
- count: 0,
434
- list: []
435
- },
436
- };
437
- for (let modName in this.#modules) {
438
- const mod = this.#modules[modName];
439
- let modStatus = mod.getStatus();
440
- stats.modules.content[modName] = modStatus;
441
- stats.routes.count += modStatus.routes.count;
442
- stats.models.count += modStatus.models.count;
443
- stats.forms.count += modStatus.forms.count;
444
- stats.actions.count += modStatus.actions.count;
445
- for (let t of ['routes', 'models', 'actions', 'forms']) {
446
- stats[t].list.push(...(modStatus[t].list.map(itmName => `${modName}//${itmName}`)));
447
- }
448
- }
449
- return stats;
450
- }
451
-
452
- getEnv(key) {
453
- return Env.getEnv(key);
454
- }
455
-
456
- /**
457
- * Setting application environment variable
458
- * @param {string} key name of var
459
- * @param {object} val value
460
- * @return {notDomain} chainable
461
- */
462
- static setEnv(key, val) {
463
- Env.setEnv(key, val);
464
- return this;
465
- }
466
-
467
- getModulesNames(){
468
- return Object.keys(this.#modules);
469
- }
454
+ return stats;
455
+ }
470
456
 
457
+ getEnv(key) {
458
+ return Env.getEnv(key);
459
+ }
460
+
461
+ /**
462
+ * Setting application environment variable
463
+ * @param {string} key name of var
464
+ * @param {object} val value
465
+ * @return {notDomain} chainable
466
+ */
467
+ static setEnv(key, val) {
468
+ Env.setEnv(key, val);
469
+ return this;
470
+ }
471
+
472
+ getModulesNames() {
473
+ return Object.keys(this.#modules);
474
+ }
471
475
  }
472
476
 
473
477
  module.exports = notDomain;