@mikro-orm/nestjs 6.1.1 → 7.0.0-dev.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Dario Mancuso, Martin Adámek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -54,7 +54,7 @@ Once the installation process is completed, we can import the `MikroOrmModule` i
54
54
  export class AppModule {}
55
55
  ```
56
56
 
57
- The `forRoot()` method accepts the same configuration object as `init()` from the MikroORM package.
57
+ The `forRoot()` method accepts the same configuration object as `init()` from the MikroORM package.
58
58
  You can also omit the parameter to use the CLI config.
59
59
 
60
60
  Afterward, the `EntityManager` will be available to inject across entire project (without importing any module elsewhere).
@@ -132,18 +132,18 @@ Instead of relying on this discovery, you can provide the driver type explicitly
132
132
  export class AppModule {}
133
133
  ```
134
134
 
135
- ## Auto entities automatically
135
+ ## Load entities automatically
136
136
 
137
- Manually adding entities to the entities array of the connection options can be
138
- tedious. In addition, referencing entities from the root module breaks application
139
- domain boundaries and causes leaking implementation details to other parts of the
137
+ Manually adding entities to the entities array of the connection options can be
138
+ tedious. In addition, referencing entities from the root module breaks application
139
+ domain boundaries and causes leaking implementation details to other parts of the
140
140
  application. To solve this issue, static glob paths can be used.
141
141
 
142
- Note, however, that glob paths are not supported by webpack, so if you are building
143
- your application within a monorepo, you won't be able to use them. To address this
144
- issue, an alternative solution is provided. To automatically load entities, set the
145
- `autoLoadEntities` property of the configuration object (passed into the `forRoot()`
146
- method) to `true`, as shown below:
142
+ Note, however, that glob paths are not supported by webpack, so if you are building
143
+ your application within a monorepo, you won't be able to use them. To address this
144
+ issue, an alternative solution is provided. To automatically load entities, set the
145
+ `autoLoadEntities` property of the configuration object (passed into the `forRoot()`
146
+ method) to `true`, as shown below:
147
147
 
148
148
  ```ts
149
149
  @Module({
@@ -157,31 +157,31 @@ method) to `true`, as shown below:
157
157
  export class AppModule {}
158
158
  ```
159
159
 
160
- With that option specified, every entity registered through the `forFeature()`
161
- method will be automatically added to the entities array of the configuration
160
+ With that option specified, every entity registered through the `forFeature()`
161
+ method will be automatically added to the entities array of the configuration
162
162
  object.
163
163
 
164
- > Note that entities that aren't registered through the `forFeature()` method, but
165
- > are only referenced from the entity (via a relationship), won't be included by
164
+ > Note that entities that aren't registered through the `forFeature()` method, but
165
+ > are only referenced from the entity (via a relationship), won't be included by
166
166
  > way of the `autoLoadEntities` setting.
167
167
 
168
- > Using `autoLoadEntities` also has no effect on the MikroORM CLI - for that we
168
+ > Using `autoLoadEntities` also has no effect on the MikroORM CLI - for that we
169
169
  > still need CLI config with the full list of entities. On the other hand, we can
170
170
  > use globs there, as the CLI won't go thru webpack.
171
171
 
172
172
  ## Request scoped handlers in queues
173
173
 
174
174
  As mentioned in the docs, we need a clean state for each request. That is handled
175
- automatically thanks to the `RequestContext` helper registered via middleware.
175
+ automatically thanks to the `RequestContext` helper registered via middleware.
176
176
 
177
177
  But middlewares are executed only for regular HTTP request handles, what if we need
178
- a request scoped method outside of that? One example of that is queue handlers or
179
- scheduled tasks.
178
+ a request scoped method outside of that? One example of that is queue handlers or
179
+ scheduled tasks.
180
180
 
181
- We can use the `@UseRequestContext()` decorator. It requires you to first inject the
182
- `MikroORM` instance to current context, it will be then used to create the context
183
- for you. Under the hood, the decorator will register new request context for your
184
- method and execute it inside the context.
181
+ We can use the `@CreateRequestContext()` decorator. It requires you to first inject the
182
+ `MikroORM` instance to current context, it will be then used to create the context
183
+ for you. Under the hood, the decorator will register new request context for your
184
+ method and execute it inside the context.
185
185
 
186
186
  ```ts
187
187
  @Injectable()
@@ -189,7 +189,7 @@ export class MyService {
189
189
 
190
190
  constructor(private readonly orm: MikroORM) { }
191
191
 
192
- @UseRequestContext()
192
+ @CreateRequestContext()
193
193
  async doSomething() {
194
194
  // this will be executed in a separate context
195
195
  }
@@ -209,10 +209,10 @@ export class Book {
209
209
 
210
210
  @Property({ hidden: true }) // --> Equivalent of class-transformer's `@Exclude`
211
211
  hiddenField: number = Date.now();
212
-
212
+
213
213
  @Property({ persist: false }) // --> Will only exist in memory (and will be serialized). Similar to class-transformer's `@Expose()`
214
214
  count?: number;
215
-
215
+
216
216
  @ManyToOne({ serializer: value => value.name, serializedName: 'authorName' }) // Equivalent of class-transformer's `@Transform()`
217
217
  author: Author;
218
218
 
@@ -274,6 +274,7 @@ export class AppModule {}
274
274
  ```
275
275
 
276
276
  Or, if you're using the Async provider:
277
+
277
278
  ```typescript
278
279
  import { Scope } from '@nestjs/common';
279
280
  import { PostgreSqlDriver } from '@mikro-orm/postgresql';
@@ -307,8 +308,8 @@ decorator by naming our repositories the same way as `getRepositoryToken()` meth
307
308
  export const getRepositoryToken = <T> (entity: EntityName<T>) => `${Utils.className(entity)}Repository`;
308
309
  ```
309
310
 
310
- In other words, as long as we name the repository same was as the entity is called,
311
- appending `Repository` suffix, the repository will be registered automatically in
311
+ In other words, as long as we name the repository same was as the entity is called,
312
+ appending `Repository` suffix, the repository will be registered automatically in
312
313
  the Nest.js DI container.
313
314
 
314
315
  `**./author.entity.ts**`
@@ -474,8 +475,8 @@ export class PhotoModule {}
474
475
 
475
476
  ## 🤝 Contributing
476
477
 
477
- Contributions, issues and feature requests are welcome. Please read
478
- [CONTRIBUTING.md](CONTRIBUTING.md)
478
+ Contributions, issues and feature requests are welcome. Please read
479
+ [CONTRIBUTING.md](CONTRIBUTING.md)
479
480
  for details on the process for submitting pull requests to us.
480
481
 
481
482
  ## Authors
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from './mikro-orm.module';
2
- export * from './mikro-orm.common';
3
- export * from './mikro-orm.middleware';
4
- export * from './multiple-mikro-orm.middleware';
5
- export * from './typings';
1
+ export * from './mikro-orm.module.js';
2
+ export * from './mikro-orm.common.js';
3
+ export * from './mikro-orm.middleware.js';
4
+ export * from './multiple-mikro-orm.middleware.js';
5
+ export * from './typings.js';
package/index.js CHANGED
@@ -1,21 +1,5 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./mikro-orm.module"), exports);
18
- __exportStar(require("./mikro-orm.common"), exports);
19
- __exportStar(require("./mikro-orm.middleware"), exports);
20
- __exportStar(require("./multiple-mikro-orm.middleware"), exports);
21
- __exportStar(require("./typings"), exports);
1
+ export * from './mikro-orm.module.js';
2
+ export * from './mikro-orm.common.js';
3
+ export * from './mikro-orm.middleware.js';
4
+ export * from './multiple-mikro-orm.middleware.js';
5
+ export * from './typings.js';
@@ -1,3 +1,3 @@
1
- import type { MikroOrmMiddlewareModuleOptions } from './typings';
2
1
  import { type MiddlewareConsumer } from '@nestjs/common';
2
+ import type { MikroOrmMiddlewareModuleOptions } from './typings.js';
3
3
  export declare function forRoutesPath(options: MikroOrmMiddlewareModuleOptions, consumer: MiddlewareConsumer): string;
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.forRoutesPath = forRoutesPath;
4
- const common_1 = require("@nestjs/common");
5
- function forRoutesPath(options, consumer) {
1
+ import { HttpStatus } from '@nestjs/common';
2
+ export function forRoutesPath(options, consumer) {
6
3
  if (options.forRoutesPath) {
7
4
  return options.forRoutesPath;
8
5
  }
9
6
  // detect nest v11 based on a newly added enum value
10
- if (common_1.HttpStatus.MULTI_STATUS) {
7
+ if (HttpStatus.MULTI_STATUS) {
11
8
  return '{*all}';
12
9
  }
13
10
  const isFastify = (consumer) => {
@@ -1,11 +1,11 @@
1
1
  import { type DynamicModule, type MiddlewareConsumer, type NestModule, type OnApplicationShutdown } from '@nestjs/common';
2
2
  import { ModuleRef } from '@nestjs/core';
3
- import { MikroOrmModuleOptions, type MikroOrmModuleAsyncOptions, type MikroOrmModuleSyncOptions } from './typings';
3
+ import type { MikroOrmModuleOptions, MikroOrmModuleAsyncOptions, MikroOrmModuleSyncOptions } from './typings.js';
4
4
  export declare class MikroOrmCoreModule implements NestModule, OnApplicationShutdown {
5
5
  private readonly options;
6
6
  private readonly moduleRef;
7
7
  constructor(options: MikroOrmModuleOptions, moduleRef: ModuleRef);
8
- static forRoot(options?: MikroOrmModuleSyncOptions): Promise<DynamicModule>;
8
+ static forRoot(options: MikroOrmModuleSyncOptions): Promise<DynamicModule>;
9
9
  static forRootAsync(options: MikroOrmModuleAsyncOptions): Promise<DynamicModule>;
10
10
  /**
11
11
  * Tries to create the driver instance to use the actual entity manager implementation for DI symbol.
@@ -1,43 +1,9 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
1
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
2
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
3
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
23
6
  };
24
- var __importStar = (this && this.__importStar) || (function () {
25
- var ownKeys = function(o) {
26
- ownKeys = Object.getOwnPropertyNames || function (o) {
27
- var ar = [];
28
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
- return ar;
30
- };
31
- return ownKeys(o);
32
- };
33
- return function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
- __setModuleDefault(result, mod);
38
- return result;
39
- };
40
- })();
41
7
  var __metadata = (this && this.__metadata) || function (k, v) {
42
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
9
  };
@@ -45,181 +11,87 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
45
11
  return function (target, key) { decorator(target, key, paramIndex); }
46
12
  };
47
13
  var MikroOrmCoreModule_1;
48
- Object.defineProperty(exports, "__esModule", { value: true });
49
- exports.MikroOrmCoreModule = void 0;
50
- const core_1 = require("@mikro-orm/core");
51
- const common_1 = require("@nestjs/common");
52
- const core_2 = require("@nestjs/core");
53
- const middleware_helper_1 = require("./middleware.helper");
54
- const mikro_orm_common_1 = require("./mikro-orm.common");
55
- const mikro_orm_entities_storage_1 = require("./mikro-orm.entities.storage");
56
- const mikro_orm_middleware_1 = require("./mikro-orm.middleware");
57
- const mikro_orm_providers_1 = require("./mikro-orm.providers");
58
- async function tryRequire(name) {
59
- try {
60
- return await Promise.resolve(`${name}`).then(s => __importStar(require(s)));
61
- }
62
- catch {
63
- return undefined; // ignore, optional dependency
64
- }
65
- }
66
- // TODO: provide the package name via some platform method, prefer that over the static map when available
67
- const PACKAGES = {
68
- MongoDriver: '@mikro-orm/mongo',
69
- MySqlDriver: '@mikro-orm/mysql',
70
- MsSqlDriver: '@mikro-orm/mssql',
71
- MariaDbDriver: '@mikro-orm/mariadb',
72
- PostgreSqlDriver: '@mikro-orm/postgresql',
73
- SqliteDriver: '@mikro-orm/sqlite',
74
- LibSqlDriver: '@mikro-orm/libsql',
75
- BetterSqliteDriver: '@mikro-orm/better-sqlite',
76
- };
14
+ import { Configuration, EntityManager, MikroORM } from '@mikro-orm/core';
15
+ import { Global, Inject, Module, RequestMethod, } from '@nestjs/common';
16
+ // oxlint-disable-next-line consistent-type-imports
17
+ import { ModuleRef } from '@nestjs/core';
18
+ import { forRoutesPath } from './middleware.helper.js';
19
+ import { CONTEXT_NAMES, getEntityManagerToken, getMikroORMToken, MIKRO_ORM_MODULE_OPTIONS, } from './mikro-orm.common.js';
20
+ import { MikroOrmEntitiesStorage } from './mikro-orm.entities.storage.js';
21
+ import { MikroOrmMiddleware } from './mikro-orm.middleware.js';
22
+ import { createAsyncProviders, createEntityManagerProvider, createMikroOrmProvider } from './mikro-orm.providers.js';
77
23
  let MikroOrmCoreModule = MikroOrmCoreModule_1 = class MikroOrmCoreModule {
24
+ options;
25
+ moduleRef;
78
26
  constructor(options, moduleRef) {
79
27
  this.options = options;
80
28
  this.moduleRef = moduleRef;
81
29
  }
82
30
  static async forRoot(options) {
83
- const contextName = this.setContextName(options?.contextName);
84
- if (options?.driver && !contextName) {
85
- const packageName = PACKAGES[options.driver.name];
86
- const driverPackage = await tryRequire(packageName);
87
- if (driverPackage) {
88
- return {
89
- module: MikroOrmCoreModule_1,
90
- providers: [
91
- { provide: mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS, useValue: options || {} },
92
- (0, mikro_orm_providers_1.createMikroOrmProvider)(contextName),
93
- (0, mikro_orm_providers_1.createMikroOrmProvider)(contextName, driverPackage.MikroORM),
94
- (0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, core_1.EntityManager),
95
- (0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, driverPackage.EntityManager),
96
- ],
97
- exports: [
98
- core_1.MikroORM,
99
- core_1.EntityManager,
100
- driverPackage.EntityManager,
101
- driverPackage.MikroORM,
102
- ],
103
- };
104
- }
105
- }
106
- const knex = await tryRequire('@mikro-orm/knex');
107
- const mongo = await tryRequire('@mikro-orm/mongodb');
31
+ const contextName = this.setContextName(options.contextName);
108
32
  const em = await this.createEntityManager(options);
109
33
  if (em && !contextName) {
110
- const packageName = PACKAGES[em.getDriver().constructor.name];
111
- const driverPackage = await tryRequire(packageName);
112
- if (driverPackage) {
113
- return {
114
- module: MikroOrmCoreModule_1,
115
- providers: [
116
- { provide: mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS, useValue: options || {} },
117
- (0, mikro_orm_providers_1.createMikroOrmProvider)(contextName),
118
- (0, mikro_orm_providers_1.createMikroOrmProvider)(contextName, driverPackage.MikroORM),
119
- (0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, core_1.EntityManager),
120
- (0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, driverPackage.EntityManager),
121
- ],
122
- exports: [
123
- core_1.MikroORM,
124
- core_1.EntityManager,
125
- driverPackage.EntityManager,
126
- driverPackage.MikroORM,
127
- ],
128
- };
129
- }
34
+ return {
35
+ module: MikroOrmCoreModule_1,
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
+ };
130
45
  }
131
46
  return {
132
47
  module: MikroOrmCoreModule_1,
133
48
  providers: [
134
- { provide: mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS, useValue: options || {} },
135
- (0, mikro_orm_providers_1.createMikroOrmProvider)(contextName),
136
- ...(mongo ? [(0, mikro_orm_providers_1.createMikroOrmProvider)(contextName, mongo.MikroORM)] : []),
137
- (0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, core_1.EntityManager, contextName),
138
- ...(em ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, em.constructor, contextName)] : []),
139
- ...(knex ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, knex.EntityManager, contextName)] : []),
140
- ...(mongo ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, mongo.EntityManager, contextName)] : []),
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)] : []),
141
54
  ],
142
55
  exports: [
143
- contextName ? (0, mikro_orm_common_1.getMikroORMToken)(contextName) : core_1.MikroORM,
144
- contextName ? (0, mikro_orm_common_1.getEntityManagerToken)(contextName) : core_1.EntityManager,
145
- ...(em && !contextName ? [em.constructor] : []),
146
- ...(knex && !contextName ? [knex.EntityManager] : []),
147
- ...(mongo && !contextName ? [mongo.EntityManager, mongo.MikroORM] : []),
56
+ contextName ? getMikroORMToken(contextName) : MikroORM,
57
+ contextName ? getEntityManagerToken(contextName) : EntityManager,
58
+ ...(em && !contextName ? [em.constructor, em.getDriver().getORMClass()] : []),
148
59
  ],
149
60
  };
150
61
  }
151
62
  static async forRootAsync(options) {
152
- const contextName = this.setContextName(options?.contextName);
153
- if (options?.driver && !contextName) {
154
- const packageName = PACKAGES[options.driver.name];
155
- const driverPackage = await tryRequire(packageName);
156
- if (driverPackage) {
157
- return {
158
- module: MikroOrmCoreModule_1,
159
- imports: options.imports || [],
160
- providers: [
161
- ...(options.providers || []),
162
- ...(0, mikro_orm_providers_1.createAsyncProviders)({ ...options, contextName: options.contextName }),
163
- (0, mikro_orm_providers_1.createMikroOrmProvider)(contextName),
164
- (0, mikro_orm_providers_1.createMikroOrmProvider)(contextName, driverPackage.MikroORM),
165
- (0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, core_1.EntityManager),
166
- (0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, driverPackage.EntityManager),
167
- ],
168
- exports: [
169
- core_1.MikroORM,
170
- core_1.EntityManager,
171
- driverPackage.EntityManager,
172
- driverPackage.MikroORM,
173
- ],
174
- };
175
- }
176
- }
177
- const knex = await tryRequire('@mikro-orm/knex');
178
- const mongo = await tryRequire('@mikro-orm/mongodb');
63
+ const contextName = this.setContextName(options.contextName);
179
64
  const em = await this.createEntityManager(options);
180
65
  if (em && !contextName) {
181
- const packageName = PACKAGES[em.getDriver().constructor.name];
182
- const driverPackage = await tryRequire(packageName);
183
- if (driverPackage) {
184
- return {
185
- module: MikroOrmCoreModule_1,
186
- imports: options.imports || [],
187
- providers: [
188
- ...(options.providers || []),
189
- ...(0, mikro_orm_providers_1.createAsyncProviders)({ ...options, contextName: options.contextName }),
190
- (0, mikro_orm_providers_1.createMikroOrmProvider)(contextName),
191
- (0, mikro_orm_providers_1.createMikroOrmProvider)(contextName, driverPackage.MikroORM),
192
- (0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, core_1.EntityManager),
193
- (0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, driverPackage.EntityManager),
194
- ],
195
- exports: [
196
- core_1.MikroORM,
197
- core_1.EntityManager,
198
- driverPackage.EntityManager,
199
- driverPackage.MikroORM,
200
- ],
201
- };
202
- }
66
+ return {
67
+ module: MikroOrmCoreModule_1,
68
+ imports: options.imports || [],
69
+ providers: [
70
+ ...(options.providers || []),
71
+ ...createAsyncProviders({ ...options, contextName: options.contextName }),
72
+ createMikroOrmProvider(contextName),
73
+ createMikroOrmProvider(contextName, em.getDriver().getORMClass()),
74
+ createEntityManagerProvider(options.scope, EntityManager),
75
+ createEntityManagerProvider(options.scope, em.constructor),
76
+ ],
77
+ exports: [MikroORM, EntityManager, em.constructor, em.getDriver().getORMClass()],
78
+ };
203
79
  }
204
80
  return {
205
81
  module: MikroOrmCoreModule_1,
206
82
  imports: options.imports || [],
207
83
  providers: [
208
84
  ...(options.providers || []),
209
- ...(0, mikro_orm_providers_1.createAsyncProviders)({ ...options, contextName: options.contextName }),
210
- (0, mikro_orm_providers_1.createMikroOrmProvider)(contextName),
211
- ...(mongo ? [(0, mikro_orm_providers_1.createMikroOrmProvider)(contextName, mongo.MikroORM)] : []),
212
- (0, mikro_orm_providers_1.createEntityManagerProvider)(options.scope, core_1.EntityManager, contextName),
213
- ...(em ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, em.constructor, contextName)] : []),
214
- ...(knex ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, knex.EntityManager, contextName)] : []),
215
- ...(mongo ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, mongo.EntityManager, contextName)] : []),
85
+ ...createAsyncProviders({ ...options, contextName: options.contextName }),
86
+ createMikroOrmProvider(contextName),
87
+ ...(em ? [createMikroOrmProvider(contextName, em.getDriver().getORMClass())] : []),
88
+ createEntityManagerProvider(options.scope, EntityManager, contextName),
89
+ ...(em ? [createEntityManagerProvider(options.scope, em.constructor, contextName)] : []),
216
90
  ],
217
91
  exports: [
218
- contextName ? (0, mikro_orm_common_1.getMikroORMToken)(contextName) : core_1.MikroORM,
219
- contextName ? (0, mikro_orm_common_1.getEntityManagerToken)(contextName) : core_1.EntityManager,
220
- ...(em && !contextName ? [em.constructor] : []),
221
- ...(knex && !contextName ? [knex.EntityManager] : []),
222
- ...(mongo && !contextName ? [mongo.EntityManager, mongo.MikroORM] : []),
92
+ contextName ? getMikroORMToken(contextName) : MikroORM,
93
+ contextName ? getEntityManagerToken(contextName) : EntityManager,
94
+ ...(em && !contextName ? [em.constructor, em.getDriver().getORMClass()] : []),
223
95
  ],
224
96
  };
225
97
  }
@@ -228,64 +100,65 @@ let MikroOrmCoreModule = MikroOrmCoreModule_1 = class MikroOrmCoreModule {
228
100
  * This helps with dependency resolution issues when importing the EM from driver package (e.g. `SqlEntityManager`).
229
101
  */
230
102
  static async createEntityManager(options) {
231
- if (options?.contextName) {
103
+ if (options.contextName) {
232
104
  return undefined;
233
105
  }
234
106
  try {
235
107
  let config;
236
- if (!options || Object.keys(options).length === 0) {
237
- config = await core_1.ConfigurationLoader.getConfiguration(false);
238
- }
239
- if (!config && 'useFactory' in options) {
240
- config = new core_1.Configuration(await options.useFactory(), false);
108
+ if ('useFactory' in options) {
109
+ config = new Configuration(await options.useFactory(), false);
241
110
  }
242
- if (!config && options instanceof core_1.Configuration) {
111
+ if (!config && options instanceof Configuration) {
243
112
  config = options;
244
113
  }
245
114
  if (!config && typeof options === 'object' && options && 'driver' in options) {
246
- config = new core_1.Configuration(options, false);
115
+ config = new Configuration(options, false);
247
116
  }
248
117
  return config?.getDriver().createEntityManager();
249
118
  }
250
119
  catch {
251
- if (options && 'useFactory' in options && 'inject' in options && options.inject.length > 0) {
120
+ if (options &&
121
+ 'useFactory' in options &&
122
+ 'inject' in options &&
123
+ !options.driver &&
124
+ options.inject.length > 0) {
252
125
  // eslint-disable-next-line no-console
253
126
  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');
254
127
  }
255
128
  }
256
129
  }
257
130
  async onApplicationShutdown() {
258
- const token = this.options.contextName ? (0, mikro_orm_common_1.getMikroORMToken)(this.options.contextName) : core_1.MikroORM;
131
+ const token = this.options.contextName ? getMikroORMToken(this.options.contextName) : MikroORM;
259
132
  const orm = this.moduleRef.get(token);
260
133
  if (orm) {
261
134
  await orm.close();
262
- mikro_orm_entities_storage_1.MikroOrmEntitiesStorage.clearLater();
135
+ MikroOrmEntitiesStorage.clearLater();
263
136
  }
264
- mikro_orm_common_1.CONTEXT_NAMES.length = 0;
137
+ CONTEXT_NAMES.length = 0;
265
138
  }
266
139
  configure(consumer) {
267
140
  if (this.options.registerRequestContext === false) {
268
141
  return;
269
142
  }
270
143
  consumer
271
- .apply(mikro_orm_middleware_1.MikroOrmMiddleware) // register request context automatically
272
- .forRoutes({ path: (0, middleware_helper_1.forRoutesPath)(this.options, consumer), method: common_1.RequestMethod.ALL });
144
+ .apply(MikroOrmMiddleware) // register request context automatically
145
+ .forRoutes({ path: forRoutesPath(this.options, consumer), method: RequestMethod.ALL });
273
146
  }
274
147
  static setContextName(contextName) {
275
148
  if (!contextName) {
276
149
  return;
277
150
  }
278
- if (mikro_orm_common_1.CONTEXT_NAMES.includes(contextName)) {
151
+ if (CONTEXT_NAMES.includes(contextName)) {
279
152
  throw new Error(`ContextName '${contextName}' already registered`);
280
153
  }
281
- mikro_orm_common_1.CONTEXT_NAMES.push(contextName);
154
+ CONTEXT_NAMES.push(contextName);
282
155
  return contextName;
283
156
  }
284
157
  };
285
- exports.MikroOrmCoreModule = MikroOrmCoreModule;
286
- exports.MikroOrmCoreModule = MikroOrmCoreModule = MikroOrmCoreModule_1 = __decorate([
287
- (0, common_1.Global)(),
288
- (0, common_1.Module)({}),
289
- __param(0, (0, common_1.Inject)(mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS)),
290
- __metadata("design:paramtypes", [Object, core_2.ModuleRef])
158
+ MikroOrmCoreModule = MikroOrmCoreModule_1 = __decorate([
159
+ Global(),
160
+ Module({}),
161
+ __param(0, Inject(MIKRO_ORM_MODULE_OPTIONS)),
162
+ __metadata("design:paramtypes", [Object, ModuleRef])
291
163
  ], MikroOrmCoreModule);
164
+ export { MikroOrmCoreModule };
@@ -1,6 +1,6 @@
1
1
  import { type MiddlewareConsumer, type NestModule } from '@nestjs/common';
2
2
  import type { MikroORM } from '@mikro-orm/core';
3
- import { MikroOrmMiddlewareModuleOptions } from './typings';
3
+ import type { MikroOrmMiddlewareModuleOptions } from './typings.js';
4
4
  export declare class MikroOrmMiddlewareModule implements NestModule {
5
5
  private readonly options;
6
6
  constructor(options: MikroOrmMiddlewareModuleOptions);
@@ -13,7 +13,7 @@ export declare class MikroOrmMiddlewareModule implements NestModule {
13
13
  inject?: undefined;
14
14
  } | {
15
15
  provide: string;
16
- useFactory: (...args: MikroORM[]) => MikroORM<import("@mikro-orm/core").IDatabaseDriver<import("@mikro-orm/core").Connection>, import("@mikro-orm/core").EntityManager<import("@mikro-orm/core").IDatabaseDriver<import("@mikro-orm/core").Connection>>>[];
16
+ useFactory: (...args: MikroORM[]) => MikroORM<import("@mikro-orm/core").IDatabaseDriver<import("@mikro-orm/core").Connection>, import("@mikro-orm/core").EntityManager<import("@mikro-orm/core").IDatabaseDriver<import("@mikro-orm/core").Connection>>, (string | import("@mikro-orm/core").EntitySchema<any, never> | import("@mikro-orm/core").EntityClass<Partial<any>>)[]>[];
17
17
  inject: string[];
18
18
  useValue?: undefined;
19
19
  })[];