taon 19.0.52 → 19.0.54
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.mjs +407 -239
- package/browser/fesm2022/taon.mjs.map +1 -1
- package/browser/lib/base-classes/base-angular-service.d.ts +3 -6
- package/browser/lib/base-classes/base-controller.d.ts +11 -0
- package/browser/lib/base-classes/base-file-upload.middleware.d.ts +15 -0
- package/browser/lib/base-classes/base-middleware.d.ts +30 -8
- package/browser/lib/decorators/classes/controller-config.d.ts +10 -0
- package/browser/lib/decorators/classes/controller-decorator.d.ts +2 -12
- package/browser/lib/decorators/classes/controller-options.d.ts +12 -0
- package/browser/lib/decorators/classes/entity-decorator.d.ts +2 -2
- package/browser/lib/decorators/classes/middleware-decorator.d.ts +2 -2
- package/browser/lib/decorators/classes/migration-decorator.d.ts +2 -2
- package/browser/lib/decorators/classes/provider-decorator.d.ts +2 -2
- package/browser/lib/decorators/classes/repository-decorator.d.ts +2 -2
- package/browser/lib/decorators/classes/subscriber-decorator.d.ts +2 -2
- package/browser/lib/decorators/decorator-abstract-opt.d.ts +4 -0
- package/browser/lib/decorators/http/http-methods-decorators.d.ts +8 -5
- package/browser/lib/endpoint-context.d.ts +4 -3
- package/browser/lib/helpers/class-helpers.d.ts +7 -3
- package/browser/lib/helpers/taon-helpers.d.ts +2 -1
- package/browser/lib/index.d.ts +2 -1
- package/browser/lib/models.d.ts +15 -22
- package/browser/package.json +1 -1
- package/lib/base-classes/base-angular-service.d.ts +3 -6
- package/lib/base-classes/base-angular-service.js +12 -16
- package/lib/base-classes/base-angular-service.js.map +1 -1
- package/lib/base-classes/base-context.js +4 -0
- package/lib/base-classes/base-context.js.map +1 -1
- package/lib/base-classes/base-controller.d.ts +12 -0
- package/lib/base-classes/base-controller.js +56 -1
- package/lib/base-classes/base-controller.js.map +1 -1
- package/lib/base-classes/base-file-upload.middleware.d.ts +14 -0
- package/lib/base-classes/base-file-upload.middleware.js +85 -0
- package/lib/base-classes/base-file-upload.middleware.js.map +1 -0
- package/lib/base-classes/base-middleware.d.ts +30 -12
- package/lib/base-classes/base-middleware.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/decorators/classes/controller-config.d.ts +9 -0
- package/lib/decorators/classes/controller-config.js +11 -0
- package/lib/decorators/classes/controller-config.js.map +1 -0
- package/lib/decorators/classes/controller-decorator.d.ts +2 -12
- package/lib/decorators/classes/controller-decorator.js +0 -13
- package/lib/decorators/classes/controller-decorator.js.map +1 -1
- package/lib/decorators/classes/controller-options.d.ts +11 -0
- package/lib/decorators/classes/controller-options.js +16 -0
- package/lib/decorators/classes/controller-options.js.map +1 -0
- package/lib/decorators/classes/entity-decorator.d.ts +2 -2
- package/lib/decorators/classes/entity-decorator.js +7 -9
- package/lib/decorators/classes/entity-decorator.js.map +1 -1
- package/lib/decorators/classes/middleware-decorator.d.ts +2 -2
- package/lib/decorators/classes/middleware-decorator.js +2 -2
- package/lib/decorators/classes/middleware-decorator.js.map +1 -1
- package/lib/decorators/classes/migration-decorator.d.ts +2 -2
- package/lib/decorators/classes/migration-decorator.js +2 -2
- package/lib/decorators/classes/migration-decorator.js.map +1 -1
- package/lib/decorators/classes/provider-decorator.d.ts +2 -2
- package/lib/decorators/classes/provider-decorator.js +2 -2
- package/lib/decorators/classes/provider-decorator.js.map +1 -1
- package/lib/decorators/classes/repository-decorator.d.ts +2 -2
- package/lib/decorators/classes/repository-decorator.js +2 -2
- package/lib/decorators/classes/repository-decorator.js.map +1 -1
- package/lib/decorators/classes/subscriber-decorator.d.ts +2 -2
- package/lib/decorators/classes/subscriber-decorator.js +2 -2
- package/lib/decorators/classes/subscriber-decorator.js.map +1 -1
- package/lib/decorators/decorator-abstract-opt.d.ts +3 -0
- package/lib/decorators/decorator-abstract-opt.js +8 -0
- package/lib/decorators/decorator-abstract-opt.js.map +1 -0
- package/lib/decorators/http/http-methods-decorators.d.ts +8 -5
- package/lib/decorators/http/http-methods-decorators.js +3 -2
- package/lib/decorators/http/http-methods-decorators.js.map +1 -1
- package/lib/endpoint-context.d.ts +4 -3
- package/lib/endpoint-context.js +128 -75
- package/lib/endpoint-context.js.map +1 -1
- package/lib/helpers/class-helpers.d.ts +7 -3
- package/lib/helpers/class-helpers.js +12 -6
- package/lib/helpers/class-helpers.js.map +1 -1
- package/lib/helpers/taon-helpers.d.ts +2 -1
- package/lib/helpers/taon-helpers.js +1 -1
- package/lib/helpers/taon-helpers.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js.map +1 -1
- package/lib/models.d.ts +16 -24
- package/lib/models.js +4 -31
- package/lib/models.js.map +1 -1
- package/lib/realtime/realtime-client.js +2 -1
- package/lib/realtime/realtime-client.js.map +1 -1
- package/lib/ui/directives/index.d.ts +3 -0
- package/lib/ui/directives/index.js +5 -0
- package/lib/ui/directives/index.js.map +1 -0
- package/lib/ui/directives/safe.pipe.d.ts +7 -0
- package/lib/ui/directives/taon-inject-html.directive.d.ts +6 -0
- package/lib/ui/directives/taon-long-press.directive.d.ts +22 -0
- package/lib/ui/directives/view-mode.d.ts +5 -0
- package/lib/ui/directives/view-mode.js +10 -0
- package/lib/ui/directives/view-mode.js.map +1 -0
- package/lib/ui/index.js +2 -2
- package/lib/ui/taon-admin-mode-configuration/index.js +2 -2
- package/lib/ui/taon-admin-mode-configuration/taon-admin-mode-configuration.component.d.ts +43 -0
- package/lib/ui/taon-admin-mode-configuration/taon-admin.models.d.ts +5 -0
- package/lib/ui/taon-admin-mode-configuration/taon-admin.models.js +3 -0
- package/lib/ui/taon-admin-mode-configuration/taon-admin.models.js.map +1 -0
- package/lib/ui/taon-full-material.module.d.ts +5 -0
- package/lib/ui/taon-github-fork-me-corner/index.d.ts +2 -0
- package/lib/ui/taon-github-fork-me-corner/index.js +5 -0
- package/lib/ui/taon-github-fork-me-corner/index.js.map +1 -0
- package/lib/ui/taon-github-fork-me-corner/taon-github-fork-me-corner.component.d.ts +3 -0
- package/lib/ui/taon-github-fork-me-corner/taon-github-fork-me-corner.module.d.ts +2 -0
- package/lib/ui/taon-github-fork-me-ribbon/index.d.ts +2 -0
- package/lib/ui/taon-github-fork-me-ribbon/index.js +5 -0
- package/lib/ui/taon-github-fork-me-ribbon/index.js.map +1 -0
- package/lib/ui/taon-github-fork-me-ribbon/taon-github-fork-me-ribbon.component.d.ts +3 -0
- package/lib/ui/taon-github-fork-me-ribbon/taon-github-fork-me-ribbon.module.d.ts +2 -0
- package/lib/ui/taon-notifications/index.d.ts +4 -0
- package/lib/ui/taon-notifications/index.js +24 -0
- package/lib/ui/taon-notifications/index.js.map +1 -0
- package/lib/ui/taon-notifications/taon-notifications.component.d.ts +9 -0
- package/lib/ui/taon-notifications/taon-notifications.models.d.ts +6 -0
- package/lib/ui/taon-notifications/taon-notifications.models.js +5 -0
- package/lib/ui/taon-notifications/taon-notifications.models.js.map +1 -0
- package/lib/ui/taon-notifications/taon-notifications.module.d.ts +2 -0
- package/lib/ui/taon-notifications/taon-notifications.service.d.ts +11 -0
- package/lib/ui/taon-progress-bar/index.d.ts +2 -0
- package/lib/ui/taon-progress-bar/index.js +5 -0
- package/lib/ui/taon-progress-bar/index.js.map +1 -0
- package/lib/ui/taon-progress-bar/taon-progress-bar.component.d.ts +13 -0
- package/lib/ui/taon-progress-bar/taon-progress-bar.module.d.ts +2 -0
- package/lib/ui/taon-session-passcode/index.d.ts +1 -0
- package/lib/ui/taon-session-passcode/index.js +5 -0
- package/lib/ui/taon-session-passcode/index.js.map +1 -0
- package/lib/ui/taon-session-passcode/taon-session-passcode.component.d.ts +35 -0
- package/lib/ui/taon-table/index.d.ts +2 -0
- package/lib/ui/taon-table/index.js +5 -0
- package/lib/ui/taon-table/index.js.map +1 -0
- package/lib/ui/taon-table/taon-table.component.d.ts +34 -0
- package/lib/ui/taon-table/taon-table.module.d.ts +2 -0
- package/lib/ui/taon.models.d.ts +11 -0
- package/lib/ui/taon.models.js +3 -0
- package/lib/ui/taon.models.js.map +1 -0
- package/package.json +1 -1
- package/tmp-environment.json +39 -0
- package/websql/fesm2022/taon.mjs +407 -235
- package/websql/fesm2022/taon.mjs.map +1 -1
- package/websql/lib/base-classes/base-angular-service.d.ts +3 -6
- package/websql/lib/base-classes/base-controller.d.ts +11 -0
- package/websql/lib/base-classes/base-file-upload.middleware.d.ts +15 -0
- package/websql/lib/base-classes/base-middleware.d.ts +30 -12
- package/websql/lib/decorators/classes/controller-config.d.ts +10 -0
- package/websql/lib/decorators/classes/controller-decorator.d.ts +2 -12
- package/websql/lib/decorators/classes/controller-options.d.ts +12 -0
- package/websql/lib/decorators/classes/entity-decorator.d.ts +2 -2
- package/websql/lib/decorators/classes/middleware-decorator.d.ts +2 -2
- package/websql/lib/decorators/classes/migration-decorator.d.ts +2 -2
- package/websql/lib/decorators/classes/provider-decorator.d.ts +2 -2
- package/websql/lib/decorators/classes/repository-decorator.d.ts +2 -2
- package/websql/lib/decorators/classes/subscriber-decorator.d.ts +2 -2
- package/websql/lib/decorators/decorator-abstract-opt.d.ts +4 -0
- package/websql/lib/decorators/http/http-methods-decorators.d.ts +8 -5
- package/websql/lib/endpoint-context.d.ts +4 -3
- package/websql/lib/helpers/class-helpers.d.ts +7 -3
- package/websql/lib/helpers/taon-helpers.d.ts +2 -1
- package/websql/lib/index.d.ts +2 -1
- package/websql/lib/models.d.ts +16 -24
- package/websql/package.json +1 -1
|
@@ -5,7 +5,6 @@ import type { Application } from 'express';
|
|
|
5
5
|
import type { Repository } from 'taon-typeorm';
|
|
6
6
|
import { DataSource } from 'taon-typeorm';
|
|
7
7
|
import type { BaseInjector } from './base-classes/base-injector';
|
|
8
|
-
export type { TaonMiddlewareInterceptOptions } from './base-classes/base-middleware';
|
|
9
8
|
import { ContextDbMigrations } from './context-db-migrations';
|
|
10
9
|
import { Models } from './models';
|
|
11
10
|
export declare class EndpointContext {
|
|
@@ -65,7 +64,7 @@ export declare class EndpointContext {
|
|
|
65
64
|
/**
|
|
66
65
|
* Inside docker there is not need for https secure server
|
|
67
66
|
*/
|
|
68
|
-
|
|
67
|
+
readonly isRunningInsideDocker: boolean;
|
|
69
68
|
constructor(originalConfig: Models.ContextOptions<any, any, any, any, any, any, any, any>, configFn: (env: any) => Models.ContextOptions<any, any, any, any, any, any, any, any>);
|
|
70
69
|
init(options?: {
|
|
71
70
|
initFromRecrusiveContextResovle?: boolean;
|
|
@@ -141,6 +140,7 @@ export declare class EndpointContext {
|
|
|
141
140
|
* ipc/udp needs this
|
|
142
141
|
*/
|
|
143
142
|
get contextName(): string;
|
|
143
|
+
get cwd(): string;
|
|
144
144
|
get activeContext(): string | null;
|
|
145
145
|
get appId(): string;
|
|
146
146
|
get publicAssets(): {
|
|
@@ -158,7 +158,8 @@ export declare class EndpointContext {
|
|
|
158
158
|
initControllers(): Promise<void>;
|
|
159
159
|
writeActiveRoutes(): void;
|
|
160
160
|
get middlewares(): Models.MiddlewareType[];
|
|
161
|
-
private
|
|
161
|
+
private initCustomClientMiddlewares;
|
|
162
|
+
private initCustomBackendMiddlewares;
|
|
162
163
|
private initBackendMiddlewares;
|
|
163
164
|
private initServer;
|
|
164
165
|
/**
|
package/lib/endpoint-context.js
CHANGED
|
@@ -8,8 +8,9 @@ const bodyParser = require("body-parser"); // @backend
|
|
|
8
8
|
const cookieParser = require("cookie-parser"); // @backend
|
|
9
9
|
const cors = require("cors"); // @backend
|
|
10
10
|
const electron_1 = require("electron"); // @backend
|
|
11
|
-
const express = require("express");
|
|
12
|
-
|
|
11
|
+
const express = require("express");
|
|
12
|
+
// multer in taon middleware will do better job than express-fileupload
|
|
13
|
+
// import * as fileUpload from 'express-fileupload'; // @backend
|
|
13
14
|
const expressSession = require("express-session"); // @backend
|
|
14
15
|
const lib_1 = require("json10/lib");
|
|
15
16
|
const lib_2 = require("lodash-walk-object/lib");
|
|
@@ -408,7 +409,11 @@ class EndpointContext {
|
|
|
408
409
|
if (this.mode === 'backend-frontend(tcp+udp)' && !this.config.abstract) {
|
|
409
410
|
//#region @backend
|
|
410
411
|
this.expressApp = express();
|
|
412
|
+
if (process.env.NODE_ENV === 'production') {
|
|
413
|
+
this.expressApp.set('trust proxy', 1);
|
|
414
|
+
}
|
|
411
415
|
await this.initBackendMiddlewares();
|
|
416
|
+
await this.initCustomBackendMiddlewares();
|
|
412
417
|
const shouldStartHttpsSecureServer = this.isHttpServer && !this.isRunningInsideDocker;
|
|
413
418
|
this.logFramework &&
|
|
414
419
|
lib_10.Helpers.info(`
|
|
@@ -426,7 +431,7 @@ class EndpointContext {
|
|
|
426
431
|
this.expressApp.use(asset.serverPath, express.static(asset.locationOnDisk));
|
|
427
432
|
});
|
|
428
433
|
//#endregion
|
|
429
|
-
await this.
|
|
434
|
+
await this.initCustomClientMiddlewares();
|
|
430
435
|
}
|
|
431
436
|
//#endregion
|
|
432
437
|
//#region prepare realtime
|
|
@@ -613,7 +618,7 @@ class EndpointContext {
|
|
|
613
618
|
lib_10.Helpers.log(`Express server (inside docker) started 0.0.0.0:${this.uriPort}`);
|
|
614
619
|
lib_10.Helpers.log(`[taon][express-server]listening on port: ${this.uriPort}, hostname: ${this.uriPathname},
|
|
615
620
|
address: ${this.uriProtocol}//localhost:${this.uriPort}${this.uriPathname}
|
|
616
|
-
|
|
621
|
+
ExpressJS mode: ${this.expressApp.settings.env}
|
|
617
622
|
`);
|
|
618
623
|
resolve(void 0);
|
|
619
624
|
});
|
|
@@ -623,8 +628,8 @@ class EndpointContext {
|
|
|
623
628
|
this.serverTcpUdp.listen(Number(this.uriPort), () => {
|
|
624
629
|
lib_10.Helpers.log(`Express server (inside nodejs app) started on localhost:${this.uriPort}`);
|
|
625
630
|
lib_10.Helpers.log(`[taon][express-server]listening on port: ${this.uriPort}, hostname: ${this.uriPathname},
|
|
626
|
-
|
|
627
|
-
|
|
631
|
+
address: ${this.uriProtocol}//localhost:${this.uriPort}${this.uriPathname}
|
|
632
|
+
expressJS mode: ${this.expressApp.settings.env}
|
|
628
633
|
`);
|
|
629
634
|
resolve(void 0);
|
|
630
635
|
});
|
|
@@ -1093,6 +1098,9 @@ class EndpointContext {
|
|
|
1093
1098
|
return this.config.contextName;
|
|
1094
1099
|
}
|
|
1095
1100
|
//#endregion
|
|
1101
|
+
get cwd() {
|
|
1102
|
+
return this.config.cwd || process.cwd();
|
|
1103
|
+
}
|
|
1096
1104
|
get activeContext() {
|
|
1097
1105
|
return this.config.activeContext || null;
|
|
1098
1106
|
}
|
|
@@ -1264,7 +1272,9 @@ class EndpointContext {
|
|
|
1264
1272
|
[taon][typeorm] db prepration done.. db initialize=${this.connection?.isInitialized}
|
|
1265
1273
|
|
|
1266
1274
|
|
|
1267
|
-
`,
|
|
1275
|
+
`,
|
|
1276
|
+
// dataSourceDbConfig,
|
|
1277
|
+
{ 'this.connection': !!this.connection });
|
|
1268
1278
|
console.log(`Database file location: ${this.connection.options.database}`);
|
|
1269
1279
|
}
|
|
1270
1280
|
// const entityMetadata = getMetadataArgsStorage();
|
|
@@ -1295,6 +1305,7 @@ class EndpointContext {
|
|
|
1295
1305
|
const configs = class_helpers_1.ClassHelpers.getControllerConfigs(controllerClassFn);
|
|
1296
1306
|
// console.log(`Class config for ${ClassHelpers.getName(controllerClassFn)}`, configs)
|
|
1297
1307
|
const classConfig = configs[0];
|
|
1308
|
+
//#region update class calculate path
|
|
1298
1309
|
const parentscalculatedPath = lib_10._.slice(configs, 1)
|
|
1299
1310
|
.reverse()
|
|
1300
1311
|
.map(bc => {
|
|
@@ -1318,6 +1329,7 @@ class EndpointContext {
|
|
|
1318
1329
|
}, [])
|
|
1319
1330
|
.join('/');
|
|
1320
1331
|
}
|
|
1332
|
+
//#endregion
|
|
1321
1333
|
// console.log('calculatedPath', classConfig.calculatedPath);
|
|
1322
1334
|
lib_10._.slice(configs, 1).forEach(bc => {
|
|
1323
1335
|
const alreadyIs = classConfig.methods;
|
|
@@ -1432,61 +1444,55 @@ class EndpointContext {
|
|
|
1432
1444
|
}
|
|
1433
1445
|
//#endregion
|
|
1434
1446
|
//#region methods & getters / init middlewares
|
|
1435
|
-
async
|
|
1436
|
-
const middlewares = this.getClassesInstancesArrBy(models_1.Models.ClassType.MIDDLEWARE)
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
});
|
|
1457
|
-
})(middlewareInstance, this.contextName, constants_1.apiPrefix, this.uriPathnameOrNothingIfRoot);
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1447
|
+
async initCustomClientMiddlewares() {
|
|
1448
|
+
const middlewares = this.getClassesInstancesArrBy(models_1.Models.ClassType.MIDDLEWARE)
|
|
1449
|
+
.map(f => f)
|
|
1450
|
+
.filter(f => lib_10._.isFunction(f.interceptClient));
|
|
1451
|
+
middlewares.forEach(instance => {
|
|
1452
|
+
const contextName = this.contextName;
|
|
1453
|
+
const interceptorName = `${contextName}-${class_helpers_1.ClassHelpers.getName(instance)}`;
|
|
1454
|
+
lib_3.Resource.request.interceptors.set(interceptorName, {
|
|
1455
|
+
intercept: ({ req, next }) => {
|
|
1456
|
+
const url = new url_1.URL(req.url);
|
|
1457
|
+
if (url.pathname.startsWith(`${this.uriPathnameOrNothingIfRoot}/${constants_1.apiPrefix}/${contextName}/`)) {
|
|
1458
|
+
// console.log('intercepting', url.pathname, req);
|
|
1459
|
+
return instance.interceptClient({
|
|
1460
|
+
req,
|
|
1461
|
+
next,
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1464
|
+
return next.handle(req);
|
|
1465
|
+
},
|
|
1466
|
+
});
|
|
1467
|
+
});
|
|
1460
1468
|
}
|
|
1461
|
-
async
|
|
1469
|
+
async initCustomBackendMiddlewares() {
|
|
1462
1470
|
//#region @backend
|
|
1463
1471
|
const app = this.expressApp;
|
|
1464
1472
|
const middlewares = this.getClassesInstancesArrBy(models_1.Models.ClassType.MIDDLEWARE);
|
|
1465
1473
|
for (const middleware of middlewares) {
|
|
1466
1474
|
const middlewareInstance = middleware;
|
|
1467
|
-
if (lib_10._.isFunction(middlewareInstance.
|
|
1468
|
-
((
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
res,
|
|
1478
|
-
},
|
|
1479
|
-
});
|
|
1480
|
-
}
|
|
1481
|
-
else {
|
|
1482
|
-
// console.log('not fit backend', url.href);
|
|
1483
|
-
}
|
|
1475
|
+
if (lib_10._.isFunction(middlewareInstance.interceptServer)) {
|
|
1476
|
+
const middlewareFn = class_helpers_1.ClassHelpers.asyncHandler(async (req, res, next) => {
|
|
1477
|
+
if (req.originalUrl.startsWith(`${this.uriPathnameOrNothingIfRoot}/${constants_1.apiPrefix}/${this.contextName}/`)) {
|
|
1478
|
+
await middlewareInstance.interceptServer({
|
|
1479
|
+
req,
|
|
1480
|
+
res,
|
|
1481
|
+
next,
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
else {
|
|
1484
1485
|
next();
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1486
|
+
}
|
|
1487
|
+
});
|
|
1488
|
+
app.use(middlewareFn);
|
|
1488
1489
|
}
|
|
1489
1490
|
}
|
|
1491
|
+
//#endregion
|
|
1492
|
+
}
|
|
1493
|
+
async initBackendMiddlewares() {
|
|
1494
|
+
//#region @backend
|
|
1495
|
+
const app = this.expressApp;
|
|
1490
1496
|
// if (this.middlewares) {
|
|
1491
1497
|
// this.middlewares.forEach(m => {
|
|
1492
1498
|
// const [fun, args] = m;
|
|
@@ -1496,7 +1502,7 @@ class EndpointContext {
|
|
|
1496
1502
|
this.expressApp.get('/helloworld', (req, res) => {
|
|
1497
1503
|
res.send(`Hello, world from context ${this.contextName}`);
|
|
1498
1504
|
});
|
|
1499
|
-
app.use(fileUpload());
|
|
1505
|
+
// app.use(fileUpload());
|
|
1500
1506
|
app.use(bodyParser.urlencoded({ extended: true }));
|
|
1501
1507
|
app.use(bodyParser.json());
|
|
1502
1508
|
app.use(methodOverride());
|
|
@@ -1576,16 +1582,31 @@ class EndpointContext {
|
|
|
1576
1582
|
//#region methods & getters / init methods node
|
|
1577
1583
|
initServer(
|
|
1578
1584
|
//#region parameters
|
|
1579
|
-
|
|
1585
|
+
httpMethodType, methodConfig, classConfig, expressPath, target) {
|
|
1580
1586
|
//#region resolve variables
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1587
|
+
const middlewareHandlers = (Array.isArray(methodConfig.middlewares) &&
|
|
1588
|
+
methodConfig.middlewares?.length > 0
|
|
1589
|
+
? methodConfig.middlewares
|
|
1590
|
+
: [])
|
|
1591
|
+
.map(middlewareClassFun => {
|
|
1592
|
+
const middlewareInstance = this.getInstanceBy(middlewareClassFun);
|
|
1593
|
+
if (middlewareInstance &&
|
|
1594
|
+
lib_10._.isFunction(middlewareInstance.interceptServerMethod)) {
|
|
1595
|
+
const middlewareFn = class_helpers_1.ClassHelpers.asyncHandler(async (req, res, next) => {
|
|
1596
|
+
await middlewareInstance.interceptServerMethod({
|
|
1597
|
+
req,
|
|
1598
|
+
res,
|
|
1599
|
+
next,
|
|
1600
|
+
}, {
|
|
1601
|
+
methodName: methodConfig.methodName,
|
|
1602
|
+
expressPath,
|
|
1603
|
+
httpRequestType: methodConfig.type,
|
|
1604
|
+
});
|
|
1605
|
+
});
|
|
1606
|
+
return middlewareFn;
|
|
1607
|
+
}
|
|
1608
|
+
})
|
|
1609
|
+
.filter(f => !!f);
|
|
1589
1610
|
// const url = this.uri;
|
|
1590
1611
|
//#region get result
|
|
1591
1612
|
const getResult = async (resolvedParams, req, res) => {
|
|
@@ -1595,7 +1616,7 @@ class EndpointContext {
|
|
|
1595
1616
|
*/
|
|
1596
1617
|
this.getInstanceBy(target),
|
|
1597
1618
|
/**
|
|
1598
|
-
* Params for
|
|
1619
|
+
* Params for method @GET, @PUT etc.
|
|
1599
1620
|
*/
|
|
1600
1621
|
resolvedParams);
|
|
1601
1622
|
let result = await (0, get_response_value_1.getResponseValue)(response, { req, res });
|
|
@@ -1623,15 +1644,17 @@ class EndpointContext {
|
|
|
1623
1644
|
//#region apply dummy websql express routers
|
|
1624
1645
|
//#region @websql
|
|
1625
1646
|
if (lib_10.Helpers.isWebSQL) {
|
|
1626
|
-
if (!this.expressApp[
|
|
1627
|
-
this.expressApp[
|
|
1647
|
+
if (!this.expressApp[httpMethodType.toLowerCase()]) {
|
|
1648
|
+
this.expressApp[httpMethodType.toLowerCase()] = () => { };
|
|
1649
|
+
// TODO add middlewares for WEBSQL and ELECTRON mode
|
|
1628
1650
|
}
|
|
1629
1651
|
}
|
|
1630
1652
|
//#endregion
|
|
1631
1653
|
//#endregion
|
|
1632
1654
|
//#region @backend
|
|
1633
|
-
this.logHttp &&
|
|
1634
|
-
|
|
1655
|
+
this.logHttp &&
|
|
1656
|
+
console.log(`[${httpMethodType.toUpperCase()}] ${expressPath} `);
|
|
1657
|
+
this.expressApp[httpMethodType.toLowerCase()](expressPath, ...middlewareHandlers, async (req, res) => {
|
|
1635
1658
|
// console.log(`[${type.toUpperCase()}] ${expressPath} `);
|
|
1636
1659
|
//#region process params
|
|
1637
1660
|
const args = [];
|
|
@@ -1816,10 +1839,31 @@ class EndpointContext {
|
|
|
1816
1839
|
*/
|
|
1817
1840
|
async initClient(
|
|
1818
1841
|
//#region parameters
|
|
1819
|
-
target,
|
|
1842
|
+
target, httpRequestType, methodConfig, // Models.Http.Rest.MethodConfig,
|
|
1843
|
+
expressPath) {
|
|
1820
1844
|
const ctx = this;
|
|
1845
|
+
//#region init middlewares
|
|
1846
|
+
const middlewares = methodConfig.middlewares
|
|
1847
|
+
.map(f => this.getInstanceBy(f))
|
|
1848
|
+
.filter(f => lib_10._.isFunction(f.interceptClientMethod));
|
|
1849
|
+
middlewares.forEach(instance => {
|
|
1850
|
+
lib_3.Resource.request.methodsInterceptors.set(`${methodConfig.type?.toUpperCase()}-${expressPath}`, {
|
|
1851
|
+
intercept: ({ req, next }) => {
|
|
1852
|
+
return instance.interceptClientMethod({
|
|
1853
|
+
req,
|
|
1854
|
+
next,
|
|
1855
|
+
}, {
|
|
1856
|
+
methodName: methodConfig.methodName,
|
|
1857
|
+
expressPath,
|
|
1858
|
+
httpRequestType: httpRequestType,
|
|
1859
|
+
});
|
|
1860
|
+
},
|
|
1861
|
+
});
|
|
1862
|
+
});
|
|
1863
|
+
//#endregion
|
|
1821
1864
|
// : { received: any; /* Rest<any, any> */ }
|
|
1822
|
-
this.logHttp &&
|
|
1865
|
+
this.logHttp &&
|
|
1866
|
+
console.log(`${httpRequestType?.toUpperCase()} ${expressPath} `);
|
|
1823
1867
|
// console.log('INITING', methodConfig); // TODO inject in static
|
|
1824
1868
|
//#region resolve storage
|
|
1825
1869
|
// TODO not a good idea
|
|
@@ -1873,6 +1917,9 @@ class EndpointContext {
|
|
|
1873
1917
|
received['observable'] = (0, rxjs_1.from)(received);
|
|
1874
1918
|
return {
|
|
1875
1919
|
received,
|
|
1920
|
+
request(axiosConfig) {
|
|
1921
|
+
return received;
|
|
1922
|
+
},
|
|
1876
1923
|
};
|
|
1877
1924
|
};
|
|
1878
1925
|
return;
|
|
@@ -2024,6 +2071,11 @@ class EndpointContext {
|
|
|
2024
2071
|
/* */
|
|
2025
2072
|
/* */
|
|
2026
2073
|
/* */
|
|
2074
|
+
/* */
|
|
2075
|
+
/* */
|
|
2076
|
+
/* */
|
|
2077
|
+
/* */
|
|
2078
|
+
/* */
|
|
2027
2079
|
//#endregion
|
|
2028
2080
|
//#region handle normal request
|
|
2029
2081
|
target.prototype[methodConfig.methodName] = function (...args) {
|
|
@@ -2064,8 +2116,7 @@ class EndpointContext {
|
|
|
2064
2116
|
else {
|
|
2065
2117
|
rest = endpoints[ctx.uriOrigin][expressPath];
|
|
2066
2118
|
}
|
|
2067
|
-
const method =
|
|
2068
|
-
const isWithBody = method === 'put' || method === 'post';
|
|
2119
|
+
const method = httpRequestType.toLowerCase();
|
|
2069
2120
|
const pathPrams = {};
|
|
2070
2121
|
let queryParams = {};
|
|
2071
2122
|
let bodyObject = {};
|
|
@@ -2163,9 +2214,11 @@ instead
|
|
|
2163
2214
|
}
|
|
2164
2215
|
//#endregion
|
|
2165
2216
|
const httpResultObj = {
|
|
2166
|
-
received:
|
|
2167
|
-
|
|
2168
|
-
|
|
2217
|
+
received: rest.model(pathPrams)[method](bodyObject, [queryParams]),
|
|
2218
|
+
request(axiosConfig) {
|
|
2219
|
+
return rest
|
|
2220
|
+
.model(pathPrams)[method](bodyObject, [queryParams], axiosConfig);
|
|
2221
|
+
},
|
|
2169
2222
|
};
|
|
2170
2223
|
return httpResultObj;
|
|
2171
2224
|
};
|