taon 21.0.50 → 21.0.51
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/browser/fesm2022/taon-browser.mjs +3 -1
- package/browser/fesm2022/taon-browser.mjs.map +1 -1
- package/browser/package.json +1 -1
- package/browser/types/taon-browser.d.ts +6 -6
- package/browser-prod/fesm2022/taon-browser.mjs +3 -1
- package/browser-prod/fesm2022/taon-browser.mjs.map +1 -1
- package/browser-prod/package.json +1 -1
- package/browser-prod/types/taon-browser.d.ts +6 -6
- package/lib/base-classes/base-file-upload.middleware.d.ts +2 -2
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/endpoint-context.d.ts +2 -2
- package/lib/endpoint-context.js +87 -86
- package/lib/endpoint-context.js.map +1 -1
- package/lib/entity-process.d.ts +1 -1
- package/lib/entity-process.js +32 -33
- package/lib/entity-process.js.map +1 -1
- package/lib/express-types.d.ts +1 -1
- package/lib/package.json +1 -1
- package/lib/ui/index.js +2 -2
- package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
- package/lib-prod/base-classes/base-file-upload.middleware.ts +2 -2
- package/lib-prod/build-info._auto-generated_.ts +1 -1
- package/lib-prod/endpoint-context.ts +17 -12
- package/lib-prod/entity-process.ts +8 -5
- package/lib-prod/express-types.ts +1 -1
- package/lib-prod/package.json +1 -1
- package/lib-prod/ui/index.ts +1 -1
- package/lib-prod/ui/taon-admin-mode-configuration/index.ts +1 -1
- package/package.json +1 -1
- package/websql/fesm2022/taon-websql.mjs +3 -1
- package/websql/fesm2022/taon-websql.mjs.map +1 -1
- package/websql/package.json +1 -1
- package/websql/types/taon-websql.d.ts +6 -6
- package/websql-prod/fesm2022/taon-websql.mjs +3 -1
- package/websql-prod/fesm2022/taon-websql.mjs.map +1 -1
- package/websql-prod/package.json +1 -1
- package/websql-prod/types/taon-websql.d.ts +6 -6
package/lib/endpoint-context.js
CHANGED
|
@@ -7,9 +7,6 @@ const bodyParser = require("body-parser"); // @backend
|
|
|
7
7
|
const cookieParser = require("cookie-parser"); // @backend
|
|
8
8
|
const cors = require("cors"); // @backend
|
|
9
9
|
const electron_1 = require("electron"); // @backend
|
|
10
|
-
const express = require("express");
|
|
11
|
-
// multer in taon middleware will do better job than express-fileupload
|
|
12
|
-
// import * as fileUpload from 'express-fileupload'; // @backend
|
|
13
10
|
const expressSession = require("express-session"); // @backend
|
|
14
11
|
const lib_1 = require("json10/lib");
|
|
15
12
|
const lib_2 = require("lodash-walk-object/lib");
|
|
@@ -21,8 +18,8 @@ const lib_5 = require("taon-typeorm/lib"); // @websql
|
|
|
21
18
|
const lib_6 = require("taon-typeorm/lib");
|
|
22
19
|
const lib_7 = require("tnp-core/lib");
|
|
23
20
|
const lib_8 = require("tnp-core/lib");
|
|
24
|
-
const lib_9 = require("tnp-core/lib");
|
|
25
|
-
const lib_10 = require("tnp-core/lib");
|
|
21
|
+
const lib_9 = require("tnp-core/lib");
|
|
22
|
+
const lib_10 = require("tnp-core/lib"); // @backend
|
|
26
23
|
const lib_11 = require("tnp-core/lib");
|
|
27
24
|
const lib_12 = require("tnp-core/lib");
|
|
28
25
|
const lib_13 = require("tnp-core/lib");
|
|
@@ -38,6 +35,10 @@ const realtime_core_1 = require("./realtime/realtime-core");
|
|
|
38
35
|
const symbols_1 = require("./symbols");
|
|
39
36
|
/* */
|
|
40
37
|
//#endregion
|
|
38
|
+
let express = {};
|
|
39
|
+
//#region @backend
|
|
40
|
+
express = (0, lib_7.requireDefault)('express');
|
|
41
|
+
//#endregion
|
|
41
42
|
class EndpointContext {
|
|
42
43
|
originalConfig;
|
|
43
44
|
configFn;
|
|
@@ -153,37 +154,37 @@ class EndpointContext {
|
|
|
153
154
|
//#endregion
|
|
154
155
|
//#region fields / logs
|
|
155
156
|
get logHttp() {
|
|
156
|
-
if (
|
|
157
|
+
if (lib_13._.isObject(this.config?.logs)) {
|
|
157
158
|
return !!this.config.logs.http;
|
|
158
159
|
}
|
|
159
160
|
return this.config?.logs === true;
|
|
160
161
|
}
|
|
161
162
|
get logRealtime() {
|
|
162
|
-
if (
|
|
163
|
+
if (lib_13._.isObject(this.config?.logs)) {
|
|
163
164
|
return !!this.config.logs.realtime;
|
|
164
165
|
}
|
|
165
166
|
return this.config?.logs === true;
|
|
166
167
|
}
|
|
167
168
|
get logFramework() {
|
|
168
|
-
if (
|
|
169
|
+
if (lib_13._.isObject(this.config?.logs)) {
|
|
169
170
|
return !!this.config.logs.framework;
|
|
170
171
|
}
|
|
171
172
|
return this.config?.logs === true;
|
|
172
173
|
}
|
|
173
174
|
get logRoutes() {
|
|
174
|
-
if (
|
|
175
|
+
if (lib_13._.isObject(this.config?.logs)) {
|
|
175
176
|
return !!this.config.logs.routes;
|
|
176
177
|
}
|
|
177
178
|
return this.config?.logs === true;
|
|
178
179
|
}
|
|
179
180
|
get logDb() {
|
|
180
|
-
if (
|
|
181
|
+
if (lib_13._.isObject(this.config?.logs)) {
|
|
181
182
|
return !!this.config.logs.db;
|
|
182
183
|
}
|
|
183
184
|
return this.config?.logs === true;
|
|
184
185
|
}
|
|
185
186
|
get logMigrations() {
|
|
186
|
-
if (
|
|
187
|
+
if (lib_13._.isObject(this.config?.logs)) {
|
|
187
188
|
return !!this.config.logs.migrations;
|
|
188
189
|
}
|
|
189
190
|
return this.config?.logs === true;
|
|
@@ -207,7 +208,7 @@ class EndpointContext {
|
|
|
207
208
|
this.configFn = configFn;
|
|
208
209
|
this.cloneOptions = cloneOptions;
|
|
209
210
|
this.cloneOptions = this.cloneOptions || {};
|
|
210
|
-
this.isRunningInsideDocker =
|
|
211
|
+
this.isRunningInsideDocker = lib_11.UtilsOs.isRunningInDocker();
|
|
211
212
|
}
|
|
212
213
|
//#endregion
|
|
213
214
|
//#region methods & getters / init
|
|
@@ -219,7 +220,7 @@ class EndpointContext {
|
|
|
219
220
|
// @ts-ignore
|
|
220
221
|
this.onlyMigrationRevertToTimestamp = onlyMigrationRevertToTimestamp;
|
|
221
222
|
this.config = this.configFn({});
|
|
222
|
-
if (
|
|
223
|
+
if (lib_13._.isObject(this.config.database)) {
|
|
223
224
|
this.config.database = models_1.Models.DatabaseConfig.from(this.config.database).databaseConfigTypeORM;
|
|
224
225
|
}
|
|
225
226
|
this.config.host = this.host === null ? void 0 : this.host;
|
|
@@ -234,15 +235,15 @@ class EndpointContext {
|
|
|
234
235
|
if (this.config.host &&
|
|
235
236
|
!this.config.host.startsWith('http://') &&
|
|
236
237
|
!this.config.host.startsWith('https://')) {
|
|
237
|
-
|
|
238
|
+
lib_13.Helpers.throwError(`[taon-config] Your${this.host ? ' remote' : ''} 'host' must start with http:// or https://`);
|
|
238
239
|
}
|
|
239
|
-
if (
|
|
240
|
+
if (lib_13._.isUndefined(this.config.useIpcWhenElectron)) {
|
|
240
241
|
this.config.useIpcWhenElectron = true;
|
|
241
242
|
}
|
|
242
243
|
// console.log(`config for ${this.contextName}`, this.config);
|
|
243
244
|
//#region resolve if skipping writing server routes
|
|
244
245
|
//@ts-expect-error overriding readonly
|
|
245
|
-
this.skipWritingServerRoutes =
|
|
246
|
+
this.skipWritingServerRoutes = lib_13._.isBoolean(this.config.skipWritingServerRoutes)
|
|
246
247
|
? this.config.skipWritingServerRoutes
|
|
247
248
|
: false;
|
|
248
249
|
//#endregion
|
|
@@ -259,8 +260,8 @@ class EndpointContext {
|
|
|
259
260
|
// useIpcWhenElectron: ${this.config.useIpcWhenElectron}
|
|
260
261
|
// UtilsOs.isElectron: ${UtilsOs.isElectron}
|
|
261
262
|
// `)
|
|
262
|
-
if (this.config.useIpcWhenElectron &&
|
|
263
|
-
if (
|
|
263
|
+
if (this.config.useIpcWhenElectron && lib_11.UtilsOs.isElectron) {
|
|
264
|
+
if (lib_11.UtilsOs.isWebSQL) {
|
|
264
265
|
this.mode = 'backend-frontend(websql-electron)';
|
|
265
266
|
}
|
|
266
267
|
else {
|
|
@@ -275,7 +276,7 @@ class EndpointContext {
|
|
|
275
276
|
if (!this.mode && !this.config.abstract) {
|
|
276
277
|
const errMsg = `You need to provide host property or ` +
|
|
277
278
|
`useIpcWhenElectron or mark it as abstract`;
|
|
278
|
-
|
|
279
|
+
lib_13.Helpers.error(`[taon][Context=${this.contextName}]: ${errMsg}`, false, true);
|
|
279
280
|
//#region @backend
|
|
280
281
|
process.exit(1);
|
|
281
282
|
//#endregion
|
|
@@ -291,7 +292,7 @@ class EndpointContext {
|
|
|
291
292
|
`);
|
|
292
293
|
this.databaseConfig = this.getAutoGeneratedConfig();
|
|
293
294
|
}
|
|
294
|
-
else if (
|
|
295
|
+
else if (lib_13._.isObject(this.config.database)) {
|
|
295
296
|
this.logFramework &&
|
|
296
297
|
console.log(`
|
|
297
298
|
|
|
@@ -300,13 +301,13 @@ class EndpointContext {
|
|
|
300
301
|
`);
|
|
301
302
|
this.databaseConfig = this.getAutoGeneratedConfig();
|
|
302
303
|
lib_2.walk.Object(this.config.database, (value, lodashPath) => {
|
|
303
|
-
if (
|
|
304
|
+
if (lib_13._.isNil(value) || lib_13._.isFunction(value) || lib_13._.isObject(value)) {
|
|
304
305
|
// skipping
|
|
305
306
|
}
|
|
306
307
|
else {
|
|
307
308
|
this.logFramework &&
|
|
308
309
|
console.info(`Overriding database config: ${lodashPath}=${value}`);
|
|
309
|
-
|
|
310
|
+
lib_13._.set(this.databaseConfig, lodashPath, value);
|
|
310
311
|
}
|
|
311
312
|
}, {
|
|
312
313
|
walkGetters: false,
|
|
@@ -315,7 +316,7 @@ class EndpointContext {
|
|
|
315
316
|
//#endregion
|
|
316
317
|
//#region resolve session
|
|
317
318
|
if (this.config.session) {
|
|
318
|
-
this.session =
|
|
319
|
+
this.session = lib_13._.cloneDeep(this.config.session);
|
|
319
320
|
const oneHour = 1000 * 60 * 60 * 1; // 24;
|
|
320
321
|
if (!this.session.cookieMaxAge) {
|
|
321
322
|
this.session.cookieMaxAge = oneHour;
|
|
@@ -422,17 +423,17 @@ class EndpointContext {
|
|
|
422
423
|
await this.initCustomBackendMiddlewares();
|
|
423
424
|
const shouldStartHttpsSecureServer = this.isHttpServer && !this.isRunningInsideDocker;
|
|
424
425
|
this.logFramework &&
|
|
425
|
-
|
|
426
|
+
lib_13.Helpers.info(`
|
|
426
427
|
|
|
427
428
|
Starting server ${shouldStartHttpsSecureServer ? 'with' : 'without'} HTTPS secure server
|
|
428
429
|
|
|
429
430
|
`);
|
|
430
431
|
this.serverTcpUdp = shouldStartHttpsSecureServer
|
|
431
|
-
? new
|
|
432
|
+
? new lib_10.https.Server({
|
|
432
433
|
key: this.config.https?.key,
|
|
433
434
|
cert: this.config.https?.cert,
|
|
434
435
|
}, this.expressApp)
|
|
435
|
-
: new
|
|
436
|
+
: new lib_10.http.Server(this.expressApp);
|
|
436
437
|
this.publicAssets.forEach(asset => {
|
|
437
438
|
this.expressApp.use(asset.serverPath, express.static(asset.locationOnDisk));
|
|
438
439
|
});
|
|
@@ -461,7 +462,7 @@ class EndpointContext {
|
|
|
461
462
|
// }
|
|
462
463
|
//#endregion
|
|
463
464
|
this.logRealtime &&
|
|
464
|
-
|
|
465
|
+
lib_13.Helpers.info(`[ctx=${this.contextName}] Init Realtime for ${this.mode}`);
|
|
465
466
|
this.realtime = new realtime_core_1.RealtimeCore(this);
|
|
466
467
|
}
|
|
467
468
|
//#endregion
|
|
@@ -470,16 +471,16 @@ class EndpointContext {
|
|
|
470
471
|
// console.log({ ref })
|
|
471
472
|
if (this.config.abstract) {
|
|
472
473
|
this.logFramework &&
|
|
473
|
-
|
|
474
|
+
lib_13.Helpers.info(`[taon] Create abstract context: ${this.config.contextName}`);
|
|
474
475
|
}
|
|
475
476
|
else {
|
|
476
477
|
if (this.isRemoteHost) {
|
|
477
478
|
this.logFramework &&
|
|
478
|
-
|
|
479
|
+
lib_13.Helpers.info(`[taon] Create context for remote host: ${this.config.host}`);
|
|
479
480
|
}
|
|
480
481
|
else {
|
|
481
482
|
this.logFramework &&
|
|
482
|
-
|
|
483
|
+
lib_13.Helpers.info(`[taon] Create context for host: ${this.config.host}`);
|
|
483
484
|
}
|
|
484
485
|
}
|
|
485
486
|
//#endregion
|
|
@@ -525,7 +526,7 @@ class EndpointContext {
|
|
|
525
526
|
|
|
526
527
|
`);
|
|
527
528
|
//#region @backend
|
|
528
|
-
const locationOfTheDatabase = (0,
|
|
529
|
+
const locationOfTheDatabase = (0, lib_12.crossPlatformPath)([
|
|
529
530
|
process.cwd(),
|
|
530
531
|
`db-${this.contextName}.sqlite`,
|
|
531
532
|
]);
|
|
@@ -538,14 +539,14 @@ class EndpointContext {
|
|
|
538
539
|
logging: true,
|
|
539
540
|
});
|
|
540
541
|
//#region @backend
|
|
541
|
-
if (!
|
|
542
|
+
if (!lib_10.fse.existsSync(locationOfTheDatabase)) {
|
|
542
543
|
databaseConfig.recreateMode = 'DROP_DB+MIGRATIONS';
|
|
543
544
|
}
|
|
544
545
|
// TODO @LAST add same thing for mariadb/mysql
|
|
545
546
|
this.logFramework &&
|
|
546
547
|
console.log(`
|
|
547
548
|
location of database: ${locationOfTheDatabase}
|
|
548
|
-
db file exists: ${
|
|
549
|
+
db file exists: ${lib_10.fse.existsSync(locationOfTheDatabase)}
|
|
549
550
|
synchronize: ${databaseConfig.synchronize}
|
|
550
551
|
dropSchema: ${databaseConfig.dropSchema}
|
|
551
552
|
`);
|
|
@@ -555,24 +556,24 @@ class EndpointContext {
|
|
|
555
556
|
else {
|
|
556
557
|
//#region auto resolve db config
|
|
557
558
|
this.logFramework &&
|
|
558
|
-
|
|
559
|
+
lib_13.Helpers.info(`[taon][database] Automatically resolving database config for mode ${this.mode}`);
|
|
559
560
|
switch (this.mode) {
|
|
560
561
|
//#region resolve database config for backend-frontend(ipc-electron)
|
|
561
562
|
case 'backend-frontend(ipc-electron)':
|
|
562
563
|
let dbLocationInOs;
|
|
563
564
|
//#region @backend
|
|
564
|
-
if (
|
|
565
|
-
dbLocationInOs = (0,
|
|
566
|
-
|
|
567
|
-
`.taon/databases-for-electron-apps/${this.appId ||
|
|
565
|
+
if (lib_11.UtilsOs.isElectron) {
|
|
566
|
+
dbLocationInOs = (0, lib_12.crossPlatformPath)([
|
|
567
|
+
lib_11.UtilsOs.getRealHomeDir(),
|
|
568
|
+
`.taon/databases-for-electron-apps/${this.appId || lib_13._.snakeCase(process.cwd()).replace(/\_/, '.')}/${this.contextName}.sqlite`,
|
|
568
569
|
]);
|
|
569
|
-
if (!
|
|
570
|
-
|
|
570
|
+
if (!lib_13.Helpers.exists(lib_7.path.dirname(dbLocationInOs))) {
|
|
571
|
+
lib_13.Helpers.mkdirp(lib_7.path.dirname(dbLocationInOs));
|
|
571
572
|
}
|
|
572
573
|
}
|
|
573
574
|
//#endregion
|
|
574
575
|
databaseConfig = models_1.Models.DatabaseConfig.from({
|
|
575
|
-
location:
|
|
576
|
+
location: lib_11.UtilsOs.isElectron
|
|
576
577
|
? dbLocationInOs
|
|
577
578
|
: `db-${this.contextName}.sqlite`,
|
|
578
579
|
type: 'sqljs',
|
|
@@ -629,9 +630,9 @@ class EndpointContext {
|
|
|
629
630
|
// this.displayRoutes(this.expressApp);
|
|
630
631
|
this.serverTcpUdp.listen(Number(this.uriPort), '0.0.0.0', () => {
|
|
631
632
|
this.logFramework &&
|
|
632
|
-
|
|
633
|
+
lib_13.Helpers.log(`[ctx=${this.contextName}] Express server (inside docker) started 0.0.0.0:${this.uriPort}`);
|
|
633
634
|
this.logFramework &&
|
|
634
|
-
|
|
635
|
+
lib_13.Helpers.log(`[taon][express-server]listening on port: ${this.uriPort}, hostname: ${this.uriPathname},
|
|
635
636
|
address: ${this.uriProtocol}//localhost:${this.uriPort}${this.uriPathname}
|
|
636
637
|
ExpressJS mode: ${this.expressApp.settings.env}
|
|
637
638
|
`);
|
|
@@ -642,9 +643,9 @@ class EndpointContext {
|
|
|
642
643
|
// this.displayRoutes(this.expressApp);
|
|
643
644
|
this.serverTcpUdp.listen(Number(this.uriPort), () => {
|
|
644
645
|
this.logFramework &&
|
|
645
|
-
|
|
646
|
+
lib_13.Helpers.log(`[ctx=${this.contextName}] Express server (inside nodejs app) started on localhost:${this.uriPort}`);
|
|
646
647
|
this.logFramework &&
|
|
647
|
-
|
|
648
|
+
lib_13.Helpers.log(`[taon][express-server]listening on port: ${this.uriPort}, hostname: ${this.uriPathname},
|
|
648
649
|
address: ${this.uriProtocol}//localhost:${this.uriPort}${this.uriPathname}
|
|
649
650
|
expressJS mode: ${this.expressApp.settings.env}
|
|
650
651
|
`);
|
|
@@ -655,7 +656,7 @@ class EndpointContext {
|
|
|
655
656
|
}
|
|
656
657
|
else {
|
|
657
658
|
this.logFramework &&
|
|
658
|
-
|
|
659
|
+
lib_13.Helpers.info('Ipc communication enable instead tcp/upd');
|
|
659
660
|
}
|
|
660
661
|
//#endregion
|
|
661
662
|
}
|
|
@@ -763,7 +764,7 @@ class EndpointContext {
|
|
|
763
764
|
for (const key of Object.keys(classesInput || {})) {
|
|
764
765
|
const TaonBaseClass = classesInput[key];
|
|
765
766
|
if (!TaonBaseClass) {
|
|
766
|
-
|
|
767
|
+
lib_13.Helpers.error(`Class ${key} is not defined in context ${ctx.contextName}
|
|
767
768
|
|
|
768
769
|
Please check if you have correct import in context file
|
|
769
770
|
|
|
@@ -842,7 +843,7 @@ class EndpointContext {
|
|
|
842
843
|
let entityName = '';
|
|
843
844
|
// entity thing is only for repositories local repositories
|
|
844
845
|
// if (className === 'TaonBaseRepository') {
|
|
845
|
-
const entityFn =
|
|
846
|
+
const entityFn = lib_13._.first(locaInstanceConstructorArgs);
|
|
846
847
|
const entity = entityFn && entityFn();
|
|
847
848
|
entityName = (entity && class_helpers_1.ClassHelpers.getName(entity)) || '';
|
|
848
849
|
// console.log(`entityName `, entityName);
|
|
@@ -905,7 +906,7 @@ class EndpointContext {
|
|
|
905
906
|
//#endregion
|
|
906
907
|
//#region methods & getters / check if context initialized
|
|
907
908
|
checkIfContextInitialized() {
|
|
908
|
-
if (
|
|
909
|
+
if (lib_13._.isUndefined(this.config)) {
|
|
909
910
|
throw new Error(`Please check if your context has been initialized.
|
|
910
911
|
|
|
911
912
|
// ...
|
|
@@ -1003,7 +1004,7 @@ class EndpointContext {
|
|
|
1003
1004
|
]) {
|
|
1004
1005
|
//#region init class static _ property
|
|
1005
1006
|
for (const classFun of this.getClassFunByArr(classTypeName)) {
|
|
1006
|
-
if (
|
|
1007
|
+
if (lib_13._.isFunction(classFun._)) {
|
|
1007
1008
|
await classFun._();
|
|
1008
1009
|
}
|
|
1009
1010
|
}
|
|
@@ -1021,7 +1022,7 @@ class EndpointContext {
|
|
|
1021
1022
|
// `[taon] REINITING _ INS FN ${classTypeName} ${this.contextName} STARTED`,
|
|
1022
1023
|
// );
|
|
1023
1024
|
for (const ctrl of this.getClassesInstancesArrBy(classTypeName)) {
|
|
1024
|
-
if (
|
|
1025
|
+
if (lib_13._.isFunction(ctrl._)) {
|
|
1025
1026
|
await ctrl._();
|
|
1026
1027
|
}
|
|
1027
1028
|
}
|
|
@@ -1224,7 +1225,7 @@ class EndpointContext {
|
|
|
1224
1225
|
const entities = this.getClassFunByArr(models_1.Models.ClassType.ENTITY);
|
|
1225
1226
|
for (const entity of entities) {
|
|
1226
1227
|
const options = Reflect.getMetadata(symbols_1.Symbols.metadata.options.entity, entity);
|
|
1227
|
-
const createTable =
|
|
1228
|
+
const createTable = lib_13._.isUndefined(options.createTable)
|
|
1228
1229
|
? true
|
|
1229
1230
|
: options.createTable;
|
|
1230
1231
|
const nameForEntity = class_helpers_1.ClassHelpers.getName(entity);
|
|
@@ -1272,7 +1273,7 @@ class EndpointContext {
|
|
|
1272
1273
|
});
|
|
1273
1274
|
const subscribers = this.getClassFunByArr(models_1.Models.ClassType.SUBSCRIBER);
|
|
1274
1275
|
let autoSave = false;
|
|
1275
|
-
if (!
|
|
1276
|
+
if (!lib_13._.isNil(this.databaseConfig.autoSave)) {
|
|
1276
1277
|
autoSave = this.databaseConfig.autoSave;
|
|
1277
1278
|
}
|
|
1278
1279
|
else {
|
|
@@ -1283,7 +1284,7 @@ class EndpointContext {
|
|
|
1283
1284
|
autoSave = true; // on docker with sqljs I need to save db
|
|
1284
1285
|
}
|
|
1285
1286
|
}
|
|
1286
|
-
const dataSourceDbConfig =
|
|
1287
|
+
const dataSourceDbConfig = lib_13._.isObject(this.databaseConfig)
|
|
1287
1288
|
? {
|
|
1288
1289
|
type: this.databaseConfig.type,
|
|
1289
1290
|
port: this.databaseConfig.databasePort,
|
|
@@ -1312,7 +1313,7 @@ class EndpointContext {
|
|
|
1312
1313
|
if (this.modeAllowsDatabaseCreation && this.databaseConfig) {
|
|
1313
1314
|
this.logDb &&
|
|
1314
1315
|
this.logFramework &&
|
|
1315
|
-
|
|
1316
|
+
lib_13.Helpers.info('[taon][database] prepare typeorm connection...');
|
|
1316
1317
|
try {
|
|
1317
1318
|
const connection = new lib_6.DataSource(dataSourceDbConfig);
|
|
1318
1319
|
this.connection = connection;
|
|
@@ -1354,7 +1355,7 @@ class EndpointContext {
|
|
|
1354
1355
|
// debugger;
|
|
1355
1356
|
}
|
|
1356
1357
|
else {
|
|
1357
|
-
|
|
1358
|
+
lib_13.Helpers.info(`[taon][typeorm] Not initing db for mode ${this.mode}`);
|
|
1358
1359
|
}
|
|
1359
1360
|
//#endregion
|
|
1360
1361
|
}
|
|
@@ -1362,7 +1363,7 @@ class EndpointContext {
|
|
|
1362
1363
|
//#region methods & getters / initialize metadata
|
|
1363
1364
|
//#region methods & getters / update class calculate path
|
|
1364
1365
|
updateCalculatedPathsForControllers(rawConfigs, classConfig, controllerClassFn) {
|
|
1365
|
-
const parentsCalculatedPath =
|
|
1366
|
+
const parentsCalculatedPath = lib_13._.slice(rawConfigs, 1)
|
|
1366
1367
|
.reverse()
|
|
1367
1368
|
.map(bc => {
|
|
1368
1369
|
if (taon_helpers_1.TaonHelpers.isGoodPath(bc.path)) {
|
|
@@ -1382,7 +1383,7 @@ class EndpointContext {
|
|
|
1382
1383
|
.replace(/\/\//g, '/')
|
|
1383
1384
|
.split('/')
|
|
1384
1385
|
.reduce((acc, bc) => {
|
|
1385
|
-
return
|
|
1386
|
+
return lib_13._.last(acc) === bc ? acc : [...acc, bc];
|
|
1386
1387
|
}, [])
|
|
1387
1388
|
.join('/');
|
|
1388
1389
|
}
|
|
@@ -1392,8 +1393,8 @@ class EndpointContext {
|
|
|
1392
1393
|
//#region methods & getters / dedupe class configs
|
|
1393
1394
|
mergeControllerMethodsConfigs(rawConfigs, classConfig, controllerClassFn) {
|
|
1394
1395
|
const currentControllerMethodsConfig = classConfig.methods;
|
|
1395
|
-
|
|
1396
|
-
const parentControllerMethods =
|
|
1396
|
+
lib_13._.slice(rawConfigs, 1).forEach(bc => {
|
|
1397
|
+
const parentControllerMethods = lib_13._.cloneDeep(bc.methods);
|
|
1397
1398
|
for (const methodsName in parentControllerMethods) {
|
|
1398
1399
|
if (parentControllerMethods.hasOwnProperty(methodsName)) {
|
|
1399
1400
|
if (!currentControllerMethodsConfig[methodsName]) {
|
|
@@ -1414,7 +1415,7 @@ class EndpointContext {
|
|
|
1414
1415
|
const allControllers = this.getClassFunByArr(models_1.Models.ClassType.CONTROLLER);
|
|
1415
1416
|
for (const controllerClassFn of allControllers) {
|
|
1416
1417
|
const instance = this.getInstanceBy(controllerClassFn);
|
|
1417
|
-
if (
|
|
1418
|
+
if (lib_13._.isFunction(instance.afterAllCtxInited)) {
|
|
1418
1419
|
await instance.afterAllCtxInited({ ctxStorage });
|
|
1419
1420
|
}
|
|
1420
1421
|
}
|
|
@@ -1444,7 +1445,7 @@ class EndpointContext {
|
|
|
1444
1445
|
//#region combine middlewares from controllers
|
|
1445
1446
|
classConfig.calculatedMiddlewaresControllerObj = {};
|
|
1446
1447
|
[...rawConfigs].reverse().forEach(rc => {
|
|
1447
|
-
if (
|
|
1448
|
+
if (lib_13._.isFunction(rc.middlewares)) {
|
|
1448
1449
|
classConfig.calculatedMiddlewaresControllerObj = rc.middlewares({
|
|
1449
1450
|
parentMiddlewares: classConfig.calculatedMiddlewaresControllerObj,
|
|
1450
1451
|
className(middlewareClass) {
|
|
@@ -1456,7 +1457,7 @@ class EndpointContext {
|
|
|
1456
1457
|
//#endregion
|
|
1457
1458
|
//#region group start
|
|
1458
1459
|
//#region @backend
|
|
1459
|
-
if (!
|
|
1460
|
+
if (!lib_11.UtilsOs.isRunningInCliMode()) {
|
|
1460
1461
|
//#endregion
|
|
1461
1462
|
this.logHttp &&
|
|
1462
1463
|
console.groupCollapsed(`[taon][express-server] routes [${classConfig.className}]`);
|
|
@@ -1473,7 +1474,7 @@ class EndpointContext {
|
|
|
1473
1474
|
[...rawConfigs].reverse().forEach(rc => {
|
|
1474
1475
|
if (rc.methods[methodName]) {
|
|
1475
1476
|
const parentMethodConfig = rc.methods[methodName];
|
|
1476
|
-
if (
|
|
1477
|
+
if (lib_13._.isFunction(parentMethodConfig.middlewares)) {
|
|
1477
1478
|
calculatedMiddlewaresMethodObj = parentMethodConfig.middlewares({
|
|
1478
1479
|
parentMiddlewares: calculatedMiddlewaresMethodObj,
|
|
1479
1480
|
className(middlewareClass) {
|
|
@@ -1504,7 +1505,7 @@ class EndpointContext {
|
|
|
1504
1505
|
//#endregion
|
|
1505
1506
|
//#region init server
|
|
1506
1507
|
// console.log({ expressPath });
|
|
1507
|
-
if (
|
|
1508
|
+
if (lib_11.UtilsOs.isNode || lib_11.UtilsOs.isWebSQL) {
|
|
1508
1509
|
//#region @websql
|
|
1509
1510
|
const route = this.initServer(httpMethodType, methodConfig, classConfig, expressPath, controllerClassFn);
|
|
1510
1511
|
this.activeRoutes.push({
|
|
@@ -1515,7 +1516,7 @@ class EndpointContext {
|
|
|
1515
1516
|
}
|
|
1516
1517
|
//#endregion
|
|
1517
1518
|
//#region init client
|
|
1518
|
-
const shouldInitClient =
|
|
1519
|
+
const shouldInitClient = lib_11.UtilsOs.isBrowser || this.isRemoteHost || lib_11.UtilsOs.isWebSQL;
|
|
1519
1520
|
// console.log('shouldInitClient', shouldInitClient);
|
|
1520
1521
|
if (shouldInitClient) {
|
|
1521
1522
|
// console.log(
|
|
@@ -1532,7 +1533,7 @@ class EndpointContext {
|
|
|
1532
1533
|
//#endregion
|
|
1533
1534
|
//#region group end
|
|
1534
1535
|
//#region @backend
|
|
1535
|
-
if (!
|
|
1536
|
+
if (!lib_11.UtilsOs.isRunningInCliMode()) {
|
|
1536
1537
|
//#endregion
|
|
1537
1538
|
this.logHttp && console.groupEnd();
|
|
1538
1539
|
//#region @backend
|
|
@@ -1549,11 +1550,11 @@ class EndpointContext {
|
|
|
1549
1550
|
}
|
|
1550
1551
|
// const contexts: EndpointContext[] = [this];
|
|
1551
1552
|
//#region @websql
|
|
1552
|
-
const troutes =
|
|
1553
|
+
const troutes = lib_11.Utils.uniqArray(this.activeRoutes.map(f => {
|
|
1553
1554
|
return `${f.method} ${f.expressPath}`;
|
|
1554
1555
|
})).map(f => {
|
|
1555
1556
|
const [method, expressPath] = f.split(' ');
|
|
1556
|
-
return (`\n### ${
|
|
1557
|
+
return (`\n### ${lib_13._.startCase(lib_13._.last(expressPath.split('/')))}\n` +
|
|
1557
1558
|
taon_helpers_1.TaonHelpers.fillUpTo(method.toUpperCase() + ' ', 10) +
|
|
1558
1559
|
this.uriOrigin +
|
|
1559
1560
|
expressPath);
|
|
@@ -1564,7 +1565,7 @@ class EndpointContext {
|
|
|
1564
1565
|
...['', `# ROUTES FOR HOST ${this.uriOrigin} `],
|
|
1565
1566
|
...troutes,
|
|
1566
1567
|
].join('\n');
|
|
1567
|
-
const fileName = (0,
|
|
1568
|
+
const fileName = (0, lib_12.crossPlatformPath)([
|
|
1568
1569
|
//#region @backend
|
|
1569
1570
|
process.cwd(),
|
|
1570
1571
|
//#endregion
|
|
@@ -1573,8 +1574,8 @@ class EndpointContext {
|
|
|
1573
1574
|
this.logFramework && console.log(`[taon] routes file: ${fileName} `);
|
|
1574
1575
|
this.logRoutes && console.log(routes);
|
|
1575
1576
|
//#region @backend
|
|
1576
|
-
if (!
|
|
1577
|
-
|
|
1577
|
+
if (!lib_11.UtilsOs.isElectron && !this.skipWritingServerRoutes) {
|
|
1578
|
+
lib_13.Helpers.writeFile(fileName, routes);
|
|
1578
1579
|
}
|
|
1579
1580
|
//#endregion
|
|
1580
1581
|
//#endregion
|
|
@@ -1591,7 +1592,7 @@ class EndpointContext {
|
|
|
1591
1592
|
async initCustomClientMiddlewares() {
|
|
1592
1593
|
const middlewares = this.getClassesInstancesArrBy(models_1.Models.ClassType.MIDDLEWARE)
|
|
1593
1594
|
.map(f => f)
|
|
1594
|
-
.filter(f =>
|
|
1595
|
+
.filter(f => lib_13._.isFunction(f.interceptClient));
|
|
1595
1596
|
middlewares.forEach(middlewareInstanceName => {
|
|
1596
1597
|
const contextName = this.contextName;
|
|
1597
1598
|
const interceptorName = `${contextName}-${class_helpers_1.ClassHelpers.getName(middlewareInstanceName)}`;
|
|
@@ -1616,7 +1617,7 @@ class EndpointContext {
|
|
|
1616
1617
|
const middlewares = this.getClassesInstancesArrBy(models_1.Models.ClassType.MIDDLEWARE);
|
|
1617
1618
|
for (const middleware of middlewares) {
|
|
1618
1619
|
const middlewareInstance = middleware;
|
|
1619
|
-
if (
|
|
1620
|
+
if (lib_13._.isFunction(middlewareInstance.interceptServer)) {
|
|
1620
1621
|
const middlewareFn = class_helpers_1.ClassHelpers.asyncHandler(async (req, res, next) => {
|
|
1621
1622
|
if (req.originalUrl.startsWith(`${this.uriPathnameOrNothingIfRoot}/${constants_1.apiPrefix}/${this.contextName}/`)) {
|
|
1622
1623
|
await middlewareInstance.interceptServer({
|
|
@@ -1652,7 +1653,7 @@ class EndpointContext {
|
|
|
1652
1653
|
app.use(methodOverride());
|
|
1653
1654
|
app.use(cookieParser());
|
|
1654
1655
|
if (this.session) {
|
|
1655
|
-
|
|
1656
|
+
lib_13.Helpers.info('[taon][express-server] session enabled for this context ' +
|
|
1656
1657
|
this.contextName);
|
|
1657
1658
|
const { cookieMaxAge } = this.session;
|
|
1658
1659
|
const frontendHost = this.config.frontendHost;
|
|
@@ -1678,7 +1679,7 @@ class EndpointContext {
|
|
|
1678
1679
|
else {
|
|
1679
1680
|
// if(this.config?.serverLogs) {
|
|
1680
1681
|
this.logHttp &&
|
|
1681
|
-
|
|
1682
|
+
lib_13.Helpers.info(`[taon][express-server] session not enabled for this context '${this.contextName}'`);
|
|
1682
1683
|
// }
|
|
1683
1684
|
app.use(cors({
|
|
1684
1685
|
// origin: "http://localhost:5555",
|
|
@@ -1735,7 +1736,7 @@ class EndpointContext {
|
|
|
1735
1736
|
.map(middlewareClassFun => {
|
|
1736
1737
|
const middlewareInstance = this.getInstanceBy(middlewareClassFun);
|
|
1737
1738
|
if (middlewareInstance &&
|
|
1738
|
-
|
|
1739
|
+
lib_13._.isFunction(middlewareInstance.interceptServerMethod)) {
|
|
1739
1740
|
const middlewareFn = class_helpers_1.ClassHelpers.asyncHandler(async (req, res, next) => {
|
|
1740
1741
|
await middlewareInstance.interceptServerMethod({
|
|
1741
1742
|
req,
|
|
@@ -1769,7 +1770,7 @@ class EndpointContext {
|
|
|
1769
1770
|
//#endregion
|
|
1770
1771
|
// console.log(`BACKEND: expressPath: "${expressPath}" `);
|
|
1771
1772
|
//#endregion
|
|
1772
|
-
if (
|
|
1773
|
+
if (lib_11.UtilsOs.isElectron) {
|
|
1773
1774
|
//#region @backend
|
|
1774
1775
|
const ipcKeyName = taon_helpers_1.TaonHelpers.ipcKeyNameRequest(target, methodConfig, expressPath);
|
|
1775
1776
|
electron_1.ipcMain.on(ipcKeyName, async (event, paramsFromBrowser) => {
|
|
@@ -1787,7 +1788,7 @@ class EndpointContext {
|
|
|
1787
1788
|
if (!this.isRemoteHost) {
|
|
1788
1789
|
//#region apply dummy websql express routers
|
|
1789
1790
|
//#region @websql
|
|
1790
|
-
if (
|
|
1791
|
+
if (lib_11.UtilsOs.isWebSQL) {
|
|
1791
1792
|
if (!this.expressApp[httpMethodType.toLowerCase()]) {
|
|
1792
1793
|
this.expressApp[httpMethodType.toLowerCase()] = () => { };
|
|
1793
1794
|
// TODO add middlewares for WEBSQL and ELECTRON mode
|
|
@@ -1849,7 +1850,7 @@ class EndpointContext {
|
|
|
1849
1850
|
try {
|
|
1850
1851
|
const entityForParam = JSON.parse(taon_helpers_1.TaonHelpers.firstStringOrElemFromArray(req.headers[`${symbols_1.Symbols.old.MAPPING_CONFIG_HEADER_QUERY_PARAMS}${queryParamName} `]));
|
|
1851
1852
|
let beforeTransofrm = tQuery[queryParamName];
|
|
1852
|
-
if (
|
|
1853
|
+
if (lib_13._.isString(beforeTransofrm)) {
|
|
1853
1854
|
try {
|
|
1854
1855
|
const paresed = taon_helpers_1.TaonHelpers.tryTransformParam(beforeTransofrm);
|
|
1855
1856
|
beforeTransofrm = paresed;
|
|
@@ -1921,7 +1922,7 @@ class EndpointContext {
|
|
|
1921
1922
|
res.end(file);
|
|
1922
1923
|
//#endregion
|
|
1923
1924
|
}
|
|
1924
|
-
else if (
|
|
1925
|
+
else if (lib_13._.isString(result) &&
|
|
1925
1926
|
methodConfig.responseType ===
|
|
1926
1927
|
'blob') {
|
|
1927
1928
|
// console.log('BASE64')
|
|
@@ -1999,7 +2000,7 @@ class EndpointContext {
|
|
|
1999
2000
|
message,
|
|
2000
2001
|
details,
|
|
2001
2002
|
code,
|
|
2002
|
-
[
|
|
2003
|
+
[lib_9.CoreModels.TaonHttpErrorCustomProp]: true,
|
|
2003
2004
|
});
|
|
2004
2005
|
//#endregion
|
|
2005
2006
|
}
|
|
@@ -2018,7 +2019,7 @@ class EndpointContext {
|
|
|
2018
2019
|
const middlewares = methodConfig.calculatedMiddlewares;
|
|
2019
2020
|
const middlewaresInstances = middlewares
|
|
2020
2021
|
.map(f => this.getInstanceBy(f))
|
|
2021
|
-
.filter(f =>
|
|
2022
|
+
.filter(f => lib_13._.isFunction(f.interceptClientMethod));
|
|
2022
2023
|
middlewaresInstances.forEach(instance => {
|
|
2023
2024
|
const middlewareName = class_helpers_1.ClassHelpers.getName(instance);
|
|
2024
2025
|
// middlewareName - only needed for inheritace and uniqness of interceptors
|
|
@@ -2047,7 +2048,7 @@ class EndpointContext {
|
|
|
2047
2048
|
//#endregion
|
|
2048
2049
|
const orgMethods = target.prototype[methodConfig.methodName];
|
|
2049
2050
|
//#region handle electron ipc request
|
|
2050
|
-
if (
|
|
2051
|
+
if (lib_11.UtilsOs.isElectron) {
|
|
2051
2052
|
const ipcRenderer = window.require('electron').ipcRenderer;
|
|
2052
2053
|
target.prototype[methodConfig.methodName] = function (...args) {
|
|
2053
2054
|
const received = new Promise(async (resolve, reject) => {
|
|
@@ -2306,7 +2307,7 @@ class EndpointContext {
|
|
|
2306
2307
|
}
|
|
2307
2308
|
}
|
|
2308
2309
|
if (!currentParam) {
|
|
2309
|
-
const errorMessage = `[${
|
|
2310
|
+
const errorMessage = `[${lib_8.config.frameworkName}] Unable to resolve parameter` +
|
|
2310
2311
|
` at index ${i} for method ${methodConfig.methodName} at path ${expressPath}.`;
|
|
2311
2312
|
//#region @backend
|
|
2312
2313
|
console.error(errorMessage);
|
|
@@ -2330,7 +2331,7 @@ class EndpointContext {
|
|
|
2330
2331
|
if (mapping) {
|
|
2331
2332
|
rest.headers.set(symbols_1.Symbols.old.MAPPING_CONFIG_HEADER_QUERY_PARAMS, JSON.stringify(mapping));
|
|
2332
2333
|
}
|
|
2333
|
-
queryParams =
|
|
2334
|
+
queryParams = lib_13._.cloneDeep(param);
|
|
2334
2335
|
}
|
|
2335
2336
|
}
|
|
2336
2337
|
if (currentParam.paramType === 'Header') {
|