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,51 @@
|
|
|
1
|
+
import { HttpMethod } from "../HttpRequest";
|
|
2
|
+
export interface RequestOptions {
|
|
3
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
retries?: number;
|
|
6
|
+
params?: Record<string, string | number | undefined>;
|
|
7
|
+
}
|
|
8
|
+
export interface HttpClientResponse<T> {
|
|
9
|
+
data: T;
|
|
10
|
+
status: number;
|
|
11
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
12
|
+
}
|
|
13
|
+
interface SourceConfig {
|
|
14
|
+
url: string;
|
|
15
|
+
method?: HttpMethod;
|
|
16
|
+
body?: any;
|
|
17
|
+
headers?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
type SourceDef = string | SourceConfig;
|
|
20
|
+
export interface AggregateOption<S extends Record<string, SourceDef>, R> {
|
|
21
|
+
sources: S;
|
|
22
|
+
output: (sources: {
|
|
23
|
+
[K in keyof S]: any;
|
|
24
|
+
}, errors?: {
|
|
25
|
+
[K in keyof S]?: Error;
|
|
26
|
+
}) => R;
|
|
27
|
+
timeout?: number;
|
|
28
|
+
partial?: boolean;
|
|
29
|
+
params?: Record<string, any>;
|
|
30
|
+
baseUrl?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface AggregateResult<R> {
|
|
33
|
+
data: R;
|
|
34
|
+
errors?: Record<string, Error>;
|
|
35
|
+
}
|
|
36
|
+
export declare class HttpClient {
|
|
37
|
+
private defaultTimeout;
|
|
38
|
+
private defaultRetries;
|
|
39
|
+
get<T = any>(url: string, options?: RequestOptions): Promise<HttpClientResponse<T>>;
|
|
40
|
+
post<T = any>(url: string, body?: any, options?: RequestOptions): Promise<HttpClientResponse<T>>;
|
|
41
|
+
put<T = any>(url: string, body?: any, options?: RequestOptions): Promise<HttpClientResponse<T>>;
|
|
42
|
+
patch<T = any>(url: string, body?: any, options?: RequestOptions): Promise<HttpClientResponse<T>>;
|
|
43
|
+
delete<T = any>(url: string, options?: RequestOptions): Promise<HttpClientResponse<T>>;
|
|
44
|
+
aggregate<S extends Record<string, SourceDef>, R>(options: AggregateOption<S, R>): Promise<AggregateResult<R>>;
|
|
45
|
+
private resolveUrl;
|
|
46
|
+
private dispatchRequest;
|
|
47
|
+
private buildUrl;
|
|
48
|
+
private delay;
|
|
49
|
+
}
|
|
50
|
+
export {};
|
|
51
|
+
//# sourceMappingURL=httpClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpClient.d.ts","sourceRoot":"","sources":["../../../src/http/client/httpClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,MAAM,WAAW,cAAc;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACxD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAAA;CACvD;AAED,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACjC,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAA;CAC1D;AAED,UAAU,YAAY;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACnC;AAQD,KAAK,SAAS,GAAG,MAAM,GAAG,YAAY,CAAA;AAEtC,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC;IACnE,OAAO,EAAE,CAAC,CAAC;IACX,MAAM,EAAE,CACJ,OAAO,EAAE;SACJ,CAAC,IAAI,MAAM,CAAC,GAAG,GAAG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CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;IAItF,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IAkEpH,OAAO,CAAC,UAAU;YAUJ,eAAe;IA8C7B,OAAO,CAAC,QAAQ;IAchB,OAAO,CAAC,KAAK;CAGhB"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.HttpClient = void 0;
|
|
10
|
+
const undici_1 = require("undici");
|
|
11
|
+
const Injectable_1 = require("../../decorators/Injectable");
|
|
12
|
+
const log_1 = require("../../utils/log");
|
|
13
|
+
let HttpClient = class HttpClient {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.defaultTimeout = 10000;
|
|
16
|
+
this.defaultRetries = 0;
|
|
17
|
+
}
|
|
18
|
+
async get(url, options) {
|
|
19
|
+
return this.dispatchRequest('GET', url, undefined, options);
|
|
20
|
+
}
|
|
21
|
+
async post(url, body, options) {
|
|
22
|
+
return this.dispatchRequest('POST', url, body, options);
|
|
23
|
+
}
|
|
24
|
+
async put(url, body, options) {
|
|
25
|
+
return this.dispatchRequest('PUT', url, body, options);
|
|
26
|
+
}
|
|
27
|
+
async patch(url, body, options) {
|
|
28
|
+
return this.dispatchRequest('PATCH', url, body, options);
|
|
29
|
+
}
|
|
30
|
+
async delete(url, options) {
|
|
31
|
+
return this.dispatchRequest('DELETE', url, undefined, options);
|
|
32
|
+
}
|
|
33
|
+
async aggregate(options) {
|
|
34
|
+
const { params = {}, sources, output, timeout, partial = false, baseUrl = '' } = options;
|
|
35
|
+
const requestEntries = Object.entries(sources);
|
|
36
|
+
const promises = requestEntries.map(async ([key, source]) => {
|
|
37
|
+
//if source is only string default to get method
|
|
38
|
+
const config = typeof source === 'string' ? { url: source, method: "GET", headers: undefined, body: undefined } : { method: "GET", ...source };
|
|
39
|
+
const url = baseUrl + this.resolveUrl(config.url, params);
|
|
40
|
+
try {
|
|
41
|
+
let res;
|
|
42
|
+
switch (config.method) {
|
|
43
|
+
case "GET":
|
|
44
|
+
res = await this.get(url, { timeout, headers: config.headers });
|
|
45
|
+
break;
|
|
46
|
+
case "POST":
|
|
47
|
+
res = await this.post(url, config.body, { timeout, headers: config.headers });
|
|
48
|
+
break;
|
|
49
|
+
case "PUT":
|
|
50
|
+
res = await this.put(url, config.body, { timeout, headers: config.headers });
|
|
51
|
+
break;
|
|
52
|
+
case "DELETE":
|
|
53
|
+
res = await this.delete(url, { timeout, headers: config.headers });
|
|
54
|
+
break;
|
|
55
|
+
case "PATCH":
|
|
56
|
+
res = await this.patch(url, config.body, { timeout, headers: config.headers });
|
|
57
|
+
break;
|
|
58
|
+
default:
|
|
59
|
+
throw Error("Unsupported method detected");
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
key,
|
|
63
|
+
data: res?.data,
|
|
64
|
+
error: null
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (partial) {
|
|
69
|
+
return {
|
|
70
|
+
key,
|
|
71
|
+
data: null,
|
|
72
|
+
error: error
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const results = await Promise.all(promises);
|
|
81
|
+
const sourcesData = {};
|
|
82
|
+
const errors = {};
|
|
83
|
+
for (const result of results) {
|
|
84
|
+
if (result.error) {
|
|
85
|
+
errors[result.key] = result.error;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
sourcesData[result.key] = result.data;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const data = output(sourcesData, errors);
|
|
92
|
+
return {
|
|
93
|
+
data,
|
|
94
|
+
errors
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
resolveUrl(template, params) {
|
|
98
|
+
return template.replace(/:(\w+)/g, (_, key) => {
|
|
99
|
+
const value = params[key];
|
|
100
|
+
if (value === undefined) {
|
|
101
|
+
throw new Error(`Missing param: ${key}`);
|
|
102
|
+
}
|
|
103
|
+
return encodeURIComponent(String(value));
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async dispatchRequest(method, url, body, options) {
|
|
107
|
+
const fullUrl = this.buildUrl(url, options?.params);
|
|
108
|
+
const retries = options?.retries ?? this.defaultRetries;
|
|
109
|
+
const timeout = options?.timeout ?? this.defaultTimeout;
|
|
110
|
+
let lastError;
|
|
111
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
112
|
+
try {
|
|
113
|
+
const startTimeStamp = Date.now();
|
|
114
|
+
const response = await (0, undici_1.request)(fullUrl, {
|
|
115
|
+
method: method,
|
|
116
|
+
headers: {
|
|
117
|
+
"Content-type": "application/json",
|
|
118
|
+
...options?.headers
|
|
119
|
+
},
|
|
120
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
121
|
+
headersTimeout: timeout,
|
|
122
|
+
bodyTimeout: timeout
|
|
123
|
+
});
|
|
124
|
+
const data = await response.body.json();
|
|
125
|
+
log_1.Log.info(`[HttpClient] ${method} ${fullUrl} - ${response.statusCode} (${Date.now() - startTimeStamp}ms)`);
|
|
126
|
+
return {
|
|
127
|
+
data,
|
|
128
|
+
status: response.statusCode,
|
|
129
|
+
headers: response.headers
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
134
|
+
log_1.Log.warn(`[HttpClient] ${method} ${fullUrl} - attempt ${attempt + 1} failed: ${lastError.message}`);
|
|
135
|
+
if (attempt < retries) {
|
|
136
|
+
await this.delay(100 * Math.pow(2, attempt));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
log_1.Log.error(`[HttpClient] ${method} ${fullUrl} - all ${retries + 1} attempts failed`);
|
|
141
|
+
throw lastError;
|
|
142
|
+
}
|
|
143
|
+
buildUrl(url, params) {
|
|
144
|
+
if (!params)
|
|
145
|
+
return url;
|
|
146
|
+
const filtered = Object.entries(params)
|
|
147
|
+
.filter(([_, v]) => v !== undefined)
|
|
148
|
+
.map(([k, v]) => [k, String(v)]);
|
|
149
|
+
if (filtered.length === 0)
|
|
150
|
+
return url;
|
|
151
|
+
const queryString = new URLSearchParams(filtered).toString();
|
|
152
|
+
const separator = url.includes('?') ? '&' : '?';
|
|
153
|
+
return url + separator + queryString;
|
|
154
|
+
}
|
|
155
|
+
delay(ms) {
|
|
156
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
exports.HttpClient = HttpClient;
|
|
160
|
+
exports.HttpClient = HttpClient = __decorate([
|
|
161
|
+
(0, Injectable_1.Injectable)()
|
|
162
|
+
], HttpClient);
|
|
163
|
+
//# sourceMappingURL=httpClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpClient.js","sourceRoot":"","sources":["../../../src/http/client/httpClient.ts"],"names":[],"mappings":";;;;;;;;;AAAA,mCAAiC;AACjC,4DAAyD;AAEzD,yCAA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AAC,MAAM,KAAK,CAAC;YAAE,OAAO,GAAG,CAAC;QAEtC,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC7D,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;QAChD,OAAO,GAAG,GAAG,SAAS,GAAG,WAAW,CAAC;IACzC,CAAC;IAEO,KAAK,CAAC,EAAU;QACpB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;CACJ,CAAA;AAnKY,gCAAU;qBAAV,UAAU;IADtB,IAAA,uBAAU,GAAE;GACA,UAAU,CAmKtB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { createMiniNestApp, App } from './core/app/App';
|
|
2
|
+
export type { AppOptions, HTTPAdapter } from './core/app/App';
|
|
3
|
+
export { Container } from './core/container/container';
|
|
4
|
+
export type { Constructor } from './core/container/container';
|
|
5
|
+
export { ExecutionContext } from './core/pipeline/ExecutionContext';
|
|
6
|
+
export type { RouteMetadata } from './core/pipeline/ExecutionContext';
|
|
7
|
+
export { Controller, Get, Post, Put, Delete, Patch, Options, Head, Body, Query, Param, Header, Cache, Retry, Timeout, CircuitBreaker, Injectable, UseGuard, UseInterceptor, } from './decorators';
|
|
8
|
+
export type { CacheOptions, CircuitBreakerOptions } from './decorators';
|
|
9
|
+
export { HttpClient } from './http/client/httpClient';
|
|
10
|
+
export type { RequestOptions, HttpClientResponse, AggregateOption, AggregateResult, } from './http/client/httpClient';
|
|
11
|
+
export { HttpRequest } from './http/HttpRequest';
|
|
12
|
+
export type { RawRequest, HttpMethod } from './http/HttpRequest';
|
|
13
|
+
export { HttpResponse } from './http/HttpResponse';
|
|
14
|
+
export { BaseHTTPException, BadRequestException, UnauthorizedException, ForbiddenException, NotFoundException, InternalServerErrorException, NotImplementedException, BadGatewayException, ValidationException, DefaultExceptionFilter, ExceptionHandler, exceptionHandler, } from './exceptions';
|
|
15
|
+
export type { HttpExceptionResponse, ExceptionFilter, ValidationError, } from './exceptions';
|
|
16
|
+
export type { Guard } from './guards/Guard';
|
|
17
|
+
export type { Interceptor } from './interceptors/Interceptor';
|
|
18
|
+
export type { OnInit, OnDestroy, OnAppBootstrap, OnAppShutdown, OnBeforeHandle, OnAfterHandle, OnHandleError, } from './lifecycle/lifecycle';
|
|
19
|
+
export { rule, RuleBuilder } from './validation/rule';
|
|
20
|
+
export type { Validator, ValidatorRule } from './validation/rule';
|
|
21
|
+
export { CircuitOpenError } from './circuitBreaker/circuitOpenError';
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACxD,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,YAAY,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,YAAY,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAGtE,OAAO,EAEH,UAAU,EACV,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAC5C,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAE1B,KAAK,EACL,KAAK,EACL,OAAO,EACP,cAAc,EAEd,UAAU,EAEV,QAAQ,EACR,cAAc,GACjB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAGxE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,YAAY,EACR,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,eAAe,GAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,EACH,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,4BAA4B,EAC5B,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,GACnB,MAAM,cAAc,CAAC;AACtB,YAAY,EACR,qBAAqB,EACrB,eAAe,EACf,eAAe,GAClB,MAAM,cAAc,CAAC;AAGtB,YAAY,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,YAAY,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAG9D,YAAY,EACR,MAAM,EACN,SAAS,EACT,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,EACb,aAAa,GAChB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACtD,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CircuitOpenError = exports.RuleBuilder = exports.rule = exports.exceptionHandler = exports.ExceptionHandler = exports.DefaultExceptionFilter = exports.ValidationException = exports.BadGatewayException = exports.NotImplementedException = exports.InternalServerErrorException = exports.NotFoundException = exports.ForbiddenException = exports.UnauthorizedException = exports.BadRequestException = exports.BaseHTTPException = exports.HttpResponse = exports.HttpRequest = exports.HttpClient = exports.UseInterceptor = exports.UseGuard = exports.Injectable = exports.CircuitBreaker = exports.Timeout = exports.Retry = exports.Cache = exports.Header = exports.Param = exports.Query = exports.Body = exports.Head = exports.Options = exports.Patch = exports.Delete = exports.Put = exports.Post = exports.Get = exports.Controller = exports.ExecutionContext = exports.Container = exports.App = exports.createMiniNestApp = void 0;
|
|
4
|
+
// Core
|
|
5
|
+
var App_1 = require("./core/app/App");
|
|
6
|
+
Object.defineProperty(exports, "createMiniNestApp", { enumerable: true, get: function () { return App_1.createMiniNestApp; } });
|
|
7
|
+
Object.defineProperty(exports, "App", { enumerable: true, get: function () { return App_1.App; } });
|
|
8
|
+
var container_1 = require("./core/container/container");
|
|
9
|
+
Object.defineProperty(exports, "Container", { enumerable: true, get: function () { return container_1.Container; } });
|
|
10
|
+
var ExecutionContext_1 = require("./core/pipeline/ExecutionContext");
|
|
11
|
+
Object.defineProperty(exports, "ExecutionContext", { enumerable: true, get: function () { return ExecutionContext_1.ExecutionContext; } });
|
|
12
|
+
// Decorators
|
|
13
|
+
var decorators_1 = require("./decorators");
|
|
14
|
+
// HTTP
|
|
15
|
+
Object.defineProperty(exports, "Controller", { enumerable: true, get: function () { return decorators_1.Controller; } });
|
|
16
|
+
Object.defineProperty(exports, "Get", { enumerable: true, get: function () { return decorators_1.Get; } });
|
|
17
|
+
Object.defineProperty(exports, "Post", { enumerable: true, get: function () { return decorators_1.Post; } });
|
|
18
|
+
Object.defineProperty(exports, "Put", { enumerable: true, get: function () { return decorators_1.Put; } });
|
|
19
|
+
Object.defineProperty(exports, "Delete", { enumerable: true, get: function () { return decorators_1.Delete; } });
|
|
20
|
+
Object.defineProperty(exports, "Patch", { enumerable: true, get: function () { return decorators_1.Patch; } });
|
|
21
|
+
Object.defineProperty(exports, "Options", { enumerable: true, get: function () { return decorators_1.Options; } });
|
|
22
|
+
Object.defineProperty(exports, "Head", { enumerable: true, get: function () { return decorators_1.Head; } });
|
|
23
|
+
Object.defineProperty(exports, "Body", { enumerable: true, get: function () { return decorators_1.Body; } });
|
|
24
|
+
Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return decorators_1.Query; } });
|
|
25
|
+
Object.defineProperty(exports, "Param", { enumerable: true, get: function () { return decorators_1.Param; } });
|
|
26
|
+
Object.defineProperty(exports, "Header", { enumerable: true, get: function () { return decorators_1.Header; } });
|
|
27
|
+
// AOP
|
|
28
|
+
Object.defineProperty(exports, "Cache", { enumerable: true, get: function () { return decorators_1.Cache; } });
|
|
29
|
+
Object.defineProperty(exports, "Retry", { enumerable: true, get: function () { return decorators_1.Retry; } });
|
|
30
|
+
Object.defineProperty(exports, "Timeout", { enumerable: true, get: function () { return decorators_1.Timeout; } });
|
|
31
|
+
Object.defineProperty(exports, "CircuitBreaker", { enumerable: true, get: function () { return decorators_1.CircuitBreaker; } });
|
|
32
|
+
// DI
|
|
33
|
+
Object.defineProperty(exports, "Injectable", { enumerable: true, get: function () { return decorators_1.Injectable; } });
|
|
34
|
+
// Guards & Interceptors
|
|
35
|
+
Object.defineProperty(exports, "UseGuard", { enumerable: true, get: function () { return decorators_1.UseGuard; } });
|
|
36
|
+
Object.defineProperty(exports, "UseInterceptor", { enumerable: true, get: function () { return decorators_1.UseInterceptor; } });
|
|
37
|
+
// HTTP
|
|
38
|
+
var httpClient_1 = require("./http/client/httpClient");
|
|
39
|
+
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return httpClient_1.HttpClient; } });
|
|
40
|
+
var HttpRequest_1 = require("./http/HttpRequest");
|
|
41
|
+
Object.defineProperty(exports, "HttpRequest", { enumerable: true, get: function () { return HttpRequest_1.HttpRequest; } });
|
|
42
|
+
var HttpResponse_1 = require("./http/HttpResponse");
|
|
43
|
+
Object.defineProperty(exports, "HttpResponse", { enumerable: true, get: function () { return HttpResponse_1.HttpResponse; } });
|
|
44
|
+
// Exceptions
|
|
45
|
+
var exceptions_1 = require("./exceptions");
|
|
46
|
+
Object.defineProperty(exports, "BaseHTTPException", { enumerable: true, get: function () { return exceptions_1.BaseHTTPException; } });
|
|
47
|
+
Object.defineProperty(exports, "BadRequestException", { enumerable: true, get: function () { return exceptions_1.BadRequestException; } });
|
|
48
|
+
Object.defineProperty(exports, "UnauthorizedException", { enumerable: true, get: function () { return exceptions_1.UnauthorizedException; } });
|
|
49
|
+
Object.defineProperty(exports, "ForbiddenException", { enumerable: true, get: function () { return exceptions_1.ForbiddenException; } });
|
|
50
|
+
Object.defineProperty(exports, "NotFoundException", { enumerable: true, get: function () { return exceptions_1.NotFoundException; } });
|
|
51
|
+
Object.defineProperty(exports, "InternalServerErrorException", { enumerable: true, get: function () { return exceptions_1.InternalServerErrorException; } });
|
|
52
|
+
Object.defineProperty(exports, "NotImplementedException", { enumerable: true, get: function () { return exceptions_1.NotImplementedException; } });
|
|
53
|
+
Object.defineProperty(exports, "BadGatewayException", { enumerable: true, get: function () { return exceptions_1.BadGatewayException; } });
|
|
54
|
+
Object.defineProperty(exports, "ValidationException", { enumerable: true, get: function () { return exceptions_1.ValidationException; } });
|
|
55
|
+
Object.defineProperty(exports, "DefaultExceptionFilter", { enumerable: true, get: function () { return exceptions_1.DefaultExceptionFilter; } });
|
|
56
|
+
Object.defineProperty(exports, "ExceptionHandler", { enumerable: true, get: function () { return exceptions_1.ExceptionHandler; } });
|
|
57
|
+
Object.defineProperty(exports, "exceptionHandler", { enumerable: true, get: function () { return exceptions_1.exceptionHandler; } });
|
|
58
|
+
// Validation
|
|
59
|
+
var rule_1 = require("./validation/rule");
|
|
60
|
+
Object.defineProperty(exports, "rule", { enumerable: true, get: function () { return rule_1.rule; } });
|
|
61
|
+
Object.defineProperty(exports, "RuleBuilder", { enumerable: true, get: function () { return rule_1.RuleBuilder; } });
|
|
62
|
+
// Circuit Breaker
|
|
63
|
+
var circuitOpenError_1 = require("./circuitBreaker/circuitOpenError");
|
|
64
|
+
Object.defineProperty(exports, "CircuitOpenError", { enumerable: true, get: function () { return circuitOpenError_1.CircuitOpenError; } });
|
|
65
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,OAAO;AACP,sCAAwD;AAA/C,wGAAA,iBAAiB,OAAA;AAAE,0FAAA,GAAG,OAAA;AAE/B,wDAAuD;AAA9C,sGAAA,SAAS,OAAA;AAElB,qEAAoE;AAA3D,oHAAA,gBAAgB,OAAA;AAGzB,aAAa;AACb,2CAesB;AAdlB,OAAO;AACP,wGAAA,UAAU,OAAA;AACV,iGAAA,GAAG,OAAA;AAAE,kGAAA,IAAI,OAAA;AAAE,iGAAA,GAAG,OAAA;AAAE,oGAAA,MAAM,OAAA;AAAE,mGAAA,KAAK,OAAA;AAAE,qGAAA,OAAO,OAAA;AAAE,kGAAA,IAAI,OAAA;AAC5C,kGAAA,IAAI,OAAA;AAAE,mGAAA,KAAK,OAAA;AAAE,mGAAA,KAAK,OAAA;AAAE,oGAAA,MAAM,OAAA;AAC1B,MAAM;AACN,mGAAA,KAAK,OAAA;AACL,mGAAA,KAAK,OAAA;AACL,qGAAA,OAAO,OAAA;AACP,4GAAA,cAAc,OAAA;AACd,KAAK;AACL,wGAAA,UAAU,OAAA;AACV,wBAAwB;AACxB,sGAAA,QAAQ,OAAA;AACR,4GAAA,cAAc,OAAA;AAIlB,OAAO;AACP,uDAAsD;AAA7C,wGAAA,UAAU,OAAA;AAOnB,kDAAiD;AAAxC,0GAAA,WAAW,OAAA;AAEpB,oDAAmD;AAA1C,4GAAA,YAAY,OAAA;AAErB,aAAa;AACb,2CAasB;AAZlB,+GAAA,iBAAiB,OAAA;AACjB,iHAAA,mBAAmB,OAAA;AACnB,mHAAA,qBAAqB,OAAA;AACrB,gHAAA,kBAAkB,OAAA;AAClB,+GAAA,iBAAiB,OAAA;AACjB,0HAAA,4BAA4B,OAAA;AAC5B,qHAAA,uBAAuB,OAAA;AACvB,iHAAA,mBAAmB,OAAA;AACnB,iHAAA,mBAAmB,OAAA;AACnB,oHAAA,sBAAsB,OAAA;AACtB,8GAAA,gBAAgB,OAAA;AAChB,8GAAA,gBAAgB,OAAA;AAuBpB,aAAa;AACb,0CAAsD;AAA7C,4FAAA,IAAI,OAAA;AAAE,mGAAA,WAAW,OAAA;AAG1B,kBAAkB;AAClB,sEAAqE;AAA5D,oHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Injectable = Injectable;
|
|
4
|
+
const container_1 = require("./container");
|
|
5
|
+
require("reflect-metadata");
|
|
6
|
+
function Injectable() {
|
|
7
|
+
return function (target) {
|
|
8
|
+
const dependencies = Reflect.getMetadata('design:paramtypes', target);
|
|
9
|
+
console.log('Dependencies for', target.name, ':', dependencies);
|
|
10
|
+
container_1.container.register(target, dependencies || []);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.methodInterceptors = exports.classInterceptors = void 0;
|
|
4
|
+
exports.resolveController = resolveController;
|
|
5
|
+
exports.UseInterceptor = UseInterceptor;
|
|
6
|
+
exports.applyInterceptors = applyInterceptors;
|
|
7
|
+
exports.getClassInterceptors = getClassInterceptors;
|
|
8
|
+
exports.getMethodInterceptors = getMethodInterceptors;
|
|
9
|
+
exports.classInterceptors = new Map();
|
|
10
|
+
exports.methodInterceptors = new Map();
|
|
11
|
+
function resolveController(target) {
|
|
12
|
+
return typeof target === 'function' ? target : target.constructor;
|
|
13
|
+
}
|
|
14
|
+
function UseInterceptor(interceptor) {
|
|
15
|
+
return function (target, propertyKey, descriptor) {
|
|
16
|
+
const controller = resolveController(target);
|
|
17
|
+
if (propertyKey) {
|
|
18
|
+
const methodMap = exports.methodInterceptors.get(controller) ?? new Map();
|
|
19
|
+
const list = methodMap.get(propertyKey) ?? [];
|
|
20
|
+
list.push(interceptor);
|
|
21
|
+
methodMap.set(propertyKey, list);
|
|
22
|
+
exports.methodInterceptors.set(controller, methodMap);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const list = exports.classInterceptors.get(controller) ?? [];
|
|
26
|
+
list.push(interceptor);
|
|
27
|
+
exports.classInterceptors.set(controller, list);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function applyInterceptors(interceptors, next) {
|
|
32
|
+
if (interceptors.length === 0)
|
|
33
|
+
return next();
|
|
34
|
+
const interceptor = interceptors[0];
|
|
35
|
+
const rest = interceptors.slice(1);
|
|
36
|
+
const instance = new interceptor();
|
|
37
|
+
return Promise.resolve(instance.intercept(() => applyInterceptors(rest, next)));
|
|
38
|
+
}
|
|
39
|
+
function getClassInterceptors(controller) {
|
|
40
|
+
return exports.classInterceptors.get(controller) || [];
|
|
41
|
+
}
|
|
42
|
+
function getMethodInterceptors(controller, method) {
|
|
43
|
+
return exports.methodInterceptors.get(controller)?.get(method) || [];
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Interceptor.d.ts","sourceRoot":"","sources":["../../src/interceptors/Interceptor.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IACxB,SAAS,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CACjF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Interceptor.js","sourceRoot":"","sources":["../../src/interceptors/Interceptor.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Constructor } from "../core/container/container";
|
|
2
|
+
import { Interceptor } from "./Interceptor";
|
|
3
|
+
export declare function resolveController(target: any): Constructor;
|
|
4
|
+
export declare function applyInterceptors(interceptors: Constructor<Interceptor>[], next: () => Promise<unknown> | unknown): Promise<unknown>;
|
|
5
|
+
//# sourceMappingURL=applyInterceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyInterceptor.d.ts","sourceRoot":"","sources":["../../src/interceptors/applyInterceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAa,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,GAAG,GAAG,WAAW,CAE1D;AAGD,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,WAAW,CAAC,WAAW,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAYpI"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveController = resolveController;
|
|
4
|
+
exports.applyInterceptors = applyInterceptors;
|
|
5
|
+
const container_1 = require("../core/container/container");
|
|
6
|
+
function resolveController(target) {
|
|
7
|
+
return typeof target === 'function' ? target : target.constructor;
|
|
8
|
+
}
|
|
9
|
+
function applyInterceptors(interceptors, next) {
|
|
10
|
+
if (interceptors.length === 0)
|
|
11
|
+
return Promise.resolve(next());
|
|
12
|
+
try {
|
|
13
|
+
const interceptor = interceptors[0];
|
|
14
|
+
const rest = interceptors.slice(1);
|
|
15
|
+
const instance = container_1.Container.instance.resolve(interceptor);
|
|
16
|
+
return Promise.resolve(instance.intercept(() => applyInterceptors(rest, next)));
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
return Promise.reject(err);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=applyInterceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyInterceptor.js","sourceRoot":"","sources":["../../src/interceptors/applyInterceptor.ts"],"names":[],"mappings":";;AAEA,8CAEC;AAGD,8CAYC;AAnBD,2DAAqE;AAErE,SAAgB,iBAAiB,CAAC,MAAW;IACzC,OAAO,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC;AACtE,CAAC;AAGD,SAAgB,iBAAiB,CAAC,YAAwC,EAAE,IAAsC;IAC9G,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9D,IAAI,CAAC;QACD,MAAM,WAAW,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACnC,MAAM,QAAQ,GAAG,qBAAS,CAAC,QAAQ,CAAC,OAAO,CAAc,WAAW,CAAC,CAAC;QACtE,OAAO,OAAO,CAAC,OAAO,CAClB,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAC1D,CAAC;IACN,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,OAAO,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ExecutionContext } from "../core/pipeline/ExecutionContext";
|
|
2
|
+
export interface OnInit {
|
|
3
|
+
onModuleInit(): void | Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
export interface OnDestroy {
|
|
6
|
+
onModuleDestroy(): void | Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export interface OnAppBootstrap {
|
|
9
|
+
onAppBootstrap(): void | Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export interface OnAppShutdown {
|
|
12
|
+
onAppShutdown(): void | Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export interface OnBeforeHandle {
|
|
15
|
+
onBeforeHandle(ctx: ExecutionContext): void | Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export interface OnAfterHandle {
|
|
18
|
+
onAfterHandle(ctx: ExecutionContext, result: unknown): void | Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export interface OnHandleError {
|
|
21
|
+
onHandleError(ctx: ExecutionContext, error: Error): void | Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/lifecycle/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAGrE,MAAM,WAAW,MAAM;IACnB,YAAY,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,SAAS;IACtB,eAAe,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C;AAID,MAAM,WAAW,cAAc;IAC3B,cAAc,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,aAAa;IAC1B,aAAa,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzC;AAGD,MAAM,WAAW,cAAc;IAC3B,cAAc,CAAC,GAAG,EAAE,gBAAgB,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/D;AAED,MAAM,WAAW,aAAa;IAC1B,aAAa,CAAC,GAAG,EAAE,gBAAgB,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/E;AAED,MAAM,WAAW,aAAa;IAC1B,aAAa,CAAC,GAAG,EAAE,gBAAgB,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/lifecycle/lifecycle.ts"],"names":[],"mappings":""}
|
package/dist/main.js
ADDED
package/dist/metadata.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.metadata = void 0;
|
|
4
|
+
const routeRegistry_1 = require("./routeRegistry");
|
|
5
|
+
const paramRegistry_1 = require("./paramRegistry");
|
|
6
|
+
const interceptor_1 = require("./interceptor");
|
|
7
|
+
const routeMetaData = new Map();
|
|
8
|
+
exports.metadata = {
|
|
9
|
+
// 🟦 Route Metadata
|
|
10
|
+
getRoute(method, url) {
|
|
11
|
+
return routeRegistry_1.routeRegistryTrie.findRoute(method, url)?.route;
|
|
12
|
+
},
|
|
13
|
+
registerRoute(route) {
|
|
14
|
+
routeRegistry_1.routeRegistryTrie.addRoute(route.method, route);
|
|
15
|
+
},
|
|
16
|
+
registerRouteOnMethodDecoratorLoad(controller, url, method, handlerName) {
|
|
17
|
+
const route = routeMetaData.get(controller) || [];
|
|
18
|
+
const newRoute = {
|
|
19
|
+
method,
|
|
20
|
+
url,
|
|
21
|
+
handlerName,
|
|
22
|
+
controllerClass: controller,
|
|
23
|
+
};
|
|
24
|
+
route.push(newRoute);
|
|
25
|
+
routeMetaData.set(controller, route);
|
|
26
|
+
},
|
|
27
|
+
finalizeRouteOnControllerLoad(controller, baseUrl) {
|
|
28
|
+
const routes = routeMetaData.get(controller);
|
|
29
|
+
if (!routes) {
|
|
30
|
+
throw new Error(`No routes found for controller ${controller.name}`);
|
|
31
|
+
}
|
|
32
|
+
for (const route of routes) {
|
|
33
|
+
if (route.url.startsWith('/')) {
|
|
34
|
+
route.fullUrl = baseUrl + route.url;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
route.fullUrl = baseUrl + '/' + route.url;
|
|
38
|
+
}
|
|
39
|
+
this.registerRoute(route);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
// 🟨 Parameter Metadata
|
|
43
|
+
getParams(controller, methodName) {
|
|
44
|
+
return paramRegistry_1.paramRegistry.get(controller)?.get(methodName) || [];
|
|
45
|
+
},
|
|
46
|
+
registerParam(controller, methodName, param) {
|
|
47
|
+
if (!paramRegistry_1.paramRegistry.has(controller)) {
|
|
48
|
+
paramRegistry_1.paramRegistry.set(controller, new Map());
|
|
49
|
+
}
|
|
50
|
+
const methodParams = paramRegistry_1.paramRegistry.get(controller);
|
|
51
|
+
const list = methodParams.get(methodName) || [];
|
|
52
|
+
list[param.index] = param; // index-safe
|
|
53
|
+
methodParams.set(methodName, list);
|
|
54
|
+
},
|
|
55
|
+
// 🟥 Interceptor Metadata
|
|
56
|
+
getClassInterceptors(controller) {
|
|
57
|
+
return interceptor_1.classInterceptors.get(controller) || [];
|
|
58
|
+
},
|
|
59
|
+
getMethodInterceptors(controller, method) {
|
|
60
|
+
return interceptor_1.methodInterceptors.get(controller)?.get(method) || [];
|
|
61
|
+
},
|
|
62
|
+
registerClassInterceptor(controller, interceptor) {
|
|
63
|
+
const list = interceptor_1.classInterceptors.get(controller) || [];
|
|
64
|
+
list.push(interceptor);
|
|
65
|
+
interceptor_1.classInterceptors.set(controller, list);
|
|
66
|
+
},
|
|
67
|
+
registerMethodInterceptor(controller, method, interceptor) {
|
|
68
|
+
if (!interceptor_1.methodInterceptors.has(controller)) {
|
|
69
|
+
interceptor_1.methodInterceptors.set(controller, new Map());
|
|
70
|
+
}
|
|
71
|
+
const methodMap = interceptor_1.methodInterceptors.get(controller);
|
|
72
|
+
const list = methodMap.get(method) || [];
|
|
73
|
+
list.push(interceptor);
|
|
74
|
+
methodMap.set(method, list);
|
|
75
|
+
},
|
|
76
|
+
// 🧹 Optional Cleanup
|
|
77
|
+
clearAll() {
|
|
78
|
+
routeRegistry_1.routeRegistryTrie.clear();
|
|
79
|
+
paramRegistry_1.paramRegistry.clear();
|
|
80
|
+
interceptor_1.classInterceptors.clear();
|
|
81
|
+
interceptor_1.methodInterceptors.clear();
|
|
82
|
+
},
|
|
83
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HttpRequest } from "../http/HttpRequest";
|
|
2
|
+
import { HttpResponse } from "../http/HttpResponse";
|
|
3
|
+
import { Middleware } from "./type";
|
|
4
|
+
declare class MiddlewareRegistry {
|
|
5
|
+
private globalMiddlewares;
|
|
6
|
+
private routeMiddlewares;
|
|
7
|
+
registerGlobal(middleware: Middleware): void;
|
|
8
|
+
registerForRoute(routeKey: string, middleware: Middleware): void;
|
|
9
|
+
getMiddlewares(routeKey?: string): Middleware[];
|
|
10
|
+
}
|
|
11
|
+
export declare const middlewareRegistry: MiddlewareRegistry;
|
|
12
|
+
export declare function runMiddleware(middlewares: Middleware[], req: HttpRequest, res: HttpResponse): Promise<void>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAGnC,cAAM,kBAAkB;IACrB,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,gBAAgB,CAAwC;IAEhE,cAAc,CAAC,UAAU,EAAE,UAAU;IAGrC,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU;IAMzD,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,EAAE;CAKlD;AAED,eAAO,MAAM,kBAAkB,oBAA2B,CAAC;AAE3D,wBAAsB,aAAa,CAAC,WAAW,EAAE,UAAU,EAAE,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBjH"}
|