@tsed/di 7.0.0-beta.3 → 7.0.0-beta.4
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/constants/{index.js → constants.js} +1 -1
- package/lib/cjs/constants/constants.js.map +1 -0
- package/lib/cjs/decorators/constant.js +1 -1
- package/lib/cjs/decorators/constant.js.map +1 -1
- package/lib/cjs/decorators/controller.js.map +1 -1
- package/lib/cjs/decorators/inject.js +1 -1
- package/lib/cjs/decorators/inject.js.map +1 -1
- package/lib/cjs/decorators/injectable.js +0 -2
- package/lib/cjs/decorators/injectable.js.map +1 -1
- package/lib/cjs/decorators/intercept.js +20 -12
- package/lib/cjs/decorators/intercept.js.map +1 -1
- package/lib/cjs/decorators/module.js +4 -3
- package/lib/cjs/decorators/module.js.map +1 -1
- package/lib/cjs/decorators/opts.js +1 -1
- package/lib/cjs/decorators/opts.js.map +1 -1
- package/lib/cjs/decorators/useOpts.js +1 -1
- package/lib/cjs/decorators/useOpts.js.map +1 -1
- package/lib/cjs/decorators/value.js +1 -1
- package/lib/cjs/decorators/value.js.map +1 -1
- package/lib/cjs/domain/Container.js.map +1 -1
- package/lib/cjs/domain/DIContext.js.map +1 -1
- package/lib/cjs/domain/Provider.js.map +1 -1
- package/lib/cjs/errors/InjectionError.js.map +1 -1
- package/lib/cjs/index.js +52 -17
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/{IProvider.js → ProviderOpts.js} +1 -1
- package/lib/cjs/interfaces/ProviderOpts.js.map +1 -0
- package/lib/cjs/interfaces/RegistrySettings.js.map +1 -1
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/registries/GlobalProviders.js +4 -4
- package/lib/cjs/registries/GlobalProviders.js.map +1 -1
- package/lib/cjs/registries/ProviderRegistry.js +7 -6
- package/lib/cjs/registries/ProviderRegistry.js.map +1 -1
- package/lib/cjs/services/DIConfiguration.js.map +1 -1
- package/lib/cjs/services/InjectorService.js +45 -30
- package/lib/cjs/services/InjectorService.js.map +1 -1
- package/lib/esm/constants/{index.js → constants.js} +1 -1
- package/lib/esm/constants/constants.js.map +1 -0
- package/lib/esm/decorators/configuration.js +1 -1
- package/lib/esm/decorators/constant.js +2 -2
- package/lib/esm/decorators/constant.js.map +1 -1
- package/lib/esm/decorators/controller.js +1 -1
- package/lib/esm/decorators/controller.js.map +1 -1
- package/lib/esm/decorators/inject.js +1 -1
- package/lib/esm/decorators/inject.js.map +1 -1
- package/lib/esm/decorators/injectable.js +1 -3
- package/lib/esm/decorators/injectable.js.map +1 -1
- package/lib/esm/decorators/intercept.js +21 -13
- package/lib/esm/decorators/intercept.js.map +1 -1
- package/lib/esm/decorators/interceptor.js +2 -2
- package/lib/esm/decorators/lazyInject.js +1 -1
- package/lib/esm/decorators/module.js +4 -3
- package/lib/esm/decorators/module.js.map +1 -1
- package/lib/esm/decorators/opts.js +4 -4
- package/lib/esm/decorators/opts.js.map +1 -1
- package/lib/esm/decorators/overrideProvider.js +1 -1
- package/lib/esm/decorators/scope.js +1 -1
- package/lib/esm/decorators/service.js +1 -1
- package/lib/esm/decorators/useOpts.js +1 -1
- package/lib/esm/decorators/useOpts.js.map +1 -1
- package/lib/esm/decorators/value.js +2 -2
- package/lib/esm/decorators/value.js.map +1 -1
- package/lib/esm/domain/Container.js +2 -2
- package/lib/esm/domain/Container.js.map +1 -1
- package/lib/esm/domain/DIContext.js +2 -2
- package/lib/esm/domain/DIContext.js.map +1 -1
- package/lib/esm/domain/Provider.js +2 -2
- package/lib/esm/domain/Provider.js.map +1 -1
- package/lib/esm/errors/InjectionError.js +1 -1
- package/lib/esm/errors/InjectionError.js.map +1 -1
- package/lib/esm/index.js +52 -17
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/ProviderOpts.js +2 -0
- package/lib/esm/interfaces/ProviderOpts.js.map +1 -0
- package/lib/esm/interfaces/RegistrySettings.js.map +1 -1
- package/lib/esm/package.json +3 -0
- package/lib/esm/registries/GlobalProviders.js +2 -2
- package/lib/esm/registries/GlobalProviders.js.map +1 -1
- package/lib/esm/registries/ProviderRegistry.js +5 -4
- package/lib/esm/registries/ProviderRegistry.js.map +1 -1
- package/lib/esm/services/DIConfiguration.js.map +1 -1
- package/lib/esm/services/DILogger.js +2 -2
- package/lib/esm/services/DITest.js +4 -4
- package/lib/esm/services/InjectorService.js +27 -12
- package/lib/esm/services/InjectorService.js.map +1 -1
- package/lib/esm/utils/createContainer.js +2 -2
- package/lib/types/constants/{index.d.ts → constants.d.ts} +0 -0
- package/lib/types/decorators/controller.d.ts +2 -2
- package/lib/types/decorators/injectable.d.ts +2 -4
- package/lib/types/decorators/intercept.d.ts +2 -2
- package/lib/types/decorators/module.d.ts +3 -2
- package/lib/types/domain/Container.d.ts +3 -3
- package/lib/types/domain/DIContext.d.ts +0 -6
- package/lib/types/domain/Provider.d.ts +4 -2
- package/lib/types/errors/InjectionError.d.ts +1 -1
- package/lib/types/index.d.ts +46 -11
- package/lib/types/interfaces/{IProvider.d.ts → ProviderOpts.d.ts} +10 -4
- package/lib/types/interfaces/RegistrySettings.d.ts +1 -1
- package/lib/types/registries/GlobalProviders.d.ts +6 -4
- package/lib/types/registries/ProviderRegistry.d.ts +4 -4
- package/lib/types/services/DIConfiguration.d.ts +3 -2
- package/lib/types/services/InjectorService.d.ts +12 -3
- package/package.json +24 -9
- package/readme.md +37 -41
- package/tsconfig.compile.esm.json +1 -0
- package/lib/cjs/constants/index.js.map +0 -1
- package/lib/cjs/decorators/index.js +0 -19
- package/lib/cjs/decorators/index.js.map +0 -1
- package/lib/cjs/domain/index.js +0 -12
- package/lib/cjs/domain/index.js.map +0 -1
- package/lib/cjs/interfaces/IProvider.js.map +0 -1
- package/lib/cjs/interfaces/index.js +0 -18
- package/lib/cjs/interfaces/index.js.map +0 -1
- package/lib/cjs/utils/data/Test1.js +0 -8
- package/lib/cjs/utils/data/Test1.js.map +0 -1
- package/lib/cjs/utils/data/Test2.js +0 -8
- package/lib/cjs/utils/data/Test2.js.map +0 -1
- package/lib/esm/constants/index.js.map +0 -1
- package/lib/esm/decorators/index.js +0 -16
- package/lib/esm/decorators/index.js.map +0 -1
- package/lib/esm/domain/index.js +0 -9
- package/lib/esm/domain/index.js.map +0 -1
- package/lib/esm/interfaces/IProvider.js +0 -2
- package/lib/esm/interfaces/IProvider.js.map +0 -1
- package/lib/esm/interfaces/index.js +0 -15
- package/lib/esm/interfaces/index.js.map +0 -1
- package/lib/esm/utils/data/Test1.js +0 -4
- package/lib/esm/utils/data/Test1.js.map +0 -1
- package/lib/esm/utils/data/Test2.js +0 -4
- package/lib/esm/utils/data/Test2.js.map +0 -1
- package/lib/types/decorators/index.d.ts +0 -15
- package/lib/types/domain/index.d.ts +0 -8
- package/lib/types/interfaces/index.d.ts +0 -14
- package/lib/types/utils/data/Test1.d.ts +0 -3
- package/lib/types/utils/data/Test2.d.ts +0 -3
|
@@ -4,4 +4,4 @@ exports.DI_PARAM_OPTIONS = exports.DI_PARAMS = exports.INJECTABLE_PROP = void 0;
|
|
|
4
4
|
exports.INJECTABLE_PROP = "DI:INJECTABLE_PROP";
|
|
5
5
|
exports.DI_PARAMS = "DI:PARAMS";
|
|
6
6
|
exports.DI_PARAM_OPTIONS = "DI:PARAM:OPTIONS";
|
|
7
|
-
//# sourceMappingURL=
|
|
7
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG,oBAAoB,CAAC;AACvC,QAAA,SAAS,GAAG,WAAW,CAAC;AACxB,QAAA,gBAAgB,GAAG,kBAAkB,CAAC","sourcesContent":["export const INJECTABLE_PROP = \"DI:INJECTABLE_PROP\";\nexport const DI_PARAMS = \"DI:PARAMS\";\nexport const DI_PARAM_OPTIONS = \"DI:PARAM:OPTIONS\";\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Constant = void 0;
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
5
|
+
const constants_1 = require("../constants/constants");
|
|
6
6
|
const InjectablePropertyType_1 = require("../domain/InjectablePropertyType");
|
|
7
7
|
/**
|
|
8
8
|
* Return value from Configuration.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../../../src/decorators/constant.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,
|
|
1
|
+
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../../../src/decorators/constant.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,sDAAuD;AAEvD,6EAAwE;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,SAAgB,QAAQ,CAAC,UAAkB,EAAE,YAAkB;IAC7D,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,2BAAe,EAAE;YACxC,CAAC,WAAW,CAAC,EAAE;gBACb,WAAW,EAAE,+CAAsB,CAAC,QAAQ;gBAC5C,WAAW;gBACX,UAAU;gBACV,YAAY;aACb;SACsB,CAAC,CAAC;IAC7B,CAAC,CAAC;AACJ,CAAC;AAXD,4BAWC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {INJECTABLE_PROP} from \"../constants/constants\";\nimport type {InjectableProperties} from \"../interfaces/InjectableProperties\";\nimport {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\n\n/**\n * Return value from Configuration.\n *\n * ## Example\n *\n * ```typescript\n * import {Env} from \"@tsed/core\";\n * import {Constant, Value} from \"@tsed/di\";\n *\n * export class MyClass {\n *\n * @Constant(\"env\")\n * env: Env;\n *\n * @Value(\"swagger.path\")\n * swaggerPath: string;\n *\n * @Value(\"swagger.path\", \"defaultValue\")\n * swaggerPath: string;\n *\n * constructor() {\n * console.log(this.swaggerPath) // undefined. Not available on constructor\n * }\n *\n * $onInit() {\n * console.log(this.swaggerPath) // something\n * }\n * }\n * ```\n *\n * @param {string} expression\n * @param defaultValue\n * @returns {(targetClass: any, attributeName: string) => any}\n * @decorator\n */\nexport function Constant(expression: string, defaultValue?: any): any {\n return (target: any, propertyKey: string) => {\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType: InjectablePropertyType.CONSTANT,\n propertyKey,\n expression,\n defaultValue\n }\n } as InjectableProperties);\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../src/decorators/controller.ts"],"names":[],"mappings":";;;AAAA,qCAAoE;AACpE,yCAA4C;AAE5C,qEAAkE;AAiBlE,SAAS,UAAU,CAAC,OAAY;IAC9B,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,YAAY,MAAM,IAAI,IAAA,0BAAmB,EAAC,OAAO,CAAC,EAAE;QAC5F,OAAO;YACL,IAAI,EAAE,OAAO;SACd,CAAC;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,UAAU,CAAC,OAAqC;IAC9D,MAAM,EAAC,QAAQ,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,IAAI,EAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAE3D,OAAO,IAAA,oBAAa,EAClB,CAAC,MAAY,EAAE,EAAE;QACf,IAAA,qCAAkB,EAAC;YACjB,OAAO,EAAE,MAAM;YACf,GAAG,IAAI;SACR,CAAC,CAAC;IACL,CAAC,EACD,IAAI,IAAI,IAAA,aAAI,EAAC,IAAW,CAAC,EACzB,IAAA,iBAAQ,EAAC,GAAG,QAAQ,CAAC,CACtB,CAAC;AACJ,CAAC;AAbD,gCAaC","sourcesContent":["import {isArrayOrArrayClass, Type, useDecorators} from \"@tsed/core\";\nimport {Children, Path} from \"@tsed/schema\";\nimport {
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../../src/decorators/controller.ts"],"names":[],"mappings":";;;AAAA,qCAAoE;AACpE,yCAA4C;AAE5C,qEAAkE;AAiBlE,SAAS,UAAU,CAAC,OAAY;IAC9B,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,YAAY,MAAM,IAAI,IAAA,0BAAmB,EAAC,OAAO,CAAC,EAAE;QAC5F,OAAO;YACL,IAAI,EAAE,OAAO;SACd,CAAC;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,UAAU,CAAC,OAAqC;IAC9D,MAAM,EAAC,QAAQ,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,IAAI,EAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAE3D,OAAO,IAAA,oBAAa,EAClB,CAAC,MAAY,EAAE,EAAE;QACf,IAAA,qCAAkB,EAAC;YACjB,OAAO,EAAE,MAAM;YACf,GAAG,IAAI;SACR,CAAC,CAAC;IACL,CAAC,EACD,IAAI,IAAI,IAAA,aAAI,EAAC,IAAW,CAAC,EACzB,IAAA,iBAAQ,EAAC,GAAG,QAAQ,CAAC,CACtB,CAAC;AACJ,CAAC;AAbD,gCAaC","sourcesContent":["import {isArrayOrArrayClass, Type, useDecorators} from \"@tsed/core\";\nimport {Children, Path} from \"@tsed/schema\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {registerController} from \"../registries/ProviderRegistry\";\n\nexport type PathType = string | RegExp | (string | RegExp)[];\n\nexport interface ControllerMiddlewares {\n useBefore: any[];\n use: any[];\n useAfter: any[];\n}\n\nexport interface ControllerOptions extends Partial<ProviderOpts<any>> {\n path?: PathType;\n children?: Type<any>[];\n routerOptions?: any;\n middlewares?: Partial<ControllerMiddlewares>;\n}\n\nfunction mapOptions(options: any): ControllerOptions {\n if (typeof options === \"string\" || options instanceof RegExp || isArrayOrArrayClass(options)) {\n return {\n path: options\n };\n }\n\n return options;\n}\n\n/**\n * Declare a new controller with his Rest path. His methods annotated will be collected to build the routing list.\n * This routing listing will be built with the `express.Router` object.\n *\n * ::: tip\n * See [Controllers](/docs/controllers.md) section for more details\n * :::\n *\n * ```typescript\n * @Controller(\"/calendars\")\n * export provide CalendarCtrl {\n *\n * @Get(\"/:id\")\n * public get(\n * @Req() request: Req,\n * @Res() response: Res,\n * @Next() next: Next\n * ): void {\n *\n * }\n * }\n * ```\n *\n * @param options\n * @controller\n * @decorator\n * @classDecorator\n */\nexport function Controller(options: PathType | ControllerOptions): ClassDecorator {\n const {children = [], path, ...opts} = mapOptions(options);\n\n return useDecorators(\n (target: Type) => {\n registerController({\n provide: target,\n ...opts\n });\n },\n path && Path(path as any),\n Children(...children)\n );\n}\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Inject = exports.injectProperty = void 0;
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
5
|
+
const constants_1 = require("../constants/constants");
|
|
6
6
|
function injectProperty(target, propertyKey, options) {
|
|
7
7
|
core_1.Store.from(target).merge(constants_1.INJECTABLE_PROP, {
|
|
8
8
|
[propertyKey]: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/decorators/inject.ts"],"names":[],"mappings":";;;AAAA,qCAAiH;AACjH,
|
|
1
|
+
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/decorators/inject.ts"],"names":[],"mappings":";;;AAAA,qCAAiH;AACjH,sDAAyE;AAGzE,SAAgB,cAAc,CAAC,MAAW,EAAE,WAAmB,EAAE,OAA2C;IAC1G,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KA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,EAAE,aAAa,CAAC,CAAC;4BACvD,MAAM,CAAC,MAAM,CAAC,4BAAgB,CAAC,CAAC;yBACjC;wBAED,IAAI,IAAA,gBAAS,EAAC,IAAI,CAAC,EAAE;4BACnB,IAAI,CAAC,IAAI,CAAC,CAAC,MAAW,EAAE,EAAE;gCACxB,IAAI,GAAG,MAAM,CAAC;4BAChB,CAAC,CAAC,CAAC;yBACJ;wBAED,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBAC3B,CAAC;iBACF,CAAC,CAAC;gBACH,MAAM;YAER,KAAK,qBAAc,CAAC,MAAM;gBACxB,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,2BAAe,EAAE;oBACxC,CAAC,WAAW,CAAC,EAAE;wBACb,WAAW;wBACX,WAAW;qBACZ;iBACF,CAAC,CAAC;gBAEH,OAAO,UAAU,CAAC;YAEpB;gBACE,MAAM,IAAI,+BAAwB,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;SACjF;IACH,CAAC,CAAC;AACJ,CAAC;AArDD,wBAqDC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, isPromise, Metadata, Store, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants/constants\";\nimport type {InjectablePropertyOptions} from \"../interfaces/InjectableProperties\";\n\nexport function injectProperty(target: any, propertyKey: string, options: Partial<InjectablePropertyOptions>) {\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType: DecoratorTypes.PROP,\n propertyKey,\n ...options\n }\n });\n}\n\n/**\n * Inject a provider to another provider.\n *\n * Use this decorator to inject a custom provider on constructor parameter or property.\n *\n * ```typescript\n * @Injectable()\n * export class MyService {\n * @Inject(CONNECTION)\n * connection: CONNECTION;\n * }\n * ```\n *\n * @param symbol\n * @param onGet Use the given name method to inject\n * @returns {Function}\n * @decorator\n */\nexport function Inject(symbol?: any, onGet = (bean: any) => bean): Function {\n return (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<Function> | number): any | void => {\n const bindingType = decoratorTypeOf([target, propertyKey, descriptor]);\n\n switch (bindingType) {\n case DecoratorTypes.PARAM:\n case DecoratorTypes.PARAM_CTOR:\n if (symbol) {\n const paramTypes = Metadata.getParamTypes(target, propertyKey);\n\n paramTypes[descriptor as number] = symbol;\n Metadata.setParamTypes(target, propertyKey, paramTypes);\n }\n break;\n\n case DecoratorTypes.PROP:\n injectProperty(target, propertyKey, {\n resolver(injector, locals, {options, ...invokeOptions}) {\n locals.set(DI_PARAM_OPTIONS, {...options});\n\n let bean: any;\n\n if (!bean) {\n const useType = symbol || Metadata.getType(target, propertyKey);\n bean = injector.invoke(useType, locals, invokeOptions);\n locals.delete(DI_PARAM_OPTIONS);\n }\n\n if (isPromise(bean)) {\n bean.then((result: any) => {\n bean = result;\n });\n }\n\n return () => onGet(bean);\n }\n });\n break;\n\n case DecoratorTypes.METHOD:\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType,\n propertyKey\n }\n });\n\n return descriptor;\n\n default:\n throw new UnsupportedDecoratorType(Inject, [target, propertyKey, descriptor]);\n }\n };\n}\n"]}
|
|
@@ -6,8 +6,6 @@ const ProviderRegistry_1 = require("../registries/ProviderRegistry");
|
|
|
6
6
|
* The decorators `@Injectable()` declare a new service can be injected in other service, controller, interceptor, etc.. on there `constructor`.
|
|
7
7
|
* All classes annotated with `@Injectable()` are built one time, excepted if you change the default provider configuration.
|
|
8
8
|
*
|
|
9
|
-
* <<< @/docs/snippets/providers/getting-started-injectable.ts
|
|
10
|
-
*
|
|
11
9
|
* ::: tip
|
|
12
10
|
* `@Injectable()` use the `reflect-metadata` to collect and inject the built provided to other services.
|
|
13
11
|
* :::
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"injectable.js","sourceRoot":"","sources":["../../../src/decorators/injectable.ts"],"names":[],"mappings":";;;AACA,qEAAgE;AAEhE
|
|
1
|
+
{"version":3,"file":"injectable.js","sourceRoot":"","sources":["../../../src/decorators/injectable.ts"],"names":[],"mappings":";;;AACA,qEAAgE;AAEhE;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,UAAU,CAAC,UAAiC,EAAE;IAC5D,OAAO,CAAC,MAAW,EAAE,EAAE;QACrB,IAAA,mCAAgB,EAAC;YACf,GAAG,OAAO;YACV,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC,CAAC,EAAC,OAAO,EAAE,MAAM,EAAC,CAAC;SAC9D,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAPD,gCAOC","sourcesContent":["import type {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {registerProvider} from \"../registries/ProviderRegistry\";\n\n/**\n * The decorators `@Injectable()` declare a new service can be injected in other service, controller, interceptor, etc.. on there `constructor`.\n * All classes annotated with `@Injectable()` are built one time, excepted if you change the default provider configuration.\n *\n * ::: tip\n * `@Injectable()` use the `reflect-metadata` to collect and inject the built provided to other services.\n * :::\n *\n * ### Options\n *\n * - type (@@ProviderType@@ or `string`): Kind of provider. (Default: `ProviderType.PROVIDER`)\n * - scope (@@ProviderScope@@): Kind of provider. (Default: `ProviderScope.SINGLETON`)\n * - provide (@@TokenProvider@@): An injection token (Note: This option override default metadata generated by Typescript).\n * - deps (`Type<any>`): List of class or provider which will be injected to the constructor (Note: This options override default metadata generated by Typescript).\n *\n * @returns {Function}\n * @decorator\n */\nexport function Injectable(options: Partial<ProviderOpts> = {}): ClassDecorator {\n return (target: any) => {\n registerProvider({\n ...options,\n ...(options.provide ? {useClass: target} : {provide: target})\n });\n };\n}\n"]}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Intercept = void 0;
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
const
|
|
5
|
+
const constants_1 = require("../constants/constants");
|
|
6
|
+
const InjectablePropertyType_1 = require("../domain/InjectablePropertyType");
|
|
7
7
|
/**
|
|
8
8
|
* Attaches interceptor to method call and executes the before and after methods
|
|
9
9
|
*
|
|
@@ -12,16 +12,24 @@ const domain_1 = require("../domain");
|
|
|
12
12
|
* @decorator
|
|
13
13
|
*/
|
|
14
14
|
function Intercept(interceptor, options) {
|
|
15
|
-
return (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
return (...args) => {
|
|
16
|
+
const [target, propertyKey, descriptor] = args;
|
|
17
|
+
const type = (0, core_1.decoratorTypeOf)(args);
|
|
18
|
+
switch (type) {
|
|
19
|
+
case core_1.DecoratorTypes.CLASS:
|
|
20
|
+
(0, core_1.decorateMethodsOf)(target, Intercept(interceptor, options));
|
|
21
|
+
break;
|
|
22
|
+
case core_1.DecoratorTypes.METHOD:
|
|
23
|
+
core_1.Store.from(target).merge(constants_1.INJECTABLE_PROP, {
|
|
24
|
+
[propertyKey]: {
|
|
25
|
+
options,
|
|
26
|
+
propertyKey,
|
|
27
|
+
useType: interceptor,
|
|
28
|
+
bindingType: InjectablePropertyType_1.InjectablePropertyType.INTERCEPTOR
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return descriptor;
|
|
32
|
+
}
|
|
25
33
|
};
|
|
26
34
|
}
|
|
27
35
|
exports.Intercept = Intercept;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intercept.js","sourceRoot":"","sources":["../../../src/decorators/intercept.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"intercept.js","sourceRoot":"","sources":["../../../src/decorators/intercept.ts"],"names":[],"mappings":";;;AAAA,qCAAgH;AAChH,sDAAuD;AACvD,6EAAwE;AAIxE;;;;;;GAMG;AACH,SAAgB,SAAS,CAA+B,WAAoB,EAAE,OAAa;IACzF,OAAO,CAAC,GAAG,IAAyB,EAAE,EAAE;QACtC,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,IAAI,CAAC;QAC/C,MAAM,IAAI,GAAG,IAAA,sBAAe,EAAC,IAAI,CAAC,CAAC;QACnC,QAAQ,IAAI,EAAE;YACZ,KAAK,qBAAc,CAAC,KAAK;gBACvB,IAAA,wBAAiB,EAAC,MAAM,EAAE,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;gBAC3D,MAAM;YACR,KAAK,qBAAc,CAAC,MAAM;gBACxB,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,2BAAe,EAAE;oBACxC,CAAC,WAAW,CAAC,EAAE;wBACb,OAAO;wBACP,WAAW;wBACX,OAAO,EAAE,WAAW;wBACpB,WAAW,EAAE,+CAAsB,CAAC,WAAW;qBAChD;iBACsB,CAAC,CAAC;gBAE3B,OAAO,UAAU,CAAC;SACrB;IACH,CAAC,CAAC;AACJ,CAAC;AArBD,8BAqBC","sourcesContent":["import {decorateMethodsOf, DecoratorParameters, decoratorTypeOf, DecoratorTypes, Store, Type} from \"@tsed/core\";\nimport {INJECTABLE_PROP} from \"../constants/constants\";\nimport {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\nimport type {InterceptorMethods} from \"../interfaces/InterceptorMethods\";\nimport type {InjectableProperties} from \"../interfaces/InjectableProperties\";\n\n/**\n * Attaches interceptor to method call and executes the before and after methods\n *\n * @param interceptor\n * @param options\n * @decorator\n */\nexport function Intercept<T extends InterceptorMethods>(interceptor: Type<T>, options?: any): any {\n return (...args: DecoratorParameters) => {\n const [target, propertyKey, descriptor] = args;\n const type = decoratorTypeOf(args);\n switch (type) {\n case DecoratorTypes.CLASS:\n decorateMethodsOf(target, Intercept(interceptor, options));\n break;\n case DecoratorTypes.METHOD:\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n options,\n propertyKey,\n useType: interceptor,\n bindingType: InjectablePropertyType.INTERCEPTOR\n }\n } as InjectableProperties);\n\n return descriptor;\n }\n };\n}\n"]}
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Module = void 0;
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
|
-
const
|
|
5
|
+
const ProviderScope_1 = require("../domain/ProviderScope");
|
|
6
6
|
const configuration_1 = require("./configuration");
|
|
7
7
|
const injectable_1 = require("./injectable");
|
|
8
|
+
const ProviderType_1 = require("../domain/ProviderType");
|
|
8
9
|
/**
|
|
9
10
|
* Declare a new Ts.ED module
|
|
10
11
|
*
|
|
@@ -19,8 +20,8 @@ const injectable_1 = require("./injectable");
|
|
|
19
20
|
function Module(options = {}) {
|
|
20
21
|
const { scopes, imports, resolvers, deps, scope, ...configuration } = options;
|
|
21
22
|
return (0, core_1.useDecorators)((0, configuration_1.Configuration)(configuration), (0, injectable_1.Injectable)({
|
|
22
|
-
type:
|
|
23
|
-
scope:
|
|
23
|
+
type: ProviderType_1.ProviderType.MODULE,
|
|
24
|
+
scope: ProviderScope_1.ProviderScope.SINGLETON,
|
|
24
25
|
imports,
|
|
25
26
|
deps,
|
|
26
27
|
injectable: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../src/decorators/module.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../../src/decorators/module.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AACzC,2DAAsD;AAEtD,mDAA8C;AAC9C,6CAAwC;AACxC,yDAAoD;AA2BpD;;;;;;;;;;GAUG;AACH,SAAgB,MAAM,CAAC,UAAkC,EAAE;IACzD,MAAM,EAAC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,aAAa,EAAC,GAAG,OAAO,CAAC;IAE5E,OAAO,IAAA,oBAAa,EAClB,IAAA,6BAAa,EAAC,aAAa,CAAC,EAC5B,IAAA,uBAAU,EAAC;QACT,IAAI,EAAE,2BAAY,CAAC,MAAM;QACzB,KAAK,EAAE,6BAAa,CAAC,SAAS;QAC9B,OAAO;QACP,IAAI;QACJ,UAAU,EAAE,KAAK;QACjB,SAAS;KACV,CAAC,CACH,CAAC;AACJ,CAAC;AAdD,wBAcC","sourcesContent":["import {useDecorators} from \"@tsed/core\";\nimport {ProviderScope} from \"../domain/ProviderScope\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {Configuration} from \"./configuration\";\nimport {Injectable} from \"./injectable\";\nimport {ProviderType} from \"../domain/ProviderType\";\nimport {DIResolver} from \"../interfaces/DIResolver\";\n\nexport interface ModuleOptions extends Omit<TsED.Configuration, \"scopes\"> {\n /**\n * Provider scope\n */\n scope?: ProviderScope;\n /**\n * Providers must be initialized before building this module\n */\n imports?: TokenProvider[];\n /**\n * Explicit token must be injected in the constructor\n */\n deps?: TokenProvider[];\n /**\n * A list of resolvers to inject provider from external DI.\n */\n resolvers?: DIResolver[];\n\n /**\n * Additional properties are stored as provider configuration.\n */\n [key: string]: any;\n}\n\n/**\n * Declare a new Ts.ED module\n *\n * ## Options\n * - imports: List of Provider which must be built by injector before invoking the module\n * - resolvers: List of external DI must be used to resolve unknown provider\n * - deps: List of provider must be injected to the module constructor (explicit declaration)\n *\n * @param options\n * @decorator\n */\nexport function Module(options: Partial<ModuleOptions> = {}) {\n const {scopes, imports, resolvers, deps, scope, ...configuration} = options;\n\n return useDecorators(\n Configuration(configuration),\n Injectable({\n type: ProviderType.MODULE,\n scope: ProviderScope.SINGLETON,\n imports,\n deps,\n injectable: false,\n resolvers\n })\n );\n}\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Opts = void 0;
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
5
|
+
const constants_1 = require("../constants/constants");
|
|
6
6
|
const ProviderScope_1 = require("../domain/ProviderScope");
|
|
7
7
|
const inject_1 = require("./inject");
|
|
8
8
|
const scope_1 = require("./scope");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opts.js","sourceRoot":"","sources":["../../../src/decorators/opts.ts"],"names":[],"mappings":";;;AAAA,qCAAmC;AACnC,
|
|
1
|
+
{"version":3,"file":"opts.js","sourceRoot":"","sources":["../../../src/decorators/opts.ts"],"names":[],"mappings":";;;AAAA,qCAAmC;AACnC,sDAAwD;AACxD,2DAAsD;AACtD,qCAAgC;AAChC,mCAA8B;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,SAAgB,IAAI,CAAC,MAAW,EAAE,WAA4B,EAAE,KAAa;IAC3E,IAAA,aAAK,EAAC,6BAAa,CAAC,QAAQ,CAAC,CAAC,IAAA,cAAO,EAAC,MAAM,CAAC,CAAC,CAAC;IAC/C,IAAA,eAAM,EAAC,4BAAgB,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;AACvD,CAAC;AAHD,oBAGC","sourcesContent":["import {classOf} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS} from \"../constants/constants\";\nimport {ProviderScope} from \"../domain/ProviderScope\";\nimport {Inject} from \"./inject\";\nimport {Scope} from \"./scope\";\n\n/**\n * Get instance options. This options depending on his invocation context.\n *\n * ```typescript\n * import {Injectable, Opts, UseOpts} from \"@tsed/di\";\n *\n * @Injectable()\n * class MyConfigurableService {\n * source: string;\n * constructor(@Opts options: any = {}) {\n * console.log(\"Hello \", options.source); // log: Hello Service1 then Hello Service2\n *\n * this.source = options.source;\n * }\n * }\n *\n * @Injectable()\n * class MyService1 {\n * constructor(@UseOpts({source: 'Service1'}) service: MyConfigurableService) {\n * console.log(service.source) // log: Service1\n * }\n * }\n *\n * @Injectable()\n * class MyService2 {\n * constructor(@UseOpts({source: 'Service2'}) service: MyConfigurableService) {\n * console.log(service.source) // log: Service2\n * }\n * }\n * ```\n *\n * ::: warning\n * Using @@Opts@@ decorator on a constructor parameter change the Scope of the provider to `ProviderScope.INSTANCE`.\n * :::\n *\n * @param target\n * @param propertyKey\n * @param index\n * @decorator\n */\nexport function Opts(target: any, propertyKey: string | symbol, index: number) {\n Scope(ProviderScope.INSTANCE)(classOf(target));\n Inject(DI_PARAM_OPTIONS)(target, propertyKey, index);\n}\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UseOpts = void 0;
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
5
|
+
const constants_1 = require("../constants/constants");
|
|
6
6
|
/**
|
|
7
7
|
* Add options to invoke the Service.
|
|
8
8
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOpts.js","sourceRoot":"","sources":["../../../src/decorators/useOpts.ts"],"names":[],"mappings":";;;AAAA,qCAA4F;AAC5F,
|
|
1
|
+
{"version":3,"file":"useOpts.js","sourceRoot":"","sources":["../../../src/decorators/useOpts.ts"],"names":[],"mappings":";;;AAAA,qCAA4F;AAC5F,sDAAyE;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,SAAgB,OAAO,CAAC,OAA6B;IACnD,OAAO,CAAC,MAAc,EAAE,WAA4B,EAAE,KAAc,EAAO,EAAE;QAC3E,MAAM,WAAW,GAAG,IAAA,sBAAe,EAAC,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;QAElE,QAAQ,WAAW,EAAE;YACnB,KAAK,qBAAc,CAAC,UAAU;gBAC5B,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,4BAAgB,IAAI,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;gBAClE,MAAM;YAER,KAAK,qBAAc,CAAC,IAAI;gBACtB,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,2BAAe,EAAE;oBACxC,CAAC,WAAqB,CAAC,EAAE;wBACvB,OAAO;qBACR;iBACF,CAAC,CAAC;gBACH,MAAM;YAER;gBACE,MAAM,IAAI,+BAAwB,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;SAC7E;IACH,CAAC,CAAC;AACJ,CAAC;AArBD,0BAqBC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, Store, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants/constants\";\n\n/**\n * Add options to invoke the Service.\n *\n * ```typescript\n * import {Injectable, Opts, UseOpts} from \"@tsed/di\";\n *\n * @Injectable()\n * class MyConfigurableService {\n * source: string;\n * constructor(@Opts options: any = {}) {\n * console.log(\"Hello \", options.source); // log: Hello Service1 then Hello Service2\n *\n * this.source = options.source;\n * }\n * }\n *\n * @Injectable()\n * class MyService1 {\n * constructor(@UseOpts({source: 'Service1'}) service: MyConfigurableService) {\n * console.log(service.source) // log: Service1\n * }\n * }\n *\n * @Injectable()\n * class MyService2 {\n * constructor(@UseOpts({source: 'Service2'}) service: MyConfigurableService) {\n * console.log(service.source) // log: Service2\n * }\n * }\n * ```\n *\n * ::: warning\n * Using @@Opts@@ decorator on a constructor parameter change the Scope of the provider to `ProviderScope.INSTANCE`.\n * :::\n *\n * @returns {Function}\n * @decorator\n * @param options\n */\nexport function UseOpts(options: {[key: string]: any}): Function {\n return (target: Object, propertyKey: string | symbol, index?: number): any => {\n const bindingType = decoratorTypeOf([target, propertyKey, index]);\n\n switch (bindingType) {\n case DecoratorTypes.PARAM_CTOR:\n Store.from(target).merge(`${DI_PARAM_OPTIONS}:${index}`, options);\n break;\n\n case DecoratorTypes.PROP:\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey as string]: {\n options\n }\n });\n break;\n\n default:\n throw new UnsupportedDecoratorType(UseOpts, [target, propertyKey, index]);\n }\n };\n}\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Value = void 0;
|
|
4
4
|
const core_1 = require("@tsed/core");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
5
|
+
const constants_1 = require("../constants/constants");
|
|
6
6
|
const InjectablePropertyType_1 = require("../domain/InjectablePropertyType");
|
|
7
7
|
/**
|
|
8
8
|
* Return value from Configuration.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../../src/decorators/value.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,
|
|
1
|
+
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../../src/decorators/value.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,sDAAuD;AAEvD,6EAAwE;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,SAAgB,KAAK,CAAC,UAAe,EAAE,YAAkB;IACvD,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAE;QAC1C,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,2BAAe,EAAE;YACxC,CAAC,WAAW,CAAC,EAAE;gBACb,WAAW,EAAE,+CAAsB,CAAC,KAAK;gBACzC,WAAW;gBACX,UAAU;gBACV,YAAY;aACb;SACsB,CAAC,CAAC;IAC7B,CAAC,CAAC;AACJ,CAAC;AAXD,sBAWC","sourcesContent":["import {Store} from \"@tsed/core\";\nimport {INJECTABLE_PROP} from \"../constants/constants\";\nimport type {InjectableProperties} from \"../interfaces/InjectableProperties\";\nimport {InjectablePropertyType} from \"../domain/InjectablePropertyType\";\n\n/**\n * Return value from Configuration.\n *\n * ## Example\n *\n * ```typescript\n * import {Env} from \"@tsed/core\";\n * import {Constant, Value} from \"@tsed/di\";\n *\n * export class MyClass {\n *\n * @Constant(\"env\")\n * env: Env;\n *\n * @Value(\"swagger.path\")\n * swaggerPath: string;\n *\n * @Value(\"swagger.path\", \"defaultValue\")\n * swaggerPath: string;\n *\n * constructor() {\n * console.log(this.swaggerPath) // undefined. Not available on constructor\n * }\n *\n * $onInit() {\n * console.log(this.swaggerPath) // something\n * }\n * }\n * ```\n *\n * @param expression\n * @param defaultValue\n * @returns {(targetClass: any, attributeName: string) => any}\n * @decorator\n */\nexport function Value(expression: any, defaultValue?: any) {\n return (target: any, propertyKey: string) => {\n Store.from(target).merge(INJECTABLE_PROP, {\n [propertyKey]: {\n bindingType: InjectablePropertyType.VALUE,\n propertyKey,\n expression,\n defaultValue\n }\n } as InjectableProperties);\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Container.js","sourceRoot":"","sources":["../../../src/domain/Container.ts"],"names":[],"mappings":";;;AAGA,mEAA8D;AAC9D,yCAAoC;AAEpC,MAAa,SAAU,SAAQ,GAA4B;IACzD;;;;OAIG;IACI,GAAG,CAAC,KAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"Container.js","sourceRoot":"","sources":["../../../src/domain/Container.ts"],"names":[],"mappings":";;;AAGA,mEAA8D;AAC9D,yCAAoC;AAEpC,MAAa,SAAU,SAAQ,GAA4B;IACzD;;;;OAIG;IACI,GAAG,CAAC,KAAoB,EAAE,WAAkC,EAAE;;QACnE,MAAM,QAAQ,GAAG,CAAA,MAAA,iCAAe,CAAC,GAAG,CAAC,KAAK,CAAC,0CAAE,KAAK,EAAE,KAAI,IAAI,mBAAQ,CAAC,KAAK,CAAC,CAAC;QAE5E,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAElC,OAAO,KAAK,CA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interfaces/ProviderOpts\";\nimport type {ProviderType} from \"./ProviderType\";\nimport type {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {GlobalProviders} from \"../registries/GlobalProviders\";\nimport {Provider} from \"./Provider\";\n\nexport class Container extends Map<TokenProvider, Provider> {\n /**\n *\n * @param token\n * @param settings\n */\n public add(token: TokenProvider, settings: Partial<ProviderOpts> = {}): this {\n const provider = GlobalProviders.get(token)?.clone() || new Provider(token);\n\n Object.assign(provider, settings);\n\n return super.set(token, provider);\n }\n\n /**\n * Add a provider to the\n * @param token\n * @param settings\n */\n public addProvider(token: TokenProvider, settings: Partial<ProviderOpts> = {}): this {\n return this.add(token, settings);\n }\n\n /**\n *\n * @param token\n */\n public hasProvider(token: TokenProvider) {\n return super.has(token);\n }\n\n /**\n * Add a provider to the\n * @param token\n * @param provider\n */\n public setProvider(token: TokenProvider, provider: Provider) {\n return super.set(token, provider);\n }\n\n /**\n * The getProvider() method returns a specified element from a Map object.\n * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.\n * @param token\n */\n public getProvider<T extends Provider = Provider>(token: TokenProvider): T | undefined {\n return super.get(token) as T;\n }\n\n /**\n * Get all providers registered in the injector container.\n *\n * @param {ProviderType} type Filter the list by the given ProviderType.\n * @returns {[TokenProvider , Provider<any>][]}\n */\n public getProviders(type?: ProviderType | string): Provider[] {\n return [...this].reduce((providers, [_, provider]) => {\n if (provider.type === type || !type) {\n return [...providers, provider];\n }\n return providers;\n }, []);\n }\n\n public addProviders(container: Map<TokenProvider, Provider>) {\n container.forEach((provider) => {\n if (!this.hasProvider(provider.provide)) {\n this.setProvider(provider.provide, provider.clone());\n }\n });\n }\n}\n"]}
|
|
@@ -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;AAkBlD,MAAa,SAAU,SAAQ,GAAa;IA4C1C,YAAY,EAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,EAAmB;QACzE,KAAK,EAAE,CAAC;QAlBV;;WAEG;QACM,cAAS,GAAS,IAAI,IAAI,EAAE,CAAC;QACtC;;WAEG;QACI,cAAS,GAAG,IAAI,iCAAe,EAAO,CAAC;QAY5C,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;IACpC,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACtB,aAAa;QACb,OAAO,IAAI,CAAC,SAAS,CAAC;QACtB,aAAa;QACb,OAAO,IAAI,CAAC,MAAM,CAAC;QACnB,aAAa;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,GAAG,IAAW;;QAC1C,OAAO,MAAA,IAAI,CAAC,QAAQ,0CAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;CACF;AA5ED,8BA4EC","sourcesContent":["import type {Env} from \"@tsed/core\";\nimport {InjectorService} from \"../services/InjectorService\";\nimport {ContextLogger, ContextLoggerOptions} from \"./ContextLogger\";\nimport {LocalsContainer} from \"./LocalsContainer\";\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 public logger: ContextLogger;\n /**\n *\n */\n public 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.env;\n }\n\n async destroy() {\n await this.container.destroy();\n this.logger.destroy();\n // @ts-ignore\n delete this.container;\n // @ts-ignore\n delete this.logger;\n // @ts-ignore\n delete this.injector;\n }\n\n async emit(eventName: string, ...args: any[]) {\n return this.injector?.emit(eventName, ...args);\n }\n}\n\nexport type BaseContext = DIContext & TsED.Context;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../src/domain/Provider.ts"],"names":[],"mappings":";;;AAAA,qCAAmF;
|
|
1
|
+
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../../../src/domain/Provider.ts"],"names":[],"mappings":";;;AAAA,qCAAmF;AAGnF,mDAA8C;AAC9C,iDAA4C;AAE5C,MAAa,QAAQ;IAenB,YAAY,KAAoB,EAAE,UAA6B,EAAE;QAd1D,SAAI,GAAuB,2BAAY,CAAC,QAAQ,CAAC;QAetD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QAEtB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC/B,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,OAAO,CAAC,KAAoB;QAC9B,IAAI,KAAK,EAAE;YACT,IAAI,CAAC,QAAQ,GAAG,IAAA,uBAAgB,EAAC,KAAK,CAAC,CAAC;YACxC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,MAAM,GAAG,YAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACpD;IACH,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,IAAI,QAAQ,CAAC,KAAc;QACzB,IAAI,IAAA,cAAO,EAAC,KAAK,CAAC,EAAE;YAClB,IAAI,CAAC,SAAS,GAAG,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC;YAChC,IAAI,CAAC,MAAM,GAAG,YAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACjC;IACH,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,IAAI;QACN,O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AAA,cAAO,EAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;IAED;;;OAGG;IACI,WAAW;QAChB,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAChC,CAAC;IAED;;;OAGG;IACI,SAAS;QACd,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC9C,CAAC;IAED,QAAQ;QACN,OAAO;YACL,OAAO;YACP,IAAI,CAAC,IAAI;YACT,IAAI,CAAC,QAAQ,IAAI,IAAA,aAAM,EAAC,IAAI,CAAC,QAAQ,CAAC;YACtC,IAAI,CAAC,UAAU,IAAI,SAAS;YAC5B,IAAI,CAAC,QAAQ,IAAI,OAAO;YACxB,IAAI,CAAC,eAAe,IAAI,cAAc;SACvC;aACE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;CACF;AArJD,4BAqJC","sourcesContent":["import {classOf, getClassOrSymbol, isClass, nameOf, Store, Type} from \"@tsed/core\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {ProviderScope} from \"./ProviderScope\";\nimport {ProviderType} from \"./ProviderType\";\n\nexport class Provider<T = any> implements ProviderOpts<T> {\n public type: ProviderType | any = ProviderType.PROVIDER;\n public deps: TokenProvider[];\n public imports: any[];\n public useFactory: Function;\n public useAsyncFactory: Function;\n public useValue: any;\n public hooks?: Record<string, (instance: T, ...args: any[]) => Promise<void> | void>;\n private _useClass: Type<T>;\n private _provide: TokenProvider;\n private _store: Store;\n private _tokenStore: Store;\n\n [key: string]: any;\n\n constructor(token: TokenProvider, options: Partial<Provider> = {}) {\n this.provide = token;\n this.useClass = token;\n\n Object.assign(this, options);\n }\n\n get token() {\n return this._provide;\n }\n\n get provide(): TokenProvider {\n return this._provide;\n }\n\n set provide(value: TokenProvider) {\n if (value) {\n this._provide = getClassOrSymbol(value);\n this._tokenStore = this._store = Store.from(value);\n }\n }\n\n get useClass(): Type<T> {\n return this._useClass;\n }\n\n /**\n * Create a new store if the given value is a class. Otherwise the value is ignored.\n * @param value\n */\n set useClass(value: Type<T>) {\n if (isClass(value)) {\n this._useClass = classOf(value);\n this._store = Store.from(value);\n }\n }\n\n get className() {\n return this.name;\n }\n\n get name() {\n return nameOf(this.provide);\n }\n\n get store(): Store {\n return this._store;\n }\n\n get path() {\n return this.store.get(\"path\", \"/\");\n }\n\n set path(path: string) {\n this.store.set(\"path\", path);\n }\n\n /**\n * Get the scope of the provider.\n *\n * ::: tip Note\n * Async provider is always a SINGLETON\n * :::\n *\n * @returns {boolean}\n */\n get scope(): ProviderScope {\n if (this.isAsync()) {\n return ProviderScope.SINGLETON;\n }\n\n return this.get(\"scope\");\n }\n\n /**\n * Change the scope value of the provider.\n * @param scope\n */\n set scope(scope: ProviderScope) {\n this.store.set(\"scope\", scope);\n }\n\n get configuration(): Partial<TsED.Configuration> {\n return this.get(\"configuration\");\n }\n\n set configuration(configuration: Partial<TsED.Configuration>) {\n this.store.set(\"configuration\", configuration);\n }\n\n get children(): TokenProvider[] {\n return this.store.get(\"childrenControllers\", []);\n }\n\n get(key: string) {\n return this.store.get(key) || this._tokenStore.get(key);\n }\n\n isAsync(): boolean {\n return !!this.useAsyncFactory;\n }\n\n clone(): Provider {\n return new (classOf(this))(this._provide, this);\n }\n\n /**\n *\n * @returns {boolean}\n */\n public hasChildren(): boolean {\n return !!this.children.length;\n }\n\n /**\n *\n * @returns {boolean}\n */\n public hasParent(): boolean {\n return !!this.store.get(\"parentController\");\n }\n\n toString() {\n return [\n \"Token\",\n this.name,\n this.useClass && nameOf(this.useClass),\n this.useFactory && \"Factory\",\n this.useValue && \"Value\",\n this.useAsyncFactory && \"AsyncFactory\"\n ]\n .filter(Boolean)\n .join(\":\");\n }\n}\n"]}
|
|
@@ -1 +1 @@
|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CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAEhH,OAAO,+BAA+B,GAAG,OAAO,CAAC,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACjI,CAAC","sourcesContent":["import {getConstructorArgNames, isClass, isString, nameOf} from \"@tsed/core\";\nimport {TokenProvider} from \"../interfaces\";\nimport {colors} from \"../utils/colors\";\n\nexport class InjectionError extends Error {\n name = \"INJECTION_ERROR\";\n\n public tokens: TokenProvider[] = [];\n public origin: any;\n\n constructor(token: TokenProvider, origin?: any) {\n super(isString(origin) ? origin : \"\");\n\n this.tokens = [token];\n\n if (origin) {\n if (isString(origin)) {\n this.origin = {\n message: origin,\n stack: this.stack\n };\n } else {\n if (origin.tokens) {\n this.tokens = this.tokens.concat(origin.tokens);\n this.origin = origin.origin;\n } else {\n this.origin = origin;\n this.stack = origin.stack;\n }\n }\n }\n\n const originMessage = this.origin ? \"\\nOrigin: \" + this.origin.message : \"\";\n const tokensMessage = this.tokens.map((token) => nameOf(token)).join(\" > \");\n\n this.message = `Injection failed on ${tokensMessage}${originMessage}`;\n }\n\n static throwInjectorError(token: any, currentDependency: any, error: any) {\n if (currentDependency && isClass(token)) {\n error.message = printDependencyInjectionError(token, {...currentDependency, message: error.message});\n }\n\n throw new InjectionError(token, error);\n }\n}\n\nfunction printDependencyInjectionError(token: any, options: {token: any; index: number; deps: any[]; message: string}) {\n let erroredArg = \"\";\n\n const args = getConstructorArgNames(token)\n .map((arg, index) => {\n if (options.index === index) {\n erroredArg = arg;\n arg = colors.red(arg);\n }\n\n return `${arg}: ${nameOf(options.deps[index])}`;\n })\n .join(\", \");\n\n const signature = nameOf(token) + \"->constructor(\" + args + \")\";\n const indexOf = signature.indexOf(erroredArg) - 5;\n const drawline = (indexOf: number) => \" \".repeat(indexOf) + colors.red(\"^\" + \"‾\".repeat(erroredArg.length - 1));\n\n return \"Unable to inject dependency. \" + options.message + \"\\n\\n\" + signature + \"\\n\" + (indexOf > -1 ? drawline(indexOf) : \"\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"InjectionError.js","sourceRoot":"","sources":["../../../src/errors/InjectionError.ts"],"names":[],"mappings":";;;AAAA,qCAA6E;AAE7E,4CAAuC;AAEvC,MAAa,cAAe,SAAQ,KAAK;IAMvC,YAAY,KAAoB,EAAE,MAAY;QAC5C,KAAK,CAAC,IAAA,eAAQ,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QANxC,SAAI,GAAG,iBAAiB,CAAC;QAElB,WAAM,GAAoB,EAAE,CAAC;QAMlC,IAAI,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC;QAEtB,IAAI,MAAM,EAAE;YACV,IAAI,IAAA,eAAQ,EAAC,MAAM,CAAC,EAAE;gBACpB,IAAI,CAAC,MAAM,GAAG;oBACZ,OAAO,EAAE,MAAM;oBACf,KAAK,EAAE,IAAI,CAAC,KAAK;iBAClB,CAAC;aACH;iBAAM;gBACL,IAAI,MAAM,CAAC,MAAM,EAAE;oBACjB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;oBAChD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;iBAC7B;qBAAM;oBACL,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;oBACrB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;iBAC3B;aACF;SACF;QAED,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,MAAM,aAA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C,GAAG,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,eAAM,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAEhH,OAAO,+BAA+B,GAAG,OAAO,CAAC,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACjI,CAAC","sourcesContent":["import {getConstructorArgNames, isClass, isString, nameOf} from \"@tsed/core\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {colors} from \"../utils/colors\";\n\nexport class InjectionError extends Error {\n name = \"INJECTION_ERROR\";\n\n public tokens: TokenProvider[] = [];\n public origin: any;\n\n constructor(token: TokenProvider, origin?: any) {\n super(isString(origin) ? origin : \"\");\n\n this.tokens = [token];\n\n if (origin) {\n if (isString(origin)) {\n this.origin = {\n message: origin,\n stack: this.stack\n };\n } else {\n if (origin.tokens) {\n this.tokens = this.tokens.concat(origin.tokens);\n this.origin = origin.origin;\n } else {\n this.origin = origin;\n this.stack = origin.stack;\n }\n }\n }\n\n const originMessage = this.origin ? \"\\nOrigin: \" + this.origin.message : \"\";\n const tokensMessage = this.tokens.map((token) => nameOf(token)).join(\" > \");\n\n this.message = `Injection failed on ${tokensMessage}${originMessage}`;\n }\n\n static throwInjectorError(token: any, currentDependency: any, error: any) {\n if (currentDependency && isClass(token)) {\n error.message = printDependencyInjectionError(token, {...currentDependency, message: error.message});\n }\n\n throw new InjectionError(token, error);\n }\n}\n\nfunction printDependencyInjectionError(token: any, options: {token: any; index: number; deps: any[]; message: string}) {\n let erroredArg = \"\";\n\n const args = getConstructorArgNames(token)\n .map((arg, index) => {\n if (options.index === index) {\n erroredArg = arg;\n arg = colors.red(arg);\n }\n\n return `${arg}: ${nameOf(options.deps[index])}`;\n })\n .join(\", \");\n\n const signature = nameOf(token) + \"->constructor(\" + args + \")\";\n const indexOf = signature.indexOf(erroredArg) - 5;\n const drawline = (indexOf: number) => \" \".repeat(indexOf) + colors.red(\"^\" + \"‾\".repeat(erroredArg.length - 1));\n\n return \"Unable to inject dependency. \" + options.message + \"\\n\\n\" + signature + \"\\n\" + (indexOf > -1 ? drawline(indexOf) : \"\");\n}\n"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,21 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file Automatically generated by barrelsby.
|
|
4
|
+
*/
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
tslib_1.__exportStar(require("./constants/constants"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./decorators/configuration"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./decorators/constant"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./decorators/controller"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./decorators/inject"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./decorators/injectable"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./decorators/intercept"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./decorators/interceptor"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./decorators/lazyInject"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./decorators/module"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./decorators/opts"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./decorators/overrideProvider"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./decorators/scope"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./decorators/service"), exports);
|
|
21
|
+
tslib_1.__exportStar(require("./decorators/useOpts"), exports);
|
|
22
|
+
tslib_1.__exportStar(require("./decorators/value"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./domain/Container"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./domain/ContextLogger"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./domain/DIContext"), exports);
|
|
26
|
+
tslib_1.__exportStar(require("./domain/InjectablePropertyType"), exports);
|
|
27
|
+
tslib_1.__exportStar(require("./domain/LocalsContainer"), exports);
|
|
28
|
+
tslib_1.__exportStar(require("./domain/Provider"), exports);
|
|
29
|
+
tslib_1.__exportStar(require("./domain/ProviderScope"), exports);
|
|
30
|
+
tslib_1.__exportStar(require("./domain/ProviderType"), exports);
|
|
31
|
+
tslib_1.__exportStar(require("./errors/InjectionError"), exports);
|
|
32
|
+
tslib_1.__exportStar(require("./errors/UndefinedTokenError"), exports);
|
|
33
|
+
tslib_1.__exportStar(require("./interfaces/DIConfigurationOptions"), exports);
|
|
34
|
+
tslib_1.__exportStar(require("./interfaces/DILogger"), exports);
|
|
35
|
+
tslib_1.__exportStar(require("./interfaces/DIResolver"), exports);
|
|
36
|
+
tslib_1.__exportStar(require("./interfaces/InjectableProperties"), exports);
|
|
37
|
+
tslib_1.__exportStar(require("./interfaces/InterceptorContext"), exports);
|
|
38
|
+
tslib_1.__exportStar(require("./interfaces/InterceptorMethods"), exports);
|
|
39
|
+
tslib_1.__exportStar(require("./interfaces/InvokeOptions"), exports);
|
|
40
|
+
tslib_1.__exportStar(require("./interfaces/OnDestroy"), exports);
|
|
41
|
+
tslib_1.__exportStar(require("./interfaces/OnInit"), exports);
|
|
42
|
+
tslib_1.__exportStar(require("./interfaces/ProviderOpts"), exports);
|
|
43
|
+
tslib_1.__exportStar(require("./interfaces/RegistrySettings"), exports);
|
|
44
|
+
tslib_1.__exportStar(require("./interfaces/ResolvedInvokeOptions"), exports);
|
|
45
|
+
tslib_1.__exportStar(require("./interfaces/TokenProvider"), exports);
|
|
46
|
+
tslib_1.__exportStar(require("./registries/GlobalProviders"), exports);
|
|
47
|
+
tslib_1.__exportStar(require("./registries/ProviderRegistry"), exports);
|
|
48
|
+
tslib_1.__exportStar(require("./services/DIConfiguration"), exports);
|
|
49
|
+
tslib_1.__exportStar(require("./services/DILogger"), exports);
|
|
50
|
+
tslib_1.__exportStar(require("./services/DITest"), exports);
|
|
51
|
+
tslib_1.__exportStar(require("./services/InjectorService"), exports);
|
|
52
|
+
tslib_1.__exportStar(require("./utils/colors"), exports);
|
|
53
|
+
tslib_1.__exportStar(require("./utils/createContainer"), exports);
|
|
54
|
+
tslib_1.__exportStar(require("./utils/getConfiguration"), exports);
|
|
55
|
+
tslib_1.__exportStar(require("./utils/setLoggerLevel"), exports);
|
|
21
56
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;
|
|
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,kEAAwC;AACxC,4EAAkD;AAClD,0EAAgD;AAChD,0EAAgD;AAChD,qEAA2C;AAC3C,iEAAuC;AACvC,8DAAoC;AACpC,oEAA0C;AAC1C,wEAA8C;AAC9C,6EAAmD;AACnD,qEAA2C;AAC3C,uEAA6C;AAC7C,wEAA8C;AAC9C,qEAA2C;AAC3C,8DAAoC;AACpC,4DAAkC;AAClC,qEAA2C;AAC3C,yDAA+B;AAC/B,kEAAwC;AACxC,mEAAyC;AACzC,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/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 \"./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/setLoggerLevel\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProviderOpts.js","sourceRoot":"","sources":["../../../src/interfaces/ProviderOpts.ts"],"names":[],"mappings":"","sourcesContent":["import type {Type} from \"@tsed/core\";\nimport type {DIResolver} from \"./DIResolver\";\nimport type {ProviderScope} from \"../domain/ProviderScope\";\nimport type {ProviderType} from \"../domain/ProviderType\";\nimport type {TokenProvider} from \"./TokenProvider\";\n\nexport interface ProviderOpts<T = any> {\n /**\n * An injection token. (Typically an instance of `Type` or `InjectionToken`, but can be `any`).\n */\n provide: TokenProvider;\n /**\n * Provider type\n */\n type?: ProviderType | string;\n /**\n * Instance build by the injector\n */\n instance?: T;\n /**\n * Define dependencies to build the provider\n */\n deps?: TokenProvider[];\n /**\n * Class to instantiate for the `token`.\n */\n useClass?: Type<T>;\n /**\n * Provide a function to build the provider\n */\n useFactory?: Function;\n /**\n * Provide an async function to build the provider\n */\n useAsyncFactory?: Function;\n /**\n * Provide predefined value\n */\n useValue?: any;\n /**\n * Scope used by the injector to build the provider.\n */\n scope?: ProviderScope;\n /**\n * A list of resolvers which will be used to resolve missing Symbol/Class when injector invoke a Class. This property allow external DI usage.\n */\n resolvers?: DIResolver[];\n\n /**\n * hooks to intercept custom events\n */\n hooks?: Record<string, (instance: T, ...args: any[]) => Promise<any> | any>;\n /**\n *\n */\n [key: string]: any;\n}\n\n/**\n * @deprecated\n */\nexport interface IProvider<T = any> extends ProviderOpts<T> {}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegistrySettings.js","sourceRoot":"","sources":["../../../src/interfaces/RegistrySettings.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\nimport type {Provider} from \"../domain\";\nimport type {InjectorService} from \"../services/InjectorService\";\nimport type {ResolvedInvokeOptions} from \"./ResolvedInvokeOptions\";\n\n/**\n * @ignore\n */\nexport interface RegistrySettings {\n injectable?: boolean;\n model?: Type<Provider>;\n\n /**\n *\n * @param provider\n * @param {Map<string | Function, any>} locals\n * @param options\n */\n onInvoke?(provider: Provider, locals: Map<string | Function, any>, options: ResolvedInvokeOptions & {injector: InjectorService}): void;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"RegistrySettings.js","sourceRoot":"","sources":["../../../src/interfaces/RegistrySettings.ts"],"names":[],"mappings":"","sourcesContent":["import {Type} from \"@tsed/core\";\nimport type {Provider} from \"../domain/Provider\";\nimport type {InjectorService} from \"../services/InjectorService\";\nimport type {ResolvedInvokeOptions} from \"./ResolvedInvokeOptions\";\n\n/**\n * @ignore\n */\nexport interface RegistrySettings {\n injectable?: boolean;\n model?: Type<Provider>;\n\n /**\n *\n * @param provider\n * @param {Map<string | Function, any>} locals\n * @param options\n */\n onInvoke?(provider: Provider, locals: Map<string | Function, any>, options: ResolvedInvokeOptions & {injector: InjectorService}): void;\n}\n"]}
|
|
@@ -62,11 +62,11 @@ class GlobalProviderRegistry extends Map {
|
|
|
62
62
|
...options,
|
|
63
63
|
model
|
|
64
64
|
});
|
|
65
|
-
|
|
65
|
+
tslib_1.__classPrivateFieldGet(this, _GlobalProviderRegistry_settings, "f").set(type, options);
|
|
66
66
|
return this;
|
|
67
67
|
}
|
|
68
68
|
onInvoke(provider, locals, options) {
|
|
69
|
-
const settings =
|
|
69
|
+
const settings = tslib_1.__classPrivateFieldGet(this, _GlobalProviderRegistry_settings, "f").get(provider.type);
|
|
70
70
|
if (settings === null || settings === void 0 ? void 0 : settings.onInvoke) {
|
|
71
71
|
settings.onInvoke(provider, locals, options);
|
|
72
72
|
}
|
|
@@ -82,7 +82,7 @@ class GlobalProviderRegistry extends Map {
|
|
|
82
82
|
type = provider.type;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
return (
|
|
85
|
+
return (tslib_1.__classPrivateFieldGet(this, _GlobalProviderRegistry_settings, "f").get(type) || {
|
|
86
86
|
model: Provider_1.Provider
|
|
87
87
|
});
|
|
88
88
|
}
|
|
@@ -106,7 +106,7 @@ class GlobalProviderRegistry extends Map {
|
|
|
106
106
|
createIfNotExists(key, options) {
|
|
107
107
|
const type = options.type || ProviderType_1.ProviderType.PROVIDER;
|
|
108
108
|
if (!this.has(key)) {
|
|
109
|
-
const { model = Provider_1.Provider } =
|
|
109
|
+
const { model = Provider_1.Provider } = tslib_1.__classPrivateFieldGet(this, _GlobalProviderRegistry_settings, "f").get(type) || {};
|
|
110
110
|
const item = new model(key, options);
|
|
111
111
|
this.set(key, item);
|
|
112
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalProviders.js","sourceRoot":"","sources":["../../../src/registries/GlobalProviders.ts"],"names":[],"mappings":";;;;;AAAA,qCAAkD;AAClD,iDAA4C;AAC5C,yDAAoD;
|
|
1
|
+
{"version":3,"file":"GlobalProviders.js","sourceRoot":"","sources":["../../../src/registries/GlobalProviders.ts"],"names":[],"mappings":";;;;;AAAA,qCAAkD;AAClD,iDAA4C;AAC5C,yDAAoD;AAOpD,MAAa,sBAAuB,SAAQ,GAA4B;IAAxE;;QACE,2CAA2C,IAAI,GAAG,EAAE,EAAC;IA+HvD,CAAC;IA7HC;;;;OAIG;IACH,GAAG,CAAC,GAAkB;QACpB,OAAO,KAAK,CAAC,GAAG,CAAC,IAAA,uBAAgB,EAAC,GAAG,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAkB;QACpB,OAAO,KAAK,CAAC,GAAG,CAAC,IAA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,+BAAA,IAAI,wCAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YAE1D,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YAErC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;SACrB;QAED,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC;IACxB,CAAC;CACF;AAhID,wDAgIC;;AAED;;;GAGG;AACH,0CAA0C;AAC7B,QAAA,eAAe,GAAG,IAAI,sBAAsB,EAAE,CAAC","sourcesContent":["import {getClassOrSymbol, Type} from \"@tsed/core\";\nimport {Provider} from \"../domain/Provider\";\nimport {ProviderType} from \"../domain/ProviderType\";\nimport type {InjectorService} from \"../services/InjectorService\";\nimport {ResolvedInvokeOptions} from \"../interfaces/ResolvedInvokeOptions\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {RegistrySettings} from \"../interfaces/RegistrySettings\";\nimport {ProviderOpts} from \"../interfaces/ProviderOpts\";\n\nexport class GlobalProviderRegistry extends Map<TokenProvider, Provider> {\n #settings: Map<string, RegistrySettings> = new Map();\n\n /**\n * The get() method returns a specified element from a Map object.\n * @param key Required. The key of the element to return from the Map object.\n * @returns {T} Returns the element associated with the specified key or undefined if the key can't be found in the Map object.\n */\n get(key: TokenProvider): Provider | undefined {\n return super.get(getClassOrSymbol(key));\n }\n\n /**\n * The has() method returns a boolean indicating whether an element with the specified key exists or not.\n * @param key\n * @returns {boolean}\n */\n has(key: TokenProvider): boolean {\n return super.has(getClassOrSymbol(key));\n }\n\n /**\n * The set() method adds or updates an element with a specified key and value to a Map object.\n * @param key Required. The key of the element to add to the Map object.\n * @param metadata Required. The value of the element to add to the Map object.\n */\n set(key: TokenProvider, metadata: Provider): this {\n super.set(getClassOrSymbol(key), metadata);\n\n return this;\n }\n\n /**\n *\n * @param target\n * @param options\n */\n merge(target: TokenProvider, options: Partial<ProviderOpts>): void {\n const meta = this.createIfNotExists(target, options);\n\n Object.keys(options).forEach((key) => {\n meta[key] = (options as any)[key];\n });\n\n this.set(target, meta);\n }\n\n /**\n * The delete() method removes the specified element from a Map object.\n * @param key Required. The key of the element to remove from the Map object.\n * @returns {boolean} Returns true if an element in the Map object existed and has been removed, or false if the element does not exist.\n */\n delete(key: TokenProvider): boolean {\n return super.delete(getClassOrSymbol(key));\n }\n\n createRegistry(type: string, model: Type<Provider>, options: Partial<RegistrySettings> = {}) {\n const defaultOptions = this.getRegistrySettings(type);\n\n options = Object.assign(defaultOptions, {\n ...options,\n model\n });\n\n this.#settings.set(type, options);\n\n return this;\n }\n\n onInvoke(provider: Provider, locals: Map<TokenProvider, any>, options: ResolvedInvokeOptions & {injector: InjectorService}) {\n const settings = this.#settings.get(provider.type);\n\n if (settings?.onInvoke) {\n settings.onInvoke(provider, locals, options);\n }\n }\n\n getRegistrySettings(target: string | TokenProvider): RegistrySettings {\n let type: string = \"provider\";\n\n if (typeof target === \"string\") {\n type = target;\n } else {\n const provider = this.get(target);\n if (provider) {\n type = provider.type;\n }\n }\n\n return (\n this.#settings.get(type) || {\n model: Provider\n }\n );\n }\n\n createRegisterFn(type: string) {\n return (provider: any | ProviderOpts, instance?: any): void => {\n // istanbul ignore next\n if (!provider.provide) {\n provider = {\n provide: provider\n };\n }\n\n provider = Object.assign({instance}, provider, {type});\n this.merge(provider.provide, provider);\n };\n }\n\n /**\n *\n * @param key\n * @param options\n */\n protected createIfNotExists(key: TokenProvider, options: Partial<ProviderOpts>): Provider {\n const type = options.type || ProviderType.PROVIDER;\n\n if (!this.has(key)) {\n const {model = Provider} = this.#settings.get(type) || {};\n\n const item = new model(key, options);\n\n this.set(key, item);\n }\n\n return this.get(key)!;\n }\n}\n\n/**\n *\n * @type {GlobalProviders}\n */\n// tslint:disable-next-line: variable-name\nexport const GlobalProviders = new GlobalProviderRegistry();\n"]}
|