@tsed/di 6.114.18 → 6.115.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/lib/cjs/domain/DIContext.js +7 -0
- package/lib/cjs/domain/DIContext.js.map +1 -1
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/AlterRunInContext.js +3 -0
- package/lib/cjs/interfaces/AlterRunInContext.js.map +1 -0
- package/lib/esm/domain/DIContext.js +7 -0
- package/lib/esm/domain/DIContext.js.map +1 -1
- package/lib/esm/index.js +1 -0
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/AlterRunInContext.js +2 -0
- package/lib/esm/interfaces/AlterRunInContext.js.map +1 -0
- package/lib/types/domain/DIContext.d.ts +1 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/interfaces/AlterRunInContext.d.ts +4 -0
- package/package.json +5 -5
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DIContext = void 0;
|
|
4
4
|
const ContextLogger_1 = require("./ContextLogger");
|
|
5
5
|
const LocalsContainer_1 = require("./LocalsContainer");
|
|
6
|
+
const runInContext_1 = require("../utils/runInContext");
|
|
6
7
|
class DIContext extends Map {
|
|
7
8
|
/**
|
|
8
9
|
* Request id generated by @@contextMiddleware@@.
|
|
@@ -68,6 +69,12 @@ class DIContext extends Map {
|
|
|
68
69
|
async emit(eventName, ...args) {
|
|
69
70
|
return this.injector?.emit(eventName, ...args);
|
|
70
71
|
}
|
|
72
|
+
async runInContext(next) {
|
|
73
|
+
return (0, runInContext_1.runInContext)(this, async () => {
|
|
74
|
+
next = (await this.injector?.alterAsync("$alterRunInContext", next, this)) || next;
|
|
75
|
+
return next();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
71
78
|
}
|
|
72
79
|
exports.DIContext = DIContext;
|
|
73
80
|
//# sourceMappingURL=DIContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../../src/domain/DIContext.ts"],"names":[],"mappings":";;;AAEA,mDAAoE;AACpE,uDAAkD;
|
|
1
|
+
{"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../../src/domain/DIContext.ts"],"names":[],"mappings":";;;AAEA,mDAAoE;AACpE,uDAAkD;AAClD,wDAAmD;AAkBnD,MAAa,SAAU,SAAQ,GAAa;IAE1C;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACM,EAAE,CAAS;IACpB;;OAEG;IACM,SAAS,GAAS,IAAI,IAAI,EAAE,CAAC;IACtC;;OAEG;IACI,SAAS,GAAG,IAAI,iCAAe,EAAO,CAAC;IAC9C;;OAEG;IACM,MAAM,CAAgB;IAC/B;;OAEG;IACM,QAAQ,CAAkB;IAEnC,YAAY,EAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,EAAmB;QACzE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QAEb,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,6BAAa,CAAC,MAAM,EAAE;YACtC,GAAG,OAAO;YACV,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,EAAE;YACF,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAEtB,aAAa;QACb,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,GAAG,IAAW;QAC1C,OAAO,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,IAAc;QAC/B,OAAO,IAAA,2BAAY,EAAC,IAAI,EAAE,KAAK,IAAI,EAAE;YACnC,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,oBAAoB,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC;YACnF,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAhFD,8BAgFC","sourcesContent":["import type {Env} from \"@tsed/core\";\nimport {InjectorService} from \"../services/InjectorService\";\nimport {ContextLogger, ContextLoggerOptions} from \"./ContextLogger\";\nimport {LocalsContainer} from \"./LocalsContainer\";\nimport {runInContext} from \"../utils/runInContext\";\n\nexport interface ContextMethods extends Map<any, any> {\n readonly id: string;\n readonly logger: ContextLogger;\n readonly injector: InjectorService;\n readonly container: LocalsContainer;\n readonly env: Env;\n\n destroy(): any;\n}\n\nexport interface DIContextOptions extends Omit<ContextLoggerOptions, \"dateStart\"> {\n id: string;\n logger: any;\n injector?: InjectorService;\n}\n\nexport class DIContext extends Map<any, any> implements ContextMethods {\n [x: string]: any;\n /**\n * Request id generated by @@contextMiddleware@@.\n *\n * ::: tip\n * By default Ts.ED generate uuid like that `uuidv4().replace(/-/gi, \"\"))`.\n * Dash are removed to simplify tracking logs in Kibana\n * :::\n *\n * ::: tip\n * Request id can by customized by changing the server configuration.\n *\n * ```typescript\n * @Configuration({\n * logger: {\n * reqIdBuilder: createUniqId // give your own id generator function\n * }\n * })\n * class Server {\n *\n * }\n * ```\n * :::\n *\n */\n readonly id: string;\n /**\n * Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration.\n */\n readonly dateStart: Date = new Date();\n /**\n * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`\n */\n public container = new LocalsContainer<any>();\n /**\n * Logger attached to the context request.\n */\n readonly logger: ContextLogger;\n /**\n *\n */\n readonly injector: InjectorService;\n\n constructor({id, injector, logger, ignoreLog, ...options}: DIContextOptions) {\n super();\n this.id = id;\n\n injector && (this.injector = injector);\n\n this.logger = new ContextLogger(logger, {\n ...options,\n dateStart: this.dateStart,\n id,\n ignoreLog\n });\n }\n\n get env() {\n return this.injector.settings.get(\"env\");\n }\n\n async destroy() {\n await this.container.destroy();\n this.logger.destroy();\n\n // @ts-ignore\n delete this.container;\n }\n\n async emit(eventName: string, ...args: any[]) {\n return this.injector?.emit(eventName, ...args);\n }\n\n async runInContext(next: Function) {\n return runInContext(this, async () => {\n next = (await this.injector?.alterAsync(\"$alterRunInContext\", next, this)) || next;\n return next();\n });\n }\n}\n\nexport type BaseContext = DIContext & TsED.Context;\n"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -30,6 +30,7 @@ tslib_1.__exportStar(require("./domain/ProviderScope"), exports);
|
|
|
30
30
|
tslib_1.__exportStar(require("./domain/ProviderType"), exports);
|
|
31
31
|
tslib_1.__exportStar(require("./errors/InjectionError"), exports);
|
|
32
32
|
tslib_1.__exportStar(require("./errors/UndefinedTokenError"), exports);
|
|
33
|
+
tslib_1.__exportStar(require("./interfaces/AlterRunInContext"), exports);
|
|
33
34
|
tslib_1.__exportStar(require("./interfaces/DIConfigurationOptions"), exports);
|
|
34
35
|
tslib_1.__exportStar(require("./interfaces/DILogger"), exports);
|
|
35
36
|
tslib_1.__exportStar(require("./interfaces/DILoggerOptions"), exports);
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,gEAAsC;AACtC,qEAA2C;AAC3C,gEAAsC;AACtC,kEAAwC;AACxC,8DAAoC;AACpC,kEAAwC;AACxC,iEAAuC;AACvC,mEAAyC;AACzC,kEAAwC;AACxC,8DAAoC;AACpC,4DAAkC;AAClC,wEAA8C;AAC9C,6DAAmC;AACnC,+DAAqC;AACrC,+DAAqC;AACrC,6DAAmC;AACnC,6DAAmC;AACnC,iEAAuC;AACvC,6DAAmC;AACnC,0EAAgD;AAChD,mEAAyC;AACzC,4DAAkC;AAClC,iEAAuC;AACvC,gEAAsC;AACtC,kEAAwC;AACxC,uEAA6C;AAC7C,8EAAoD;AACpD,gEAAsC;AACtC,uEAA6C;AAC7C,kEAAwC;AACxC,4EAAkD;AAClD,0EAAgD;AAChD,0EAAgD;AAChD,qEAA2C;AAC3C,iEAAuC;AACvC,8DAAoC;AACpC,oEAA0C;AAC1C,wEAA8C;AAC9C,6EAAmD;AACnD,qEAA2C;AAC3C,kEAAwC;AACxC,uEAA6C;AAC7C,wEAA8C;AAC9C,qEAA2C;AAC3C,8DAAoC;AACpC,4DAAkC;AAClC,qEAA2C;AAC3C,yDAA+B;AAC/B,kEAAwC;AACxC,mEAAyC;AACzC,qEAA2C;AAC3C,+DAAqC;AACrC,yEAA+C;AAC/C,kEAAwC;AACxC,iEAAuC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./constants/constants\";\nexport * from \"./decorators/configuration\";\nexport * from \"./decorators/constant\";\nexport * from \"./decorators/controller\";\nexport * from \"./decorators/inject\";\nexport * from \"./decorators/injectable\";\nexport * from \"./decorators/intercept\";\nexport * from \"./decorators/interceptor\";\nexport * from \"./decorators/lazyInject\";\nexport * from \"./decorators/module\";\nexport * from \"./decorators/opts\";\nexport * from \"./decorators/overrideProvider\";\nexport * from \"./decorators/scope\";\nexport * from \"./decorators/service\";\nexport * from \"./decorators/useOpts\";\nexport * from \"./decorators/value\";\nexport * from \"./domain/Container\";\nexport * from \"./domain/ContextLogger\";\nexport * from \"./domain/DIContext\";\nexport * from \"./domain/InjectablePropertyType\";\nexport * from \"./domain/LocalsContainer\";\nexport * from \"./domain/Provider\";\nexport * from \"./domain/ProviderScope\";\nexport * from \"./domain/ProviderType\";\nexport * from \"./errors/InjectionError\";\nexport * from \"./errors/UndefinedTokenError\";\nexport * from \"./interfaces/DIConfigurationOptions\";\nexport * from \"./interfaces/DILogger\";\nexport * from \"./interfaces/DILoggerOptions\";\nexport * from \"./interfaces/DIResolver\";\nexport * from \"./interfaces/InjectableProperties\";\nexport * from \"./interfaces/InterceptorContext\";\nexport * from \"./interfaces/InterceptorMethods\";\nexport * from \"./interfaces/InvokeOptions\";\nexport * from \"./interfaces/OnDestroy\";\nexport * from \"./interfaces/OnInit\";\nexport * from \"./interfaces/ProviderOpts\";\nexport * from \"./interfaces/RegistrySettings\";\nexport * from \"./interfaces/ResolvedInvokeOptions\";\nexport * from \"./interfaces/TokenProvider\";\nexport * from \"./interfaces/TokenRoute\";\nexport * from \"./registries/GlobalProviders\";\nexport * from \"./registries/ProviderRegistry\";\nexport * from \"./services/DIConfiguration\";\nexport * from \"./services/DILogger\";\nexport * from \"./services/DITest\";\nexport * from \"./services/InjectorService\";\nexport * from \"./utils/colors\";\nexport * from \"./utils/createContainer\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/resolveControllers\";\nexport * from \"./utils/runInContext\";\nexport * from \"./utils/setLoggerConfiguration\";\nexport * from \"./utils/setLoggerFormat\";\nexport * from \"./utils/setLoggerLevel\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,gEAAsC;AACtC,qEAA2C;AAC3C,gEAAsC;AACtC,kEAAwC;AACxC,8DAAoC;AACpC,kEAAwC;AACxC,iEAAuC;AACvC,mEAAyC;AACzC,kEAAwC;AACxC,8DAAoC;AACpC,4DAAkC;AAClC,wEAA8C;AAC9C,6DAAmC;AACnC,+DAAqC;AACrC,+DAAqC;AACrC,6DAAmC;AACnC,6DAAmC;AACnC,iEAAuC;AACvC,6DAAmC;AACnC,0EAAgD;AAChD,mEAAyC;AACzC,4DAAkC;AAClC,iEAAuC;AACvC,gEAAsC;AACtC,kEAAwC;AACxC,uEAA6C;AAC7C,yEAA+C;AAC/C,8EAAoD;AACpD,gEAAsC;AACtC,uEAA6C;AAC7C,kEAAwC;AACxC,4EAAkD;AAClD,0EAAgD;AAChD,0EAAgD;AAChD,qEAA2C;AAC3C,iEAAuC;AACvC,8DAAoC;AACpC,oEAA0C;AAC1C,wEAA8C;AAC9C,6EAAmD;AACnD,qEAA2C;AAC3C,kEAAwC;AACxC,uEAA6C;AAC7C,wEAA8C;AAC9C,qEAA2C;AAC3C,8DAAoC;AACpC,4DAAkC;AAClC,qEAA2C;AAC3C,yDAA+B;AAC/B,kEAAwC;AACxC,mEAAyC;AACzC,qEAA2C;AAC3C,+DAAqC;AACrC,yEAA+C;AAC/C,kEAAwC;AACxC,iEAAuC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./constants/constants\";\nexport * from \"./decorators/configuration\";\nexport * from \"./decorators/constant\";\nexport * from \"./decorators/controller\";\nexport * from \"./decorators/inject\";\nexport * from \"./decorators/injectable\";\nexport * from \"./decorators/intercept\";\nexport * from \"./decorators/interceptor\";\nexport * from \"./decorators/lazyInject\";\nexport * from \"./decorators/module\";\nexport * from \"./decorators/opts\";\nexport * from \"./decorators/overrideProvider\";\nexport * from \"./decorators/scope\";\nexport * from \"./decorators/service\";\nexport * from \"./decorators/useOpts\";\nexport * from \"./decorators/value\";\nexport * from \"./domain/Container\";\nexport * from \"./domain/ContextLogger\";\nexport * from \"./domain/DIContext\";\nexport * from \"./domain/InjectablePropertyType\";\nexport * from \"./domain/LocalsContainer\";\nexport * from \"./domain/Provider\";\nexport * from \"./domain/ProviderScope\";\nexport * from \"./domain/ProviderType\";\nexport * from \"./errors/InjectionError\";\nexport * from \"./errors/UndefinedTokenError\";\nexport * from \"./interfaces/AlterRunInContext\";\nexport * from \"./interfaces/DIConfigurationOptions\";\nexport * from \"./interfaces/DILogger\";\nexport * from \"./interfaces/DILoggerOptions\";\nexport * from \"./interfaces/DIResolver\";\nexport * from \"./interfaces/InjectableProperties\";\nexport * from \"./interfaces/InterceptorContext\";\nexport * from \"./interfaces/InterceptorMethods\";\nexport * from \"./interfaces/InvokeOptions\";\nexport * from \"./interfaces/OnDestroy\";\nexport * from \"./interfaces/OnInit\";\nexport * from \"./interfaces/ProviderOpts\";\nexport * from \"./interfaces/RegistrySettings\";\nexport * from \"./interfaces/ResolvedInvokeOptions\";\nexport * from \"./interfaces/TokenProvider\";\nexport * from \"./interfaces/TokenRoute\";\nexport * from \"./registries/GlobalProviders\";\nexport * from \"./registries/ProviderRegistry\";\nexport * from \"./services/DIConfiguration\";\nexport * from \"./services/DILogger\";\nexport * from \"./services/DITest\";\nexport * from \"./services/InjectorService\";\nexport * from \"./utils/colors\";\nexport * from \"./utils/createContainer\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/resolveControllers\";\nexport * from \"./utils/runInContext\";\nexport * from \"./utils/setLoggerConfiguration\";\nexport * from \"./utils/setLoggerFormat\";\nexport * from \"./utils/setLoggerLevel\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AlterRunInContext.js","sourceRoot":"","sources":["../../../src/interfaces/AlterRunInContext.ts"],"names":[],"mappings":"","sourcesContent":["import {DIContext} from \"../domain/DIContext\";\n\nexport interface AlterRunInContext {\n $alterRunInContext(next: (...args: unknown[]) => unknown, ctx: DIContext): () => unknown | Promise<() => unknown>;\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ContextLogger } from "./ContextLogger.js";
|
|
2
2
|
import { LocalsContainer } from "./LocalsContainer.js";
|
|
3
|
+
import { runInContext } from "../utils/runInContext.js";
|
|
3
4
|
export class DIContext extends Map {
|
|
4
5
|
/**
|
|
5
6
|
* Request id generated by @@contextMiddleware@@.
|
|
@@ -65,5 +66,11 @@ export class DIContext extends Map {
|
|
|
65
66
|
async emit(eventName, ...args) {
|
|
66
67
|
return this.injector?.emit(eventName, ...args);
|
|
67
68
|
}
|
|
69
|
+
async runInContext(next) {
|
|
70
|
+
return runInContext(this, async () => {
|
|
71
|
+
next = (await this.injector?.alterAsync("$alterRunInContext", next, this)) || next;
|
|
72
|
+
return next();
|
|
73
|
+
});
|
|
74
|
+
}
|
|
68
75
|
}
|
|
69
76
|
//# sourceMappingURL=DIContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../../src/domain/DIContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"DIContext.js","sourceRoot":"","sources":["../../../src/domain/DIContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AAkBnD,MAAM,OAAO,SAAU,SAAQ,GAAa;IAE1C;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACM,EAAE,CAAS;IACpB;;OAEG;IACM,SAAS,GAAS,IAAI,IAAI,EAAE,CAAC;IACtC;;OAEG;IACI,SAAS,GAAG,IAAI,eAAe,EAAO,CAAC;IAC9C;;OAEG;IACM,MAAM,CAAgB;IAC/B;;OAEG;IACM,QAAQ,CAAkB;IAEnC,YAAY,EAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,EAAmB;QACzE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QAEb,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,CAAC;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,aAAa,CAAC,MAAM,EAAE;YACtC,GAAG,OAAO;YACV,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,EAAE;YACF,SAAS;SACV,CAAC,CAAC;IACL,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAEtB,aAAa;QACb,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,GAAG,IAAW;QAC1C,OAAO,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,IAAc;QAC/B,OAAO,YAAY,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE;YACnC,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,oBAAoB,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC;YACnF,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {Env} from \"@tsed/core\";\nimport {InjectorService} from \"../services/InjectorService\";\nimport {ContextLogger, ContextLoggerOptions} from \"./ContextLogger\";\nimport {LocalsContainer} from \"./LocalsContainer\";\nimport {runInContext} from \"../utils/runInContext\";\n\nexport interface ContextMethods extends Map<any, any> {\n readonly id: string;\n readonly logger: ContextLogger;\n readonly injector: InjectorService;\n readonly container: LocalsContainer;\n readonly env: Env;\n\n destroy(): any;\n}\n\nexport interface DIContextOptions extends Omit<ContextLoggerOptions, \"dateStart\"> {\n id: string;\n logger: any;\n injector?: InjectorService;\n}\n\nexport class DIContext extends Map<any, any> implements ContextMethods {\n [x: string]: any;\n /**\n * Request id generated by @@contextMiddleware@@.\n *\n * ::: tip\n * By default Ts.ED generate uuid like that `uuidv4().replace(/-/gi, \"\"))`.\n * Dash are removed to simplify tracking logs in Kibana\n * :::\n *\n * ::: tip\n * Request id can by customized by changing the server configuration.\n *\n * ```typescript\n * @Configuration({\n * logger: {\n * reqIdBuilder: createUniqId // give your own id generator function\n * }\n * })\n * class Server {\n *\n * }\n * ```\n * :::\n *\n */\n readonly id: string;\n /**\n * Date when request have been handled by the server. @@RequestLogger@@ use this date to log request duration.\n */\n readonly dateStart: Date = new Date();\n /**\n * The request container used by the Ts.ED DI. It contain all services annotated with `@Scope(ProviderScope.REQUEST)`\n */\n public container = new LocalsContainer<any>();\n /**\n * Logger attached to the context request.\n */\n readonly logger: ContextLogger;\n /**\n *\n */\n readonly injector: InjectorService;\n\n constructor({id, injector, logger, ignoreLog, ...options}: DIContextOptions) {\n super();\n this.id = id;\n\n injector && (this.injector = injector);\n\n this.logger = new ContextLogger(logger, {\n ...options,\n dateStart: this.dateStart,\n id,\n ignoreLog\n });\n }\n\n get env() {\n return this.injector.settings.get(\"env\");\n }\n\n async destroy() {\n await this.container.destroy();\n this.logger.destroy();\n\n // @ts-ignore\n delete this.container;\n }\n\n async emit(eventName: string, ...args: any[]) {\n return this.injector?.emit(eventName, ...args);\n }\n\n async runInContext(next: Function) {\n return runInContext(this, async () => {\n next = (await this.injector?.alterAsync(\"$alterRunInContext\", next, this)) || next;\n return next();\n });\n }\n}\n\nexport type BaseContext = DIContext & TsED.Context;\n"]}
|
package/lib/esm/index.js
CHANGED
|
@@ -27,6 +27,7 @@ export * from "./domain/ProviderScope.js";
|
|
|
27
27
|
export * from "./domain/ProviderType.js";
|
|
28
28
|
export * from "./errors/InjectionError.js";
|
|
29
29
|
export * from "./errors/UndefinedTokenError.js";
|
|
30
|
+
export * from "./interfaces/AlterRunInContext.js";
|
|
30
31
|
export * from "./interfaces/DIConfigurationOptions.js";
|
|
31
32
|
export * from "./interfaces/DILogger.js";
|
|
32
33
|
export * from "./interfaces/DILoggerOptions.js";
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mCAAmC,CAAC;AAClD,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oCAAoC,CAAC;AACnD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./constants/constants\";\nexport * from \"./decorators/configuration\";\nexport * from \"./decorators/constant\";\nexport * from \"./decorators/controller\";\nexport * from \"./decorators/inject\";\nexport * from \"./decorators/injectable\";\nexport * from \"./decorators/intercept\";\nexport * from \"./decorators/interceptor\";\nexport * from \"./decorators/lazyInject\";\nexport * from \"./decorators/module\";\nexport * from \"./decorators/opts\";\nexport * from \"./decorators/overrideProvider\";\nexport * from \"./decorators/scope\";\nexport * from \"./decorators/service\";\nexport * from \"./decorators/useOpts\";\nexport * from \"./decorators/value\";\nexport * from \"./domain/Container\";\nexport * from \"./domain/ContextLogger\";\nexport * from \"./domain/DIContext\";\nexport * from \"./domain/InjectablePropertyType\";\nexport * from \"./domain/LocalsContainer\";\nexport * from \"./domain/Provider\";\nexport * from \"./domain/ProviderScope\";\nexport * from \"./domain/ProviderType\";\nexport * from \"./errors/InjectionError\";\nexport * from \"./errors/UndefinedTokenError\";\nexport * from \"./interfaces/DIConfigurationOptions\";\nexport * from \"./interfaces/DILogger\";\nexport * from \"./interfaces/DILoggerOptions\";\nexport * from \"./interfaces/DIResolver\";\nexport * from \"./interfaces/InjectableProperties\";\nexport * from \"./interfaces/InterceptorContext\";\nexport * from \"./interfaces/InterceptorMethods\";\nexport * from \"./interfaces/InvokeOptions\";\nexport * from \"./interfaces/OnDestroy\";\nexport * from \"./interfaces/OnInit\";\nexport * from \"./interfaces/ProviderOpts\";\nexport * from \"./interfaces/RegistrySettings\";\nexport * from \"./interfaces/ResolvedInvokeOptions\";\nexport * from \"./interfaces/TokenProvider\";\nexport * from \"./interfaces/TokenRoute\";\nexport * from \"./registries/GlobalProviders\";\nexport * from \"./registries/ProviderRegistry\";\nexport * from \"./services/DIConfiguration\";\nexport * from \"./services/DILogger\";\nexport * from \"./services/DITest\";\nexport * from \"./services/InjectorService\";\nexport * from \"./utils/colors\";\nexport * from \"./utils/createContainer\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/resolveControllers\";\nexport * from \"./utils/runInContext\";\nexport * from \"./utils/setLoggerConfiguration\";\nexport * from \"./utils/setLoggerFormat\";\nexport * from \"./utils/setLoggerLevel\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mCAAmC,CAAC;AAClD,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oCAAoC,CAAC;AACnD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./constants/constants\";\nexport * from \"./decorators/configuration\";\nexport * from \"./decorators/constant\";\nexport * from \"./decorators/controller\";\nexport * from \"./decorators/inject\";\nexport * from \"./decorators/injectable\";\nexport * from \"./decorators/intercept\";\nexport * from \"./decorators/interceptor\";\nexport * from \"./decorators/lazyInject\";\nexport * from \"./decorators/module\";\nexport * from \"./decorators/opts\";\nexport * from \"./decorators/overrideProvider\";\nexport * from \"./decorators/scope\";\nexport * from \"./decorators/service\";\nexport * from \"./decorators/useOpts\";\nexport * from \"./decorators/value\";\nexport * from \"./domain/Container\";\nexport * from \"./domain/ContextLogger\";\nexport * from \"./domain/DIContext\";\nexport * from \"./domain/InjectablePropertyType\";\nexport * from \"./domain/LocalsContainer\";\nexport * from \"./domain/Provider\";\nexport * from \"./domain/ProviderScope\";\nexport * from \"./domain/ProviderType\";\nexport * from \"./errors/InjectionError\";\nexport * from \"./errors/UndefinedTokenError\";\nexport * from \"./interfaces/AlterRunInContext\";\nexport * from \"./interfaces/DIConfigurationOptions\";\nexport * from \"./interfaces/DILogger\";\nexport * from \"./interfaces/DILoggerOptions\";\nexport * from \"./interfaces/DIResolver\";\nexport * from \"./interfaces/InjectableProperties\";\nexport * from \"./interfaces/InterceptorContext\";\nexport * from \"./interfaces/InterceptorMethods\";\nexport * from \"./interfaces/InvokeOptions\";\nexport * from \"./interfaces/OnDestroy\";\nexport * from \"./interfaces/OnInit\";\nexport * from \"./interfaces/ProviderOpts\";\nexport * from \"./interfaces/RegistrySettings\";\nexport * from \"./interfaces/ResolvedInvokeOptions\";\nexport * from \"./interfaces/TokenProvider\";\nexport * from \"./interfaces/TokenRoute\";\nexport * from \"./registries/GlobalProviders\";\nexport * from \"./registries/ProviderRegistry\";\nexport * from \"./services/DIConfiguration\";\nexport * from \"./services/DILogger\";\nexport * from \"./services/DITest\";\nexport * from \"./services/InjectorService\";\nexport * from \"./utils/colors\";\nexport * from \"./utils/createContainer\";\nexport * from \"./utils/getConfiguration\";\nexport * from \"./utils/resolveControllers\";\nexport * from \"./utils/runInContext\";\nexport * from \"./utils/setLoggerConfiguration\";\nexport * from \"./utils/setLoggerFormat\";\nexport * from \"./utils/setLoggerLevel\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AlterRunInContext.js","sourceRoot":"","sources":["../../../src/interfaces/AlterRunInContext.ts"],"names":[],"mappings":"","sourcesContent":["import {DIContext} from \"../domain/DIContext\";\n\nexport interface AlterRunInContext {\n $alterRunInContext(next: (...args: unknown[]) => unknown, ctx: DIContext): () => unknown | Promise<() => unknown>;\n}\n"]}
|
|
@@ -62,5 +62,6 @@ export declare class DIContext extends Map<any, any> implements ContextMethods {
|
|
|
62
62
|
get env(): any;
|
|
63
63
|
destroy(): Promise<void>;
|
|
64
64
|
emit(eventName: string, ...args: any[]): Promise<void>;
|
|
65
|
+
runInContext(next: Function): Promise<any>;
|
|
65
66
|
}
|
|
66
67
|
export declare type BaseContext = DIContext & TsED.Context;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export * from "./domain/ProviderScope";
|
|
|
27
27
|
export * from "./domain/ProviderType";
|
|
28
28
|
export * from "./errors/InjectionError";
|
|
29
29
|
export * from "./errors/UndefinedTokenError";
|
|
30
|
+
export * from "./interfaces/AlterRunInContext";
|
|
30
31
|
export * from "./interfaces/DIConfigurationOptions";
|
|
31
32
|
export * from "./interfaces/DILogger";
|
|
32
33
|
export * from "./interfaces/DILoggerOptions";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/di",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.115.0",
|
|
4
4
|
"description": "DI module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"tslib": "2.4.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@tsed/core": "6.
|
|
27
|
+
"@tsed/core": "6.115.0",
|
|
28
28
|
"@tsed/logger": ">=6.1.4",
|
|
29
|
-
"@tsed/schema": "6.
|
|
29
|
+
"@tsed/schema": "6.115.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@tsed/core": "^6.
|
|
32
|
+
"@tsed/core": "^6.115.0",
|
|
33
33
|
"@tsed/logger": ">=6.1.4",
|
|
34
|
-
"@tsed/schema": "^6.
|
|
34
|
+
"@tsed/schema": "^6.115.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@tsed/core": {
|