not-node 4.0.20 → 5.0.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 (73) hide show
  1. package/.eslintrc.json +2 -7
  2. package/.github/workflows/codesee-arch-diagram.yml +81 -0
  3. package/.idea/codeStyles/Project.xml +16 -0
  4. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  5. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  6. package/.idea/modules.xml +8 -0
  7. package/.idea/project.iml +12 -0
  8. package/.idea/vcs.xml +6 -0
  9. package/.idea/workspace.xml +24 -0
  10. package/package.json +20 -20
  11. package/src/app.js +2 -2
  12. package/src/common.js +7 -3
  13. package/src/core/config.json +2 -16
  14. package/src/core/fields/ID.js +2 -2
  15. package/src/core/fields/__closed.js +5 -0
  16. package/src/core/fields/__latest.js +5 -0
  17. package/src/core/fields/__version.js +5 -0
  18. package/src/core/fields/__versions.js +5 -0
  19. package/src/core/fields/active.js +1 -1
  20. package/src/core/fields/codeName.js +2 -2
  21. package/src/core/fields/createdAt.js +2 -2
  22. package/src/core/fields/default.js +1 -1
  23. package/src/core/fields/description.js +2 -2
  24. package/src/core/fields/email.js +11 -0
  25. package/src/core/fields/enabled.js +1 -1
  26. package/src/core/fields/expiredAt.js +2 -2
  27. package/src/core/fields/height.js +2 -2
  28. package/src/core/fields/ip.js +2 -2
  29. package/src/core/fields/objectId.js +13 -0
  30. package/src/core/fields/owner.js +4 -1
  31. package/src/core/fields/ownerModel.js +3 -0
  32. package/src/core/fields/price.js +2 -2
  33. package/src/core/fields/session.js +2 -2
  34. package/src/core/fields/size.js +2 -2
  35. package/src/core/fields/telephone.js +11 -0
  36. package/src/core/fields/title.js +2 -2
  37. package/src/core/fields/updatedAt.js +2 -2
  38. package/src/core/fields/userId.js +2 -2
  39. package/src/core/fields/uuid.js +2 -2
  40. package/src/core/fields/validators/email.js +4 -0
  41. package/src/core/fields/validators/owner.js +4 -0
  42. package/src/core/fields/width.js +2 -2
  43. package/src/core/index.js +6 -0
  44. package/src/core/locales/en.json +6 -0
  45. package/src/core/locales/ru.json +6 -0
  46. package/src/domain.js +71 -48
  47. package/src/fields/.old.js +193 -0
  48. package/src/fields/index.js +114 -100
  49. package/src/form/form.js +138 -35
  50. package/src/init/app.js +8 -1
  51. package/src/init/db/ioredis.js +0 -1
  52. package/src/init/index.js +4 -3
  53. package/src/init/layers/fields.js +7 -0
  54. package/src/init/layers/forms.js +0 -0
  55. package/src/init/layers/models.js +0 -0
  56. package/src/init/layers/routes.js +0 -0
  57. package/src/init/sequence.standart.js +3 -3
  58. package/src/manifest/batchRunner.js +33 -0
  59. package/src/manifest/initializator/forms.js +30 -0
  60. package/src/manifest/initializator/index.js +24 -0
  61. package/src/manifest/initializator/manifests.js +47 -0
  62. package/src/manifest/initializator/models.js +39 -0
  63. package/src/manifest/module.js +55 -29
  64. package/src/manifest/registrator/fields.js +17 -16
  65. package/src/manifest/registrator/forms.js +2 -2
  66. package/src/manifest/registrator/index.js +3 -27
  67. package/src/manifest/registrator/locales.js +1 -1
  68. package/src/manifest/registrator/logics.js +3 -3
  69. package/src/manifest/registrator/models.js +3 -3
  70. package/src/manifest/registrator/routes.js +1 -1
  71. package/src/model/enrich.js +4 -4
  72. package/src/model/proto.js +0 -1
  73. package/test/notApp.js +2 -2
@@ -4,8 +4,8 @@ const Schema = require('mongoose').Schema;
4
4
  module.exports = {
5
5
  ui:{
6
6
  component: 'UITextfield',
7
- label: 'core:field_userId_label',
8
- placeholder: 'core:field_userId_placeholder'
7
+ label: 'not-node:field_userId_label',
8
+ placeholder: 'not-node:field_userId_placeholder'
9
9
  },
10
10
  model: {
11
11
  type: Schema.Types.ObjectId,
@@ -1,8 +1,8 @@
1
1
  module.exports = {
2
2
  ui: {
3
3
  component: 'UITextfield',
4
- placeholder: 'core:field_UUID_placeholder',
5
- label: 'core:field_UUID_label',
4
+ placeholder: 'not-node:field_UUID_placeholder',
5
+ label: 'not-node:field_UUID_label',
6
6
  readonly: true
7
7
  },
8
8
  model:{
@@ -0,0 +1,4 @@
1
+ module.exports = [{
2
+ validator: 'isEmail',
3
+ message: 'not-node:email_is_not_valid'
4
+ }];
@@ -0,0 +1,4 @@
1
+ module.exports = [{
2
+ validator: 'isMongoId',
3
+ message: 'not-node:owner_is_not_valid'
4
+ }];
@@ -1,8 +1,8 @@
1
1
  module.exports = {
2
2
  ui:{
3
3
  component: 'UITextfield',
4
- placeholder: 'core:field_width_placeholder',
5
- label: 'core:field_width_label'
4
+ placeholder: 'not-node:field_width_placeholder',
5
+ label: 'not-node:field_width_label'
6
6
  },
7
7
  model:{
8
8
  type: Number,
@@ -0,0 +1,6 @@
1
+ const {generatePaths} = require('../common');
2
+
3
+ module.exports = {
4
+ name: 'not-node',
5
+ paths: generatePaths(['fields', 'locales'], __dirname)
6
+ };
@@ -22,6 +22,12 @@
22
22
  "field_size_label": "Size",
23
23
  "field_size_placeholder": "Size",
24
24
 
25
+ "field_email_label": "Email",
26
+ "field_email_placeholder": "email@server.com",
27
+
28
+ "field_telephone_label": "Tel.",
29
+ "field_telephone_placeholder": "+1 (111) 111-11-11",
30
+
25
31
  "field_ID_label": "ID",
26
32
  "field_ID_placeholder": "ID",
27
33
 
@@ -22,6 +22,12 @@
22
22
  "field_size_label": "Size",
23
23
  "field_size_placeholder": "Size",
24
24
 
25
+ "field_email_label": "Email",
26
+ "field_email_placeholder": "email@server.ru",
27
+
28
+ "field_telephone_label": "Тел.",
29
+ "field_telephone_placeholder": "+7 (111) 111-11-11",
30
+
25
31
  "field_ID_label": "ID",
26
32
  "field_ID_placeholder": "ID",
27
33
 
package/src/domain.js CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
  const EventEmitter = require('events');
7
7
  const {isFunc,isAsync, objHas, firstLetterToUpper} = require('./common');
8
-
8
+ const {error} = require('not-log')(module, 'domain');
9
9
  const Env = require('./env');
10
10
  const
11
11
  notModule = require('./manifest/module'),
@@ -41,32 +41,38 @@ const OPT_DEFAULT_SHUTDOWN_TIMEOUT = 5000;
41
41
  **/
42
42
  class notDomain extends EventEmitter {
43
43
  static OPT_DEFAULT_SHUTDOWN_TIMEOUT = OPT_DEFAULT_SHUTDOWN_TIMEOUT;
44
+ //named array of notModules wrappers for notModule format modules
45
+ #modules = {};
46
+ #options = {};
47
+
48
+ #logger = null;
49
+ #reporter = null;
50
+ #informer = null;
51
+ //named ws servers
52
+ #wss = {};
53
+ //named ws clients
54
+ #wsc = {};
55
+
44
56
  constructor(options) {
45
57
  super();
46
- this.options = options;
47
- //named array of notModules wrappers for notModule format modules
48
- this.modules = {};
49
- this._logger = null;
50
- this._reporter = null;
51
- this._informer = null;
52
- //named ws servers
53
- this._wss = {};
54
- //named ws clients
55
- this._wsc = {};
56
- //store
57
- this.envs = {};
58
+ this.#options = options;
59
+
58
60
  return this;
59
61
  }
60
62
 
63
+ getOptions(){
64
+ return this.#options;
65
+ }
66
+
61
67
  /**
62
68
  * Cycles throu all imported modules, passes name, module, and itself
63
69
  * to argument function
64
70
  * @param {function} func function to perfom some action with module
65
71
  **/
66
72
  forEachMod(func){
67
- if (this.modules) {
68
- for (let t of Object.keys(this.modules)) {
69
- let mod = this.modules[t];
73
+ if (this.#modules) {
74
+ for (let t of Object.keys(this.#modules)) {
75
+ let mod = this.#modules[t];
70
76
  if (mod) {
71
77
  func(t, mod, this);
72
78
  }
@@ -96,9 +102,9 @@ class notDomain extends EventEmitter {
96
102
  let mod = new notModule({
97
103
  modPath: modulePath,
98
104
  modObject: null,
99
- mongoose: this.options.mongoose,
105
+ mongoose: this.#options.mongoose,
100
106
  notApp: this,
101
- fields: this.options.fields
107
+ fields: this.#options.fields
102
108
  });
103
109
  this.importModule(mod, moduleName || mod.getName());
104
110
  return this;
@@ -111,7 +117,7 @@ class notDomain extends EventEmitter {
111
117
  * @return {object} notDomain
112
118
  **/
113
119
  importModule(mod, moduleName) {
114
- this.modules[moduleName] = mod;
120
+ this.#modules[moduleName] = mod;
115
121
  return this;
116
122
  }
117
123
 
@@ -123,8 +129,8 @@ class notDomain extends EventEmitter {
123
129
  getRoute(name) {
124
130
  if (name.indexOf('//') > 0) {
125
131
  let [moduleName, routeName, routeFunctionName] = name.split('//');
126
- if (this.modules && objHas(this.modules, moduleName)) {
127
- let route = this.modules[moduleName].getRoute(routeName);
132
+ if (this.#modules && objHas(this.#modules, moduleName)) {
133
+ let route = this.#modules[moduleName].getRoute(routeName);
128
134
  if (objHas(route, routeFunctionName)) {
129
135
  return route[routeFunctionName];
130
136
  }
@@ -144,6 +150,17 @@ class notDomain extends EventEmitter {
144
150
  return this.getByPath(name, type);
145
151
  }
146
152
 
153
+ /**
154
+ * Returns field description
155
+ * @param {string} name 'fieldName' or 'moduleName//fieldName'
156
+ * ('username', 'not-user//username')
157
+ * @return {object} field
158
+ **/
159
+ getField(name) {
160
+ const type = 'field';
161
+ return this.getByPath(name, type);
162
+ }
163
+
147
164
  /**
148
165
  * Returns model
149
166
  * @param {string} name 'modelName' or 'moduleName//modelName'
@@ -157,20 +174,22 @@ class notDomain extends EventEmitter {
157
174
 
158
175
  getByFullPath(name, type){
159
176
  let [moduleName, resourceName] = name.split('//');
160
- if (this.modules && objHas(this.modules, moduleName)) {
161
- return this.modules[moduleName][`get${firstLetterToUpper(type)}`](resourceName);
177
+ if (this.#modules && objHas(this.#modules, moduleName)) {
178
+ return this.#modules[moduleName][`get${firstLetterToUpper(type)}`](resourceName);
162
179
  } else {
180
+ error(`resource not found ${type}:${name}`);
163
181
  return null;
164
182
  }
165
183
  }
166
184
 
167
185
  getByShortPath(resourceName, type){
168
- for (let moduleName of Object.keys(this.modules)) {
169
- const res = this.modules[moduleName][`get${firstLetterToUpper(type)}`](resourceName);
186
+ for (let moduleName of Object.keys(this.#modules)) {
187
+ const res = this.#modules[moduleName][`get${firstLetterToUpper(type)}`](resourceName);
170
188
  if(res){
171
189
  return res;
172
190
  }
173
191
  }
192
+ error(`resource not found ${type}:${resourceName}`);
174
193
  return null;
175
194
  }
176
195
 
@@ -231,12 +250,12 @@ class notDomain extends EventEmitter {
231
250
  * @return {object} module
232
251
  **/
233
252
  getModule(moduleName) {
234
- if (this.modules && objHas(this.modules,moduleName)) {
235
- return this.modules[moduleName];
253
+ if (this.#modules && objHas(this.#modules,moduleName)) {
254
+ return this.#modules[moduleName];
236
255
  } else {
237
- for (let t in this.modules) {
238
- if (this.modules[t].getName() === moduleName) {
239
- return this.modules[t];
256
+ for (let t in this.#modules) {
257
+ if (this.#modules[t].getName() === moduleName) {
258
+ return this.#modules[t];
240
259
  }
241
260
  }
242
261
  return null;
@@ -248,7 +267,7 @@ class notDomain extends EventEmitter {
248
267
  * @param {string} methodName name of the method to execute
249
268
  **/
250
269
  async execInModules(methodName) {
251
- for (let mod of Object.values(this.modules)) {
270
+ for (let mod of Object.values(this.#modules)) {
252
271
  try{
253
272
  if(isFunc(mod.exec)){
254
273
  if(isAsync(mod.exec)){
@@ -268,7 +287,7 @@ class notDomain extends EventEmitter {
268
287
  * Create mongoose models.
269
288
  **/
270
289
  fabricate() {
271
- for (let mod of Object.values(this.modules)) {
290
+ for (let mod of Object.values(this.#modules)) {
272
291
  mod.fabricateModels && mod.fabricateModels();
273
292
  }
274
293
  }
@@ -277,12 +296,12 @@ class notDomain extends EventEmitter {
277
296
  * logger
278
297
  */
279
298
  set logger(logger) {
280
- this._logger = logger;
299
+ this.#logger = logger;
281
300
  }
282
301
 
283
302
  get logger() {
284
- if (typeof this._logger !== 'undefined' && this._logger !== null) {
285
- return this._logger;
303
+ if (typeof this.#logger !== 'undefined' && this.#logger !== null) {
304
+ return this.#logger;
286
305
  } else {
287
306
  return console;
288
307
  }
@@ -306,11 +325,11 @@ class notDomain extends EventEmitter {
306
325
  }
307
326
 
308
327
  set reporter(reporter) {
309
- this._reporter = reporter;
328
+ this.#reporter = reporter;
310
329
  }
311
330
 
312
331
  get reporter() {
313
- return this._reporter || this.DEFAULT_REPORTER;
332
+ return this.#reporter || this.DEFAULT_REPORTER;
314
333
  }
315
334
 
316
335
  report(err) {
@@ -327,11 +346,11 @@ class notDomain extends EventEmitter {
327
346
  }
328
347
 
329
348
  set informer(informer /* not-informer.Informer */ ) {
330
- this._informer = informer;
349
+ this.#informer = informer;
331
350
  }
332
351
 
333
352
  get informer() {
334
- return this._informer || this.DEFAULT_INFORMER;
353
+ return this.#informer || this.DEFAULT_INFORMER;
335
354
  }
336
355
 
337
356
  inform(data /* look for not-informer.Informer.now */ ) {
@@ -339,24 +358,24 @@ class notDomain extends EventEmitter {
339
358
  }
340
359
 
341
360
  addWSServer(name, wss) {
342
- this._wss[name] = wss;
361
+ this.#wss[name] = wss;
343
362
  }
344
363
 
345
364
  WSServer(name = 'main') {
346
- if (objHas(this._wss, name)) {
347
- return this._wss[name];
365
+ if (objHas(this.#wss, name)) {
366
+ return this.#wss[name];
348
367
  } else {
349
368
  return undefined;
350
369
  }
351
370
  }
352
371
 
353
372
  addWSClient(name, wsc) {
354
- this._wsc[name] = wsc;
373
+ this.#wsc[name] = wsc;
355
374
  }
356
375
 
357
376
  WSClient(name) {
358
- if (objHas(this._wsc, name)) {
359
- return this._wsc[name];
377
+ if (objHas(this.#wsc, name)) {
378
+ return this.#wsc[name];
360
379
  } else {
361
380
  return undefined;
362
381
  }
@@ -387,7 +406,7 @@ class notDomain extends EventEmitter {
387
406
  * @return {Object} complex object with results
388
407
  **/
389
408
  getStatus() {
390
- const mods = Object.keys(this.modules);
409
+ const mods = Object.keys(this.#modules);
391
410
  let stats = {
392
411
  modules: {
393
412
  count: mods.length,
@@ -415,8 +434,8 @@ class notDomain extends EventEmitter {
415
434
  list: []
416
435
  },
417
436
  };
418
- for (let modName in this.modules) {
419
- const mod = this.modules[modName];
437
+ for (let modName in this.#modules) {
438
+ const mod = this.#modules[modName];
420
439
  let modStatus = mod.getStatus();
421
440
  stats.modules.content[modName] = modStatus;
422
441
  stats.routes.count += modStatus.routes.count;
@@ -445,6 +464,10 @@ class notDomain extends EventEmitter {
445
464
  return this;
446
465
  }
447
466
 
467
+ getModulesNames(){
468
+ return Object.keys(this.#modules);
469
+ }
470
+
448
471
  }
449
472
 
450
473
  module.exports = notDomain;
@@ -0,0 +1,193 @@
1
+ const clone = require('rfdc')();
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const {objHas, tryFile} = require('../common');
5
+
6
+ const DEFAULT_FIELD_REGISTRATION_RULES = {
7
+ overwrite: false,
8
+ compose: true
9
+ };
10
+
11
+ const FIELDS = {};
12
+
13
+ module.exports.importFromDir = (srcDir, {overwrite = false, compose = true} = DEFAULT_FIELD_REGISTRATION_RULES)=>{
14
+ fs.readdirSync(srcDir).forEach((file) => {
15
+ let fromPath = path.join(srcDir, file);
16
+ if (!tryFile(fromPath)) { return; }
17
+ const parts = path.parse(fromPath);
18
+ registerField(parts.name, require(fromPath), {overwrite, compose});
19
+ });
20
+ };
21
+
22
+
23
+ const registerField = module.exports.registerField = (name, value, {overwrite = false, compose = true} = DEFAULT_FIELD_REGISTRATION_RULES)=>{
24
+ if(objHas(FIELDS, name)){
25
+ if(overwrite){
26
+ FIELDS[name] = value;
27
+ }else if(compose){
28
+ Object.assign(FIELDS[name], value);
29
+ }
30
+ }else{
31
+ FIELDS[name] = value;
32
+ }
33
+ };
34
+
35
+
36
+ module.exports.registerFields = (fields, {overwrite = false, compose = true})=>{
37
+ for(let t in fields){
38
+ module.exports.registerField(t, fields[t], {overwrite, compose});
39
+ }
40
+ };
41
+
42
+ /**
43
+ list = [
44
+ 'title', //for standart only name
45
+ ['titleNonStandart', {component: 'UITextforBlind'}] //arrays of [name, mutation]
46
+ ['someID', {}, 'ID'], //copy of standart ID field under name as someID
47
+ ]
48
+ */
49
+ module.exports.initFields = (list, type = 'ui') => {
50
+ let fields = {};
51
+ list.forEach((field) => {
52
+ let res = module.exports.initField(field, false, type);
53
+ fields[res[0]] = res[1];
54
+ });
55
+ return fields;
56
+ };
57
+
58
+
59
+ /**
60
+ * Retrieves field information
61
+ * there are few signatures of this function
62
+ * (field:string, resultOnly:boolean = true, type:string = 'ui')=> Object | [string, Object]
63
+ * (field:Array<string, Object>, resultOnly:boolean = true, type:string = 'ui')=> Object | [string, Object]
64
+ * @param {(string|Array)} field field to retrieve from store and init
65
+ field: string - just name of the field
66
+ field: Array - [destinationField:string, mutation: Object, sourceField:string]
67
+ field: Array - [sourceField:string, mutation: Object]
68
+ sourceField - standart field to extend
69
+ mutation - to extend by
70
+ destinationField - name of resulting field,
71
+ if no dest then src will be used
72
+ * @param {boolean} resultOnly return only result, if false then returns [name, value]
73
+ * @param {string} type type of field information
74
+ **/
75
+ module.exports.initField = (field, resultOnly = true, type = 'ui') => {
76
+ let srcName, destName, mutation = {};
77
+ if (Array.isArray(field)) {
78
+ destName = srcName = field[0];
79
+ mutation = field[1];
80
+ if (field.length === 3) {
81
+ srcName = field[2];
82
+ }
83
+ } else {
84
+ destName = srcName = field;
85
+ }
86
+ let proto = findFieldDescription(srcName, type);
87
+ let result = Object.assign({}, clone(proto), mutation);
88
+ if (resultOnly) {
89
+ return result;
90
+ } else {
91
+ return [destName, result];
92
+ }
93
+ };
94
+
95
+ function findFieldDescription(name, type){
96
+ return (objHas(FIELDS, name) && objHas(FIELDS[name], type)) ? FIELDS[name][type]:{};
97
+ }
98
+
99
+
100
+
101
+ /**
102
+ * Returns mutation tuple for a field or false
103
+ * @param {string} name field name
104
+ * @param {Array} list fields description lists
105
+ * @return {boolean|item}
106
+ */
107
+ function getMutationForField(name, list) {
108
+ for(let item of list){
109
+ if (Array.isArray(item) && item[0] === name) {
110
+ return item;
111
+ }
112
+ }
113
+ return false;
114
+ }
115
+ module.exports.getMutationForField = getMutationForField;
116
+
117
+ /**
118
+ * Takes in mongoose model schema, scans for fields names and creates list of
119
+ * field's names to initialize from LIB, if in supplied rawMutationsList, exists
120
+ * mutation for a field in list, field name in list will be replaced by a
121
+ * mutation description
122
+ * @param {Object} schema mongoose model schema
123
+ * @param {Array} rawMutationsList list of mutations [src, mutation]/[dst,mutation,src]
124
+ * @returns {Object} initialized ui descriptions of fields for schema
125
+ **/
126
+ module.exports.fromSchema = (schema, rawMutationsList = []) => {
127
+ let
128
+ //shallow copy of array
129
+ mutationsList = [...rawMutationsList],
130
+ list = [];
131
+ if (schema && Object.keys(schema).length > 0) {
132
+ let rawKeys = Object.keys(schema);
133
+ rawKeys.forEach((key) => {
134
+ let mutation = getMutationForField(key, mutationsList);
135
+ if (mutation) {
136
+ list.push(mutation);
137
+ mutationsList.splice(mutationsList.indexOf(mutation), 1);
138
+ } else {
139
+ list.push(key);
140
+ }
141
+ });
142
+ list.push(...mutationsList);
143
+ return module.exports.initFields(list);
144
+ }else{
145
+ return {};
146
+ }
147
+ };
148
+
149
+ module.exports.LIB = FIELDS;
150
+
151
+
152
+ module.exports.initFieldsFromApp = (list, type = 'ui', app) => {
153
+ let fields = {};
154
+ list.forEach((field) => {
155
+ let res = module.exports.initFieldFromApp(field, false, type, app);
156
+ fields[res[0]] = res[1];
157
+ });
158
+ return fields;
159
+ };
160
+
161
+
162
+ module.exports.initFieldFromApp = (field, resultOnly = true, type = 'ui', app) => {
163
+ let srcName, destName, mutation = {};
164
+ if (Array.isArray(field)) {
165
+ destName = srcName = field[0];
166
+ mutation = field[1];
167
+ if (field.length === 3) {
168
+ srcName = field[2];
169
+ }
170
+ } else {
171
+ destName = srcName = field;
172
+ }
173
+ let proto = findFieldDescriptionFromApp(srcName, type, app);
174
+ if(proto){
175
+ let result = Object.assign({}, clone(proto), mutation);
176
+ if (resultOnly) {
177
+ return result;
178
+ } else {
179
+ return [destName, result];
180
+ }
181
+ }else{
182
+ throw new Error(`Field (${srcName}) definition is not found`);
183
+ }
184
+ };
185
+
186
+ function findFieldDescriptionFromApp(name, type, app){
187
+ const field = app.getField(name);
188
+ if(field && objHas(field, type)){
189
+ return field[type];
190
+ }else{
191
+ return null;
192
+ }
193
+ }