not-node 5.0.19 → 5.1.0

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 (128) hide show
  1. package/.eslintrc.json +1 -1
  2. package/bin/not-deploy.js +52 -0
  3. package/error.format +11 -0
  4. package/index.js +22 -18
  5. package/package.json +1 -1
  6. package/src/app.js +61 -58
  7. package/src/auth/abstract.js +17 -19
  8. package/src/auth/const.js +8 -12
  9. package/src/auth/fields.js +143 -124
  10. package/src/auth/index.js +14 -14
  11. package/src/auth/roles.js +64 -63
  12. package/src/auth/routes.js +89 -54
  13. package/src/auth/rules.js +63 -63
  14. package/src/auth/session.js +60 -62
  15. package/src/bootstrap/form.js +18 -0
  16. package/src/bootstrap/index.js +11 -0
  17. package/src/bootstrap/logic.js +50 -0
  18. package/src/bootstrap/model.js +15 -0
  19. package/src/bootstrap/route.js +139 -0
  20. package/src/common.js +86 -79
  21. package/src/core/fields/ID.js +6 -6
  22. package/src/core/fields/__closed.js +3 -3
  23. package/src/core/fields/__latest.js +3 -3
  24. package/src/core/fields/__version.js +3 -3
  25. package/src/core/fields/__versions.js +3 -3
  26. package/src/core/fields/_id.js +6 -6
  27. package/src/core/fields/active.js +9 -9
  28. package/src/core/fields/codeName.js +9 -9
  29. package/src/core/fields/createdAt.js +17 -17
  30. package/src/core/fields/default.js +9 -9
  31. package/src/core/fields/description.js +11 -11
  32. package/src/core/fields/email.js +9 -9
  33. package/src/core/fields/enabled.js +9 -9
  34. package/src/core/fields/expiredAt.js +16 -16
  35. package/src/core/fields/height.js +11 -11
  36. package/src/core/fields/ip.js +10 -10
  37. package/src/core/fields/objectId.js +10 -10
  38. package/src/core/fields/owner.js +13 -13
  39. package/src/core/fields/ownerModel.js +11 -11
  40. package/src/core/fields/price.js +11 -11
  41. package/src/core/fields/requiredObject.js +10 -10
  42. package/src/core/fields/session.js +10 -10
  43. package/src/core/fields/size.js +11 -11
  44. package/src/core/fields/telephone.js +9 -9
  45. package/src/core/fields/title.js +15 -15
  46. package/src/core/fields/updatedAt.js +17 -17
  47. package/src/core/fields/userId.js +11 -12
  48. package/src/core/fields/uuid.js +11 -11
  49. package/src/core/fields/validators/email.js +6 -4
  50. package/src/core/fields/validators/owner.js +6 -4
  51. package/src/core/fields/width.js +11 -11
  52. package/src/domain.js +435 -431
  53. package/src/env.js +23 -23
  54. package/src/error.js +20 -23
  55. package/src/exceptions/db.js +23 -0
  56. package/src/exceptions/http.js +43 -0
  57. package/src/fields/index.js +139 -121
  58. package/src/form/fabric.js +19 -24
  59. package/src/form/form.js +195 -186
  60. package/src/form/index.js +2 -2
  61. package/src/generic/index.js +2 -0
  62. package/src/generic/logic.js +595 -0
  63. package/src/generic/route.js +76 -0
  64. package/src/getApp.js +2 -0
  65. package/src/init/additional.js +7 -7
  66. package/src/init/app.js +75 -68
  67. package/src/init/bodyparser.js +14 -14
  68. package/src/init/compression.js +6 -7
  69. package/src/init/core.js +12 -12
  70. package/src/init/cors.js +22 -24
  71. package/src/init/db/index.js +41 -43
  72. package/src/init/db/ioredis.js +28 -20
  73. package/src/init/db/mongoose.js +42 -32
  74. package/src/init/db/redis.js +59 -48
  75. package/src/init/env.js +44 -36
  76. package/src/init/express.js +18 -21
  77. package/src/init/fileupload.js +8 -10
  78. package/src/init/http.js +65 -47
  79. package/src/init/index.js +141 -148
  80. package/src/init/informer.js +7 -9
  81. package/src/init/methodoverride.js +4 -6
  82. package/src/init/middleware.js +23 -26
  83. package/src/init/modules.js +4 -4
  84. package/src/init/monitoring.js +8 -8
  85. package/src/init/rateLimiter.js +53 -45
  86. package/src/init/routes.js +67 -69
  87. package/src/init/security.js +37 -33
  88. package/src/init/sequence.js +111 -107
  89. package/src/init/sequence.standart.js +54 -56
  90. package/src/init/sessions/index.js +21 -21
  91. package/src/init/sessions/mongoose.js +49 -36
  92. package/src/init/sessions/redis.js +28 -27
  93. package/src/init/static.js +53 -40
  94. package/src/init/template.js +17 -17
  95. package/src/lib.js +230 -200
  96. package/src/manifest/batchRunner.js +26 -25
  97. package/src/manifest/initializator/forms.js +24 -24
  98. package/src/manifest/initializator/index.js +8 -10
  99. package/src/manifest/initializator/manifests.js +45 -42
  100. package/src/manifest/initializator/models.js +37 -34
  101. package/src/manifest/manifest.filter.js +130 -97
  102. package/src/manifest/manifest.js +103 -77
  103. package/src/manifest/module.js +350 -360
  104. package/src/manifest/registrator/fields.js +90 -85
  105. package/src/manifest/registrator/forms.js +47 -47
  106. package/src/manifest/registrator/index.js +14 -16
  107. package/src/manifest/registrator/locales.js +17 -16
  108. package/src/manifest/registrator/logics.js +66 -64
  109. package/src/manifest/registrator/models.js +64 -62
  110. package/src/manifest/registrator/routes.js +171 -132
  111. package/src/manifest/registrator/routes.ws.js +109 -103
  112. package/src/manifest/route.js +216 -161
  113. package/src/model/buildValidator.js +53 -42
  114. package/src/model/default.js +304 -286
  115. package/src/model/enrich.js +69 -61
  116. package/src/model/increment.js +124 -137
  117. package/src/model/proto.js +179 -148
  118. package/src/model/routine.js +85 -76
  119. package/src/model/utils.js +33 -0
  120. package/src/model/versioning.js +148 -124
  121. package/src/obsolete.js +12 -8
  122. package/src/parser.js +29 -22
  123. package/src/repos.js +29 -31
  124. package/src/rollup.js +75 -65
  125. package/src/shell.helpers.js +28 -28
  126. package/static.js +31 -0
  127. package/src/manifest/module.models.js +0 -0
  128. package/src/manifest/module.status.js +0 -0
@@ -1,98 +1,103 @@
1
- const path = require('path');
2
- const fs = require('fs');
3
- const {tryFile, objHas} = require('../../common');
4
- const Fields = require('../../fields');
5
- const {log} = require('not-log')(module, 'registrator');
1
+ const path = require("path");
2
+ const fs = require("fs");
3
+ const { tryFile, objHas } = require("../../common");
4
+ const Fields = require("../../fields");
6
5
 
7
- module.exports = class notModuleRegistratorFields{
6
+ module.exports = class notModuleRegistratorFields {
7
+ static openFile = require;
8
+ static fieldsManager = Fields;
8
9
 
9
- static openFile = require;
10
- static fieldsManager = Fields;
11
-
12
- constructor({nModule}){
13
- this.run({nModule});
14
- }
15
-
16
- run({nModule}){
17
- const srcDir = notModuleRegistratorFields.getPath(nModule);
18
- if (!srcDir) { return false; }
19
- this.findAll(
20
- {
21
- nModule,
22
- srcDir
23
- }
24
- );
25
- return true;
26
- }
10
+ constructor({ nModule }) {
11
+ this.run({ nModule });
12
+ }
27
13
 
28
- static getPath(nModule){
29
- return nModule.module.paths.fields;
30
- }
14
+ run({ nModule }) {
15
+ const srcDir = notModuleRegistratorFields.getPath(nModule);
16
+ if (!srcDir) {
17
+ return false;
18
+ }
19
+ this.findAll({
20
+ nModule,
21
+ srcDir,
22
+ });
23
+ return true;
24
+ }
31
25
 
32
- registerFields({ nModule, lib, fromPath}){
33
- for(let t in lib){
34
- this.registerField({
35
- nModule,
36
- name: t,
37
- field: lib[t],
38
- fromPath
39
- });
26
+ static getPath(nModule) {
27
+ return nModule.module.paths.fields;
40
28
  }
41
- }
42
29
 
43
- registerField({nModule, name, field, fromPath}){
44
- this.extendByFrontValidators({name, field, fromPath});
45
- nModule.setField(name, field);
46
- //log(`${nModule.getName()}//${name}`);
47
- }
30
+ registerFields({ nModule, lib, fromPath }) {
31
+ for (let t in lib) {
32
+ this.registerField({
33
+ nModule,
34
+ name: t,
35
+ field: lib[t],
36
+ fromPath,
37
+ });
38
+ }
39
+ }
48
40
 
49
- /**
50
- *
51
- **/
52
- extendByFrontValidators({name, field, fromPath}){
53
- if(!(field && objHas(field, 'model'))){ return; }
54
- //load validators
55
- const validatorName = path.join(fromPath, 'validators', name + '.js');
56
- if(!tryFile(validatorName)){ return; }
57
- const validators = notModuleRegistratorFields.openFile(validatorName);
58
- //inject into field.model
59
- if(!objHas(field.model, 'validate')){
60
- field.model.validate = [];
41
+ registerField({ nModule, name, field, fromPath }) {
42
+ this.extendByFrontValidators({ name, field, fromPath });
43
+ nModule.setField(name, field);
44
+ //log(`${nModule.getName()}//${name}`);
61
45
  }
62
- field.model.validate.push(...validators);
63
- }
64
46
 
65
- /**
66
- * Searching fields in directory
67
- * @param {Object} input
68
- * @param {notModule} input.notModule
69
- * @param {string} input.srcDir
70
- **/
71
- findAll({nModule, srcDir}){
72
- fs.readdirSync(srcDir).forEach((file) => {
73
- let fromPath = path.join(srcDir, file);
74
- if (!tryFile(fromPath)) { return; }
75
- this.register({nModule, fromPath});
76
- });
77
- }
47
+ /**
48
+ *
49
+ **/
50
+ extendByFrontValidators({ name, field, fromPath }) {
51
+ if (!(field && objHas(field, "model"))) {
52
+ return;
53
+ }
54
+ //load validators
55
+ const validatorName = path.join(fromPath, "validators", name + ".js");
56
+ if (!tryFile(validatorName)) {
57
+ return;
58
+ }
59
+ const validators = notModuleRegistratorFields.openFile(validatorName);
60
+ //inject into field.model
61
+ if (!objHas(field.model, "validate")) {
62
+ field.model.validate = [];
63
+ }
64
+ field.model.validate.push(...validators);
65
+ }
78
66
 
79
- register({nModule, fromPath}){
80
- let fields = notModuleRegistratorFields.openFile(fromPath);
81
- if (fields && objHas(fields, 'FIELDS')) {//collection
82
- this.registerFields({
83
- nModule,
84
- lib: fields.FIELDS, //fields dictionary
85
- fromPath
86
- });
87
- } else {//single file fieldname.js
88
- const parts = path.parse(fromPath);
89
- this.registerField({
90
- nModule,
91
- name: parts.name, //fields name
92
- field: fields, //field description
93
- fromPath
94
- });
67
+ /**
68
+ * Searching fields in directory
69
+ * @param {Object} input
70
+ * @param {notModule} input.notModule
71
+ * @param {string} input.srcDir
72
+ **/
73
+ findAll({ nModule, srcDir }) {
74
+ fs.readdirSync(srcDir).forEach((file) => {
75
+ let fromPath = path.join(srcDir, file);
76
+ if (!tryFile(fromPath)) {
77
+ return;
78
+ }
79
+ this.register({ nModule, fromPath });
80
+ });
95
81
  }
96
- }
97
82
 
83
+ register({ nModule, fromPath }) {
84
+ let fields = notModuleRegistratorFields.openFile(fromPath);
85
+ if (fields && objHas(fields, "FIELDS")) {
86
+ //collection
87
+ this.registerFields({
88
+ nModule,
89
+ lib: fields.FIELDS, //fields dictionary
90
+ fromPath,
91
+ });
92
+ } else {
93
+ //single file fieldname.js
94
+ const parts = path.parse(fromPath);
95
+ this.registerField({
96
+ nModule,
97
+ name: parts.name, //fields name
98
+ field: fields, //field description
99
+ fromPath,
100
+ });
101
+ }
102
+ }
98
103
  };
@@ -1,48 +1,48 @@
1
- const path = require('path');
2
- const fs = require('fs');
3
- const {tryFile} = require('../../common');
4
-
5
- module.exports = class notModuleRegistratorForms{
6
-
7
- static openFile = require;
8
-
9
- constructor({nModule}){
10
- this.run({nModule});
11
- }
12
-
13
- run({nModule}){
14
- const srcDir = notModuleRegistratorForms.getPath(nModule);
15
- if (!srcDir) { return false; }
16
- this.findAll(
17
- {
18
- nModule,
19
- srcDir
20
- }
21
- );
22
- return true;
23
- }
24
-
25
- static getPath(nModule){
26
- return nModule.module.paths.forms;
27
- }
28
-
29
- /**
30
- * Searching forms in directory
31
- * @param {Object} input
32
- * @param {string} input.srcDir
33
- **/
34
- findAll({nModule, srcDir}){
35
- fs.readdirSync(srcDir).forEach((file) => {
36
- let fromPath = path.join(srcDir, file);
37
- if (!tryFile(fromPath)) { return; }
38
- this.register({nModule, fromPath});
39
- });
40
- }
41
-
42
- register({nModule, fromPath}){
43
- const Form = notModuleRegistratorForms.openFile(fromPath);
44
- const parts = path.parse(fromPath);
45
- nModule.setFormConstructor(parts.name, Form);
46
- }
47
-
1
+ const path = require("path");
2
+ const fs = require("fs");
3
+ const { tryFile } = require("../../common");
4
+
5
+ module.exports = class notModuleRegistratorForms {
6
+ static openFile = require;
7
+
8
+ constructor({ nModule }) {
9
+ this.run({ nModule });
10
+ }
11
+
12
+ run({ nModule }) {
13
+ const srcDir = notModuleRegistratorForms.getPath(nModule);
14
+ if (!srcDir) {
15
+ return false;
16
+ }
17
+ this.findAll({
18
+ nModule,
19
+ srcDir,
20
+ });
21
+ return true;
22
+ }
23
+
24
+ static getPath(nModule) {
25
+ return nModule.module.paths.forms;
26
+ }
27
+
28
+ /**
29
+ * Searching forms in directory
30
+ * @param {Object} input
31
+ * @param {string} input.srcDir
32
+ **/
33
+ findAll({ nModule, srcDir }) {
34
+ fs.readdirSync(srcDir).forEach((file) => {
35
+ let fromPath = path.join(srcDir, file);
36
+ if (!tryFile(fromPath)) {
37
+ return;
38
+ }
39
+ this.register({ nModule, fromPath });
40
+ });
41
+ }
42
+
43
+ register({ nModule, fromPath }) {
44
+ const Form = notModuleRegistratorForms.openFile(fromPath);
45
+ const parts = path.parse(fromPath);
46
+ nModule.setFormConstructor(parts.name, Form);
47
+ }
48
48
  };
@@ -1,30 +1,28 @@
1
- const BatchRunner = require('../batchRunner.js');
1
+ const BatchRunner = require("../batchRunner.js");
2
2
 
3
3
  /**
4
4
  * Logic to find and register resources of notModule
5
5
  * @module notModuleRegistrator
6
6
  **/
7
7
 
8
- const
9
- notModuleRegistratorFields = require('./fields'),
10
- notModuleRegistratorForms = require('./forms'),
11
- notModuleRegistratorModels = require('./models'),
12
- notModuleRegistratorLogics = require('./logics'),
13
- notModuleRegistratorRoutes = require('./routes'),
14
- notModuleRegistratorLocales = require('./locales');
15
-
8
+ const notModuleRegistratorFields = require("./fields"),
9
+ notModuleRegistratorForms = require("./forms"),
10
+ notModuleRegistratorModels = require("./models"),
11
+ notModuleRegistratorLogics = require("./logics"),
12
+ notModuleRegistratorRoutes = require("./routes"),
13
+ notModuleRegistratorLocales = require("./locales");
16
14
 
17
15
  const DEFAULT_REGISTRATORS = [
18
- notModuleRegistratorFields,
19
- notModuleRegistratorForms,
20
- notModuleRegistratorModels,
21
- notModuleRegistratorLogics,
22
- notModuleRegistratorRoutes,
23
- notModuleRegistratorLocales
16
+ notModuleRegistratorFields,
17
+ notModuleRegistratorForms,
18
+ notModuleRegistratorModels,
19
+ notModuleRegistratorLogics,
20
+ notModuleRegistratorRoutes,
21
+ notModuleRegistratorLocales,
24
22
  ];
25
23
 
26
24
  /**
27
25
  * Search and register notModule resouces
28
26
  * @class
29
27
  **/
30
- module.exports = new BatchRunner(DEFAULT_REGISTRATORS);
28
+ module.exports = new BatchRunner(DEFAULT_REGISTRATORS);
@@ -1,20 +1,21 @@
1
- const log = require('not-log')(module, 'registrator');
2
- const notLocale = require('not-locale');
1
+ const log = require("not-log")(module, "registrator");
2
+ const notLocale = require("not-locale");
3
3
 
4
- module.exports = class notModuleRegistratorLocales{
5
- constructor({nModule}){
6
- this.run({nModule});
7
- }
4
+ module.exports = class notModuleRegistratorLocales {
5
+ constructor({ nModule }) {
6
+ this.run({ nModule });
7
+ }
8
8
 
9
- run({nModule}){
10
- const srcDir = notModuleRegistratorLocales.getPath(nModule);
11
- if (!srcDir) { return false; }
12
- notLocale.fromDir(srcDir, nModule.getName()).catch(log.error);
13
- return true;
14
- }
15
-
16
- static getPath(nModule){
17
- return nModule.module.paths.locales;
18
- }
9
+ run({ nModule }) {
10
+ const srcDir = notModuleRegistratorLocales.getPath(nModule);
11
+ if (!srcDir) {
12
+ return false;
13
+ }
14
+ notLocale.fromDir(srcDir, nModule.getName()).catch(log.error);
15
+ return true;
16
+ }
19
17
 
18
+ static getPath(nModule) {
19
+ return nModule.module.paths.locales;
20
+ }
20
21
  };
@@ -1,83 +1,85 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const logger = require('not-log');
4
- const log = logger(module, 'registrator');
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const logger = require("not-log");
5
4
 
6
- const {tryFile, mapBind} = require('../../common');
5
+ const { tryFile, mapBind } = require("../../common");
7
6
  /**
8
7
  * List of methods to be binded from notApp to logics
9
8
  * @constant
10
9
  * @type {string}
11
10
  **/
12
11
  const LOGIC_BINDINGS_LIST = [
13
- 'getModel', 'getModelFile', 'getModelSchema',
14
- 'getLogic', 'getLogicFile',
15
- 'getModule'
12
+ "getModel",
13
+ "getModelFile",
14
+ "getModelSchema",
15
+ "getLogic",
16
+ "getLogicFile",
17
+ "getModule",
16
18
  ];
17
19
 
18
- module.exports = class notModuleRegistratorLogics{
19
- static openFile = require;
20
+ module.exports = class notModuleRegistratorLogics {
21
+ static openFile = require;
20
22
 
21
- constructor({nModule}){
22
- this.run({nModule});
23
- }
24
-
25
- run({nModule}){
26
- const srcDir = notModuleRegistratorLogics.getPath(nModule);
27
- if (!srcDir) { return false; }
28
- this.findAll(
29
- {
30
- nModule,
31
- srcDir
32
- }
33
- );
34
- return true;
35
- }
36
-
37
- static getPath(nModule){
38
- return nModule.module.paths.logics;
39
- }
23
+ constructor({ nModule }) {
24
+ this.run({ nModule });
25
+ }
40
26
 
27
+ run({ nModule }) {
28
+ const srcDir = notModuleRegistratorLogics.getPath(nModule);
29
+ if (!srcDir) {
30
+ return false;
31
+ }
32
+ this.findAll({
33
+ nModule,
34
+ srcDir,
35
+ });
36
+ return true;
37
+ }
41
38
 
42
- /**
43
- * Searching fields in directory
44
- * @static
45
- * @param {Object} input
46
- * @param {notModule} input.notModule
47
- * @param {string} input.srcDir
48
- **/
49
- findAll({nModule,srcDir}){
50
- fs.readdirSync(srcDir).forEach((file) => {
51
- let fromPath = path.join(srcDir, file);
52
- //log.info(`Checking logic in ${fromPath}`);
53
- if (!tryFile(fromPath)) { return; }
54
- this.register({nModule, fromPath, file});
55
- });
56
- }
39
+ static getPath(nModule) {
40
+ return nModule.module.paths.logics;
41
+ }
57
42
 
58
- register({nModule, fromPath, file}){
59
- const logic = notModuleRegistratorLogics.openFile(fromPath);
60
- const logicName = notModuleRegistratorLogics.getName({logic, file});
61
- this.extend({nModule, logic, logicName, fromPath});
62
- nModule.setLogic(logicName, logic);
63
- //log.info(`${logicName}`);
64
- }
43
+ /**
44
+ * Searching fields in directory
45
+ * @static
46
+ * @param {Object} input
47
+ * @param {notModule} input.notModule
48
+ * @param {string} input.srcDir
49
+ **/
50
+ findAll({ nModule, srcDir }) {
51
+ fs.readdirSync(srcDir).forEach((file) => {
52
+ let fromPath = path.join(srcDir, file);
53
+ //log.info(`Checking logic in ${fromPath}`);
54
+ if (!tryFile(fromPath)) {
55
+ return;
56
+ }
57
+ this.register({ nModule, fromPath, file });
58
+ });
59
+ }
65
60
 
66
- extend({nModule, logic, logicName, fromPath}) {
67
- logic.filename = fromPath;
68
- if (nModule.appIsSet()) {
69
- mapBind(nModule.getApp(), logic, LOGIC_BINDINGS_LIST);
61
+ register({ nModule, fromPath, file }) {
62
+ const logic = notModuleRegistratorLogics.openFile(fromPath);
63
+ const logicName = notModuleRegistratorLogics.getName({ logic, file });
64
+ this.extend({ nModule, logic, logicName, fromPath });
65
+ nModule.setLogic(logicName, logic);
66
+ //log.info(`${logicName}`);
70
67
  }
71
- logic.log = logger(logic, `Logic#${logicName}`);
72
- logic.getThisModule = () => nModule;
73
- }
74
68
 
75
- static getName({logic, file}){
76
- let logicName = file;
77
- if (logic && logic.thisLogicName) {
78
- logicName = logic.thisLogicName;
69
+ extend({ nModule, logic, logicName, fromPath }) {
70
+ logic.filename = fromPath;
71
+ if (nModule.appIsSet()) {
72
+ mapBind(nModule.getApp(), logic, LOGIC_BINDINGS_LIST);
73
+ }
74
+ logic.log = logger(logic, `Logic#${logicName}`);
75
+ logic.getThisModule = () => nModule;
79
76
  }
80
- return logicName;
81
- }
82
77
 
78
+ static getName({ logic, file }) {
79
+ let logicName = file;
80
+ if (logic && logic.thisLogicName) {
81
+ logicName = logic.thisLogicName;
82
+ }
83
+ return logicName;
84
+ }
83
85
  };
@@ -1,80 +1,82 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const logger = require('not-log');
4
- const log = logger(module, 'registrator');
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const logger = require("not-log");
5
4
 
6
- const {tryFile, mapBind} = require('../../common');
5
+ const { tryFile, mapBind } = require("../../common");
7
6
  /**
8
7
  * List of methods to be binded from notApp to models
9
8
  * @constant
10
9
  * @type {string}
11
10
  **/
12
11
  const MODEL_BINDINGS_LIST = [
13
- 'getModel', 'getModelFile', 'getModelSchema',
14
- 'getModule'
12
+ "getModel",
13
+ "getModelFile",
14
+ "getModelSchema",
15
+ "getModule",
15
16
  ];
16
17
 
17
- module.exports = class notModuleRegistratorModels{
18
- static openFile = require;
19
- constructor({nModule}){
20
- this.run({nModule});
21
- }
22
-
23
- run({nModule}){
24
- const srcDir = notModuleRegistratorModels.getPath(nModule);
25
- if (!srcDir) { return false; }
26
- this.findAll(
27
- {
28
- nModule,
29
- srcDir
30
- }
31
- );
32
- return true;
33
- }
18
+ module.exports = class notModuleRegistratorModels {
19
+ static openFile = require;
20
+ constructor({ nModule }) {
21
+ this.run({ nModule });
22
+ }
34
23
 
35
- static getPath(nModule){
36
- return nModule.module.paths.models;
37
- }
24
+ run({ nModule }) {
25
+ const srcDir = notModuleRegistratorModels.getPath(nModule);
26
+ if (!srcDir) {
27
+ return false;
28
+ }
29
+ this.findAll({
30
+ nModule,
31
+ srcDir,
32
+ });
33
+ return true;
34
+ }
38
35
 
39
- /**
40
- * Searching fields in directory
41
- * @static
42
- * @param {Object} input
43
- * @param {notModule} input.notModule
44
- * @param {string} input.srcDir
45
- **/
46
- findAll({nModule,srcDir}){
47
- fs.readdirSync(srcDir).forEach((file) => {
48
- let fromPath = path.join(srcDir, file);
49
- //log.info(`Checking model in ${fromPath}`);
50
- if (!tryFile(fromPath)) { return; }
51
- this.register({nModule, fromPath, file});
52
- });
53
- }
36
+ static getPath(nModule) {
37
+ return nModule.module.paths.models;
38
+ }
54
39
 
55
- register({nModule, fromPath, file}){
56
- const model = notModuleRegistratorModels.openFile(fromPath);
57
- const modelName = notModuleRegistratorModels.getName({model, file});
58
- this.extend({nModule, model, modelName, fromPath});
59
- nModule.setModel(modelName, model);
60
- //log.info(`${modelName}`);
61
- }
40
+ /**
41
+ * Searching fields in directory
42
+ * @static
43
+ * @param {Object} input
44
+ * @param {notModule} input.notModule
45
+ * @param {string} input.srcDir
46
+ **/
47
+ findAll({ nModule, srcDir }) {
48
+ fs.readdirSync(srcDir).forEach((file) => {
49
+ let fromPath = path.join(srcDir, file);
50
+ //log.info(`Checking model in ${fromPath}`);
51
+ if (!tryFile(fromPath)) {
52
+ return;
53
+ }
54
+ this.register({ nModule, fromPath, file });
55
+ });
56
+ }
62
57
 
63
- extend({nModule, model, modelName, fromPath}) {
64
- model.filename = fromPath;
65
- if (nModule.appIsSet()) {
66
- mapBind(nModule.getApp(), model, MODEL_BINDINGS_LIST);
58
+ register({ nModule, fromPath, file }) {
59
+ const model = notModuleRegistratorModels.openFile(fromPath);
60
+ const modelName = notModuleRegistratorModels.getName({ model, file });
61
+ this.extend({ nModule, model, modelName, fromPath });
62
+ nModule.setModel(modelName, model);
63
+ //log.info(`${modelName}`);
67
64
  }
68
- model.log = logger(model, `Model#${modelName}`);
69
- model.getThisModule = () => nModule;
70
- }
71
65
 
72
- static getName({model, file}){
73
- let modelName = file;
74
- if (model && model.thisModelName) {
75
- modelName = model.thisModelName;
66
+ extend({ nModule, model, modelName, fromPath }) {
67
+ model.filename = fromPath;
68
+ if (nModule.appIsSet()) {
69
+ mapBind(nModule.getApp(), model, MODEL_BINDINGS_LIST);
70
+ }
71
+ model.log = logger(model, `Model#${modelName}`);
72
+ model.getThisModule = () => nModule;
76
73
  }
77
- return modelName;
78
- }
79
74
 
75
+ static getName({ model, file }) {
76
+ let modelName = file;
77
+ if (model && model.thisModelName) {
78
+ modelName = model.thisModelName;
79
+ }
80
+ return modelName;
81
+ }
80
82
  };