@lerianstudio/sindarian-server 1.0.0-beta.1 → 1.0.0-beta.2
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/README.md +367 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +1 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/constants/keys.d.ts +4 -0
- package/dist/constants/keys.d.ts.map +1 -1
- package/dist/constants/keys.js +5 -1
- package/dist/constants/keys.js.map +1 -1
- package/dist/constants/scopes.d.ts +6 -0
- package/dist/constants/scopes.d.ts.map +1 -0
- package/dist/constants/scopes.js +10 -0
- package/dist/constants/scopes.js.map +1 -0
- package/dist/context/arguments-host.d.ts +14 -0
- package/dist/context/arguments-host.d.ts.map +1 -0
- package/dist/context/arguments-host.js +28 -0
- package/dist/context/arguments-host.js.map +1 -0
- package/dist/context/execution-context.d.ts +10 -0
- package/dist/context/execution-context.d.ts.map +1 -0
- package/dist/context/execution-context.js +19 -0
- package/dist/context/execution-context.js.map +1 -0
- package/dist/context/http-arguments-host.d.ts +8 -0
- package/dist/context/http-arguments-host.d.ts.map +1 -0
- package/dist/context/http-arguments-host.js +17 -0
- package/dist/context/http-arguments-host.js.map +1 -0
- package/dist/context/index.d.ts +4 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +20 -0
- package/dist/context/index.js.map +1 -0
- package/dist/controllers/base-controller.d.ts +0 -2
- package/dist/controllers/base-controller.d.ts.map +1 -1
- package/dist/controllers/base-controller.js +0 -15
- package/dist/controllers/base-controller.js.map +1 -1
- package/dist/controllers/decorators/body-decorator.d.ts +2 -3
- package/dist/controllers/decorators/body-decorator.d.ts.map +1 -1
- package/dist/controllers/decorators/body-decorator.js +31 -13
- package/dist/controllers/decorators/body-decorator.js.map +1 -1
- package/dist/controllers/decorators/controller-decorator.d.ts +0 -4
- package/dist/controllers/decorators/controller-decorator.d.ts.map +1 -1
- package/dist/controllers/decorators/controller-decorator.js +1 -44
- package/dist/controllers/decorators/controller-decorator.js.map +1 -1
- package/dist/dependency-injection/container.js +1 -1
- package/dist/dependency-injection/container.js.map +1 -1
- package/dist/dependency-injection/index.d.ts +2 -1
- package/dist/dependency-injection/index.d.ts.map +1 -1
- package/dist/dependency-injection/index.js +3 -2
- package/dist/dependency-injection/index.js.map +1 -1
- package/dist/dependency-injection/injectable-decorator.d.ts +7 -0
- package/dist/dependency-injection/injectable-decorator.d.ts.map +1 -0
- package/dist/dependency-injection/injectable-decorator.js +21 -0
- package/dist/dependency-injection/injectable-decorator.js.map +1 -0
- package/dist/exceptions/base-exception-filter.d.ts +8 -0
- package/dist/exceptions/base-exception-filter.d.ts.map +1 -0
- package/dist/exceptions/base-exception-filter.js +14 -0
- package/dist/exceptions/base-exception-filter.js.map +1 -0
- package/dist/exceptions/decorators/catch-decorator.d.ts +8 -0
- package/dist/exceptions/decorators/catch-decorator.d.ts.map +1 -0
- package/dist/exceptions/decorators/catch-decorator.js +14 -0
- package/dist/exceptions/decorators/catch-decorator.js.map +1 -0
- package/dist/exceptions/decorators/index.d.ts +3 -0
- package/dist/exceptions/decorators/index.d.ts.map +1 -0
- package/dist/exceptions/decorators/index.js +8 -0
- package/dist/exceptions/decorators/index.js.map +1 -0
- package/dist/exceptions/decorators/use-filters-decorator.d.ts +4 -0
- package/dist/exceptions/decorators/use-filters-decorator.d.ts.map +1 -0
- package/dist/exceptions/decorators/use-filters-decorator.js +16 -0
- package/dist/exceptions/decorators/use-filters-decorator.js.map +1 -0
- package/dist/exceptions/exception-filter.d.ts +6 -0
- package/dist/exceptions/exception-filter.d.ts.map +1 -0
- package/dist/exceptions/exception-filter.js +7 -0
- package/dist/exceptions/exception-filter.js.map +1 -0
- package/dist/exceptions/index.d.ts +3 -0
- package/dist/exceptions/index.d.ts.map +1 -1
- package/dist/exceptions/index.js +3 -0
- package/dist/exceptions/index.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/interceptor/call-handler.d.ts +4 -0
- package/dist/interceptor/call-handler.d.ts.map +1 -0
- package/dist/interceptor/call-handler.js +3 -0
- package/dist/interceptor/call-handler.js.map +1 -0
- package/dist/interceptor/decorators/index.d.ts +2 -0
- package/dist/interceptor/decorators/index.d.ts.map +1 -0
- package/dist/interceptor/decorators/index.js +6 -0
- package/dist/interceptor/decorators/index.js.map +1 -0
- package/dist/interceptor/decorators/use-interceptor-decorator.d.ts +8 -0
- package/dist/interceptor/decorators/use-interceptor-decorator.d.ts.map +1 -0
- package/dist/interceptor/decorators/use-interceptor-decorator.js +38 -0
- package/dist/interceptor/decorators/use-interceptor-decorator.js.map +1 -0
- package/dist/interceptor/index.d.ts +4 -0
- package/dist/interceptor/index.d.ts.map +1 -0
- package/dist/interceptor/index.js +20 -0
- package/dist/interceptor/index.js.map +1 -0
- package/dist/interceptor/interceptor.d.ts +3 -5
- package/dist/interceptor/interceptor.d.ts.map +1 -1
- package/dist/interceptor/interceptor.js.map +1 -1
- package/dist/logger/console-logger.d.ts +24 -0
- package/dist/logger/console-logger.d.ts.map +1 -0
- package/dist/logger/console-logger.js +78 -0
- package/dist/logger/console-logger.js.map +1 -0
- package/dist/logger/index.d.ts +4 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +8 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/logger/logger-service.d.ts +34 -0
- package/dist/logger/logger-service.d.ts.map +1 -0
- package/dist/logger/logger-service.js +12 -0
- package/dist/logger/logger-service.js.map +1 -0
- package/dist/logger/logger.d.ts +21 -0
- package/dist/logger/logger.d.ts.map +1 -0
- package/dist/logger/logger.js +86 -0
- package/dist/logger/logger.js.map +1 -0
- package/dist/modules/module-decorator.d.ts +3 -1
- package/dist/modules/module-decorator.d.ts.map +1 -1
- package/dist/modules/module-decorator.js +83 -23
- package/dist/modules/module-decorator.js.map +1 -1
- package/dist/server/server-factory.d.ts +15 -8
- package/dist/server/server-factory.d.ts.map +1 -1
- package/dist/server/server-factory.js +95 -49
- package/dist/server/server-factory.js.map +1 -1
- package/dist/services/filters.d.ts +2 -0
- package/dist/services/filters.d.ts.map +1 -0
- package/dist/services/filters.js +5 -0
- package/dist/services/filters.js.map +1 -0
- package/dist/services/http-service.d.ts +68 -0
- package/dist/services/http-service.d.ts.map +1 -0
- package/dist/services/http-service.js +233 -0
- package/dist/services/http-service.js.map +1 -0
- package/dist/services/interceptor.d.ts +2 -0
- package/dist/services/interceptor.d.ts.map +1 -0
- package/dist/services/interceptor.js +5 -0
- package/dist/services/interceptor.js.map +1 -0
- package/dist/utils/form-data/get-form-data.d.ts +2 -0
- package/dist/utils/form-data/get-form-data.d.ts.map +1 -0
- package/dist/utils/form-data/get-form-data.js +11 -0
- package/dist/utils/form-data/get-form-data.js.map +1 -0
- package/dist/utils/search/create-query-string.d.ts +9 -0
- package/dist/utils/search/create-query-string.d.ts.map +1 -0
- package/dist/utils/search/create-query-string.js +26 -0
- package/dist/utils/search/create-query-string.js.map +1 -0
- package/package.json +2 -5
- package/dist/interceptor/decorators/use-interceptor.d.ts +0 -3
- package/dist/interceptor/decorators/use-interceptor.d.ts.map +0 -1
- package/dist/interceptor/decorators/use-interceptor.js +0 -9
- package/dist/interceptor/decorators/use-interceptor.js.map +0 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interceptorExecute = interceptorExecute;
|
|
4
|
+
exports.interceptorHandler = interceptorHandler;
|
|
5
|
+
exports.UseInterceptors = UseInterceptors;
|
|
6
|
+
const keys_1 = require("../../constants/keys");
|
|
7
|
+
async function interceptorExecute(executionContext, middlewares, action) {
|
|
8
|
+
if (middlewares.length === 0) {
|
|
9
|
+
return await action();
|
|
10
|
+
}
|
|
11
|
+
let i = 0;
|
|
12
|
+
const next = {
|
|
13
|
+
handle: async () => {
|
|
14
|
+
if (i >= middlewares.length) {
|
|
15
|
+
return await action();
|
|
16
|
+
}
|
|
17
|
+
const layer = middlewares[i++];
|
|
18
|
+
try {
|
|
19
|
+
return await layer.intercept(executionContext, next);
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return await next.handle();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return await next.handle();
|
|
28
|
+
}
|
|
29
|
+
function interceptorHandler(target) {
|
|
30
|
+
return Reflect.getOwnMetadata(keys_1.INTERCEPTOR_KEY, target) || [];
|
|
31
|
+
}
|
|
32
|
+
function UseInterceptors(...interceptors) {
|
|
33
|
+
return (target) => {
|
|
34
|
+
const existingInterceptors = Reflect.getOwnMetadata(keys_1.INTERCEPTOR_KEY, target) || [];
|
|
35
|
+
Reflect.defineMetadata(keys_1.INTERCEPTOR_KEY, [...existingInterceptors, ...interceptors], target);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=use-interceptor-decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-interceptor-decorator.js","sourceRoot":"","sources":["../../../src/interceptor/decorators/use-interceptor-decorator.ts"],"names":[],"mappings":";;AAMA,gDA6BC;AAID,gDAEC;AAED,0CAYC;AAvDD,2CAAkD;AAM3C,KAAK,UAAU,kBAAkB,CACtC,gBAAkC,EAClC,WAA0B,EAC1B,MAA0B;IAE1B,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,MAAM,MAAM,EAAE,CAAA;IACvB,CAAC;IAED,IAAI,CAAC,GAAG,CAAC,CAAA;IAET,MAAM,IAAI,GAAgB;QACxB,MAAM,EAAE,KAAK,IAAI,EAAE;YACjB,IAAI,CAAC,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;gBAC5B,OAAO,MAAM,MAAM,EAAE,CAAA;YACvB,CAAC;YAED,MAAM,KAAK,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAA;YAE9B,IAAI,CAAC;gBACH,OAAO,MAAM,KAAK,CAAC,SAAS,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAA;gBACpD,6DAA6D;YAC/D,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,OAAO,MAAM,IAAI,CAAC,MAAM,EAAE,CAAA;YAC5B,CAAC;QACH,CAAC;KACF,CAAA;IAED,OAAO,MAAM,IAAI,CAAC,MAAM,EAAE,CAAA;AAC5B,CAAC;AAID,SAAgB,kBAAkB,CAAC,MAAc;IAC/C,OAAO,OAAO,CAAC,cAAc,CAAC,sBAAe,EAAE,MAAM,CAAC,IAAI,EAAE,CAAA;AAC9D,CAAC;AAED,SAAgB,eAAe,CAC7B,GAAG,YAAkD;IAErD,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,MAAM,oBAAoB,GACxB,OAAO,CAAC,cAAc,CAAC,sBAAe,EAAE,MAAM,CAAC,IAAI,EAAE,CAAA;QACvD,OAAO,CAAC,cAAc,CACpB,sBAAe,EACf,CAAC,GAAG,oBAAoB,EAAE,GAAG,YAAY,CAAC,EAC1C,MAAM,CACP,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interceptor/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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("./decorators"), exports);
|
|
18
|
+
__exportStar(require("./interceptor"), exports);
|
|
19
|
+
__exportStar(require("./call-handler"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interceptor/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,gDAA6B;AAC7B,iDAA8B"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
};
|
|
1
|
+
import { ExecutionContext } from '../context/execution-context';
|
|
2
|
+
import { CallHandler } from './call-handler';
|
|
4
3
|
export declare abstract class Interceptor {
|
|
5
|
-
abstract intercept(context:
|
|
4
|
+
abstract intercept(context: ExecutionContext, next: CallHandler): Promise<any>;
|
|
6
5
|
}
|
|
7
|
-
export {};
|
|
8
6
|
//# sourceMappingURL=interceptor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../../src/interceptor/interceptor.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../../src/interceptor/interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,8BAAsB,WAAW;IAC/B,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;CAC/E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interceptor.js","sourceRoot":"","sources":["../../src/interceptor/interceptor.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"interceptor.js","sourceRoot":"","sources":["../../src/interceptor/interceptor.ts"],"names":[],"mappings":";;;AAGA,MAAsB,WAAW;CAEhC;AAFD,kCAEC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { LoggerService, LogLevel } from './logger-service';
|
|
2
|
+
export type ConsoleLoggerOptions = {
|
|
3
|
+
prefix?: string;
|
|
4
|
+
logLevels?: LogLevel[];
|
|
5
|
+
};
|
|
6
|
+
export declare class ConsoleLogger implements LoggerService {
|
|
7
|
+
protected logLevels: LogLevel[];
|
|
8
|
+
protected options: ConsoleLoggerOptions;
|
|
9
|
+
constructor(options?: ConsoleLoggerOptions);
|
|
10
|
+
log(message: any, ...optionalParams: any[]): void;
|
|
11
|
+
fatal(message: any, ...optionalParams: any[]): void;
|
|
12
|
+
error(message: any, ...optionalParams: any[]): void;
|
|
13
|
+
warn(message: any, ...optionalParams: any[]): void;
|
|
14
|
+
debug?(message: any, ...optionalParams: any[]): void;
|
|
15
|
+
verbose?(message: any, ...optionalParams: any[]): void;
|
|
16
|
+
/**
|
|
17
|
+
* Set log levels
|
|
18
|
+
* @param levels log levels
|
|
19
|
+
*/
|
|
20
|
+
setLogLevels(levels: LogLevel[]): void;
|
|
21
|
+
protected printMessage(level: string | undefined, message: any, writeStreamType?: 'stdout' | 'stderr'): void;
|
|
22
|
+
protected formatMessage(level: string, message: any): string;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=console-logger.d.ts.map
|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AG,GAAG,MAAM;CAM7D"}
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ConsoleLogger = void 0;
|
|
16
|
+
const inversify_1 = require("inversify");
|
|
17
|
+
const logger_1 = require("./logger");
|
|
18
|
+
const DEFAULT_LOG_LEVELS = [
|
|
19
|
+
'log',
|
|
20
|
+
'error',
|
|
21
|
+
'warn',
|
|
22
|
+
'debug',
|
|
23
|
+
'verbose',
|
|
24
|
+
'fatal'
|
|
25
|
+
];
|
|
26
|
+
let ConsoleLogger = class ConsoleLogger {
|
|
27
|
+
constructor(options) {
|
|
28
|
+
this.logLevels = DEFAULT_LOG_LEVELS;
|
|
29
|
+
options = options ?? {};
|
|
30
|
+
options.logLevels = DEFAULT_LOG_LEVELS;
|
|
31
|
+
options.prefix ??= 'Sindarian';
|
|
32
|
+
this.options = options;
|
|
33
|
+
}
|
|
34
|
+
log(message, ...optionalParams) {
|
|
35
|
+
this.printMessage('log', message, ...optionalParams);
|
|
36
|
+
}
|
|
37
|
+
fatal(message, ...optionalParams) {
|
|
38
|
+
this.printMessage('fatal', message, ...optionalParams);
|
|
39
|
+
}
|
|
40
|
+
error(message, ...optionalParams) {
|
|
41
|
+
this.printMessage('error', message, ...optionalParams);
|
|
42
|
+
}
|
|
43
|
+
warn(message, ...optionalParams) {
|
|
44
|
+
this.printMessage('warn', message, ...optionalParams);
|
|
45
|
+
}
|
|
46
|
+
debug(message, ...optionalParams) {
|
|
47
|
+
this.printMessage('debug', message, ...optionalParams);
|
|
48
|
+
}
|
|
49
|
+
verbose(message, ...optionalParams) {
|
|
50
|
+
this.printMessage('verbose', message, ...optionalParams);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Set log levels
|
|
54
|
+
* @param levels log levels
|
|
55
|
+
*/
|
|
56
|
+
setLogLevels(levels) {
|
|
57
|
+
if (!this.options) {
|
|
58
|
+
this.options = {};
|
|
59
|
+
}
|
|
60
|
+
this.options.logLevels = levels;
|
|
61
|
+
}
|
|
62
|
+
printMessage(level = 'log', message, writeStreamType = 'stdout') {
|
|
63
|
+
const logLevel = level.toUpperCase();
|
|
64
|
+
process[writeStreamType].write(this.formatMessage(logLevel, message));
|
|
65
|
+
}
|
|
66
|
+
formatMessage(level, message) {
|
|
67
|
+
const timestamp = logger_1.Logger.getTimestamp();
|
|
68
|
+
const logLevel = level.toUpperCase();
|
|
69
|
+
return `[${this.options.prefix}] - ${timestamp} [${logLevel}] ${message}\n`;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
exports.ConsoleLogger = ConsoleLogger;
|
|
73
|
+
exports.ConsoleLogger = ConsoleLogger = __decorate([
|
|
74
|
+
(0, inversify_1.injectable)(),
|
|
75
|
+
__param(0, (0, inversify_1.unmanaged)()),
|
|
76
|
+
__metadata("design:paramtypes", [Object])
|
|
77
|
+
], ConsoleLogger);
|
|
78
|
+
//# sourceMappingURL=console-logger.js.map
|
|
@@ -0,0 +1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
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = exports.ConsoleLogger = void 0;
|
|
4
|
+
var console_logger_1 = require("./console-logger");
|
|
5
|
+
Object.defineProperty(exports, "ConsoleLogger", { enumerable: true, get: function () { return console_logger_1.ConsoleLogger; } });
|
|
6
|
+
var logger_1 = require("./logger");
|
|
7
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":";;;AAAA,mDAAsE;AAA7D,+GAAA,aAAa,OAAA;AACtB,mCAAiC;AAAxB,gGAAA,MAAM,OAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const LOG_LEVELS: ["verbose", "debug", "log", "warn", "error", "fatal"];
|
|
2
|
+
export type LogLevel = (typeof LOG_LEVELS)[number];
|
|
3
|
+
export interface LoggerService {
|
|
4
|
+
/**
|
|
5
|
+
* Write a 'log' level log.
|
|
6
|
+
*/
|
|
7
|
+
log(message: any, ...optionalParams: any[]): any;
|
|
8
|
+
/**
|
|
9
|
+
* Write an 'error' level log.
|
|
10
|
+
*/
|
|
11
|
+
error(message: any, ...optionalParams: any[]): any;
|
|
12
|
+
/**
|
|
13
|
+
* Write a 'warn' level log.
|
|
14
|
+
*/
|
|
15
|
+
warn(message: any, ...optionalParams: any[]): any;
|
|
16
|
+
/**
|
|
17
|
+
* Write a 'debug' level log.
|
|
18
|
+
*/
|
|
19
|
+
debug?(message: any, ...optionalParams: any[]): any;
|
|
20
|
+
/**
|
|
21
|
+
* Write a 'verbose' level log.
|
|
22
|
+
*/
|
|
23
|
+
verbose?(message: any, ...optionalParams: any[]): any;
|
|
24
|
+
/**
|
|
25
|
+
* Write a 'fatal' level log.
|
|
26
|
+
*/
|
|
27
|
+
fatal?(message: any, ...optionalParams: any[]): any;
|
|
28
|
+
/**
|
|
29
|
+
* Set log levels.
|
|
30
|
+
* @param levels log levels
|
|
31
|
+
*/
|
|
32
|
+
setLogLevels?(levels: LogLevel[]): any;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=logger-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-service.d.ts","sourceRoot":"","sources":["../../src/logger/logger-service.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,uDAOM,CAAA;AAE7B,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAA;AAElD,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;IAEhD;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;IAElD;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;IAEjD;;OAEG;IACH,KAAK,CAAC,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;IAEnD;;OAEG;IACH,OAAO,CAAC,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;IAErD;;OAEG;IACH,KAAK,CAAC,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;IAEnD;;;OAGG;IACH,YAAY,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAA;CACvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-service.js","sourceRoot":"","sources":["../../src/logger/logger-service.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG;IACxB,SAAS;IACT,OAAO;IACP,KAAK;IACL,MAAM;IACN,OAAO;IACP,OAAO;CACoB,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LoggerService, LogLevel } from './logger-service';
|
|
2
|
+
export declare class Logger implements LoggerService {
|
|
3
|
+
private logger;
|
|
4
|
+
private static staticLogger?;
|
|
5
|
+
log(message: any, ...optionalParams: any[]): void;
|
|
6
|
+
error(message: any, ...optionalParams: any[]): void;
|
|
7
|
+
warn(message: any, ...optionalParams: any[]): void;
|
|
8
|
+
debug?(message: any, ...optionalParams: any[]): void;
|
|
9
|
+
verbose?(message: any, ...optionalParams: any[]): void;
|
|
10
|
+
fatal?(message: any, ...optionalParams: any[]): void;
|
|
11
|
+
setLogLevels?(levels: LogLevel[]): void;
|
|
12
|
+
static log(message: any, ...optionalParams: any[]): void;
|
|
13
|
+
static error(message: any, ...optionalParams: any[]): void;
|
|
14
|
+
static warn(message: any, ...optionalParams: any[]): void;
|
|
15
|
+
static debug?(message: any, ...optionalParams: any[]): void;
|
|
16
|
+
static verbose?(message: any, ...optionalParams: any[]): void;
|
|
17
|
+
static fatal?(message: any, ...optionalParams: any[]): void;
|
|
18
|
+
static getTimestamp(): string;
|
|
19
|
+
static overrideLogger(logger: LoggerService | boolean): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAa1D,qBACa,MAAO,YAAW,aAAa;IAC1C,OAAO,CAAC,MAAM,CAAqC;IACnD,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAe;IAE3C,GAAG,CAAC,OAAO,EAAE,GA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: 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
|
+
var Logger_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.Logger = void 0;
|
|
11
|
+
const inversify_1 = require("inversify");
|
|
12
|
+
const console_logger_1 = require("./console-logger");
|
|
13
|
+
const lodash_1 = require("lodash");
|
|
14
|
+
const dateTimeFormatter = new Intl.DateTimeFormat(undefined, {
|
|
15
|
+
year: 'numeric',
|
|
16
|
+
hour: 'numeric',
|
|
17
|
+
minute: 'numeric',
|
|
18
|
+
second: 'numeric',
|
|
19
|
+
day: '2-digit',
|
|
20
|
+
month: '2-digit'
|
|
21
|
+
});
|
|
22
|
+
let Logger = Logger_1 = class Logger {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.logger = new console_logger_1.ConsoleLogger();
|
|
25
|
+
}
|
|
26
|
+
log(message, ...optionalParams) {
|
|
27
|
+
this.logger.log(message, ...optionalParams);
|
|
28
|
+
}
|
|
29
|
+
error(message, ...optionalParams) {
|
|
30
|
+
this.logger.error(message, ...optionalParams);
|
|
31
|
+
}
|
|
32
|
+
warn(message, ...optionalParams) {
|
|
33
|
+
this.logger.warn(message, ...optionalParams);
|
|
34
|
+
}
|
|
35
|
+
debug(message, ...optionalParams) {
|
|
36
|
+
this.logger.debug?.(message, ...optionalParams);
|
|
37
|
+
}
|
|
38
|
+
verbose(message, ...optionalParams) {
|
|
39
|
+
this.logger.verbose?.(message, ...optionalParams);
|
|
40
|
+
}
|
|
41
|
+
fatal(message, ...optionalParams) {
|
|
42
|
+
this.logger.fatal?.(message, ...optionalParams);
|
|
43
|
+
}
|
|
44
|
+
setLogLevels(levels) {
|
|
45
|
+
this.logger.setLogLevels?.(levels);
|
|
46
|
+
}
|
|
47
|
+
static log(message, ...optionalParams) {
|
|
48
|
+
this.staticLogger?.log(message, ...optionalParams);
|
|
49
|
+
}
|
|
50
|
+
static error(message, ...optionalParams) {
|
|
51
|
+
this.staticLogger?.error(message, ...optionalParams);
|
|
52
|
+
}
|
|
53
|
+
static warn(message, ...optionalParams) {
|
|
54
|
+
this.staticLogger?.warn(message, ...optionalParams);
|
|
55
|
+
}
|
|
56
|
+
static debug(message, ...optionalParams) {
|
|
57
|
+
this.staticLogger?.debug?.(message, ...optionalParams);
|
|
58
|
+
}
|
|
59
|
+
static verbose(message, ...optionalParams) {
|
|
60
|
+
this.staticLogger?.verbose?.(message, ...optionalParams);
|
|
61
|
+
}
|
|
62
|
+
static fatal(message, ...optionalParams) {
|
|
63
|
+
this.staticLogger?.fatal?.(message, ...optionalParams);
|
|
64
|
+
}
|
|
65
|
+
static getTimestamp() {
|
|
66
|
+
return dateTimeFormatter.format(Date.now());
|
|
67
|
+
}
|
|
68
|
+
static overrideLogger(logger) {
|
|
69
|
+
if ((0, lodash_1.isObject)(logger)) {
|
|
70
|
+
if (logger instanceof Logger_1 && logger.constructor !== Logger_1) {
|
|
71
|
+
const errorMessage = `Using the "extends Logger" instruction is not allowed. Please, use "extends ConsoleLogger" instead.`;
|
|
72
|
+
this.staticLogger?.error(errorMessage);
|
|
73
|
+
throw new Error(errorMessage);
|
|
74
|
+
}
|
|
75
|
+
this.staticLogger = logger;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.staticLogger = undefined;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
exports.Logger = Logger;
|
|
83
|
+
exports.Logger = Logger = Logger_1 = __decorate([
|
|
84
|
+
(0, inversify_1.injectable)()
|
|
85
|
+
], Logger);
|
|
86
|
+
//# sourceMappingURL=logger.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IAAA,iBAAQ,EAAC,MAAM,CAAC,EAAE,CAAC;YACrB,IAAI,MAAM,YAAY,QAAM,IAAI,MAAM,CAAC,WAAW,KAAK,QAAM,EAAE,CAAC;gBAC9D,MAAM,YAAY,GAAG,qGAAqG,CAAA;gBAC1H,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,CAAA;gBACtC,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAA;YAC/B,CAAC;YACD,IAAI,CAAC,YAAY,GAAG,MAAuB,CAAA;QAC7C,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,YAAY,GAAG,SAAS,CAAA;QAC/B,CAAC;IACH,CAAC;CACF,CAAA;AA7DY,wBAAM;iBAAN,MAAM;IADlB,IAAA,sBAAU,GAAE;GACA,MAAM,CA6DlB"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { ResolutionContext } from 'inversify';
|
|
1
2
|
import { Class, Constructor } from '../types/class';
|
|
3
|
+
import { Scope } from '../constants/scopes';
|
|
2
4
|
import { ControllerMetadata } from '../controllers/decorators/controller-decorator';
|
|
3
|
-
import { ResolutionContext } from 'inversify';
|
|
4
5
|
export type InjectionToken<T = any> = symbol | string | Constructor<T>;
|
|
5
6
|
type Provider = {
|
|
6
7
|
provide: InjectionToken;
|
|
7
8
|
useClass?: Class;
|
|
8
9
|
useValue?: any;
|
|
9
10
|
useFactory?: (context: ResolutionContext) => any | Promise<any>;
|
|
11
|
+
scope?: Scope;
|
|
10
12
|
} | Class;
|
|
11
13
|
export type ModuleOptions = {
|
|
12
14
|
imports?: Class[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-decorator.d.ts","sourceRoot":"","sources":["../../src/modules/module-decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AASlD,OAAO,
|
|
1
|
+
{"version":3,"file":"module-decorator.d.ts","sourceRoot":"","sources":["../../src/modules/module-decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,iBAAiB,EAAE,MAAM,WAAW,CAAA;AACjE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AASlD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAEL,kBAAkB,EACnB,MAAM,+CAA+C,CAAA;AAKtD,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,GAAG,IAAI,MAAM,GAAG,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;AAEtE,KAAK,QAAQ,GACT;IACE,OAAO,EAAE,cAAc,CAAA;IACvB,QAAQ,CAAC,EAAE,KAAK,CAAA;IAChB,QAAQ,CAAC,EAAE,GAAG,CAAA;IACd,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;IAC/D,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,GACD,KAAK,CAAA;AAET,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,CAAC,EAAE,KAAK,EAAE,CAAA;IACjB,WAAW,CAAC,EAAE,KAAK,EAAE,CAAA;IACrB,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG,kBAAkB,GAAG;IAChD,UAAU,EAAE,KAAK,CAAA;CAClB,CAAA;AAED,wBAAgB,aAAa,CAC3B,MAAM,EAAE,QAAQ,EAChB,OAAO,GAAE,GAAG,CAAC,QAAQ,CAAa,GACjC,cAAc,EAAE,CAiClB;AAED,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,cAAc,CAsD9D"}
|
|
@@ -4,7 +4,10 @@ exports.moduleHandler = moduleHandler;
|
|
|
4
4
|
exports.Module = Module;
|
|
5
5
|
const container_1 = require("../dependency-injection/container");
|
|
6
6
|
const keys_1 = require("../constants/keys");
|
|
7
|
+
const scopes_1 = require("../constants/scopes");
|
|
7
8
|
const controller_decorator_1 = require("../controllers/decorators/controller-decorator");
|
|
9
|
+
const use_interceptor_decorator_1 = require("../interceptor/decorators/use-interceptor-decorator");
|
|
10
|
+
const logger_1 = require("../logger/logger");
|
|
8
11
|
function moduleHandler(target, visited = new Set()) {
|
|
9
12
|
// Prevent infinite recursion by tracking visited modules
|
|
10
13
|
if (visited.has(target)) {
|
|
@@ -25,6 +28,7 @@ function moduleHandler(target, visited = new Set()) {
|
|
|
25
28
|
...route,
|
|
26
29
|
controller
|
|
27
30
|
}));
|
|
31
|
+
logger_1.Logger.log(`Registered ${controllerRoutes.length} routes for controller ${controller.name}`);
|
|
28
32
|
routes.push(...controllerRoutes);
|
|
29
33
|
}
|
|
30
34
|
}
|
|
@@ -41,32 +45,24 @@ function Module(options) {
|
|
|
41
45
|
});
|
|
42
46
|
}
|
|
43
47
|
if (providers) {
|
|
44
|
-
providers.forEach((
|
|
45
|
-
if (typeof providerEntity === 'object') {
|
|
46
|
-
if (providerEntity.useClass) {
|
|
47
|
-
container.bind(providerEntity.provide).to(providerEntity.useClass);
|
|
48
|
-
}
|
|
49
|
-
else if (providerEntity.useFactory) {
|
|
50
|
-
container
|
|
51
|
-
.bind(providerEntity.provide)
|
|
52
|
-
.toDynamicValue(async (context) => {
|
|
53
|
-
return await providerEntity.useFactory(context);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
else if (providerEntity.useValue) {
|
|
57
|
-
container
|
|
58
|
-
.bind(providerEntity.provide)
|
|
59
|
-
.toConstantValue(providerEntity.useValue);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
container.bind(providerEntity).to(providerEntity);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
48
|
+
providers.forEach((provider) => registerProvider(container, provider));
|
|
66
49
|
}
|
|
67
50
|
if (controllers) {
|
|
68
51
|
controllers.forEach((controller) => {
|
|
69
|
-
|
|
52
|
+
// Bind the controller
|
|
53
|
+
container.bind(controller).to(controller).inSingletonScope();
|
|
54
|
+
// Check for interceptors and register class types
|
|
55
|
+
const interceptors = (0, use_interceptor_decorator_1.interceptorHandler)(controller);
|
|
56
|
+
interceptors.forEach((interceptor) => {
|
|
57
|
+
// If it's a class constructor (function), register it in the container
|
|
58
|
+
if (typeof interceptor === 'function') {
|
|
59
|
+
container.bind(interceptor).toSelf().inSingletonScope();
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// If it's an instance, bind it to its constructor class as a constant value
|
|
63
|
+
container.bind(interceptor.constructor).toConstantValue(interceptor);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
70
66
|
});
|
|
71
67
|
}
|
|
72
68
|
});
|
|
@@ -83,4 +79,68 @@ function Module(options) {
|
|
|
83
79
|
prototype[keys_1.CONTROLLERS_PROPERTY] = controllers;
|
|
84
80
|
};
|
|
85
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Register a provider in the container
|
|
84
|
+
* @param container
|
|
85
|
+
* @param provider
|
|
86
|
+
*/
|
|
87
|
+
function registerProvider(container, provider) {
|
|
88
|
+
// Checks if provider is a object with options
|
|
89
|
+
if (typeof provider === 'object') {
|
|
90
|
+
registerProviderObject(container, provider);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// If not, it's a simple class type
|
|
94
|
+
container.bind(provider).to(provider);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Registers a provider object in the container
|
|
99
|
+
* @param container
|
|
100
|
+
* @param provider
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
function registerProviderObject(container, provider) {
|
|
104
|
+
// Protect the method by avoid non objects
|
|
105
|
+
if (typeof provider !== 'object') {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const { provide, useClass, useValue, useFactory, scope } = provider;
|
|
109
|
+
const bind = container.bind(provide);
|
|
110
|
+
if (useClass) {
|
|
111
|
+
registerScope(bind.to(useClass), scope);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (useFactory) {
|
|
115
|
+
registerScope(bind.toDynamicValue(async (context) => {
|
|
116
|
+
return await useFactory(context);
|
|
117
|
+
}), scope);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (useValue) {
|
|
121
|
+
bind.toConstantValue(useValue);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const message = `Module: Invalid provider ${provider.provide.toString()} configuration`;
|
|
125
|
+
logger_1.Logger.error(message);
|
|
126
|
+
throw new Error(message);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Registers a scope for a binding
|
|
130
|
+
* @param bind
|
|
131
|
+
* @param scope
|
|
132
|
+
* @returns
|
|
133
|
+
*/
|
|
134
|
+
function registerScope(bind, scope) {
|
|
135
|
+
switch (scope) {
|
|
136
|
+
case scopes_1.Scope.DEFAULT:
|
|
137
|
+
return bind.inSingletonScope();
|
|
138
|
+
case scopes_1.Scope.REQUEST:
|
|
139
|
+
return bind.inRequestScope();
|
|
140
|
+
case scopes_1.Scope.TRANSIENT:
|
|
141
|
+
return bind.inTransientScope();
|
|
142
|
+
default:
|
|
143
|
+
return bind.inSingletonScope();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
86
146
|
//# sourceMappingURL=module-decorator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-decorator.js","sourceRoot":"","sources":["../../src/modules/module-decorator.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"module-decorator.js","sourceRoot":"","sources":["../../src/modules/module-decorator.ts"],"names":[],"mappings":";;AAyCA,sCAoCC;AAED,wBAsDC;AAnID,gEAA6E;AAC7E,2CAMyB;AACzB,+CAA0C;AAC1C,wFAGsD;AACtD,kGAAuF;AACvF,4CAAwC;AAyBxC,SAAgB,aAAa,CAC3B,MAAgB,EAChB,UAAyB,IAAI,GAAG,EAAE;IAElC,yDAAyD;IACzD,IAAI,O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