Skip to content

Commit

Permalink
fix(di): fix @Inject when the decorator is used to inject many providers
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Sep 6, 2023
1 parent 6d9af54 commit 9fc43c0
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 53 deletions.
3 changes: 2 additions & 1 deletion packages/di/src/common/decorators/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ export function Inject(token?: TokenProvider | (() => TokenProvider), onGet = (b
switch (bindingType) {
case DecoratorTypes.PARAM_CTOR:
if (token) {
const paramTypes = getConstructorDependencies(target);
const paramTypes = getConstructorDependencies(target, propertyKey);
const type = paramTypes[descriptor as number];

paramTypes[descriptor as number] = type === Array ? [token] : token;

Metadata.setParamTypes(target, propertyKey!, paramTypes);
setConstructorDependencies(target, paramTypes);
}
break;
Expand Down
4 changes: 2 additions & 2 deletions packages/di/src/common/utils/getConstructorDependencies.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Metadata} from "@tsed/core";

export function getConstructorDependencies(target: any) {
return [...(Metadata.get("override:ctor:design:paramtypes", target, undefined) || Metadata.getParamTypes(target) || [])];
export function getConstructorDependencies(target: any, propertyKey?: string | symbol | undefined) {
return Metadata.getOwn("override:ctor:design:paramtypes", target, propertyKey) || [...Metadata.getParamTypes(target, propertyKey)] || [];
}

export function setConstructorDependencies(target: any, deps: any[]) {
Expand Down
6 changes: 3 additions & 3 deletions packages/orm/mongoose/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ module.exports = {
},
coverageThreshold: {
global: {
statements: 98.95,
branches: 95,
statements: 99.06,
branches: 95.41,
functions: 99,
lines: 98.95
lines: 99.06
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export class PostsRepository {
return this.collection.groupBy.bind(this.collection);
}

deleteMany(args: Prisma.PostDeleteManyArgs) {
return this.collection.deleteMany(args);
protected deserialize<T>(obj: null | Post | Post[]): T {
return deserialize<T>(obj, {type: PostModel, collectionType: isArray(obj) ? Array : undefined});
}

async findUnique(args: Prisma.PostFindUniqueArgs): Promise<PostModel | null> {
Expand Down Expand Up @@ -57,8 +57,8 @@ export class PostsRepository {
return this.deserialize<PostModel>(obj);
}

protected deserialize<T>(obj: null | Post | Post[]): T {
return deserialize<T>(obj, {type: PostModel, collectionType: isArray(obj) ? Array : undefined});
deleteMany(args: Prisma.PostDeleteManyArgs) {
return this.collection.deleteMany(args);
}

updateMany(args: Prisma.PostUpdateManyArgs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export class UsersRepository {
return this.collection.groupBy.bind(this.collection);
}

deleteMany(args: Prisma.UserDeleteManyArgs) {
return this.collection.deleteMany(args);
protected deserialize<T>(obj: null | User | User[]): T {
return deserialize<T>(obj, {type: UserModel, collectionType: isArray(obj) ? Array : undefined});
}

async findUnique(args: Prisma.UserFindUniqueArgs): Promise<UserModel | null> {
Expand Down Expand Up @@ -57,8 +57,8 @@ export class UsersRepository {
return this.deserialize<UserModel>(obj);
}

protected deserialize<T>(obj: null | User | User[]): T {
return deserialize<T>(obj, {type: UserModel, collectionType: isArray(obj) ? Array : undefined});
deleteMany(args: Prisma.UserDeleteManyArgs) {
return this.collection.deleteMany(args);
}

updateMany(args: Prisma.UserUpdateManyArgs) {
Expand Down
6 changes: 3 additions & 3 deletions packages/specs/schema/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ module.exports = {
roots: ["<rootDir>/src", "<rootDir>/test"],
coverageThreshold: {
global: {
statements: 99.46,
branches: 96.23,
statements: 99.45,
branches: 96.18,
functions: 100,
lines: 99.46
lines: 99.45
}
},
moduleNameMapper: {
Expand Down
18 changes: 0 additions & 18 deletions packages/specs/schema/src/tsconfig.json

This file was deleted.

18 changes: 0 additions & 18 deletions packages/specs/schema/test/tsconfig.json

This file was deleted.

0 comments on commit 9fc43c0

Please sign in to comment.