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
package/src/manifest/module.js
CHANGED
|
@@ -1,33 +1,26 @@
|
|
|
1
1
|
//importing modules
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
{objHas, mapBind, isAsync, isFunc} = require('../common');
|
|
11
|
-
|
|
2
|
+
const fs = require("fs"),
|
|
3
|
+
Auth = require("../auth"),
|
|
4
|
+
logger = require("not-log"),
|
|
5
|
+
log = logger(module, "notModule"),
|
|
6
|
+
notManifest = require("./manifest.js"),
|
|
7
|
+
notModuleRegistrator = require("./registrator"),
|
|
8
|
+
notModuleInitializator = require("./initializator"),
|
|
9
|
+
{ objHas, mapBind, isAsync, isFunc } = require("../common");
|
|
12
10
|
|
|
13
11
|
/**
|
|
14
12
|
* Standart splitter of module resources paths
|
|
15
13
|
* @constant
|
|
16
14
|
* @type {string}
|
|
17
15
|
*/
|
|
18
|
-
const DEFAULT_WS_ROUTE_ACTION_SPLITTER =
|
|
19
|
-
|
|
16
|
+
const DEFAULT_WS_ROUTE_ACTION_SPLITTER = "//";
|
|
20
17
|
|
|
21
18
|
/**
|
|
22
19
|
* List of methods to be binded from notApp to notModule
|
|
23
20
|
* @constant
|
|
24
21
|
* @type {string}
|
|
25
22
|
*/
|
|
26
|
-
const MODULE_BINDINGS_LIST = [
|
|
27
|
-
'getModel',
|
|
28
|
-
'getModelSchema',
|
|
29
|
-
'getModelFile'
|
|
30
|
-
];
|
|
23
|
+
const MODULE_BINDINGS_LIST = ["getModel", "getModelSchema", "getModelFile"];
|
|
31
24
|
/**
|
|
32
25
|
* Module representation
|
|
33
26
|
* @class
|
|
@@ -36,353 +29,350 @@ const MODULE_BINDINGS_LIST = [
|
|
|
36
29
|
* @param {Object} options.modObject loaded module object
|
|
37
30
|
**/
|
|
38
31
|
class notModule {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}else{
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
if (this.module === null || typeof this.module === 'undefined') {
|
|
77
|
-
log.error(`Module ${this.path} not loaded`);
|
|
78
|
-
} else if(this.appIsSet()) {
|
|
79
|
-
mapBind(this.notApp, this.module, MODULE_BINDINGS_LIST);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
initFromPath(modulePath) {
|
|
84
|
-
try {
|
|
85
|
-
if (fs.lstatSync(modulePath).isDirectory()) {
|
|
86
|
-
this.module = require(modulePath);
|
|
87
|
-
this.registerContent();
|
|
88
|
-
}else{
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
} catch (e) {
|
|
92
|
-
this.faulty = true;
|
|
93
|
-
log.error(e);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
initFromModule() {
|
|
98
|
-
try {
|
|
99
|
-
this.registerContent();
|
|
100
|
-
} catch (e) {
|
|
101
|
-
this.faulty = true;
|
|
102
|
-
log.error(e);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
registerContent(){
|
|
107
|
-
notModuleRegistrator.exec({nModule: this});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
getEndPoints() {
|
|
111
|
-
return this.routesWS;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
getManifest({
|
|
115
|
-
auth,
|
|
116
|
-
role,
|
|
117
|
-
root
|
|
118
|
-
} = {
|
|
119
|
-
auth: false,
|
|
120
|
-
role: Auth.DEFAULT_USER_ROLE_FOR_GUEST,
|
|
121
|
-
root: false
|
|
122
|
-
}) {
|
|
123
|
-
return this.manifest.filterManifest(
|
|
124
|
-
this.manifests,
|
|
125
|
-
auth,
|
|
126
|
-
role,
|
|
127
|
-
root
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
getRouteManifest(name){
|
|
132
|
-
return this.manifests[name];
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
getRoutesManifests(){
|
|
136
|
-
return this.manifests;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
getModelFile(modelName) {
|
|
140
|
-
if (this.models && objHas(this.models, modelName)) {
|
|
141
|
-
return this.models[modelName];
|
|
142
|
-
} else {
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
getModel(modelName) {
|
|
148
|
-
let modelFile = this.getModelFile(modelName);
|
|
149
|
-
if (modelFile && (modelName in modelFile)) {
|
|
150
|
-
return modelFile[modelName];
|
|
151
|
-
} else {
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
getModels(){
|
|
157
|
-
return this.models;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
getLogicFile(logicName) {
|
|
161
|
-
if (this.logics && objHas(this.logics, logicName)) {
|
|
162
|
-
return this.logics[logicName];
|
|
163
|
-
} else {
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
getLogic(logicName) {
|
|
169
|
-
let logicFile = this.getLogicFile(logicName);
|
|
170
|
-
if (logicFile && (logicName in logicFile)) {
|
|
171
|
-
return logicFile[logicName];
|
|
172
|
-
} else {
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
getModelSchema(modelName) {
|
|
178
|
-
let modelFile = this.getModelFile(modelName);
|
|
179
|
-
if (modelFile && objHas(modelFile, modelName) && modelFile.thisSchema) {
|
|
180
|
-
return modelFile.thisSchema;
|
|
181
|
-
}
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
expose(expressApp, moduleName) {
|
|
186
|
-
if (this.manifests && expressApp) {
|
|
187
|
-
notModuleInitializator.exec({nModule: this});
|
|
188
|
-
this.initManifest(expressApp, moduleName);
|
|
189
|
-
this.manifest.registerRoutes(this.manifests);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
initManifest(expressApp, moduleName){
|
|
194
|
-
this.manifest = new notManifest(expressApp, this.notApp, moduleName);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
async exec(methodName) {
|
|
198
|
-
if (!this.module) {
|
|
199
|
-
log.error(`Cant exec ${methodName} in module ${this.path}, module not loaded`);
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
if ((objHas(this.module, methodName)) && (isFunc(this.module[methodName]))) {
|
|
203
|
-
try {
|
|
204
|
-
if (isAsync(this.module[methodName])) {
|
|
205
|
-
await this.module[methodName](this.notApp);
|
|
32
|
+
constructor(options) {
|
|
33
|
+
this.path = options.modPath;
|
|
34
|
+
this.module = options.modObject;
|
|
35
|
+
this.mongoose = options.mongoose;
|
|
36
|
+
this.notApp = options.notApp;
|
|
37
|
+
this.routes = {};
|
|
38
|
+
this.routesWS = {
|
|
39
|
+
servers: {},
|
|
40
|
+
clients: {},
|
|
41
|
+
};
|
|
42
|
+
this.models = {};
|
|
43
|
+
this.logics = {};
|
|
44
|
+
this.forms = {};
|
|
45
|
+
this.formsConstructors = {};
|
|
46
|
+
this.fields = {};
|
|
47
|
+
this.manifests = {};
|
|
48
|
+
this.faulty = false;
|
|
49
|
+
this.paths = {
|
|
50
|
+
routes: {},
|
|
51
|
+
models: {},
|
|
52
|
+
};
|
|
53
|
+
this.fieldsImportRules =
|
|
54
|
+
objHas(options, "fields") && options.fields ? options.fields : {};
|
|
55
|
+
|
|
56
|
+
// log.info(`Creating module: ${this.getName()}`);
|
|
57
|
+
this.init();
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
init() {
|
|
62
|
+
if (this.path) {
|
|
63
|
+
this.initFromPath(this.path);
|
|
64
|
+
} else if (this.module) {
|
|
65
|
+
this.initFromModule(this.module);
|
|
206
66
|
} else {
|
|
207
|
-
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
if (this.module === null || typeof this.module === "undefined") {
|
|
70
|
+
log.error(`Module ${this.path} not loaded`);
|
|
71
|
+
} else if (this.appIsSet()) {
|
|
72
|
+
mapBind(this.notApp, this.module, MODULE_BINDINGS_LIST);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
initFromPath(modulePath) {
|
|
77
|
+
try {
|
|
78
|
+
if (fs.lstatSync(modulePath).isDirectory()) {
|
|
79
|
+
this.module = require(modulePath);
|
|
80
|
+
this.registerContent();
|
|
81
|
+
} else {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
} catch (e) {
|
|
85
|
+
this.faulty = true;
|
|
86
|
+
log.error(e);
|
|
208
87
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
getStatus() {
|
|
220
|
-
const formsList = Object.keys(this.forms);
|
|
221
|
-
const modelsList = Object.keys(this.models);
|
|
222
|
-
const routesList = Object.keys(this.routes);
|
|
223
|
-
const actionsList = this.getActionsList();
|
|
224
|
-
return {
|
|
225
|
-
forms: {
|
|
226
|
-
count: formsList.length,
|
|
227
|
-
list: formsList
|
|
228
|
-
},
|
|
229
|
-
models: {
|
|
230
|
-
count: modelsList.length,
|
|
231
|
-
list: modelsList,
|
|
232
|
-
content: this.getModelsStatuses()
|
|
233
|
-
},
|
|
234
|
-
routes: {
|
|
235
|
-
count: routesList.length,
|
|
236
|
-
list: routesList,
|
|
237
|
-
content: this.getRoutesStatuses()
|
|
238
|
-
},
|
|
239
|
-
actions: {
|
|
240
|
-
count: actionsList.length,
|
|
241
|
-
list: actionsList
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
getActionsList() {
|
|
247
|
-
let list = [];
|
|
248
|
-
for (let route in this.manifests) {
|
|
249
|
-
if (this.manifests[route] && this.manifests[route].actions) {
|
|
250
|
-
for (let action in this.manifests[route].actions) {
|
|
251
|
-
list.push(`${route}//${action}`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
initFromModule() {
|
|
91
|
+
try {
|
|
92
|
+
this.registerContent();
|
|
93
|
+
} catch (e) {
|
|
94
|
+
this.faulty = true;
|
|
95
|
+
log.error(e);
|
|
252
96
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
//endPoint name
|
|
366
|
-
const endPointName = `${wsRouteName}${DEFAULT_WS_ROUTE_ACTION_SPLITTER}${action}`;
|
|
367
|
-
//finally assigning function
|
|
368
|
-
endPoints[endPointName] = func;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
createEmptyIfNotExistsRouteWSType(
|
|
372
|
-
{
|
|
373
|
-
collectionType, //client, server
|
|
374
|
-
collectionName, //concrete client/server name
|
|
375
|
-
endPointType //request,event,response, etc
|
|
376
|
-
}
|
|
377
|
-
) {
|
|
378
|
-
if (!objHas(this.routesWS[collectionType], collectionName)) {
|
|
379
|
-
this.routesWS[collectionType][collectionName] = {};
|
|
380
|
-
}
|
|
381
|
-
if (!objHas(this.routesWS[collectionType][collectionName], endPointType)) {
|
|
382
|
-
this.routesWS[collectionType][collectionName][endPointType] = {};
|
|
383
|
-
}
|
|
384
|
-
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
registerContent() {
|
|
100
|
+
notModuleRegistrator.exec({ nModule: this });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
getEndPoints() {
|
|
104
|
+
return this.routesWS;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
getManifest(
|
|
108
|
+
{ auth, role, root } = {
|
|
109
|
+
auth: false,
|
|
110
|
+
role: Auth.DEFAULT_USER_ROLE_FOR_GUEST,
|
|
111
|
+
root: false,
|
|
112
|
+
}
|
|
113
|
+
) {
|
|
114
|
+
return this.manifest.filterManifest(this.manifests, auth, role, root);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
getRouteManifest(name) {
|
|
118
|
+
return this.manifests[name];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
getRoutesManifests() {
|
|
122
|
+
return this.manifests;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
getModelFile(modelName) {
|
|
126
|
+
if (this.models && objHas(this.models, modelName)) {
|
|
127
|
+
return this.models[modelName];
|
|
128
|
+
} else {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
getModel(modelName) {
|
|
134
|
+
let modelFile = this.getModelFile(modelName);
|
|
135
|
+
if (modelFile && modelName in modelFile) {
|
|
136
|
+
return modelFile[modelName];
|
|
137
|
+
} else {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
getModels() {
|
|
143
|
+
return this.models;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
getLogicFile(logicName) {
|
|
147
|
+
if (this.logics && objHas(this.logics, logicName)) {
|
|
148
|
+
return this.logics[logicName];
|
|
149
|
+
} else {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
getLogic(logicName) {
|
|
155
|
+
let logicFile = this.getLogicFile(logicName);
|
|
156
|
+
if (logicFile && logicName in logicFile) {
|
|
157
|
+
return logicFile[logicName];
|
|
158
|
+
} else {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
getModelSchema(modelName) {
|
|
164
|
+
let modelFile = this.getModelFile(modelName);
|
|
165
|
+
if (modelFile && objHas(modelFile, modelName) && modelFile.thisSchema) {
|
|
166
|
+
return modelFile.thisSchema;
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
expose(expressApp, moduleName) {
|
|
172
|
+
if (this.manifests && expressApp) {
|
|
173
|
+
notModuleInitializator.exec({ nModule: this });
|
|
174
|
+
this.initManifest(expressApp, moduleName);
|
|
175
|
+
this.manifest.registerRoutes(this.manifests);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
initManifest(expressApp, moduleName) {
|
|
180
|
+
this.manifest = new notManifest(expressApp, this.notApp, moduleName);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async exec(methodName) {
|
|
184
|
+
if (!this.module) {
|
|
185
|
+
log.error(
|
|
186
|
+
`Cant exec ${methodName} in module ${this.path}, module not loaded`
|
|
187
|
+
);
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
if (
|
|
191
|
+
objHas(this.module, methodName) &&
|
|
192
|
+
isFunc(this.module[methodName])
|
|
193
|
+
) {
|
|
194
|
+
try {
|
|
195
|
+
if (isAsync(this.module[methodName])) {
|
|
196
|
+
await this.module[methodName](this.notApp);
|
|
197
|
+
} else {
|
|
198
|
+
this.module[methodName](this.notApp);
|
|
199
|
+
}
|
|
200
|
+
return true;
|
|
201
|
+
} catch (e) {
|
|
202
|
+
log.error(e);
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
385
209
|
|
|
210
|
+
getStatus() {
|
|
211
|
+
const formsList = Object.keys(this.forms);
|
|
212
|
+
const modelsList = Object.keys(this.models);
|
|
213
|
+
const routesList = Object.keys(this.routes);
|
|
214
|
+
const actionsList = this.getActionsList();
|
|
215
|
+
return {
|
|
216
|
+
forms: {
|
|
217
|
+
count: formsList.length,
|
|
218
|
+
list: formsList,
|
|
219
|
+
},
|
|
220
|
+
models: {
|
|
221
|
+
count: modelsList.length,
|
|
222
|
+
list: modelsList,
|
|
223
|
+
content: this.getModelsStatuses(),
|
|
224
|
+
},
|
|
225
|
+
routes: {
|
|
226
|
+
count: routesList.length,
|
|
227
|
+
list: routesList,
|
|
228
|
+
content: this.getRoutesStatuses(),
|
|
229
|
+
},
|
|
230
|
+
actions: {
|
|
231
|
+
count: actionsList.length,
|
|
232
|
+
list: actionsList,
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
getActionsList() {
|
|
238
|
+
let list = [];
|
|
239
|
+
for (let route in this.manifests) {
|
|
240
|
+
if (this.manifests[route] && this.manifests[route].actions) {
|
|
241
|
+
for (let action in this.manifests[route].actions) {
|
|
242
|
+
list.push(`${route}//${action}`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return list;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
getRoutesStatuses() {
|
|
250
|
+
let result = {};
|
|
251
|
+
for (let route in this.manifests) {
|
|
252
|
+
if (this.manifests[route] && this.manifests[route].actions) {
|
|
253
|
+
result[route] = this.manifests[route].actions;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return result;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
getModelsStatuses() {
|
|
260
|
+
let content = {};
|
|
261
|
+
Object.keys(this.models).forEach((name) => {
|
|
262
|
+
content[name] = this.getModelSchema(name);
|
|
263
|
+
});
|
|
264
|
+
return content;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
setManifest(key, val) {
|
|
268
|
+
this.manifests[key] = val;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
getForm(key) {
|
|
272
|
+
return this.forms[key];
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
setForm(key, val) {
|
|
276
|
+
this.forms[key] = val;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
getFormConstructor(key) {
|
|
280
|
+
return this.formsConstructors[key];
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
setFormConstructor(key, val) {
|
|
284
|
+
this.formsConstructors[key] = val;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
getFormsConstructors() {
|
|
288
|
+
return this.formsConstructors;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
getField(key) {
|
|
292
|
+
return this.fields[key];
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
setField(key, val) {
|
|
296
|
+
this.fields[key] = val;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
setModel(key, val) {
|
|
300
|
+
this.models[key] = val;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
setRoute(key, val) {
|
|
304
|
+
this.routes[key] = val;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
setLogic(key, val) {
|
|
308
|
+
this.logics[key] = val;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
getRoute(routeName) {
|
|
312
|
+
if (this.routes && objHas(this.routes, routeName)) {
|
|
313
|
+
return this.routes[routeName];
|
|
314
|
+
} else {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
getRoutes() {
|
|
320
|
+
return this.routes;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
appIsSet() {
|
|
324
|
+
return typeof this.notApp !== "undefined";
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
getApp() {
|
|
328
|
+
return this.notApp;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
getName() {
|
|
332
|
+
if (this.module && this.module.name) {
|
|
333
|
+
return this.module.name;
|
|
334
|
+
}
|
|
335
|
+
return this.path;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
getOptions() {
|
|
339
|
+
return this.module && this.module.options ? this.module.options : {};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
setRouteWS({
|
|
343
|
+
collectionType,
|
|
344
|
+
collectionName,
|
|
345
|
+
endPointType,
|
|
346
|
+
wsRouteName,
|
|
347
|
+
action,
|
|
348
|
+
func,
|
|
349
|
+
}) {
|
|
350
|
+
//servers/client
|
|
351
|
+
const collection = this.routesWS[collectionType];
|
|
352
|
+
//concrete client or server
|
|
353
|
+
const wsConnection = collection[collectionName];
|
|
354
|
+
//request, event, response etc
|
|
355
|
+
const endPoints = wsConnection[endPointType];
|
|
356
|
+
//endPoint name
|
|
357
|
+
const endPointName = `${wsRouteName}${DEFAULT_WS_ROUTE_ACTION_SPLITTER}${action}`;
|
|
358
|
+
//finally assigning function
|
|
359
|
+
endPoints[endPointName] = func;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
createEmptyIfNotExistsRouteWSType({
|
|
363
|
+
collectionType, //client, server
|
|
364
|
+
collectionName, //concrete client/server name
|
|
365
|
+
endPointType, //request,event,response, etc
|
|
366
|
+
}) {
|
|
367
|
+
if (!objHas(this.routesWS[collectionType], collectionName)) {
|
|
368
|
+
this.routesWS[collectionType][collectionName] = {};
|
|
369
|
+
}
|
|
370
|
+
if (
|
|
371
|
+
!objHas(this.routesWS[collectionType][collectionName], endPointType)
|
|
372
|
+
) {
|
|
373
|
+
this.routesWS[collectionType][collectionName][endPointType] = {};
|
|
374
|
+
}
|
|
375
|
+
}
|
|
386
376
|
}
|
|
387
377
|
|
|
388
378
|
module.exports = notModule;
|