@tsed/di 7.0.0-rc.5 → 7.0.0-rc.7
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/coverage.json
CHANGED
|
@@ -53,6 +53,7 @@ function Inject(token, onGet = (bean) => bean) {
|
|
|
53
53
|
}
|
|
54
54
|
injectProperty(target, propertyKey, {
|
|
55
55
|
resolver(injector, locals, { options, ...invokeOptions }) {
|
|
56
|
+
const originalType = core_1.Metadata.getType(target, propertyKey);
|
|
56
57
|
locals.set(constants_1.DI_PARAM_OPTIONS, { ...options });
|
|
57
58
|
if (originalType === Array) {
|
|
58
59
|
let bean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/decorators/inject.ts"],"names":[],"mappings":";;;AAAA,qCAAiH;AACjH,sDAAyE;AACzE,mFAA8E;AAG9E,gEAAqD;AAErD,SAAgB,cAAc,CAAC,MAAW,EAAE,WAAmB,EAAE,OAA2C;IAC1G,YAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,2BAAe,EAAE;QACxC,CAAC,WAAW,CAAC,EAAE;YACb,WAAW,EAAE,qBAAc,CAAC,IAAI;YAChC,WAAW;YACX,GAAG,OAAO;SACX;KACF,CAAC,CAAC;AACL,CAAC;AARD,wCAQC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,MAAM,CAAC,KAA6C,EAAE,QAAQ,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI;IAC/F,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,UAAsD,EAAc,EAAE;QAC9G,MAAM,WAAW,GAAG,IAAA,sBAAe,EAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;QAEvE,QAAQ,WAAW,EAAE;YACnB,KAAK,qBAAc,CAAC,UAAU;gBAC5B,IAAI,KAAK,EAAE;oBACT,MAAM,UAAU,GAAG,eAAQ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AAU,CAAC,CAAC,CAAC;SACjF;IACH,CAAC,CAAC;AACJ,CAAC;AAtED,wBAsEC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,aAAa;IAC3B,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAc,EAAE;QACtD,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;YAClC,QAAQ;gBACN,OAAO,GAAG,EAAE,CAAC,IAAA,6BAAU,GAAE,CAAC;YAC5B,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AARD,sCAQC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, isPromise, Metadata, Store, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants/constants\";\nimport {InvalidPropertyTokenError} from \"../errors/InvalidPropertyTokenError\";\nimport type {InjectablePropertyOptions} from \"../interfaces/InjectableProperties\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {getContext} from \"../utils/asyncHookContext\";\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 token A token provider or token provider group\n * @param onGet Use the given name method to inject\n * @returns {Function}\n * @decorator\n */\nexport function Inject(token?: TokenProvider | (() => TokenProvider), 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_CTOR:\n if (token) {\n const paramTypes = Metadata.getParamTypes(target, propertyKey);\n const type = paramTypes[descriptor as number];\n\n paramTypes[descriptor as number] = type === Array ? [token] : token;\n\n Metadata.setParamTypes(target, propertyKey, paramTypes);\n }\n break;\n\n case DecoratorTypes.PROP:\n const useType = token || Metadata.getType(target, propertyKey);\n const originalType = Metadata.getType(target, propertyKey);\n\n if (useType === Object) {\n throw new InvalidPropertyTokenError(target, propertyKey);\n }\n\n injectProperty(target, propertyKey, {\n resolver(injector, locals, {options, ...invokeOptions}) {\n const originalType = Metadata.getType(target, propertyKey);\n locals.set(DI_PARAM_OPTIONS, {...options});\n\n if (originalType === Array) {\n let bean: any[] | undefined;\n\n if (!bean) {\n bean = injector.getMany(token, locals, invokeOptions);\n locals.delete(DI_PARAM_OPTIONS);\n }\n\n bean.forEach((instance: any, index) => {\n if (isPromise(bean)) {\n instance.then((result: any) => {\n bean![index] = result;\n });\n }\n });\n\n return () => onGet(bean);\n }\n\n let bean: any;\n\n if (!bean) {\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 default:\n throw new UnsupportedDecoratorType(Inject, [target, propertyKey, descriptor]);\n }\n };\n}\n\n/**\n * Inject a context like PlatformContext or any BaseContext.\n *\n * ```typescript\n * @Injectable()\n * export class MyService {\n * @InjectContext()\n * ctx?: Context;\n * }\n * ```\n *\n * @returns {Function}\n * @decorator\n */\nexport function InjectContext(): PropertyDecorator {\n return (target: any, propertyKey: string): any | void => {\n injectProperty(target, propertyKey, {\n resolver() {\n return () => getContext();\n }\n });\n };\n}\n"]}
|
|
@@ -49,6 +49,7 @@ export function Inject(token, onGet = (bean) => bean) {
|
|
|
49
49
|
}
|
|
50
50
|
injectProperty(target, propertyKey, {
|
|
51
51
|
resolver(injector, locals, { options, ...invokeOptions }) {
|
|
52
|
+
const originalType = Metadata.getType(target, propertyKey);
|
|
52
53
|
locals.set(DI_PARAM_OPTIONS, { ...options });
|
|
53
54
|
if (originalType === Array) {
|
|
54
55
|
let bean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/decorators/inject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,wBAAwB,EAAC,MAAM,YAAY,CAAC;AACjH,OAAO,EAAC,gBAAgB,EAAE,eAAe,EAAC,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAC,yBAAyB,EAAC,MAAM,qCAAqC,CAAC;AAG9E,OAAO,EAAC,UAAU,EAAC,MAAM,2BAA2B,CAAC;AAErD,MAAM,UAAU,cAAc,CAAC,MAAW,EAAE,WAAmB,EAAE,OAA2C;IAC1G,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,eAAe,EAAE;QACxC,CAAC,WAAW,CAAC,EAAE;YACb,WAAW,EAAE,cAAc,CAAC,IAAI;YAChC,WAAW;YACX,GAAG,OAAO;SACX;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,MAAM,CAAC,KAA6C,EAAE,QAAQ,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI;IAC/F,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,UAAsD,EAAc,EAAE;QAC9G,MAAM,WAAW,GAAG,eAAe,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;QAEvE,QAAQ,WAAW,EAAE;YACnB,KAAK,cAAc,CAAC,UAAU;gBAC5B,IAAI,KAAK,EAAE;oBACT,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;oBAC/D,MAAM,IAAI,GAAG,UAAU,CAAC,UAAoB,CAAC,CAAC;oBAE9C,UAAU,CAAC,UAAoB,CAAC,GAAG,IAAI,KA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CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;yBAC1B;wBAED,IAAI,IAAS,CAAC;wBAEd,IAAI,CAAC,IAAI,EAAE;4BACT,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;4BACvD,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;yBACjC;wBAED,IAAI,SAAS,CAAC,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;gBACE,MAAM,IAAI,wBAAwB,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;SACjF;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAc,EAAE;QACtD,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;YAClC,QAAQ;gBACN,OAAO,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC;YAC5B,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, isPromise, Metadata, Store, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants/constants\";\nimport {InvalidPropertyTokenError} from \"../errors/InvalidPropertyTokenError\";\nimport type {InjectablePropertyOptions} from \"../interfaces/InjectableProperties\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {getContext} from \"../utils/asyncHookContext\";\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 token A token provider or token provider group\n * @param onGet Use the given name method to inject\n * @returns {Function}\n * @decorator\n */\nexport function Inject(token?: TokenProvider | (() => TokenProvider), 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_CTOR:\n if (token) {\n const paramTypes = Metadata.getParamTypes(target, propertyKey);\n const type = paramTypes[descriptor as number];\n\n paramTypes[descriptor as number] = type === Array ? [token] : token;\n\n Metadata.setParamTypes(target, propertyKey, paramTypes);\n }\n break;\n\n case DecoratorTypes.PROP:\n const useType = token || Metadata.getType(target, propertyKey);\n const originalType = Metadata.getType(target, propertyKey);\n\n if (useType === Object) {\n throw new InvalidPropertyTokenError(target, propertyKey);\n }\n\n injectProperty(target, propertyKey, {\n resolver(injector, locals, {options, ...invokeOptions}) {\n locals.set(DI_PARAM_OPTIONS, {...options});\n\n if (originalType === Array) {\n let bean: any[] | undefined;\n\n if (!bean) {\n bean = injector.getMany(token, locals, invokeOptions);\n locals.delete(DI_PARAM_OPTIONS);\n }\n\n bean.forEach((instance: any, index) => {\n if (isPromise(bean)) {\n instance.then((result: any) => {\n bean![index] = result;\n });\n }\n });\n\n return () => onGet(bean);\n }\n\n let bean: any;\n\n if (!bean) {\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 default:\n throw new UnsupportedDecoratorType(Inject, [target, propertyKey, descriptor]);\n }\n };\n}\n\n/**\n * Inject a context like PlatformContext or any BaseContext.\n *\n * ```typescript\n * @Injectable()\n * export class MyService {\n * @InjectContext()\n * ctx?: Context;\n * }\n * ```\n *\n * @returns {Function}\n * @decorator\n */\nexport function InjectContext(): PropertyDecorator {\n return (target: any, propertyKey: string): any | void => {\n injectProperty(target, propertyKey, {\n resolver() {\n return () => getContext();\n }\n });\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/decorators/inject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,wBAAwB,EAAC,MAAM,YAAY,CAAC;AACjH,OAAO,EAAC,gBAAgB,EAAE,eAAe,EAAC,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAC,yBAAyB,EAAC,MAAM,qCAAqC,CAAC;AAG9E,OAAO,EAAC,UAAU,EAAC,MAAM,2BAA2B,CAAC;AAErD,MAAM,UAAU,cAAc,CAAC,MAAW,EAAE,WAAmB,EAAE,OAA2C;IAC1G,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,eAAe,EAAE;QACxC,CAAC,WAAW,CAAC,EAAE;YACb,WAAW,EAAE,cAAc,CAAC,IAAI;YAChC,WAAW;YACX,GAAG,OAAO;SACX;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,MAAM,CAAC,KAA6C,EAAE,QAAQ,CAAC,IAAS,EAAE,EAAE,CAAC,IAAI;IAC/F,OAAO,CAAC,MAAW,EAAE,WAAmB,EAAE,UAAsD,EAAc,EAAE;QAC9G,MAAM,WAAW,GAAG,eAAe,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;QAEvE,QAAQ,WAAW,E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CAAC","sourcesContent":["import {decoratorTypeOf, DecoratorTypes, isPromise, Metadata, Store, UnsupportedDecoratorType} from \"@tsed/core\";\nimport {DI_PARAM_OPTIONS, INJECTABLE_PROP} from \"../constants/constants\";\nimport {InvalidPropertyTokenError} from \"../errors/InvalidPropertyTokenError\";\nimport type {InjectablePropertyOptions} from \"../interfaces/InjectableProperties\";\nimport {TokenProvider} from \"../interfaces/TokenProvider\";\nimport {getContext} from \"../utils/asyncHookContext\";\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 token A token provider or token provider group\n * @param onGet Use the given name method to inject\n * @returns {Function}\n * @decorator\n */\nexport function Inject(token?: TokenProvider | (() => TokenProvider), 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_CTOR:\n if (token) {\n const paramTypes = Metadata.getParamTypes(target, propertyKey);\n const type = paramTypes[descriptor as number];\n\n paramTypes[descriptor as number] = type === Array ? [token] : token;\n\n Metadata.setParamTypes(target, propertyKey, paramTypes);\n }\n break;\n\n case DecoratorTypes.PROP:\n const useType = token || Metadata.getType(target, propertyKey);\n const originalType = Metadata.getType(target, propertyKey);\n\n if (useType === Object) {\n throw new InvalidPropertyTokenError(target, propertyKey);\n }\n\n injectProperty(target, propertyKey, {\n resolver(injector, locals, {options, ...invokeOptions}) {\n const originalType = Metadata.getType(target, propertyKey);\n locals.set(DI_PARAM_OPTIONS, {...options});\n\n if (originalType === Array) {\n let bean: any[] | undefined;\n\n if (!bean) {\n bean = injector.getMany(token, locals, invokeOptions);\n locals.delete(DI_PARAM_OPTIONS);\n }\n\n bean.forEach((instance: any, index) => {\n if (isPromise(bean)) {\n instance.then((result: any) => {\n bean![index] = result;\n });\n }\n });\n\n return () => onGet(bean);\n }\n\n let bean: any;\n\n if (!bean) {\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 default:\n throw new UnsupportedDecoratorType(Inject, [target, propertyKey, descriptor]);\n }\n };\n}\n\n/**\n * Inject a context like PlatformContext or any BaseContext.\n *\n * ```typescript\n * @Injectable()\n * export class MyService {\n * @InjectContext()\n * ctx?: Context;\n * }\n * ```\n *\n * @returns {Function}\n * @decorator\n */\nexport function InjectContext(): PropertyDecorator {\n return (target: any, propertyKey: string): any | void => {\n injectProperty(target, propertyKey, {\n resolver() {\n return () => getContext();\n }\n });\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/di",
|
|
3
|
-
"version": "7.0.0-rc.
|
|
3
|
+
"version": "7.0.0-rc.7",
|
|
4
4
|
"description": "DI module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -18,20 +18,20 @@
|
|
|
18
18
|
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
19
19
|
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
20
20
|
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\"",
|
|
21
|
-
"test": "cross-env NODE_ENV=test yarn jest --max-workers=2"
|
|
21
|
+
"test": "cross-env NODE_ENV=test yarn jest --max-workers=2 -u"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"tslib": "2.4.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@tsed/core": "7.0.0-rc.
|
|
27
|
+
"@tsed/core": "7.0.0-rc.7",
|
|
28
28
|
"@tsed/logger": ">=6.2.2",
|
|
29
|
-
"@tsed/schema": "7.0.0-rc.
|
|
29
|
+
"@tsed/schema": "7.0.0-rc.7"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@tsed/core": "^7.0.0-rc.
|
|
32
|
+
"@tsed/core": "^7.0.0-rc.7",
|
|
33
33
|
"@tsed/logger": ">=6.2.2",
|
|
34
|
-
"@tsed/schema": "^7.0.0-rc.
|
|
34
|
+
"@tsed/schema": "^7.0.0-rc.7"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"@tsed/core": {
|