taon 19.0.54 → 19.0.56
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/README.md +160 -160
- package/bin/start.js +279 -279
- package/bin/taon +6 -6
- package/bin/taon-debug +5 -5
- package/bin/taon-debug-brk +5 -5
- package/browser/README.md +24 -24
- package/browser/fesm2022/taon.mjs +271 -156
- package/browser/fesm2022/taon.mjs.map +1 -1
- package/browser/lib/config/controller-config.d.ts +22 -0
- package/{websql/lib/decorators/classes → browser/lib/config}/controller-options.d.ts +6 -1
- package/browser/lib/config/method-config.d.ts +39 -0
- package/browser/lib/config/param-config.d.ts +9 -0
- package/browser/lib/decorators/classes/controller-decorator.d.ts +1 -1
- package/browser/lib/decorators/http/http-methods-decorators.d.ts +14 -1
- package/browser/lib/endpoint-context.d.ts +3 -1
- package/browser/lib/helpers/class-helpers.d.ts +5 -2
- package/browser/lib/helpers/clone-obj.d.ts +2 -0
- package/browser/lib/helpers/taon-helpers.d.ts +5 -5
- package/browser/lib/models.d.ts +1 -32
- package/browser/lib/symbols.d.ts +0 -2
- package/browser/lib/validators.d.ts +2 -2
- package/browser/package.json +1 -1
- package/lib/base-classes/base-class.js +2 -16
- package/lib/base-classes/base-class.js.map +1 -1
- package/lib/base-classes/base-controller.js +4 -1
- package/lib/base-classes/base-controller.js.map +1 -1
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/config/controller-config.d.ts +21 -0
- package/lib/config/controller-config.js +34 -0
- package/lib/config/controller-config.js.map +1 -0
- package/lib/{decorators/classes → config}/controller-options.d.ts +6 -1
- package/lib/config/controller-options.js +8 -0
- package/lib/config/controller-options.js.map +1 -0
- package/lib/config/method-config.d.ts +38 -0
- package/lib/config/method-config.js +12 -0
- package/lib/config/method-config.js.map +1 -0
- package/lib/config/param-config.d.ts +8 -0
- package/lib/config/param-config.js +8 -0
- package/lib/config/param-config.js.map +1 -0
- package/lib/decorators/classes/controller-decorator.d.ts +1 -1
- package/lib/decorators/classes/controller-decorator.js +6 -1
- package/lib/decorators/classes/controller-decorator.js.map +1 -1
- package/lib/decorators/classes/middleware-decorator.js.map +1 -1
- package/lib/decorators/classes/provider-decorator.js.map +1 -1
- package/lib/decorators/decorator-abstract-opt.js +0 -1
- package/lib/decorators/decorator-abstract-opt.js.map +1 -1
- package/lib/decorators/http/http-methods-decorators.d.ts +14 -1
- package/lib/decorators/http/http-methods-decorators.js +3 -10
- package/lib/decorators/http/http-methods-decorators.js.map +1 -1
- package/lib/decorators/http/http-params-decorators.js +10 -16
- package/lib/decorators/http/http-params-decorators.js.map +1 -1
- package/lib/endpoint-context.d.ts +3 -1
- package/lib/endpoint-context.js +244 -144
- package/lib/endpoint-context.js.map +1 -1
- package/lib/helpers/class-helpers.d.ts +5 -2
- package/lib/helpers/class-helpers.js +47 -35
- package/lib/helpers/class-helpers.js.map +1 -1
- package/lib/helpers/clone-obj.d.ts +1 -0
- package/lib/helpers/clone-obj.js +22 -0
- package/lib/helpers/clone-obj.js.map +1 -0
- package/lib/helpers/taon-helpers.d.ts +5 -5
- package/lib/helpers/taon-helpers.js.map +1 -1
- package/lib/models.d.ts +1 -32
- package/lib/models.js +0 -33
- package/lib/models.js.map +1 -1
- package/lib/symbols.d.ts +0 -2
- package/lib/symbols.js +5 -7
- package/lib/symbols.js.map +1 -1
- package/lib/ui/index.js +2 -2
- package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
- package/lib/validators.d.ts +2 -2
- package/lib/validators.js.map +1 -1
- package/package.json +1 -1
- package/scss/vars.scss +6 -6
- package/websql/README.md +24 -24
- package/websql/fesm2022/taon.mjs +272 -157
- package/websql/fesm2022/taon.mjs.map +1 -1
- package/websql/lib/config/controller-config.d.ts +22 -0
- package/{browser/lib/decorators/classes → websql/lib/config}/controller-options.d.ts +6 -1
- package/websql/lib/config/method-config.d.ts +39 -0
- package/websql/lib/config/param-config.d.ts +9 -0
- package/websql/lib/decorators/classes/controller-decorator.d.ts +1 -1
- package/websql/lib/decorators/http/http-methods-decorators.d.ts +14 -1
- package/websql/lib/endpoint-context.d.ts +3 -1
- package/websql/lib/helpers/class-helpers.d.ts +5 -2
- package/websql/lib/helpers/clone-obj.d.ts +2 -0
- package/websql/lib/helpers/taon-helpers.d.ts +5 -5
- package/websql/lib/models.d.ts +1 -32
- package/websql/lib/symbols.d.ts +0 -2
- package/websql/lib/validators.d.ts +2 -2
- package/websql/package.json +1 -1
- package/browser/lib/decorators/classes/controller-config.d.ts +0 -10
- package/lib/decorators/classes/controller-config.d.ts +0 -9
- package/lib/decorators/classes/controller-config.js +0 -11
- package/lib/decorators/classes/controller-config.js.map +0 -1
- package/lib/decorators/classes/controller-options.js +0 -16
- package/lib/decorators/classes/controller-options.js.map +0 -1
- package/lib/env.d.ts +0 -2
- package/lib/env.js +0 -7
- package/lib/env.js.map +0 -1
- package/lib/storage.d.ts +0 -1
- package/lib/storage.js +0 -6
- package/lib/storage.js.map +0 -1
- package/lib/ui/directives/index.d.ts +0 -3
- package/lib/ui/directives/index.js +0 -5
- package/lib/ui/directives/index.js.map +0 -1
- package/lib/ui/directives/safe.pipe.d.ts +0 -7
- package/lib/ui/directives/taon-inject-html.directive.d.ts +0 -6
- package/lib/ui/directives/taon-long-press.directive.d.ts +0 -22
- package/lib/ui/directives/view-mode.d.ts +0 -5
- package/lib/ui/directives/view-mode.js +0 -10
- package/lib/ui/directives/view-mode.js.map +0 -1
- package/lib/ui/taon-admin-mode-configuration/taon-admin-mode-configuration.component.d.ts +0 -43
- package/lib/ui/taon-admin-mode-configuration/taon-admin.models.d.ts +0 -5
- package/lib/ui/taon-admin-mode-configuration/taon-admin.models.js +0 -3
- package/lib/ui/taon-admin-mode-configuration/taon-admin.models.js.map +0 -1
- package/lib/ui/taon-full-material.module.d.ts +0 -5
- package/lib/ui/taon-github-fork-me-corner/index.d.ts +0 -2
- package/lib/ui/taon-github-fork-me-corner/index.js +0 -5
- package/lib/ui/taon-github-fork-me-corner/index.js.map +0 -1
- package/lib/ui/taon-github-fork-me-corner/taon-github-fork-me-corner.component.d.ts +0 -3
- package/lib/ui/taon-github-fork-me-corner/taon-github-fork-me-corner.module.d.ts +0 -2
- package/lib/ui/taon-github-fork-me-ribbon/index.d.ts +0 -2
- package/lib/ui/taon-github-fork-me-ribbon/index.js +0 -5
- package/lib/ui/taon-github-fork-me-ribbon/index.js.map +0 -1
- package/lib/ui/taon-github-fork-me-ribbon/taon-github-fork-me-ribbon.component.d.ts +0 -3
- package/lib/ui/taon-github-fork-me-ribbon/taon-github-fork-me-ribbon.module.d.ts +0 -2
- package/lib/ui/taon-notifications/index.d.ts +0 -4
- package/lib/ui/taon-notifications/index.js +0 -24
- package/lib/ui/taon-notifications/index.js.map +0 -1
- package/lib/ui/taon-notifications/taon-notifications.component.d.ts +0 -9
- package/lib/ui/taon-notifications/taon-notifications.models.d.ts +0 -6
- package/lib/ui/taon-notifications/taon-notifications.models.js +0 -5
- package/lib/ui/taon-notifications/taon-notifications.models.js.map +0 -1
- package/lib/ui/taon-notifications/taon-notifications.module.d.ts +0 -2
- package/lib/ui/taon-notifications/taon-notifications.service.d.ts +0 -11
- package/lib/ui/taon-progress-bar/index.d.ts +0 -2
- package/lib/ui/taon-progress-bar/index.js +0 -5
- package/lib/ui/taon-progress-bar/index.js.map +0 -1
- package/lib/ui/taon-progress-bar/taon-progress-bar.component.d.ts +0 -13
- package/lib/ui/taon-progress-bar/taon-progress-bar.module.d.ts +0 -2
- package/lib/ui/taon-session-passcode/index.d.ts +0 -1
- package/lib/ui/taon-session-passcode/index.js +0 -5
- package/lib/ui/taon-session-passcode/index.js.map +0 -1
- package/lib/ui/taon-session-passcode/taon-session-passcode.component.d.ts +0 -35
- package/lib/ui/taon-table/index.d.ts +0 -2
- package/lib/ui/taon-table/index.js +0 -5
- package/lib/ui/taon-table/index.js.map +0 -1
- package/lib/ui/taon-table/taon-table.component.d.ts +0 -34
- package/lib/ui/taon-table/taon-table.module.d.ts +0 -2
- package/lib/ui/taon.models.d.ts +0 -11
- package/lib/ui/taon.models.js +0 -3
- package/lib/ui/taon.models.js.map +0 -1
- package/tmp-environment.json +0 -39
- package/websql/lib/decorators/classes/controller-config.d.ts +0 -10
package/lib/endpoint-context.js
CHANGED
|
@@ -20,11 +20,12 @@ const rxjs_1 = require("rxjs");
|
|
|
20
20
|
const lib_4 = require("taon-typeorm/lib"); // @websql
|
|
21
21
|
const lib_5 = require("taon-typeorm/lib"); // @websql
|
|
22
22
|
const lib_6 = require("taon-typeorm/lib");
|
|
23
|
-
const lib_7 = require("tnp-
|
|
24
|
-
const lib_8 = require("tnp-core/lib");
|
|
23
|
+
const lib_7 = require("tnp-config/lib");
|
|
24
|
+
const lib_8 = require("tnp-core/lib"); // @backend
|
|
25
25
|
const lib_9 = require("tnp-core/lib");
|
|
26
26
|
const lib_10 = require("tnp-core/lib");
|
|
27
27
|
const lib_11 = require("tnp-core/lib");
|
|
28
|
+
const lib_12 = require("tnp-core/lib");
|
|
28
29
|
const constants_1 = require("./constants");
|
|
29
30
|
const context_db_migrations_1 = require("./context-db-migrations");
|
|
30
31
|
const di_container_1 = require("./dependency-injection/di-container");
|
|
@@ -154,31 +155,31 @@ class EndpointContext {
|
|
|
154
155
|
//#endregion
|
|
155
156
|
//#region fields / logs
|
|
156
157
|
get logHttp() {
|
|
157
|
-
if (
|
|
158
|
+
if (lib_11._.isObject(this.config?.logs)) {
|
|
158
159
|
return !!this.config.logs.http;
|
|
159
160
|
}
|
|
160
161
|
return this.config?.logs === true;
|
|
161
162
|
}
|
|
162
163
|
get logRealtime() {
|
|
163
|
-
if (
|
|
164
|
+
if (lib_11._.isObject(this.config?.logs)) {
|
|
164
165
|
return !!this.config.logs.realtime;
|
|
165
166
|
}
|
|
166
167
|
return this.config?.logs === true;
|
|
167
168
|
}
|
|
168
169
|
get logFramework() {
|
|
169
|
-
if (
|
|
170
|
+
if (lib_11._.isObject(this.config?.logs)) {
|
|
170
171
|
return !!this.config.logs.framework;
|
|
171
172
|
}
|
|
172
173
|
return this.config?.logs === true;
|
|
173
174
|
}
|
|
174
175
|
get logDb() {
|
|
175
|
-
if (
|
|
176
|
+
if (lib_11._.isObject(this.config?.logs)) {
|
|
176
177
|
return !!this.config.logs.db;
|
|
177
178
|
}
|
|
178
179
|
return this.config?.logs === true;
|
|
179
180
|
}
|
|
180
181
|
get logMigrations() {
|
|
181
|
-
if (
|
|
182
|
+
if (lib_11._.isObject(this.config?.logs)) {
|
|
182
183
|
return !!this.config.logs.migrations;
|
|
183
184
|
}
|
|
184
185
|
return this.config?.logs === true;
|
|
@@ -193,7 +194,7 @@ class EndpointContext {
|
|
|
193
194
|
constructor(originalConfig, configFn) {
|
|
194
195
|
this.originalConfig = originalConfig;
|
|
195
196
|
this.configFn = configFn;
|
|
196
|
-
this.isRunningInsideDocker =
|
|
197
|
+
this.isRunningInsideDocker = lib_9.UtilsOs.isRunningInDocker();
|
|
197
198
|
}
|
|
198
199
|
//#endregion
|
|
199
200
|
//#region methods & getters / init
|
|
@@ -205,16 +206,16 @@ class EndpointContext {
|
|
|
205
206
|
// @ts-ignore
|
|
206
207
|
this.onlyMigrationRevertToTimestamp = onlyMigrationRevertToTimestamp;
|
|
207
208
|
this.config = this.configFn({});
|
|
208
|
-
if (
|
|
209
|
+
if (lib_11._.isObject(this.config.database)) {
|
|
209
210
|
this.config.database = models_1.Models.DatabaseConfig.from(this.config.database).databaseConfigTypeORM;
|
|
210
211
|
}
|
|
211
212
|
if (overrideHost && overrideRemoteHost) {
|
|
212
|
-
|
|
213
|
+
lib_11.Helpers.throw(`[taon-config] You can't have overrideHost and overrideRemoteHost at the same time`);
|
|
213
214
|
}
|
|
214
|
-
this.config.host = !
|
|
215
|
+
this.config.host = !lib_11._.isUndefined(overrideHost)
|
|
215
216
|
? overrideHost
|
|
216
217
|
: this.config.host;
|
|
217
|
-
this.config.remoteHost = !
|
|
218
|
+
this.config.remoteHost = !lib_11._.isUndefined(overrideRemoteHost)
|
|
218
219
|
? overrideRemoteHost
|
|
219
220
|
: this.config.remoteHost;
|
|
220
221
|
this.config.host = this.host === null ? void 0 : this.host;
|
|
@@ -223,19 +224,19 @@ class EndpointContext {
|
|
|
223
224
|
if (this.config.host &&
|
|
224
225
|
!this.config.host.startsWith('http://') &&
|
|
225
226
|
!this.config.host.startsWith('https://')) {
|
|
226
|
-
|
|
227
|
+
lib_11.Helpers.throw(`[taon-config] Your 'host' must start with http:// or https://`);
|
|
227
228
|
}
|
|
228
|
-
if (
|
|
229
|
+
if (lib_11._.isUndefined(this.config.useIpcWhenElectron)) {
|
|
229
230
|
this.config.useIpcWhenElectron = true;
|
|
230
231
|
}
|
|
231
232
|
if (this.config.remoteHost &&
|
|
232
233
|
!this.config.remoteHost.startsWith('http://') &&
|
|
233
234
|
!this.config.remoteHost.startsWith('https://')) {
|
|
234
|
-
|
|
235
|
+
lib_11.Helpers.throw(`[taon-config] Your 'remoteHost' must start with http:// or https://`);
|
|
235
236
|
}
|
|
236
237
|
//#region resolve if skipping writing server routes
|
|
237
238
|
//@ts-expect-error overriding readonly
|
|
238
|
-
this.skipWritingServerRoutes =
|
|
239
|
+
this.skipWritingServerRoutes = lib_11._.isBoolean(this.config.skipWritingServerRoutes)
|
|
239
240
|
? this.config.skipWritingServerRoutes
|
|
240
241
|
: false;
|
|
241
242
|
//#endregion
|
|
@@ -247,7 +248,7 @@ class EndpointContext {
|
|
|
247
248
|
}
|
|
248
249
|
if (this.config.remoteHost) {
|
|
249
250
|
if (this.config.host) {
|
|
250
|
-
|
|
251
|
+
lib_11.Helpers.throw(`[taon] You can't have remoteHost and host at the same time`);
|
|
251
252
|
}
|
|
252
253
|
this.mode = 'remote-backend(tcp+udp)';
|
|
253
254
|
}
|
|
@@ -255,8 +256,8 @@ class EndpointContext {
|
|
|
255
256
|
// useIpcWhenElectron: ${this.config.useIpcWhenElectron}
|
|
256
257
|
// Helpers.isElectron: ${Helpers.isElectron}
|
|
257
258
|
// `)
|
|
258
|
-
if (this.config.useIpcWhenElectron &&
|
|
259
|
-
if (
|
|
259
|
+
if (this.config.useIpcWhenElectron && lib_11.Helpers.isElectron) {
|
|
260
|
+
if (lib_11.Helpers.isWebSQL) {
|
|
260
261
|
this.mode = 'backend-frontend(websql-electron)';
|
|
261
262
|
}
|
|
262
263
|
else {
|
|
@@ -269,7 +270,7 @@ class EndpointContext {
|
|
|
269
270
|
// console.log(this.config)
|
|
270
271
|
// }
|
|
271
272
|
if (!this.mode && !this.config.abstract) {
|
|
272
|
-
|
|
273
|
+
lib_11.Helpers.error(`[taon] Context "${this.contextName}": You need to provide host or remoteHost or useIpcWhenElectron`, false, true);
|
|
273
274
|
//#region @backend
|
|
274
275
|
process.exit(1);
|
|
275
276
|
//#endregion
|
|
@@ -285,7 +286,7 @@ class EndpointContext {
|
|
|
285
286
|
`);
|
|
286
287
|
this.databaseConfig = this.getAutoGeneratedConfig();
|
|
287
288
|
}
|
|
288
|
-
else if (
|
|
289
|
+
else if (lib_11._.isObject(this.config.database)) {
|
|
289
290
|
this.logFramework &&
|
|
290
291
|
console.log(`
|
|
291
292
|
|
|
@@ -294,13 +295,13 @@ class EndpointContext {
|
|
|
294
295
|
`);
|
|
295
296
|
this.databaseConfig = this.getAutoGeneratedConfig();
|
|
296
297
|
lib_2.walk.Object(this.config.database, (value, lodashPath) => {
|
|
297
|
-
if (
|
|
298
|
+
if (lib_11._.isNil(value) || lib_11._.isFunction(value) || lib_11._.isObject(value)) {
|
|
298
299
|
// skipping
|
|
299
300
|
}
|
|
300
301
|
else {
|
|
301
302
|
this.logFramework &&
|
|
302
303
|
console.info(`Overriding database config: ${lodashPath}=${value}`);
|
|
303
|
-
|
|
304
|
+
lib_11._.set(this.databaseConfig, lodashPath, value);
|
|
304
305
|
}
|
|
305
306
|
}, {
|
|
306
307
|
walkGetters: false,
|
|
@@ -309,7 +310,7 @@ class EndpointContext {
|
|
|
309
310
|
//#endregion
|
|
310
311
|
//#region resolve session
|
|
311
312
|
if (this.config.session) {
|
|
312
|
-
this.session =
|
|
313
|
+
this.session = lib_11._.cloneDeep(this.config.session);
|
|
313
314
|
const oneHour = 1000 * 60 * 60 * 1; // 24;
|
|
314
315
|
if (!this.session.cookieMaxAge) {
|
|
315
316
|
this.session.cookieMaxAge = oneHour;
|
|
@@ -416,17 +417,17 @@ class EndpointContext {
|
|
|
416
417
|
await this.initCustomBackendMiddlewares();
|
|
417
418
|
const shouldStartHttpsSecureServer = this.isHttpServer && !this.isRunningInsideDocker;
|
|
418
419
|
this.logFramework &&
|
|
419
|
-
|
|
420
|
+
lib_11.Helpers.info(`
|
|
420
421
|
|
|
421
422
|
Starting server ${shouldStartHttpsSecureServer ? 'with' : 'without'} HTTPS secure server
|
|
422
423
|
|
|
423
424
|
`);
|
|
424
425
|
this.serverTcpUdp = shouldStartHttpsSecureServer
|
|
425
|
-
? new
|
|
426
|
+
? new lib_8.https.Server({
|
|
426
427
|
key: this.config.https?.key,
|
|
427
428
|
cert: this.config.https?.cert,
|
|
428
429
|
}, this.expressApp)
|
|
429
|
-
: new
|
|
430
|
+
: new lib_8.http.Server(this.expressApp);
|
|
430
431
|
this.publicAssets.forEach(asset => {
|
|
431
432
|
this.expressApp.use(asset.serverPath, express.static(asset.locationOnDisk));
|
|
432
433
|
});
|
|
@@ -438,7 +439,7 @@ class EndpointContext {
|
|
|
438
439
|
if (!this.config.abstract) {
|
|
439
440
|
this.disabledRealtime = !!this.config.disabledRealtime;
|
|
440
441
|
//#region @backend
|
|
441
|
-
if (
|
|
442
|
+
if (lib_11.Helpers.isRunningIn.cliMode()) {
|
|
442
443
|
// TODO for now...
|
|
443
444
|
this.disabledRealtime = true;
|
|
444
445
|
}
|
|
@@ -451,16 +452,16 @@ class EndpointContext {
|
|
|
451
452
|
// console.log({ ref })
|
|
452
453
|
if (this.config.abstract) {
|
|
453
454
|
this.logFramework &&
|
|
454
|
-
|
|
455
|
+
lib_11.Helpers.info(`[taon] Create abstract context: ${this.config.contextName}`);
|
|
455
456
|
}
|
|
456
457
|
else {
|
|
457
458
|
if (this.config.remoteHost) {
|
|
458
459
|
this.logFramework &&
|
|
459
|
-
|
|
460
|
+
lib_11.Helpers.info(`[taon] Create context for remote host: ${this.config.remoteHost}`);
|
|
460
461
|
}
|
|
461
462
|
else {
|
|
462
463
|
this.logFramework &&
|
|
463
|
-
|
|
464
|
+
lib_11.Helpers.info(`[taon] Create context for host: ${this.config.host}`);
|
|
464
465
|
}
|
|
465
466
|
}
|
|
466
467
|
//#endregion
|
|
@@ -505,7 +506,7 @@ class EndpointContext {
|
|
|
505
506
|
|
|
506
507
|
`);
|
|
507
508
|
//#region @backend
|
|
508
|
-
const locationOfTheDatabase = (0,
|
|
509
|
+
const locationOfTheDatabase = (0, lib_10.crossPlatformPath)([
|
|
509
510
|
process.cwd(),
|
|
510
511
|
`db-${this.contextName}.sqlite`,
|
|
511
512
|
]);
|
|
@@ -518,14 +519,14 @@ class EndpointContext {
|
|
|
518
519
|
logging: true,
|
|
519
520
|
});
|
|
520
521
|
//#region @backend
|
|
521
|
-
if (!
|
|
522
|
+
if (!lib_8.fse.existsSync(locationOfTheDatabase)) {
|
|
522
523
|
databaseConfig.recreateMode = 'DROP_DB+MIGRATIONS';
|
|
523
524
|
}
|
|
524
525
|
// TODO @LAST add same thing for mariadb/mysql
|
|
525
526
|
this.logFramework &&
|
|
526
527
|
console.log(`
|
|
527
528
|
location of database: ${locationOfTheDatabase}
|
|
528
|
-
db file exists: ${
|
|
529
|
+
db file exists: ${lib_8.fse.existsSync(locationOfTheDatabase)}
|
|
529
530
|
synchronize: ${databaseConfig.synchronize}
|
|
530
531
|
dropSchema: ${databaseConfig.dropSchema}
|
|
531
532
|
`);
|
|
@@ -535,24 +536,24 @@ class EndpointContext {
|
|
|
535
536
|
else {
|
|
536
537
|
//#region auto resolve db config
|
|
537
538
|
this.logFramework &&
|
|
538
|
-
|
|
539
|
+
lib_11.Helpers.info(`[taon][database] Automatically resolving database config for mode ${this.mode}`);
|
|
539
540
|
switch (this.mode) {
|
|
540
541
|
//#region resolve database config for backend-frontend(ipc-electron)
|
|
541
542
|
case 'backend-frontend(ipc-electron)':
|
|
542
543
|
let dbLocationInOs;
|
|
543
544
|
//#region @backend
|
|
544
|
-
if (
|
|
545
|
-
dbLocationInOs = (0,
|
|
546
|
-
|
|
547
|
-
`.taon/databases-for-electron-apps/${this.appId ||
|
|
545
|
+
if (lib_9.UtilsOs.isElectron) {
|
|
546
|
+
dbLocationInOs = (0, lib_10.crossPlatformPath)([
|
|
547
|
+
lib_9.UtilsOs.getRealHomeDir(),
|
|
548
|
+
`.taon/databases-for-electron-apps/${this.appId || lib_11._.snakeCase(process.cwd()).replace(/\_/, '.')}/${this.contextName}.sqlite`,
|
|
548
549
|
]);
|
|
549
|
-
if (!
|
|
550
|
-
|
|
550
|
+
if (!lib_11.Helpers.exists(lib_12.path.dirname(dbLocationInOs))) {
|
|
551
|
+
lib_11.Helpers.mkdirp(lib_12.path.dirname(dbLocationInOs));
|
|
551
552
|
}
|
|
552
553
|
}
|
|
553
554
|
//#endregion
|
|
554
555
|
databaseConfig = models_1.Models.DatabaseConfig.from({
|
|
555
|
-
location:
|
|
556
|
+
location: lib_9.UtilsOs.isElectron
|
|
556
557
|
? dbLocationInOs
|
|
557
558
|
: `db-${this.contextName}.sqlite`,
|
|
558
559
|
type: 'sqljs',
|
|
@@ -615,8 +616,8 @@ class EndpointContext {
|
|
|
615
616
|
if (this.isRunningInsideDocker) {
|
|
616
617
|
// this.displayRoutes(this.expressApp);
|
|
617
618
|
this.serverTcpUdp.listen(Number(this.uriPort), '0.0.0.0', () => {
|
|
618
|
-
|
|
619
|
-
|
|
619
|
+
lib_11.Helpers.log(`Express server (inside docker) started 0.0.0.0:${this.uriPort}`);
|
|
620
|
+
lib_11.Helpers.log(`[taon][express-server]listening on port: ${this.uriPort}, hostname: ${this.uriPathname},
|
|
620
621
|
address: ${this.uriProtocol}//localhost:${this.uriPort}${this.uriPathname}
|
|
621
622
|
ExpressJS mode: ${this.expressApp.settings.env}
|
|
622
623
|
`);
|
|
@@ -626,8 +627,8 @@ class EndpointContext {
|
|
|
626
627
|
else {
|
|
627
628
|
// this.displayRoutes(this.expressApp);
|
|
628
629
|
this.serverTcpUdp.listen(Number(this.uriPort), () => {
|
|
629
|
-
|
|
630
|
-
|
|
630
|
+
lib_11.Helpers.log(`Express server (inside nodejs app) started on localhost:${this.uriPort}`);
|
|
631
|
+
lib_11.Helpers.log(`[taon][express-server]listening on port: ${this.uriPort}, hostname: ${this.uriPathname},
|
|
631
632
|
address: ${this.uriProtocol}//localhost:${this.uriPort}${this.uriPathname}
|
|
632
633
|
expressJS mode: ${this.expressApp.settings.env}
|
|
633
634
|
`);
|
|
@@ -638,7 +639,7 @@ class EndpointContext {
|
|
|
638
639
|
}
|
|
639
640
|
else {
|
|
640
641
|
this.logFramework &&
|
|
641
|
-
|
|
642
|
+
lib_11.Helpers.info('Ipc communication enable instead tcp/upd');
|
|
642
643
|
}
|
|
643
644
|
//#endregion
|
|
644
645
|
}
|
|
@@ -746,7 +747,7 @@ class EndpointContext {
|
|
|
746
747
|
for (const key of Object.keys(classesInput || {})) {
|
|
747
748
|
const BaseClass = classesInput[key];
|
|
748
749
|
if (!BaseClass) {
|
|
749
|
-
|
|
750
|
+
lib_11.Helpers.error(`Class ${key} is not defined in context ${ctx.contextName}
|
|
750
751
|
|
|
751
752
|
Please check if you have correct import in context file
|
|
752
753
|
|
|
@@ -825,7 +826,7 @@ class EndpointContext {
|
|
|
825
826
|
let entityName = '';
|
|
826
827
|
// entity thing is only for repositories local repositories
|
|
827
828
|
// if (className === 'BaseRepository') {
|
|
828
|
-
const entityFn =
|
|
829
|
+
const entityFn = lib_11._.first(locaInstanceConstructorArgs);
|
|
829
830
|
const entity = entityFn && entityFn();
|
|
830
831
|
entityName = (entity && class_helpers_1.ClassHelpers.getName(entity)) || '';
|
|
831
832
|
// console.log(`entityName `, entityName);
|
|
@@ -888,7 +889,7 @@ class EndpointContext {
|
|
|
888
889
|
//#endregion
|
|
889
890
|
//#region methods & getters / check if context initialized
|
|
890
891
|
checkIfContextInitialized() {
|
|
891
|
-
if (
|
|
892
|
+
if (lib_11._.isUndefined(this.config)) {
|
|
892
893
|
throw new Error(`Please check if your context has been initialized.
|
|
893
894
|
|
|
894
895
|
// ...
|
|
@@ -986,7 +987,7 @@ class EndpointContext {
|
|
|
986
987
|
]) {
|
|
987
988
|
//#region init class static _ property
|
|
988
989
|
for (const classFun of this.getClassFunByArr(classTypeName)) {
|
|
989
|
-
if (
|
|
990
|
+
if (lib_11._.isFunction(classFun._)) {
|
|
990
991
|
await classFun._();
|
|
991
992
|
}
|
|
992
993
|
}
|
|
@@ -1004,7 +1005,7 @@ class EndpointContext {
|
|
|
1004
1005
|
// `[taon] REINITING _ INS FN ${classTypeName} ${this.contextName} STARTED`,
|
|
1005
1006
|
// );
|
|
1006
1007
|
for (const ctrl of this.getClassesInstancesArrBy(classTypeName)) {
|
|
1007
|
-
if (
|
|
1008
|
+
if (lib_11._.isFunction(ctrl._)) {
|
|
1008
1009
|
await ctrl._();
|
|
1009
1010
|
}
|
|
1010
1011
|
}
|
|
@@ -1038,15 +1039,12 @@ class EndpointContext {
|
|
|
1038
1039
|
return url;
|
|
1039
1040
|
}
|
|
1040
1041
|
//#endregion
|
|
1041
|
-
|
|
1042
|
-
if (!this.uri?.origin?.includes('localhost')) {
|
|
1043
|
-
return this.config?.hostPortNumber?.toString();
|
|
1044
|
-
}
|
|
1045
|
-
return this.uri?.port;
|
|
1046
|
-
}
|
|
1042
|
+
//#region methods & getters / host uri protocol
|
|
1047
1043
|
get uriProtocol() {
|
|
1048
1044
|
return this.uri?.protocol;
|
|
1049
1045
|
}
|
|
1046
|
+
//#endregion
|
|
1047
|
+
//#region methods & getters / host uri origin
|
|
1050
1048
|
/**
|
|
1051
1049
|
* Examples
|
|
1052
1050
|
* http://localhost:3000
|
|
@@ -1055,6 +1053,8 @@ class EndpointContext {
|
|
|
1055
1053
|
get uriOrigin() {
|
|
1056
1054
|
return this.uri?.origin;
|
|
1057
1055
|
}
|
|
1056
|
+
//#endregion
|
|
1057
|
+
//#region methods & getters / host uri pathname
|
|
1058
1058
|
/**
|
|
1059
1059
|
* Exampels
|
|
1060
1060
|
* http://localhost:3000/path/to/somewhere
|
|
@@ -1068,6 +1068,8 @@ class EndpointContext {
|
|
|
1068
1068
|
get uriPathname() {
|
|
1069
1069
|
return this.uri?.pathname;
|
|
1070
1070
|
}
|
|
1071
|
+
//#endregion
|
|
1072
|
+
//#region methods & getters / uri pathname or nothing if root
|
|
1071
1073
|
/**
|
|
1072
1074
|
* Examples
|
|
1073
1075
|
* http://localhost:3000/path/to/somewhere -> '/path/to/somewhere'
|
|
@@ -1078,6 +1080,15 @@ class EndpointContext {
|
|
|
1078
1080
|
const isNonRootProperPathName = this.uri?.pathname && this.uri.pathname !== '/';
|
|
1079
1081
|
return isNonRootProperPathName ? this.uri.pathname.replace(/\/$/, '') : '';
|
|
1080
1082
|
}
|
|
1083
|
+
//#endregion
|
|
1084
|
+
//#region port from uri
|
|
1085
|
+
get uriPort() {
|
|
1086
|
+
if (!this.uri?.origin?.includes('localhost')) {
|
|
1087
|
+
return this.config?.hostPortNumber?.toString();
|
|
1088
|
+
}
|
|
1089
|
+
return this.uri?.port;
|
|
1090
|
+
}
|
|
1091
|
+
// TODO do i need 2 getters for port?
|
|
1081
1092
|
/**
|
|
1082
1093
|
* Port from uri as number
|
|
1083
1094
|
* @returns {Number | undefined}
|
|
@@ -1085,6 +1096,7 @@ class EndpointContext {
|
|
|
1085
1096
|
get port() {
|
|
1086
1097
|
return this.uri?.port ? Number(this.uriPort) : undefined;
|
|
1087
1098
|
}
|
|
1099
|
+
//#endregion
|
|
1088
1100
|
//#region methods & getters / is https server
|
|
1089
1101
|
get isHttpServer() {
|
|
1090
1102
|
return this.uriProtocol === 'https:';
|
|
@@ -1098,15 +1110,21 @@ class EndpointContext {
|
|
|
1098
1110
|
return this.config.contextName;
|
|
1099
1111
|
}
|
|
1100
1112
|
//#endregion
|
|
1113
|
+
//#region methods & getters / current working directory
|
|
1101
1114
|
get cwd() {
|
|
1102
1115
|
return this.config.cwd || process.cwd();
|
|
1103
1116
|
}
|
|
1117
|
+
//#endregion
|
|
1118
|
+
//#region methods & getters / active context
|
|
1104
1119
|
get activeContext() {
|
|
1105
1120
|
return this.config.activeContext || null;
|
|
1106
1121
|
}
|
|
1122
|
+
//#endregion
|
|
1123
|
+
//#region methods & getters / app id
|
|
1107
1124
|
get appId() {
|
|
1108
1125
|
return this.config.appId;
|
|
1109
1126
|
}
|
|
1127
|
+
//#endregion
|
|
1110
1128
|
//#region methods & getters / public assets
|
|
1111
1129
|
get publicAssets() {
|
|
1112
1130
|
return this.config?.publicAssets || [];
|
|
@@ -1157,7 +1175,7 @@ class EndpointContext {
|
|
|
1157
1175
|
const entities = this.getClassFunByArr(models_1.Models.ClassType.ENTITY);
|
|
1158
1176
|
for (const entity of entities) {
|
|
1159
1177
|
const options = Reflect.getMetadata(symbols_1.Symbols.metadata.options.entity, entity);
|
|
1160
|
-
const createTable =
|
|
1178
|
+
const createTable = lib_11._.isUndefined(options.createTable)
|
|
1161
1179
|
? true
|
|
1162
1180
|
: options.createTable;
|
|
1163
1181
|
const nameForEntity = class_helpers_1.ClassHelpers.getName(entity);
|
|
@@ -1205,7 +1223,7 @@ class EndpointContext {
|
|
|
1205
1223
|
});
|
|
1206
1224
|
const subscribers = this.getClassFunByArr(models_1.Models.ClassType.SUBSCRIBER);
|
|
1207
1225
|
let autoSave = false;
|
|
1208
|
-
if (!
|
|
1226
|
+
if (!lib_11._.isNil(this.databaseConfig.autoSave)) {
|
|
1209
1227
|
autoSave = this.databaseConfig.autoSave;
|
|
1210
1228
|
}
|
|
1211
1229
|
else {
|
|
@@ -1216,7 +1234,7 @@ class EndpointContext {
|
|
|
1216
1234
|
autoSave = true; // on docker with sqljs I need to save db
|
|
1217
1235
|
}
|
|
1218
1236
|
}
|
|
1219
|
-
const dataSourceDbConfig =
|
|
1237
|
+
const dataSourceDbConfig = lib_11._.isObject(this.databaseConfig)
|
|
1220
1238
|
? {
|
|
1221
1239
|
type: this.databaseConfig.type,
|
|
1222
1240
|
port: this.databaseConfig.databasePort,
|
|
@@ -1245,7 +1263,7 @@ class EndpointContext {
|
|
|
1245
1263
|
if (this.modeAllowsDatabaseCreation && this.databaseConfig) {
|
|
1246
1264
|
this.logDb &&
|
|
1247
1265
|
this.logFramework &&
|
|
1248
|
-
|
|
1266
|
+
lib_11.Helpers.info('[taon][database] prepare typeorm connection...');
|
|
1249
1267
|
try {
|
|
1250
1268
|
const connection = new lib_6.DataSource(dataSourceDbConfig);
|
|
1251
1269
|
this.connection = connection;
|
|
@@ -1287,74 +1305,132 @@ class EndpointContext {
|
|
|
1287
1305
|
// debugger;
|
|
1288
1306
|
}
|
|
1289
1307
|
else {
|
|
1290
|
-
|
|
1308
|
+
lib_11.Helpers.info(`[taon][typeorm] Not initing db for mode ${this.mode}`);
|
|
1291
1309
|
}
|
|
1292
1310
|
//#endregion
|
|
1293
1311
|
}
|
|
1294
1312
|
//#endregion
|
|
1295
1313
|
//#region methods & getters / initialize metadata
|
|
1314
|
+
//#region methods & getters / update class calculate path
|
|
1315
|
+
updateCalculatedPathsForControllers(rawConfigs, classConfig, controllerClassFn) {
|
|
1316
|
+
const parentsCalculatedPath = lib_11._.slice(rawConfigs, 1)
|
|
1317
|
+
.reverse()
|
|
1318
|
+
.map(bc => {
|
|
1319
|
+
if (taon_helpers_1.TaonHelpers.isGoodPath(bc.path)) {
|
|
1320
|
+
return bc.path;
|
|
1321
|
+
}
|
|
1322
|
+
return bc.className;
|
|
1323
|
+
})
|
|
1324
|
+
.join('/');
|
|
1325
|
+
if (taon_helpers_1.TaonHelpers.isGoodPath(classConfig.path)) {
|
|
1326
|
+
classConfig.calculatedPath = classConfig.path;
|
|
1327
|
+
}
|
|
1328
|
+
else {
|
|
1329
|
+
classConfig.calculatedPath = (`${this.uriPathnameOrNothingIfRoot}` +
|
|
1330
|
+
`/${constants_1.apiPrefix}/${this.contextName}/tcp${parentsCalculatedPath}/` +
|
|
1331
|
+
`${class_helpers_1.ClassHelpers.getName(controllerClassFn)}`)
|
|
1332
|
+
.replace(/\/\//g, '/')
|
|
1333
|
+
.split('/')
|
|
1334
|
+
.reduce((acc, bc) => {
|
|
1335
|
+
return lib_11._.last(acc) === bc ? acc : [...acc, bc];
|
|
1336
|
+
}, [])
|
|
1337
|
+
.join('/');
|
|
1338
|
+
}
|
|
1339
|
+
// console.log('calculatedPath', classConfig.calculatedPath);
|
|
1340
|
+
}
|
|
1341
|
+
//#endregion
|
|
1342
|
+
//#region methods & getters / dedupe class configs
|
|
1343
|
+
mergeControllerMethodsConfigs(rawConfigs, classConfig, controllerClassFn) {
|
|
1344
|
+
const currentControllerMethodsConfig = classConfig.methods;
|
|
1345
|
+
lib_11._.slice(rawConfigs, 1).forEach(bc => {
|
|
1346
|
+
const parentControllerMethods = lib_11._.cloneDeep(bc.methods);
|
|
1347
|
+
for (const methodsName in parentControllerMethods) {
|
|
1348
|
+
if (parentControllerMethods.hasOwnProperty(methodsName)) {
|
|
1349
|
+
if (!currentControllerMethodsConfig[methodsName]) {
|
|
1350
|
+
//#region add non existed method
|
|
1351
|
+
const methodConfig = parentControllerMethods[methodsName];
|
|
1352
|
+
currentControllerMethodsConfig[methodsName] = methodConfig;
|
|
1353
|
+
//#endregion
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
});
|
|
1358
|
+
}
|
|
1359
|
+
//#endregion
|
|
1296
1360
|
async initControllers() {
|
|
1297
1361
|
if (this.isRunOrRevertOnlyMigrationAppStart) {
|
|
1298
1362
|
return;
|
|
1299
1363
|
}
|
|
1300
1364
|
const allControllers = this.getClassFunByArr(models_1.Models.ClassType.CONTROLLER);
|
|
1365
|
+
// debugger
|
|
1301
1366
|
// console.log('allControllers', allControllers);
|
|
1302
1367
|
for (const controllerClassFn of allControllers) {
|
|
1368
|
+
// console.log(ClassHelpers.getClassConfig(controllerClassFn));
|
|
1369
|
+
// const controllerName = ClassHelpers.getName(controllerClassFn);
|
|
1370
|
+
// console.log(
|
|
1371
|
+
// `for ${controllerName}`,
|
|
1372
|
+
// ClassHelpers.getClassConfig(controllerClassFn),
|
|
1373
|
+
// );
|
|
1303
1374
|
controllerClassFn[symbols_1.Symbols.classMethodsNames] =
|
|
1304
1375
|
class_helpers_1.ClassHelpers.getMethodsNames(controllerClassFn);
|
|
1305
|
-
const
|
|
1376
|
+
const rawConfigs = class_helpers_1.ClassHelpers.getControllerConfigs(controllerClassFn);
|
|
1377
|
+
// console.log(controllerName, { rawConfigs });
|
|
1306
1378
|
// console.log(`Class config for ${ClassHelpers.getName(controllerClassFn)}`, configs)
|
|
1307
|
-
const classConfig =
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
}
|
|
1321
|
-
else {
|
|
1322
|
-
classConfig.calculatedPath = (`${this.uriPathnameOrNothingIfRoot}` +
|
|
1323
|
-
`/${constants_1.apiPrefix}/${this.contextName}/tcp${parentscalculatedPath}/` +
|
|
1324
|
-
`${class_helpers_1.ClassHelpers.getName(controllerClassFn)}`)
|
|
1325
|
-
.replace(/\/\//g, '/')
|
|
1326
|
-
.split('/')
|
|
1327
|
-
.reduce((acc, bc) => {
|
|
1328
|
-
return lib_10._.last(acc) === bc ? acc : [...acc, bc];
|
|
1329
|
-
}, [])
|
|
1330
|
-
.join('/');
|
|
1331
|
-
}
|
|
1332
|
-
//#endregion
|
|
1333
|
-
// console.log('calculatedPath', classConfig.calculatedPath);
|
|
1334
|
-
lib_10._.slice(configs, 1).forEach(bc => {
|
|
1335
|
-
const alreadyIs = classConfig.methods;
|
|
1336
|
-
const toMerge = lib_10._.cloneDeep(bc.methods);
|
|
1337
|
-
for (const key in toMerge) {
|
|
1338
|
-
if (toMerge.hasOwnProperty(key) && !alreadyIs[key]) {
|
|
1339
|
-
const element = toMerge[key];
|
|
1340
|
-
alreadyIs[key] = element;
|
|
1341
|
-
}
|
|
1379
|
+
const classConfig = rawConfigs[0];
|
|
1380
|
+
this.updateCalculatedPathsForControllers(rawConfigs, classConfig, controllerClassFn);
|
|
1381
|
+
this.mergeControllerMethodsConfigs(rawConfigs, classConfig, controllerClassFn);
|
|
1382
|
+
//#region combine middlewares from controllers
|
|
1383
|
+
classConfig.calculatedMiddlewaresControllerObj = {};
|
|
1384
|
+
[...rawConfigs].reverse().forEach(rc => {
|
|
1385
|
+
if (lib_11._.isFunction(rc.middlewares)) {
|
|
1386
|
+
classConfig.calculatedMiddlewaresControllerObj = rc.middlewares({
|
|
1387
|
+
parentMiddlewares: classConfig.calculatedMiddlewaresControllerObj,
|
|
1388
|
+
className(middlewareClass) {
|
|
1389
|
+
return class_helpers_1.ClassHelpers.getName(controllerClassFn);
|
|
1390
|
+
},
|
|
1391
|
+
});
|
|
1342
1392
|
}
|
|
1343
1393
|
});
|
|
1394
|
+
//#endregion
|
|
1395
|
+
//#region group start
|
|
1344
1396
|
//#region @backend
|
|
1345
|
-
if (!
|
|
1397
|
+
if (!lib_11.Helpers.isRunningIn.cliMode()) {
|
|
1346
1398
|
//#endregion
|
|
1347
1399
|
this.logHttp &&
|
|
1348
1400
|
console.groupCollapsed(`[taon][express-server] routes [${classConfig.className}]`);
|
|
1349
1401
|
//#region @backend
|
|
1350
1402
|
}
|
|
1351
1403
|
//#endregion
|
|
1352
|
-
|
|
1404
|
+
//#endregion
|
|
1405
|
+
//#region init client or server methods
|
|
1353
1406
|
const methodNames = Object.keys(classConfig.methods);
|
|
1354
1407
|
for (const methodName of methodNames) {
|
|
1355
1408
|
const methodConfig = classConfig.methods[methodName];
|
|
1356
|
-
|
|
1357
|
-
|
|
1409
|
+
//#region combine all class methods middlewares
|
|
1410
|
+
let calculatedMiddlewaresMethodObj = {};
|
|
1411
|
+
[...rawConfigs].reverse().forEach(rc => {
|
|
1412
|
+
if (rc.methods[methodName]) {
|
|
1413
|
+
const parentMethodConfig = rc.methods[methodName];
|
|
1414
|
+
if (lib_11._.isFunction(parentMethodConfig.middlewares)) {
|
|
1415
|
+
calculatedMiddlewaresMethodObj = parentMethodConfig.middlewares({
|
|
1416
|
+
parentMiddlewares: calculatedMiddlewaresMethodObj,
|
|
1417
|
+
className(middlewareClass) {
|
|
1418
|
+
return class_helpers_1.ClassHelpers.getName(controllerClassFn);
|
|
1419
|
+
},
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
});
|
|
1424
|
+
// add class middlewares to method middlewares
|
|
1425
|
+
methodConfig.calculatedMiddlewaresMethodObj = {
|
|
1426
|
+
...calculatedMiddlewaresMethodObj,
|
|
1427
|
+
...classConfig.calculatedMiddlewaresControllerObj,
|
|
1428
|
+
};
|
|
1429
|
+
methodConfig.calculatedMiddlewares = Object.values(methodConfig.calculatedMiddlewaresMethodObj || {});
|
|
1430
|
+
//#endregion
|
|
1431
|
+
// methodConfig.calculatedMiddlewares = TODO
|
|
1432
|
+
//#region initialized method express path
|
|
1433
|
+
const httpMethodType = methodConfig.type;
|
|
1358
1434
|
// this is quick fix - in docker global path should not be used
|
|
1359
1435
|
const globalPathPart = this.isRunningInsideDocker ||
|
|
1360
1436
|
!this.frontendHostUri?.origin?.includes('localhost') // fe with domain -> is in docker
|
|
@@ -1363,17 +1439,21 @@ class EndpointContext {
|
|
|
1363
1439
|
const expressPath = methodConfig.global
|
|
1364
1440
|
? `${globalPathPart}/${methodConfig.path?.replace(/\/$/, '')}`.replace(/\/\//, '/')
|
|
1365
1441
|
: taon_helpers_1.TaonHelpers.getExpressPath(classConfig, methodConfig);
|
|
1442
|
+
//#endregion
|
|
1443
|
+
//#region init server
|
|
1366
1444
|
// console.log({ expressPath });
|
|
1367
|
-
if (
|
|
1445
|
+
if (lib_11.Helpers.isNode || lib_11.Helpers.isWebSQL) {
|
|
1368
1446
|
//#region @websql
|
|
1369
|
-
const route = this.initServer(
|
|
1447
|
+
const route = this.initServer(httpMethodType, methodConfig, classConfig, expressPath, controllerClassFn);
|
|
1370
1448
|
this.activeRoutes.push({
|
|
1371
1449
|
expressPath: route.expressPath,
|
|
1372
1450
|
method: route.method,
|
|
1373
1451
|
});
|
|
1374
1452
|
//#endregion
|
|
1375
1453
|
}
|
|
1376
|
-
|
|
1454
|
+
//#endregion
|
|
1455
|
+
//#region init client
|
|
1456
|
+
const shouldInitClient = lib_11.Helpers.isBrowser || this.remoteHost || lib_11.Helpers.isWebSQL;
|
|
1377
1457
|
// console.log('shouldInitClient', shouldInitClient);
|
|
1378
1458
|
if (shouldInitClient) {
|
|
1379
1459
|
// console.log(
|
|
@@ -1383,16 +1463,20 @@ class EndpointContext {
|
|
|
1383
1463
|
// methodConfig,
|
|
1384
1464
|
// expressPath,
|
|
1385
1465
|
// );
|
|
1386
|
-
await this.initClient(controllerClassFn,
|
|
1466
|
+
await this.initClient(controllerClassFn, httpMethodType, methodConfig, expressPath);
|
|
1387
1467
|
}
|
|
1468
|
+
//#endregion
|
|
1388
1469
|
}
|
|
1470
|
+
//#endregion
|
|
1471
|
+
//#region group end
|
|
1389
1472
|
//#region @backend
|
|
1390
|
-
if (!
|
|
1473
|
+
if (!lib_11.Helpers.isRunningIn.cliMode()) {
|
|
1391
1474
|
//#endregion
|
|
1392
1475
|
this.logHttp && console.groupEnd();
|
|
1393
1476
|
//#region @backend
|
|
1394
1477
|
}
|
|
1395
1478
|
//#endregion
|
|
1479
|
+
//#endregion
|
|
1396
1480
|
}
|
|
1397
1481
|
}
|
|
1398
1482
|
//#endregion
|
|
@@ -1405,11 +1489,11 @@ class EndpointContext {
|
|
|
1405
1489
|
}
|
|
1406
1490
|
// const contexts: EndpointContext[] = [this];
|
|
1407
1491
|
//#region @websql
|
|
1408
|
-
const troutes =
|
|
1492
|
+
const troutes = lib_9.Utils.uniqArray(this.activeRoutes.map(f => {
|
|
1409
1493
|
return `${f.method} ${f.expressPath}`;
|
|
1410
1494
|
})).map(f => {
|
|
1411
1495
|
const [method, expressPath] = f.split(' ');
|
|
1412
|
-
return (`\n### ${
|
|
1496
|
+
return (`\n### ${lib_11._.startCase(lib_11._.last(expressPath.split('/')))}\n` +
|
|
1413
1497
|
taon_helpers_1.TaonHelpers.fillUpTo(method.toUpperCase() + ' ', 10) +
|
|
1414
1498
|
this.uriOrigin +
|
|
1415
1499
|
expressPath);
|
|
@@ -1420,7 +1504,7 @@ class EndpointContext {
|
|
|
1420
1504
|
...['', `# ROUTES FOR HOST ${this.uriOrigin} `],
|
|
1421
1505
|
...troutes,
|
|
1422
1506
|
].join('\n');
|
|
1423
|
-
const fileName = (0,
|
|
1507
|
+
const fileName = (0, lib_10.crossPlatformPath)([
|
|
1424
1508
|
//#region @backend
|
|
1425
1509
|
process.cwd(),
|
|
1426
1510
|
//#endregion
|
|
@@ -1429,8 +1513,8 @@ class EndpointContext {
|
|
|
1429
1513
|
this.logFramework && console.log(`[taon] routes file: ${fileName} `);
|
|
1430
1514
|
// Helpers.log(JSON.stringify(routes, null, 4))
|
|
1431
1515
|
//#region @backend
|
|
1432
|
-
if (!
|
|
1433
|
-
|
|
1516
|
+
if (!lib_9.UtilsOs.isElectron) {
|
|
1517
|
+
lib_11.Helpers.writeFile(fileName, routes);
|
|
1434
1518
|
}
|
|
1435
1519
|
//#endregion
|
|
1436
1520
|
//#endregion
|
|
@@ -1447,16 +1531,16 @@ class EndpointContext {
|
|
|
1447
1531
|
async initCustomClientMiddlewares() {
|
|
1448
1532
|
const middlewares = this.getClassesInstancesArrBy(models_1.Models.ClassType.MIDDLEWARE)
|
|
1449
1533
|
.map(f => f)
|
|
1450
|
-
.filter(f =>
|
|
1451
|
-
middlewares.forEach(
|
|
1534
|
+
.filter(f => lib_11._.isFunction(f.interceptClient));
|
|
1535
|
+
middlewares.forEach(middlewareInstanceName => {
|
|
1452
1536
|
const contextName = this.contextName;
|
|
1453
|
-
const interceptorName = `${contextName}-${class_helpers_1.ClassHelpers.getName(
|
|
1537
|
+
const interceptorName = `${contextName}-${class_helpers_1.ClassHelpers.getName(middlewareInstanceName)}`;
|
|
1454
1538
|
lib_3.Resource.request.interceptors.set(interceptorName, {
|
|
1455
1539
|
intercept: ({ req, next }) => {
|
|
1456
1540
|
const url = new url_1.URL(req.url);
|
|
1457
1541
|
if (url.pathname.startsWith(`${this.uriPathnameOrNothingIfRoot}/${constants_1.apiPrefix}/${contextName}/`)) {
|
|
1458
1542
|
// console.log('intercepting', url.pathname, req);
|
|
1459
|
-
return
|
|
1543
|
+
return middlewareInstanceName.interceptClient({
|
|
1460
1544
|
req,
|
|
1461
1545
|
next,
|
|
1462
1546
|
});
|
|
@@ -1472,7 +1556,7 @@ class EndpointContext {
|
|
|
1472
1556
|
const middlewares = this.getClassesInstancesArrBy(models_1.Models.ClassType.MIDDLEWARE);
|
|
1473
1557
|
for (const middleware of middlewares) {
|
|
1474
1558
|
const middlewareInstance = middleware;
|
|
1475
|
-
if (
|
|
1559
|
+
if (lib_11._.isFunction(middlewareInstance.interceptServer)) {
|
|
1476
1560
|
const middlewareFn = class_helpers_1.ClassHelpers.asyncHandler(async (req, res, next) => {
|
|
1477
1561
|
if (req.originalUrl.startsWith(`${this.uriPathnameOrNothingIfRoot}/${constants_1.apiPrefix}/${this.contextName}/`)) {
|
|
1478
1562
|
await middlewareInstance.interceptServer({
|
|
@@ -1508,7 +1592,7 @@ class EndpointContext {
|
|
|
1508
1592
|
app.use(methodOverride());
|
|
1509
1593
|
app.use(cookieParser());
|
|
1510
1594
|
if (this.session) {
|
|
1511
|
-
|
|
1595
|
+
lib_11.Helpers.info('[taon][express-server] session enabled for this context ' +
|
|
1512
1596
|
this.contextName);
|
|
1513
1597
|
const { cookieMaxAge } = this.session;
|
|
1514
1598
|
const frontendHost = this.config.frontendHost;
|
|
@@ -1534,7 +1618,7 @@ class EndpointContext {
|
|
|
1534
1618
|
else {
|
|
1535
1619
|
// if(this.config?.serverLogs) {
|
|
1536
1620
|
this.logHttp &&
|
|
1537
|
-
|
|
1621
|
+
lib_11.Helpers.info(`[taon][express-server] session not enabled for this context '${this.contextName}'`);
|
|
1538
1622
|
// }
|
|
1539
1623
|
app.use(cors({
|
|
1540
1624
|
// origin: "http://localhost:5555",
|
|
@@ -1584,14 +1668,14 @@ class EndpointContext {
|
|
|
1584
1668
|
//#region parameters
|
|
1585
1669
|
httpMethodType, methodConfig, classConfig, expressPath, target) {
|
|
1586
1670
|
//#region resolve variables
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1671
|
+
// console.log(
|
|
1672
|
+
// `CLIENT: expressPath: "${expressPath}" interceptor for method: ${methodConfig.calculatedMiddlewares.length}`,
|
|
1673
|
+
// );
|
|
1674
|
+
const middlewareHandlers = methodConfig.calculatedMiddlewares
|
|
1591
1675
|
.map(middlewareClassFun => {
|
|
1592
1676
|
const middlewareInstance = this.getInstanceBy(middlewareClassFun);
|
|
1593
1677
|
if (middlewareInstance &&
|
|
1594
|
-
|
|
1678
|
+
lib_11._.isFunction(middlewareInstance.interceptServerMethod)) {
|
|
1595
1679
|
const middlewareFn = class_helpers_1.ClassHelpers.asyncHandler(async (req, res, next) => {
|
|
1596
1680
|
await middlewareInstance.interceptServerMethod({
|
|
1597
1681
|
req,
|
|
@@ -1625,7 +1709,7 @@ class EndpointContext {
|
|
|
1625
1709
|
//#endregion
|
|
1626
1710
|
// console.log(`BACKEND: expressPath: "${expressPath}" `);
|
|
1627
1711
|
//#endregion
|
|
1628
|
-
if (
|
|
1712
|
+
if (lib_11.Helpers.isElectron) {
|
|
1629
1713
|
//#region @backend
|
|
1630
1714
|
const ipcKeyName = taon_helpers_1.TaonHelpers.ipcKeyNameRequest(target, methodConfig, expressPath);
|
|
1631
1715
|
electron_1.ipcMain.on(ipcKeyName, async (event, paramsFromBrowser) => {
|
|
@@ -1643,7 +1727,7 @@ class EndpointContext {
|
|
|
1643
1727
|
if (!this.remoteHost) {
|
|
1644
1728
|
//#region apply dummy websql express routers
|
|
1645
1729
|
//#region @websql
|
|
1646
|
-
if (
|
|
1730
|
+
if (lib_11.Helpers.isWebSQL) {
|
|
1647
1731
|
if (!this.expressApp[httpMethodType.toLowerCase()]) {
|
|
1648
1732
|
this.expressApp[httpMethodType.toLowerCase()] = () => { };
|
|
1649
1733
|
// TODO add middlewares for WEBSQL and ELECTRON mode
|
|
@@ -1705,7 +1789,7 @@ class EndpointContext {
|
|
|
1705
1789
|
try {
|
|
1706
1790
|
const entityForParam = JSON.parse(req.headers[`${symbols_1.Symbols.old.MAPPING_CONFIG_HEADER_QUERY_PARAMS}${queryParamName} `]);
|
|
1707
1791
|
let beforeTransofrm = tQuery[queryParamName];
|
|
1708
|
-
if (
|
|
1792
|
+
if (lib_11._.isString(beforeTransofrm)) {
|
|
1709
1793
|
try {
|
|
1710
1794
|
const paresed = taon_helpers_1.TaonHelpers.tryTransformParam(beforeTransofrm);
|
|
1711
1795
|
beforeTransofrm = paresed;
|
|
@@ -1767,7 +1851,7 @@ class EndpointContext {
|
|
|
1767
1851
|
res.end(file);
|
|
1768
1852
|
//#endregion
|
|
1769
1853
|
}
|
|
1770
|
-
else if (
|
|
1854
|
+
else if (lib_11._.isString(result) &&
|
|
1771
1855
|
methodConfig.responseType ===
|
|
1772
1856
|
'blob') {
|
|
1773
1857
|
// console.log('BASE64')
|
|
@@ -1794,7 +1878,7 @@ class EndpointContext {
|
|
|
1794
1878
|
}
|
|
1795
1879
|
catch (error) {
|
|
1796
1880
|
//#region process error
|
|
1797
|
-
if (
|
|
1881
|
+
if (lib_11._.isString(error)) {
|
|
1798
1882
|
res.status(400).send(lib_1.JSON10.stringify({
|
|
1799
1883
|
message: `
|
|
1800
1884
|
Error inside: ${req.path}
|
|
@@ -1805,21 +1889,21 @@ class EndpointContext {
|
|
|
1805
1889
|
}));
|
|
1806
1890
|
}
|
|
1807
1891
|
else if (error instanceof models_1.Models.Http.Errors) {
|
|
1808
|
-
|
|
1892
|
+
lib_11.Helpers.error(error, true, false);
|
|
1809
1893
|
const err = error;
|
|
1810
1894
|
res.status(400).send(lib_1.JSON10.stringify(err));
|
|
1811
1895
|
}
|
|
1812
1896
|
else if (error instanceof Error) {
|
|
1813
1897
|
const err = error;
|
|
1814
|
-
|
|
1898
|
+
lib_11.Helpers.error(error, true, false);
|
|
1815
1899
|
res.status(400).send(lib_1.JSON10.stringify({
|
|
1816
1900
|
stack: err.stack,
|
|
1817
1901
|
message: err.message,
|
|
1818
1902
|
}));
|
|
1819
1903
|
}
|
|
1820
1904
|
else {
|
|
1821
|
-
|
|
1822
|
-
|
|
1905
|
+
lib_11.Helpers.log(error);
|
|
1906
|
+
lib_11.Helpers.error(`[Taon] Bad result isomorphic method: ${error} `, true, false);
|
|
1823
1907
|
res.status(400).send(lib_1.JSON10.stringify(error));
|
|
1824
1908
|
}
|
|
1825
1909
|
//#endregion
|
|
@@ -1837,17 +1921,22 @@ class EndpointContext {
|
|
|
1837
1921
|
/**
|
|
1838
1922
|
* client can be browser or nodejs (when remote host)
|
|
1839
1923
|
*/
|
|
1840
|
-
async initClient(
|
|
1841
|
-
//#region parameters
|
|
1842
|
-
target, httpRequestType, methodConfig, // Models.Http.Rest.MethodConfig,
|
|
1924
|
+
async initClient(target, httpRequestType, methodConfig, // Models.Http.Rest.MethodConfig,
|
|
1843
1925
|
expressPath) {
|
|
1844
1926
|
const ctx = this;
|
|
1927
|
+
// console.log(
|
|
1928
|
+
// `CLIENT: expressPath: "${expressPath}" interceptor for method: ${methodConfig.calculatedMiddlewares?.length} `,
|
|
1929
|
+
// );
|
|
1845
1930
|
//#region init middlewares
|
|
1846
|
-
const middlewares = methodConfig.
|
|
1931
|
+
const middlewares = methodConfig.calculatedMiddlewares;
|
|
1932
|
+
const middlewaresInstances = middlewares
|
|
1847
1933
|
.map(f => this.getInstanceBy(f))
|
|
1848
|
-
.filter(f =>
|
|
1849
|
-
|
|
1850
|
-
|
|
1934
|
+
.filter(f => lib_11._.isFunction(f.interceptClientMethod));
|
|
1935
|
+
middlewaresInstances.forEach(instance => {
|
|
1936
|
+
const middlewareName = class_helpers_1.ClassHelpers.getName(instance);
|
|
1937
|
+
// middlewareName - only needed for inheritace and uniqness of interceptors
|
|
1938
|
+
const interceptorKey = `${middlewareName}-${methodConfig.type?.toUpperCase()}-${expressPath}`;
|
|
1939
|
+
lib_3.Resource.request.methodsInterceptors.set(interceptorKey, {
|
|
1851
1940
|
intercept: ({ req, next }) => {
|
|
1852
1941
|
return instance.interceptClientMethod({
|
|
1853
1942
|
req,
|
|
@@ -1871,7 +1960,7 @@ class EndpointContext {
|
|
|
1871
1960
|
//#endregion
|
|
1872
1961
|
const orgMethods = target.prototype[methodConfig.methodName];
|
|
1873
1962
|
//#region handle electron ipc request
|
|
1874
|
-
if (
|
|
1963
|
+
if (lib_11.Helpers.isElectron) {
|
|
1875
1964
|
const ipcRenderer = window.require('electron').ipcRenderer;
|
|
1876
1965
|
target.prototype[methodConfig.methodName] = function (...args) {
|
|
1877
1966
|
const received = new Promise(async (resolve, reject) => {
|
|
@@ -2129,6 +2218,15 @@ class EndpointContext {
|
|
|
2129
2218
|
break;
|
|
2130
2219
|
}
|
|
2131
2220
|
}
|
|
2221
|
+
if (!currentParam) {
|
|
2222
|
+
const errorMessage = `[${lib_7.config.frameworkName}] Unable to resolve parameter` +
|
|
2223
|
+
` at index ${i} for method ${methodConfig.methodName} at path ${expressPath}.`;
|
|
2224
|
+
//#region @backend
|
|
2225
|
+
console.error(errorMessage);
|
|
2226
|
+
process.exit(0);
|
|
2227
|
+
//#endregion
|
|
2228
|
+
throw new Error(errorMessage);
|
|
2229
|
+
}
|
|
2132
2230
|
if (currentParam.paramType === 'Path') {
|
|
2133
2231
|
pathPrams[currentParam.paramName] = param;
|
|
2134
2232
|
}
|
|
@@ -2145,7 +2243,7 @@ class EndpointContext {
|
|
|
2145
2243
|
if (mapping) {
|
|
2146
2244
|
rest.headers.set(symbols_1.Symbols.old.MAPPING_CONFIG_HEADER_QUERY_PARAMS, JSON.stringify(mapping));
|
|
2147
2245
|
}
|
|
2148
|
-
queryParams =
|
|
2246
|
+
queryParams = lib_11._.cloneDeep(param);
|
|
2149
2247
|
}
|
|
2150
2248
|
}
|
|
2151
2249
|
if (currentParam.paramType === 'Header') {
|
|
@@ -2214,7 +2312,9 @@ instead
|
|
|
2214
2312
|
}
|
|
2215
2313
|
//#endregion
|
|
2216
2314
|
const httpResultObj = {
|
|
2217
|
-
received
|
|
2315
|
+
get received() {
|
|
2316
|
+
return rest.model(pathPrams)[method](bodyObject, [queryParams]);
|
|
2317
|
+
},
|
|
2218
2318
|
request(axiosConfig) {
|
|
2219
2319
|
return rest
|
|
2220
2320
|
.model(pathPrams)[method](bodyObject, [queryParams], axiosConfig);
|