@hazeljs/typeorm 0.2.0-beta.53 → 0.2.0-beta.54
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/README.md
CHANGED
|
@@ -85,12 +85,12 @@ export class UserEntity {
|
|
|
85
85
|
|
|
86
86
|
### 4. Create a repository
|
|
87
87
|
|
|
88
|
+
`@Repository` implies `@Injectable()` — no need to add both decorators.
|
|
89
|
+
|
|
88
90
|
```typescript
|
|
89
|
-
import { Injectable } from '@hazeljs/core';
|
|
90
91
|
import { BaseRepository, Repository, TypeOrmService } from '@hazeljs/typeorm';
|
|
91
92
|
import { UserEntity } from './user.entity';
|
|
92
93
|
|
|
93
|
-
@Injectable()
|
|
94
94
|
@Repository({ model: 'User' })
|
|
95
95
|
export class UserRepository extends BaseRepository<UserEntity> {
|
|
96
96
|
constructor(typeOrm: TypeOrmService) {
|
|
@@ -105,12 +105,14 @@ export class UserRepository extends BaseRepository<UserEntity> {
|
|
|
105
105
|
|
|
106
106
|
### 5. Use in a service
|
|
107
107
|
|
|
108
|
+
Use `@Service` for service classes — it is the correct decorator for business-logic classes in HazelJS (not `@Injectable`).
|
|
109
|
+
|
|
108
110
|
```typescript
|
|
109
|
-
import {
|
|
111
|
+
import { Service } from '@hazeljs/core';
|
|
110
112
|
import { InjectRepository } from '@hazeljs/typeorm';
|
|
111
113
|
import { UserRepository } from './user.repository';
|
|
112
114
|
|
|
113
|
-
@
|
|
115
|
+
@Service()
|
|
114
116
|
export class UserService {
|
|
115
117
|
constructor(
|
|
116
118
|
@InjectRepository()
|
|
@@ -132,9 +134,10 @@ export class UserService {
|
|
|
132
134
|
Use `TypeOrmService.dataSource` for transactions:
|
|
133
135
|
|
|
134
136
|
```typescript
|
|
137
|
+
import { Service } from '@hazeljs/core';
|
|
135
138
|
import { TypeOrmService } from '@hazeljs/typeorm';
|
|
136
139
|
|
|
137
|
-
@
|
|
140
|
+
@Service()
|
|
138
141
|
export class TransferService {
|
|
139
142
|
constructor(private readonly typeOrm: TypeOrmService) {}
|
|
140
143
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.decorator.d.ts","sourceRoot":"","sources":["../src/repository.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,kBAAkB,CAAC;AAE1B,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,GAAG,cAAc,
|
|
1
|
+
{"version":3,"file":"repository.decorator.d.ts","sourceRoot":"","sources":["../src/repository.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,kBAAkB,CAAC;AAE1B,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,GAAG,cAAc,CAW9E;AAED,wBAAgB,gBAAgB,IAAI,kBAAkB,CAyBrD"}
|
|
@@ -7,6 +7,12 @@ function Repository(options) {
|
|
|
7
7
|
return function (target) {
|
|
8
8
|
const opts = typeof options === 'string' ? { model: options } : options;
|
|
9
9
|
Reflect.defineMetadata('hazel:repository', opts, target);
|
|
10
|
+
// Implicitly mark the class as injectable — @Injectable() is not needed separately.
|
|
11
|
+
// Write metadata directly to avoid the ClassDecorator `Function` type constraint.
|
|
12
|
+
Reflect.defineMetadata('hazel:injectable', opts.scope ? { scope: opts.scope } : {}, target);
|
|
13
|
+
if (opts.scope) {
|
|
14
|
+
Reflect.defineMetadata('hazel:scope', opts.scope, target);
|
|
15
|
+
}
|
|
10
16
|
};
|
|
11
17
|
}
|
|
12
18
|
function InjectRepository() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hazeljs/typeorm",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.54",
|
|
4
4
|
"description": "TypeORM integration for HazelJS framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@hazeljs/core": ">=0.2.0-beta.0"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "c593ce33447cdc62d7bd2386cc2db47840292fcb"
|
|
53
53
|
}
|