Skip to content

Commit 87fd6b8

Browse files
authored
feat: expose fork options in the MikroOrmModule options configuration object (#182)
Closes #181
1 parent e7af71a commit 87fd6b8

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/mikro-orm.providers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ConfigurationLoader, EntityManager, MetadataStorage, MikroORM, type AnyEntity, type EntityClass, type EntityClassGroup, type EntitySchema } from '@mikro-orm/core';
1+
import { ConfigurationLoader, EntityManager, MetadataStorage, MikroORM, type AnyEntity, type EntityClass, type EntityClassGroup, type EntitySchema, type ForkOptions } from '@mikro-orm/core';
22
import { MIKRO_ORM_MODULE_OPTIONS, getEntityManagerToken, getMikroORMToken, getRepositoryToken, logger } from './mikro-orm.common';
33

44
import { Scope, type InjectionToken, type Provider, type Type } from '@nestjs/common';
@@ -44,6 +44,7 @@ export function createEntityManagerProvider(
4444
scope = Scope.DEFAULT,
4545
entityManager: Type = EntityManager,
4646
contextName?: string,
47+
forkOptions?: ForkOptions,
4748
): Provider<EntityManager> {
4849
if (!contextName && entityManager !== EntityManager) {
4950
return {
@@ -57,7 +58,7 @@ export function createEntityManagerProvider(
5758
return {
5859
provide: contextName ? getEntityManagerToken(contextName) : entityManager,
5960
scope,
60-
useFactory: (orm: MikroORM) => scope === Scope.DEFAULT ? orm.em : orm.em.fork(),
61+
useFactory: (orm: MikroORM) => scope === Scope.DEFAULT ? orm.em : orm.em.fork(forkOptions),
6162
inject: [contextName ? getMikroORMToken(contextName) : MikroORM],
6263
};
6364
}

src/typings.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AnyEntity, EntityName as CoreEntityName, EntitySchema, IDatabaseDriver, Options } from '@mikro-orm/core';
1+
import type { AnyEntity, EntityName as CoreEntityName, EntitySchema, ForkOptions, IDatabaseDriver, Options } from '@mikro-orm/core';
22
import type { MiddlewareConsumer, ModuleMetadata, Scope, Type } from '@nestjs/common';
33
import type { AbstractHttpAdapter } from '@nestjs/core';
44

@@ -15,6 +15,14 @@ type MikroOrmNestScopeOptions = {
1515
* @see [NestJS Scope Hierarchy](https://docs.nestjs.com/fundamentals/injection-scopes#scope-hierarchy)
1616
*/
1717
scope?: Scope;
18+
/**
19+
* An optional configuration object to use when forking the Event Manager if it is configured with a scope other than Scope.DEFAULT
20+
*
21+
* This configuration option has no effect when the scope is set to Scope.DEFAULT.
22+
*
23+
* https://mikro-orm.io/api/core/interface/ForkOptions
24+
*/
25+
forkOptions?: ForkOptions;
1826
};
1927

2028
export type MikroOrmMiddlewareModuleOptions = {

0 commit comments

Comments
 (0)