Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
feat: Add reproduction
Browse files Browse the repository at this point in the history
  • Loading branch information
AndKiel committed Jul 19, 2023
0 parents commit a992270
Show file tree
Hide file tree
Showing 7 changed files with 2,537 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
8 changes: 8 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```shell
docker-compose up -d
yarn install
yarn build
yarn run:ts-node
yarn run:built
docker-compose stop
```
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3.7"
services:
db-mongo:
image: "public.ecr.aws/docker/library/mongo:3"
healthcheck:
test: ["CMD-SHELL", 'mongo --eval ''db.runCommand("ping").ok'' localhost:27017/test --quiet']
interval: 10s
timeout: 2s
retries: 10
ports:
- "27017:27017"
37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "mikro-orm-nestjs-issue-128",
"version": "1.0.0",
"repository": "[email protected]:AndKiel/mikro-orm-nestjs-issue-128.git",
"license": "MIT",
"scripts": {
"compile": "tsc",
"build": "ncc build --out dist --source-map ./reproduction.ts",
"run:ts-node": "yarn ts-node ./reproduction.ts",
"run:built": "node ./dist/index.js"
},
"resolutions": {
"mongodb": "4.1.4"
},
"dependencies": {
"@mikro-orm/core": "5.7.13",
"@mikro-orm/mongodb": "5.7.13",
"@mikro-orm/nestjs": "5.2.0",
"@nestjs/common": "10.1.0",
"@nestjs/config": "3.0.0",
"@nestjs/core": "10.1.0",
"nestjs-pino": "3.3.0",
"pino-http": "8.3.3",
"reflect-metadata": "0.1.13",
"source-map-support": "0.5.21",
"tslib": "2.6.0"
},
"devDependencies": {
"@nestjs/cli": "10.1.4",
"@nestjs/schematics": "10.0.1",
"@nestjs/testing": "10.0.5",
"@types/node": "18.16.19",
"@vercel/ncc": "0.36.1",
"ts-node": "10.9.1",
"typescript": "5.1.6"
}
}
68 changes: 68 additions & 0 deletions reproduction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import "reflect-metadata";

import { BaseEntity, Entity, PrimaryKey, SerializedPrimaryKey } from "@mikro-orm/core";
import { EntityManager, ObjectId } from "@mikro-orm/mongodb";
import { MikroOrmModule } from "@mikro-orm/nestjs";
import { INestApplicationContext, Injectable, Module, Scope } from "@nestjs/common";
import { NestFactory } from "@nestjs/core";
import { LoggerModule, PinoLogger } from "nestjs-pino";

@Entity({ collection: "entities" })
export class MongoEntity extends BaseEntity<MongoEntity, "id"> {
@PrimaryKey()
public _id!: ObjectId;

@SerializedPrimaryKey()
public id!: string;
}


@Injectable({ scope: Scope.TRANSIENT })
export class MongoService {
private entityManager: EntityManager;

constructor(entityManager: EntityManager) {
this.entityManager = entityManager.fork();
}
}

@Module({ providers: [MongoService] })
export class MongoModule {}

@Module({
imports: [
LoggerModule.forRoot(),
MikroOrmModule.forRootAsync({
inject: [PinoLogger],
useFactory: (logger: PinoLogger) => {
logger.setContext("MikroOrm");

return {
type: "mongo",
clientUrl: "mongodb://127.0.0.1:27017/dbName", // run a local dockerized MongoDB v3 instance
dbName: "dbName",
entities: [MongoEntity],
debug: ["query"], // Log all queries
logger: message => logger.info(message),
};
},
}),
MongoModule,
],
})
class AppModule {}

let applicationContext: INestApplicationContext;

if (require.main === module) {
(async () => {
applicationContext = await NestFactory.createApplicationContext(AppModule);
applicationContext = await applicationContext.init();
await applicationContext.resolve(MongoService);
await applicationContext.close();
process.exit(0)
})().catch(async error => {
await applicationContext?.close();
throw error;
});
}
13 changes: 13 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es2021",
"lib": ["es2021"],
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
Loading

0 comments on commit a992270

Please sign in to comment.