@mikro-orm/nestjs 4.3.1 → 5.0.0
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/README.md +70 -2
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/middleware.helper.d.ts +3 -0
- package/middleware.helper.js +14 -0
- package/mikro-orm-core.module.d.ts +4 -2
- package/mikro-orm-core.module.js +46 -43
- package/mikro-orm-middleware.module.d.ts +22 -0
- package/mikro-orm-middleware.module.js +54 -0
- package/mikro-orm.common.d.ts +8 -4
- package/mikro-orm.common.js +15 -22
- package/mikro-orm.middleware.d.ts +1 -1
- package/mikro-orm.middleware.js +1 -1
- package/mikro-orm.module.d.ts +5 -4
- package/mikro-orm.module.js +10 -3
- package/mikro-orm.providers.d.ts +10 -9
- package/mikro-orm.providers.js +50 -40
- package/multiple-mikro-orm.middleware.d.ts +7 -0
- package/multiple-mikro-orm.middleware.js +31 -0
- package/package.json +60 -44
- package/typings.d.ts +10 -7
package/README.md
CHANGED
|
@@ -178,6 +178,8 @@ export class MyService {
|
|
|
178
178
|
|
|
179
179
|
## Using `AsyncLocalStorage` for request context
|
|
180
180
|
|
|
181
|
+
> Since v5 AsyncLocalStorage is used inside RequestContext helper so this section is no longer valid.
|
|
182
|
+
|
|
181
183
|
By default, the `domain` api is used in the `RequestContext` helper. Since `@mikro-orm/core@4.0.3`,
|
|
182
184
|
you can use the new `AsyncLocalStorage` too, if you are on up to date node version:
|
|
183
185
|
|
|
@@ -208,8 +210,7 @@ app.use((req, res, next) => {
|
|
|
208
210
|
|
|
209
211
|
## Using NestJS `Injection Scopes` for request context
|
|
210
212
|
|
|
211
|
-
|
|
212
|
-
you can use the new `Injection Scopes` (https://docs.nestjs.com/fundamentals/injection-scopes) too:
|
|
213
|
+
Since `@nestjs/common@6`, you can use the new `Injection Scopes` (https://docs.nestjs.com/fundamentals/injection-scopes) too:
|
|
213
214
|
|
|
214
215
|
```typescript
|
|
215
216
|
import { Scope } from '@nestjs/common';
|
|
@@ -317,6 +318,73 @@ async function bootstrap() {
|
|
|
317
318
|
|
|
318
319
|
More information about [enableShutdownHooks](https://docs.nestjs.com/fundamentals/lifecycle-events#application-shutdown)
|
|
319
320
|
|
|
321
|
+
## Multiple Database Connections
|
|
322
|
+
|
|
323
|
+
You can define multiple database connections by registering multiple `MikroOrmModule` and setting their `contextName`. If you want to use middleware request context you must disable automatic middleware and register `MikroOrmModule` with `forMiddleware()` or use NestJS `Injection Scope`
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
@Module({
|
|
327
|
+
imports: [
|
|
328
|
+
MikroOrmModule.forRoot({
|
|
329
|
+
contextName: 'db1',
|
|
330
|
+
registerRequestContext: false, // disable automatatic middleware
|
|
331
|
+
...
|
|
332
|
+
}),
|
|
333
|
+
MikroOrmModule.forRoot({
|
|
334
|
+
contextName: 'db2',
|
|
335
|
+
registerRequestContext: false, // disable automatatic middleware
|
|
336
|
+
...
|
|
337
|
+
}),
|
|
338
|
+
MikroOrmModule.forMiddleware()
|
|
339
|
+
],
|
|
340
|
+
controllers: [AppController],
|
|
341
|
+
providers: [AppService],
|
|
342
|
+
})
|
|
343
|
+
export class AppModule {}
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
To access different `MikroORM`/`EntityManager` connections you have to use the new injection tokens `@InjectMikroORM()`/`@InjectEntityManager()` where you are required to pass the `contextName` in:
|
|
347
|
+
|
|
348
|
+
```ts
|
|
349
|
+
@Injectable()
|
|
350
|
+
export class MyService {
|
|
351
|
+
|
|
352
|
+
constructor(@InjectMikroORM('db1') private readonly orm1: MikroORM,
|
|
353
|
+
@InjectMikroORM('db2') private readonly orm2: MikroORM,
|
|
354
|
+
@InjectEntityManager('db1') private readonly em1: EntityManager,
|
|
355
|
+
@InjectEntityManager('db2') private readonly em2: EntityManager) { }
|
|
356
|
+
|
|
357
|
+
}
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
When defining your repositories with `forFeature()` method you will need to set which `contextName` you want it registered against:
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
// photo.module.ts
|
|
364
|
+
|
|
365
|
+
@Module({
|
|
366
|
+
imports: [MikroOrmModule.forFeature([Photo], 'db1')],
|
|
367
|
+
providers: [PhotoService],
|
|
368
|
+
controllers: [PhotoController],
|
|
369
|
+
})
|
|
370
|
+
export class PhotoModule {}
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
When using the `@InjectRepository` decorator you will also need to pass the `contextName` you want to get it from:
|
|
374
|
+
|
|
375
|
+
```typescript
|
|
376
|
+
@Injectable()
|
|
377
|
+
export class PhotoService {
|
|
378
|
+
constructor(
|
|
379
|
+
@InjectRepository(Photo, 'db1')
|
|
380
|
+
private readonly photoRepository: EntityRepository<Photo>
|
|
381
|
+
) {}
|
|
382
|
+
|
|
383
|
+
// ...
|
|
384
|
+
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
320
388
|
## Testing
|
|
321
389
|
|
|
322
390
|
The `nestjs-mikro-orm` package exposes `getRepositoryToken()` function that returns prepared token based on a given entity to allow mocking the repository.
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -13,4 +13,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
13
|
__exportStar(require("./mikro-orm.module"), exports);
|
|
14
14
|
__exportStar(require("./mikro-orm.common"), exports);
|
|
15
15
|
__exportStar(require("./mikro-orm.middleware"), exports);
|
|
16
|
+
__exportStar(require("./multiple-mikro-orm.middleware"), exports);
|
|
16
17
|
__exportStar(require("./typings"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.forRoutesPath = void 0;
|
|
4
|
+
function forRoutesPath(options, consumer) {
|
|
5
|
+
const isNestMiddleware = (consumer) => {
|
|
6
|
+
return typeof consumer.httpAdapter === 'object';
|
|
7
|
+
};
|
|
8
|
+
const usingFastify = (consumer) => {
|
|
9
|
+
return consumer.httpAdapter.constructor.name.toLowerCase().startsWith('fastify');
|
|
10
|
+
};
|
|
11
|
+
return options.forRoutesPath ??
|
|
12
|
+
(isNestMiddleware(consumer) && usingFastify(consumer) ? '(.*)' : '*');
|
|
13
|
+
}
|
|
14
|
+
exports.forRoutesPath = forRoutesPath;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { DynamicModule, MiddlewareConsumer, OnApplicationShutdown } from '@nestjs/common';
|
|
1
|
+
import type { DynamicModule, MiddlewareConsumer, OnApplicationShutdown } from '@nestjs/common';
|
|
2
2
|
import { ModuleRef } from '@nestjs/core';
|
|
3
|
-
import { MikroOrmModuleAsyncOptions,
|
|
3
|
+
import type { MikroOrmModuleAsyncOptions, MikroOrmModuleSyncOptions } from './typings';
|
|
4
|
+
import { MikroOrmModuleOptions } from './typings';
|
|
4
5
|
export declare class MikroOrmCoreModule implements OnApplicationShutdown {
|
|
5
6
|
private readonly options;
|
|
6
7
|
private readonly moduleRef;
|
|
@@ -9,4 +10,5 @@ export declare class MikroOrmCoreModule implements OnApplicationShutdown {
|
|
|
9
10
|
static forRootAsync(options: MikroOrmModuleAsyncOptions): Promise<DynamicModule>;
|
|
10
11
|
onApplicationShutdown(): Promise<void>;
|
|
11
12
|
configure(consumer: MiddlewareConsumer): void;
|
|
13
|
+
private static setContextName;
|
|
12
14
|
}
|
package/mikro-orm-core.module.js
CHANGED
|
@@ -37,22 +37,15 @@ const core_1 = require("@mikro-orm/core");
|
|
|
37
37
|
const common_1 = require("@nestjs/common");
|
|
38
38
|
const core_2 = require("@nestjs/core");
|
|
39
39
|
const mikro_orm_common_1 = require("./mikro-orm.common");
|
|
40
|
-
const mikro_orm_middleware_1 = require("./mikro-orm.middleware");
|
|
41
40
|
const mikro_orm_providers_1 = require("./mikro-orm.providers");
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
EntityManagerModuleName["MongoDb"] = "@mikro-orm/mongodb";
|
|
46
|
-
})(EntityManagerModuleName || (EntityManagerModuleName = {}));
|
|
47
|
-
async function whenModuleAvailable(moduleName, returnFn) {
|
|
41
|
+
const mikro_orm_middleware_1 = require("./mikro-orm.middleware");
|
|
42
|
+
const middleware_helper_1 = require("./middleware.helper");
|
|
43
|
+
async function tryRequire(cb) {
|
|
48
44
|
try {
|
|
49
|
-
|
|
50
|
-
// TReturnValue may be incorrect if expecting it to extend Promise<T> since its being awaited in the return
|
|
51
|
-
// casting to Awaited<TReturnValue> to satisfy the return type will prevent that confusion
|
|
52
|
-
return [await returnFn(module)];
|
|
45
|
+
return await cb();
|
|
53
46
|
}
|
|
54
|
-
catch
|
|
55
|
-
return
|
|
47
|
+
catch {
|
|
48
|
+
return undefined; // ignore, optional dependency
|
|
56
49
|
}
|
|
57
50
|
}
|
|
58
51
|
let MikroOrmCoreModule = MikroOrmCoreModule_1 = class MikroOrmCoreModule {
|
|
@@ -61,70 +54,80 @@ let MikroOrmCoreModule = MikroOrmCoreModule_1 = class MikroOrmCoreModule {
|
|
|
61
54
|
this.moduleRef = moduleRef;
|
|
62
55
|
}
|
|
63
56
|
static async forRoot(options) {
|
|
57
|
+
const contextName = this.setContextName(options?.contextName);
|
|
58
|
+
const knex = await tryRequire(() => Promise.resolve().then(() => __importStar(require('@mikro-orm/knex'))));
|
|
59
|
+
const mongo = await tryRequire(() => Promise.resolve().then(() => __importStar(require('@mikro-orm/mongodb'))));
|
|
64
60
|
return {
|
|
65
61
|
module: MikroOrmCoreModule_1,
|
|
66
62
|
providers: [
|
|
67
63
|
{ provide: mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS, useValue: options || {} },
|
|
68
|
-
mikro_orm_providers_1.createMikroOrmProvider(),
|
|
69
|
-
mikro_orm_providers_1.
|
|
70
|
-
...(
|
|
71
|
-
...(
|
|
64
|
+
(0, mikro_orm_providers_1.createMikroOrmProvider)(contextName),
|
|
65
|
+
(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, core_1.EntityManager, contextName),
|
|
66
|
+
...(knex ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, contextName ? (0, mikro_orm_common_1.getEntityManagerToken)(contextName) : knex.SqlEntityManager, contextName)] : []),
|
|
67
|
+
...(mongo ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, contextName ? (0, mikro_orm_common_1.getEntityManagerToken)(contextName) : mongo.MongoEntityManager, contextName)] : []),
|
|
72
68
|
],
|
|
73
69
|
exports: [
|
|
74
|
-
core_1.MikroORM,
|
|
75
|
-
core_1.EntityManager,
|
|
76
|
-
...(
|
|
77
|
-
...(
|
|
70
|
+
contextName ? (0, mikro_orm_common_1.getMikroORMToken)(contextName) : core_1.MikroORM,
|
|
71
|
+
contextName ? (0, mikro_orm_common_1.getEntityManagerToken)(contextName) : core_1.EntityManager,
|
|
72
|
+
...(knex ? (contextName ? [] : [knex.SqlEntityManager]) : []),
|
|
73
|
+
...(mongo ? (contextName ? [] : [mongo.MongoEntityManager]) : []),
|
|
78
74
|
],
|
|
79
75
|
};
|
|
80
76
|
}
|
|
81
77
|
static async forRootAsync(options) {
|
|
78
|
+
const contextName = this.setContextName(options?.contextName);
|
|
79
|
+
const knex = await tryRequire(() => Promise.resolve().then(() => __importStar(require('@mikro-orm/knex'))));
|
|
80
|
+
const mongo = await tryRequire(() => Promise.resolve().then(() => __importStar(require('@mikro-orm/mongodb'))));
|
|
82
81
|
return {
|
|
83
82
|
module: MikroOrmCoreModule_1,
|
|
84
83
|
imports: options.imports || [],
|
|
85
84
|
providers: [
|
|
86
85
|
...(options.providers || []),
|
|
87
|
-
...mikro_orm_providers_1.createAsyncProviders(options),
|
|
88
|
-
mikro_orm_providers_1.createMikroOrmProvider(),
|
|
89
|
-
mikro_orm_providers_1.
|
|
90
|
-
...(
|
|
91
|
-
...(
|
|
86
|
+
...(0, mikro_orm_providers_1.createAsyncProviders)({ ...options, contextName: options.contextName }),
|
|
87
|
+
(0, mikro_orm_providers_1.createMikroOrmProvider)(contextName),
|
|
88
|
+
(0, mikro_orm_providers_1.createEntityManagerProvider)(options.scope, core_1.EntityManager, contextName),
|
|
89
|
+
...(knex ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, contextName ? (0, mikro_orm_common_1.getEntityManagerToken)(contextName) : knex.SqlEntityManager, contextName)] : []),
|
|
90
|
+
...(mongo ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, contextName ? (0, mikro_orm_common_1.getEntityManagerToken)(contextName) : mongo.MongoEntityManager, contextName)] : []),
|
|
92
91
|
],
|
|
93
92
|
exports: [
|
|
94
|
-
core_1.MikroORM,
|
|
95
|
-
core_1.EntityManager,
|
|
96
|
-
...(
|
|
97
|
-
...(
|
|
93
|
+
contextName ? (0, mikro_orm_common_1.getMikroORMToken)(contextName) : core_1.MikroORM,
|
|
94
|
+
contextName ? (0, mikro_orm_common_1.getEntityManagerToken)(contextName) : core_1.EntityManager,
|
|
95
|
+
...(knex ? (contextName ? [] : [knex.SqlEntityManager]) : []),
|
|
96
|
+
...(mongo ? (contextName ? [] : [mongo.MongoEntityManager]) : []),
|
|
98
97
|
],
|
|
99
98
|
};
|
|
100
99
|
}
|
|
101
100
|
async onApplicationShutdown() {
|
|
102
|
-
const
|
|
101
|
+
const token = this.options.contextName ? (0, mikro_orm_common_1.getMikroORMToken)(this.options.contextName) : core_1.MikroORM;
|
|
102
|
+
const orm = this.moduleRef.get(token);
|
|
103
103
|
if (orm) {
|
|
104
104
|
await orm.close();
|
|
105
105
|
}
|
|
106
|
+
mikro_orm_common_1.CONTEXT_NAMES.length = 0;
|
|
106
107
|
}
|
|
107
108
|
configure(consumer) {
|
|
108
|
-
var _a;
|
|
109
109
|
if (this.options.registerRequestContext === false) {
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
|
-
const isNestMiddleware = (consumer) => {
|
|
113
|
-
return typeof consumer.httpAdapter === 'object';
|
|
114
|
-
};
|
|
115
|
-
const usingFastify = (consumer) => {
|
|
116
|
-
return consumer.httpAdapter.constructor.name.toLowerCase().startsWith('fastify');
|
|
117
|
-
};
|
|
118
|
-
const forRoutesPath = (_a = this.options.forRoutesPath) !== null && _a !== void 0 ? _a : (isNestMiddleware(consumer) && usingFastify(consumer) ? '(.*)' : '*');
|
|
119
112
|
consumer
|
|
120
113
|
.apply(mikro_orm_middleware_1.MikroOrmMiddleware) // register request context automatically
|
|
121
|
-
.forRoutes({ path: forRoutesPath, method: common_1.RequestMethod.ALL });
|
|
114
|
+
.forRoutes({ path: (0, middleware_helper_1.forRoutesPath)(this.options, consumer), method: common_1.RequestMethod.ALL });
|
|
115
|
+
}
|
|
116
|
+
static setContextName(contextName) {
|
|
117
|
+
if (!contextName) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (mikro_orm_common_1.CONTEXT_NAMES.includes(contextName)) {
|
|
121
|
+
throw new Error(`ContextName '${contextName}' already registered`);
|
|
122
|
+
}
|
|
123
|
+
mikro_orm_common_1.CONTEXT_NAMES.push(contextName);
|
|
124
|
+
return contextName;
|
|
122
125
|
}
|
|
123
126
|
};
|
|
124
127
|
MikroOrmCoreModule = MikroOrmCoreModule_1 = __decorate([
|
|
125
|
-
common_1.Global(),
|
|
126
|
-
common_1.Module({}),
|
|
127
|
-
__param(0, common_1.Inject(mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS)),
|
|
128
|
+
(0, common_1.Global)(),
|
|
129
|
+
(0, common_1.Module)({}),
|
|
130
|
+
__param(0, (0, common_1.Inject)(mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS)),
|
|
128
131
|
__metadata("design:paramtypes", [Object, core_2.ModuleRef])
|
|
129
132
|
], MikroOrmCoreModule);
|
|
130
133
|
exports.MikroOrmCoreModule = MikroOrmCoreModule;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { MiddlewareConsumer } from '@nestjs/common';
|
|
2
|
+
import { MikroOrmMiddlewareModuleOptions } from './typings';
|
|
3
|
+
import type { MikroORM } from '@mikro-orm/core';
|
|
4
|
+
export declare class MikroOrmMiddlewareModule {
|
|
5
|
+
private readonly options;
|
|
6
|
+
constructor(options: MikroOrmMiddlewareModuleOptions);
|
|
7
|
+
static forMiddleware(options?: MikroOrmMiddlewareModuleOptions): {
|
|
8
|
+
module: typeof MikroOrmMiddlewareModule;
|
|
9
|
+
providers: ({
|
|
10
|
+
provide: symbol;
|
|
11
|
+
useValue: MikroOrmMiddlewareModuleOptions;
|
|
12
|
+
useFactory?: undefined;
|
|
13
|
+
inject?: undefined;
|
|
14
|
+
} | {
|
|
15
|
+
provide: string;
|
|
16
|
+
useFactory: (...args: MikroORM[]) => MikroORM<import("@mikro-orm/core").IDatabaseDriver<import("@mikro-orm/core").Connection>>[];
|
|
17
|
+
inject: string[];
|
|
18
|
+
useValue?: undefined;
|
|
19
|
+
})[];
|
|
20
|
+
};
|
|
21
|
+
configure(consumer: MiddlewareConsumer): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var MikroOrmMiddlewareModule_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.MikroOrmMiddlewareModule = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const mikro_orm_common_1 = require("./mikro-orm.common");
|
|
19
|
+
const multiple_mikro_orm_middleware_1 = require("./multiple-mikro-orm.middleware");
|
|
20
|
+
const middleware_helper_1 = require("./middleware.helper");
|
|
21
|
+
let MikroOrmMiddlewareModule = MikroOrmMiddlewareModule_1 = class MikroOrmMiddlewareModule {
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.options = options;
|
|
24
|
+
}
|
|
25
|
+
static forMiddleware(options) {
|
|
26
|
+
// Work around due to nestjs not supporting the ability to register multiple types
|
|
27
|
+
// https://github.com/nestjs/nest/issues/770
|
|
28
|
+
// https://github.com/nestjs/nest/issues/4786#issuecomment-755032258 - workaround suggestion
|
|
29
|
+
const inject = mikro_orm_common_1.CONTEXT_NAMES.map(name => (0, mikro_orm_common_1.getMikroORMToken)(name));
|
|
30
|
+
return {
|
|
31
|
+
module: MikroOrmMiddlewareModule_1,
|
|
32
|
+
providers: [
|
|
33
|
+
{ provide: mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS, useValue: options || {} },
|
|
34
|
+
{
|
|
35
|
+
provide: 'MikroORMs',
|
|
36
|
+
useFactory: (...args) => args,
|
|
37
|
+
inject,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
configure(consumer) {
|
|
43
|
+
consumer
|
|
44
|
+
.apply(multiple_mikro_orm_middleware_1.MultipleMikroOrmMiddleware)
|
|
45
|
+
.forRoutes({ path: (0, middleware_helper_1.forRoutesPath)(this.options, consumer), method: common_1.RequestMethod.ALL });
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
MikroOrmMiddlewareModule = MikroOrmMiddlewareModule_1 = __decorate([
|
|
49
|
+
(0, common_1.Global)(),
|
|
50
|
+
(0, common_1.Module)({}),
|
|
51
|
+
__param(0, (0, common_1.Inject)(mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS)),
|
|
52
|
+
__metadata("design:paramtypes", [Object])
|
|
53
|
+
], MikroOrmMiddlewareModule);
|
|
54
|
+
exports.MikroOrmMiddlewareModule = MikroOrmMiddlewareModule;
|
package/mikro-orm.common.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { AnyEntity, EntityName } from '@mikro-orm/core';
|
|
1
|
+
import type { AnyEntity, EntityName } from '@mikro-orm/core';
|
|
2
2
|
import { Logger } from '@nestjs/common';
|
|
3
3
|
export declare const MIKRO_ORM_MODULE_OPTIONS: unique symbol;
|
|
4
4
|
export declare const REGISTERED_ENTITIES: Set<EntityName<AnyEntity<any>>>;
|
|
5
|
+
export declare const CONTEXT_NAMES: string[];
|
|
5
6
|
export declare const logger: Logger;
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare
|
|
7
|
+
export declare const getMikroORMToken: (name: string) => string;
|
|
8
|
+
export declare const InjectMikroORM: (name: string) => (target: object, key: string | symbol, index?: number | undefined) => void;
|
|
9
|
+
export declare const getEntityManagerToken: (name: string) => string;
|
|
10
|
+
export declare const InjectEntityManager: (name: string) => (target: object, key: string | symbol, index?: number | undefined) => void;
|
|
11
|
+
export declare const getRepositoryToken: <T>(entity: EntityName<T>, name?: string | undefined) => string;
|
|
12
|
+
export declare const InjectRepository: <T>(entity: EntityName<T>, name?: string | undefined) => (target: object, key: string | symbol, index?: number | undefined) => void;
|
package/mikro-orm.common.js
CHANGED
|
@@ -1,31 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.InjectRepository = exports.getRepositoryToken = exports.InjectEntityManager = exports.getEntityManagerToken = exports.InjectMikroORM = exports.getMikroORMToken = exports.logger = exports.CONTEXT_NAMES = exports.REGISTERED_ENTITIES = exports.MIKRO_ORM_MODULE_OPTIONS = void 0;
|
|
4
4
|
const core_1 = require("@mikro-orm/core");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
exports.MIKRO_ORM_MODULE_OPTIONS = Symbol('mikro-orm-module-options');
|
|
7
7
|
exports.REGISTERED_ENTITIES = new Set();
|
|
8
|
+
exports.CONTEXT_NAMES = [];
|
|
8
9
|
exports.logger = new common_1.Logger(core_1.MikroORM.name);
|
|
9
|
-
const
|
|
10
|
+
const getMikroORMToken = (name) => `${name}_MikroORM`;
|
|
11
|
+
exports.getMikroORMToken = getMikroORMToken;
|
|
12
|
+
const InjectMikroORM = (name) => (0, common_1.Inject)((0, exports.getMikroORMToken)(name));
|
|
13
|
+
exports.InjectMikroORM = InjectMikroORM;
|
|
14
|
+
const getEntityManagerToken = (name) => `${name}_EntityManager`;
|
|
15
|
+
exports.getEntityManagerToken = getEntityManagerToken;
|
|
16
|
+
const InjectEntityManager = (name) => (0, common_1.Inject)((0, exports.getEntityManagerToken)(name));
|
|
17
|
+
exports.InjectEntityManager = InjectEntityManager;
|
|
18
|
+
const getRepositoryToken = (entity, name) => {
|
|
19
|
+
const suffix = name ? `_${name}` : '';
|
|
20
|
+
return `${core_1.Utils.className(entity)}Repository${suffix}`;
|
|
21
|
+
};
|
|
10
22
|
exports.getRepositoryToken = getRepositoryToken;
|
|
11
|
-
const InjectRepository = (entity) => common_1.Inject(exports.getRepositoryToken(entity));
|
|
23
|
+
const InjectRepository = (entity, name) => (0, common_1.Inject)((0, exports.getRepositoryToken)(entity, name));
|
|
12
24
|
exports.InjectRepository = InjectRepository;
|
|
13
|
-
function UseRequestContext() {
|
|
14
|
-
return function (target, propertyKey, descriptor) {
|
|
15
|
-
const originalMethod = descriptor.value;
|
|
16
|
-
descriptor.value = async function (...args) {
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
18
|
-
const context = this;
|
|
19
|
-
if (!(context.orm instanceof core_1.MikroORM)) {
|
|
20
|
-
throw new Error('@UseRequestContext() decorator can only be applied to methods of classes that carry `orm: MikroORM`');
|
|
21
|
-
}
|
|
22
|
-
let result;
|
|
23
|
-
await core_1.RequestContext.createAsync(context.orm.em, async () => {
|
|
24
|
-
result = await originalMethod.apply(context, args);
|
|
25
|
-
});
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
return descriptor;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
exports.UseRequestContext = UseRequestContext;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MikroORM } from '@mikro-orm/core';
|
|
2
|
-
import { NestMiddleware } from '@nestjs/common';
|
|
2
|
+
import type { NestMiddleware } from '@nestjs/common';
|
|
3
3
|
export declare class MikroOrmMiddleware implements NestMiddleware {
|
|
4
4
|
private readonly orm;
|
|
5
5
|
constructor(orm: MikroORM);
|
package/mikro-orm.middleware.js
CHANGED
|
@@ -21,7 +21,7 @@ let MikroOrmMiddleware = class MikroOrmMiddleware {
|
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
MikroOrmMiddleware = __decorate([
|
|
24
|
-
common_1.Injectable(),
|
|
24
|
+
(0, common_1.Injectable)(),
|
|
25
25
|
__metadata("design:paramtypes", [core_1.MikroORM])
|
|
26
26
|
], MikroOrmMiddleware);
|
|
27
27
|
exports.MikroOrmMiddleware = MikroOrmMiddleware;
|
package/mikro-orm.module.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { AnyEntity, EntityName } from '@mikro-orm/core';
|
|
2
|
-
import { DynamicModule } from '@nestjs/common';
|
|
3
|
-
import { MikroOrmModuleAsyncOptions, MikroOrmModuleSyncOptions } from './typings';
|
|
1
|
+
import type { AnyEntity, EntityName } from '@mikro-orm/core';
|
|
2
|
+
import type { DynamicModule } from '@nestjs/common';
|
|
3
|
+
import type { MikroOrmModuleAsyncOptions, MikroOrmModuleSyncOptions, MikroOrmMiddlewareModuleOptions } from './typings';
|
|
4
4
|
export declare class MikroOrmModule {
|
|
5
5
|
static forRoot(options?: MikroOrmModuleSyncOptions): DynamicModule;
|
|
6
6
|
static forRootAsync(options: MikroOrmModuleAsyncOptions): DynamicModule;
|
|
7
7
|
static forFeature(options: EntityName<AnyEntity>[] | {
|
|
8
8
|
entities?: EntityName<AnyEntity>[];
|
|
9
|
-
}): DynamicModule;
|
|
9
|
+
}, contextName?: string): DynamicModule;
|
|
10
|
+
static forMiddleware(options?: MikroOrmMiddlewareModuleOptions): DynamicModule;
|
|
10
11
|
}
|
package/mikro-orm.module.js
CHANGED
|
@@ -13,6 +13,7 @@ const common_1 = require("@nestjs/common");
|
|
|
13
13
|
const mikro_orm_providers_1 = require("./mikro-orm.providers");
|
|
14
14
|
const mikro_orm_core_module_1 = require("./mikro-orm-core.module");
|
|
15
15
|
const mikro_orm_common_1 = require("./mikro-orm.common");
|
|
16
|
+
const mikro_orm_middleware_module_1 = require("./mikro-orm-middleware.module");
|
|
16
17
|
let MikroOrmModule = MikroOrmModule_1 = class MikroOrmModule {
|
|
17
18
|
static forRoot(options) {
|
|
18
19
|
return {
|
|
@@ -26,9 +27,9 @@ let MikroOrmModule = MikroOrmModule_1 = class MikroOrmModule {
|
|
|
26
27
|
imports: [mikro_orm_core_module_1.MikroOrmCoreModule.forRootAsync(options)],
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
|
-
static forFeature(options) {
|
|
30
|
+
static forFeature(options, contextName) {
|
|
30
31
|
const entities = Array.isArray(options) ? options : (options.entities || []);
|
|
31
|
-
const providers = mikro_orm_providers_1.createMikroOrmRepositoryProviders(entities);
|
|
32
|
+
const providers = (0, mikro_orm_providers_1.createMikroOrmRepositoryProviders)(entities, contextName);
|
|
32
33
|
for (const e of entities) {
|
|
33
34
|
if (!core_1.Utils.isString(e)) {
|
|
34
35
|
mikro_orm_common_1.REGISTERED_ENTITIES.add(e);
|
|
@@ -40,8 +41,14 @@ let MikroOrmModule = MikroOrmModule_1 = class MikroOrmModule {
|
|
|
40
41
|
exports: [...providers],
|
|
41
42
|
};
|
|
42
43
|
}
|
|
44
|
+
static forMiddleware(options) {
|
|
45
|
+
return {
|
|
46
|
+
module: MikroOrmModule_1,
|
|
47
|
+
imports: [mikro_orm_middleware_module_1.MikroOrmMiddlewareModule.forMiddleware(options)],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
43
50
|
};
|
|
44
51
|
MikroOrmModule = MikroOrmModule_1 = __decorate([
|
|
45
|
-
common_1.Module({})
|
|
52
|
+
(0, common_1.Module)({})
|
|
46
53
|
], MikroOrmModule);
|
|
47
54
|
exports.MikroOrmModule = MikroOrmModule;
|
package/mikro-orm.providers.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { AnyEntity,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare
|
|
7
|
-
export declare
|
|
8
|
-
export declare
|
|
9
|
-
export declare
|
|
1
|
+
import type { AnyEntity, EntityName } from '@mikro-orm/core';
|
|
2
|
+
import { EntityManager } from '@mikro-orm/core';
|
|
3
|
+
import type { MikroOrmModuleAsyncOptions } from './typings';
|
|
4
|
+
import type { Provider } from '@nestjs/common';
|
|
5
|
+
import { Scope } from '@nestjs/common';
|
|
6
|
+
export declare function createMikroOrmProvider(contextName?: string): Provider;
|
|
7
|
+
export declare function createEntityManagerProvider(scope?: Scope, entityManager?: any, contextName?: string): Provider<EntityManager>;
|
|
8
|
+
export declare function createMikroOrmAsyncOptionsProvider(options: MikroOrmModuleAsyncOptions): Provider;
|
|
9
|
+
export declare function createAsyncProviders(options: MikroOrmModuleAsyncOptions): Provider[];
|
|
10
|
+
export declare function createMikroOrmRepositoryProviders(entities: EntityName<AnyEntity>[], contextName?: string): Provider[];
|
package/mikro-orm.providers.js
CHANGED
|
@@ -1,37 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createMikroOrmRepositoryProviders = exports.createAsyncProviders = exports.createMikroOrmAsyncOptionsProvider = exports.
|
|
3
|
+
exports.createMikroOrmRepositoryProviders = exports.createAsyncProviders = exports.createMikroOrmAsyncOptionsProvider = exports.createEntityManagerProvider = exports.createMikroOrmProvider = void 0;
|
|
4
4
|
const mikro_orm_common_1 = require("./mikro-orm.common");
|
|
5
5
|
const core_1 = require("@mikro-orm/core");
|
|
6
6
|
const common_1 = require("@nestjs/common");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
function createMikroOrmProvider(contextName) {
|
|
8
|
+
return {
|
|
9
|
+
provide: contextName ? (0, mikro_orm_common_1.getMikroORMToken)(contextName) : core_1.MikroORM,
|
|
10
|
+
useFactory: async (options) => {
|
|
11
|
+
if (options?.autoLoadEntities) {
|
|
12
|
+
options.entities = [...(options.entities || []), ...mikro_orm_common_1.REGISTERED_ENTITIES.values()];
|
|
13
|
+
options.entitiesTs = [...(options.entitiesTs || []), ...mikro_orm_common_1.REGISTERED_ENTITIES.values()];
|
|
14
|
+
delete options.autoLoadEntities;
|
|
15
|
+
}
|
|
16
|
+
mikro_orm_common_1.REGISTERED_ENTITIES.clear();
|
|
17
|
+
if (!options || Object.keys(options).length === 0) {
|
|
18
|
+
const config = await core_1.ConfigurationLoader.getConfiguration();
|
|
19
|
+
config.set('logger', mikro_orm_common_1.logger.log.bind(mikro_orm_common_1.logger));
|
|
20
|
+
options = config;
|
|
21
|
+
}
|
|
22
|
+
return core_1.MikroORM.init(options);
|
|
23
|
+
},
|
|
24
|
+
inject: [mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
25
27
|
exports.createMikroOrmProvider = createMikroOrmProvider;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
function createEntityManagerProvider(scope = common_1.Scope.DEFAULT, entityManager = core_1.EntityManager, contextName) {
|
|
29
|
+
function getProvide() {
|
|
30
|
+
if (core_1.Utils.isString(entityManager)) {
|
|
31
|
+
return entityManager;
|
|
32
|
+
}
|
|
33
|
+
return contextName ? (0, mikro_orm_common_1.getEntityManagerToken)(contextName) : entityManager;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
provide: getProvide(),
|
|
37
|
+
scope,
|
|
38
|
+
useFactory: (orm) => scope === common_1.Scope.DEFAULT ? orm.em : orm.em.fork(),
|
|
39
|
+
inject: [contextName ? (0, mikro_orm_common_1.getMikroORMToken)(contextName) : core_1.MikroORM],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
exports.createEntityManagerProvider = createEntityManagerProvider;
|
|
43
|
+
function createMikroOrmAsyncOptionsProvider(options) {
|
|
35
44
|
if (options.useFactory) {
|
|
36
45
|
return {
|
|
37
46
|
provide: mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS,
|
|
@@ -41,46 +50,47 @@ const createMikroOrmAsyncOptionsProvider = (options) => {
|
|
|
41
50
|
}
|
|
42
51
|
const inject = [];
|
|
43
52
|
if (options.useClass || options.useExisting) {
|
|
44
|
-
inject.push(
|
|
53
|
+
inject.push(options.useClass ?? options.useExisting);
|
|
45
54
|
}
|
|
46
55
|
return {
|
|
47
56
|
provide: mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS,
|
|
48
57
|
useFactory: async (optionsFactory) => await optionsFactory.createMikroOrmOptions(),
|
|
49
58
|
inject,
|
|
50
59
|
};
|
|
51
|
-
}
|
|
60
|
+
}
|
|
52
61
|
exports.createMikroOrmAsyncOptionsProvider = createMikroOrmAsyncOptionsProvider;
|
|
53
|
-
|
|
62
|
+
function createAsyncProviders(options) {
|
|
54
63
|
if (options.useExisting || options.useFactory) {
|
|
55
|
-
return [
|
|
64
|
+
return [createMikroOrmAsyncOptionsProvider(options)];
|
|
56
65
|
}
|
|
57
66
|
if (options.useClass) {
|
|
58
67
|
return [
|
|
59
|
-
|
|
68
|
+
createMikroOrmAsyncOptionsProvider(options),
|
|
60
69
|
{ provide: options.useClass, useClass: options.useClass },
|
|
61
70
|
];
|
|
62
71
|
}
|
|
63
72
|
throw new Error('Invalid MikroORM async options: one of `useClass`, `useExisting` or `useFactory` should be defined.');
|
|
64
|
-
}
|
|
73
|
+
}
|
|
65
74
|
exports.createAsyncProviders = createAsyncProviders;
|
|
66
|
-
|
|
75
|
+
function createMikroOrmRepositoryProviders(entities, contextName) {
|
|
67
76
|
const metadata = Object.values(core_1.MetadataStorage.getMetadata());
|
|
68
77
|
const providers = [];
|
|
78
|
+
const inject = contextName ? (0, mikro_orm_common_1.getEntityManagerToken)(contextName) : core_1.EntityManager;
|
|
69
79
|
(entities || []).forEach(entity => {
|
|
70
80
|
const meta = metadata.find(meta => meta.class === entity);
|
|
71
|
-
if (meta
|
|
81
|
+
if (meta?.customRepository) {
|
|
72
82
|
providers.push({
|
|
73
83
|
provide: meta.customRepository(),
|
|
74
84
|
useFactory: em => em.getRepository(entity),
|
|
75
|
-
inject: [
|
|
85
|
+
inject: [inject],
|
|
76
86
|
});
|
|
77
87
|
}
|
|
78
88
|
providers.push({
|
|
79
|
-
provide: mikro_orm_common_1.getRepositoryToken(entity),
|
|
89
|
+
provide: (0, mikro_orm_common_1.getRepositoryToken)(entity, contextName),
|
|
80
90
|
useFactory: em => em.getRepository(entity),
|
|
81
|
-
inject: [
|
|
91
|
+
inject: [inject],
|
|
82
92
|
});
|
|
83
93
|
});
|
|
84
94
|
return providers;
|
|
85
|
-
}
|
|
95
|
+
}
|
|
86
96
|
exports.createMikroOrmRepositoryProviders = createMikroOrmRepositoryProviders;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MikroORM } from '@mikro-orm/core';
|
|
2
|
+
import type { NestMiddleware } from '@nestjs/common';
|
|
3
|
+
export declare class MultipleMikroOrmMiddleware implements NestMiddleware {
|
|
4
|
+
private readonly orm;
|
|
5
|
+
constructor(orm: MikroORM[]);
|
|
6
|
+
use(req: unknown, res: unknown, next: (...args: any[]) => void): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MultipleMikroOrmMiddleware = void 0;
|
|
16
|
+
const core_1 = require("@mikro-orm/core");
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
let MultipleMikroOrmMiddleware = class MultipleMikroOrmMiddleware {
|
|
19
|
+
constructor(orm) {
|
|
20
|
+
this.orm = orm;
|
|
21
|
+
}
|
|
22
|
+
use(req, res, next) {
|
|
23
|
+
core_1.RequestContext.create(this.orm.map(orm => orm.em), next);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
MultipleMikroOrmMiddleware = __decorate([
|
|
27
|
+
(0, common_1.Injectable)(),
|
|
28
|
+
__param(0, (0, common_1.Inject)('MikroORMs')),
|
|
29
|
+
__metadata("design:paramtypes", [Array])
|
|
30
|
+
], MultipleMikroOrmMiddleware);
|
|
31
|
+
exports.MultipleMikroOrmMiddleware = MultipleMikroOrmMiddleware;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/nestjs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
|
-
"name": "
|
|
7
|
-
"email": "
|
|
6
|
+
"name": "Martin Adamek",
|
|
7
|
+
"email": "banan23@gmail.com"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
10
10
|
"nestjs",
|
|
@@ -37,55 +37,52 @@
|
|
|
37
37
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1",
|
|
38
38
|
"release": "yarn build && cd dist && npm publish && cd ..",
|
|
39
39
|
"coverage": "yarn test --coverage",
|
|
40
|
-
"coveralls": "cat ./coverage/lcov.info | coveralls",
|
|
41
40
|
"lint": "eslint src/**/*.ts"
|
|
42
41
|
},
|
|
43
42
|
"peerDependencies": {
|
|
44
|
-
"@mikro-orm/core": "^
|
|
45
|
-
"@
|
|
46
|
-
"@
|
|
43
|
+
"@mikro-orm/core": "^5.0.0",
|
|
44
|
+
"@mikro-orm/knex": "^5.0.0",
|
|
45
|
+
"@mikro-orm/mongodb": "^5.0.0",
|
|
46
|
+
"@nestjs/common": "^8.0.0",
|
|
47
|
+
"@nestjs/core": "^8.0.0"
|
|
47
48
|
},
|
|
48
|
-
"
|
|
49
|
-
"@mikro-orm/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"@
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"@typescript-eslint/eslint-plugin": "~3.9.1",
|
|
56
|
-
"@typescript-eslint/parser": "~3.9.1",
|
|
57
|
-
"conventional-changelog": "^3.1.23",
|
|
58
|
-
"conventional-changelog-cli": "^2.1.1",
|
|
59
|
-
"eslint": "^7.7.0",
|
|
60
|
-
"eslint-plugin-jsdoc": "^30.2.4",
|
|
61
|
-
"jest": "^26.4.0",
|
|
62
|
-
"rxjs": "^6.6.2",
|
|
63
|
-
"ts-jest": "^26.2.0",
|
|
64
|
-
"typescript": "4.3.5"
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"@mikro-orm/knex": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"@mikro-orm/mongodb": {
|
|
54
|
+
"optional": true
|
|
55
|
+
}
|
|
65
56
|
},
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@mikro-orm/core": "^5.0.3",
|
|
59
|
+
"@mikro-orm/sqlite": "^5.0.3",
|
|
60
|
+
"@mikro-orm/mongodb": "^5.0.3",
|
|
61
|
+
"@mikro-orm/knex": "^5.0.3",
|
|
62
|
+
"@nestjs/common": "^8.2.6",
|
|
63
|
+
"@nestjs/core": "^8.2.6",
|
|
64
|
+
"@nestjs/platform-express": "^8.2.6",
|
|
65
|
+
"@nestjs/testing": "^8.2.6",
|
|
66
|
+
"@types/jest": "^27.4.0",
|
|
67
|
+
"@types/node": "^17.0.17",
|
|
68
|
+
"@types/supertest": "^2.0.11",
|
|
69
|
+
"@typescript-eslint/eslint-plugin": "~5.12.0",
|
|
70
|
+
"@typescript-eslint/parser": "~5.12.0",
|
|
71
|
+
"conventional-changelog": "^3.1.25",
|
|
72
|
+
"conventional-changelog-cli": "^2.2.2",
|
|
73
|
+
"eslint": "^8.9.0",
|
|
74
|
+
"jest": "^27.5.1",
|
|
75
|
+
"rxjs": "^7.5.4",
|
|
76
|
+
"supertest": "^6.2.2",
|
|
77
|
+
"ts-jest": "^27.1.3",
|
|
78
|
+
"ts-node": "^10.5.0",
|
|
79
|
+
"typescript": "4.5.5"
|
|
77
80
|
},
|
|
78
81
|
"commitlint": {
|
|
79
82
|
"extends": [
|
|
80
83
|
"@commitlint/config-conventional"
|
|
81
84
|
]
|
|
82
85
|
},
|
|
83
|
-
"husky": {
|
|
84
|
-
"hooks": {
|
|
85
|
-
"pre-commit": "lint-staged",
|
|
86
|
-
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
86
|
"lint-staged": {
|
|
90
87
|
"*.ts": [
|
|
91
88
|
"eslint src/**/*.ts --fix"
|
|
@@ -93,11 +90,30 @@
|
|
|
93
90
|
},
|
|
94
91
|
"renovate": {
|
|
95
92
|
"extends": [
|
|
96
|
-
"config:base"
|
|
93
|
+
"config:base",
|
|
94
|
+
":preserveSemverRanges",
|
|
95
|
+
":semanticCommitTypeAll(chore)"
|
|
97
96
|
],
|
|
98
|
-
"
|
|
97
|
+
"semanticCommits": "enabled",
|
|
98
|
+
"separateMajorMinor": false,
|
|
99
|
+
"dependencyDashboard": false,
|
|
100
|
+
"packageRules": [
|
|
101
|
+
{
|
|
102
|
+
"matchUpdateTypes": [
|
|
103
|
+
"patch",
|
|
104
|
+
"minor"
|
|
105
|
+
],
|
|
106
|
+
"groupName": "patch/minor dependencies",
|
|
107
|
+
"groupSlug": "all-non-major",
|
|
108
|
+
"automerge": true,
|
|
109
|
+
"automergeType": "branch"
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
"schedule": [
|
|
113
|
+
"every weekday"
|
|
114
|
+
]
|
|
99
115
|
},
|
|
100
116
|
"engines": {
|
|
101
|
-
"node": ">=
|
|
117
|
+
"node": ">= 14.0.0"
|
|
102
118
|
}
|
|
103
119
|
}
|
package/typings.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { IDatabaseDriver, Options } from '@mikro-orm/core';
|
|
2
|
-
import { MiddlewareConsumer, ModuleMetadata, Scope, Type } from '@nestjs/common';
|
|
3
|
-
import { AbstractHttpAdapter } from '@nestjs/core';
|
|
1
|
+
import type { IDatabaseDriver, Options } from '@mikro-orm/core';
|
|
2
|
+
import type { MiddlewareConsumer, ModuleMetadata, Scope, Type } from '@nestjs/common';
|
|
3
|
+
import type { AbstractHttpAdapter } from '@nestjs/core';
|
|
4
4
|
export interface NestMiddlewareConsumer extends MiddlewareConsumer {
|
|
5
5
|
httpAdapter: AbstractHttpAdapter;
|
|
6
6
|
}
|
|
7
7
|
declare type MikroOrmNestScopeOptions = {
|
|
8
8
|
scope?: Scope;
|
|
9
9
|
};
|
|
10
|
-
export declare type
|
|
11
|
-
registerRequestContext?: boolean;
|
|
12
|
-
autoLoadEntities?: boolean;
|
|
10
|
+
export declare type MikroOrmMiddlewareModuleOptions = {
|
|
13
11
|
/**
|
|
14
12
|
* Routes to apply the middleware.
|
|
15
13
|
*
|
|
@@ -18,13 +16,18 @@ export declare type MikroOrmModuleOptions<D extends IDatabaseDriver = IDatabaseD
|
|
|
18
16
|
* For all other frameworks including Express, the middleware applies to all routes using `*`.
|
|
19
17
|
*/
|
|
20
18
|
forRoutesPath?: string;
|
|
21
|
-
}
|
|
19
|
+
};
|
|
20
|
+
export declare type MikroOrmModuleOptions<D extends IDatabaseDriver = IDatabaseDriver> = {
|
|
21
|
+
registerRequestContext?: boolean;
|
|
22
|
+
autoLoadEntities?: boolean;
|
|
23
|
+
} & Options<D> & MikroOrmMiddlewareModuleOptions;
|
|
22
24
|
export interface MikroOrmOptionsFactory<D extends IDatabaseDriver = IDatabaseDriver> {
|
|
23
25
|
createMikroOrmOptions(): Promise<MikroOrmModuleOptions<D>> | MikroOrmModuleOptions<D>;
|
|
24
26
|
}
|
|
25
27
|
export interface MikroOrmModuleSyncOptions extends MikroOrmModuleOptions, MikroOrmNestScopeOptions {
|
|
26
28
|
}
|
|
27
29
|
export interface MikroOrmModuleAsyncOptions<D extends IDatabaseDriver = IDatabaseDriver> extends Pick<ModuleMetadata, 'imports' | 'providers'>, MikroOrmNestScopeOptions {
|
|
30
|
+
contextName?: string;
|
|
28
31
|
useExisting?: Type<MikroOrmOptionsFactory<D>>;
|
|
29
32
|
useClass?: Type<MikroOrmOptionsFactory<D>>;
|
|
30
33
|
useFactory?: (...args: any[]) => Promise<MikroOrmModuleOptions<D>> | MikroOrmModuleOptions<D>;
|