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
@@ -1,30 +1,27 @@
1
- const log = require('not-log')(module, 'not-node//init');
2
- const ADDS = require('./additional');
1
+ const log = require("not-log")(module, "not-node//init");
2
+ const ADDS = require("./additional");
3
3
 
4
- module.exports = class InitMiddleware{
5
-
6
- async run({config, options, master}) {
7
- log.info('Setting up middlewares...');
8
- await ADDS.run('middleware.pre', {config, options, master});
9
- const input = config.get('middleware');
10
- if (input) {
11
- for (let ware in input) {
12
- let warePath = input[ware].path || ware,
13
- proc;
14
- if (require(warePath).getMiddleware) {
15
- proc = require(warePath).getMiddleware(input[ware]);
16
- } else if (require(warePath).middleware) {
17
- proc = require(warePath).middleware;
18
- } else {
19
- proc = require(warePath);
20
- }
21
- if(typeof proc === 'function'){
22
- master.getServer().use(proc);
4
+ module.exports = class InitMiddleware {
5
+ async run({ config, options, master }) {
6
+ log.info("Setting up middlewares...");
7
+ await ADDS.run("middleware.pre", { config, options, master });
8
+ const input = config.get("middleware");
9
+ if (input) {
10
+ for (let ware in input) {
11
+ let warePath = input[ware].path || ware,
12
+ proc;
13
+ if (require(warePath).getMiddleware) {
14
+ proc = require(warePath).getMiddleware(input[ware]);
15
+ } else if (require(warePath).middleware) {
16
+ proc = require(warePath).middleware;
17
+ } else {
18
+ proc = require(warePath);
19
+ }
20
+ if (typeof proc === "function") {
21
+ master.getServer().use(proc);
22
+ }
23
+ }
23
24
  }
24
- }
25
+ await ADDS.run("middleware.post", { config, options, master });
25
26
  }
26
- await ADDS.run('middleware.post', {config, options, master});
27
- }
28
-
29
-
30
27
  };
@@ -1,5 +1,5 @@
1
- module.exports = class InitModules{
2
- async run({master}) {
3
- master.getApp().execInModules('initialize');
4
- }
1
+ module.exports = class InitModules {
2
+ async run({ master }) {
3
+ master.getApp().execInModules("initialize");
4
+ }
5
5
  };
@@ -1,11 +1,11 @@
1
- const Log = require('not-log')(module, 'not-node//init');
1
+ const Log = require("not-log")(module, "not-node//init");
2
2
 
3
3
  module.exports = class InitMonitoring {
4
- async run() {
5
- const monitor = require('not-monitor').monitor;
6
- monitor.on('afterReportError', (err) => {
7
- Log.error('Report error', err.message);
8
- });
9
- Log.log('Development monitor initialized');
10
- }
4
+ async run() {
5
+ const monitor = require("not-monitor").monitor;
6
+ monitor.on("afterReportError", (err) => {
7
+ Log.error("Report error", err.message);
8
+ });
9
+ Log.log("Development monitor initialized");
10
+ }
11
11
  };
@@ -1,51 +1,59 @@
1
- const emit = require('./additional').run;
2
- const log = require('not-log')(module, 'RateLimiter');
3
- const {partCopyObj} = require('../common');
1
+ const emit = require("./additional").run;
2
+ const log = require("not-log")(module, "RateLimiter");
3
+ const { partCopyObj } = require("../common");
4
4
 
5
5
  const DEFAULT_OPTIONS = {
6
- keyPrefix: 'rateLimiterMiddleware',
7
- points: 20,
8
- duration: 1
6
+ keyPrefix: "rateLimiterMiddleware",
7
+ points: 20,
8
+ duration: 1,
9
9
  };
10
10
 
11
- const DEFAULT_CLIENT = 'ioredis';
12
-
13
- module.exports = class InitRateLimiter{
14
-
15
- static createMiddleware({rateLimiter}){
16
- return (req, res, next) => {
17
- rateLimiter.consume(req.ip)
18
- .then(() => next())
19
- .catch(() => {
20
- log.error('Too many requests by ' + req.ip);
21
- res.status(429).send('Too Many Requests');
11
+ const DEFAULT_CLIENT = "ioredis";
12
+
13
+ module.exports = class InitRateLimiter {
14
+ static createMiddleware({ rateLimiter }) {
15
+ return (req, res, next) => {
16
+ rateLimiter
17
+ .consume(req.ip)
18
+ .then(() => next())
19
+ .catch(() => {
20
+ log.error("Too many requests by " + req.ip);
21
+ res.status(429).send("Too Many Requests");
22
+ });
23
+ };
24
+ }
25
+
26
+ async run({ config, master }) {
27
+ await emit("rateLimiter.pre", { config, master });
28
+ const rateLimiter = InitRateLimiter.createRateLimiter({
29
+ config,
30
+ master,
22
31
  });
23
- };
24
- }
25
-
26
- async run({config, master}){
27
- await emit('rateLimiter.pre', { config, master});
28
- const rateLimiter = InitRateLimiter.createRateLimiter({config, master});
29
- const middleware = InitRateLimiter.createMiddleware({rateLimiter});
30
- master.getServer().use(middleware);
31
- await emit('rateLimiter.post', { config, master});
32
- }
33
-
34
-
35
- static getOptions({config}){
36
- const opts = partCopyObj(config.get('modules.rateLimiter', {}), Object.keys(DEFAULT_OPTIONS));
37
- return {
38
- ...DEFAULT_OPTIONS,
39
- ...opts
40
- };
41
- }
42
-
43
- static createRateLimiter({master, config}){
44
- const {RateLimiterRedis} = require('rate-limiter-flexible');
45
- const storeClient = config.get('modules.rateLimiter.client', DEFAULT_CLIENT);
46
- return new RateLimiterRedis({
47
- storeClient: master.getEnv(`db.${storeClient}`),
48
- ...InitRateLimiter.getOptions({master, config})
49
- });
50
- }
32
+ const middleware = InitRateLimiter.createMiddleware({ rateLimiter });
33
+ master.getServer().use(middleware);
34
+ await emit("rateLimiter.post", { config, master });
35
+ }
36
+
37
+ static getOptions({ config }) {
38
+ const opts = partCopyObj(
39
+ config.get("modules.rateLimiter", {}),
40
+ Object.keys(DEFAULT_OPTIONS)
41
+ );
42
+ return {
43
+ ...DEFAULT_OPTIONS,
44
+ ...opts,
45
+ };
46
+ }
47
+
48
+ static createRateLimiter({ master, config }) {
49
+ const { RateLimiterRedis } = require("rate-limiter-flexible");
50
+ const storeClient = config.get(
51
+ "modules.rateLimiter.client",
52
+ DEFAULT_CLIENT
53
+ );
54
+ return new RateLimiterRedis({
55
+ storeClient: master.getEnv(`db.${storeClient}`),
56
+ ...InitRateLimiter.getOptions({ master, config }),
57
+ });
58
+ }
51
59
  };
@@ -1,74 +1,72 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- const serveStatic = require('serve-static');
4
- const log = require('not-log')(module, 'not-node//init');
5
- const {
6
- notError,
7
- notValidationError,
8
- notRequestError
9
- } = require('not-error');
3
+ const serveStatic = require("serve-static");
4
+ const log = require("not-log")(module, "not-node//init");
5
+ const { notError, notValidationError, notRequestError } = require("not-error");
10
6
 
11
7
  module.exports = class InitRoutes {
8
+ static finalError({ master }) {
9
+ return (err, req, res, next) => {
10
+ //reportable errors from known cases
11
+ if (err instanceof notError) {
12
+ master.getApp().report(err);
13
+ //if request params - ok, but result is not
14
+ if (err instanceof notRequestError) {
15
+ if (err.getRedirect()) {
16
+ return res.redirect(err.getRedirect());
17
+ } else {
18
+ return res.status(err.getCode()).json({
19
+ status: "error",
20
+ message: err.getResult().message,
21
+ errors: err.getResult().errors,
22
+ });
23
+ }
24
+ //bad request params
25
+ } else if (err instanceof notValidationError) {
26
+ return res.status(400).json({
27
+ status: "error",
28
+ message: err.message,
29
+ errors: err.getFieldsErrors(),
30
+ });
31
+ }
32
+ }
33
+ //other cases
34
+ if (err instanceof Error && res && res.status && res.json) {
35
+ res.status(err.statusCode || 500);
36
+ //reporting as unknown
37
+ master
38
+ .getApp()
39
+ .report(
40
+ new notError(
41
+ `Internal error(${res.statusCode}): %${req.url} - %${err.message}`,
42
+ {},
43
+ err
44
+ )
45
+ );
46
+ res.json({
47
+ status: "error",
48
+ message: err.message,
49
+ });
50
+ } else {
51
+ log.error("Unknown error:", err);
52
+ res.status(500).json({
53
+ status: "error",
54
+ });
55
+ }
56
+ next();
57
+ };
58
+ }
12
59
 
13
- static finalError({
14
- master
15
- }) {
16
- return (err, req, res, next) => {
17
- //reportable errors from known cases
18
- if (err instanceof notError) {
19
- master.getApp().report(err);
20
- //if request params - ok, but result is not
21
- if (err instanceof notRequestError) {
22
- if (err.getRedirect()) {
23
- return res.redirect(err.getRedirect());
24
- } else {
25
- return res.status(err.getCode()).json({
26
- status: 'error',
27
- message: err.getResult().message,
28
- errors: err.getResult().errors
29
- });
30
- }
31
- //bad request params
32
- }else if (err instanceof notValidationError){
33
- return res.status(400).json({
34
- status: 'error',
35
- message: err.message,
36
- errors: err.getFieldsErrors()
37
- });
38
- }
39
- }
40
- //other cases
41
- if (err instanceof Error && (res && res.status && res.json)) {
42
- res.status(err.statusCode || 500);
43
- //reporting as unknown
44
- master.getApp().report(new notError(`Internal error(${res.statusCode}): %${req.url} - %${err.message}`, {}, err));
45
- res.json({
46
- status: 'error',
47
- message: err.message
48
- });
49
- } else {
50
- log.error('Unknown error:', err);
51
- res.status(500).json({
52
- status: 'error'
53
- });
54
- }
55
- next();
56
- };
57
- }
58
-
59
- async run({
60
- master,
61
- config,
62
- options
63
- }) {
64
- log.info('Setting up routes...');
65
- master.getApp().expose(master.getServer());
66
- require(options.routesPath)(master.getServer(), master.getApp());
67
- master.getServer().use(serveStatic(config.get('staticPath')));
68
- master.getServer().use(options.indexRoute);
69
- master.getServer().use(InitRoutes.finalError({
70
- master
71
- }));
72
- }
73
-
60
+ async run({ master, config, options }) {
61
+ log.info("Setting up routes...");
62
+ master.getApp().expose(master.getServer());
63
+ require(options.routesPath)(master.getServer(), master.getApp());
64
+ master.getServer().use(serveStatic(config.get("staticPath")));
65
+ master.getServer().use(options.indexRoute);
66
+ master.getServer().use(
67
+ InitRoutes.finalError({
68
+ master,
69
+ })
70
+ );
71
+ }
74
72
  };
@@ -1,38 +1,42 @@
1
- const Log = require('not-log')(module, 'not-node//init');
1
+ const Log = require("not-log")(module, "not-node//init");
2
2
 
3
- module.exports = class InitSecurity{
4
- getCSPDirectives({config}){
5
- try {
6
- let corsArr = config.get('cors');
7
- let corsLine = (corsArr ? corsArr.join(' ') : '');
8
- let CSPDirectives = config.get('CSP');
9
- let result = {};
10
- Object.keys(CSPDirectives).forEach((nm) => {
11
- result[nm + 'Src'] = CSPDirectives[nm].join(' ');
12
- if (['default', 'connect'].includes(nm)) {
13
- result[nm + 'Src'] += (' ' + corsLine);
3
+ module.exports = class InitSecurity {
4
+ getCSPDirectives({ config }) {
5
+ try {
6
+ let corsArr = config.get("cors");
7
+ let corsLine = corsArr ? corsArr.join(" ") : "";
8
+ let CSPDirectives = config.get("CSP");
9
+ let result = {};
10
+ Object.keys(CSPDirectives).forEach((nm) => {
11
+ result[nm + "Src"] = CSPDirectives[nm].join(" ");
12
+ if (["default", "connect"].includes(nm)) {
13
+ result[nm + "Src"] += " " + corsLine;
14
+ }
15
+ });
16
+ return result;
17
+ } catch (e) {
18
+ Log.error(e);
19
+ return {};
14
20
  }
15
- });
16
- return result;
17
- } catch (e) {
18
- Log.error(e);
19
- return {};
20
21
  }
21
- }
22
22
 
23
- async run({master, config, options}){
24
- //adding protection
25
- const helmet = require('helmet');
26
- const CSPDirectives = this.getCSPDirectives({options, config, master});
27
- master.getServer().use(
28
- helmet({
29
- contentSecurityPolicy: {
30
- directives: {
31
- ...CSPDirectives,
32
- upgradeInsecureRequests: [],
33
- }
34
- }
35
- })
36
- );
37
- }
23
+ async run({ master, config, options }) {
24
+ //adding protection
25
+ const helmet = require("helmet");
26
+ const CSPDirectives = this.getCSPDirectives({
27
+ options,
28
+ config,
29
+ master,
30
+ });
31
+ master.getServer().use(
32
+ helmet({
33
+ contentSecurityPolicy: {
34
+ directives: {
35
+ ...CSPDirectives,
36
+ upgradeInsecureRequests: [],
37
+ },
38
+ },
39
+ })
40
+ );
41
+ }
38
42
  };
@@ -1,121 +1,125 @@
1
- const Log = require('not-log')(module, 'InitSequence');
2
- const {objHas} = require('../common');
1
+ const Log = require("not-log")(module, "InitSequence");
2
+ const { objHas } = require("../common");
3
3
 
4
4
  /**
5
- * Initialization sequence manipulations
6
- * Holds list of initalizers and manages em adds/removes
7
- **/
8
- module.exports = class InitSequence{
9
- constructor(list = []){
10
- this.list = [...list];
11
- }
12
- /**
13
- * Insert initalizator after and before specified modules or at the end
14
- * @param {Object} what initializator class constructor
15
- * @param {Object} where specification where to insert
16
- * @param {Array.String} where.after list of constructor names of
17
- * initalizators after which item should be inserted
18
- * @param {Array.String} where.before list of constructor names of
19
- * initalizators before which item should be inserted
20
- **/
21
- insert(what, where = {}){
22
- if(where && this.list.length > 0){
23
- let start = -1, end = this.list.length;
24
- if(objHas(where, 'after')){
25
- start = this.highestPos(where.after);
26
- }
27
- if(objHas(where, 'before')){
28
- end = this.lowestPos(where.before);
29
- }
30
- if(start > end){
31
- throw new Error('Insertion of initalization module impossible: ' + what.prototype.constructor.name);
32
- }
33
- if(start > -1){
34
- this.list.splice(start + 1, 0, what);
35
- }else if(end < this.list.length){
36
- this.list.splice(end, 0, what);
37
- }else{
38
- this.list.push(what);
39
- }
40
- }else{
41
- this.list.push(what);
5
+ * Initialization sequence manipulations
6
+ * Holds list of initalizers and manages em adds/removes
7
+ **/
8
+ module.exports = class InitSequence {
9
+ constructor(list = []) {
10
+ this.list = [...list];
42
11
  }
43
- }
44
-
45
- /**
46
- * Removing item and optionally adding few on place of removed
47
- * @param {string} rem name of class of initalizator to remove
48
- * @param {Array.Constructor} add list of class constructors
49
- **/
50
- remove(rem, add = []){
51
- const index = this.pos(rem);
52
- if(index > -1){
53
- this.list.splice(index, 1, ...add);
12
+ /**
13
+ * Insert initalizator after and before specified modules or at the end
14
+ * @param {Object} what initializator class constructor
15
+ * @param {Object} where specification where to insert
16
+ * @param {Array.String} where.after list of constructor names of
17
+ * initalizators after which item should be inserted
18
+ * @param {Array.String} where.before list of constructor names of
19
+ * initalizators before which item should be inserted
20
+ **/
21
+ insert(what, where = {}) {
22
+ if (where && this.list.length > 0) {
23
+ let start = -1,
24
+ end = this.list.length;
25
+ if (objHas(where, "after")) {
26
+ start = this.highestPos(where.after);
27
+ }
28
+ if (objHas(where, "before")) {
29
+ end = this.lowestPos(where.before);
30
+ }
31
+ if (start > end) {
32
+ throw new Error(
33
+ "Insertion of initalization module impossible: " +
34
+ what.prototype.constructor.name
35
+ );
36
+ }
37
+ if (start > -1) {
38
+ this.list.splice(start + 1, 0, what);
39
+ } else if (end < this.list.length) {
40
+ this.list.splice(end, 0, what);
41
+ } else {
42
+ this.list.push(what);
43
+ }
44
+ } else {
45
+ this.list.push(what);
46
+ }
54
47
  }
55
- }
56
-
57
48
 
58
- /**
59
- * Replacing existing item or if item is not exists in list
60
- * then inserting items accroding to where instruction
61
- * @param {string} whatRemove name of class of initalizator to remove
62
- * @param {Array.Constructor} whatInsert list of class constructors
63
- * @param {Object} where specification where to insert
64
- * @param {Array.String} where.after list of constructor names of
65
- * initalizators after which item should be inserted
66
- * @param {Array.String} where.before list of constructor names of
67
- * initalizators before which item should be inserted
68
- **/
69
- replace(whatRemove, whatInsert = [], where = {}){
70
- const pos = this.pos(whatRemove);
71
- if(pos > -1){//if what is presented, we replace
72
- this.remove(whatRemove, whatInsert);
73
- }else{
74
- //else, use where to position insertion
75
- this.insert(whatInsert, where);
49
+ /**
50
+ * Removing item and optionally adding few on place of removed
51
+ * @param {string} rem name of class of initalizator to remove
52
+ * @param {Array.Constructor} add list of class constructors
53
+ **/
54
+ remove(rem, add = []) {
55
+ const index = this.pos(rem);
56
+ if (index > -1) {
57
+ this.list.splice(index, 1, ...add);
58
+ }
76
59
  }
77
- }
78
60
 
79
- pos(what){
80
- return this.list.findIndex((val)=>{
81
- return val.prototype.constructor.name === what;
82
- });
83
- }
61
+ /**
62
+ * Replacing existing item or if item is not exists in list
63
+ * then inserting items accroding to where instruction
64
+ * @param {string} whatRemove name of class of initalizator to remove
65
+ * @param {Array.Constructor} whatInsert list of class constructors
66
+ * @param {Object} where specification where to insert
67
+ * @param {Array.String} where.after list of constructor names of
68
+ * initalizators after which item should be inserted
69
+ * @param {Array.String} where.before list of constructor names of
70
+ * initalizators before which item should be inserted
71
+ **/
72
+ replace(whatRemove, whatInsert = [], where = {}) {
73
+ const pos = this.pos(whatRemove);
74
+ if (pos > -1) {
75
+ //if what is presented, we replace
76
+ this.remove(whatRemove, whatInsert);
77
+ } else {
78
+ //else, use where to position insertion
79
+ this.insert(whatInsert, where);
80
+ }
81
+ }
84
82
 
83
+ pos(what) {
84
+ return this.list.findIndex((val) => {
85
+ return val.prototype.constructor.name === what;
86
+ });
87
+ }
85
88
 
86
- highestPos(whats){
87
- return whats.reduce((prev/*number*/, cur /*string*/)=>{
88
- const index = this.pos(cur);
89
- if(index > prev){
90
- return index;
91
- }else{
92
- return prev;
93
- }
94
- }, -1);
95
- }
89
+ highestPos(whats) {
90
+ return whats.reduce((prev /*number*/, cur /*string*/) => {
91
+ const index = this.pos(cur);
92
+ if (index > prev) {
93
+ return index;
94
+ } else {
95
+ return prev;
96
+ }
97
+ }, -1);
98
+ }
96
99
 
97
- lowestPos(whats){
98
- return whats.reduce((prev/*number*/, cur /*string*/)=>{
99
- const index = this.pos(cur);
100
- if((index > -1) && (index < prev)){
101
- return index;
102
- }else{
103
- return prev;
104
- }
105
- }, this.list.length);
106
- }
100
+ lowestPos(whats) {
101
+ return whats.reduce((prev /*number*/, cur /*string*/) => {
102
+ const index = this.pos(cur);
103
+ if (index > -1 && index < prev) {
104
+ return index;
105
+ } else {
106
+ return prev;
107
+ }
108
+ }, this.list.length);
109
+ }
107
110
 
108
- async run(context){
109
- for(let Step of this.list){
110
- try{
111
- if(Step && Step.prototype && Step.prototype.constructor){
112
- await ((new Step()).run({...context}));
111
+ async run(context) {
112
+ for (let Step of this.list) {
113
+ try {
114
+ if (Step && Step.prototype && Step.prototype.constructor) {
115
+ await new Step().run({ ...context });
116
+ }
117
+ } catch (e) {
118
+ Log.error(
119
+ `Initalization step failed, initializator class name: '${Step.prototype.constructor.name}'`
120
+ );
121
+ Log.error(e);
122
+ }
113
123
  }
114
- }catch(e){
115
- Log.error(`Initalization step failed, initializator class name: '${Step.prototype.constructor.name}'`);
116
- Log.error(e);
117
- }
118
124
  }
119
- }
120
-
121
125
  };