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,10 +1,10 @@
|
|
|
1
|
-
const myRequest = require(
|
|
1
|
+
const myRequest = require("request");
|
|
2
2
|
const {
|
|
3
3
|
graphql
|
|
4
|
-
} = require(
|
|
4
|
+
} = require("graphql");
|
|
5
5
|
|
|
6
6
|
class Controller extends nodefony.Service {
|
|
7
|
-
constructor(container, context) {
|
|
7
|
+
constructor (container, context) {
|
|
8
8
|
super(null, container, container.get("notificationsCenter"));
|
|
9
9
|
this.setContext(context);
|
|
10
10
|
this.graphql = graphql;
|
|
@@ -12,10 +12,10 @@ class Controller extends nodefony.Service {
|
|
|
12
12
|
this.httpKernel = this.get("httpKernel");
|
|
13
13
|
this.mailer = this.get("mailer");
|
|
14
14
|
this.router = this.get("router");
|
|
15
|
-
this.serviceTemplating = this.get(
|
|
15
|
+
this.serviceTemplating = this.get("templating");
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
setContext(context) {
|
|
18
|
+
setContext (context) {
|
|
19
19
|
this.context = context;
|
|
20
20
|
this.method = this.getMethod();
|
|
21
21
|
this.response = this.context.response;
|
|
@@ -32,31 +32,34 @@ class Controller extends nodefony.Service {
|
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
getContext() {
|
|
35
|
+
getContext () {
|
|
36
36
|
return this.context;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
setContextJson(encoding) {
|
|
39
|
+
setContextJson (encoding) {
|
|
40
40
|
return this.context.setContextJson(encoding);
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
|
|
43
|
+
setJsonContext (encoding) {
|
|
43
44
|
return this.context.setContextJson(encoding);
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
+
|
|
47
|
+
setContextHtml (encoding) {
|
|
46
48
|
return this.context.setContextHtml(encoding);
|
|
47
49
|
}
|
|
48
|
-
|
|
50
|
+
|
|
51
|
+
setHtmlContext (encoding) {
|
|
49
52
|
return this.context.setContextHtml(encoding);
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
log(pci, severity, msgid, msg) {
|
|
55
|
+
log (pci, severity, msgid, msg) {
|
|
53
56
|
if (!msgid) {
|
|
54
57
|
msgid = `CONTROLLER : ${this.bundle.name}Bundle:${this.name}`;
|
|
55
58
|
}
|
|
56
59
|
return super.log(pci, severity, msgid, msg);
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
clean() {
|
|
62
|
+
clean () {
|
|
60
63
|
delete this.session;
|
|
61
64
|
delete this.context;
|
|
62
65
|
delete this.response;
|
|
@@ -71,70 +74,67 @@ class Controller extends nodefony.Service {
|
|
|
71
74
|
super.clean();
|
|
72
75
|
}
|
|
73
76
|
|
|
74
|
-
getLocale() {
|
|
77
|
+
getLocale () {
|
|
75
78
|
return this.context.locale;
|
|
76
79
|
}
|
|
77
80
|
|
|
78
|
-
getRequest() {
|
|
81
|
+
getRequest () {
|
|
79
82
|
return this.request;
|
|
80
83
|
}
|
|
81
84
|
|
|
82
|
-
getResponse(content) {
|
|
85
|
+
getResponse (content) {
|
|
83
86
|
if (content) {
|
|
84
87
|
this.response.setBody(content);
|
|
85
88
|
}
|
|
86
89
|
return this.response;
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
getMethod() {
|
|
92
|
+
getMethod () {
|
|
90
93
|
return this.context.getMethod();
|
|
91
94
|
}
|
|
92
95
|
|
|
93
|
-
startSession(sessionContext) {
|
|
94
|
-
|
|
96
|
+
startSession (sessionContext) {
|
|
97
|
+
const sessionService = this.get("sessions");
|
|
95
98
|
// is subRequest
|
|
96
|
-
if (this.context.parent){
|
|
97
|
-
return this.getSession()
|
|
99
|
+
if (this.context.parent) {
|
|
100
|
+
return this.getSession();
|
|
98
101
|
}
|
|
99
|
-
if (!this.context.requestEnded) {
|
|
102
|
+
if (!this.context.requestEnded || this.context.security) {
|
|
100
103
|
return this.sessionAutoStart = sessionService.setAutoStart(sessionContext);
|
|
101
|
-
} else {
|
|
102
|
-
return sessionService.start(this.context, sessionContext);
|
|
103
104
|
}
|
|
105
|
+
return sessionService.start(this.context, sessionContext);
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
getSession() {
|
|
108
|
+
getSession () {
|
|
107
109
|
return this.context.session || null;
|
|
108
110
|
}
|
|
109
111
|
|
|
110
|
-
getFlashBag(key) {
|
|
111
|
-
|
|
112
|
+
getFlashBag (key) {
|
|
113
|
+
const session = this.getSession();
|
|
112
114
|
if (session) {
|
|
113
115
|
return session.getFlashBag(key);
|
|
114
|
-
} else {
|
|
115
|
-
this.log("getFlashBag session not started !", "ERROR");
|
|
116
|
-
return null;
|
|
117
116
|
}
|
|
117
|
+
this.log("getFlashBag session not started !", "ERROR");
|
|
118
|
+
return null;
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
setFlashBag(key, value) {
|
|
121
|
-
|
|
121
|
+
setFlashBag (key, value) {
|
|
122
|
+
const session = this.getSession();
|
|
122
123
|
if (session) {
|
|
123
124
|
return session.setFlashBag(key, value);
|
|
124
|
-
} else {
|
|
125
|
-
return null;
|
|
126
125
|
}
|
|
126
|
+
return null;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
addFlash(key, value) {
|
|
129
|
+
addFlash (key, value) {
|
|
130
130
|
return this.setFlashBag(key, value);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
setCsrfToken(name, options) {
|
|
133
|
+
setCsrfToken (name, options) {
|
|
134
134
|
return this.context.setCsrfToken(name, options);
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
setContentType(mime, encoding) {
|
|
137
|
+
setContentType (mime, encoding) {
|
|
138
138
|
if (this.context.method !== "websoket") {
|
|
139
139
|
let type = null;
|
|
140
140
|
if (encoding) {
|
|
@@ -146,33 +146,33 @@ class Controller extends nodefony.Service {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
getORM() {
|
|
149
|
+
getORM () {
|
|
150
150
|
return this.getOrm();
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
getOrm() {
|
|
153
|
+
getOrm () {
|
|
154
154
|
return this.get(this.kernel.settings.orm);
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
getConnection(name) {
|
|
157
|
+
getConnection (name) {
|
|
158
158
|
if (name) {
|
|
159
159
|
return this.getOrm().getConnection(name);
|
|
160
160
|
}
|
|
161
161
|
throw new Error("getConnection must have name");
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
getEntity(name) {
|
|
164
|
+
getEntity (name) {
|
|
165
165
|
return this.getOrm().getEntity(name);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
getNodefonyEntity(name) {
|
|
168
|
+
getNodefonyEntity (name) {
|
|
169
169
|
return this.getOrm().getNodefonyEntity(name);
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
getTransaction(name) {
|
|
172
|
+
getTransaction (name) {
|
|
173
173
|
const orm = this.getOrm();
|
|
174
174
|
if (!orm) {
|
|
175
|
-
throw new Error(
|
|
175
|
+
throw new Error("Orm not found");
|
|
176
176
|
}
|
|
177
177
|
try {
|
|
178
178
|
return orm.getTransaction(name);
|
|
@@ -181,10 +181,10 @@ class Controller extends nodefony.Service {
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
async startTransaction(name) {
|
|
184
|
+
async startTransaction (name) {
|
|
185
185
|
const orm = this.getOrm();
|
|
186
186
|
if (!orm) {
|
|
187
|
-
throw new Error(
|
|
187
|
+
throw new Error("Orm not found");
|
|
188
188
|
}
|
|
189
189
|
try {
|
|
190
190
|
return await orm.startTransaction(name);
|
|
@@ -193,7 +193,7 @@ class Controller extends nodefony.Service {
|
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
sendMail() {
|
|
196
|
+
sendMail () {
|
|
197
197
|
if (!this.mailer) {
|
|
198
198
|
throw new Error("mail-bundle not registred !");
|
|
199
199
|
}
|
|
@@ -223,18 +223,16 @@ class Controller extends nodefony.Service {
|
|
|
223
223
|
* this.log(e, "ERROR");
|
|
224
224
|
* });
|
|
225
225
|
**/
|
|
226
|
-
push(asset, headers, options) {
|
|
226
|
+
push (asset, headers, options) {
|
|
227
227
|
if (this.context.type === "HTTP2" && this.context.pushAllowed) {
|
|
228
228
|
let assetPublic = null;
|
|
229
229
|
if (!headers) {
|
|
230
230
|
headers = {};
|
|
231
|
-
assetPublic = asset.replace(this.bundle.publicPath,
|
|
231
|
+
assetPublic = asset.replace(this.bundle.publicPath, `/${this.bundle.bundleName}`);
|
|
232
|
+
headers.path = assetPublic;
|
|
233
|
+
} else if (!headers.path) {
|
|
234
|
+
assetPublic = asset.replace(this.bundle.publicPath, `/${this.bundle.bundleName}`);
|
|
232
235
|
headers.path = assetPublic;
|
|
233
|
-
} else {
|
|
234
|
-
if (!headers.path) {
|
|
235
|
-
assetPublic = asset.replace(this.bundle.publicPath, "/" + this.bundle.bundleName);
|
|
236
|
-
headers.path = assetPublic;
|
|
237
|
-
}
|
|
238
236
|
}
|
|
239
237
|
try {
|
|
240
238
|
return this.response.push(asset, headers, options)
|
|
@@ -244,27 +242,25 @@ class Controller extends nodefony.Service {
|
|
|
244
242
|
return error;
|
|
245
243
|
});
|
|
246
244
|
} catch (e) {
|
|
247
|
-
return new Promise((resolve, reject) =>
|
|
248
|
-
return reject(e);
|
|
249
|
-
});
|
|
245
|
+
return new Promise((resolve, reject) => reject(e));
|
|
250
246
|
}
|
|
251
247
|
} else {
|
|
252
|
-
return new Promise((resolve
|
|
248
|
+
return new Promise((resolve /* , reject*/) => {
|
|
253
249
|
if (this.context.type !== "HTTP2") {
|
|
254
|
-
//let error = `HTTP2 push : ${asset} method must be called with HTTP2 request !!!!`;
|
|
255
|
-
//this.log(error, "WARNING");
|
|
250
|
+
// let error = `HTTP2 push : ${asset} method must be called with HTTP2 request !!!!`;
|
|
251
|
+
// this.log(error, "WARNING");
|
|
256
252
|
return resolve();
|
|
257
|
-
//return reject();
|
|
253
|
+
// return reject();
|
|
258
254
|
}
|
|
259
|
-
|
|
255
|
+
const error = `HTTP2 Server push : ${asset} not pushAllowed `;
|
|
260
256
|
this.log(error, "WARNING");
|
|
261
257
|
return resolve();
|
|
262
|
-
//return reject(new Error("HTTP2 Server push not pushAllowed"));
|
|
258
|
+
// return reject(new Error("HTTP2 Server push not pushAllowed"));
|
|
263
259
|
});
|
|
264
260
|
}
|
|
265
261
|
}
|
|
266
262
|
|
|
267
|
-
renderResponse(data, status, headers) {
|
|
263
|
+
renderResponse (data, status, headers) {
|
|
268
264
|
return new Promise((resolve, reject) => {
|
|
269
265
|
try {
|
|
270
266
|
return resolve(this.renderResponseSync(data, status, headers));
|
|
@@ -274,11 +270,9 @@ class Controller extends nodefony.Service {
|
|
|
274
270
|
});
|
|
275
271
|
}
|
|
276
272
|
|
|
277
|
-
renderResponseAsync(data, status, headers) {
|
|
273
|
+
renderResponseAsync (data, status, headers) {
|
|
278
274
|
return this.renderResponse(data, status, headers)
|
|
279
|
-
.then((result) =>
|
|
280
|
-
return this.context.send(result);
|
|
281
|
-
})
|
|
275
|
+
.then((result) => this.context.send(result))
|
|
282
276
|
.catch((e) => {
|
|
283
277
|
this.log(e, "ERROR");
|
|
284
278
|
this.createException(e);
|
|
@@ -286,7 +280,7 @@ class Controller extends nodefony.Service {
|
|
|
286
280
|
});
|
|
287
281
|
}
|
|
288
282
|
|
|
289
|
-
renderResponseSync(data, status, headers) {
|
|
283
|
+
renderResponseSync (data, status, headers) {
|
|
290
284
|
try {
|
|
291
285
|
this.response.setBody(data);
|
|
292
286
|
if (headers) {
|
|
@@ -303,13 +297,9 @@ class Controller extends nodefony.Service {
|
|
|
303
297
|
}
|
|
304
298
|
|
|
305
299
|
|
|
306
|
-
renderJson(obj, status, headers) {
|
|
300
|
+
renderJson (obj, status, headers) {
|
|
307
301
|
if (nodefony.isPromise(obj)) {
|
|
308
|
-
return obj.then(result =>
|
|
309
|
-
return this.renderJsonSync(result, status, headers);
|
|
310
|
-
}).catch(error => {
|
|
311
|
-
return this.createException(error);
|
|
312
|
-
});
|
|
302
|
+
return obj.then((result) => this.renderJsonSync(result, status, headers)).catch((error) => this.createException(error));
|
|
313
303
|
}
|
|
314
304
|
return new Promise((resolve, reject) => {
|
|
315
305
|
try {
|
|
@@ -320,18 +310,17 @@ class Controller extends nodefony.Service {
|
|
|
320
310
|
});
|
|
321
311
|
}
|
|
322
312
|
|
|
323
|
-
renderJsonAsync(obj, status, headers) {
|
|
313
|
+
renderJsonAsync (obj, status, headers) {
|
|
324
314
|
return this.renderJson(obj, status, headers)
|
|
325
|
-
.then((result) =>
|
|
326
|
-
|
|
327
|
-
}).catch((e) => {
|
|
315
|
+
.then((result) => this.context.send(result))
|
|
316
|
+
.catch((e) => {
|
|
328
317
|
this.log(e, "ERROR");
|
|
329
318
|
this.createException(e);
|
|
330
319
|
return e;
|
|
331
320
|
});
|
|
332
321
|
}
|
|
333
322
|
|
|
334
|
-
renderJsonSync(obj, status, headers) {
|
|
323
|
+
renderJsonSync (obj, status, headers) {
|
|
335
324
|
let data = null;
|
|
336
325
|
try {
|
|
337
326
|
data = JSON.stringify(obj);
|
|
@@ -351,10 +340,9 @@ class Controller extends nodefony.Service {
|
|
|
351
340
|
this.log(e, "ERROR");
|
|
352
341
|
throw e;
|
|
353
342
|
}
|
|
354
|
-
|
|
355
343
|
}
|
|
356
344
|
|
|
357
|
-
async render(view, param) {
|
|
345
|
+
async render (view, param) {
|
|
358
346
|
if (!this.response) {
|
|
359
347
|
throw new Error("WARNING ASYNC !! RESPONSE ALREADY SENT BY EXPCEPTION FRAMEWORK");
|
|
360
348
|
}
|
|
@@ -365,7 +353,7 @@ class Controller extends nodefony.Service {
|
|
|
365
353
|
}
|
|
366
354
|
}
|
|
367
355
|
|
|
368
|
-
renderSync(view, param) {
|
|
356
|
+
renderSync (view, param) {
|
|
369
357
|
if (!this.response) {
|
|
370
358
|
throw new Error("WARNING ASYNC !! RESPONSE ALREADY SENT BY EXPCEPTION FRAMEWORK", "WARNING");
|
|
371
359
|
}
|
|
@@ -376,18 +364,17 @@ class Controller extends nodefony.Service {
|
|
|
376
364
|
}
|
|
377
365
|
}
|
|
378
366
|
|
|
379
|
-
renderAsync(view, param) {
|
|
367
|
+
renderAsync (view, param) {
|
|
380
368
|
return this.render(view, param)
|
|
381
|
-
.then((result) =>
|
|
382
|
-
|
|
383
|
-
}).catch((e) => {
|
|
369
|
+
.then((result) => this.context.send(result))
|
|
370
|
+
.catch((e) => {
|
|
384
371
|
this.log(e, "ERROR");
|
|
385
372
|
this.createException(e);
|
|
386
373
|
return e;
|
|
387
374
|
});
|
|
388
375
|
}
|
|
389
376
|
|
|
390
|
-
renderView(view, param) {
|
|
377
|
+
renderView (view, param) {
|
|
391
378
|
return new Promise((resolve, reject) => {
|
|
392
379
|
try {
|
|
393
380
|
return resolve(this.renderViewSync(view, param));
|
|
@@ -397,7 +384,7 @@ class Controller extends nodefony.Service {
|
|
|
397
384
|
});
|
|
398
385
|
}
|
|
399
386
|
|
|
400
|
-
renderViewSync(view, param) {
|
|
387
|
+
renderViewSync (view, param) {
|
|
401
388
|
let res = null;
|
|
402
389
|
let templ = null;
|
|
403
390
|
let extendParam = null;
|
|
@@ -419,13 +406,13 @@ class Controller extends nodefony.Service {
|
|
|
419
406
|
}
|
|
420
407
|
}
|
|
421
408
|
|
|
422
|
-
renderRawView(Path, param) {
|
|
409
|
+
renderRawView (Path, param) {
|
|
423
410
|
let extendParam = this.httpKernel.extendTemplate(param, this.context);
|
|
424
411
|
try {
|
|
425
412
|
this.serviceTemplating.renderFile(Path, extendParam, (error, result) => {
|
|
426
413
|
if (error || result === undefined) {
|
|
427
414
|
if (!error) {
|
|
428
|
-
error = new Error(
|
|
415
|
+
error = new Error(`ERROR PARSING TEMPLATE :${Path.path}`);
|
|
429
416
|
}
|
|
430
417
|
extendParam = null;
|
|
431
418
|
throw error;
|
|
@@ -447,10 +434,10 @@ class Controller extends nodefony.Service {
|
|
|
447
434
|
return this.response.body;
|
|
448
435
|
}
|
|
449
436
|
|
|
450
|
-
renderHtmlFile(Path) {
|
|
437
|
+
renderHtmlFile (Path) {
|
|
451
438
|
return new Promise((resolve, reject) => {
|
|
452
439
|
try {
|
|
453
|
-
|
|
440
|
+
const file = this.getFile(Path);
|
|
454
441
|
return resolve(file.readAsync());
|
|
455
442
|
} catch (e) {
|
|
456
443
|
return reject(e);
|
|
@@ -458,7 +445,7 @@ class Controller extends nodefony.Service {
|
|
|
458
445
|
});
|
|
459
446
|
}
|
|
460
447
|
|
|
461
|
-
renderTwigFile(Path, param) {
|
|
448
|
+
renderTwigFile (Path, param) {
|
|
462
449
|
return new Promise((resolve, reject) => {
|
|
463
450
|
let extendParam = null;
|
|
464
451
|
try {
|
|
@@ -474,10 +461,10 @@ class Controller extends nodefony.Service {
|
|
|
474
461
|
});
|
|
475
462
|
}
|
|
476
463
|
|
|
477
|
-
renderXmlFile(Path, mime, encoding) {
|
|
464
|
+
renderXmlFile (Path, mime, encoding) {
|
|
478
465
|
return new Promise((resolve, reject) => {
|
|
479
466
|
try {
|
|
480
|
-
|
|
467
|
+
const file = this.getFile(Path);
|
|
481
468
|
this.setContentType(mime || "application/xml", encoding);
|
|
482
469
|
return resolve(file.readAsync());
|
|
483
470
|
} catch (e) {
|
|
@@ -486,20 +473,19 @@ class Controller extends nodefony.Service {
|
|
|
486
473
|
});
|
|
487
474
|
}
|
|
488
475
|
|
|
489
|
-
getFile(file) {
|
|
476
|
+
getFile (file) {
|
|
490
477
|
try {
|
|
491
478
|
let File = null;
|
|
492
479
|
if (file instanceof nodefony.fileClass) {
|
|
493
480
|
File = file;
|
|
481
|
+
} else if (typeof file === "string") {
|
|
482
|
+
// eslint-disable-next-line new-cap
|
|
483
|
+
File = new nodefony.fileClass(file);
|
|
494
484
|
} else {
|
|
495
|
-
|
|
496
|
-
File = new nodefony.fileClass(file);
|
|
497
|
-
} else {
|
|
498
|
-
throw new Error("File argument bad type for getFile :" + typeof file);
|
|
499
|
-
}
|
|
485
|
+
throw new Error(`File argument bad type for getFile :${typeof file}`);
|
|
500
486
|
}
|
|
501
487
|
if (File.type !== "File") {
|
|
502
|
-
throw new Error(
|
|
488
|
+
throw new Error(`getFile bad type for :${file}`);
|
|
503
489
|
}
|
|
504
490
|
return File;
|
|
505
491
|
} catch (e) {
|
|
@@ -507,12 +493,12 @@ class Controller extends nodefony.Service {
|
|
|
507
493
|
}
|
|
508
494
|
}
|
|
509
495
|
|
|
510
|
-
streamFile(file, headers, options={}) {
|
|
511
|
-
options.autoClose =false;
|
|
496
|
+
streamFile (file, headers, options = {}) {
|
|
497
|
+
options.autoClose = false;
|
|
512
498
|
try {
|
|
513
499
|
const streamFile = fs.createReadStream(this.getFile(file).path, options);
|
|
514
500
|
streamFile.on("open", () => {
|
|
515
|
-
//console.log("open")
|
|
501
|
+
// console.log("open")
|
|
516
502
|
try {
|
|
517
503
|
this.response.response.writeHead(this.response.statusCode, headers);
|
|
518
504
|
streamFile.pipe(this.response.response, {
|
|
@@ -525,11 +511,11 @@ class Controller extends nodefony.Service {
|
|
|
525
511
|
}
|
|
526
512
|
});
|
|
527
513
|
streamFile.on("end", () => {
|
|
528
|
-
//console.log("end")
|
|
514
|
+
// console.log("end")
|
|
529
515
|
try {
|
|
530
516
|
if (streamFile) {
|
|
531
517
|
streamFile.unpipe(this.response.response);
|
|
532
|
-
//console.trace(streamFile)
|
|
518
|
+
// console.trace(streamFile)
|
|
533
519
|
if (streamFile.fd) {
|
|
534
520
|
fs.close(streamFile.fd);
|
|
535
521
|
}
|
|
@@ -543,7 +529,7 @@ class Controller extends nodefony.Service {
|
|
|
543
529
|
}
|
|
544
530
|
});
|
|
545
531
|
streamFile.on("close", () => {
|
|
546
|
-
//console.log("close")
|
|
532
|
+
// console.log("close")
|
|
547
533
|
if (streamFile) {
|
|
548
534
|
streamFile.unpipe(this.response.response);
|
|
549
535
|
if (streamFile.fd) {
|
|
@@ -561,7 +547,7 @@ class Controller extends nodefony.Service {
|
|
|
561
547
|
}
|
|
562
548
|
throw error;
|
|
563
549
|
});
|
|
564
|
-
streamFile.on(
|
|
550
|
+
streamFile.on("close", () => {
|
|
565
551
|
if (streamFile) {
|
|
566
552
|
streamFile.unpipe(this.response.response);
|
|
567
553
|
if (streamFile.fd) {
|
|
@@ -579,16 +565,16 @@ class Controller extends nodefony.Service {
|
|
|
579
565
|
}
|
|
580
566
|
}
|
|
581
567
|
|
|
582
|
-
renderFileDownload(file, options, headers) {
|
|
583
|
-
//console.log("renderFileDownload :" + file.path)
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
568
|
+
renderFileDownload (file, options, headers) {
|
|
569
|
+
// console.log("renderFileDownload :" + file.path)
|
|
570
|
+
const File = this.getFile(file);
|
|
571
|
+
const length = File.stats.size;
|
|
572
|
+
const head = nodefony.extend({
|
|
573
|
+
"Content-Disposition": `attachment; filename="${File.name}"`,
|
|
574
|
+
"Content-Length": length,
|
|
589
575
|
"Expires": "0",
|
|
590
|
-
|
|
591
|
-
|
|
576
|
+
"Content-Description": "File Transfer",
|
|
577
|
+
"Content-Type": File.mimeType || "application/octet-stream"
|
|
592
578
|
}, headers || {});
|
|
593
579
|
try {
|
|
594
580
|
this.streamFile(File, head, options);
|
|
@@ -597,44 +583,44 @@ class Controller extends nodefony.Service {
|
|
|
597
583
|
}
|
|
598
584
|
}
|
|
599
585
|
|
|
600
|
-
renderMediaStream(file, options, headers) {
|
|
601
|
-
|
|
586
|
+
renderMediaStream (file, options, headers) {
|
|
587
|
+
const File = this.getFile(file);
|
|
602
588
|
if (!options) {
|
|
603
589
|
options = {};
|
|
604
590
|
}
|
|
605
591
|
this.response.setEncoding("binary");
|
|
606
|
-
|
|
607
|
-
|
|
592
|
+
const {range} = this.request.headers;
|
|
593
|
+
const length = File.stats.size;
|
|
608
594
|
let head = null;
|
|
609
595
|
let value = null;
|
|
610
596
|
if (range) {
|
|
611
|
-
//console.log("HEADER = " + range);
|
|
612
|
-
|
|
613
|
-
//console.log(parts)
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
//console.log("start :" + start) ;
|
|
620
|
-
//console.log("end :" + end) ;
|
|
597
|
+
// console.log("HEADER = " + range);
|
|
598
|
+
const parts = range.replace(/bytes=/, "").split("-");
|
|
599
|
+
// console.log(parts)
|
|
600
|
+
const partialstart = parts[0];
|
|
601
|
+
const partialend = parts[1];
|
|
602
|
+
const start = parseInt(partialstart, 10);
|
|
603
|
+
const end = partialend ? parseInt(partialend, 10) : length - 1;
|
|
604
|
+
const chunksize = end - start + 1;
|
|
605
|
+
// console.log("start :" + start) ;
|
|
606
|
+
// console.log("end :" + end) ;
|
|
621
607
|
value = nodefony.extend(options, {
|
|
622
|
-
start
|
|
623
|
-
end
|
|
608
|
+
start,
|
|
609
|
+
end
|
|
624
610
|
});
|
|
625
|
-
//console.log('RANGE: ' + start + ' - ' + end + ' = ' + chunksize);
|
|
611
|
+
// console.log('RANGE: ' + start + ' - ' + end + ' = ' + chunksize);
|
|
626
612
|
head = nodefony.extend({
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
613
|
+
"Content-Range": `bytes ${start}-${end}/${length}`,
|
|
614
|
+
"Accept-Ranges": "bytes",
|
|
615
|
+
"Content-Length": chunksize,
|
|
616
|
+
"Content-Type": File.mimeType || "application/octet-stream"
|
|
631
617
|
}, headers);
|
|
632
618
|
this.response.setStatusCode(206);
|
|
633
619
|
} else {
|
|
634
620
|
head = nodefony.extend({
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
621
|
+
"Content-Type": File.mimeType || "application/octet-stream",
|
|
622
|
+
"Content-Length": length,
|
|
623
|
+
"Content-Disposition": ` inline; filename="${File.name}"`
|
|
638
624
|
}, headers);
|
|
639
625
|
}
|
|
640
626
|
// streamFile
|
|
@@ -645,31 +631,32 @@ class Controller extends nodefony.Service {
|
|
|
645
631
|
}
|
|
646
632
|
}
|
|
647
633
|
|
|
648
|
-
createNotFoundException(message) {
|
|
634
|
+
createNotFoundException (message) {
|
|
649
635
|
throw new nodefony.httpError(message, 404, this.container);
|
|
650
636
|
}
|
|
651
637
|
|
|
652
|
-
createUnauthorizedException(message) {
|
|
638
|
+
createUnauthorizedException (message) {
|
|
653
639
|
throw new nodefony.securityError(message, 401, null, this.context);
|
|
654
640
|
}
|
|
655
641
|
|
|
656
|
-
createException(message, code = 500) {
|
|
642
|
+
createException (message, code = 500) {
|
|
657
643
|
throw new nodefony.httpError(message, code, this.container);
|
|
658
644
|
}
|
|
659
|
-
|
|
645
|
+
|
|
646
|
+
renderException (message, code = 500) {
|
|
660
647
|
throw new nodefony.httpError(message, code, this.container);
|
|
661
648
|
}
|
|
662
649
|
|
|
663
|
-
createAccessDeniedException(message, code = 403) {
|
|
650
|
+
createAccessDeniedException (message, code = 403) {
|
|
664
651
|
throw new nodefony.authorizationError(message, code, this.context);
|
|
665
652
|
}
|
|
666
653
|
|
|
667
|
-
createSecurityException(message, code = 401) {
|
|
654
|
+
createSecurityException (message, code = 401) {
|
|
668
655
|
throw new nodefony.securityError(message, code, this.context.security, this.context);
|
|
669
656
|
}
|
|
670
657
|
|
|
671
658
|
|
|
672
|
-
isGranted(role) {
|
|
659
|
+
isGranted (role) {
|
|
673
660
|
try {
|
|
674
661
|
return this.context.is_granted(role);
|
|
675
662
|
} catch (e) {
|
|
@@ -677,15 +664,15 @@ class Controller extends nodefony.Service {
|
|
|
677
664
|
}
|
|
678
665
|
}
|
|
679
666
|
|
|
680
|
-
is_granted(role) {
|
|
667
|
+
is_granted (role) {
|
|
681
668
|
return this.isGranted(role);
|
|
682
669
|
}
|
|
683
670
|
|
|
684
|
-
translate() {
|
|
671
|
+
translate () {
|
|
685
672
|
return this.context.translation.trans.apply(this.context.translation, arguments);
|
|
686
673
|
}
|
|
687
674
|
|
|
688
|
-
redirect(url, status, headers) {
|
|
675
|
+
redirect (url, status, headers) {
|
|
689
676
|
if (!this.context.redirect) {
|
|
690
677
|
throw new Error("subRequest can't redirect request");
|
|
691
678
|
}
|
|
@@ -699,7 +686,7 @@ class Controller extends nodefony.Service {
|
|
|
699
686
|
}
|
|
700
687
|
}
|
|
701
688
|
|
|
702
|
-
redirectToRoute(route, variables, status, headers) {
|
|
689
|
+
redirectToRoute (route, variables, status, headers) {
|
|
703
690
|
if (!route) {
|
|
704
691
|
throw new Error("Redirect error no route !!!");
|
|
705
692
|
}
|
|
@@ -710,65 +697,65 @@ class Controller extends nodefony.Service {
|
|
|
710
697
|
}
|
|
711
698
|
}
|
|
712
699
|
|
|
713
|
-
redirectHttps(status) {
|
|
700
|
+
redirectHttps (status) {
|
|
714
701
|
return this.context.redirectHttps(status || 301);
|
|
715
702
|
}
|
|
716
703
|
|
|
717
|
-
forward(name, param) {
|
|
718
|
-
//let pattern = Array.prototype.shift.call(arguments);
|
|
719
|
-
//let data = Array.prototype.slice.call(arguments);
|
|
720
|
-
//let subRequest = new nodefony.subRequest(this, pattern);
|
|
721
|
-
//return subRequest.handle(data);
|
|
722
|
-
|
|
704
|
+
forward (name, param) {
|
|
705
|
+
// let pattern = Array.prototype.shift.call(arguments);
|
|
706
|
+
// let data = Array.prototype.slice.call(arguments);
|
|
707
|
+
// let subRequest = new nodefony.subRequest(this, pattern);
|
|
708
|
+
// return subRequest.handle(data);
|
|
709
|
+
const resolver = this.router.resolveName(this.context, name);
|
|
723
710
|
return resolver.callController(param, true);
|
|
724
711
|
}
|
|
725
712
|
|
|
726
|
-
getUser() {
|
|
713
|
+
getUser () {
|
|
727
714
|
return this.context.getUser();
|
|
728
715
|
}
|
|
729
716
|
|
|
730
|
-
getToken() {
|
|
717
|
+
getToken () {
|
|
731
718
|
return this.context.getToken();
|
|
732
719
|
}
|
|
733
720
|
|
|
734
|
-
isAjax() {
|
|
721
|
+
isAjax () {
|
|
735
722
|
return this.getRequest().isAjax();
|
|
736
723
|
}
|
|
737
724
|
|
|
738
|
-
hideDebugBar() {
|
|
725
|
+
hideDebugBar () {
|
|
739
726
|
this.context.showDebugBar = false;
|
|
740
727
|
}
|
|
741
728
|
|
|
742
|
-
getRoute() {
|
|
729
|
+
getRoute () {
|
|
743
730
|
return this.context.resolver.getRoute();
|
|
744
731
|
}
|
|
745
732
|
|
|
746
|
-
logout() {
|
|
747
|
-
if (this.security) {
|
|
733
|
+
logout () {
|
|
734
|
+
if (this.context.security) {
|
|
748
735
|
this.log(`Logout Controller : ${this.name}`, "DEBUG");
|
|
749
|
-
return this.security.logout(this.context)
|
|
750
|
-
.then(() =>
|
|
751
|
-
return true;
|
|
752
|
-
})
|
|
736
|
+
return this.context.security.logout(this.context)
|
|
737
|
+
.then(() => true)
|
|
753
738
|
.catch((e) => {
|
|
754
739
|
throw e;
|
|
755
740
|
});
|
|
756
741
|
}
|
|
757
742
|
return new Promise((resolve, reject) => {
|
|
758
743
|
if (this.context.session) {
|
|
759
|
-
|
|
744
|
+
this.context.session.invalidate()
|
|
760
745
|
.then(() => {
|
|
761
|
-
|
|
762
|
-
})
|
|
746
|
+
resolve(true);
|
|
747
|
+
})
|
|
748
|
+
.catch((e) => {
|
|
763
749
|
this.log(e, "ERROR");
|
|
764
|
-
|
|
750
|
+
reject(e);
|
|
765
751
|
});
|
|
752
|
+
return;
|
|
766
753
|
}
|
|
767
|
-
|
|
754
|
+
resolve(true);
|
|
768
755
|
});
|
|
769
756
|
}
|
|
770
757
|
|
|
771
|
-
generateUrl(name, variables, absolute) {
|
|
758
|
+
generateUrl (name, variables, absolute) {
|
|
772
759
|
try {
|
|
773
760
|
if (absolute) {
|
|
774
761
|
return this.context.generateAbsoluteUrl(name, variables);
|
|
@@ -779,7 +766,7 @@ class Controller extends nodefony.Service {
|
|
|
779
766
|
}
|
|
780
767
|
}
|
|
781
768
|
|
|
782
|
-
generateAbsoluteUrl(name, variables) {
|
|
769
|
+
generateAbsoluteUrl (name, variables) {
|
|
783
770
|
try {
|
|
784
771
|
return this.context.generateAbsoluteUrl(name, variables);
|
|
785
772
|
} catch (e) {
|
|
@@ -787,8 +774,8 @@ class Controller extends nodefony.Service {
|
|
|
787
774
|
}
|
|
788
775
|
}
|
|
789
776
|
|
|
790
|
-
htmlMdParser(content, options) {
|
|
791
|
-
|
|
777
|
+
htmlMdParser (content, options) {
|
|
778
|
+
const markdown = require("markdown-it")(nodefony.extend({
|
|
792
779
|
html: true
|
|
793
780
|
}, options));
|
|
794
781
|
try {
|