Skip to content

Commit 7bd2e12

Browse files
author
Slava Fomin II
committed
Decorators updated to use latest TypeDI version.
Added IDEA to gitignore. Updated dependencies.
1 parent 9f51658 commit 7bd2e12

File tree

8 files changed

+90
-22
lines changed

8 files changed

+90
-22
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.idea/
12
node_modules/
23
build/

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"typeorm-typedi"
2424
],
2525
"devDependencies": {
26+
"@types/node": "^7.0.4",
2627
"chai": "^3.5.0",
2728
"del": "^2.2.2",
2829
"gulp": "^3.9.1",
@@ -33,16 +34,16 @@
3334
"gulpclass": "^0.1.1",
3435
"pg": "^6.1.0",
3536
"reflect-metadata": "^0.1.9",
37+
"sinon-chai": "^2.9.0",
3638
"ts-node": "^1.3.0",
3739
"tslint": "^3.15.1",
3840
"tslint-stylish": "^2.1.0-beta",
39-
"typedi": "^0.4.2",
41+
"typedi": "^0.5.0",
4042
"typeorm": "^0.0.11",
41-
"typescript": "^2.1.5",
42-
"@types/node": "^7.0.4"
43+
"typescript": "^2.1.5"
4344
},
4445
"peerDependencies": {
4546
"typeorm": "^0.0.11",
46-
"typedi": "^0.4.2"
47+
"typedi": "^0.5.0"
4748
}
4849
}

src/decorators/OrmConnection.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {ConnectionManager} from "typeorm";
22
import {Container} from "typedi";
3+
import {Handler} from "typedi/types/Handler";
34

45
/**
56
* Allows to inject an Connection using typedi's Container.
@@ -17,10 +18,20 @@ export function OrmConnection(connectionName: string = "default"): Function {
1718
return connectionManager.get(connectionName);
1819
};
1920

21+
let handler = <Handler> {
22+
object: target,
23+
value: getValue
24+
};
25+
2026
if (index !== undefined) {
21-
Container.registerParamHandler({ type: target as Function, index: index, getValue: getValue });
22-
} else {
23-
Container.registerPropertyHandler({ target: target as Function /* todo: looks like typedi wrong type here */, key: propertyName, getValue: getValue });
27+
handler.index = index;
28+
}
29+
30+
if (propertyName !== undefined) {
31+
handler.propertyName = propertyName;
2432
}
33+
34+
Container.registerHandler(handler);
35+
2536
};
2637
}

src/decorators/OrmCustomRepository.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ConnectionManager } from "typeorm";
22
import { Container } from "typedi";
3+
import {Handler} from "typedi/types/Handler";
34

45
/**
56
* Allows to inject a custom Repository using typedi's Container.
@@ -19,10 +20,20 @@ export function OrmCustomRepository(cls: Function, connectionName: string = "def
1920
return connection.getCustomRepository(cls as any);
2021
};
2122

23+
let handler = <Handler> {
24+
object: target,
25+
value: getValue
26+
};
27+
2228
if (index !== undefined) {
23-
Container.registerParamHandler({ type: target as Function, index: index, getValue: getValue });
24-
} else {
25-
Container.registerPropertyHandler({ target: target as Function /* todo: looks like typedi wrong type here */, key: propertyName, getValue: getValue });
29+
handler.index = index;
30+
}
31+
32+
if (propertyName !== undefined) {
33+
handler.propertyName = propertyName;
2634
}
35+
36+
Container.registerHandler(handler);
37+
2738
};
2839
}

src/decorators/OrmEntityManager.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {ConnectionManager} from "typeorm";
22
import {Container} from "typedi";
3+
import {Handler} from "typedi/types/Handler";
34

45
/**
56
* Allows to inject an EntityManager using typedi's Container.
@@ -23,10 +24,20 @@ export function OrmEntityManager(connectionName: string = "default"): Function {
2324
return entityManager;
2425
};
2526

27+
let handler = <Handler> {
28+
object: target,
29+
value: getValue
30+
};
31+
2632
if (index !== undefined) {
27-
Container.registerParamHandler({ type: target as Function, index: index, getValue: getValue });
28-
} else {
29-
Container.registerPropertyHandler({ target: target as Function /* todo: looks like typedi wrong type here */, key: propertyName, getValue: getValue });
33+
handler.index = index;
34+
}
35+
36+
if (propertyName !== undefined) {
37+
handler.propertyName = propertyName;
3038
}
39+
40+
Container.registerHandler(handler);
41+
3142
};
3243
}

src/decorators/OrmRepository.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {ConnectionManager} from "typeorm";
22
import {Container} from "typedi";
3+
import {Handler} from "typedi/types/Handler";
34

45
/**
56
* Allows to inject a Repository using typedi's Container.
@@ -19,10 +20,20 @@ export function OrmRepository(cls: Function, connectionName: string = "default")
1920
return connection.getRepository(cls as any);
2021
};
2122

23+
let handler = <Handler> {
24+
object: target,
25+
value: getValue
26+
};
27+
2228
if (index !== undefined) {
23-
Container.registerParamHandler({ type: target as Function, index: index, getValue: getValue });
24-
} else {
25-
Container.registerPropertyHandler({ target: target as Function /* todo: looks like typedi wrong type here */, key: propertyName, getValue: getValue });
29+
handler.index = index;
30+
}
31+
32+
if (propertyName !== undefined) {
33+
handler.propertyName = propertyName;
2634
}
35+
36+
Container.registerHandler(handler);
37+
2738
};
2839
}

src/decorators/OrmSpecificRepository.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {ConnectionManager} from "typeorm";
22
import {Container} from "typedi";
3+
import {Handler} from "typedi/types/Handler";
34

45
/**
56
* Allows to inject a SpecificRepository using typedi's Container.
@@ -18,10 +19,20 @@ export function OrmSpecificRepository(cls: Function, connectionName: string = "d
1819
return connection.getSpecificRepository(cls as any);
1920
};
2021

22+
let handler = <Handler> {
23+
object: target,
24+
value: getValue
25+
};
26+
2127
if (index !== undefined) {
22-
Container.registerParamHandler({ type: target as Function, index: index, getValue: getValue });
23-
} else {
24-
Container.registerPropertyHandler({ target: target as Function /* todo: looks like typedi wrong type here */, key: propertyName, getValue: getValue });
28+
handler.index = index;
29+
}
30+
31+
if (propertyName !== undefined) {
32+
handler.propertyName = propertyName;
2533
}
34+
35+
Container.registerHandler(handler);
36+
2637
};
2738
}

src/decorators/OrmTreeRepository.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {ConnectionManager} from "typeorm";
22
import {Container} from "typedi";
3+
import {Handler} from "typedi/types/Handler";
34

45
/**
56
* Allows to inject a TreeRepository using typedi's Container.
@@ -18,10 +19,20 @@ export function OrmTreeRepository(cls: Function, connectionName: string = "defau
1819
return connection.getTreeRepository(cls as any);
1920
};
2021

22+
let handler = <Handler> {
23+
object: target,
24+
value: getValue
25+
};
26+
2127
if (index !== undefined) {
22-
Container.registerParamHandler({ type: target as Function, index: index, getValue: getValue });
23-
} else {
24-
Container.registerPropertyHandler({ target: target as Function /* todo: looks like typedi wrong type here */, key: propertyName, getValue: getValue });
28+
handler.index = index;
29+
}
30+
31+
if (propertyName !== undefined) {
32+
handler.propertyName = propertyName;
2533
}
34+
35+
Container.registerHandler(handler);
36+
2637
};
2738
}

0 commit comments

Comments
 (0)