@breautek/storm 9.7.4 → 9.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/highlight.css +5 -5
- package/docs/assets/main.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +18 -3
- package/docs/classes/Application.html +959 -256
- package/docs/classes/Command.html +1470 -147
- package/docs/classes/ConfigLoader.html +110 -4
- package/docs/classes/Database.html +220 -3
- package/docs/classes/DatabaseCastObject.html +104 -3
- package/docs/classes/DatabaseConnection.html +484 -50
- package/docs/classes/DatabaseQueryError.html +264 -13
- package/docs/classes/DeadLockError.html +265 -14
- package/docs/classes/DiskSpaceError.html +245 -11
- package/docs/classes/DropTemporaryTableQuery.html +199 -12
- package/docs/classes/DuplicateEntryError.html +247 -11
- package/docs/classes/EntityNotFoundError.html +245 -11
- package/docs/classes/ExpiredTokenError.html +245 -11
- package/docs/classes/ForbiddenError.html +241 -11
- package/docs/classes/GetMySQLVersion.html +203 -12
- package/docs/classes/Handler.html +283 -3
- package/docs/classes/IllegalStateError.html +250 -12
- package/docs/classes/InternalError.html +245 -11
- package/docs/classes/InvalidCredentialsError.html +245 -11
- package/docs/classes/InvalidValueError.html +247 -11
- package/docs/classes/LineString.html +112 -3
- package/docs/classes/LockWaitTimeoutError.html +265 -14
- package/docs/classes/ManagedDatabaseConnection.html +349 -6
- package/docs/classes/MetricStore.html +119 -2
- package/docs/classes/Middleware.html +122 -3
- package/docs/classes/MissingConfigError.html +245 -11
- package/docs/classes/MissingParameterError.html +245 -11
- package/docs/classes/MySQLConnection.html +509 -54
- package/docs/classes/MySQLDatabase.html +235 -3
- package/docs/classes/NotImplementedError.html +245 -11
- package/docs/classes/Point.html +113 -3
- package/docs/classes/Polygon.html +112 -3
- package/docs/classes/Query.html +220 -12
- package/docs/classes/RawError.html +249 -12
- package/docs/classes/RawQuery.html +212 -12
- package/docs/classes/Request.html +345 -8
- package/docs/classes/Response.html +204 -3
- package/docs/classes/ResponseData.html +162 -5
- package/docs/classes/ServiceProvider.html +243 -3
- package/docs/classes/ServiceResponse.html +108 -3
- package/docs/classes/SetSessionVariableQuery.html +199 -12
- package/docs/classes/StormError.html +261 -11
- package/docs/classes/TemporaryTableQuery.html +203 -12
- package/docs/classes/TimeoutError.html +246 -12
- package/docs/classes/Token.html +80 -3
- package/docs/classes/TokenManager.html +137 -5
- package/docs/classes/Transaction.html +163 -4
- package/docs/classes/UnauthorizedAccessError.html +245 -11
- package/docs/enums/ErrorCode.html +94 -2
- package/docs/enums/ExitCode.html +59 -2
- package/docs/enums/HTTPMethod.html +69 -2
- package/docs/enums/IsolationLevel.html +69 -2
- package/docs/enums/JWTError.html +59 -2
- package/docs/enums/StatusCode.html +289 -2
- package/docs/enums/TransactionAccessLevel.html +64 -3
- package/docs/functions/getInstance.html +42 -2
- package/docs/hierarchy.html +83 -1
- package/docs/index.html +59 -1
- package/docs/interfaces/IAdditionalErrorDetails.html +37 -1
- package/docs/interfaces/IAuthTokenData.html +65 -2
- package/docs/interfaces/ICloudwatchConfig.html +65 -2
- package/docs/interfaces/ICloudwatchCredentials.html +60 -2
- package/docs/interfaces/ICloudwatchStreamConfig.html +60 -2
- package/docs/interfaces/IConfig.html +114 -3
- package/docs/interfaces/IDatabaseConfig.html +84 -2
- package/docs/interfaces/IDatabaseConnection.html +270 -5
- package/docs/interfaces/IDatabasePosition.html +65 -3
- package/docs/interfaces/IErrorResponse.html +75 -2
- package/docs/interfaces/IFormData.html +60 -2
- package/docs/interfaces/IGetMySQLVersionResult.html +70 -2
- package/docs/interfaces/IGetMySQLVersionRow.html +55 -2
- package/docs/interfaces/IHistogramConfig.html +79 -2
- package/docs/interfaces/IInsertQueryResult.html +65 -2
- package/docs/interfaces/IJWTVerifyOptions.html +55 -2
- package/docs/interfaces/IMetricConfig.html +71 -2
- package/docs/interfaces/IMetricCounter.html +74 -2
- package/docs/interfaces/IMetricGauge.html +122 -2
- package/docs/interfaces/IMetricHistogram.html +87 -2
- package/docs/interfaces/IOKPacket.html +95 -3
- package/docs/interfaces/IParameterMap.html +37 -1
- package/docs/interfaces/IQueryable.html +134 -2
- package/docs/interfaces/IRequestResponse.html +65 -2
- package/docs/interfaces/ISetSessionVariableQueryInput.html +60 -2
- package/docs/interfaces/IStormCLIArgs.html +85 -2
- package/docs/interfaces/ITemporaryTableQueryInput.html +60 -2
- package/docs/interfaces/IUpdateQueryResult.html +60 -2
- package/docs/interfaces/formidable.EmitData.html +71 -2
- package/docs/interfaces/formidable.EventData.html +86 -2
- package/docs/interfaces/formidable.File.html +138 -12
- package/docs/interfaces/formidable.FileJSON.html +120 -9
- package/docs/interfaces/formidable.Options.html +226 -32
- package/docs/interfaces/formidable.Part.html +534 -64
- package/docs/modules/formidable.html +41 -1
- package/docs/types/IDeleteQueryResult.html +33 -1
- package/docs/types/IStoredProcedureResult.html +44 -3
- package/docs/types/TCoordinate.html +33 -1
- package/docs/types/TExpiresIn.html +33 -1
- package/docs/types/TSerializableResponse.html +41 -4
- package/docs/types/TSupportedResponsePrimitives.html +33 -1
- package/docs/types/TSupportedResponseTypes.html +33 -1
- package/docs/types/formidable.BufferEncoding.html +34 -1
- package/docs/types/formidable.DefaultOptions.html +34 -1
- package/docs/types/formidable.EnabledPlugins.html +34 -1
- package/docs/types/formidable.EventNames.html +64 -8
- package/docs/types/formidable.Fields.html +38 -1
- package/docs/types/formidable.Files.html +38 -1
- package/docs/types/formidable.FormidableError.html +34 -1
- package/docs/types/formidable.MappedParsers.html +34 -1
- package/docs/types/formidable.Plugin.html +34 -1
- package/docs/types/formidable.PluginFunction.html +47 -1
- package/docs/types/formidable.Plugins.html +34 -1
- package/docs/variables/formidable.html +81 -1
- package/lib/Application.d.ts +9 -1
- package/lib/Application.js +12 -1
- package/lib/Application.js.map +1 -1
- package/lib/HandlerAttacher.d.ts +10 -0
- package/lib/HandlerAttacher.js +31 -0
- package/lib/HandlerAttacher.js.map +1 -0
- package/lib/IHandlerAttachBridge.d.ts +4 -0
- package/lib/IHandlerAttachBridge.js +3 -0
- package/lib/IHandlerAttachBridge.js.map +1 -0
- package/lib/MySQLConnection.js +2 -2
- package/lib/RawHandlerAttacher.d.ts +11 -0
- package/lib/RawHandlerAttacher.js +37 -0
- package/lib/RawHandlerAttacher.js.map +1 -0
- package/package.json +8 -9
- package/pnpm-workspace.yaml +7 -1
- package/src/Application.ts +17 -2
- package/src/HandlerAttacher.ts +37 -0
- package/src/IHandlerAttachBridge.ts +6 -0
- package/src/MySQLConnection.ts +2 -2
- package/src/RawHandlerAttacher.ts +44 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Express = require('express');
|
|
2
|
+
import { Application } from './Application';
|
|
3
|
+
import { Handler } from './Handler';
|
|
4
|
+
import { IHandlerAttachBridge } from './IHandlerAttachBridge';
|
|
5
|
+
export declare class RawHandlerAttacher implements IHandlerAttachBridge {
|
|
6
|
+
private $server;
|
|
7
|
+
private $app;
|
|
8
|
+
private $parser;
|
|
9
|
+
constructor(app: Application, server: Express.Application);
|
|
10
|
+
attach(path: string, handler: Handler): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RawHandlerAttacher = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Request_1 = require("./Request");
|
|
6
|
+
const Response_1 = require("./Response");
|
|
7
|
+
const BodyParser = tslib_1.__importStar(require("body-parser"));
|
|
8
|
+
class RawHandlerAttacher {
|
|
9
|
+
constructor(app, server) {
|
|
10
|
+
this.$server = server;
|
|
11
|
+
this.$app = app;
|
|
12
|
+
this.$parser = BodyParser.raw({
|
|
13
|
+
type: '*/*',
|
|
14
|
+
limit: app.getRequestSizeLimit()
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
attach(path, handler) {
|
|
18
|
+
this.$server.get(path, this.$parser, (request, response) => {
|
|
19
|
+
let r = new Request_1.Request(request);
|
|
20
|
+
void handler.get(r, new Response_1.Response(this.$app, response, r.getURL()));
|
|
21
|
+
});
|
|
22
|
+
this.$server.post(path, this.$parser, (request, response) => {
|
|
23
|
+
let r = new Request_1.Request(request);
|
|
24
|
+
void handler.post(r, new Response_1.Response(this.$app, response, r.getURL()));
|
|
25
|
+
});
|
|
26
|
+
this.$server.put(path, this.$parser, (request, response) => {
|
|
27
|
+
let r = new Request_1.Request(request);
|
|
28
|
+
void handler.put(r, new Response_1.Response(this.$app, response, r.getURL()));
|
|
29
|
+
});
|
|
30
|
+
this.$server.delete(path, this.$parser, (request, response) => {
|
|
31
|
+
let r = new Request_1.Request(request);
|
|
32
|
+
void handler.delete(r, new Response_1.Response(this.$app, response, r.getURL()));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.RawHandlerAttacher = RawHandlerAttacher;
|
|
37
|
+
//# sourceMappingURL=RawHandlerAttacher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RawHandlerAttacher.js","sourceRoot":"","sources":["../src/RawHandlerAttacher.ts"],"names":[],"mappings":";;;;AAMA,uCAAkC;AAClC,yCAAoC;AACpC,gEAA0C;AAE1C,MAAa,kBAAkB;IAK3B,YAAmB,GAAgB,EAAE,MAA2B;QAC5D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAEhB,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,CAAC;YAC1B,IAAI,EAAE,KAAK;YACX,KAAK,EAAE,GAAG,CAAC,mBAAmB,EAAE;SACnC,CAAC,CAAC;IACP,CAAC;IAEM,MAAM,CAAC,IAAY,EAAE,OAAgB;QACxC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,OAAwB,EAAE,QAA0B,EAAE,EAAE;YAC1F,IAAI,CAAC,GAAY,IAAI,iBAAO,CAAC,OAAO,CAAC,CAAC;YACtC,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,mBAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,OAAwB,EAAE,QAA0B,EAAE,EAAE;YAC3F,IAAI,CAAC,GAAY,IAAI,iBAAO,CAAC,OAAO,CAAC,CAAC;YACtC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,mBAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACxE,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,OAAwB,EAAE,QAA0B,EAAE,EAAE;YAC1F,IAAI,CAAC,GAAY,IAAI,iBAAO,CAAC,OAAO,CAAC,CAAC;YACtC,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,mBAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,OAAwB,EAAE,QAA0B,EAAE,EAAE;YAC7F,IAAI,CAAC,GAAY,IAAI,iBAAO,CAAC,OAAO,CAAC,CAAC;YACtC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,mBAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAjCD,gDAiCC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@breautek/storm",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.8.0",
|
|
4
4
|
"description": "Object-Oriented REST API framework",
|
|
5
5
|
"main": "lib/api.js",
|
|
6
6
|
"types": "lib/api.d.ts",
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"unit": "jest",
|
|
18
18
|
"test": "npm run-script lint && jest",
|
|
19
19
|
"coverage": "codecov",
|
|
20
|
-
"clean": "rm -r ./lib && rm -r ./docs",
|
|
21
20
|
"prepublishOnly": "npm run-script build-lib",
|
|
22
21
|
"changelog": "auto-changelog --output CHANGELOG.md -p --release-summary --ignore-commit-pattern chore",
|
|
23
22
|
"preversion": "npm test",
|
|
@@ -56,9 +55,9 @@
|
|
|
56
55
|
"form-data": "4.0.6",
|
|
57
56
|
"formidable": "3.5.4",
|
|
58
57
|
"jsonwebtoken": "9.0.3",
|
|
59
|
-
"mysql2": "3.
|
|
58
|
+
"mysql2": "3.24.2",
|
|
60
59
|
"prom-client": "15.1.3",
|
|
61
|
-
"sql-formatter": "15.8.
|
|
60
|
+
"sql-formatter": "15.8.2",
|
|
62
61
|
"tslib": "2.8.1"
|
|
63
62
|
},
|
|
64
63
|
"peerDependencies": {
|
|
@@ -67,20 +66,20 @@
|
|
|
67
66
|
},
|
|
68
67
|
"devDependencies": {
|
|
69
68
|
"@arashi/interfaces": "1.2.1",
|
|
70
|
-
"@arashi/logger": "4.1.
|
|
69
|
+
"@arashi/logger": "4.1.7",
|
|
71
70
|
"@jest/types": "30.4.1",
|
|
72
|
-
"@totalpave/eslint-plugin": "7.1.
|
|
71
|
+
"@totalpave/eslint-plugin": "7.1.2",
|
|
73
72
|
"@types/body-parser": "1.19.6",
|
|
74
73
|
"@types/jest": "30.0.0",
|
|
75
74
|
"@types/jsonwebtoken": "9.0.10",
|
|
76
75
|
"@types/mysql": "2.15.27",
|
|
77
|
-
"@types/node": "
|
|
76
|
+
"@types/node": "26.3.0",
|
|
78
77
|
"auto-changelog": "2.6.0",
|
|
79
78
|
"jest": "30.4.2",
|
|
80
79
|
"jest-jasmine2": "30.4.2",
|
|
81
|
-
"ts-jest": "29.4.
|
|
80
|
+
"ts-jest": "29.4.12",
|
|
82
81
|
"ts-node": "10.9.2",
|
|
83
|
-
"typedoc": "0.28.
|
|
82
|
+
"typedoc": "0.28.20",
|
|
84
83
|
"typedoc-plugin-markdown": "4.12.0",
|
|
85
84
|
"typescript": "5.9.3"
|
|
86
85
|
}
|
package/pnpm-workspace.yaml
CHANGED
package/src/Application.ts
CHANGED
|
@@ -40,6 +40,9 @@ import { StormError } from './StormError';
|
|
|
40
40
|
import { PrometheusServer } from './PrometheusServer';
|
|
41
41
|
import { MetricStore } from './MetricStore';
|
|
42
42
|
import * as OS from 'node:os';
|
|
43
|
+
import { IHandlerAttachBridge } from './IHandlerAttachBridge';
|
|
44
|
+
import { RawHandlerAttacher } from './RawHandlerAttacher';
|
|
45
|
+
import { HandlerAttacher } from './HandlerAttacher';
|
|
43
46
|
|
|
44
47
|
export interface IStormCLIArgs {
|
|
45
48
|
bind?: string;
|
|
@@ -192,6 +195,10 @@ export abstract class Application
|
|
|
192
195
|
|
|
193
196
|
this.$getLogger().trace(TAG, 'Starting server...');
|
|
194
197
|
this.$server = Express();
|
|
198
|
+
this.$server.set('trust proxy', 'loopback');
|
|
199
|
+
|
|
200
|
+
await this._attachRawHandlers(new RawHandlerAttacher(this, this.$server));
|
|
201
|
+
|
|
195
202
|
this.$server.use(BodyParser.json({
|
|
196
203
|
type : 'application/json',
|
|
197
204
|
limit : this.getRequestSizeLimit()
|
|
@@ -211,7 +218,7 @@ export abstract class Application
|
|
|
211
218
|
|
|
212
219
|
this.$getLogger().trace(TAG, 'Attaching handlers...');
|
|
213
220
|
await this.$attachHandlers();
|
|
214
|
-
await this._attachHandlers();
|
|
221
|
+
await this._attachHandlers(new HandlerAttacher(this, this.$server));
|
|
215
222
|
|
|
216
223
|
await this._onBeforeReadyAsync();
|
|
217
224
|
|
|
@@ -400,11 +407,17 @@ export abstract class Application
|
|
|
400
407
|
*
|
|
401
408
|
* @param path The URL API path. E.g. /api/myService/myCommand/
|
|
402
409
|
* @param Handler
|
|
410
|
+
* @deprecated - Use {@link IHandlerAttachBridge} instead
|
|
403
411
|
*/
|
|
404
412
|
public attachHandler(path: string, handler: Handler): void {
|
|
405
413
|
this.attachHandlerInstance(path, handler);
|
|
406
414
|
}
|
|
407
415
|
|
|
416
|
+
/**
|
|
417
|
+
* @deprecated - Use {@link IHandlerAttachBridge} instead
|
|
418
|
+
* @param path
|
|
419
|
+
* @param handler
|
|
420
|
+
*/
|
|
408
421
|
public attachHandlerInstance(path: string, handler: Handler): void {
|
|
409
422
|
this.$server.get(path, (request: Express.Request, response: Express.Response) => {
|
|
410
423
|
let r: Request = new Request(request);
|
|
@@ -454,7 +467,9 @@ export abstract class Application
|
|
|
454
467
|
* Subclasses are expected to attach the API handlers for their service. This will be invoked during application startup.
|
|
455
468
|
* @returns Promise<void>
|
|
456
469
|
*/
|
|
457
|
-
protected abstract _attachHandlers(): Promise<void>;
|
|
470
|
+
protected abstract _attachHandlers(attacher: IHandlerAttachBridge): Promise<void>;
|
|
471
|
+
|
|
472
|
+
protected async _attachRawHandlers(attacher: IHandlerAttachBridge): Promise<void> {}
|
|
458
473
|
|
|
459
474
|
/**
|
|
460
475
|
* @deprecated Supply the configs via --config and --local-config arguments
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
3
|
+
import Express = require('express');
|
|
4
|
+
import {Application} from './Application';
|
|
5
|
+
import { Handler } from './Handler';
|
|
6
|
+
import { IHandlerAttachBridge } from './IHandlerAttachBridge';
|
|
7
|
+
import {Request} from './Request';
|
|
8
|
+
import {Response} from './Response';
|
|
9
|
+
|
|
10
|
+
export class HandlerAttacher implements IHandlerAttachBridge {
|
|
11
|
+
private $server: Express.Application;
|
|
12
|
+
private $app: Application;
|
|
13
|
+
|
|
14
|
+
public constructor(app: Application, server: Express.Application) {
|
|
15
|
+
this.$server = server;
|
|
16
|
+
this.$app = app;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public attach(path: string, handler: Handler): void {
|
|
20
|
+
this.$server.get(path, (request: Express.Request, response: Express.Response) => {
|
|
21
|
+
let r: Request = new Request(request);
|
|
22
|
+
void handler.get(r, new Response(this.$app, response, r.getURL()));
|
|
23
|
+
});
|
|
24
|
+
this.$server.post(path, (request: Express.Request, response: Express.Response) => {
|
|
25
|
+
let r: Request = new Request(request);
|
|
26
|
+
void handler.post(r, new Response(this.$app, response, r.getURL()));
|
|
27
|
+
});
|
|
28
|
+
this.$server.put(path, (request: Express.Request, response: Express.Response) => {
|
|
29
|
+
let r: Request = new Request(request);
|
|
30
|
+
void handler.put(r, new Response(this.$app, response, r.getURL()));
|
|
31
|
+
});
|
|
32
|
+
this.$server.delete(path, (request: Express.Request, response: Express.Response) => {
|
|
33
|
+
let r: Request = new Request(request);
|
|
34
|
+
void handler.delete(r, new Response(this.$app, response, r.getURL()));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/MySQLConnection.ts
CHANGED
|
@@ -266,8 +266,8 @@ export class MySQLConnection extends DatabaseConnection<MySQL.PoolConnection> {
|
|
|
266
266
|
streamOptions = {};
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
-
if (!streamOptions.
|
|
270
|
-
streamOptions.
|
|
269
|
+
if (!streamOptions.highWaterMark) {
|
|
270
|
+
streamOptions.highWaterMark = DEFAULT_HIGH_WATERMARK;
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
let queryObject: MySQL.Query = this.getAPI().query({
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
3
|
+
import Express = require('express');
|
|
4
|
+
import {Application} from './Application';
|
|
5
|
+
import { Handler } from './Handler';
|
|
6
|
+
import { IHandlerAttachBridge } from './IHandlerAttachBridge';
|
|
7
|
+
import {Request} from './Request';
|
|
8
|
+
import {Response} from './Response';
|
|
9
|
+
import * as BodyParser from 'body-parser';
|
|
10
|
+
|
|
11
|
+
export class RawHandlerAttacher implements IHandlerAttachBridge {
|
|
12
|
+
private $server: Express.Application;
|
|
13
|
+
private $app: Application;
|
|
14
|
+
private $parser: ReturnType<typeof BodyParser.raw>;
|
|
15
|
+
|
|
16
|
+
public constructor(app: Application, server: Express.Application) {
|
|
17
|
+
this.$server = server;
|
|
18
|
+
this.$app = app;
|
|
19
|
+
|
|
20
|
+
this.$parser = BodyParser.raw({
|
|
21
|
+
type: '*/*',
|
|
22
|
+
limit: app.getRequestSizeLimit()
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public attach(path: string, handler: Handler): void {
|
|
27
|
+
this.$server.get(path, this.$parser, (request: Express.Request, response: Express.Response) => {
|
|
28
|
+
let r: Request = new Request(request);
|
|
29
|
+
void handler.get(r, new Response(this.$app, response, r.getURL()));
|
|
30
|
+
});
|
|
31
|
+
this.$server.post(path, this.$parser, (request: Express.Request, response: Express.Response) => {
|
|
32
|
+
let r: Request = new Request(request);
|
|
33
|
+
void handler.post(r, new Response(this.$app, response, r.getURL()));
|
|
34
|
+
});
|
|
35
|
+
this.$server.put(path, this.$parser, (request: Express.Request, response: Express.Response) => {
|
|
36
|
+
let r: Request = new Request(request);
|
|
37
|
+
void handler.put(r, new Response(this.$app, response, r.getURL()));
|
|
38
|
+
});
|
|
39
|
+
this.$server.delete(path, this.$parser, (request: Express.Request, response: Express.Response) => {
|
|
40
|
+
let r: Request = new Request(request);
|
|
41
|
+
void handler.delete(r, new Response(this.$app, response, r.getURL()));
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|