@mikro-orm/nestjs 7.0.0-dev.4 → 7.0.0-dev.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 +1 -0
- package/mikro-orm-core.module.js +16 -40
- package/mikro-orm.providers.js +1 -1
- package/package.json +2 -2
|
@@ -7,6 +7,7 @@ export declare class MikroOrmCoreModule implements NestModule, OnApplicationShut
|
|
|
7
7
|
constructor(options: MikroOrmModuleOptions, moduleRef: ModuleRef);
|
|
8
8
|
static forRoot(options: MikroOrmModuleSyncOptions): Promise<DynamicModule>;
|
|
9
9
|
static forRootAsync(options: MikroOrmModuleAsyncOptions): Promise<DynamicModule>;
|
|
10
|
+
private static buildDynamicModule;
|
|
10
11
|
/**
|
|
11
12
|
* Tries to create the driver instance to use the actual entity manager implementation for DI symbol.
|
|
12
13
|
* This helps with dependency resolution issues when importing the EM from driver package (e.g. `SqlEntityManager`).
|
package/mikro-orm-core.module.js
CHANGED
|
@@ -30,63 +30,39 @@ let MikroOrmCoreModule = MikroOrmCoreModule_1 = class MikroOrmCoreModule {
|
|
|
30
30
|
static async forRoot(options) {
|
|
31
31
|
const contextName = this.setContextName(options.contextName);
|
|
32
32
|
const em = await this.createEntityManager(options);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
providers: [
|
|
37
|
-
{ provide: MIKRO_ORM_MODULE_OPTIONS, useValue: options || {} },
|
|
38
|
-
createMikroOrmProvider(contextName),
|
|
39
|
-
createMikroOrmProvider(contextName, em.getDriver().getORMClass()),
|
|
40
|
-
createEntityManagerProvider(options.scope, EntityManager),
|
|
41
|
-
createEntityManagerProvider(options.scope, em.constructor),
|
|
42
|
-
],
|
|
43
|
-
exports: [MikroORM, EntityManager, em.constructor, em.getDriver().getORMClass()],
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
module: MikroOrmCoreModule_1,
|
|
48
|
-
providers: [
|
|
49
|
-
{ provide: MIKRO_ORM_MODULE_OPTIONS, useValue: options || {} },
|
|
50
|
-
createMikroOrmProvider(contextName),
|
|
51
|
-
...(em ? [createMikroOrmProvider(contextName, em.getDriver().getORMClass())] : []),
|
|
52
|
-
createEntityManagerProvider(options.scope, EntityManager, contextName),
|
|
53
|
-
...(em ? [createEntityManagerProvider(options.scope, em.constructor, contextName)] : []),
|
|
54
|
-
],
|
|
55
|
-
exports: [
|
|
56
|
-
contextName ? getMikroORMToken(contextName) : MikroORM,
|
|
57
|
-
contextName ? getEntityManagerToken(contextName) : EntityManager,
|
|
58
|
-
...(em && !contextName ? [em.constructor, em.getDriver().getORMClass()] : []),
|
|
59
|
-
],
|
|
60
|
-
};
|
|
33
|
+
return this.buildDynamicModule(em, contextName, options, [
|
|
34
|
+
{ provide: MIKRO_ORM_MODULE_OPTIONS, useValue: options },
|
|
35
|
+
]);
|
|
61
36
|
}
|
|
62
37
|
static async forRootAsync(options) {
|
|
63
38
|
const contextName = this.setContextName(options.contextName);
|
|
64
39
|
const em = await this.createEntityManager(options);
|
|
40
|
+
return this.buildDynamicModule(em, contextName, options, [...(options.providers || []), ...createAsyncProviders({ ...options, contextName: options.contextName })], options.imports || []);
|
|
41
|
+
}
|
|
42
|
+
static buildDynamicModule(em, contextName, options, baseProviders, imports = []) {
|
|
65
43
|
if (em && !contextName) {
|
|
66
44
|
return {
|
|
67
45
|
module: MikroOrmCoreModule_1,
|
|
68
|
-
imports
|
|
46
|
+
imports,
|
|
69
47
|
providers: [
|
|
70
|
-
...
|
|
71
|
-
...createAsyncProviders({ ...options, contextName: options.contextName }),
|
|
48
|
+
...baseProviders,
|
|
72
49
|
createMikroOrmProvider(contextName),
|
|
73
50
|
createMikroOrmProvider(contextName, em.getDriver().getORMClass()),
|
|
74
|
-
createEntityManagerProvider(options.scope, EntityManager),
|
|
75
|
-
createEntityManagerProvider(options.scope, em.constructor),
|
|
51
|
+
createEntityManagerProvider(options.scope, EntityManager, undefined, options.forkOptions),
|
|
52
|
+
createEntityManagerProvider(options.scope, em.constructor, undefined, options.forkOptions),
|
|
76
53
|
],
|
|
77
54
|
exports: [MikroORM, EntityManager, em.constructor, em.getDriver().getORMClass()],
|
|
78
55
|
};
|
|
79
56
|
}
|
|
80
57
|
return {
|
|
81
58
|
module: MikroOrmCoreModule_1,
|
|
82
|
-
imports
|
|
59
|
+
imports,
|
|
83
60
|
providers: [
|
|
84
|
-
...
|
|
85
|
-
...createAsyncProviders({ ...options, contextName: options.contextName }),
|
|
61
|
+
...baseProviders,
|
|
86
62
|
createMikroOrmProvider(contextName),
|
|
87
63
|
...(em ? [createMikroOrmProvider(contextName, em.getDriver().getORMClass())] : []),
|
|
88
|
-
createEntityManagerProvider(options.scope, EntityManager, contextName),
|
|
89
|
-
...(em ? [createEntityManagerProvider(options.scope, em.constructor, contextName)] : []),
|
|
64
|
+
createEntityManagerProvider(options.scope, EntityManager, contextName, options.forkOptions),
|
|
65
|
+
...(em ? [createEntityManagerProvider(options.scope, em.constructor, contextName, options.forkOptions)] : []),
|
|
90
66
|
],
|
|
91
67
|
exports: [
|
|
92
68
|
contextName ? getMikroORMToken(contextName) : MikroORM,
|
|
@@ -105,7 +81,7 @@ let MikroOrmCoreModule = MikroOrmCoreModule_1 = class MikroOrmCoreModule {
|
|
|
105
81
|
}
|
|
106
82
|
try {
|
|
107
83
|
let config;
|
|
108
|
-
if (typeof options === 'object' && options && 'driver' in options) {
|
|
84
|
+
if (typeof options === 'object' && options && 'driver' in options && !('useFactory' in options)) {
|
|
109
85
|
config = new Configuration(options, false);
|
|
110
86
|
}
|
|
111
87
|
if (!config && 'useFactory' in options) {
|
|
@@ -122,7 +98,7 @@ let MikroOrmCoreModule = MikroOrmCoreModule_1 = class MikroOrmCoreModule {
|
|
|
122
98
|
'inject' in options &&
|
|
123
99
|
!options.driver &&
|
|
124
100
|
options.inject.length > 0) {
|
|
125
|
-
//
|
|
101
|
+
// oxlint-disable-next-line no-console
|
|
126
102
|
console.warn('Support for driver specific imports in modules defined with `useFactory` and `inject` requires an explicit `driver` option. See https://github.com/mikro-orm/nestjs/pull/204');
|
|
127
103
|
}
|
|
128
104
|
}
|
package/mikro-orm.providers.js
CHANGED
|
@@ -42,7 +42,7 @@ export function createEntityManagerProvider(scope = Scope.DEFAULT, entityManager
|
|
|
42
42
|
return {
|
|
43
43
|
provide: contextName ? getEntityManagerToken(contextName) : entityManager,
|
|
44
44
|
scope,
|
|
45
|
-
useFactory: (orm) => (scope === Scope.DEFAULT ? orm.em : orm.em.fork(forkOptions)),
|
|
45
|
+
useFactory: (orm) => (scope === Scope.DEFAULT ? orm.em : orm.em.fork({ useContext: true, ...forkOptions })),
|
|
46
46
|
inject: [contextName ? getMikroORMToken(contextName) : MikroORM],
|
|
47
47
|
};
|
|
48
48
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/nestjs",
|
|
3
|
-
"version": "7.0.0-dev.
|
|
3
|
+
"version": "7.0.0-dev.6",
|
|
4
4
|
"description": "NestJS module for MikroORM",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"clean": "rimraf ./dist",
|
|
39
39
|
"compile": "tsc -p tsconfig.build.json",
|
|
40
40
|
"copy": "node ./scripts/copy.mjs",
|
|
41
|
-
"test": "vitest
|
|
41
|
+
"test": "vitest run",
|
|
42
42
|
"tsc-check-tests": "tsc --noEmit --project tests/tsconfig.json",
|
|
43
43
|
"format": "oxfmt --write .",
|
|
44
44
|
"lint": "oxlint --type-aware",
|