nodefony 7.0.0-beta.2 → 7.0.0-beta.21

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 (136) hide show
  1. package/CHANGELOG.md +534 -8028
  2. package/README.md +33 -30
  3. package/autoloader.es6 +46 -48
  4. package/builder.es6 +66 -76
  5. package/cli/builder/bundles/bundle.js +57 -63
  6. package/cli/builder/bundles/controller.js +34 -38
  7. package/cli/builder/bundles/users-bundle/Command/fixtureTask.js +11 -12
  8. package/cli/builder/bundles/users-bundle/Command/usersCommand.js +23 -24
  9. package/cli/builder/bundles/users-bundle/Entity/mongoose/userEntity.js +25 -30
  10. package/cli/builder/bundles/users-bundle/Entity/sequelize/userEntity.js +42 -31
  11. package/cli/builder/bundles/users-bundle/Fixtures/users.js +24 -26
  12. package/cli/builder/bundles/users-bundle/Fixtures/usersFixtures.js +28 -29
  13. package/cli/builder/bundles/users-bundle/Resources/config/config.js +4 -3
  14. package/cli/builder/bundles/users-bundle/Resources/config/routing.js +2 -2
  15. package/cli/builder/bundles/users-bundle/Resources/config/security.js +9 -8
  16. package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.dev.config.js +3 -3
  17. package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.prod.config.js +4 -3
  18. package/cli/builder/bundles/users-bundle/Resources/config/webpack.config.js +74 -75
  19. package/cli/builder/bundles/users-bundle/Resources/scss/awesome/font-awesome.config.js +9 -9
  20. package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/login.js +13 -13
  21. package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/users.js +14 -14
  22. package/cli/builder/bundles/users-bundle/controller/api/graphql/graphqlController.js +13 -15
  23. package/cli/builder/bundles/users-bundle/controller/api/graphql/userResolver.js +29 -29
  24. package/cli/builder/bundles/users-bundle/controller/api/graphql/usertype.js +2 -2
  25. package/cli/builder/bundles/users-bundle/controller/api/openapi/loginApiController.js +34 -36
  26. package/cli/builder/bundles/users-bundle/controller/api/openapi/restUserController.js +32 -36
  27. package/cli/builder/bundles/users-bundle/controller/loginController.js +30 -34
  28. package/cli/builder/bundles/users-bundle/controller/usersController.js +54 -60
  29. package/cli/builder/bundles/users-bundle/package.json +27 -25
  30. package/cli/builder/bundles/users-bundle/pnpm-lock.yaml +4262 -0
  31. package/cli/builder/bundles/users-bundle/readme.md +7 -7
  32. package/cli/builder/bundles/users-bundle/services/usersService.js +97 -102
  33. package/cli/builder/bundles/users-bundle/src/providers/mongoose/userProvider.js +6 -8
  34. package/cli/builder/bundles/users-bundle/src/providers/sequelize/userProvider.js +9 -10
  35. package/cli/builder/bundles/users-bundle/tests/loginTest.js +119 -70
  36. package/cli/builder/bundles/users-bundle/usersBundle.js +2 -3
  37. package/cli/builder/microService/microService.js +139 -141
  38. package/cli/builder/microService/skeletons/package.json +23 -22
  39. package/cli/builder/project/project.js +228 -181
  40. package/cli/builder/project/skeletons/README.md +33 -30
  41. package/cli/builder/project/skeletons/bin/dev-deploy.sh +5 -0
  42. package/cli/builder/project/skeletons/bin/prod-deploy.sh +3 -0
  43. package/cli/builder/project/skeletons/config/config.js.skeleton +1 -0
  44. package/cli/builder/project/skeletons/config/pm2.config.js.skeleton +41 -17
  45. package/cli/builder/project/skeletons/eslintignore.skeleton +15 -0
  46. package/cli/builder/project/skeletons/eslintrc.js.skeleton +97 -0
  47. package/cli/builder/project/skeletons/gitignore.skeleton +1 -0
  48. package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.37.entity-user.js +137 -0
  49. package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.38.entity-session.js +97 -0
  50. package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.39.entity-requests.js +115 -0
  51. package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.40.entity-jwts.js +97 -0
  52. package/cli/builder/project/skeletons/migrations/migrations.skeleton.js +0 -2
  53. package/cli/builder/project/skeletons/package.json.twig +70 -0
  54. package/cli/builder/react/reactBuilder.js +59 -65
  55. package/cli/builder/sandbox/sandBoxBuilder.js +132 -134
  56. package/cli/builder/skeletons/app/appKernel.js +120 -2
  57. package/cli/builder/skeletons/config/config.js +1 -1
  58. package/cli/builder/skeletons/config/nodefony/framework-bundle.js +2 -1
  59. package/cli/builder/skeletons/config/nodefony/http-bundle.js +1 -0
  60. package/cli/builder/skeletons/config/nodefony/mongoose-bundle.js +38 -12
  61. package/cli/builder/skeletons/config/nodefony/monitoring-bundle.js +21 -2
  62. package/cli/builder/skeletons/config/nodefony/sequelize-bundle.js +122 -13
  63. package/cli/builder/skeletons/package.json.twig +57 -0
  64. package/cli/builder/skeletons/unittest/testFile.js +44 -45
  65. package/cli/builder/vue/skeletons/vue.config.js +84 -10
  66. package/cli/builder/vue/vueBuilder.js +116 -114
  67. package/cli/generate/generate.es6 +38 -39
  68. package/cli/install/install.js +45 -58
  69. package/cli/sequelize/sequelize.js +50 -39
  70. package/cli/start.js +353 -347
  71. package/cli/tools/pm2.es6 +55 -57
  72. package/cli/tools/tools.es6 +36 -37
  73. package/cli.es6 +280 -228
  74. package/container.es6 +51 -59
  75. package/error.es6 +25 -27
  76. package/fileClass.es6 +53 -55
  77. package/finder/file.es6 +5 -4
  78. package/finder/fileResult.es6 +23 -22
  79. package/finder/finder2.es6 +46 -54
  80. package/finder.es6 +88 -97
  81. package/kernel/annotations/annotations.es6 +44 -46
  82. package/kernel/api/api.es6 +6 -8
  83. package/kernel/api/graphqlApi.es6 +21 -21
  84. package/kernel/api/jsonApi.es6 +40 -45
  85. package/kernel/api/openApi.es6 +9 -11
  86. package/kernel/api/schemas/openApiSchema.js +61 -32
  87. package/kernel/babylon.es6 +31 -38
  88. package/kernel/bundle.es6 +252 -220
  89. package/kernel/cliKernel.es6 +157 -170
  90. package/kernel/command.es6 +17 -20
  91. package/kernel/commands/nodefonyCommand.es6 +111 -58
  92. package/kernel/commands/tasks/bundlesTask.es6 +14 -19
  93. package/kernel/controllers/controller.es6 +167 -180
  94. package/kernel/fixture.es6 +4 -7
  95. package/kernel/injections/injections.es6 +97 -103
  96. package/kernel/kernel.es6 +476 -384
  97. package/kernel/kernelWatcher.es6 +64 -54
  98. package/kernel/orm/entity.es6 +10 -12
  99. package/kernel/orm/orm.es6 +68 -48
  100. package/kernel/reader.es6 +45 -47
  101. package/kernel/security/encoder.es6 +8 -6
  102. package/kernel/security/factories/factory.es6 +34 -37
  103. package/kernel/security/factories/passeportFactory.es6 +13 -14
  104. package/kernel/security/provider.es6 +11 -13
  105. package/kernel/security/providers/chainProvider.es6 +13 -28
  106. package/kernel/security/providers/memoryProvider.es6 +7 -11
  107. package/kernel/security/providers/providerManager.es6 +11 -14
  108. package/kernel/security/providers/userEntityProvider.es6 +7 -8
  109. package/kernel/security/role.es6 +3 -3
  110. package/kernel/security/secureArea.es6 +143 -149
  111. package/kernel/security/tokens/token.es6 +30 -32
  112. package/kernel/security/user.es6 +19 -19
  113. package/kernel/serviceRealTime.es6 +5 -7
  114. package/kernel/services/connectionsService.es6 +20 -22
  115. package/kernel/services/cron/cronService.es6 +14 -16
  116. package/kernel/task.es6 +20 -26
  117. package/kernel/templates.es6 +4 -5
  118. package/kernel/templating/twig.es6 +56 -47
  119. package/kernel/tests/cliTest.js +7 -11
  120. package/kernel/tests/containerTest.js +25 -37
  121. package/kernel/tests/kernelTest.js +9 -16
  122. package/nodefony.es6 +279 -256
  123. package/notificationsCenter.es6 +28 -20
  124. package/package.json +40 -40
  125. package/protocol.es6 +19 -21
  126. package/protocols/bayeux.es6 +35 -38
  127. package/protocols/jsonRpc/jsonrpc.es6 +12 -14
  128. package/result.es6 +11 -12
  129. package/service.es6 +62 -62
  130. package/syslog/pdu.es6 +99 -91
  131. package/syslog/syslog.es6 +101 -102
  132. package/watcher.es6 +21 -20
  133. package/cli/builder/project/skeletons/jshintignore.skeleton +0 -1
  134. package/cli/builder/project/skeletons/jshintrc.skeleton +0 -60
  135. package/cli/builder/project/skeletons/package.json.skeleton +0 -52
  136. package/cli/builder/skeletons/package.json +0 -61
@@ -8,15 +8,15 @@ const defaultWatcherSettings = {
8
8
  followSymlinks: true,
9
9
  alwaysStat: false,
10
10
  depth: 50,
11
- //usePolling: true,
12
- //interval: 500,
13
- //binaryInterval: 300,
11
+ // usePolling: true,
12
+ // interval: 500,
13
+ // binaryInterval: 300,
14
14
  awaitWriteFinish: true,
15
15
  atomic: true // or a custom 'atomicity delay', in milliseconds (default 100)
16
16
  };
17
17
 
18
18
  class Watcher extends nodefony.Watcher {
19
- constructor(Path, settings, bundle) {
19
+ constructor (Path, settings, bundle) {
20
20
  super(Path, nodefony.extend(true, {}, defaultWatcherSettings, settings), bundle.container);
21
21
  if (bundle) {
22
22
  this.bundle = bundle;
@@ -26,32 +26,32 @@ class Watcher extends nodefony.Watcher {
26
26
  this.webpackService = this.get("webpack");
27
27
  }
28
28
 
29
- log(payload, severity, msgid, msg) {
29
+ log (payload, severity, msgid, msg) {
30
30
  if (severity === "ERROR") {
31
31
  console.trace(payload);
32
32
  }
33
33
  if (typeof payload === "string") {
34
34
  let txt = "\x1b[36m";
35
35
  if (this.bundle) {
36
- txt += "BUNDLE " + this.bundle.name + "\x1b[0m ";
36
+ txt += `BUNDLE ${this.bundle.name}\x1b[0m `;
37
37
  }
38
38
  txt += payload;
39
- msgid = "\x1b[36mWATCHER EVENT " + msgid + "\x1b[0m";
39
+ msgid = `\x1b[36mWATCHER EVENT ${msgid}\x1b[0m`;
40
40
  payload = txt;
41
41
  }
42
42
  return super.log(payload, severity, msgid, msg);
43
43
  }
44
44
 
45
- setSockjsServer(server) {
45
+ setSockjsServer (server) {
46
46
  this.sockjs = server;
47
47
  }
48
48
 
49
- listenWatcherController() {
50
- this.on('all', (event, Path) => {
51
- let basename = path.basename(Path);
49
+ listenWatcherController () {
50
+ this.on("all", (event, Path) => {
51
+ const basename = path.basename(Path);
52
52
  let res = null;
53
53
  let name = null;
54
- let file = this.cwd + "/" + Path;
54
+ const file = `${this.cwd}/${Path}`;
55
55
  switch (event) {
56
56
  case "addDir":
57
57
  this.log(Path, "WARNING", event);
@@ -61,7 +61,7 @@ class Watcher extends nodefony.Watcher {
61
61
  this.log(Path, "INFO", event);
62
62
  try {
63
63
  switch (true) {
64
- // controller
64
+ // controller
65
65
  case this.bundle.regController.test(basename):
66
66
  res = this.bundle.regController.exec(basename);
67
67
  if (res) {
@@ -98,7 +98,7 @@ class Watcher extends nodefony.Watcher {
98
98
  res = this.bundle.regController.exec(basename);
99
99
  name = res[1];
100
100
  if (this.bundle.controllers[name]) {
101
- this.log("REMOVE CONTROLLER : " + Path, "INFO", event);
101
+ this.log(`REMOVE CONTROLLER : ${Path}`, "INFO", event);
102
102
  delete this.bundle.controllers[name];
103
103
  this.bundle.controllers[name] = null;
104
104
  }
@@ -110,8 +110,8 @@ class Watcher extends nodefony.Watcher {
110
110
  });
111
111
  }
112
112
 
113
- listenWatcherView() {
114
- this.on('all', async (event, Path) => {
113
+ listenWatcherView () {
114
+ this.on("all", async (event, Path) => {
115
115
  let file = null;
116
116
  switch (event) {
117
117
  case "addDir":
@@ -120,14 +120,14 @@ class Watcher extends nodefony.Watcher {
120
120
  case "add":
121
121
  case "change":
122
122
  this.log(Path, "INFO", event);
123
- file = this.cwd + "/" + Path;
123
+ file = `${this.cwd}/${Path}`;
124
124
  try {
125
- let fileClass = new nodefony.fileClass(file);
126
- let ele = await this.bundle.recompileTemplate(fileClass);
125
+ const fileClass = new nodefony.fileClass(file);
126
+ const ele = await this.bundle.recompileTemplate(fileClass);
127
127
  if (ele.basename === ".") {
128
- this.log("RECOMPILE Template : '" + this.bundle.name + "Bundle:" + "" + ":" + ele.name + "'", "INFO", event);
128
+ this.log(`${String(`RECOMPILE Template : '${this.bundle.name}Bundle:`)}:${ele.name}'`, "INFO", event);
129
129
  } else {
130
- this.log("RECOMPILE Template : '" + this.bundle.name + "Bundle:" + ele.basename + ":" + ele.name + "'", "INFO", event);
130
+ this.log(`RECOMPILE Template : '${this.bundle.name}Bundle:${ele.basename}:${ele.name}'`, "INFO", event);
131
131
  }
132
132
  if (this.sockjs) {
133
133
  switch (this.bundle.settings.type) {
@@ -137,7 +137,6 @@ class Watcher extends nodefony.Watcher {
137
137
  default:
138
138
  this.sockjs.sendWatcher("change", file);
139
139
  }
140
-
141
140
  }
142
141
  } catch (e) {
143
142
  this.log(e, "ERROR", event);
@@ -157,23 +156,21 @@ class Watcher extends nodefony.Watcher {
157
156
  break;
158
157
  case "unlink":
159
158
  this.log(Path, "INFO", event);
160
- file = this.cwd + "/" + Path;
161
- let parse = path.parse(file);
162
- if (parse.ext === "." + this.bundle.serviceTemplate.extention) {
163
- let name = parse.name;
164
- let directory = path.basename(parse.dir);
159
+ file = `${this.cwd}/${Path}`;
160
+ const parse = path.parse(file);
161
+ if (parse.ext === `.${this.bundle.serviceTemplate.extention}`) {
162
+ const {name} = parse;
163
+ const directory = path.basename(parse.dir);
165
164
  if (directory !== "views") {
166
165
  if (this.bundle.views[directory]) {
167
166
  if (this.bundle.views[directory][name]) {
168
167
  delete this.bundle.views[directory][name];
169
- this.log("REMOVE TEMPLATE : " + file, "INFO", event);
168
+ this.log(`REMOVE TEMPLATE : ${file}`, "INFO", event);
170
169
  }
171
170
  }
172
- } else {
173
- if (this.bundle.views["."][name]) {
174
- delete this.bundle.views["."][name];
175
- this.log("REMOVE TEMPLATE : " + file, "INFO", event);
176
- }
171
+ } else if (this.bundle.views["."][name]) {
172
+ delete this.bundle.views["."][name];
173
+ this.log(`REMOVE TEMPLATE : ${file}`, "INFO", event);
177
174
  }
178
175
  }
179
176
  break;
@@ -182,8 +179,8 @@ class Watcher extends nodefony.Watcher {
182
179
  });
183
180
  }
184
181
 
185
- listenWatcherI18n() {
186
- this.on('all', (event, Path) => {
182
+ listenWatcherI18n () {
183
+ this.on("all", (event, Path) => {
187
184
  let file = null;
188
185
  switch (event) {
189
186
  case "addDir":
@@ -192,13 +189,13 @@ class Watcher extends nodefony.Watcher {
192
189
  case "add":
193
190
  case "change":
194
191
  this.log(Path, "INFO", event);
195
- file = this.cwd + "/" + Path;
192
+ file = `${this.cwd}/${Path}`;
196
193
  try {
197
194
  const fileClass = new nodefony.fileClass(file);
198
195
  fileClass.matchName(this.bundle.regI18nFile);
199
- let domain = fileClass.match[1];
200
- let Locale = fileClass.match[2];
201
- //console.log(`${file} : ${domain} : ${Locale}`)
196
+ const domain = fileClass.match[1];
197
+ const Locale = fileClass.match[2];
198
+ // console.log(`${file} : ${domain} : ${Locale}`)
202
199
  this.bundle.translation.reader(fileClass.path, this.bundle, Locale, domain);
203
200
  if (this.sockjs) {
204
201
  this.sockjs.sendWatcher("change", file);
@@ -225,20 +222,21 @@ class Watcher extends nodefony.Watcher {
225
222
  }
226
223
  });
227
224
  }
228
- listenWatcherConfig() {
229
- this.on('all', (event, Path) => {
225
+
226
+ listenWatcherConfig () {
227
+ this.on("all", (event, Path) => {
230
228
  let file = null;
231
229
  switch (event) {
232
230
  case "addDir":
233
- this.log(Path, "INFO", event);
231
+ this.log(`Add dir ${Path}`, "INFO", event);
234
232
  break;
235
233
  case "add":
236
234
  case "change":
237
- this.log(Path, "INFO", event);
238
- let basename = path.basename(Path);
235
+ this.log(`${Path}`, "INFO", event);
236
+ const basename = path.basename(Path);
239
237
  let name = null;
240
238
  let res = null;
241
- file = this.cwd + "/" + Path;
239
+ file = `${this.cwd}/${Path}`;
242
240
  switch (true) {
243
241
  case this.bundle.regRoutingFile.test(basename):
244
242
  res = this.bundle.regRoutingFile.exec(basename);
@@ -260,7 +258,7 @@ class Watcher extends nodefony.Watcher {
260
258
  }
261
259
  break;
262
260
  case this.bundle.regWebpackCongig.test(basename):
263
- let myPath = path.resolve(this.bundle.path, Path);
261
+ const myPath = path.resolve(this.bundle.path, Path);
264
262
  delete require.cache[myPath];
265
263
  if (!this.bundle.webpackConfigFile) {
266
264
  return;
@@ -282,7 +280,17 @@ class Watcher extends nodefony.Watcher {
282
280
  });
283
281
  });
284
282
  }
285
-
283
+ break;
284
+ case (/config\.(js|yml|xml)/).test(basename):
285
+ this.kernel.readConfigFile.call(this.bundle, this.bundle.name, `${this.bundle.path}/${Path}`, (config) => {
286
+ if (config) {
287
+ this.setParameters(`bundles.${this.bundle.name}`, config);
288
+ this.bundle.settings = config;
289
+ }
290
+ if (this.sockjs) {
291
+ this.sockjs.sendWatcher("change", file);
292
+ }
293
+ });
286
294
  break;
287
295
  default:
288
296
  try {
@@ -309,7 +317,8 @@ class Watcher extends nodefony.Watcher {
309
317
  break;
310
318
  case "unlink":
311
319
  this.log(Path, "INFO", event);
312
- /*file = this.cwd + "/" + Path ;
320
+
321
+ /* file = this.cwd + "/" + Path ;
313
322
  try{
314
323
  const fileClass = new nodefony.fileClass(file);
315
324
  this.router.removeRoutes(fileClass.path);
@@ -320,8 +329,9 @@ class Watcher extends nodefony.Watcher {
320
329
  }
321
330
  });
322
331
  }
323
- listenWatcherServices() {
324
- this.on('all', async (event, Path) => {
332
+
333
+ listenWatcherServices () {
334
+ this.on("all", async (event, Path) => {
325
335
  switch (event) {
326
336
  case "addDir":
327
337
  this.log(Path, "INFO", event);
@@ -334,12 +344,12 @@ class Watcher extends nodefony.Watcher {
334
344
  case "change":
335
345
  try {
336
346
  this.log(Path, "INFO", event);
337
- let file = this.cwd + "/" + Path;
338
- let basename = path.basename(file);
347
+ const file = `${this.cwd}/${Path}`;
348
+ const basename = path.basename(file);
339
349
  switch (true) {
340
- // service
350
+ // service
341
351
  case this.bundle.regService.test(basename):
342
- let File = new nodefony.fileClass(file);
352
+ const File = new nodefony.fileClass(file);
343
353
  await this.bundle.reloadWatcherService(File, file, true);
344
354
  break;
345
355
  default:
@@ -1,7 +1,6 @@
1
- module.exports = nodefony.register("Entity", function () {
2
-
1
+ module.exports = nodefony.register("Entity", () => {
3
2
  class Entity extends nodefony.Service {
4
- constructor(bundle, name, orm, connectionName) {
3
+ constructor (bundle, name, orm, connectionName) {
5
4
  super(name, bundle.container);
6
5
  this.bundle = bundle;
7
6
  this.orm = this.get(orm);
@@ -9,9 +8,9 @@ module.exports = nodefony.register("Entity", function () {
9
8
  this.model = null;
10
9
  this.encoder = null;
11
10
  if (!this.orm) {
12
- throw new Error(this.name + " entity can't be registered ORM not found : " + orm);
11
+ throw new Error(`${this.name} entity can't be registered ORM not found : ${orm}`);
13
12
  }
14
- this.orm.on('onConnect', (connectionName, db) => {
13
+ this.orm.on("onConnect", (connectionName, db) => {
15
14
  if (connectionName === this.connectionName) {
16
15
  this.db = db;
17
16
  this.model = this.registerModel(this.db);
@@ -20,25 +19,25 @@ module.exports = nodefony.register("Entity", function () {
20
19
  });
21
20
  }
22
21
 
23
- logger(pci, severity, msgid, msg) {
22
+ logger (pci, severity, msgid, msg) {
24
23
  if (!msgid) {
25
- msgid = "Entity " + this.name;
24
+ msgid = `Entity ${this.name}`;
26
25
  }
27
26
  return super.logger(pci, severity, msgid, msg);
28
27
  }
29
28
 
30
- setEncoder(encoder) {
29
+ setEncoder (encoder) {
31
30
  if (encoder instanceof nodefony.Encoder) {
32
31
  return this.encoder = encoder;
33
32
  }
34
33
  throw new Error(`setEncoder : Entity ${this.name} encoder must be an instance of nodefony.Encoder`);
35
34
  }
36
35
 
37
- getEncoder() {
36
+ getEncoder () {
38
37
  return this.encoder;
39
38
  }
40
39
 
41
- hasEncoder() {
40
+ hasEncoder () {
42
41
  if (this.encoder instanceof nodefony.Encoder) {
43
42
  return true;
44
43
  }
@@ -48,13 +47,12 @@ module.exports = nodefony.register("Entity", function () {
48
47
  throw new Error(`setEncoder : Entity ${this.name} encoder must be an instance of nodefony.Encoder`);
49
48
  }
50
49
 
51
- async encode(value) {
50
+ async encode (value) {
52
51
  if (this.hasEncoder()) {
53
52
  return await this.encoder.encodePassword.apply(this.encoder, arguments);
54
53
  }
55
54
  return value;
56
55
  }
57
-
58
56
  }
59
57
 
60
58
  return Entity;
@@ -1,116 +1,136 @@
1
- const connectionMonitor = function ( /*name, db*/ ) {
2
- this.connectionNotification++;
3
- if (Object.keys(this.settings.connectors).length === this.connectionNotification) {
4
- process.nextTick(() => {
5
- if (this.kernel.type !== "CONSOLE") {
6
- this.log('onOrmReady', "INFO", `EVENTS ${this.name} ORM`);
7
- }
8
- //this.log('onOrmReady', "INFO", `EVENTS ${this.name} ORM`);
9
- this.fire('onOrmReady', this);
10
- this.ready = true;
11
- });
12
- }
13
- };
14
1
 
15
2
  class Orm extends nodefony.Service {
16
-
17
- constructor(name, container /*, kernel, autoLoader*/ ) {
18
- super(name, container);
19
- if ((this.kernel.debug === false && this.debug === true) || this.debug === undefined) {
3
+ constructor (name, container /* , kernel, autoLoader*/) {
4
+ super(name, container, null, {
5
+ events: {
6
+ nbListeners: 100
7
+ }
8
+ });
9
+ if (this.kernel.debug === false && this.debug === true || this.debug === undefined) {
20
10
  this.debug = this.kernel.debug;
21
11
  }
22
12
  this.entities = {};
23
13
  this.connections = {};
24
14
  this.connectionNotification = 0;
25
15
  this.ready = false;
16
+ this.prependOnceListener("onOrmReady", async () => {
17
+ if (this.bundle.booted) {
18
+ return await this.bundle.emitAsync("onReady", this.bundle)
19
+ .then(() => {
20
+ this.bundle.ready = true;
21
+ })
22
+ .catch((e) => {
23
+ throw e;
24
+ });
25
+ }
26
+ this.bundle.ready = true;
27
+ });
28
+ }
29
+
30
+ boot () {
31
+ this.on("onConnect", async (connection) => this.ormReady(connection));
32
+ this.on("onErrorConnection", async (connection, error) => this.ormReady(connection, error));
26
33
  }
27
34
 
28
- boot() {
29
- this.on("onConnect", connectionMonitor.bind(this));
30
- this.on("onErrorConnection", connectionMonitor.bind(this));
35
+ ormReady (connection, error = null) {
36
+ const nbConnectors = Object.keys(this.settings.connectors).length;
37
+ this.connectionNotification++;
38
+ if (error) {
39
+ this.log(error, "ERROR");
40
+ }
41
+ if (nbConnectors === this.connectionNotification) {
42
+ process.nextTick(async () => await this.emitAsync("onOrmReady", this)
43
+ .then(() => {
44
+ if (this.kernel.type !== "CONSOLE") {
45
+ this.log("onOrmReady", "INFO", `EVENTS ${this.name} ORM`);
46
+ }
47
+ this.connectionNotification = 0;
48
+ this.ready = true;
49
+ })
50
+ .catch((e) => {
51
+ this.log(e, "ERROR");
52
+ }));
53
+ }
31
54
  }
32
55
 
33
- log(pci, severity, msgid, msg) {
56
+ log (pci, severity, msgid, msg) {
34
57
  if (!msgid) {
35
- msgid = this.kernel.cli.clc.magenta(this.name + " ");
58
+ msgid = this.kernel.cli.clc.magenta(`${this.name} `);
36
59
  }
37
60
  return super.log(pci, severity, msgid, msg);
38
61
  }
39
62
 
40
- getConnection(name) {
63
+ getConnection (name) {
41
64
  if (this.connections[name]) {
42
65
  return this.connections[name].db;
43
66
  }
44
67
  return null;
45
68
  }
46
69
 
47
- getConnections(name) {
70
+ getConnections (name) {
48
71
  if (name) {
49
72
  return this.getConnection(name);
50
73
  }
51
74
  return this.connections;
52
75
  }
53
76
 
54
- getEntity(name) {
77
+ getEntity (name) {
55
78
  if (name) {
56
79
  if (name in this.entities) {
57
80
  return this.entities[name].model;
58
81
  }
59
82
  return null;
60
- } else {
61
- return this.entities;
62
83
  }
84
+ return this.entities;
63
85
  }
64
86
 
65
- getNodefonyEntity(name) {
87
+ getNodefonyEntity (name) {
66
88
  if (name) {
67
89
  if (name in this.entities) {
68
90
  return this.entities[name];
69
91
  }
70
92
  return null;
71
- } else {
72
- return this.entities;
73
93
  }
94
+ return this.entities;
74
95
  }
75
96
 
76
- getEntityTable(severity = "DEBUG") {
77
- let options = {
97
+ getEntityTable (severity = "DEBUG") {
98
+ const options = {
78
99
  head: [
79
- "NAME ENTITY",
80
- "BUNDLE",
81
- "CONNECTION"
82
- ]
100
+ "NAME ENTITY",
101
+ "BUNDLE",
102
+ "CONNECTION"
103
+ ]
83
104
  };
84
- let table = this.kernel.cli.displayTable(null, options);
85
- for (let entity in this.entities) {
86
- let tab = ["", "", ""];
105
+ const table = this.kernel.cli.displayTable(null, options);
106
+ for (const entity in this.entities) {
107
+ const tab = ["", "", ""];
87
108
  tab[0] = this.entities[entity].name;
88
109
  tab[1] = this.entities[entity].bundle.name;
89
110
  tab[2] = this.entities[entity].connectionName;
90
111
  table.push(tab);
91
112
  }
92
- let res = table.toString();
93
- this.log("ORM ENTITY LIST : \n" + res, severity);
113
+ const res = table.toString();
114
+ this.log(`ORM ENTITY LIST : \n${res}`, severity);
94
115
  return res;
95
-
96
116
  }
97
117
 
98
- setEntity(entity) {
118
+ setEntity (entity) {
99
119
  if (!entity) {
100
- throw new Error(this.name + " setEntity : entity is null ");
120
+ throw new Error(`${this.name} setEntity : entity is null `);
101
121
  }
102
122
  if (!(entity instanceof nodefony.Entity)) {
103
- throw new Error(this.name + " setEntity : not instance of nodefony.Entity");
123
+ throw new Error(`${this.name} setEntity : not instance of nodefony.Entity`);
104
124
  }
105
125
  if (this.entities[entity.name]) {
106
- throw new Error(this.name + " setEntity : Entity Already exist " + entity.name);
126
+ throw new Error(`${this.name} setEntity : Entity Already exist ${entity.name}`);
107
127
  }
108
128
  if (!entity.model) {
109
- throw new Error(this.name + " setEntity : Bundle : " + entity.bundle.name + " Model is undefined in Entity : " + entity.name);
129
+ throw new Error(`${this.name} setEntity : Bundle : ${entity.bundle.name} Model is undefined in Entity : ${entity.name}`);
110
130
  }
111
131
  this.entities[entity.name] = entity;
112
132
  if (this.kernel.type === "SERVER") {
113
- this.log(" REGISTER ENTITY : " + entity.name + " PROVIDE BUNDLE : " + entity.bundle.name, "INFO");
133
+ this.log(` REGISTER ENTITY : ${entity.name} PROVIDE BUNDLE : ${entity.bundle.name}`, "INFO");
114
134
  }
115
135
  }
116
136
  }