@mikro-orm/nestjs 5.0.1 → 5.0.2
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 +23 -0
- package/mikro-orm.providers.js +7 -2
- package/package.json +9 -9
- package/typings.d.ts +1 -1
package/README.md
CHANGED
|
@@ -176,6 +176,29 @@ export class MyService {
|
|
|
176
176
|
}
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
+
## Serialization caveat
|
|
180
|
+
|
|
181
|
+
[NestJS built-in serialization](https://docs.nestjs.com/techniques/serialization) relies on [class-transformer](https://github.com/typestack/class-transformer). Since MikroORM wraps every single entity relation in a `Reference` or a `Collection` instance (for type-safety), this will make the built-in `ClassSerializerInterceptor` blind to any wrapped relations. In other words, if you return MikroORM entities from your HTTP or WebSocket handlers, all of their relations will NOT be serialized.
|
|
182
|
+
|
|
183
|
+
Luckily, MikroORM provides a [serialization API](https://mikro-orm.io/docs/serializing) which can be used in lieu of `ClassSerializerInterceptor`.
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
@Entity()
|
|
187
|
+
export class Book {
|
|
188
|
+
|
|
189
|
+
@Property({ hidden: true }) // --> Equivalent of class-transformer's `@Exclude`
|
|
190
|
+
hiddenField: number = Date.now();
|
|
191
|
+
|
|
192
|
+
@Property({ persist: false }) // --> Will only exist in memory (and will be serialized). Similar to class-transformer's `@Expose()`
|
|
193
|
+
count?: number;
|
|
194
|
+
|
|
195
|
+
@ManyToOne({ serializer: value => value.name, serializedName: 'authorName' }) // Equivalent of class-transformer's `@Transform()`
|
|
196
|
+
author: Author;
|
|
197
|
+
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
|
|
179
202
|
## Using `AsyncLocalStorage` for request context
|
|
180
203
|
|
|
181
204
|
> Since v5 AsyncLocalStorage is used inside RequestContext helper so this section is no longer valid.
|
package/mikro-orm.providers.js
CHANGED
|
@@ -39,7 +39,12 @@ function createMikroOrmAsyncOptionsProvider(options) {
|
|
|
39
39
|
if (options.useFactory) {
|
|
40
40
|
return {
|
|
41
41
|
provide: mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS,
|
|
42
|
-
useFactory:
|
|
42
|
+
useFactory: (...args) => {
|
|
43
|
+
const factoryOptions = options.useFactory(...args);
|
|
44
|
+
return options.contextName
|
|
45
|
+
? { contextName: options.contextName, ...factoryOptions }
|
|
46
|
+
: factoryOptions;
|
|
47
|
+
},
|
|
43
48
|
inject: options.inject || [],
|
|
44
49
|
};
|
|
45
50
|
}
|
|
@@ -49,7 +54,7 @@ function createMikroOrmAsyncOptionsProvider(options) {
|
|
|
49
54
|
}
|
|
50
55
|
return {
|
|
51
56
|
provide: mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS,
|
|
52
|
-
useFactory: async (optionsFactory) => await optionsFactory.createMikroOrmOptions(),
|
|
57
|
+
useFactory: async (optionsFactory) => await optionsFactory.createMikroOrmOptions(options.contextName),
|
|
53
58
|
inject,
|
|
54
59
|
};
|
|
55
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/nestjs",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Martin Adamek",
|
|
@@ -56,27 +56,27 @@
|
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@mikro-orm/core": "^5.0.3",
|
|
59
|
-
"@mikro-orm/sqlite": "^5.0.3",
|
|
60
|
-
"@mikro-orm/mongodb": "^5.0.3",
|
|
61
59
|
"@mikro-orm/knex": "^5.0.3",
|
|
60
|
+
"@mikro-orm/mongodb": "^5.0.3",
|
|
61
|
+
"@mikro-orm/sqlite": "^5.0.3",
|
|
62
62
|
"@nestjs/common": "^8.2.6",
|
|
63
63
|
"@nestjs/core": "^8.2.6",
|
|
64
64
|
"@nestjs/platform-express": "^8.2.6",
|
|
65
65
|
"@nestjs/testing": "^8.2.6",
|
|
66
|
-
"@types/jest": "^
|
|
66
|
+
"@types/jest": "^28.0.0",
|
|
67
67
|
"@types/node": "^17.0.17",
|
|
68
68
|
"@types/supertest": "^2.0.11",
|
|
69
|
-
"@typescript-eslint/eslint-plugin": "~5.
|
|
70
|
-
"@typescript-eslint/parser": "~5.
|
|
69
|
+
"@typescript-eslint/eslint-plugin": "~5.26.0",
|
|
70
|
+
"@typescript-eslint/parser": "~5.26.0",
|
|
71
71
|
"conventional-changelog": "^3.1.25",
|
|
72
72
|
"conventional-changelog-cli": "^2.2.2",
|
|
73
73
|
"eslint": "^8.9.0",
|
|
74
|
-
"jest": "^
|
|
74
|
+
"jest": "^28.0.0",
|
|
75
75
|
"rxjs": "^7.5.4",
|
|
76
76
|
"supertest": "^6.2.2",
|
|
77
|
-
"ts-jest": "^
|
|
77
|
+
"ts-jest": "^28.0.0",
|
|
78
78
|
"ts-node": "^10.5.0",
|
|
79
|
-
"typescript": "4.6.
|
|
79
|
+
"typescript": "4.6.4"
|
|
80
80
|
},
|
|
81
81
|
"commitlint": {
|
|
82
82
|
"extends": [
|
package/typings.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export interface MikroOrmModuleFeatureOptions {
|
|
|
26
26
|
contextName?: string;
|
|
27
27
|
}
|
|
28
28
|
export interface MikroOrmOptionsFactory<D extends IDatabaseDriver = IDatabaseDriver> {
|
|
29
|
-
createMikroOrmOptions(): Promise<MikroOrmModuleOptions<D>> | MikroOrmModuleOptions<D>;
|
|
29
|
+
createMikroOrmOptions(contextName?: string): Promise<MikroOrmModuleOptions<D>> | MikroOrmModuleOptions<D>;
|
|
30
30
|
}
|
|
31
31
|
export interface MikroOrmModuleSyncOptions extends MikroOrmModuleOptions, MikroOrmNestScopeOptions {
|
|
32
32
|
}
|