@mikro-orm/nestjs 5.0.1 → 5.1.1
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.common.d.ts +3 -3
- package/mikro-orm.entities.storage.d.ts +2 -1
- package/mikro-orm.module.d.ts +2 -2
- package/mikro-orm.providers.d.ts +2 -2
- package/mikro-orm.providers.js +15 -2
- package/package.json +17 -17
- package/typings.d.ts +3 -2
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.common.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { EntityName } from '@mikro-orm/core';
|
|
2
1
|
import { Logger } from '@nestjs/common';
|
|
2
|
+
import type { EntityName } from './typings';
|
|
3
3
|
export declare const MIKRO_ORM_MODULE_OPTIONS: unique symbol;
|
|
4
4
|
export declare const CONTEXT_NAMES: string[];
|
|
5
5
|
export declare const logger: Logger;
|
|
@@ -7,5 +7,5 @@ export declare const getMikroORMToken: (name: string) => string;
|
|
|
7
7
|
export declare const InjectMikroORM: (name: string) => (target: object, key: string | symbol, index?: number | undefined) => void;
|
|
8
8
|
export declare const getEntityManagerToken: (name: string) => string;
|
|
9
9
|
export declare const InjectEntityManager: (name: string) => (target: object, key: string | symbol, index?: number | undefined) => void;
|
|
10
|
-
export declare const getRepositoryToken: <T>(entity: EntityName<T>, name?: string
|
|
11
|
-
export declare const InjectRepository: <T>(entity: EntityName<T>, name?: string
|
|
10
|
+
export declare const getRepositoryToken: <T>(entity: EntityName<T>, name?: string) => string;
|
|
11
|
+
export declare const InjectRepository: <T>(entity: EntityName<T>, name?: string) => (target: object, key: string | symbol, index?: number | undefined) => void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { AnyEntity
|
|
1
|
+
import type { AnyEntity } from '@mikro-orm/core';
|
|
2
|
+
import type { EntityName } from './typings';
|
|
2
3
|
export declare class MikroOrmEntitiesStorage {
|
|
3
4
|
private static readonly storage;
|
|
4
5
|
static addEntity(entity: EntityName<AnyEntity>, contextName?: string): void;
|
package/mikro-orm.module.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AnyEntity
|
|
1
|
+
import type { AnyEntity } from '@mikro-orm/core';
|
|
2
2
|
import type { DynamicModule } from '@nestjs/common';
|
|
3
|
-
import type { MikroOrmModuleAsyncOptions, MikroOrmModuleSyncOptions, MikroOrmMiddlewareModuleOptions, MikroOrmModuleFeatureOptions } from './typings';
|
|
3
|
+
import type { MikroOrmModuleAsyncOptions, MikroOrmModuleSyncOptions, MikroOrmMiddlewareModuleOptions, MikroOrmModuleFeatureOptions, EntityName } from './typings';
|
|
4
4
|
export declare class MikroOrmModule {
|
|
5
5
|
static forRoot(options?: MikroOrmModuleSyncOptions): DynamicModule;
|
|
6
6
|
static forRootAsync(options: MikroOrmModuleAsyncOptions): DynamicModule;
|
package/mikro-orm.providers.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AnyEntity
|
|
1
|
+
import type { AnyEntity } from '@mikro-orm/core';
|
|
2
2
|
import { EntityManager } from '@mikro-orm/core';
|
|
3
|
-
import type { MikroOrmModuleAsyncOptions } from './typings';
|
|
3
|
+
import type { MikroOrmModuleAsyncOptions, EntityName } from './typings';
|
|
4
4
|
import type { Provider, Type } from '@nestjs/common';
|
|
5
5
|
import { Scope } from '@nestjs/common';
|
|
6
6
|
export declare function createMikroOrmProvider(contextName?: string): Provider;
|
package/mikro-orm.providers.js
CHANGED
|
@@ -27,6 +27,14 @@ function createMikroOrmProvider(contextName) {
|
|
|
27
27
|
}
|
|
28
28
|
exports.createMikroOrmProvider = createMikroOrmProvider;
|
|
29
29
|
function createEntityManagerProvider(scope = common_1.Scope.DEFAULT, entityManager = core_1.EntityManager, contextName) {
|
|
30
|
+
if (!contextName && entityManager !== core_1.EntityManager) {
|
|
31
|
+
return {
|
|
32
|
+
provide: entityManager,
|
|
33
|
+
scope,
|
|
34
|
+
useFactory: (em) => em,
|
|
35
|
+
inject: [core_1.EntityManager], // depend on the EM from core package
|
|
36
|
+
};
|
|
37
|
+
}
|
|
30
38
|
return {
|
|
31
39
|
provide: contextName ? (0, mikro_orm_common_1.getEntityManagerToken)(contextName) : entityManager,
|
|
32
40
|
scope,
|
|
@@ -39,7 +47,12 @@ function createMikroOrmAsyncOptionsProvider(options) {
|
|
|
39
47
|
if (options.useFactory) {
|
|
40
48
|
return {
|
|
41
49
|
provide: mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS,
|
|
42
|
-
useFactory:
|
|
50
|
+
useFactory: (...args) => {
|
|
51
|
+
const factoryOptions = options.useFactory(...args);
|
|
52
|
+
return options.contextName
|
|
53
|
+
? { contextName: options.contextName, ...factoryOptions }
|
|
54
|
+
: factoryOptions;
|
|
55
|
+
},
|
|
43
56
|
inject: options.inject || [],
|
|
44
57
|
};
|
|
45
58
|
}
|
|
@@ -49,7 +62,7 @@ function createMikroOrmAsyncOptionsProvider(options) {
|
|
|
49
62
|
}
|
|
50
63
|
return {
|
|
51
64
|
provide: mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS,
|
|
52
|
-
useFactory: async (optionsFactory) => await optionsFactory.createMikroOrmOptions(),
|
|
65
|
+
useFactory: async (optionsFactory) => await optionsFactory.createMikroOrmOptions(options.contextName),
|
|
53
66
|
inject,
|
|
54
67
|
};
|
|
55
68
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/nestjs",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Martin Adamek",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"@mikro-orm/core": "^5.0.0",
|
|
44
44
|
"@mikro-orm/knex": "^5.0.0",
|
|
45
45
|
"@mikro-orm/mongodb": "^5.0.0",
|
|
46
|
-
"@nestjs/common": "^8.0.0",
|
|
47
|
-
"@nestjs/core": "^8.0.0"
|
|
46
|
+
"@nestjs/common": "^8.0.0 || ^9.0.0",
|
|
47
|
+
"@nestjs/core": "^8.0.0 || ^9.0.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependenciesMeta": {
|
|
50
50
|
"@mikro-orm/knex": {
|
|
@@ -55,28 +55,28 @@
|
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@mikro-orm/core": "^5.
|
|
59
|
-
"@mikro-orm/
|
|
60
|
-
"@mikro-orm/mongodb": "^5.
|
|
61
|
-
"@mikro-orm/
|
|
62
|
-
"@nestjs/common": "^
|
|
63
|
-
"@nestjs/core": "^
|
|
64
|
-
"@nestjs/platform-express": "^
|
|
65
|
-
"@nestjs/testing": "^
|
|
66
|
-
"@types/jest": "^
|
|
58
|
+
"@mikro-orm/core": "^5.2.3",
|
|
59
|
+
"@mikro-orm/knex": "^5.2.3",
|
|
60
|
+
"@mikro-orm/mongodb": "^5.2.3",
|
|
61
|
+
"@mikro-orm/sqlite": "^5.2.3",
|
|
62
|
+
"@nestjs/common": "^9.0.1",
|
|
63
|
+
"@nestjs/core": "^9.0.1",
|
|
64
|
+
"@nestjs/platform-express": "^9.0.1",
|
|
65
|
+
"@nestjs/testing": "^9.0.1",
|
|
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.33.0",
|
|
70
|
+
"@typescript-eslint/parser": "~5.33.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.
|
|
79
|
+
"typescript": "4.7.4"
|
|
80
80
|
},
|
|
81
81
|
"commitlint": {
|
|
82
82
|
"extends": [
|
package/typings.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyEntity, EntityName, IDatabaseDriver, Options } from '@mikro-orm/core';
|
|
1
|
+
import type { AnyEntity, EntityName as CoreEntityName, EntitySchema, IDatabaseDriver, Options } from '@mikro-orm/core';
|
|
2
2
|
import type { MiddlewareConsumer, ModuleMetadata, Scope, Type } from '@nestjs/common';
|
|
3
3
|
import type { AbstractHttpAdapter } from '@nestjs/core';
|
|
4
4
|
export interface NestMiddlewareConsumer extends MiddlewareConsumer {
|
|
@@ -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
|
}
|
|
@@ -37,4 +37,5 @@ export interface MikroOrmModuleAsyncOptions<D extends IDatabaseDriver = IDatabas
|
|
|
37
37
|
useFactory?: (...args: any[]) => Promise<Omit<MikroOrmModuleOptions<D>, 'contextName'>> | Omit<MikroOrmModuleOptions<D>, 'contextName'>;
|
|
38
38
|
inject?: any[];
|
|
39
39
|
}
|
|
40
|
+
export declare type EntityName<T extends AnyEntity<T>> = CoreEntityName<T> | EntitySchema<any>;
|
|
40
41
|
export {};
|