Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support MikroORM v6 #153

Merged
merged 14 commits into from
May 19, 2024
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mikro-orm/nestjs",
"version": "5.2.3",
"version": "6.0.0",
"license": "MIT",
"author": {
"name": "Martin Adamek",
Expand Down Expand Up @@ -40,30 +40,30 @@
"lint": "eslint src/**/*.ts"
},
"peerDependencies": {
"@mikro-orm/core": "^5.0.0 || ^6.0.0-dev.0",
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0",
"@nestjs/core": "^8.0.0 || ^9.0.0 || ^10.0.0"
"@mikro-orm/core": "^5.0.0 || ^6.0.0",
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0"
},
"devDependencies": {
"@mikro-orm/core": "^5.7.12",
"@mikro-orm/sqlite": "^5.7.12",
"@nestjs/common": "^9.4.3",
"@nestjs/core": "^9.4.3",
"@nestjs/platform-express": "^9.4.3",
"@nestjs/testing": "^9.4.3",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "~5.61.0",
"@typescript-eslint/parser": "~5.61.0",
"conventional-changelog": "^5.0.0",
"conventional-changelog-cli": "^4.0.0",
"eslint": "^8.43.0",
"jest": "^29.5.0",
"@mikro-orm/core": "^6.0.1",
"@mikro-orm/sqlite": "^6.0.1",
"@nestjs/common": "^10.3.0",
"@nestjs/core": "^10.3.0",
"@nestjs/platform-express": "^10.3.0",
"@nestjs/testing": "^10.3.0",
"@types/jest": "^29.5.11",
"@types/node": "^20.10.7",
"@types/supertest": "^6.0.2",
"@typescript-eslint/eslint-plugin": "~6.18.0",
"@typescript-eslint/parser": "~6.18.0",
"conventional-changelog": "^5.1.0",
"conventional-changelog-cli": "^4.1.0",
"eslint": "^8.56.0",
"jest": "^29.7.0",
"rxjs": "^7.8.1",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"typescript": "5.3.3"
},
"commitlint": {
Expand Down Expand Up @@ -102,7 +102,7 @@
]
},
"engines": {
"node": ">= 14.0.0"
"node": ">= 18.12.0"
},
"packageManager": "yarn@4.0.2"
}
12 changes: 6 additions & 6 deletions src/mikro-orm.providers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getEntityManagerToken, getMikroORMToken, getRepositoryToken, logger, MIKRO_ORM_MODULE_OPTIONS } from './mikro-orm.common';
import type { AnyEntity } from '@mikro-orm/core';
import type { AnyEntity, EntityClass, EntityClassGroup, EntitySchema } from '@mikro-orm/core';
import { ConfigurationLoader, EntityManager, MetadataStorage, MikroORM } from '@mikro-orm/core';
import { getEntityManagerToken, getMikroORMToken, getRepositoryToken, logger, MIKRO_ORM_MODULE_OPTIONS } from './mikro-orm.common';

import type { MikroOrmModuleAsyncOptions, MikroOrmModuleOptions, MikroOrmOptionsFactory, EntityName } from './typings';
import type { InjectionToken, Provider, Type } from '@nestjs/common';
import { Scope } from '@nestjs/common';
import { MikroOrmEntitiesStorage } from './mikro-orm.entities.storage';
import type { EntityName, MikroOrmModuleAsyncOptions, MikroOrmModuleOptions, MikroOrmOptionsFactory } from './typings';

export function createMikroOrmProvider(contextName?: string): Provider {
return {
Expand All @@ -14,8 +14,8 @@ export function createMikroOrmProvider(contextName?: string): Provider {
options = { ...options };

if (options?.autoLoadEntities) {
options.entities = [...(options.entities || []), ...MikroOrmEntitiesStorage.getEntities(contextName)];
options.entitiesTs = [...(options.entitiesTs || []), ...MikroOrmEntitiesStorage.getEntities(contextName)];
options.entities = [...(options.entities || []), ...MikroOrmEntitiesStorage.getEntities(contextName)] as (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[];
options.entitiesTs = [...(options.entitiesTs || []), ...MikroOrmEntitiesStorage.getEntities(contextName)] as (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[];
delete options.autoLoadEntities;
}

Expand Down Expand Up @@ -102,7 +102,7 @@ export function createMikroOrmRepositoryProviders(entities: EntityName<AnyEntity

(entities || []).forEach(entity => {
const meta = metadata.find(meta => meta.class === entity);
const repository = (meta?.repository ?? meta?.customRepository) as unknown as (() => InjectionToken) | undefined;
const repository = (meta?.repository) as unknown as (() => InjectionToken) | undefined;

if (repository) {
providers.push({
Expand Down
9 changes: 5 additions & 4 deletions tests/mikro-orm.middleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { Options } from '@mikro-orm/core';
import { MikroORM } from '@mikro-orm/core';
import { SqliteDriver } from '@mikro-orm/sqlite';
import type { INestApplication } from '@nestjs/common';
import {
Controller,
Expand All @@ -8,14 +11,12 @@ import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import request from 'supertest';
import { InjectMikroORM, MikroOrmModule } from '../src';
import type { Options } from '@mikro-orm/core';
import { MikroORM } from '@mikro-orm/core';
import { Foo } from './entities/foo.entity';
import { Bar } from './entities/bar.entity';
import { Foo } from './entities/foo.entity';

const testOptions: Options = {
dbName: ':memory:',
type: 'sqlite',
driver: SqliteDriver,
baseDir: __dirname,
entities: ['entities'],
};
Expand Down
9 changes: 5 additions & 4 deletions tests/mikro-orm.module.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import type { EntityRepository, Options } from '@mikro-orm/core';
import { EntityManager, MikroORM } from '@mikro-orm/core';
import type { Options, EntityRepository } from '@mikro-orm/core';
import { SqliteDriver } from '@mikro-orm/sqlite';
import { Inject, Logger, Module, Scope } from '@nestjs/common';
import { ContextIdFactory } from '@nestjs/core';
import type { TestingModule } from '@nestjs/testing';
import { Test } from '@nestjs/testing';
import type { MikroOrmOptionsFactory } from '../src';
import { CONTEXT_NAMES, getEntityManagerToken, getMikroORMToken, getRepositoryToken, MikroOrmModule } from '../src';
import { Foo } from './entities/foo.entity';
import { CONTEXT_NAMES, MikroOrmModule, getEntityManagerToken, getMikroORMToken, getRepositoryToken } from '../src';
import { Bar } from './entities/bar.entity';
import { Foo } from './entities/foo.entity';

const testOptions: Options = {
dbName: ':memory:',
type: 'sqlite',
driver: SqliteDriver,
baseDir: __dirname,
entities: ['entities'],
};
Expand Down
Loading
Loading