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.
- package/.eslintrc.json +1 -1
- package/bin/not-deploy.js +52 -0
- package/index.js +21 -19
- package/package.json +1 -1
- package/src/app.js +61 -58
- package/src/auth/abstract.js +17 -19
- package/src/auth/const.js +8 -12
- package/src/auth/fields.js +143 -124
- package/src/auth/index.js +14 -14
- package/src/auth/roles.js +64 -63
- package/src/auth/routes.js +89 -54
- package/src/auth/rules.js +63 -63
- package/src/auth/session.js +60 -62
- package/src/bootstrap/form.js +13 -13
- package/src/bootstrap/logic.js +45 -41
- package/src/bootstrap/model.js +14 -17
- package/src/bootstrap/route.js +132 -53
- package/src/common.js +86 -79
- package/src/core/fields/ID.js +6 -6
- package/src/core/fields/__closed.js +3 -3
- package/src/core/fields/__latest.js +3 -3
- package/src/core/fields/__version.js +3 -3
- package/src/core/fields/__versions.js +3 -3
- package/src/core/fields/_id.js +6 -6
- package/src/core/fields/active.js +9 -9
- package/src/core/fields/codeName.js +9 -9
- package/src/core/fields/createdAt.js +17 -17
- package/src/core/fields/default.js +9 -9
- package/src/core/fields/description.js +11 -11
- package/src/core/fields/email.js +9 -9
- package/src/core/fields/enabled.js +9 -9
- package/src/core/fields/expiredAt.js +16 -16
- package/src/core/fields/height.js +11 -11
- package/src/core/fields/ip.js +10 -10
- package/src/core/fields/objectId.js +10 -10
- package/src/core/fields/owner.js +13 -13
- package/src/core/fields/ownerModel.js +11 -11
- package/src/core/fields/price.js +11 -11
- package/src/core/fields/requiredObject.js +10 -10
- package/src/core/fields/session.js +10 -10
- package/src/core/fields/size.js +11 -11
- package/src/core/fields/telephone.js +9 -9
- package/src/core/fields/title.js +15 -15
- package/src/core/fields/updatedAt.js +17 -17
- package/src/core/fields/userId.js +11 -12
- package/src/core/fields/uuid.js +11 -11
- package/src/core/fields/validators/email.js +6 -4
- package/src/core/fields/validators/owner.js +6 -4
- package/src/core/fields/width.js +11 -11
- package/src/domain.js +435 -431
- package/src/env.js +23 -23
- package/src/error.js +20 -23
- package/src/exceptions/db.js +23 -0
- package/src/exceptions/http.js +43 -0
- package/src/fields/index.js +106 -111
- package/src/form/fabric.js +19 -24
- package/src/form/form.js +195 -186
- package/src/form/index.js +2 -2
- package/src/generic/index.js +2 -0
- package/src/generic/logic.js +595 -0
- package/src/generic/route.js +76 -0
- package/src/init/additional.js +7 -7
- package/src/init/app.js +75 -68
- package/src/init/bodyparser.js +14 -14
- package/src/init/compression.js +6 -7
- package/src/init/core.js +12 -12
- package/src/init/cors.js +22 -24
- package/src/init/db/index.js +41 -43
- package/src/init/db/ioredis.js +28 -20
- package/src/init/db/mongoose.js +42 -32
- package/src/init/db/redis.js +59 -48
- package/src/init/env.js +44 -36
- package/src/init/express.js +18 -21
- package/src/init/fileupload.js +8 -10
- package/src/init/http.js +65 -47
- package/src/init/index.js +141 -148
- package/src/init/informer.js +7 -9
- package/src/init/methodoverride.js +4 -6
- package/src/init/middleware.js +23 -26
- package/src/init/modules.js +4 -4
- package/src/init/monitoring.js +8 -8
- package/src/init/rateLimiter.js +53 -45
- package/src/init/routes.js +67 -69
- package/src/init/security.js +37 -33
- package/src/init/sequence.js +111 -107
- package/src/init/sequence.standart.js +54 -56
- package/src/init/sessions/index.js +21 -21
- package/src/init/sessions/mongoose.js +49 -36
- package/src/init/sessions/redis.js +28 -27
- package/src/init/static.js +53 -40
- package/src/init/template.js +17 -17
- package/src/lib.js +230 -200
- package/src/manifest/batchRunner.js +26 -25
- package/src/manifest/initializator/forms.js +24 -24
- package/src/manifest/initializator/index.js +8 -10
- package/src/manifest/initializator/manifests.js +45 -42
- package/src/manifest/initializator/models.js +37 -34
- package/src/manifest/manifest.filter.js +130 -97
- package/src/manifest/manifest.js +103 -77
- package/src/manifest/module.js +350 -360
- package/src/manifest/registrator/fields.js +90 -85
- package/src/manifest/registrator/forms.js +47 -47
- package/src/manifest/registrator/index.js +14 -16
- package/src/manifest/registrator/locales.js +17 -16
- package/src/manifest/registrator/logics.js +66 -64
- package/src/manifest/registrator/models.js +64 -62
- package/src/manifest/registrator/routes.js +171 -132
- package/src/manifest/registrator/routes.ws.js +109 -103
- package/src/manifest/route.js +216 -161
- package/src/model/buildValidator.js +53 -42
- package/src/model/default.js +304 -286
- package/src/model/enrich.js +69 -61
- package/src/model/increment.js +124 -137
- package/src/model/proto.js +179 -148
- package/src/model/routine.js +85 -76
- package/src/model/utils.js +33 -0
- package/src/model/versioning.js +148 -130
- package/src/obsolete.js +12 -8
- package/src/parser.js +29 -22
- package/src/repos.js +29 -31
- package/src/rollup.js +75 -65
- package/src/shell.helpers.js +28 -28
- package/static.js +31 -0
- package/src/generic/router.js +0 -16
- package/src/manifest/module.models.js +0 -0
- package/src/manifest/module.status.js +0 -0
|
@@ -1,98 +1,103 @@
|
|
|
1
|
-
const path = require(
|
|
2
|
-
const fs = require(
|
|
3
|
-
const {tryFile, objHas} = require(
|
|
4
|
-
const Fields = require(
|
|
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
|
-
|
|
10
|
-
|
|
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
|
-
|
|
29
|
-
|
|
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
|
-
|
|
33
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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(
|
|
2
|
-
const fs = require(
|
|
3
|
-
const {tryFile} = require(
|
|
4
|
-
|
|
5
|
-
module.exports = class notModuleRegistratorForms{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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(
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
28
|
+
module.exports = new BatchRunner(DEFAULT_REGISTRATORS);
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
const log = require(
|
|
2
|
-
const notLocale = require(
|
|
1
|
+
const log = require("not-log")(module, "registrator");
|
|
2
|
+
const notLocale = require("not-locale");
|
|
3
3
|
|
|
4
|
-
module.exports = class notModuleRegistratorLocales{
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
module.exports = class notModuleRegistratorLocales {
|
|
5
|
+
constructor({ nModule }) {
|
|
6
|
+
this.run({ nModule });
|
|
7
|
+
}
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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(
|
|
2
|
-
const path = require(
|
|
3
|
-
const logger = require(
|
|
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(
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
"getModel",
|
|
13
|
+
"getModelFile",
|
|
14
|
+
"getModelSchema",
|
|
15
|
+
"getLogic",
|
|
16
|
+
"getLogicFile",
|
|
17
|
+
"getModule",
|
|
16
18
|
];
|
|
17
19
|
|
|
18
|
-
module.exports = class notModuleRegistratorLogics{
|
|
19
|
-
|
|
20
|
+
module.exports = class notModuleRegistratorLogics {
|
|
21
|
+
static openFile = require;
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
44
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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(
|
|
2
|
-
const path = require(
|
|
3
|
-
const logger = require(
|
|
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(
|
|
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
|
-
|
|
14
|
-
|
|
12
|
+
"getModel",
|
|
13
|
+
"getModelFile",
|
|
14
|
+
"getModelSchema",
|
|
15
|
+
"getModule",
|
|
15
16
|
];
|
|
16
17
|
|
|
17
|
-
module.exports = class notModuleRegistratorModels{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
36
|
-
|
|
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
|
-
|
|
41
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
};
|