@mikro-orm/nestjs 7.0.2-dev.7 → 7.0.2-dev.9

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 CHANGED
@@ -62,10 +62,10 @@ Afterward, the `EntityManager` will be available to inject across entire project
62
62
  ```ts
63
63
  @Injectable()
64
64
  export class MyService {
65
-
66
- constructor(private readonly orm: MikroORM,
67
- private readonly em: EntityManager) { }
68
-
65
+ constructor(
66
+ private readonly orm: MikroORM,
67
+ private readonly em: EntityManager,
68
+ ) {}
69
69
  }
70
70
  ```
71
71
 
@@ -103,11 +103,10 @@ In this way we can inject the `PhotoRepository` to the `PhotoService` using the
103
103
  export class PhotoService {
104
104
  constructor(
105
105
  @InjectRepository(Photo)
106
- private readonly photoRepository: EntityRepository<Photo>
106
+ private readonly photoRepository: EntityRepository<Photo>,
107
107
  ) {}
108
108
 
109
109
  // ...
110
-
111
110
  }
112
111
  ```
113
112
 
@@ -186,14 +185,12 @@ method and execute it inside the context.
186
185
  ```ts
187
186
  @Injectable()
188
187
  export class MyService {
189
-
190
- constructor(private readonly orm: MikroORM) { }
188
+ constructor(private readonly orm: MikroORM) {}
191
189
 
192
190
  @CreateRequestContext()
193
191
  async doSomething() {
194
192
  // this will be executed in a separate context
195
193
  }
196
-
197
194
  }
198
195
  ```
199
196
 
@@ -206,18 +203,15 @@ Luckily, MikroORM provides a [serialization API](https://mikro-orm.io/docs/seria
206
203
  ```typescript
207
204
  @Entity()
208
205
  export class Book {
209
-
210
- @Property({ hidden: true }) // --> Equivalent of class-transformer's `@Exclude`
206
+ @Property({ hidden: true }) // --> Equivalent of class-transformer's `@Exclude`
211
207
  hiddenField: number = Date.now();
212
208
 
213
209
  @Property({ persist: false }) // --> Will only exist in memory (and will be serialized). Similar to class-transformer's `@Expose()`
214
210
  count?: number;
215
211
 
216
- @ManyToOne({ serializer: value => value.name, serializedName: 'authorName' }) // Equivalent of class-transformer's `@Transform()`
212
+ @ManyToOne({ serializer: value => value.name, serializedName: 'authorName' }) // Equivalent of class-transformer's `@Transform()`
217
213
  author: Author;
218
-
219
214
  }
220
-
221
215
  ```
222
216
 
223
217
  ## Using `AsyncLocalStorage` for request context
@@ -264,11 +258,11 @@ import { Scope } from '@nestjs/common';
264
258
  MikroOrmModule.forRoot({
265
259
  // ...
266
260
  registerRequestContext: false, // disable automatatic middleware
267
- scope: Scope.REQUEST
261
+ scope: Scope.REQUEST,
268
262
  }),
269
263
  ],
270
264
  controllers: [AppController],
271
- providers: [AppService]
265
+ providers: [AppService],
272
266
  })
273
267
  export class AppModule {}
274
268
  ```
@@ -287,11 +281,11 @@ import { PostgreSqlDriver } from '@mikro-orm/postgresql';
287
281
  // ...
288
282
  registerRequestContext: false, // disable automatatic middleware
289
283
  }),
290
- scope: Scope.REQUEST
291
- })
284
+ scope: Scope.REQUEST,
285
+ }),
292
286
  ],
293
287
  controllers: [AppController],
294
- providers: [AppService]
288
+ providers: [AppService],
295
289
  })
296
290
  export class AppModule {}
297
291
  ```
@@ -305,7 +299,7 @@ When using custom repositories, we can get around the need for `@InjectRepositor
305
299
  decorator by naming our repositories the same way as `getRepositoryToken()` method do:
306
300
 
307
301
  ```ts
308
- export const getRepositoryToken = <T> (entity: EntityName<T>) => `${Utils.className(entity)}Repository`;
302
+ export const getRepositoryToken = <T>(entity: EntityName<T>) => `${Utils.className(entity)}Repository`;
309
303
  ```
310
304
 
311
305
  In other words, as long as we name the repository same was as the entity is called,
@@ -317,10 +311,8 @@ the Nest.js DI container.
317
311
  ```ts
318
312
  @Entity({ customRepository: () => AuthorRepository })
319
313
  export class Author {
320
-
321
314
  // to allow inference in `em.getRepository()`
322
315
  [EntityRepositoryType]?: AuthorRepository;
323
-
324
316
  }
325
317
  ```
326
318
 
@@ -328,9 +320,7 @@ export class Author {
328
320
 
329
321
  ```ts
330
322
  export class AuthorRepository extends EntityRepository<Author> {
331
-
332
323
  // your custom methods...
333
-
334
324
  }
335
325
  ```
336
326
 
@@ -340,9 +330,7 @@ return, we do not need the `@InjectRepository()` decorator anymore:
340
330
  ```ts
341
331
  @Injectable()
342
332
  export class MyService {
343
-
344
- constructor(private readonly repo: AuthorRepository) { }
345
-
333
+ constructor(private readonly repo: AuthorRepository) {}
346
334
  }
347
335
  ```
348
336
 
@@ -395,7 +383,7 @@ Since MikroORM v6.4, you can also define [multiple configurations](https://mikro
395
383
  imports: [
396
384
  // `config` exports an array of configs
397
385
  ...MikroOrmModule.forRoot(config),
398
- MikroOrmModule.forMiddleware()
386
+ MikroOrmModule.forMiddleware(),
399
387
  ],
400
388
  controllers: [AppController],
401
389
  providers: [AppService],
@@ -408,12 +396,12 @@ To access different `MikroORM`/`EntityManager` connections you have to use the n
408
396
  ```ts
409
397
  @Injectable()
410
398
  export class MyService {
411
-
412
- constructor(@InjectMikroORM('db1') private readonly orm1: MikroORM,
413
- @InjectMikroORM('db2') private readonly orm2: MikroORM,
414
- @InjectEntityManager('db1') private readonly em1: EntityManager,
415
- @InjectEntityManager('db2') private readonly em2: EntityManager) { }
416
-
399
+ constructor(
400
+ @InjectMikroORM('db1') private readonly orm1: MikroORM,
401
+ @InjectMikroORM('db2') private readonly orm2: MikroORM,
402
+ @InjectEntityManager('db1') private readonly em1: EntityManager,
403
+ @InjectEntityManager('db2') private readonly em2: EntityManager,
404
+ ) {}
417
405
  }
418
406
  ```
419
407
 
@@ -437,11 +425,10 @@ When using the `@InjectRepository` decorator you will also need to pass the `con
437
425
  export class PhotoService {
438
426
  constructor(
439
427
  @InjectRepository(Photo, 'db1')
440
- private readonly photoRepository: EntityRepository<Photo>
428
+ private readonly photoRepository: EntityRepository<Photo>,
441
429
  ) {}
442
430
 
443
431
  // ...
444
-
445
432
  }
446
433
  ```
447
434
 
@@ -450,9 +437,7 @@ You can use the `@InjectMikroORMs` decorator to get all registered MikroORM inst
450
437
  ```typescript
451
438
  @Injectable()
452
439
  export class MyService {
453
-
454
- constructor(@InjectMikroORMs() private readonly orms: MikroORM[]) { }
455
-
440
+ constructor(@InjectMikroORMs() private readonly orms: MikroORM[]) {}
456
441
  }
457
442
  ```
458
443
 
@@ -62,7 +62,9 @@ let MikroOrmCoreModule = MikroOrmCoreModule_1 = class MikroOrmCoreModule {
62
62
  createMikroOrmProvider(contextName),
63
63
  ...(em ? [createMikroOrmProvider(contextName, em.getDriver().getORMClass())] : []),
64
64
  createEntityManagerProvider(options.scope, EntityManager, contextName, options.forkOptions),
65
- ...(em ? [createEntityManagerProvider(options.scope, em.constructor, contextName, options.forkOptions)] : []),
65
+ ...(em
66
+ ? [createEntityManagerProvider(options.scope, em.constructor, contextName, options.forkOptions)]
67
+ : []),
66
68
  ],
67
69
  exports: [
68
70
  contextName ? getMikroORMToken(contextName) : MikroORM,
@@ -1,4 +1,4 @@
1
- import { EntityManager, EntitySchema, MetadataStorage, MikroORM } from '@mikro-orm/core';
1
+ import { EntityManager, EntitySchema, MetadataStorage, MikroORM, } from '@mikro-orm/core';
2
2
  import { Scope } from '@nestjs/common';
3
3
  import { MIKRO_ORM_MODULE_OPTIONS, getEntityManagerToken, getMikroORMToken, getRepositoryToken, logger, } from './mikro-orm.common.js';
4
4
  import { MikroOrmEntitiesStorage } from './mikro-orm.entities.storage.js';
@@ -42,7 +42,7 @@ export function createEntityManagerProvider(scope = Scope.DEFAULT, entityManager
42
42
  return {
43
43
  provide: contextName ? getEntityManagerToken(contextName) : entityManager,
44
44
  scope,
45
- useFactory: (orm) => (scope === Scope.DEFAULT ? orm.em : orm.em.fork({ useContext: true, ...forkOptions })),
45
+ useFactory: (orm) => scope === Scope.DEFAULT ? orm.em : orm.em.fork({ useContext: true, ...forkOptions }),
46
46
  inject: [contextName ? getMikroORMToken(contextName) : MikroORM],
47
47
  };
48
48
  }
@@ -53,8 +53,8 @@ export function createMikroOrmAsyncOptionsProvider(options) {
53
53
  useFactory: async (...args) => {
54
54
  const factoryOptions = await options.useFactory(...args);
55
55
  return {
56
- ...options.contextName ? { contextName: options.contextName } : {},
57
- ...options.driver ? { driver: options.driver } : {},
56
+ ...(options.contextName ? { contextName: options.contextName } : {}),
57
+ ...(options.driver ? { driver: options.driver } : {}),
58
58
  ...factoryOptions,
59
59
  };
60
60
  },
@@ -70,7 +70,7 @@ export function createMikroOrmAsyncOptionsProvider(options) {
70
70
  useFactory: async (optionsFactory) => {
71
71
  const factoryOptions = await optionsFactory.createMikroOrmOptions(options.contextName);
72
72
  return {
73
- ...options.driver ? { driver: options.driver } : {},
73
+ ...(options.driver ? { driver: options.driver } : {}),
74
74
  ...factoryOptions,
75
75
  };
76
76
  },
@@ -93,7 +93,8 @@ export function createMikroOrmRepositoryProviders(entities, contextName) {
93
93
  (entities || []).forEach(entity => {
94
94
  const meta = entity instanceof EntitySchema
95
95
  ? entity.meta
96
- : (typeof entity === 'function' ? EntitySchema.REGISTRY.get(entity)?.meta : undefined) ?? metadata.find(meta => meta.class === entity);
96
+ : ((typeof entity === 'function' ? EntitySchema.REGISTRY.get(entity)?.meta : undefined) ??
97
+ metadata.find(meta => meta.class === entity));
97
98
  const repository = meta?.repository;
98
99
  if (repository) {
99
100
  providers.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/nestjs",
3
- "version": "7.0.2-dev.7",
3
+ "version": "7.0.2-dev.9",
4
4
  "description": "NestJS module for MikroORM",
5
5
  "keywords": [
6
6
  "data-mapper",
@@ -19,15 +19,15 @@
19
19
  ],
20
20
  "homepage": "https://github.com/mikro-orm/nestjs#readme",
21
21
  "bugs": "https://github.com/mikro-orm/nestjs/issues",
22
- "repository": {
23
- "type": "git",
24
- "url": "https://github.com/mikro-orm/nestjs"
25
- },
22
+ "license": "MIT",
26
23
  "author": {
27
24
  "name": "Martin Adamek",
28
25
  "email": "banan23@gmail.com"
29
26
  },
30
- "license": "MIT",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/mikro-orm/nestjs"
30
+ },
31
31
  "type": "module",
32
32
  "exports": {
33
33
  ".": "./index.js",
@@ -43,15 +43,8 @@
43
43
  "format": "oxfmt --write .",
44
44
  "lint": "oxlint --type-aware",
45
45
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1",
46
- "coverage": "yarn test --coverage"
47
- },
48
- "commitlint": {
49
- "extends": [
50
- "@commitlint/config-conventional"
51
- ]
52
- },
53
- "lint-staged": {
54
- "*": "oxfmt --no-error-on-unmatched-pattern"
46
+ "coverage": "yarn test --coverage",
47
+ "publish:jsr": "jsr publish"
55
48
  },
56
49
  "devDependencies": {
57
50
  "@mikro-orm/core": "^7.0.0-dev.109",
@@ -67,6 +60,7 @@
67
60
  "@vitest/coverage-v8": "^4.0.16",
68
61
  "conventional-changelog": "^7.1.1",
69
62
  "conventional-changelog-cli": "^5.0.0",
63
+ "jsr": "0.14.3",
70
64
  "oxfmt": "^0.42.0",
71
65
  "oxlint": "^1.33.0",
72
66
  "oxlint-tsgolint": "^0.18.0",
@@ -74,7 +68,7 @@
74
68
  "rimraf": "^6.1.2",
75
69
  "rxjs": "^7.8.2",
76
70
  "supertest": "^7.1.4",
77
- "typescript": "5.9.3",
71
+ "typescript": "6.0.2",
78
72
  "unplugin-swc": "^1.5.9",
79
73
  "vitest": "^4.0.16"
80
74
  },
@@ -84,10 +78,18 @@
84
78
  "@nestjs/core": "^11.0.5",
85
79
  "reflect-metadata": "^0.1.0 || ^0.2.0"
86
80
  },
87
- "packageManager": "yarn@4.13.0",
81
+ "lint-staged": {
82
+ "*": "oxfmt --no-error-on-unmatched-pattern"
83
+ },
84
+ "commitlint": {
85
+ "extends": [
86
+ "@commitlint/config-conventional"
87
+ ]
88
+ },
88
89
  "engines": {
89
90
  "node": ">= 22.17.0"
90
91
  },
92
+ "packageManager": "yarn@4.13.0",
91
93
  "readme": "./README.md",
92
94
  "renovate": {
93
95
  "extends": [