mini-nest 1.0.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/LICENSE +0 -0
- package/README.md +556 -0
- package/dist/aop/aopWrapper.d.ts +17 -0
- package/dist/aop/aopWrapper.d.ts.map +1 -0
- package/dist/aop/aopWrapper.js +112 -0
- package/dist/aop/aopWrapper.js.map +1 -0
- package/dist/cache/cacheManager.d.ts +11 -0
- package/dist/cache/cacheManager.d.ts.map +1 -0
- package/dist/cache/cacheManager.js +42 -0
- package/dist/cache/cacheManager.js.map +1 -0
- package/dist/circuitBreaker/circuitBreakerManager.d.ts +21 -0
- package/dist/circuitBreaker/circuitBreakerManager.d.ts.map +1 -0
- package/dist/circuitBreaker/circuitBreakerManager.js +60 -0
- package/dist/circuitBreaker/circuitBreakerManager.js.map +1 -0
- package/dist/circuitBreaker/circuitOpenError.d.ts +4 -0
- package/dist/circuitBreaker/circuitOpenError.d.ts.map +1 -0
- package/dist/circuitBreaker/circuitOpenError.js +11 -0
- package/dist/circuitBreaker/circuitOpenError.js.map +1 -0
- package/dist/container.js +33 -0
- package/dist/controller.js +10 -0
- package/dist/core/app/App.d.ts +31 -0
- package/dist/core/app/App.d.ts.map +1 -0
- package/dist/core/app/App.js +149 -0
- package/dist/core/app/App.js.map +1 -0
- package/dist/core/container/container.d.ts +16 -0
- package/dist/core/container/container.d.ts.map +1 -0
- package/dist/core/container/container.js +61 -0
- package/dist/core/container/container.js.map +1 -0
- package/dist/core/pipeline/ExecutionContext.d.ts +22 -0
- package/dist/core/pipeline/ExecutionContext.d.ts.map +1 -0
- package/dist/core/pipeline/ExecutionContext.js +31 -0
- package/dist/core/pipeline/ExecutionContext.js.map +1 -0
- package/dist/core/pipeline/RequestPipeline.d.ts +9 -0
- package/dist/core/pipeline/RequestPipeline.d.ts.map +1 -0
- package/dist/core/pipeline/RequestPipeline.js +83 -0
- package/dist/core/pipeline/RequestPipeline.js.map +1 -0
- package/dist/createMethodDecorator.js +22 -0
- package/dist/createParamDecorator.js +46 -0
- package/dist/decorators/Injectable.d.ts +3 -0
- package/dist/decorators/Injectable.d.ts.map +1 -0
- package/dist/decorators/Injectable.js +10 -0
- package/dist/decorators/Injectable.js.map +1 -0
- package/dist/decorators/UseGuard.d.ts +6 -0
- package/dist/decorators/UseGuard.d.ts.map +1 -0
- package/dist/decorators/UseGuard.js +20 -0
- package/dist/decorators/UseGuard.js.map +1 -0
- package/dist/decorators/UseInterceptor.d.ts +5 -0
- package/dist/decorators/UseInterceptor.d.ts.map +1 -0
- package/dist/decorators/UseInterceptor.js +15 -0
- package/dist/decorators/UseInterceptor.js.map +1 -0
- package/dist/decorators/aop/Cache.d.ts +6 -0
- package/dist/decorators/aop/Cache.d.ts.map +1 -0
- package/dist/decorators/aop/Cache.js +13 -0
- package/dist/decorators/aop/Cache.js.map +1 -0
- package/dist/decorators/aop/CircuitBreaker.d.ts +6 -0
- package/dist/decorators/aop/CircuitBreaker.d.ts.map +1 -0
- package/dist/decorators/aop/CircuitBreaker.js +10 -0
- package/dist/decorators/aop/CircuitBreaker.js.map +1 -0
- package/dist/decorators/aop/Retry.d.ts +2 -0
- package/dist/decorators/aop/Retry.d.ts.map +1 -0
- package/dist/decorators/aop/Retry.js +10 -0
- package/dist/decorators/aop/Retry.js.map +1 -0
- package/dist/decorators/aop/Timeout.d.ts +2 -0
- package/dist/decorators/aop/Timeout.d.ts.map +1 -0
- package/dist/decorators/aop/Timeout.js +10 -0
- package/dist/decorators/aop/Timeout.js.map +1 -0
- package/dist/decorators/http/Controller.d.ts +3 -0
- package/dist/decorators/http/Controller.d.ts.map +1 -0
- package/dist/decorators/http/Controller.js +11 -0
- package/dist/decorators/http/Controller.js.map +1 -0
- package/dist/decorators/http/CreateMethodDecorator.d.ts +8 -0
- package/dist/decorators/http/CreateMethodDecorator.d.ts.map +1 -0
- package/dist/decorators/http/CreateMethodDecorator.js +20 -0
- package/dist/decorators/http/CreateMethodDecorator.js.map +1 -0
- package/dist/decorators/http/CreateParamDecorator.d.ts +13 -0
- package/dist/decorators/http/CreateParamDecorator.d.ts.map +1 -0
- package/dist/decorators/http/CreateParamDecorator.js +57 -0
- package/dist/decorators/http/CreateParamDecorator.js.map +1 -0
- package/dist/decorators/index.d.ts +11 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +37 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators.js +1 -0
- package/dist/examples/User.example.js +12 -0
- package/dist/examples/container.example.js +31 -0
- package/dist/examples/container.example.mjs +42 -0
- package/dist/examples/controllers/LogController.js +33 -0
- package/dist/examples/controllers/UserController.js +68 -0
- package/dist/examples/createTestApp.js +23 -0
- package/dist/examples/interceptors/LoggerInterceptor.js +12 -0
- package/dist/examples/log.example.js +6 -0
- package/dist/examples/services/LoggerService.js +19 -0
- package/dist/examples/services/UserService.js +40 -0
- package/dist/exceptions/HTTPExceptions.d.ts +36 -0
- package/dist/exceptions/HTTPExceptions.d.ts.map +1 -0
- package/dist/exceptions/HTTPExceptions.js +62 -0
- package/dist/exceptions/HTTPExceptions.js.map +1 -0
- package/dist/exceptions/baseHTTPException.d.ts +16 -0
- package/dist/exceptions/baseHTTPException.d.ts.map +1 -0
- package/dist/exceptions/baseHTTPException.js +25 -0
- package/dist/exceptions/baseHTTPException.js.map +1 -0
- package/dist/exceptions/defaultExceptionFilter.d.ts +10 -0
- package/dist/exceptions/defaultExceptionFilter.d.ts.map +1 -0
- package/dist/exceptions/defaultExceptionFilter.js +65 -0
- package/dist/exceptions/defaultExceptionFilter.js.map +1 -0
- package/dist/exceptions/exceptionFilter.d.ts +6 -0
- package/dist/exceptions/exceptionFilter.d.ts.map +1 -0
- package/dist/exceptions/exceptionFilter.js +3 -0
- package/dist/exceptions/exceptionFilter.js.map +1 -0
- package/dist/exceptions/exceptionHandler.d.ts +12 -0
- package/dist/exceptions/exceptionHandler.d.ts.map +1 -0
- package/dist/exceptions/exceptionHandler.js +50 -0
- package/dist/exceptions/exceptionHandler.js.map +1 -0
- package/dist/exceptions/index.d.ts +6 -0
- package/dist/exceptions/index.d.ts.map +1 -0
- package/dist/exceptions/index.js +22 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/guards/Guard.d.ts +5 -0
- package/dist/guards/Guard.d.ts.map +1 -0
- package/dist/guards/Guard.js +3 -0
- package/dist/guards/Guard.js.map +1 -0
- package/dist/guards/applyGuard.d.ts +5 -0
- package/dist/guards/applyGuard.d.ts.map +1 -0
- package/dist/guards/applyGuard.js +15 -0
- package/dist/guards/applyGuard.js.map +1 -0
- package/dist/http/HttpRequest.d.ts +52 -0
- package/dist/http/HttpRequest.d.ts.map +1 -0
- package/dist/http/HttpRequest.js +103 -0
- package/dist/http/HttpRequest.js.map +1 -0
- package/dist/http/HttpResponse.d.ts +20 -0
- package/dist/http/HttpResponse.d.ts.map +1 -0
- package/dist/http/HttpResponse.js +63 -0
- package/dist/http/HttpResponse.js.map +1 -0
- package/dist/http/adapters/expressAdapter.d.ts +17 -0
- package/dist/http/adapters/expressAdapter.d.ts.map +1 -0
- package/dist/http/adapters/expressAdapter.js +91 -0
- package/dist/http/adapters/expressAdapter.js.map +1 -0
- package/dist/http/adapters/fastifyAdapter.d.ts +17 -0
- package/dist/http/adapters/fastifyAdapter.d.ts.map +1 -0
- package/dist/http/adapters/fastifyAdapter.js +91 -0
- package/dist/http/adapters/fastifyAdapter.js.map +1 -0
- package/dist/http/adapters/httpAdapter.d.ts +14 -0
- package/dist/http/adapters/httpAdapter.d.ts.map +1 -0
- package/dist/http/adapters/httpAdapter.js +3 -0
- package/dist/http/adapters/httpAdapter.js.map +1 -0
- package/dist/http/client/httpClient.d.ts +51 -0
- package/dist/http/client/httpClient.d.ts.map +1 -0
- package/dist/http/client/httpClient.js +163 -0
- package/dist/http/client/httpClient.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/dist/injectable.js +12 -0
- package/dist/interceptor.js +44 -0
- package/dist/interceptors/Interceptor.d.ts +4 -0
- package/dist/interceptors/Interceptor.d.ts.map +1 -0
- package/dist/interceptors/Interceptor.js +3 -0
- package/dist/interceptors/Interceptor.js.map +1 -0
- package/dist/interceptors/applyInterceptor.d.ts +5 -0
- package/dist/interceptors/applyInterceptor.d.ts.map +1 -0
- package/dist/interceptors/applyInterceptor.js +22 -0
- package/dist/interceptors/applyInterceptor.js.map +1 -0
- package/dist/lifecycle/lifecycle.d.ts +23 -0
- package/dist/lifecycle/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle/lifecycle.js +3 -0
- package/dist/lifecycle/lifecycle.js.map +1 -0
- package/dist/main.js +6 -0
- package/dist/metadata.js +83 -0
- package/dist/middleware/middleware.d.ts +14 -0
- package/dist/middleware/middleware.d.ts.map +1 -0
- package/dist/middleware/middleware.js +41 -0
- package/dist/middleware/middleware.js.map +1 -0
- package/dist/middleware/type.d.ts +4 -0
- package/dist/middleware/type.d.ts.map +1 -0
- package/dist/middleware/type.js +3 -0
- package/dist/middleware/type.js.map +1 -0
- package/dist/paramRegistry.js +4 -0
- package/dist/request/createMethodDecorator.js +22 -0
- package/dist/request/createParamDecorator.js +46 -0
- package/dist/request/interceptor.js +44 -0
- package/dist/request/metadata.js +83 -0
- package/dist/request/paramRegistry.js +4 -0
- package/dist/request/resolveHandlerArgument.js +108 -0
- package/dist/request/routeMatch.js +24 -0
- package/dist/request/routeRegistry.js +107 -0
- package/dist/request/utils/normalizePath.js +16 -0
- package/dist/request/validation/rule.js +44 -0
- package/dist/request/validation/validationErrorException.js +8 -0
- package/dist/resolveHandlerArgument.js +33 -0
- package/dist/routeMatch.js +24 -0
- package/dist/routeRegistry.js +108 -0
- package/dist/routes.js +1 -0
- package/dist/routing/metadata.d.ts +19 -0
- package/dist/routing/metadata.d.ts.map +1 -0
- package/dist/routing/metadata.js +65 -0
- package/dist/routing/metadata.js.map +1 -0
- package/dist/routing/metadataKeys.d.ts +22 -0
- package/dist/routing/metadataKeys.d.ts.map +1 -0
- package/dist/routing/metadataKeys.js +19 -0
- package/dist/routing/metadataKeys.js.map +1 -0
- package/dist/routing/paramTypes.d.ts +18 -0
- package/dist/routing/paramTypes.d.ts.map +1 -0
- package/dist/routing/paramTypes.js +3 -0
- package/dist/routing/paramTypes.js.map +1 -0
- package/dist/routing/routeRegistry.d.ts +31 -0
- package/dist/routing/routeRegistry.d.ts.map +1 -0
- package/dist/routing/routeRegistry.js +99 -0
- package/dist/routing/routeRegistry.js.map +1 -0
- package/dist/simulateRequest.js +52 -0
- package/dist/utils/decoratorCheck.d.ts +3 -0
- package/dist/utils/decoratorCheck.d.ts.map +1 -0
- package/dist/utils/decoratorCheck.js +37 -0
- package/dist/utils/decoratorCheck.js.map +1 -0
- package/dist/utils/log.d.ts +7 -0
- package/dist/utils/log.d.ts.map +1 -0
- package/dist/utils/log.js +20 -0
- package/dist/utils/log.js.map +1 -0
- package/dist/utils/metadataKey.d.ts +9 -0
- package/dist/utils/metadataKey.d.ts.map +1 -0
- package/dist/utils/metadataKey.js +28 -0
- package/dist/utils/metadataKey.js.map +1 -0
- package/dist/utils/normalizePath.js +16 -0
- package/dist/validation/resolveHandlerArgument.d.ts +10 -0
- package/dist/validation/resolveHandlerArgument.d.ts.map +1 -0
- package/dist/validation/resolveHandlerArgument.js +112 -0
- package/dist/validation/resolveHandlerArgument.js.map +1 -0
- package/dist/validation/rule.d.ts +35 -0
- package/dist/validation/rule.d.ts.map +1 -0
- package/dist/validation/rule.js +45 -0
- package/dist/validation/rule.js.map +1 -0
- package/dist/validation/validationErrorException.d.ts +6 -0
- package/dist/validation/validationErrorException.d.ts.map +1 -0
- package/dist/validation/validationErrorException.js +9 -0
- package/dist/validation/validationErrorException.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./baseHTTPException"), exports);
|
|
18
|
+
__exportStar(require("./HTTPExceptions"), exports);
|
|
19
|
+
__exportStar(require("./defaultExceptionFilter"), exports);
|
|
20
|
+
__exportStar(require("./exceptionHandler"), exports);
|
|
21
|
+
__exportStar(require("./exceptionFilter"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,mDAAiC;AACjC,2DAAyC;AACzC,qDAAmC;AACnC,oDAAkC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Guard.d.ts","sourceRoot":"","sources":["../../src/guards/Guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,MAAM,WAAW,KAAK;IAClB,WAAW,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACjE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Guard.js","sourceRoot":"","sources":["../../src/guards/Guard.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Constructor } from "../core/container/container";
|
|
2
|
+
import { ExecutionContext } from "../core/pipeline/ExecutionContext";
|
|
3
|
+
import { Guard } from "./Guard";
|
|
4
|
+
export declare function applyGuards(guards: Constructor<Guard>[], ctx: ExecutionContext): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=applyGuard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyGuard.d.ts","sourceRoot":"","sources":["../../src/guards/applyGuard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAa,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,wBAAsB,WAAW,CAC7B,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,EAC5B,GAAG,EAAE,gBAAgB,GACtB,OAAO,CAAC,IAAI,CAAC,CAQf"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyGuards = applyGuards;
|
|
4
|
+
const container_1 = require("../core/container/container");
|
|
5
|
+
const exceptions_1 = require("../exceptions");
|
|
6
|
+
async function applyGuards(guards, ctx) {
|
|
7
|
+
for (const guardClass of guards) {
|
|
8
|
+
const instance = container_1.Container.instance.resolve(guardClass);
|
|
9
|
+
const result = await instance.canActivate(ctx);
|
|
10
|
+
if (!result) {
|
|
11
|
+
throw new exceptions_1.ForbiddenException('Access denied');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=applyGuard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyGuard.js","sourceRoot":"","sources":["../../src/guards/applyGuard.ts"],"names":[],"mappings":";;AAKA,kCAWC;AAhBD,2DAAqE;AAErE,8CAAmD;AAG5C,KAAK,UAAU,WAAW,CAC7B,MAA4B,EAC5B,GAAqB;IAErB,KAAK,MAAM,UAAU,IAAI,MAAM,EAAE,CAAC;QAC9B,MAAM,QAAQ,GAAG,qBAAS,CAAC,QAAQ,CAAC,OAAO,CAAQ,UAAU,CAAC,CAAC;QAC/D,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,MAAM,IAAI,+BAAkB,CAAC,eAAe,CAAC,CAAC;QAClD,CAAC;IACL,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD';
|
|
2
|
+
export interface RawRequest {
|
|
3
|
+
method: HttpMethod;
|
|
4
|
+
url: string;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
body?: any;
|
|
7
|
+
}
|
|
8
|
+
export declare class HttpRequest {
|
|
9
|
+
readonly method: HttpMethod;
|
|
10
|
+
readonly url: string;
|
|
11
|
+
readonly path: string;
|
|
12
|
+
readonly headers?: Record<string, string>;
|
|
13
|
+
readonly query: Record<string, string>;
|
|
14
|
+
body: any;
|
|
15
|
+
private _params;
|
|
16
|
+
constructor(raw: RawRequest);
|
|
17
|
+
/**
|
|
18
|
+
* Splits a URL string into a normalized path and a query parameter map.
|
|
19
|
+
*
|
|
20
|
+
* @param url Raw URL string (may include query string)
|
|
21
|
+
* @returns An object containing the normalized path and parsed query parameters
|
|
22
|
+
*/
|
|
23
|
+
private parseUrl;
|
|
24
|
+
static normalizePath(path: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Normalizes a path string by ensuring it starts with a forward slash and does not end with one.
|
|
27
|
+
* @param path
|
|
28
|
+
* @returns Normalized path string
|
|
29
|
+
*/
|
|
30
|
+
private normalizePath;
|
|
31
|
+
/**
|
|
32
|
+
* Normalizes header keys to lowercase for consistent access.
|
|
33
|
+
* @param headers
|
|
34
|
+
* @returns A new record with all header keys normalized to lowercase
|
|
35
|
+
*/
|
|
36
|
+
private normalizeHeaders;
|
|
37
|
+
/**
|
|
38
|
+
* Parse a query string into key-value pairs.
|
|
39
|
+
* @param queryString
|
|
40
|
+
* @returns A record of query parameters parsed from the query string
|
|
41
|
+
*/
|
|
42
|
+
private parseQueryString;
|
|
43
|
+
param(key: string): string | undefined;
|
|
44
|
+
header(key: string): string | undefined;
|
|
45
|
+
get params(): Record<string, string>;
|
|
46
|
+
setParams(params: Record<string, string>): void;
|
|
47
|
+
getQueryParam(key: string): string | undefined;
|
|
48
|
+
get isJson(): boolean;
|
|
49
|
+
get ip(): string;
|
|
50
|
+
accepts(type: string): boolean;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=HttpRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpRequest.d.ts","sourceRoot":"","sources":["../../src/http/HttpRequest.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAC1F,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,UAAU,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,GAAG,CAAC;CACd;AAED,qBAAa,WAAW;IACpB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IAC5C,IAAI,EAAE,GAAG,CAAC;IAEV,OAAO,CAAC,OAAO,CAA8B;gBACjC,GAAG,EAAE,UAAU;IAW3B;;;;;MAKE;IACF,OAAO,CAAC,QAAQ;IAOhB,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAO1C;;;;OAIG;IACH,OAAO,CAAC,aAAa;IAIrB;;;;OAIG;IAEH,OAAO,CAAC,gBAAgB;IAUxB;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAWxB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAItC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIvC,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEnC;IAED,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAIxC,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI9C,IAAI,MAAM,IAAI,OAAO,CAGpB;IAED,IAAI,EAAE,IAAI,MAAM,CAMf;IAED,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAMjC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpRequest = void 0;
|
|
4
|
+
class HttpRequest {
|
|
5
|
+
constructor(raw) {
|
|
6
|
+
this.query = {};
|
|
7
|
+
this._params = {};
|
|
8
|
+
this.method = raw.method;
|
|
9
|
+
this.url = raw.url;
|
|
10
|
+
this.headers = this.normalizeHeaders(raw.headers || {});
|
|
11
|
+
this.body = raw.body;
|
|
12
|
+
const { path, query } = this.parseUrl(raw.url);
|
|
13
|
+
this.path = this.normalizePath(path);
|
|
14
|
+
this.query = query;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Splits a URL string into a normalized path and a query parameter map.
|
|
18
|
+
*
|
|
19
|
+
* @param url Raw URL string (may include query string)
|
|
20
|
+
* @returns An object containing the normalized path and parsed query parameters
|
|
21
|
+
*/
|
|
22
|
+
parseUrl(url) {
|
|
23
|
+
const [rawPath, queryString] = url.split('?');
|
|
24
|
+
const path = this.normalizePath(rawPath);
|
|
25
|
+
const query = queryString ? this.parseQueryString(queryString) : {};
|
|
26
|
+
return { path, query };
|
|
27
|
+
}
|
|
28
|
+
static normalizePath(path) {
|
|
29
|
+
if (!path)
|
|
30
|
+
return "/";
|
|
31
|
+
if (!path.startsWith('/'))
|
|
32
|
+
path = '/' + path;
|
|
33
|
+
if (path.length > 1 && path.endsWith('/'))
|
|
34
|
+
path = path.slice(0, -1);
|
|
35
|
+
return path;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Normalizes a path string by ensuring it starts with a forward slash and does not end with one.
|
|
39
|
+
* @param path
|
|
40
|
+
* @returns Normalized path string
|
|
41
|
+
*/
|
|
42
|
+
normalizePath(path) {
|
|
43
|
+
return HttpRequest.normalizePath(path);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Normalizes header keys to lowercase for consistent access.
|
|
47
|
+
* @param headers
|
|
48
|
+
* @returns A new record with all header keys normalized to lowercase
|
|
49
|
+
*/
|
|
50
|
+
normalizeHeaders(headers) {
|
|
51
|
+
const normalized = {};
|
|
52
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
53
|
+
normalized[key.toLowerCase()] = value;
|
|
54
|
+
}
|
|
55
|
+
return normalized;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Parse a query string into key-value pairs.
|
|
59
|
+
* @param queryString
|
|
60
|
+
* @returns A record of query parameters parsed from the query string
|
|
61
|
+
*/
|
|
62
|
+
parseQueryString(queryString) {
|
|
63
|
+
const query = {};
|
|
64
|
+
const params = new URLSearchParams(queryString);
|
|
65
|
+
params.forEach((value, key) => {
|
|
66
|
+
query[key] = decodeURIComponent(value);
|
|
67
|
+
});
|
|
68
|
+
return query;
|
|
69
|
+
}
|
|
70
|
+
param(key) {
|
|
71
|
+
return this._params[key];
|
|
72
|
+
}
|
|
73
|
+
header(key) {
|
|
74
|
+
return this.headers?.[key.toLowerCase()];
|
|
75
|
+
}
|
|
76
|
+
get params() {
|
|
77
|
+
return { ...this._params };
|
|
78
|
+
}
|
|
79
|
+
setParams(params) {
|
|
80
|
+
this._params = params;
|
|
81
|
+
}
|
|
82
|
+
getQueryParam(key) {
|
|
83
|
+
return this.query[key];
|
|
84
|
+
}
|
|
85
|
+
get isJson() {
|
|
86
|
+
const contentType = this.header('content-type');
|
|
87
|
+
return contentType?.includes('application/json') ?? false;
|
|
88
|
+
}
|
|
89
|
+
get ip() {
|
|
90
|
+
return (this.header('x-forwarded-for')?.split(',')[0].trim() ||
|
|
91
|
+
this.header('x-real-ip') ||
|
|
92
|
+
'unknown');
|
|
93
|
+
}
|
|
94
|
+
accepts(type) {
|
|
95
|
+
const acceptHeader = this.header('accept');
|
|
96
|
+
if (!acceptHeader)
|
|
97
|
+
return false;
|
|
98
|
+
const acceptedTypes = acceptHeader.split(',').map(t => t.split(';')[0].trim());
|
|
99
|
+
return acceptedTypes.includes(type) || acceptedTypes.includes('*/*');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.HttpRequest = HttpRequest;
|
|
103
|
+
//# sourceMappingURL=HttpRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpRequest.js","sourceRoot":"","sources":["../../src/http/HttpRequest.ts"],"names":[],"mappings":";;;AAQA,MAAa,WAAW;IASpB,YAAY,GAAe;QAJlB,UAAK,GAA2B,EAAE,CAAC;QAGpC,YAAO,GAA2B,EAAE,CAAC;QAEzC,IAAI,CAAC,MAAM,GAAG,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C,MAAM,CAAC,cAAc,CAAC,CAAC;QAChD,OAAO,WAAW,EAAE,QAAQ,CAAC,kBAAkB,CAAC,IAAI,KAAK,CAAC;IAC9D,CAAC;IAED,IAAI,EAAE;QACF,OAAO,CACH,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;YACpD,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;YACxB,SAAS,CACZ,CAAC;IACN,CAAC;IAED,OAAO,CAAC,IAAY;QAChB,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC3C,IAAI,CAAC,YAAY;YAAE,OAAO,KAAK,CAAC;QAChC,MAAM,aAAa,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC/E,OAAO,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACzE,CAAC;CACJ;AAxHD,kCAwHC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare class HttpResponse {
|
|
2
|
+
private _statusCode;
|
|
3
|
+
private _headers;
|
|
4
|
+
private _body;
|
|
5
|
+
private _sent;
|
|
6
|
+
status(code: number): this;
|
|
7
|
+
header(key: string, value: string): this;
|
|
8
|
+
json(data: any): this;
|
|
9
|
+
send(data: any): this;
|
|
10
|
+
toJSON(): {
|
|
11
|
+
statusCode: number;
|
|
12
|
+
headers: Record<string, string>;
|
|
13
|
+
body: any;
|
|
14
|
+
};
|
|
15
|
+
get statusCode(): number;
|
|
16
|
+
get headers(): Record<string, string>;
|
|
17
|
+
get body(): any;
|
|
18
|
+
get isSent(): boolean;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=HttpResponse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpResponse.d.ts","sourceRoot":"","sources":["../../src/http/HttpResponse.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IACrB,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,KAAK,CAAM;IACnB,OAAO,CAAC,KAAK,CAAkB;IAE/B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQ1B,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAQxC,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAWrB,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IASrB,MAAM;;;;;IAQN,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEpC;IAED,IAAI,IAAI,IAAI,GAAG,CAEd;IAED,IAAI,MAAM,IAAI,OAAO,CAEpB;CACJ"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpResponse = void 0;
|
|
4
|
+
const HTTPExceptions_1 = require("../exceptions/HTTPExceptions");
|
|
5
|
+
class HttpResponse {
|
|
6
|
+
constructor() {
|
|
7
|
+
this._statusCode = 200;
|
|
8
|
+
this._headers = {};
|
|
9
|
+
this._sent = false;
|
|
10
|
+
}
|
|
11
|
+
status(code) {
|
|
12
|
+
if (this._sent) {
|
|
13
|
+
throw new HTTPExceptions_1.InternalServerErrorException("Cannot set status after response is sent.");
|
|
14
|
+
}
|
|
15
|
+
this._statusCode = code;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
header(key, value) {
|
|
19
|
+
if (this._sent) {
|
|
20
|
+
throw new HTTPExceptions_1.InternalServerErrorException("Cannot set header after response is sent.");
|
|
21
|
+
}
|
|
22
|
+
this._headers[key.toLowerCase()] = value;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
json(data) {
|
|
26
|
+
if (this._sent) {
|
|
27
|
+
throw new HTTPExceptions_1.InternalServerErrorException("Cannot send response after it is already sent.");
|
|
28
|
+
}
|
|
29
|
+
this._body = data;
|
|
30
|
+
this._headers['content-type'] = 'application/json';
|
|
31
|
+
this._sent = true;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
send(data) {
|
|
35
|
+
if (this._sent) {
|
|
36
|
+
throw new HTTPExceptions_1.InternalServerErrorException("Cannot send response after it is already sent.");
|
|
37
|
+
}
|
|
38
|
+
this._body = data;
|
|
39
|
+
this._sent = true;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
toJSON() {
|
|
43
|
+
return {
|
|
44
|
+
statusCode: this._statusCode,
|
|
45
|
+
headers: this._headers,
|
|
46
|
+
body: this._body,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
get statusCode() {
|
|
50
|
+
return this._statusCode;
|
|
51
|
+
}
|
|
52
|
+
get headers() {
|
|
53
|
+
return this._headers;
|
|
54
|
+
}
|
|
55
|
+
get body() {
|
|
56
|
+
return this._body;
|
|
57
|
+
}
|
|
58
|
+
get isSent() {
|
|
59
|
+
return this._sent;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.HttpResponse = HttpResponse;
|
|
63
|
+
//# sourceMappingURL=HttpResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HttpResponse.js","sourceRoot":"","sources":["../../src/http/HttpResponse.ts"],"names":[],"mappings":";;;AAAA,iEAA4E;AAE5E,MAAa,YAAY;IAAzB;QACY,gBAAW,GAAW,GAAG,CAAC;QAC1B,aAAQ,GAA2B,EAAE,CAAC;QAEtC,UAAK,GAAY,KAAK,CA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C,WAAW,CAAC;IAC5B,CAAC;IAED,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACtB,CAAC;CACJ;AAjED,oCAiEC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HttpAdapter, RequestHandler } from "./httpAdapter";
|
|
2
|
+
export interface ExpressAdapterOptions {
|
|
3
|
+
https?: {
|
|
4
|
+
key: string;
|
|
5
|
+
cert: string;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export declare class ExpressAdapter implements HttpAdapter {
|
|
9
|
+
private handler;
|
|
10
|
+
private options?;
|
|
11
|
+
private app;
|
|
12
|
+
private server;
|
|
13
|
+
constructor(handler: RequestHandler, options?: ExpressAdapterOptions | undefined);
|
|
14
|
+
listen(port: number, cb?: () => void): void;
|
|
15
|
+
shutdown(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=expressAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expressAdapter.d.ts","sourceRoot":"","sources":["../../../src/http/adapters/expressAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAO5D,MAAM,WAAW,qBAAqB;IAClC,KAAK,CAAC,EAAE;QACJ,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;KAChB,CAAA;CACJ;AAED,qBAAa,cAAe,YAAW,WAAW;IAIlC,OAAO,CAAC,OAAO;IAAkB,OAAO,CAAC,OAAO,CAAC;IAH7D,OAAO,CAAC,GAAG,CAAU;IACrB,OAAO,CAAC,MAAM,CAA4B;gBAEtB,OAAO,EAAE,cAAc,EAAU,OAAO,CAAC,EAAE,qBAAqB,YAAA;IAoBpF,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI;IAarC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAWlC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ExpressAdapter = void 0;
|
|
40
|
+
const express_1 = __importDefault(require("express"));
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
const https = __importStar(require("https"));
|
|
43
|
+
class ExpressAdapter {
|
|
44
|
+
constructor(handler, options) {
|
|
45
|
+
this.handler = handler;
|
|
46
|
+
this.options = options;
|
|
47
|
+
this.server = null;
|
|
48
|
+
this.app = (0, express_1.default)();
|
|
49
|
+
this.app.use(express_1.default.json());
|
|
50
|
+
this.app.use(async (req, res) => {
|
|
51
|
+
const result = await this.handler({
|
|
52
|
+
method: req.method,
|
|
53
|
+
url: req.originalUrl,
|
|
54
|
+
headers: req.headers,
|
|
55
|
+
body: req.body,
|
|
56
|
+
});
|
|
57
|
+
res.status(result.statusCode);
|
|
58
|
+
for (const [key, value] of Object.entries(result.headers)) {
|
|
59
|
+
res.setHeader(key, value);
|
|
60
|
+
}
|
|
61
|
+
res.send(result.body);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
listen(port, cb) {
|
|
65
|
+
if (this.options?.https) {
|
|
66
|
+
const { key, cert } = this.options.https;
|
|
67
|
+
const credentials = {
|
|
68
|
+
key: fs.readFileSync(key, 'utf8'),
|
|
69
|
+
cert: fs.readFileSync(cert, 'utf8'),
|
|
70
|
+
};
|
|
71
|
+
this.server = https.createServer(credentials, this.app).listen(port, cb);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
this.server = this.app.listen(port, cb);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async shutdown() {
|
|
78
|
+
return new Promise((resolve) => {
|
|
79
|
+
if (this.server) {
|
|
80
|
+
this.server.close(() => {
|
|
81
|
+
resolve();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
resolve();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.ExpressAdapter = ExpressAdapter;
|
|
91
|
+
//# sourceMappingURL=expressAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expressAdapter.js","sourceRoot":"","sources":["../../../src/http/adapters/expressAdapter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sDAA2C;AAE3C,uCAAyB;AACzB,6CAA+B;AAU/B,MAAa,cAAc;IAIvB,YAAoB,OAAuB,EAAU,OAA+B;QAAhE,YAAO,GAAP,OAAO,CAAgB;QAAU,YAAO,GAAP,OAAO,CAAwB;QAF5E,WAAM,GAAuB,IAAI,CAAC;QAGtC,IAAI,CAAC,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;QACrB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAE7B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;YAC5B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC;gBAC9B,MAAM,EAAE,GAAG,CAAC,MAAoB;gBAChC,GAAG,EAAE,GAAG,CAAC,WAAW;gBACpB,OAAO,EAAE,GAAG,CAAC,OAAiC;gBAC9C,IAAI,EAAE,GAAG,CAAC,IAAI;aACjB,CAAC,CAAC;YAEH,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAC9B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;gBACxD,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,KAAe,CAAC,CAAC;YACxC,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
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export declare class FastifyAdapter implements HttpAdapter {
|
|
9
|
+
private handler;
|
|
10
|
+
private options?;
|
|
11
|
+
private app;
|
|
12
|
+
constructor(handler: RequestHandler, options?: FastifyAdapterOptions | undefined);
|
|
13
|
+
private setupRoutes;
|
|
14
|
+
listen(port: number, cb?: () => void): void;
|
|
15
|
+
shutdown(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=fastifyAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastifyAdapter.d.ts","sourceRoot":"","sources":["../../../src/http/adapters/fastifyAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAM5D,MAAM,WAAW,qBAAqB;IAClC,KAAK,CAAC,EAAE;QACJ,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;KAChB,CAAA;CACJ;AAED,qBAAa,cAAe,YAAW,WAAW;IAGlC,OAAO,CAAC,OAAO;IAAkB,OAAO,CAAC,OAAO,CAAC;IAF7D,OAAO,CAAC,GAAG,CAAkB;gBAET,OAAO,EAAE,cAAc,EAAU,OAAO,CAAC,EAAE,qBAAqB,YAAA;IAepF,OAAO,CAAC,WAAW;IAqBnB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI;IASrC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAGlC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.FastifyAdapter = void 0;
|
|
40
|
+
const fastify_1 = __importDefault(require("fastify"));
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
class FastifyAdapter {
|
|
43
|
+
constructor(handler, options) {
|
|
44
|
+
this.handler = handler;
|
|
45
|
+
this.options = options;
|
|
46
|
+
if (this.options?.https) {
|
|
47
|
+
this.app = (0, fastify_1.default)({
|
|
48
|
+
https: {
|
|
49
|
+
key: fs.readFileSync(this.options.https.key, 'utf8'),
|
|
50
|
+
cert: fs.readFileSync(this.options.https.cert, 'utf8'),
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
this.app = (0, fastify_1.default)();
|
|
56
|
+
}
|
|
57
|
+
this.setupRoutes();
|
|
58
|
+
}
|
|
59
|
+
setupRoutes() {
|
|
60
|
+
this.app.route({
|
|
61
|
+
method: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'],
|
|
62
|
+
url: '*',
|
|
63
|
+
handler: async (request, reply) => {
|
|
64
|
+
const result = await this.handler({
|
|
65
|
+
method: request.method,
|
|
66
|
+
url: request.url,
|
|
67
|
+
headers: request.headers,
|
|
68
|
+
body: request.body,
|
|
69
|
+
});
|
|
70
|
+
reply.status(result.statusCode);
|
|
71
|
+
for (const [key, value] of Object.entries(result.headers)) {
|
|
72
|
+
reply.header(key, value);
|
|
73
|
+
}
|
|
74
|
+
return result.body;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
listen(port, cb) {
|
|
79
|
+
this.app.listen({ port, host: '0.0.0.0' }).then(() => {
|
|
80
|
+
cb?.();
|
|
81
|
+
}).catch((err) => {
|
|
82
|
+
console.error(err);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async shutdown() {
|
|
87
|
+
await this.app.close();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.FastifyAdapter = FastifyAdapter;
|
|
91
|
+
//# sourceMappingURL=fastifyAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastifyAdapter.js","sourceRoot":"","sources":["../../../src/http/adapters/fastifyAdapter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sDA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OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;oBACxD,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,KAAe,CAAC,CAAC;gBACvC,CAAC;gBACD,OAAO,MAAM,CAAC,IAAI,CAAC;YACvB,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;IAED,MAAM,CAAC,IAAY,EAAE,EAAe;QAChC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;YACjD,EAAE,EAAE,EAAE,CAAC;QACX,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;YACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,QAAQ;QACV,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;CACJ;AAnDD,wCAmDC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HttpResponse } from "../HttpResponse";
|
|
2
|
+
import { RawRequest } from "../HttpRequest";
|
|
3
|
+
export interface HTTPAdapterOptions {
|
|
4
|
+
https?: {
|
|
5
|
+
key: string;
|
|
6
|
+
cert: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export interface HttpAdapter {
|
|
10
|
+
listen(port: number, cb: () => void): void;
|
|
11
|
+
shutdown(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export type RequestHandler = (RawRequest: RawRequest) => Promise<HttpResponse>;
|
|
14
|
+
//# sourceMappingURL=httpAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpAdapter.d.ts","sourceRoot":"","sources":["../../../src/http/adapters/httpAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,WAAW,kBAAkB;IAC/B,KAAK,CAAC,EAAE;QACJ,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;KAChB,CAAA;CACJ;AAED,MAAM,WAAW,WAAW;IACxB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC3C,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,UAAU,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpAdapter.js","sourceRoot":"","sources":["../../../src/http/adapters/httpAdapter.ts"],"names":[],"mappings":""}
|