@mikro-orm/nestjs 5.1.4 → 5.1.6
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/mikro-orm-core.module.d.ts +5 -0
- package/mikro-orm-core.module.js +32 -16
- package/mikro-orm.providers.js +0 -1
- package/package.json +5 -5
- package/typings.d.ts +1 -1
|
@@ -8,6 +8,11 @@ export declare class MikroOrmCoreModule implements OnApplicationShutdown {
|
|
|
8
8
|
constructor(options: MikroOrmModuleOptions, moduleRef: ModuleRef);
|
|
9
9
|
static forRoot(options?: MikroOrmModuleSyncOptions): Promise<DynamicModule>;
|
|
10
10
|
static forRootAsync(options: MikroOrmModuleAsyncOptions): Promise<DynamicModule>;
|
|
11
|
+
/**
|
|
12
|
+
* Tries to create the driver instance to use the actual entity manager implementation for DI symbol.
|
|
13
|
+
* This helps with dependency resolution issues when importing the EM from driver package (e.g. `SqlEntityManager`).
|
|
14
|
+
*/
|
|
15
|
+
private static createEntityManager;
|
|
11
16
|
onApplicationShutdown(): Promise<void>;
|
|
12
17
|
configure(consumer: MiddlewareConsumer): void;
|
|
13
18
|
private static setContextName;
|
package/mikro-orm-core.module.js
CHANGED
|
@@ -59,40 +59,34 @@ let MikroOrmCoreModule = MikroOrmCoreModule_1 = class MikroOrmCoreModule {
|
|
|
59
59
|
this.moduleRef = moduleRef;
|
|
60
60
|
}
|
|
61
61
|
static async forRoot(options) {
|
|
62
|
-
const config = (!options || Object.keys(options).length === 0)
|
|
63
|
-
? await core_1.ConfigurationLoader.getConfiguration()
|
|
64
|
-
: new core_1.Configuration(options);
|
|
65
|
-
const em = config.getDriver().createEntityManager();
|
|
66
62
|
const contextName = this.setContextName(options?.contextName);
|
|
67
63
|
const knex = await tryRequire('@mikro-orm/knex');
|
|
68
64
|
const mongo = await tryRequire('@mikro-orm/mongodb');
|
|
65
|
+
const em = await this.createEntityManager(options);
|
|
69
66
|
return {
|
|
70
67
|
module: MikroOrmCoreModule_1,
|
|
71
68
|
providers: [
|
|
72
69
|
{ provide: mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS, useValue: options || {} },
|
|
73
70
|
(0, mikro_orm_providers_1.createMikroOrmProvider)(contextName),
|
|
74
71
|
(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, core_1.EntityManager, contextName),
|
|
75
|
-
(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, em.constructor, contextName),
|
|
72
|
+
...(em ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, em.constructor, contextName)] : []),
|
|
76
73
|
...(knex ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, knex.EntityManager, contextName)] : []),
|
|
77
74
|
...(mongo ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, mongo.EntityManager, contextName)] : []),
|
|
78
75
|
],
|
|
79
76
|
exports: [
|
|
80
77
|
contextName ? (0, mikro_orm_common_1.getMikroORMToken)(contextName) : core_1.MikroORM,
|
|
81
78
|
contextName ? (0, mikro_orm_common_1.getEntityManagerToken)(contextName) : core_1.EntityManager,
|
|
82
|
-
...(contextName ? [] : [
|
|
83
|
-
...(knex
|
|
84
|
-
...(mongo
|
|
79
|
+
...(em && !contextName ? [em.constructor] : []),
|
|
80
|
+
...(knex && !contextName ? [knex.EntityManager] : []),
|
|
81
|
+
...(mongo && !contextName ? [mongo.EntityManager] : []),
|
|
85
82
|
],
|
|
86
83
|
};
|
|
87
84
|
}
|
|
88
85
|
static async forRootAsync(options) {
|
|
89
|
-
const config = (!options || Object.keys(options).length === 0)
|
|
90
|
-
? await core_1.ConfigurationLoader.getConfiguration()
|
|
91
|
-
: new core_1.Configuration(options);
|
|
92
|
-
const em = config.getDriver().createEntityManager();
|
|
93
86
|
const contextName = this.setContextName(options?.contextName);
|
|
94
87
|
const knex = await tryRequire('@mikro-orm/knex');
|
|
95
88
|
const mongo = await tryRequire('@mikro-orm/mongodb');
|
|
89
|
+
const em = await this.createEntityManager(options);
|
|
96
90
|
return {
|
|
97
91
|
module: MikroOrmCoreModule_1,
|
|
98
92
|
imports: options.imports || [],
|
|
@@ -101,19 +95,41 @@ let MikroOrmCoreModule = MikroOrmCoreModule_1 = class MikroOrmCoreModule {
|
|
|
101
95
|
...(0, mikro_orm_providers_1.createAsyncProviders)({ ...options, contextName: options.contextName }),
|
|
102
96
|
(0, mikro_orm_providers_1.createMikroOrmProvider)(contextName),
|
|
103
97
|
(0, mikro_orm_providers_1.createEntityManagerProvider)(options.scope, core_1.EntityManager, contextName),
|
|
104
|
-
(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, em.constructor, contextName),
|
|
98
|
+
...(em ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, em.constructor, contextName)] : []),
|
|
105
99
|
...(knex ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, knex.EntityManager, contextName)] : []),
|
|
106
100
|
...(mongo ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, mongo.EntityManager, contextName)] : []),
|
|
107
101
|
],
|
|
108
102
|
exports: [
|
|
109
103
|
contextName ? (0, mikro_orm_common_1.getMikroORMToken)(contextName) : core_1.MikroORM,
|
|
110
104
|
contextName ? (0, mikro_orm_common_1.getEntityManagerToken)(contextName) : core_1.EntityManager,
|
|
111
|
-
...(contextName ? [] : [
|
|
112
|
-
...(knex
|
|
113
|
-
...(mongo
|
|
105
|
+
...(em && !contextName ? [em.constructor] : []),
|
|
106
|
+
...(knex && !contextName ? [knex.EntityManager] : []),
|
|
107
|
+
...(mongo && !contextName ? [mongo.EntityManager] : []),
|
|
114
108
|
],
|
|
115
109
|
};
|
|
116
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Tries to create the driver instance to use the actual entity manager implementation for DI symbol.
|
|
113
|
+
* This helps with dependency resolution issues when importing the EM from driver package (e.g. `SqlEntityManager`).
|
|
114
|
+
*/
|
|
115
|
+
static async createEntityManager(options) {
|
|
116
|
+
if (options?.contextName) {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
if (!options || Object.keys(options).length === 0) {
|
|
121
|
+
const config = await core_1.ConfigurationLoader.getConfiguration(false);
|
|
122
|
+
return config.getDriver().createEntityManager();
|
|
123
|
+
}
|
|
124
|
+
if ('useFactory' in options) {
|
|
125
|
+
const config = new core_1.Configuration(await options.useFactory(), false);
|
|
126
|
+
return config.getDriver().createEntityManager();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// ignore
|
|
131
|
+
}
|
|
132
|
+
}
|
|
117
133
|
async onApplicationShutdown() {
|
|
118
134
|
const token = this.options.contextName ? (0, mikro_orm_common_1.getMikroORMToken)(this.options.contextName) : core_1.MikroORM;
|
|
119
135
|
const orm = this.moduleRef.get(token);
|
package/mikro-orm.providers.js
CHANGED
|
@@ -14,7 +14,6 @@ function createMikroOrmProvider(contextName) {
|
|
|
14
14
|
options.entitiesTs = [...(options.entitiesTs || []), ...mikro_orm_entities_storage_1.MikroOrmEntitiesStorage.getEntities(contextName)];
|
|
15
15
|
delete options.autoLoadEntities;
|
|
16
16
|
}
|
|
17
|
-
mikro_orm_entities_storage_1.MikroOrmEntitiesStorage.clear(contextName);
|
|
18
17
|
if (!options || Object.keys(options).length === 0) {
|
|
19
18
|
const config = await core_1.ConfigurationLoader.getConfiguration();
|
|
20
19
|
config.set('logger', mikro_orm_common_1.logger.log.bind(mikro_orm_common_1.logger));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/nestjs",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Martin Adamek",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"lint": "eslint src/**/*.ts"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@mikro-orm/core": "^5.0.0
|
|
43
|
+
"@mikro-orm/core": "^5.0.0 || ^6.0.0-dev.0",
|
|
44
44
|
"@nestjs/common": "^8.0.0 || ^9.0.0",
|
|
45
45
|
"@nestjs/core": "^8.0.0 || ^9.0.0"
|
|
46
46
|
},
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"@types/jest": "^29.2.4",
|
|
55
55
|
"@types/node": "^18.11.17",
|
|
56
56
|
"@types/supertest": "^2.0.12",
|
|
57
|
-
"@typescript-eslint/eslint-plugin": "~5.
|
|
58
|
-
"@typescript-eslint/parser": "~5.
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "~5.48.0",
|
|
58
|
+
"@typescript-eslint/parser": "~5.48.0",
|
|
59
59
|
"conventional-changelog": "^3.1.25",
|
|
60
60
|
"conventional-changelog-cli": "^2.2.2",
|
|
61
61
|
"eslint": "^8.30.0",
|
|
@@ -104,5 +104,5 @@
|
|
|
104
104
|
"engines": {
|
|
105
105
|
"node": ">= 14.0.0"
|
|
106
106
|
},
|
|
107
|
-
"packageManager": "yarn@3.3.
|
|
107
|
+
"packageManager": "yarn@3.3.1"
|
|
108
108
|
}
|
package/typings.d.ts
CHANGED
|
@@ -37,5 +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
|
|
40
|
+
export declare type EntityName<T extends AnyEntity<T>> = CoreEntityName<T> | EntitySchema;
|
|
41
41
|
export {};
|