@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 +21 -0
- package/README.md +30 -29
- package/index.d.ts +5 -5
- package/index.js +5 -21
- package/middleware.helper.d.ts +1 -1
- package/middleware.helper.js +3 -6
- package/mikro-orm-core.module.d.ts +2 -2
- package/mikro-orm-core.module.js +76 -203
- package/mikro-orm-middleware.module.d.ts +2 -2
- package/mikro-orm-middleware.module.js +14 -16
- package/mikro-orm.common.d.ts +1 -1
- package/mikro-orm.common.js +13 -23
- package/mikro-orm.entities.storage.d.ts +1 -1
- package/mikro-orm.entities.storage.js +3 -7
- package/mikro-orm.middleware.js +9 -10
- package/mikro-orm.module.d.ts +3 -3
- package/mikro-orm.module.js +19 -23
- package/mikro-orm.providers.d.ts +1 -1
- package/mikro-orm.providers.js +36 -47
- package/multiple-mikro-orm.middleware.js +9 -11
- package/package.json +65 -57
- package/typings.js +1 -2
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -12,22 +11,21 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
12
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
12
|
};
|
|
14
13
|
var MikroOrmMiddlewareModule_1;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const mikro_orm_common_1 = require("./mikro-orm.common");
|
|
20
|
-
const multiple_mikro_orm_middleware_1 = require("./multiple-mikro-orm.middleware");
|
|
14
|
+
import { Global, Inject, Module, RequestMethod } from '@nestjs/common';
|
|
15
|
+
import { forRoutesPath } from './middleware.helper.js';
|
|
16
|
+
import { CONTEXT_NAMES, getMikroORMToken, MIKRO_ORM_MODULE_OPTIONS } from './mikro-orm.common.js';
|
|
17
|
+
import { MultipleMikroOrmMiddleware } from './multiple-mikro-orm.middleware.js';
|
|
21
18
|
let MikroOrmMiddlewareModule = MikroOrmMiddlewareModule_1 = class MikroOrmMiddlewareModule {
|
|
19
|
+
options;
|
|
22
20
|
constructor(options) {
|
|
23
21
|
this.options = options;
|
|
24
22
|
}
|
|
25
23
|
static forRoot(options) {
|
|
26
|
-
const inject =
|
|
24
|
+
const inject = CONTEXT_NAMES.map(name => getMikroORMToken(name));
|
|
27
25
|
return {
|
|
28
26
|
module: MikroOrmMiddlewareModule_1,
|
|
29
27
|
providers: [
|
|
30
|
-
{ provide:
|
|
28
|
+
{ provide: MIKRO_ORM_MODULE_OPTIONS, useValue: options || {} },
|
|
31
29
|
{
|
|
32
30
|
provide: 'MikroORMs',
|
|
33
31
|
useFactory: (...args) => args,
|
|
@@ -39,14 +37,14 @@ let MikroOrmMiddlewareModule = MikroOrmMiddlewareModule_1 = class MikroOrmMiddle
|
|
|
39
37
|
}
|
|
40
38
|
configure(consumer) {
|
|
41
39
|
consumer
|
|
42
|
-
.apply(
|
|
43
|
-
.forRoutes({ path:
|
|
40
|
+
.apply(MultipleMikroOrmMiddleware)
|
|
41
|
+
.forRoutes({ path: forRoutesPath(this.options, consumer), method: RequestMethod.ALL });
|
|
44
42
|
}
|
|
45
43
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
(
|
|
49
|
-
(0,
|
|
50
|
-
__param(0, (0, common_1.Inject)(mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS)),
|
|
44
|
+
MikroOrmMiddlewareModule = MikroOrmMiddlewareModule_1 = __decorate([
|
|
45
|
+
Global(),
|
|
46
|
+
Module({}),
|
|
47
|
+
__param(0, Inject(MIKRO_ORM_MODULE_OPTIONS)),
|
|
51
48
|
__metadata("design:paramtypes", [Object])
|
|
52
49
|
], MikroOrmMiddlewareModule);
|
|
50
|
+
export { MikroOrmMiddlewareModule };
|
package/mikro-orm.common.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Logger } from '@nestjs/common';
|
|
2
|
-
import type { EntityName } from './typings';
|
|
2
|
+
import type { EntityName } from './typings.js';
|
|
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;
|
package/mikro-orm.common.js
CHANGED
|
@@ -1,59 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
exports.MIKRO_ORM_MODULE_OPTIONS = Symbol('mikro-orm-module-options');
|
|
7
|
-
exports.CONTEXT_NAMES = [];
|
|
8
|
-
exports.logger = new common_1.Logger(core_1.MikroORM.name);
|
|
1
|
+
import { MikroORM, Utils } from '@mikro-orm/core';
|
|
2
|
+
import { Inject, Logger } from '@nestjs/common';
|
|
3
|
+
export const MIKRO_ORM_MODULE_OPTIONS = Symbol('mikro-orm-module-options');
|
|
4
|
+
export const CONTEXT_NAMES = [];
|
|
5
|
+
export const logger = new Logger(MikroORM.name);
|
|
9
6
|
/**
|
|
10
7
|
* Gets the injection token based on context name for the relevant MikroORM provider.
|
|
11
8
|
* @param name The context name of the database connection.
|
|
12
9
|
* @returns The MikroORM provider injection token for the supplied context name.
|
|
13
10
|
*/
|
|
14
|
-
const getMikroORMToken = (name) => `${name}_MikroORM`;
|
|
15
|
-
exports.getMikroORMToken = getMikroORMToken;
|
|
11
|
+
export const getMikroORMToken = (name) => `${name}_MikroORM`;
|
|
16
12
|
/**
|
|
17
13
|
* Injects a MikroORM provider based on the supplied context name.
|
|
18
14
|
*
|
|
19
15
|
* @param name The context name of the database connection.
|
|
20
16
|
* @returns A parameter decorator which will cause NestJS to inject the relevant MikroORM provider.
|
|
21
17
|
*/
|
|
22
|
-
const InjectMikroORM = (name) =>
|
|
23
|
-
exports.InjectMikroORM = InjectMikroORM;
|
|
18
|
+
export const InjectMikroORM = (name) => Inject(getMikroORMToken(name));
|
|
24
19
|
/**
|
|
25
20
|
* Injects the MikroORMs provider.
|
|
26
21
|
*
|
|
27
22
|
* @returns A decorator which will cause NestJS to inject the MikroORMs provider.
|
|
28
23
|
*/
|
|
29
|
-
const InjectMikroORMs = () =>
|
|
30
|
-
exports.InjectMikroORMs = InjectMikroORMs;
|
|
24
|
+
export const InjectMikroORMs = () => Inject('MikroORMs');
|
|
31
25
|
/**
|
|
32
26
|
* Gets the injection token based on context name for the relevant EntityManager provider.
|
|
33
27
|
* @param name The context name of the database connection.
|
|
34
28
|
* @returns The EntityManager provider injection token for the supplied context name.
|
|
35
29
|
*/
|
|
36
|
-
const getEntityManagerToken = (name) => `${name}_EntityManager`;
|
|
37
|
-
exports.getEntityManagerToken = getEntityManagerToken;
|
|
30
|
+
export const getEntityManagerToken = (name) => `${name}_EntityManager`;
|
|
38
31
|
/**
|
|
39
32
|
* Injects an EntityManager provider based on the supplied context name.
|
|
40
33
|
*
|
|
41
34
|
* @param name The context name of the database connection.
|
|
42
35
|
* @returns A parameter decorator which will cause NestJS to inject the relevant EntityManager provider.
|
|
43
36
|
*/
|
|
44
|
-
const InjectEntityManager = (name) =>
|
|
45
|
-
exports.InjectEntityManager = InjectEntityManager;
|
|
37
|
+
export const InjectEntityManager = (name) => Inject(getEntityManagerToken(name));
|
|
46
38
|
/**
|
|
47
39
|
* Gets the injection token based on class and optionally based on context name.
|
|
48
40
|
* @param entity The class of the Entity to use for the injected repository provider.
|
|
49
41
|
* @param name An optional context name - required for multiple database connections. See: [Multiple Database Connections](https://mikro-orm.io/docs/usage-with-nestjs#multiple-database-connections)
|
|
50
42
|
* @returns The EntityRepository provider injection token based on the supplied entity and context name.
|
|
51
43
|
*/
|
|
52
|
-
const getRepositoryToken = (entity, name) => {
|
|
44
|
+
export const getRepositoryToken = (entity, name) => {
|
|
53
45
|
const suffix = name ? `_${name}` : '';
|
|
54
|
-
return `${
|
|
46
|
+
return `${Utils.className(entity)}Repository${suffix}`;
|
|
55
47
|
};
|
|
56
|
-
exports.getRepositoryToken = getRepositoryToken;
|
|
57
48
|
/**
|
|
58
49
|
* Injects an EntityRepository provider.
|
|
59
50
|
*
|
|
@@ -61,5 +52,4 @@ exports.getRepositoryToken = getRepositoryToken;
|
|
|
61
52
|
* @param name An optional context name - required for multiple database connections. See: [Multiple Database Connections](https://mikro-orm.io/docs/usage-with-nestjs#multiple-database-connections)
|
|
62
53
|
* @returns A parameter decorator which will cause NestJS to inject the relevant EntityRepository provider.
|
|
63
54
|
*/
|
|
64
|
-
const InjectRepository = (entity, name) =>
|
|
65
|
-
exports.InjectRepository = InjectRepository;
|
|
55
|
+
export const InjectRepository = (entity, name) => Inject(getRepositoryToken(entity, name));
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class MikroOrmEntitiesStorage {
|
|
1
|
+
export class MikroOrmEntitiesStorage {
|
|
2
|
+
static storage = new Map();
|
|
3
|
+
static shouldClear = false;
|
|
5
4
|
static addEntity(entity, contextName = 'default') {
|
|
6
5
|
if (this.shouldClear) {
|
|
7
6
|
this.clear(contextName);
|
|
@@ -29,6 +28,3 @@ class MikroOrmEntitiesStorage {
|
|
|
29
28
|
this.shouldClear = true;
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
|
-
exports.MikroOrmEntitiesStorage = MikroOrmEntitiesStorage;
|
|
33
|
-
MikroOrmEntitiesStorage.storage = new Map();
|
|
34
|
-
MikroOrmEntitiesStorage.shouldClear = false;
|
package/mikro-orm.middleware.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,20 +7,20 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const common_1 = require("@nestjs/common");
|
|
10
|
+
// oxlint-disable-next-line consistent-type-imports
|
|
11
|
+
import { MikroORM, RequestContext } from '@mikro-orm/core';
|
|
12
|
+
import { Injectable } from '@nestjs/common';
|
|
15
13
|
let MikroOrmMiddleware = class MikroOrmMiddleware {
|
|
14
|
+
orm;
|
|
16
15
|
constructor(orm) {
|
|
17
16
|
this.orm = orm;
|
|
18
17
|
}
|
|
19
18
|
use(req, res, next) {
|
|
20
|
-
|
|
19
|
+
RequestContext.create(this.orm.em, next);
|
|
21
20
|
}
|
|
22
21
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
(
|
|
26
|
-
__metadata("design:paramtypes", [core_1.MikroORM])
|
|
22
|
+
MikroOrmMiddleware = __decorate([
|
|
23
|
+
Injectable(),
|
|
24
|
+
__metadata("design:paramtypes", [MikroORM])
|
|
27
25
|
], MikroOrmMiddleware);
|
|
26
|
+
export { MikroOrmMiddleware };
|
package/mikro-orm.module.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { type AnyEntity } from '@mikro-orm/core';
|
|
2
2
|
import { type DynamicModule } from '@nestjs/common';
|
|
3
|
-
import { EntityName, MikroOrmModuleAsyncOptions, MikroOrmModuleFeatureOptions, MikroOrmModuleSyncOptions, MikroOrmMiddlewareModuleOptions, MaybePromise } from './typings';
|
|
3
|
+
import type { EntityName, MikroOrmModuleAsyncOptions, MikroOrmModuleFeatureOptions, MikroOrmModuleSyncOptions, MikroOrmMiddlewareModuleOptions, MaybePromise } from './typings.js';
|
|
4
4
|
export declare class MikroOrmModule {
|
|
5
5
|
/**
|
|
6
6
|
* Clears the entity storage. This is useful for testing purposes, when you want to isolate the tests.
|
|
7
7
|
* Keep in mind that this should be called when using a test runner that keeps the context alive between tests (like Vitest with threads disabled).
|
|
8
8
|
*/
|
|
9
9
|
static clearStorage(contextName?: string): void;
|
|
10
|
-
static forRoot(options
|
|
11
|
-
static forRoot(options
|
|
10
|
+
static forRoot(options: MikroOrmModuleSyncOptions): MaybePromise<DynamicModule>;
|
|
11
|
+
static forRoot(options: MikroOrmModuleSyncOptions[]): MaybePromise<DynamicModule>[];
|
|
12
12
|
static forRootAsync(options: MikroOrmModuleAsyncOptions): MaybePromise<DynamicModule>;
|
|
13
13
|
static forRootAsync(options: MikroOrmModuleAsyncOptions[]): MaybePromise<DynamicModule>[];
|
|
14
14
|
static forFeature(options: EntityName<AnyEntity>[] | MikroOrmModuleFeatureOptions, contextName?: string): DynamicModule;
|
package/mikro-orm.module.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -6,41 +5,38 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
6
|
};
|
|
8
7
|
var MikroOrmModule_1;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const mikro_orm_middleware_module_1 = require("./mikro-orm-middleware.module");
|
|
15
|
-
const mikro_orm_entities_storage_1 = require("./mikro-orm.entities.storage");
|
|
16
|
-
const mikro_orm_providers_1 = require("./mikro-orm.providers");
|
|
8
|
+
import { Module } from '@nestjs/common';
|
|
9
|
+
import { MikroOrmCoreModule } from './mikro-orm-core.module.js';
|
|
10
|
+
import { MikroOrmMiddlewareModule } from './mikro-orm-middleware.module.js';
|
|
11
|
+
import { MikroOrmEntitiesStorage } from './mikro-orm.entities.storage.js';
|
|
12
|
+
import { createMikroOrmRepositoryProviders } from './mikro-orm.providers.js';
|
|
17
13
|
let MikroOrmModule = MikroOrmModule_1 = class MikroOrmModule {
|
|
18
14
|
/**
|
|
19
15
|
* Clears the entity storage. This is useful for testing purposes, when you want to isolate the tests.
|
|
20
16
|
* Keep in mind that this should be called when using a test runner that keeps the context alive between tests (like Vitest with threads disabled).
|
|
21
17
|
*/
|
|
22
18
|
static clearStorage(contextName) {
|
|
23
|
-
|
|
19
|
+
MikroOrmEntitiesStorage.clear(contextName);
|
|
24
20
|
}
|
|
25
21
|
static forRoot(options) {
|
|
26
22
|
if (Array.isArray(options)) {
|
|
27
|
-
return options.map(o =>
|
|
23
|
+
return options.map(o => MikroOrmCoreModule.forRoot(o));
|
|
28
24
|
}
|
|
29
|
-
return
|
|
25
|
+
return MikroOrmCoreModule.forRoot(options);
|
|
30
26
|
}
|
|
31
27
|
static forRootAsync(options) {
|
|
32
28
|
if (Array.isArray(options)) {
|
|
33
|
-
return options.map(o =>
|
|
29
|
+
return options.map(o => MikroOrmCoreModule.forRootAsync(o));
|
|
34
30
|
}
|
|
35
|
-
return
|
|
31
|
+
return MikroOrmCoreModule.forRootAsync(options);
|
|
36
32
|
}
|
|
37
33
|
static forFeature(options, contextName) {
|
|
38
|
-
const entities = Array.isArray(options) ? options :
|
|
39
|
-
const name =
|
|
40
|
-
const providers =
|
|
34
|
+
const entities = Array.isArray(options) ? options : options.entities || [];
|
|
35
|
+
const name = Array.isArray(options) || contextName ? contextName : options.contextName;
|
|
36
|
+
const providers = createMikroOrmRepositoryProviders(entities, name);
|
|
41
37
|
for (const e of entities) {
|
|
42
|
-
if (
|
|
43
|
-
|
|
38
|
+
if (typeof e !== 'string') {
|
|
39
|
+
MikroOrmEntitiesStorage.addEntity(e, name);
|
|
44
40
|
}
|
|
45
41
|
}
|
|
46
42
|
return {
|
|
@@ -50,10 +46,10 @@ let MikroOrmModule = MikroOrmModule_1 = class MikroOrmModule {
|
|
|
50
46
|
};
|
|
51
47
|
}
|
|
52
48
|
static forMiddleware(options) {
|
|
53
|
-
return
|
|
49
|
+
return MikroOrmMiddlewareModule.forRoot(options);
|
|
54
50
|
}
|
|
55
51
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
(0, common_1.Module)({})
|
|
52
|
+
MikroOrmModule = MikroOrmModule_1 = __decorate([
|
|
53
|
+
Module({})
|
|
59
54
|
], MikroOrmModule);
|
|
55
|
+
export { MikroOrmModule };
|
package/mikro-orm.providers.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EntityManager, type AnyEntity, type ForkOptions } from '@mikro-orm/core';
|
|
2
2
|
import { Scope, type Provider, type Type } from '@nestjs/common';
|
|
3
|
-
import type { EntityName, MikroOrmModuleAsyncOptions } from './typings';
|
|
3
|
+
import type { EntityName, MikroOrmModuleAsyncOptions } from './typings.js';
|
|
4
4
|
export declare function createMikroOrmProvider(contextName?: string, type?: Type): Provider;
|
|
5
5
|
export declare function createEntityManagerProvider(scope?: Scope, entityManager?: Type, contextName?: string, forkOptions?: ForkOptions): Provider<EntityManager>;
|
|
6
6
|
export declare function createMikroOrmAsyncOptionsProvider(options: MikroOrmModuleAsyncOptions): Provider;
|
package/mikro-orm.providers.js
CHANGED
|
@@ -1,66 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.createMikroOrmRepositoryProviders = createMikroOrmRepositoryProviders;
|
|
8
|
-
const core_1 = require("@mikro-orm/core");
|
|
9
|
-
const mikro_orm_common_1 = require("./mikro-orm.common");
|
|
10
|
-
const common_1 = require("@nestjs/common");
|
|
11
|
-
const mikro_orm_entities_storage_1 = require("./mikro-orm.entities.storage");
|
|
12
|
-
function createMikroOrmProvider(contextName, type = core_1.MikroORM) {
|
|
13
|
-
if (!contextName && type !== core_1.MikroORM) {
|
|
1
|
+
import { EntityManager, MetadataStorage, MikroORM } from '@mikro-orm/core';
|
|
2
|
+
import { Scope } from '@nestjs/common';
|
|
3
|
+
import { MIKRO_ORM_MODULE_OPTIONS, getEntityManagerToken, getMikroORMToken, getRepositoryToken, logger, } from './mikro-orm.common.js';
|
|
4
|
+
import { MikroOrmEntitiesStorage } from './mikro-orm.entities.storage.js';
|
|
5
|
+
export function createMikroOrmProvider(contextName, type = MikroORM) {
|
|
6
|
+
if (!contextName && type !== MikroORM) {
|
|
14
7
|
return {
|
|
15
8
|
provide: type,
|
|
16
9
|
useFactory: orm => orm, // just a simple alias
|
|
17
|
-
inject: [
|
|
10
|
+
inject: [MikroORM], // depend on the ORM from core package
|
|
18
11
|
};
|
|
19
12
|
}
|
|
20
13
|
return {
|
|
21
|
-
provide: contextName ?
|
|
14
|
+
provide: contextName ? getMikroORMToken(contextName) : type,
|
|
22
15
|
useFactory: async (options) => {
|
|
23
|
-
options = { ...options };
|
|
24
|
-
if (options
|
|
25
|
-
options.entities = [
|
|
26
|
-
|
|
16
|
+
options = { logger: logger.log.bind(logger), ...options };
|
|
17
|
+
if (options.autoLoadEntities) {
|
|
18
|
+
options.entities = [
|
|
19
|
+
...(options.entities || []),
|
|
20
|
+
...MikroOrmEntitiesStorage.getEntities(contextName),
|
|
21
|
+
];
|
|
22
|
+
options.entitiesTs = [
|
|
23
|
+
...(options.entitiesTs || []),
|
|
24
|
+
...MikroOrmEntitiesStorage.getEntities(contextName),
|
|
25
|
+
];
|
|
27
26
|
delete options.autoLoadEntities;
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
const config = await core_1.ConfigurationLoader.getConfiguration();
|
|
31
|
-
config.set('logger', mikro_orm_common_1.logger.log.bind(mikro_orm_common_1.logger));
|
|
32
|
-
options = config.getAll();
|
|
33
|
-
}
|
|
34
|
-
return core_1.MikroORM.init(options);
|
|
28
|
+
return MikroORM.init(options);
|
|
35
29
|
},
|
|
36
|
-
inject: [
|
|
30
|
+
inject: [MIKRO_ORM_MODULE_OPTIONS],
|
|
37
31
|
};
|
|
38
32
|
}
|
|
39
|
-
function createEntityManagerProvider(scope =
|
|
40
|
-
if (!contextName && entityManager !==
|
|
33
|
+
export function createEntityManagerProvider(scope = Scope.DEFAULT, entityManager = EntityManager, contextName, forkOptions) {
|
|
34
|
+
if (!contextName && entityManager !== EntityManager) {
|
|
41
35
|
return {
|
|
42
36
|
provide: entityManager,
|
|
43
37
|
scope,
|
|
44
38
|
useFactory: (em) => em, // just a simple alias, unlike `useExisting` from nest, this works with request scopes too
|
|
45
|
-
inject: [
|
|
39
|
+
inject: [EntityManager], // depend on the EM from core package
|
|
46
40
|
};
|
|
47
41
|
}
|
|
48
42
|
return {
|
|
49
|
-
provide: contextName ?
|
|
43
|
+
provide: contextName ? getEntityManagerToken(contextName) : entityManager,
|
|
50
44
|
scope,
|
|
51
|
-
useFactory: (orm) => scope ===
|
|
52
|
-
inject: [contextName ?
|
|
45
|
+
useFactory: (orm) => (scope === Scope.DEFAULT ? orm.em : orm.em.fork(forkOptions)),
|
|
46
|
+
inject: [contextName ? getMikroORMToken(contextName) : MikroORM],
|
|
53
47
|
};
|
|
54
48
|
}
|
|
55
|
-
function createMikroOrmAsyncOptionsProvider(options) {
|
|
49
|
+
export function createMikroOrmAsyncOptionsProvider(options) {
|
|
56
50
|
if (options.useFactory) {
|
|
57
51
|
return {
|
|
58
|
-
provide:
|
|
52
|
+
provide: MIKRO_ORM_MODULE_OPTIONS,
|
|
59
53
|
useFactory: async (...args) => {
|
|
60
54
|
const factoryOptions = await options.useFactory(...args);
|
|
61
|
-
return options.contextName
|
|
62
|
-
? { contextName: options.contextName, ...factoryOptions }
|
|
63
|
-
: factoryOptions;
|
|
55
|
+
return options.contextName ? { contextName: options.contextName, ...factoryOptions } : factoryOptions;
|
|
64
56
|
},
|
|
65
57
|
inject: options.inject || [],
|
|
66
58
|
};
|
|
@@ -70,27 +62,24 @@ function createMikroOrmAsyncOptionsProvider(options) {
|
|
|
70
62
|
inject.push(options.useClass ?? options.useExisting);
|
|
71
63
|
}
|
|
72
64
|
return {
|
|
73
|
-
provide:
|
|
65
|
+
provide: MIKRO_ORM_MODULE_OPTIONS,
|
|
74
66
|
useFactory: async (optionsFactory) => await optionsFactory.createMikroOrmOptions(options.contextName),
|
|
75
67
|
inject,
|
|
76
68
|
};
|
|
77
69
|
}
|
|
78
|
-
function createAsyncProviders(options) {
|
|
70
|
+
export function createAsyncProviders(options) {
|
|
79
71
|
if (options.useExisting || options.useFactory) {
|
|
80
72
|
return [createMikroOrmAsyncOptionsProvider(options)];
|
|
81
73
|
}
|
|
82
74
|
if (options.useClass) {
|
|
83
|
-
return [
|
|
84
|
-
createMikroOrmAsyncOptionsProvider(options),
|
|
85
|
-
{ provide: options.useClass, useClass: options.useClass },
|
|
86
|
-
];
|
|
75
|
+
return [createMikroOrmAsyncOptionsProvider(options), { provide: options.useClass, useClass: options.useClass }];
|
|
87
76
|
}
|
|
88
77
|
throw new Error('Invalid MikroORM async options: one of `useClass`, `useExisting` or `useFactory` should be defined.');
|
|
89
78
|
}
|
|
90
|
-
function createMikroOrmRepositoryProviders(entities, contextName) {
|
|
91
|
-
const metadata = Object.values(
|
|
79
|
+
export function createMikroOrmRepositoryProviders(entities, contextName) {
|
|
80
|
+
const metadata = Object.values(MetadataStorage.getMetadata());
|
|
92
81
|
const providers = [];
|
|
93
|
-
const inject = contextName ?
|
|
82
|
+
const inject = contextName ? getEntityManagerToken(contextName) : EntityManager;
|
|
94
83
|
(entities || []).forEach(entity => {
|
|
95
84
|
const meta = metadata.find(meta => meta.class === entity);
|
|
96
85
|
const repository = meta?.repository;
|
|
@@ -102,7 +91,7 @@ function createMikroOrmRepositoryProviders(entities, contextName) {
|
|
|
102
91
|
});
|
|
103
92
|
}
|
|
104
93
|
providers.push({
|
|
105
|
-
provide:
|
|
94
|
+
provide: getRepositoryToken(entity, contextName),
|
|
106
95
|
useFactory: em => em.getRepository(entity),
|
|
107
96
|
inject: [inject],
|
|
108
97
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -11,22 +10,21 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
10
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
12
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const common_1 = require("@nestjs/common");
|
|
18
|
-
const mikro_orm_common_1 = require("./mikro-orm.common");
|
|
13
|
+
import { RequestContext } from '@mikro-orm/core';
|
|
14
|
+
import { Injectable } from '@nestjs/common';
|
|
15
|
+
import { InjectMikroORMs } from './mikro-orm.common.js';
|
|
19
16
|
let MultipleMikroOrmMiddleware = class MultipleMikroOrmMiddleware {
|
|
17
|
+
orm;
|
|
20
18
|
constructor(orm) {
|
|
21
19
|
this.orm = orm;
|
|
22
20
|
}
|
|
23
21
|
use(req, res, next) {
|
|
24
|
-
|
|
22
|
+
RequestContext.create(this.orm.map(orm => orm.em), next);
|
|
25
23
|
}
|
|
26
24
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
(0,
|
|
30
|
-
__param(0, (0, mikro_orm_common_1.InjectMikroORMs)()),
|
|
25
|
+
MultipleMikroOrmMiddleware = __decorate([
|
|
26
|
+
Injectable(),
|
|
27
|
+
__param(0, InjectMikroORMs()),
|
|
31
28
|
__metadata("design:paramtypes", [Array])
|
|
32
29
|
], MultipleMikroOrmMiddleware);
|
|
30
|
+
export { MultipleMikroOrmMiddleware };
|
package/package.json
CHANGED
|
@@ -1,71 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/nestjs",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "Martin Adamek",
|
|
7
|
-
"email": "banan23@gmail.com"
|
|
8
|
-
},
|
|
3
|
+
"version": "7.0.0-dev.1",
|
|
4
|
+
"description": "NestJS module for MikroORM",
|
|
9
5
|
"keywords": [
|
|
10
|
-
"
|
|
6
|
+
"data-mapper",
|
|
7
|
+
"ddd",
|
|
8
|
+
"entity",
|
|
9
|
+
"identity-map",
|
|
11
10
|
"mikro-orm",
|
|
12
|
-
"orm",
|
|
13
11
|
"mongo",
|
|
14
12
|
"mongodb",
|
|
15
13
|
"mysql",
|
|
14
|
+
"nestjs",
|
|
15
|
+
"orm",
|
|
16
16
|
"postgresql",
|
|
17
17
|
"sqlite",
|
|
18
|
-
"
|
|
19
|
-
"ddd",
|
|
20
|
-
"mikro-orm",
|
|
21
|
-
"unit-of-work",
|
|
22
|
-
"data-mapper",
|
|
23
|
-
"identity-map"
|
|
18
|
+
"unit-of-work"
|
|
24
19
|
],
|
|
25
|
-
"description": "NestJS module for MikroORM",
|
|
26
20
|
"homepage": "https://github.com/mikro-orm/nestjs#readme",
|
|
27
21
|
"bugs": "https://github.com/mikro-orm/nestjs/issues",
|
|
28
22
|
"repository": {
|
|
29
23
|
"type": "git",
|
|
30
24
|
"url": "https://github.com/mikro-orm/nestjs"
|
|
31
25
|
},
|
|
32
|
-
"
|
|
26
|
+
"author": {
|
|
27
|
+
"name": "Martin Adamek",
|
|
28
|
+
"email": "banan23@gmail.com"
|
|
29
|
+
},
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"type": "module",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": "./index.js",
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
33
36
|
"scripts": {
|
|
34
|
-
"build": "
|
|
35
|
-
"
|
|
37
|
+
"build": "yarn clean && yarn compile && yarn copy",
|
|
38
|
+
"clean": "rimraf ./dist",
|
|
39
|
+
"compile": "tsc -p tsconfig.build.json",
|
|
40
|
+
"copy": "node ./scripts/copy.mjs",
|
|
41
|
+
"test": "vitest --run",
|
|
36
42
|
"tsc-check-tests": "tsc --noEmit --project tests/tsconfig.json",
|
|
43
|
+
"format": "oxfmt --write .",
|
|
44
|
+
"lint": "oxlint --type-aware",
|
|
37
45
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1",
|
|
38
|
-
"
|
|
39
|
-
"coverage": "yarn test --coverage",
|
|
40
|
-
"lint": "eslint src/**/*.ts"
|
|
41
|
-
},
|
|
42
|
-
"peerDependencies": {
|
|
43
|
-
"@mikro-orm/core": "^6.0.0 || ^6.0.0-dev.0 || ^7.0.0-dev.0",
|
|
44
|
-
"@nestjs/common": "^10.0.0 || ^11.0.5",
|
|
45
|
-
"@nestjs/core": "^10.0.0 || ^11.0.5"
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"@mikro-orm/core": "^6.2.7",
|
|
49
|
-
"@mikro-orm/sqlite": "^6.2.7",
|
|
50
|
-
"@nestjs/common": "^11.0.5",
|
|
51
|
-
"@nestjs/core": "^11.0.5",
|
|
52
|
-
"@nestjs/platform-express": "^11.0.5",
|
|
53
|
-
"@nestjs/testing": "^11.0.5",
|
|
54
|
-
"@stylistic/eslint-plugin-ts": "^3.0.1",
|
|
55
|
-
"@types/jest": "^29.5.12",
|
|
56
|
-
"@types/node": "^22.0.0",
|
|
57
|
-
"@types/supertest": "^6.0.2",
|
|
58
|
-
"conventional-changelog": "^6.0.0",
|
|
59
|
-
"conventional-changelog-cli": "^5.0.0",
|
|
60
|
-
"eslint": "^9.19.0",
|
|
61
|
-
"eslint-plugin-import": "^2.31.0",
|
|
62
|
-
"jest": "^29.7.0",
|
|
63
|
-
"rxjs": "^7.8.1",
|
|
64
|
-
"supertest": "^7.0.0",
|
|
65
|
-
"ts-jest": "^29.1.2",
|
|
66
|
-
"ts-node": "^10.9.2",
|
|
67
|
-
"typescript": "5.7.3",
|
|
68
|
-
"typescript-eslint": "^8.22.0"
|
|
46
|
+
"coverage": "yarn test --coverage"
|
|
69
47
|
},
|
|
70
48
|
"commitlint": {
|
|
71
49
|
"extends": [
|
|
@@ -73,10 +51,44 @@
|
|
|
73
51
|
]
|
|
74
52
|
},
|
|
75
53
|
"lint-staged": {
|
|
76
|
-
"
|
|
77
|
-
"eslint src/**/*.ts --fix"
|
|
78
|
-
]
|
|
54
|
+
"*": "oxfmt --no-error-on-unmatched-pattern"
|
|
79
55
|
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@mikro-orm/core": "^7.0.0-dev.109",
|
|
58
|
+
"@mikro-orm/decorators": "^7.0.0-dev.109",
|
|
59
|
+
"@mikro-orm/sqlite": "^7.0.0-dev.109",
|
|
60
|
+
"@nestjs/common": "^11.1.9",
|
|
61
|
+
"@nestjs/core": "^11.1.9",
|
|
62
|
+
"@nestjs/platform-express": "^11.1.9",
|
|
63
|
+
"@nestjs/testing": "^11.1.9",
|
|
64
|
+
"@swc/core": "^1.15.5",
|
|
65
|
+
"@types/node": "^25.0.1",
|
|
66
|
+
"@types/supertest": "^6.0.3",
|
|
67
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
68
|
+
"conventional-changelog": "^7.1.1",
|
|
69
|
+
"conventional-changelog-cli": "^5.0.0",
|
|
70
|
+
"oxfmt": "^0.18.0",
|
|
71
|
+
"oxlint": "^1.33.0",
|
|
72
|
+
"oxlint-tsgolint": "^0.9.1",
|
|
73
|
+
"reflect-metadata": "^0.2.2",
|
|
74
|
+
"rimraf": "^6.1.2",
|
|
75
|
+
"rxjs": "^7.8.2",
|
|
76
|
+
"supertest": "^7.1.4",
|
|
77
|
+
"typescript": "5.9.3",
|
|
78
|
+
"unplugin-swc": "^1.5.9",
|
|
79
|
+
"vitest": "^4.0.16"
|
|
80
|
+
},
|
|
81
|
+
"peerDependencies": {
|
|
82
|
+
"@mikro-orm/core": "^7.0.0 || ^7.0.0-dev.0",
|
|
83
|
+
"@nestjs/common": "^11.0.5",
|
|
84
|
+
"@nestjs/core": "^11.0.5",
|
|
85
|
+
"reflect-metadata": "^0.1.0 || ^0.2.0"
|
|
86
|
+
},
|
|
87
|
+
"packageManager": "yarn@4.12.0",
|
|
88
|
+
"engines": {
|
|
89
|
+
"node": ">= 22.17.0"
|
|
90
|
+
},
|
|
91
|
+
"readme": "./README.md",
|
|
80
92
|
"renovate": {
|
|
81
93
|
"extends": [
|
|
82
94
|
"config:base",
|
|
@@ -101,9 +113,5 @@
|
|
|
101
113
|
"schedule": [
|
|
102
114
|
"every weekday"
|
|
103
115
|
]
|
|
104
|
-
}
|
|
105
|
-
"engines": {
|
|
106
|
-
"node": ">= 18.12.0"
|
|
107
|
-
},
|
|
108
|
-
"packageManager": "yarn@4.6.0"
|
|
116
|
+
}
|
|
109
117
|
}
|