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
@@ -1,4 +1,4 @@
1
- //const regSpace = new RegExp("^[\\s]*(@.*)[\\s]*$");
1
+ // const regSpace = new RegExp("^[\\s]*(@.*)[\\s]*$");
2
2
  const regKeyValue = new RegExp("^[\\s]*([^=]*)[\\s]*=[\\s]*(([{]?).*[}]?)[\\s]*$");
3
3
  const regRouteBlock = new RegExp("^.*@Route[\\s]*\\(([^()]*)\\).*");
4
4
  const regMethodBlock = new RegExp("^.*@Method[\\s]*\\(([^()]*)\\).*");
@@ -10,9 +10,9 @@ const parseKeyValue = function (tab, obj) {
10
10
  if (!tab[i]) {
11
11
  continue;
12
12
  }
13
- let str = tab[i].replace(/(.*)\*$/, "$1");
14
- let res = regKeyValue.exec(str);
15
- let key = res[1].replace(/["' ]/g, "");
13
+ const str = tab[i].replace(/(.*)\*$/, "$1");
14
+ const res = regKeyValue.exec(str);
15
+ const key = res[1].replace(/["' ]/g, "");
16
16
  let value = res[2].replace(/["']/g, "");
17
17
  let tmp = null;
18
18
  tmp = parseInt(value, 10);
@@ -22,7 +22,7 @@ const parseKeyValue = function (tab, obj) {
22
22
  if (res) {
23
23
  if (res[3] === "{") {
24
24
  value = value.replace(/^[{]/, "").replace(/[}]$/, "");
25
- let mytab = value.split(",");
25
+ const mytab = value.split(",");
26
26
  parseKeyValue(mytab, obj[key] = {});
27
27
  continue;
28
28
  }
@@ -33,8 +33,7 @@ const parseKeyValue = function (tab, obj) {
33
33
  };
34
34
 
35
35
  class annotationRouting {
36
-
37
- constructor(annotation, bundle, pathFile) {
36
+ constructor (annotation, bundle, pathFile) {
38
37
  this.annotation = annotation;
39
38
  this.router = this.annotation.router;
40
39
  this.path = pathFile;
@@ -47,25 +46,25 @@ class annotationRouting {
47
46
  this.prefix = null;
48
47
  }
49
48
 
50
- setPatternController(name) {
51
- return this.bundleName + ":" + name + ":";
49
+ setPatternController (name) {
50
+ return `${this.bundleName}:${name}:`;
52
51
  }
53
52
 
54
- parse(comments) {
53
+ parse (comments) {
55
54
  if (comments.program && comments.program.class && comments.program.class.length) {
56
55
  try {
57
56
  if (comments.program.class && comments.program.class.length) {
58
- //console.log(comments.program.class);
59
- for (let myClass in comments.program.class) {
60
- let pattern = this.setPatternController(comments.program.class[myClass].name);
61
- let defaultNameController = comments.program.class[myClass].name;
62
- let eleClass = {
57
+ // console.log(comments.program.class);
58
+ for (const myClass in comments.program.class) {
59
+ const pattern = this.setPatternController(comments.program.class[myClass].name);
60
+ const defaultNameController = comments.program.class[myClass].name;
61
+ const eleClass = {
63
62
  type: "Class",
64
63
  comment: "",
65
64
  bundle: this.bundleName,
66
65
  defaultNameAction: null,
67
66
  patternController: pattern,
68
- defaultNameController: defaultNameController
67
+ defaultNameController
69
68
  };
70
69
  if (comments.program.class[myClass].comments && comments.program.class[myClass].comments.length) {
71
70
  comments.program.class[myClass].comments.map((ele) => {
@@ -79,7 +78,7 @@ class annotationRouting {
79
78
  }
80
79
  this.routings.push(eleClass);
81
80
  if (comments.program.class[myClass].actions && comments.program.class[myClass].actions.length) {
82
- for (let action in comments.program.class[myClass].actions) {
81
+ for (const action in comments.program.class[myClass].actions) {
83
82
  let defaultNameAction = null;
84
83
  let patternController = `${pattern}`;
85
84
  if (comments.program.class[myClass].actions[action].name) {
@@ -88,13 +87,13 @@ class annotationRouting {
88
87
  } else {
89
88
  continue;
90
89
  }
91
- let eleAction = {
90
+ const eleAction = {
92
91
  type: "Action",
93
92
  comment: "",
94
93
  bundle: this.bundleName,
95
- defaultNameAction: defaultNameAction,
96
- patternController: patternController,
97
- defaultNameController: defaultNameController
94
+ defaultNameAction,
95
+ patternController,
96
+ defaultNameController
98
97
  };
99
98
  if (comments.program.class[myClass].actions[action].comments && comments.program.class[myClass].actions[action].comments.length) {
100
99
  comments.program.class[myClass].actions[action].comments.map((ele) => {
@@ -121,12 +120,12 @@ class annotationRouting {
121
120
  * @Method ({"GET", "POST"})
122
121
  *
123
122
  */
124
- parseRouting() {
123
+ parseRouting () {
125
124
  for (let i = 0; i < this.routings.length; i++) {
126
- let obj = {};
125
+ const obj = {};
127
126
  switch (this.routings[i].type) {
128
127
  case "Class":
129
- let myobj = {};
128
+ const myobj = {};
130
129
  this.parseBlock(this.routings[i], myobj);
131
130
  this.prefix = myobj.pattern;
132
131
  this.host = myobj.host;
@@ -163,15 +162,15 @@ class annotationRouting {
163
162
  break;
164
163
  }
165
164
  }
166
- //console.log(this.obj)
165
+ // console.log(this.obj)
167
166
  return this.obj;
168
167
  }
169
168
 
170
- parseBlock(annotation, obj) {
169
+ parseBlock (annotation, obj) {
171
170
  if (annotation && annotation.comment) {
172
171
  try {
173
172
  let res = null;
174
- let cleanBlock = annotation.comment.replace(/\r?\n?/g, "");
173
+ const cleanBlock = annotation.comment.replace(/\r?\n?/g, "");
175
174
  switch (true) {
176
175
  case regRouteBlock.test(cleanBlock):
177
176
  res = regRouteBlock.exec(cleanBlock);
@@ -202,16 +201,16 @@ class annotationRouting {
202
201
  }
203
202
  }
204
203
 
205
- parseRoute(route, obj) {
206
- //let tab = route.replace(/[ ]|[\s]?\*[\s]?/g, "").split(",");
204
+ parseRoute (route, obj) {
205
+ // let tab = route.replace(/[ ]|[\s]?\*[\s]?/g, "").split(",");
207
206
  route = route.replace(/[ ]|[\s]?/g, "");
208
- let tab = route.split(",");
207
+ const tab = route.split(",");
209
208
  tab.map((ele, index) => {
210
- let res = ele.replace(/^\*([\s]?)/g, "$1");
209
+ const res = ele.replace(/^\*([\s]?)/g, "$1");
211
210
  tab[index] = res;
212
211
  return res;
213
212
  });
214
- let parser = Array.prototype.shift.call(tab).replace(/["' ]/g, "");
213
+ const parser = Array.prototype.shift.call(tab).replace(/["' ]/g, "");
215
214
  if (regKeyValue.test(parser)) {
216
215
  obj.pattern = "";
217
216
  tab.unshift(parser);
@@ -221,19 +220,19 @@ class annotationRouting {
221
220
  }
222
221
  }
223
222
 
224
- parseMethod(method, obj) {
223
+ parseMethod (method, obj) {
225
224
  obj.method = method.replace(/["'{} ]|[\s]?\*[\s]?/g, "").split(",");
226
225
  }
227
226
 
228
- parseHost(host, obj) {
227
+ parseHost (host, obj) {
229
228
  obj.host = host.replace(/["'{} ]|[\s]?\*[\s]?/g, "");
230
229
  }
231
230
 
232
- parseFirewall(firewall, obj) {
233
- let fw = {};
234
- let rep = firewall.replace(/["'{} ]|[\s]?\*[\s]?/g, "").split(",");
231
+ parseFirewall (firewall, obj) {
232
+ const fw = {};
233
+ const rep = firewall.replace(/["'{} ]|[\s]?\*[\s]?/g, "").split(",");
235
234
  for (let i = 0; i < rep.length; i++) {
236
- let spl = rep[i].split(":");
235
+ const spl = rep[i].split(":");
237
236
  if (spl.length) {
238
237
  let value = spl[1];
239
238
  if (spl[1] === "true") {
@@ -248,30 +247,29 @@ class annotationRouting {
248
247
  obj.firewalls = fw;
249
248
  }
250
249
 
251
- toString() {
250
+ toString () {
252
251
  return JSON.stringify(this.obj);
253
252
  }
254
253
  }
255
254
 
256
255
  class Annotation extends nodefony.Service {
257
-
258
- constructor(container) {
256
+ constructor (container) {
259
257
  super("Annotations", container);
260
- this.kernel.once("onBoot", async () =>{
258
+ this.kernel.once("onBoot", async () => {
261
259
  this.router = this.get("router");
262
260
  });
263
- //this.router = this.get("router");
261
+ // this.router = this.get("router");
264
262
  this.engine = nodefony.babylon;
265
263
  }
266
264
 
267
- parseController(fileContent, bundle, file) {
265
+ parseController (fileContent, bundle, file) {
268
266
  return this.engine.parseController(fileContent)
269
267
  .then((comments) => {
270
268
  try {
271
- let annotations = new annotationRouting(this, this.kernel.getBundle(bundle), file);
269
+ const annotations = new annotationRouting(this, this.kernel.getBundle(bundle), file);
272
270
  annotations.parse(comments);
273
271
  if (Object.keys(annotations.obj).length) {
274
- this.log("Bundle " + bundle + " Parse Controller Annotation : " + file, "DEBUG");
272
+ this.log(`Bundle ${bundle} Parse Controller Annotation : ${file}`, "DEBUG");
275
273
  }
276
274
  return annotations.obj;
277
275
  } catch (e) {
@@ -1,6 +1,5 @@
1
1
  class Api extends nodefony.Service {
2
-
3
- constructor(config, context = null) {
2
+ constructor (config, context = null) {
4
3
  const container = context ? context.container : kernel.container;
5
4
  super(config.name, container, false, config);
6
5
  this.name = null;
@@ -16,27 +15,27 @@ class Api extends nodefony.Service {
16
15
  }
17
16
  }
18
17
 
19
- parseArgs(config, context) {
18
+ parseArgs (config, context) {
20
19
  this.name = config.name;
21
20
  this.version = config.version;
22
21
  this.description = config.description;
23
22
  this.context = context;
24
23
  this.basePath = config.basePath;
25
- //throw new Error(`Constructor Api bad arguments : ${arguments}`);
24
+ // throw new Error(`Constructor Api bad arguments : ${arguments}`);
26
25
  }
27
26
 
28
27
  /**
29
28
  * @method logger
30
29
  */
31
- logger(pci, severity, msgid, msg) {
30
+ logger (pci, severity, msgid, msg) {
32
31
  if (!msgid) {
33
32
  msgid = clc.magenta(`API ${this.name} `);
34
33
  }
35
34
  return super.logger(pci, severity, msgid, msg);
36
35
  }
37
36
 
38
- getNodefonyInfo(service) {
39
- let obj = {
37
+ getNodefonyInfo (service) {
38
+ const obj = {
40
39
  debug: this.debug
41
40
  };
42
41
  switch (true) {
@@ -56,7 +55,6 @@ class Api extends nodefony.Service {
56
55
  }
57
56
  return obj;
58
57
  }
59
-
60
58
  }
61
59
 
62
60
  nodefony.Api = Api;
@@ -1,12 +1,11 @@
1
1
  const JsonApi = require(path.resolve(__dirname, "jsonApi.es6"));
2
- nodefony.graphql = require('graphql');
2
+ nodefony.graphql = require("graphql");
3
3
  nodefony["graphql-tools"] = {};
4
4
  nodefony["graphql-tools"].schema = require("@graphql-tools/schema");
5
- nodefony["graphql-tools"].merge = require('@graphql-tools/merge');
5
+ nodefony["graphql-tools"].merge = require("@graphql-tools/merge");
6
6
 
7
7
  class graphqlApi extends JsonApi {
8
-
9
- constructor(config = {}, context = null) {
8
+ constructor (config = {}, context = null) {
10
9
  let schema = null;
11
10
  let rootValue = null;
12
11
  let contextValue = null;
@@ -36,23 +35,23 @@ class graphqlApi extends JsonApi {
36
35
  }
37
36
  }
38
37
 
39
- static mergeSchemas(options) {
38
+ static mergeSchemas (options) {
40
39
  return nodefony["graphql-tools"].schema.mergeSchemas(options);
41
40
  }
42
41
 
43
- static mergeTypeDefs(options) {
42
+ static mergeTypeDefs (options) {
44
43
  return nodefony["graphql-tools"].merge.mergeTypeDefs(options);
45
44
  }
46
45
 
47
- static mergeResolvers(tab) {
46
+ static mergeResolvers (tab) {
48
47
  return nodefony["graphql-tools"].merge.mergeResolvers(tab);
49
48
  }
50
49
 
51
- static makeExecutableSchema(options) {
50
+ static makeExecutableSchema (options) {
52
51
  return nodefony["graphql-tools"].schema.makeExecutableSchema(options);
53
52
  }
54
53
 
55
- async query(query, variables = null, operationName = null, fieldResolver = null, typeResolver = null) {
54
+ async query (query, variables = null, operationName = null, fieldResolver = null, typeResolver = null) {
56
55
  const controller = this.get("controller");
57
56
  this.json.operationName = operationName;
58
57
  try {
@@ -62,11 +61,11 @@ class graphqlApi extends JsonApi {
62
61
  rootValue: this.rootValue || controller,
63
62
  contextValue: this.contextValue || controller,
64
63
  variableValues: variables,
65
- operationName: operationName,
66
- fieldResolver: fieldResolver,
67
- typeResolver: typeResolver
64
+ operationName,
65
+ fieldResolver,
66
+ typeResolver
68
67
  };
69
- let res = await nodefony.graphql.graphql(conf);
68
+ const res = await nodefony.graphql.graphql(conf);
70
69
  if (res.errors && res.errors.length) {
71
70
  throw res.errors;
72
71
  }
@@ -76,31 +75,32 @@ class graphqlApi extends JsonApi {
76
75
  }
77
76
  }
78
77
 
79
- buildSchema(schema) {
78
+ buildSchema (schema) {
80
79
  this.schema = nodefony.graphql.buildSchema(schema);
81
80
  return this.schema;
82
81
  }
83
82
 
84
- printSchema() {
83
+ printSchema () {
85
84
  if (this.schema) {
86
- return nodefony.graphql.printSchema(this.schema)
85
+ return nodefony.graphql.printSchema(this.schema);
87
86
  }
88
- return ''
87
+ return "";
89
88
  }
90
89
 
91
- setSchema(schema) {
90
+ setSchema (schema) {
92
91
  this.schema = schema;
93
92
  return this.schema;
94
93
  }
95
- setRootValue(rootValue) {
94
+
95
+ setRootValue (rootValue) {
96
96
  this.rootValue = rootValue;
97
97
  return this.rootValue;
98
98
  }
99
- setContextValue(contextValue) {
99
+
100
+ setContextValue (contextValue) {
100
101
  this.contextValue = contextValue;
101
102
  return this.contextValue;
102
103
  }
103
-
104
104
  }
105
105
 
106
106
  nodefony.api.Graphql = graphqlApi;
@@ -1,18 +1,17 @@
1
1
  const Api = require(path.resolve(__dirname, "api.es6"));
2
2
  class JsonApi extends Api {
3
-
4
- constructor(config, context = null) {
3
+ constructor (config, context = null) {
5
4
  super(config, context);
6
5
  this.json = {
7
6
  api: this.name,
8
7
  version: this.version,
9
- //result: null,
8
+ // result: null,
10
9
  message: "",
11
10
  messageId: null
12
- //error: null,
13
- //errorCode: null,
14
- //errorType: null,
15
- //debug: this.debug
11
+ // error: null,
12
+ // errorCode: null,
13
+ // errorType: null,
14
+ // debug: this.debug
16
15
  };
17
16
 
18
17
  this.setResultName(this.options.resultName);
@@ -23,18 +22,16 @@ class JsonApi extends Api {
23
22
  this.json.url = this.context.url || "";
24
23
  this.json.method = this.context.method;
25
24
  this.json.scheme = this.context.scheme;
26
- this.context.once("onError", (e) => {
27
- return this.renderError(e);
28
- });
25
+ this.context.once("onError", (e) => this.renderError(e));
29
26
  }
30
27
  }
31
28
 
32
- setResultName(name = "result", value = null) {
29
+ setResultName (name = "result", value = null) {
33
30
  this.resultName = name;
34
31
  this.json[this.resultName] = value;
35
32
  }
36
33
 
37
- isError(e, json = {}) {
34
+ isError (e, json = {}) {
38
35
  if (nodefony.isArray(e)) {
39
36
  const errorType = nodefony.Error.isError(e[0]);
40
37
  if (errorType) {
@@ -71,44 +68,43 @@ class JsonApi extends Api {
71
68
  return json;
72
69
  }
73
70
 
74
- sanitize(payload, json) {
71
+ sanitize (payload, json) {
75
72
  this.isError(payload, json);
76
73
  if (json.error) {
77
74
  return json[this.resultName] = null;
78
- } else {
79
- if (!json.severity) {
80
- json.severity = "INFO";
81
- }
82
- if (!json.code) {
83
- if (this.context && this.context.response) {
84
- json.code = this.context.response.getStatusCode();
85
- } else {
86
- json.code = 200;
87
- }
88
- }
89
- if (!json.message && this.context && this.context.response) {
90
- json.message = this.context.response.getStatusMessage(json.code);
75
+ }
76
+ if (!json.severity) {
77
+ json.severity = "INFO";
78
+ }
79
+ if (!json.code) {
80
+ if (this.context && this.context.response) {
81
+ json.code = this.context.response.getStatusCode();
82
+ } else {
83
+ json.code = 200;
91
84
  }
92
- return json[this.resultName] = payload;
93
85
  }
86
+ if (!json.message && this.context && this.context.response) {
87
+ json.message = this.context.response.getStatusMessage(json.code);
88
+ }
89
+ return json[this.resultName] = payload;
94
90
  }
95
91
 
96
- render(payload, code, message = "", severity = null, messageID = null) {
92
+ render (payload, code, message = "", severity = null, messageID = null) {
97
93
  try {
98
- let json = nodefony.extend(this.json, {
99
- severity: severity,
100
- code: code,
101
- message: message,
94
+ const json = nodefony.extend(this.json, {
95
+ severity,
96
+ code,
97
+ message,
102
98
  messageId: messageID
103
99
  });
104
100
  this.sanitize(payload, json);
105
101
  if (this.context) {
106
102
  const controller = this.context.get("controller");
107
- if(!controller){
103
+ if (!controller) {
108
104
  return json;
109
- //this.log(payload,"ERROR")
110
- //this.log(`Controller not found`,"ERROR")
111
- //throw new Error(`Controller not found`);
105
+ // this.log(payload,"ERROR")
106
+ // this.log(`Controller not found`,"ERROR")
107
+ // throw new Error(`Controller not found`);
112
108
  }
113
109
  if (this.debug) {
114
110
  json.pdu = new nodefony.PDU({
@@ -127,12 +123,12 @@ class JsonApi extends Api {
127
123
  }
128
124
  }
129
125
 
130
- renderAsync(payload, code, message = "", severity = null, messageID = null) {
126
+ renderAsync (payload, code, message = "", severity = null, messageID = null) {
131
127
  try {
132
- let json = nodefony.extend(this.json, {
133
- severity: severity,
134
- code: code,
135
- message: message,
128
+ const json = nodefony.extend(this.json, {
129
+ severity,
130
+ code,
131
+ message,
136
132
  messageId: messageID
137
133
  });
138
134
  this.sanitize(payload, json);
@@ -156,8 +152,8 @@ class JsonApi extends Api {
156
152
  }
157
153
 
158
154
 
159
- renderPdu(payload, code, message = "", severity = "INFO", messageID = null, api = this.name) {
160
- let json = nodefony.extend({
155
+ renderPdu (payload, code, message = "", severity = "INFO", messageID = null, api = this.name) {
156
+ const json = nodefony.extend({
161
157
 
162
158
  }, this.json);
163
159
  this.sanitize(payload, json, severity);
@@ -172,10 +168,9 @@ class JsonApi extends Api {
172
168
  return new nodefony.PDU(json, severity, api, messageID, message);
173
169
  }
174
170
 
175
- renderError(error, code, message = "", severity = "ERROR", messageID = null) {
171
+ renderError (error, code, message = "", severity = "ERROR", messageID = null) {
176
172
  return this.render(error, code, message, severity, messageID);
177
173
  }
178
-
179
174
  }
180
175
 
181
176
  nodefony.api.Json = JsonApi;
@@ -1,12 +1,11 @@
1
1
  const JsonApi = require(path.resolve(__dirname, "jsonApi.es6"));
2
2
  class openApi extends JsonApi {
3
-
4
- constructor(config, context = null) {
3
+ constructor (config, context = null) {
5
4
  super(config, context);
6
5
  }
7
6
 
8
7
  // schema api management
9
- setSchema(config = {}, entity = null) {
8
+ setSchema (config = {}, entity = null) {
10
9
  if (config.openapi) {
11
10
  this.schema = new nodefony.openApiSchema(this, config, entity);
12
11
  return this.schema;
@@ -14,13 +13,13 @@ class openApi extends JsonApi {
14
13
  throw new nodefony.Error("schema api not supported ");
15
14
  }
16
15
 
17
- getSchema(config = {}, entity = null) {
16
+ getSchema (config = {}, entity = null) {
18
17
  try {
19
18
  if (config) {
20
19
  this.setSchema(config, entity);
21
20
  }
22
21
  if (this.schema) {
23
- let conf = this.schema.getConfig();
22
+ const conf = this.schema.getConfig();
24
23
  if (conf.components && conf.components.schemas) {
25
24
  conf.components.schemas[this.name] = this.getOpenApiSchema();
26
25
  }
@@ -32,9 +31,9 @@ class openApi extends JsonApi {
32
31
  }
33
32
  }
34
33
 
35
- renderSchema(config = {}, entity = null, code = 200) {
34
+ renderSchema (config = {}, entity = null, code = 200) {
36
35
  try {
37
- let conf = this.getSchema(config, entity);
36
+ const conf = this.getSchema(config, entity);
38
37
  if (this.context) {
39
38
  const controller = this.context.get("controller");
40
39
  return controller.renderJson(conf, code);
@@ -45,7 +44,7 @@ class openApi extends JsonApi {
45
44
  }
46
45
  }
47
46
 
48
- getOpenApiSchema() {
47
+ getOpenApiSchema () {
49
48
  return {
50
49
  type: "object",
51
50
  properties: {
@@ -111,7 +110,7 @@ class openApi extends JsonApi {
111
110
  },
112
111
  code: {
113
112
  type: "integer",
114
- format: "int32",
113
+ format: "int32"
115
114
  }
116
115
  },
117
116
  example: `
@@ -134,8 +133,7 @@ class openApi extends JsonApi {
134
133
  `
135
134
  };
136
135
  }
137
-
138
136
  }
139
137
 
140
138
  nodefony.api.OpenApi = openApi;
141
- module.exports = openApi;
139
+ module.exports = openApi;