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.
- package/CHANGELOG.md +534 -8028
- package/README.md +33 -30
- package/autoloader.es6 +46 -48
- package/builder.es6 +66 -76
- package/cli/builder/bundles/bundle.js +57 -63
- package/cli/builder/bundles/controller.js +34 -38
- package/cli/builder/bundles/users-bundle/Command/fixtureTask.js +11 -12
- package/cli/builder/bundles/users-bundle/Command/usersCommand.js +23 -24
- package/cli/builder/bundles/users-bundle/Entity/mongoose/userEntity.js +25 -30
- package/cli/builder/bundles/users-bundle/Entity/sequelize/userEntity.js +42 -31
- package/cli/builder/bundles/users-bundle/Fixtures/users.js +24 -26
- package/cli/builder/bundles/users-bundle/Fixtures/usersFixtures.js +28 -29
- package/cli/builder/bundles/users-bundle/Resources/config/config.js +4 -3
- package/cli/builder/bundles/users-bundle/Resources/config/routing.js +2 -2
- package/cli/builder/bundles/users-bundle/Resources/config/security.js +9 -8
- package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.dev.config.js +3 -3
- package/cli/builder/bundles/users-bundle/Resources/config/webpack/webpack.prod.config.js +4 -3
- package/cli/builder/bundles/users-bundle/Resources/config/webpack.config.js +74 -75
- package/cli/builder/bundles/users-bundle/Resources/scss/awesome/font-awesome.config.js +9 -9
- package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/login.js +13 -13
- package/cli/builder/bundles/users-bundle/Resources/swagger/openapi/users.js +14 -14
- package/cli/builder/bundles/users-bundle/controller/api/graphql/graphqlController.js +13 -15
- package/cli/builder/bundles/users-bundle/controller/api/graphql/userResolver.js +29 -29
- package/cli/builder/bundles/users-bundle/controller/api/graphql/usertype.js +2 -2
- package/cli/builder/bundles/users-bundle/controller/api/openapi/loginApiController.js +34 -36
- package/cli/builder/bundles/users-bundle/controller/api/openapi/restUserController.js +32 -36
- package/cli/builder/bundles/users-bundle/controller/loginController.js +30 -34
- package/cli/builder/bundles/users-bundle/controller/usersController.js +54 -60
- package/cli/builder/bundles/users-bundle/package.json +27 -25
- package/cli/builder/bundles/users-bundle/pnpm-lock.yaml +4262 -0
- package/cli/builder/bundles/users-bundle/readme.md +7 -7
- package/cli/builder/bundles/users-bundle/services/usersService.js +97 -102
- package/cli/builder/bundles/users-bundle/src/providers/mongoose/userProvider.js +6 -8
- package/cli/builder/bundles/users-bundle/src/providers/sequelize/userProvider.js +9 -10
- package/cli/builder/bundles/users-bundle/tests/loginTest.js +119 -70
- package/cli/builder/bundles/users-bundle/usersBundle.js +2 -3
- package/cli/builder/microService/microService.js +139 -141
- package/cli/builder/microService/skeletons/package.json +23 -22
- package/cli/builder/project/project.js +228 -181
- package/cli/builder/project/skeletons/README.md +33 -30
- package/cli/builder/project/skeletons/bin/dev-deploy.sh +5 -0
- package/cli/builder/project/skeletons/bin/prod-deploy.sh +3 -0
- package/cli/builder/project/skeletons/config/config.js.skeleton +1 -0
- package/cli/builder/project/skeletons/config/pm2.config.js.skeleton +41 -17
- package/cli/builder/project/skeletons/eslintignore.skeleton +15 -0
- package/cli/builder/project/skeletons/eslintrc.js.skeleton +97 -0
- package/cli/builder/project/skeletons/gitignore.skeleton +1 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.37.entity-user.js +137 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.38.entity-session.js +97 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.39.entity-requests.js +115 -0
- package/cli/builder/project/skeletons/migrations/2022.12.25T17.37.40.entity-jwts.js +97 -0
- package/cli/builder/project/skeletons/migrations/migrations.skeleton.js +0 -2
- package/cli/builder/project/skeletons/package.json.twig +70 -0
- package/cli/builder/react/reactBuilder.js +59 -65
- package/cli/builder/sandbox/sandBoxBuilder.js +132 -134
- package/cli/builder/skeletons/app/appKernel.js +120 -2
- package/cli/builder/skeletons/config/config.js +1 -1
- package/cli/builder/skeletons/config/nodefony/framework-bundle.js +2 -1
- package/cli/builder/skeletons/config/nodefony/http-bundle.js +1 -0
- package/cli/builder/skeletons/config/nodefony/mongoose-bundle.js +38 -12
- package/cli/builder/skeletons/config/nodefony/monitoring-bundle.js +21 -2
- package/cli/builder/skeletons/config/nodefony/sequelize-bundle.js +122 -13
- package/cli/builder/skeletons/package.json.twig +57 -0
- package/cli/builder/skeletons/unittest/testFile.js +44 -45
- package/cli/builder/vue/skeletons/vue.config.js +84 -10
- package/cli/builder/vue/vueBuilder.js +116 -114
- package/cli/generate/generate.es6 +38 -39
- package/cli/install/install.js +45 -58
- package/cli/sequelize/sequelize.js +50 -39
- package/cli/start.js +353 -347
- package/cli/tools/pm2.es6 +55 -57
- package/cli/tools/tools.es6 +36 -37
- package/cli.es6 +280 -228
- package/container.es6 +51 -59
- package/error.es6 +25 -27
- package/fileClass.es6 +53 -55
- package/finder/file.es6 +5 -4
- package/finder/fileResult.es6 +23 -22
- package/finder/finder2.es6 +46 -54
- package/finder.es6 +88 -97
- package/kernel/annotations/annotations.es6 +44 -46
- package/kernel/api/api.es6 +6 -8
- package/kernel/api/graphqlApi.es6 +21 -21
- package/kernel/api/jsonApi.es6 +40 -45
- package/kernel/api/openApi.es6 +9 -11
- package/kernel/api/schemas/openApiSchema.js +61 -32
- package/kernel/babylon.es6 +31 -38
- package/kernel/bundle.es6 +252 -220
- package/kernel/cliKernel.es6 +157 -170
- package/kernel/command.es6 +17 -20
- package/kernel/commands/nodefonyCommand.es6 +111 -58
- package/kernel/commands/tasks/bundlesTask.es6 +14 -19
- package/kernel/controllers/controller.es6 +167 -180
- package/kernel/fixture.es6 +4 -7
- package/kernel/injections/injections.es6 +97 -103
- package/kernel/kernel.es6 +476 -384
- package/kernel/kernelWatcher.es6 +64 -54
- package/kernel/orm/entity.es6 +10 -12
- package/kernel/orm/orm.es6 +68 -48
- package/kernel/reader.es6 +45 -47
- package/kernel/security/encoder.es6 +8 -6
- package/kernel/security/factories/factory.es6 +34 -37
- package/kernel/security/factories/passeportFactory.es6 +13 -14
- package/kernel/security/provider.es6 +11 -13
- package/kernel/security/providers/chainProvider.es6 +13 -28
- package/kernel/security/providers/memoryProvider.es6 +7 -11
- package/kernel/security/providers/providerManager.es6 +11 -14
- package/kernel/security/providers/userEntityProvider.es6 +7 -8
- package/kernel/security/role.es6 +3 -3
- package/kernel/security/secureArea.es6 +143 -149
- package/kernel/security/tokens/token.es6 +30 -32
- package/kernel/security/user.es6 +19 -19
- package/kernel/serviceRealTime.es6 +5 -7
- package/kernel/services/connectionsService.es6 +20 -22
- package/kernel/services/cron/cronService.es6 +14 -16
- package/kernel/task.es6 +20 -26
- package/kernel/templates.es6 +4 -5
- package/kernel/templating/twig.es6 +56 -47
- package/kernel/tests/cliTest.js +7 -11
- package/kernel/tests/containerTest.js +25 -37
- package/kernel/tests/kernelTest.js +9 -16
- package/nodefony.es6 +279 -256
- package/notificationsCenter.es6 +28 -20
- package/package.json +40 -40
- package/protocol.es6 +19 -21
- package/protocols/bayeux.es6 +35 -38
- package/protocols/jsonRpc/jsonrpc.es6 +12 -14
- package/result.es6 +11 -12
- package/service.es6 +62 -62
- package/syslog/pdu.es6 +99 -91
- package/syslog/syslog.es6 +101 -102
- package/watcher.es6 +21 -20
- package/cli/builder/project/skeletons/jshintignore.skeleton +0 -1
- package/cli/builder/project/skeletons/jshintrc.skeleton +0 -60
- package/cli/builder/project/skeletons/package.json.skeleton +0 -52
- 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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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
|
|
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 (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
|
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 (
|
|
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
|
-
|
|
90
|
+
const eleAction = {
|
|
92
91
|
type: "Action",
|
|
93
92
|
comment: "",
|
|
94
93
|
bundle: this.bundleName,
|
|
95
|
-
defaultNameAction
|
|
96
|
-
patternController
|
|
97
|
-
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
|
-
|
|
125
|
+
const obj = {};
|
|
127
126
|
switch (this.routings[i].type) {
|
|
128
127
|
case "Class":
|
|
129
|
-
|
|
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
|
-
|
|
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
|
-
|
|
207
|
+
const tab = route.split(",");
|
|
209
208
|
tab.map((ele, index) => {
|
|
210
|
-
|
|
209
|
+
const res = ele.replace(/^\*([\s]?)/g, "$1");
|
|
211
210
|
tab[index] = res;
|
|
212
211
|
return res;
|
|
213
212
|
});
|
|
214
|
-
|
|
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
|
-
|
|
234
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
272
|
+
this.log(`Bundle ${bundle} Parse Controller Annotation : ${file}`, "DEBUG");
|
|
275
273
|
}
|
|
276
274
|
return annotations.obj;
|
|
277
275
|
} catch (e) {
|
package/kernel/api/api.es6
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
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(
|
|
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
|
|
66
|
-
fieldResolver
|
|
67
|
-
typeResolver
|
|
64
|
+
operationName,
|
|
65
|
+
fieldResolver,
|
|
66
|
+
typeResolver
|
|
68
67
|
};
|
|
69
|
-
|
|
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
|
-
|
|
94
|
+
|
|
95
|
+
setRootValue (rootValue) {
|
|
96
96
|
this.rootValue = rootValue;
|
|
97
97
|
return this.rootValue;
|
|
98
98
|
}
|
|
99
|
-
|
|
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;
|
package/kernel/api/jsonApi.es6
CHANGED
|
@@ -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
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
99
|
-
severity
|
|
100
|
-
code
|
|
101
|
-
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
|
-
|
|
133
|
-
severity
|
|
134
|
-
code
|
|
135
|
-
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
|
-
|
|
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;
|
package/kernel/api/openApi.es6
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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;
|