@mikro-orm/nestjs 5.0.0 → 5.0.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/README.md +1 -2
- package/index.js +5 -1
- package/mikro-orm-core.module.js +9 -5
- package/mikro-orm.common.d.ts +1 -2
- package/mikro-orm.common.js +1 -2
- package/mikro-orm.entities.storage.d.ts +7 -0
- package/mikro-orm.entities.storage.js +25 -0
- package/mikro-orm.module.d.ts +2 -4
- package/mikro-orm.module.js +4 -3
- package/mikro-orm.providers.d.ts +2 -2
- package/mikro-orm.providers.js +5 -10
- package/package.json +4 -4
- package/typings.d.ts +6 -2
package/README.md
CHANGED
|
@@ -269,7 +269,7 @@ the Nest.js DI container.
|
|
|
269
269
|
`**./author.entity.ts**`
|
|
270
270
|
|
|
271
271
|
```ts
|
|
272
|
-
@Entity()
|
|
272
|
+
@Entity({ customRepository: () => AuthorRepository })
|
|
273
273
|
export class Author {
|
|
274
274
|
|
|
275
275
|
// to allow inference in `em.getRepository()`
|
|
@@ -281,7 +281,6 @@ export class Author {
|
|
|
281
281
|
`**./author.repository.ts**`
|
|
282
282
|
|
|
283
283
|
```ts
|
|
284
|
-
@Repository(Author)
|
|
285
284
|
export class AuthorRepository extends EntityRepository<Author> {
|
|
286
285
|
|
|
287
286
|
// your custom methods...
|
package/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/mikro-orm-core.module.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -63,8 +67,8 @@ let MikroOrmCoreModule = MikroOrmCoreModule_1 = class MikroOrmCoreModule {
|
|
|
63
67
|
{ provide: mikro_orm_common_1.MIKRO_ORM_MODULE_OPTIONS, useValue: options || {} },
|
|
64
68
|
(0, mikro_orm_providers_1.createMikroOrmProvider)(contextName),
|
|
65
69
|
(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, core_1.EntityManager, contextName),
|
|
66
|
-
...(knex ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope,
|
|
67
|
-
...(mongo ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope,
|
|
70
|
+
...(knex ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, knex.SqlEntityManager, contextName)] : []),
|
|
71
|
+
...(mongo ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, mongo.MongoEntityManager, contextName)] : []),
|
|
68
72
|
],
|
|
69
73
|
exports: [
|
|
70
74
|
contextName ? (0, mikro_orm_common_1.getMikroORMToken)(contextName) : core_1.MikroORM,
|
|
@@ -86,8 +90,8 @@ let MikroOrmCoreModule = MikroOrmCoreModule_1 = class MikroOrmCoreModule {
|
|
|
86
90
|
...(0, mikro_orm_providers_1.createAsyncProviders)({ ...options, contextName: options.contextName }),
|
|
87
91
|
(0, mikro_orm_providers_1.createMikroOrmProvider)(contextName),
|
|
88
92
|
(0, mikro_orm_providers_1.createEntityManagerProvider)(options.scope, core_1.EntityManager, contextName),
|
|
89
|
-
...(knex ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope,
|
|
90
|
-
...(mongo ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope,
|
|
93
|
+
...(knex ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, knex.SqlEntityManager, contextName)] : []),
|
|
94
|
+
...(mongo ? [(0, mikro_orm_providers_1.createEntityManagerProvider)(options?.scope, mongo.MongoEntityManager, contextName)] : []),
|
|
91
95
|
],
|
|
92
96
|
exports: [
|
|
93
97
|
contextName ? (0, mikro_orm_common_1.getMikroORMToken)(contextName) : core_1.MikroORM,
|
package/mikro-orm.common.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EntityName } from '@mikro-orm/core';
|
|
2
2
|
import { Logger } from '@nestjs/common';
|
|
3
3
|
export declare const MIKRO_ORM_MODULE_OPTIONS: unique symbol;
|
|
4
|
-
export declare const REGISTERED_ENTITIES: Set<EntityName<AnyEntity<any>>>;
|
|
5
4
|
export declare const CONTEXT_NAMES: string[];
|
|
6
5
|
export declare const logger: Logger;
|
|
7
6
|
export declare const getMikroORMToken: (name: string) => string;
|
package/mikro-orm.common.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InjectRepository = exports.getRepositoryToken = exports.InjectEntityManager = exports.getEntityManagerToken = exports.InjectMikroORM = exports.getMikroORMToken = exports.logger = exports.CONTEXT_NAMES = exports.
|
|
3
|
+
exports.InjectRepository = exports.getRepositoryToken = exports.InjectEntityManager = exports.getEntityManagerToken = exports.InjectMikroORM = exports.getMikroORMToken = exports.logger = exports.CONTEXT_NAMES = 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
|
-
exports.REGISTERED_ENTITIES = new Set();
|
|
8
7
|
exports.CONTEXT_NAMES = [];
|
|
9
8
|
exports.logger = new common_1.Logger(core_1.MikroORM.name);
|
|
10
9
|
const getMikroORMToken = (name) => `${name}_MikroORM`;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnyEntity, EntityName } from '@mikro-orm/core';
|
|
2
|
+
export declare class MikroOrmEntitiesStorage {
|
|
3
|
+
private static readonly storage;
|
|
4
|
+
static addEntity(entity: EntityName<AnyEntity>, contextName?: string): void;
|
|
5
|
+
static getEntities(contextName?: string): never[] | IterableIterator<EntityName<AnyEntity<any>>>;
|
|
6
|
+
static clear(contextName?: string): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MikroOrmEntitiesStorage = void 0;
|
|
4
|
+
class MikroOrmEntitiesStorage {
|
|
5
|
+
static addEntity(entity, contextName = 'default') {
|
|
6
|
+
let set = this.storage.get(contextName);
|
|
7
|
+
if (!set) {
|
|
8
|
+
set = new Set();
|
|
9
|
+
this.storage.set(contextName, set);
|
|
10
|
+
}
|
|
11
|
+
set.add(entity);
|
|
12
|
+
}
|
|
13
|
+
static getEntities(contextName = 'default') {
|
|
14
|
+
return this.storage.get(contextName)?.values() || [];
|
|
15
|
+
}
|
|
16
|
+
static clear(contextName = 'default') {
|
|
17
|
+
const set = this.storage.get(contextName);
|
|
18
|
+
if (!set) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
set.clear();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.MikroOrmEntitiesStorage = MikroOrmEntitiesStorage;
|
|
25
|
+
MikroOrmEntitiesStorage.storage = new Map();
|
package/mikro-orm.module.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { AnyEntity, EntityName } from '@mikro-orm/core';
|
|
2
2
|
import type { DynamicModule } from '@nestjs/common';
|
|
3
|
-
import type { MikroOrmModuleAsyncOptions, MikroOrmModuleSyncOptions, MikroOrmMiddlewareModuleOptions } from './typings';
|
|
3
|
+
import type { MikroOrmModuleAsyncOptions, MikroOrmModuleSyncOptions, MikroOrmMiddlewareModuleOptions, MikroOrmModuleFeatureOptions } from './typings';
|
|
4
4
|
export declare class MikroOrmModule {
|
|
5
5
|
static forRoot(options?: MikroOrmModuleSyncOptions): DynamicModule;
|
|
6
6
|
static forRootAsync(options: MikroOrmModuleAsyncOptions): DynamicModule;
|
|
7
|
-
static forFeature(options: EntityName<AnyEntity>[] |
|
|
8
|
-
entities?: EntityName<AnyEntity>[];
|
|
9
|
-
}, contextName?: string): DynamicModule;
|
|
7
|
+
static forFeature(options: EntityName<AnyEntity>[] | MikroOrmModuleFeatureOptions, contextName?: string): DynamicModule;
|
|
10
8
|
static forMiddleware(options?: MikroOrmMiddlewareModuleOptions): DynamicModule;
|
|
11
9
|
}
|
package/mikro-orm.module.js
CHANGED
|
@@ -12,8 +12,8 @@ const core_1 = require("@mikro-orm/core");
|
|
|
12
12
|
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
|
-
const mikro_orm_common_1 = require("./mikro-orm.common");
|
|
16
15
|
const mikro_orm_middleware_module_1 = require("./mikro-orm-middleware.module");
|
|
16
|
+
const mikro_orm_entities_storage_1 = require("./mikro-orm.entities.storage");
|
|
17
17
|
let MikroOrmModule = MikroOrmModule_1 = class MikroOrmModule {
|
|
18
18
|
static forRoot(options) {
|
|
19
19
|
return {
|
|
@@ -29,10 +29,11 @@ let MikroOrmModule = MikroOrmModule_1 = class MikroOrmModule {
|
|
|
29
29
|
}
|
|
30
30
|
static forFeature(options, contextName) {
|
|
31
31
|
const entities = Array.isArray(options) ? options : (options.entities || []);
|
|
32
|
-
const
|
|
32
|
+
const name = (Array.isArray(options) || contextName) ? contextName : options.contextName;
|
|
33
|
+
const providers = (0, mikro_orm_providers_1.createMikroOrmRepositoryProviders)(entities, name);
|
|
33
34
|
for (const e of entities) {
|
|
34
35
|
if (!core_1.Utils.isString(e)) {
|
|
35
|
-
|
|
36
|
+
mikro_orm_entities_storage_1.MikroOrmEntitiesStorage.addEntity(e, name);
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
return {
|
package/mikro-orm.providers.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { AnyEntity, EntityName } from '@mikro-orm/core';
|
|
2
2
|
import { EntityManager } from '@mikro-orm/core';
|
|
3
3
|
import type { MikroOrmModuleAsyncOptions } from './typings';
|
|
4
|
-
import type { Provider } from '@nestjs/common';
|
|
4
|
+
import type { Provider, Type } from '@nestjs/common';
|
|
5
5
|
import { Scope } from '@nestjs/common';
|
|
6
6
|
export declare function createMikroOrmProvider(contextName?: string): Provider;
|
|
7
|
-
export declare function createEntityManagerProvider(scope?: Scope, entityManager?:
|
|
7
|
+
export declare function createEntityManagerProvider(scope?: Scope, entityManager?: Type, contextName?: string): Provider<EntityManager>;
|
|
8
8
|
export declare function createMikroOrmAsyncOptionsProvider(options: MikroOrmModuleAsyncOptions): Provider;
|
|
9
9
|
export declare function createAsyncProviders(options: MikroOrmModuleAsyncOptions): Provider[];
|
|
10
10
|
export declare function createMikroOrmRepositoryProviders(entities: EntityName<AnyEntity>[], contextName?: string): Provider[];
|
package/mikro-orm.providers.js
CHANGED
|
@@ -4,16 +4,17 @@ exports.createMikroOrmRepositoryProviders = exports.createAsyncProviders = expor
|
|
|
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
|
+
const mikro_orm_entities_storage_1 = require("./mikro-orm.entities.storage");
|
|
7
8
|
function createMikroOrmProvider(contextName) {
|
|
8
9
|
return {
|
|
9
10
|
provide: contextName ? (0, mikro_orm_common_1.getMikroORMToken)(contextName) : core_1.MikroORM,
|
|
10
11
|
useFactory: async (options) => {
|
|
11
12
|
if (options?.autoLoadEntities) {
|
|
12
|
-
options.entities = [...(options.entities || []), ...
|
|
13
|
-
options.entitiesTs = [...(options.entitiesTs || []), ...
|
|
13
|
+
options.entities = [...(options.entities || []), ...mikro_orm_entities_storage_1.MikroOrmEntitiesStorage.getEntities(contextName)];
|
|
14
|
+
options.entitiesTs = [...(options.entitiesTs || []), ...mikro_orm_entities_storage_1.MikroOrmEntitiesStorage.getEntities(contextName)];
|
|
14
15
|
delete options.autoLoadEntities;
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
mikro_orm_entities_storage_1.MikroOrmEntitiesStorage.clear(contextName);
|
|
17
18
|
if (!options || Object.keys(options).length === 0) {
|
|
18
19
|
const config = await core_1.ConfigurationLoader.getConfiguration();
|
|
19
20
|
config.set('logger', mikro_orm_common_1.logger.log.bind(mikro_orm_common_1.logger));
|
|
@@ -26,14 +27,8 @@ function createMikroOrmProvider(contextName) {
|
|
|
26
27
|
}
|
|
27
28
|
exports.createMikroOrmProvider = createMikroOrmProvider;
|
|
28
29
|
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
30
|
return {
|
|
36
|
-
provide:
|
|
31
|
+
provide: contextName ? (0, mikro_orm_common_1.getEntityManagerToken)(contextName) : entityManager,
|
|
37
32
|
scope,
|
|
38
33
|
useFactory: (orm) => scope === common_1.Scope.DEFAULT ? orm.em : orm.em.fork(),
|
|
39
34
|
inject: [contextName ? (0, mikro_orm_common_1.getMikroORMToken)(contextName) : core_1.MikroORM],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/nestjs",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Martin Adamek",
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"@types/jest": "^27.4.0",
|
|
67
67
|
"@types/node": "^17.0.17",
|
|
68
68
|
"@types/supertest": "^2.0.11",
|
|
69
|
-
"@typescript-eslint/eslint-plugin": "~5.
|
|
70
|
-
"@typescript-eslint/parser": "~5.
|
|
69
|
+
"@typescript-eslint/eslint-plugin": "~5.14.0",
|
|
70
|
+
"@typescript-eslint/parser": "~5.14.0",
|
|
71
71
|
"conventional-changelog": "^3.1.25",
|
|
72
72
|
"conventional-changelog-cli": "^2.2.2",
|
|
73
73
|
"eslint": "^8.9.0",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"supertest": "^6.2.2",
|
|
77
77
|
"ts-jest": "^27.1.3",
|
|
78
78
|
"ts-node": "^10.5.0",
|
|
79
|
-
"typescript": "4.
|
|
79
|
+
"typescript": "4.6.2"
|
|
80
80
|
},
|
|
81
81
|
"commitlint": {
|
|
82
82
|
"extends": [
|
package/typings.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IDatabaseDriver, Options } from '@mikro-orm/core';
|
|
1
|
+
import type { AnyEntity, EntityName, IDatabaseDriver, Options } from '@mikro-orm/core';
|
|
2
2
|
import type { MiddlewareConsumer, ModuleMetadata, Scope, Type } from '@nestjs/common';
|
|
3
3
|
import type { AbstractHttpAdapter } from '@nestjs/core';
|
|
4
4
|
export interface NestMiddlewareConsumer extends MiddlewareConsumer {
|
|
@@ -21,6 +21,10 @@ export declare type MikroOrmModuleOptions<D extends IDatabaseDriver = IDatabaseD
|
|
|
21
21
|
registerRequestContext?: boolean;
|
|
22
22
|
autoLoadEntities?: boolean;
|
|
23
23
|
} & Options<D> & MikroOrmMiddlewareModuleOptions;
|
|
24
|
+
export interface MikroOrmModuleFeatureOptions {
|
|
25
|
+
entities?: EntityName<AnyEntity>[];
|
|
26
|
+
contextName?: string;
|
|
27
|
+
}
|
|
24
28
|
export interface MikroOrmOptionsFactory<D extends IDatabaseDriver = IDatabaseDriver> {
|
|
25
29
|
createMikroOrmOptions(): Promise<MikroOrmModuleOptions<D>> | MikroOrmModuleOptions<D>;
|
|
26
30
|
}
|
|
@@ -30,7 +34,7 @@ export interface MikroOrmModuleAsyncOptions<D extends IDatabaseDriver = IDatabas
|
|
|
30
34
|
contextName?: string;
|
|
31
35
|
useExisting?: Type<MikroOrmOptionsFactory<D>>;
|
|
32
36
|
useClass?: Type<MikroOrmOptionsFactory<D>>;
|
|
33
|
-
useFactory?: (...args: any[]) => Promise<MikroOrmModuleOptions<D>> | MikroOrmModuleOptions<D>;
|
|
37
|
+
useFactory?: (...args: any[]) => Promise<Omit<MikroOrmModuleOptions<D>, 'contextName'>> | Omit<MikroOrmModuleOptions<D>, 'contextName'>;
|
|
34
38
|
inject?: any[];
|
|
35
39
|
}
|
|
36
40
|
export {};
|