@mikro-orm/nestjs 5.2.2 → 5.2.3

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.
@@ -135,7 +135,7 @@ let MikroOrmCoreModule = MikroOrmCoreModule_1 = class MikroOrmCoreModule {
135
135
  const orm = this.moduleRef.get(token);
136
136
  if (orm) {
137
137
  await orm.close();
138
- mikro_orm_entities_storage_1.MikroOrmEntitiesStorage.clear(orm.config.get('contextName'));
138
+ mikro_orm_entities_storage_1.MikroOrmEntitiesStorage.clearLater();
139
139
  }
140
140
  mikro_orm_common_1.CONTEXT_NAMES.length = 0;
141
141
  }
@@ -2,7 +2,14 @@ import type { AnyEntity } from '@mikro-orm/core';
2
2
  import type { EntityName } from './typings';
3
3
  export declare class MikroOrmEntitiesStorage {
4
4
  private static readonly storage;
5
+ private static shouldClear;
5
6
  static addEntity(entity: EntityName<AnyEntity>, contextName?: string): void;
6
7
  static getEntities(contextName?: string): never[] | IterableIterator<EntityName<Partial<any>>>;
7
8
  static clear(contextName?: string): void;
9
+ /**
10
+ * When the `addEntity` is called next, the storage will be cleared automatically before it.
11
+ * We want to keep the cache, as it's populated on require time, but sometimes (tests) the contexts could be cleared.
12
+ * This resolves both cases by deferring the `clear` call to the first `addEntity` call.
13
+ */
14
+ static clearLater(): void;
8
15
  }
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MikroOrmEntitiesStorage = void 0;
4
4
  class MikroOrmEntitiesStorage {
5
5
  static addEntity(entity, contextName = 'default') {
6
+ if (this.shouldClear) {
7
+ this.clear(contextName);
8
+ this.shouldClear = false;
9
+ }
6
10
  let set = this.storage.get(contextName);
7
11
  if (!set) {
8
12
  set = new Set();
@@ -16,6 +20,15 @@ class MikroOrmEntitiesStorage {
16
20
  static clear(contextName = 'default') {
17
21
  this.storage.get(contextName)?.clear();
18
22
  }
23
+ /**
24
+ * When the `addEntity` is called next, the storage will be cleared automatically before it.
25
+ * We want to keep the cache, as it's populated on require time, but sometimes (tests) the contexts could be cleared.
26
+ * This resolves both cases by deferring the `clear` call to the first `addEntity` call.
27
+ */
28
+ static clearLater() {
29
+ this.shouldClear = true;
30
+ }
19
31
  }
20
32
  exports.MikroOrmEntitiesStorage = MikroOrmEntitiesStorage;
21
33
  MikroOrmEntitiesStorage.storage = new Map();
34
+ MikroOrmEntitiesStorage.shouldClear = false;
@@ -31,7 +31,7 @@ function createEntityManagerProvider(scope = common_1.Scope.DEFAULT, entityManag
31
31
  return {
32
32
  provide: entityManager,
33
33
  scope,
34
- useFactory: (em) => em,
34
+ useFactory: (em) => em, // just a simple alias, unlike `useExisting` from nest, this works with request scopes too
35
35
  inject: [core_1.EntityManager], // depend on the EM from core package
36
36
  };
37
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/nestjs",
3
- "version": "5.2.2",
3
+ "version": "5.2.3",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "Martin Adamek",
@@ -56,15 +56,15 @@
56
56
  "@types/supertest": "^2.0.12",
57
57
  "@typescript-eslint/eslint-plugin": "~5.61.0",
58
58
  "@typescript-eslint/parser": "~5.61.0",
59
- "conventional-changelog": "^4.0.0",
60
- "conventional-changelog-cli": "^3.0.0",
59
+ "conventional-changelog": "^5.0.0",
60
+ "conventional-changelog-cli": "^4.0.0",
61
61
  "eslint": "^8.43.0",
62
62
  "jest": "^29.5.0",
63
63
  "rxjs": "^7.8.1",
64
64
  "supertest": "^6.3.3",
65
65
  "ts-jest": "^29.1.0",
66
66
  "ts-node": "^10.9.1",
67
- "typescript": "5.2.2"
67
+ "typescript": "5.3.3"
68
68
  },
69
69
  "commitlint": {
70
70
  "extends": [
@@ -104,5 +104,5 @@
104
104
  "engines": {
105
105
  "node": ">= 14.0.0"
106
106
  },
107
- "packageManager": "yarn@3.6.3"
107
+ "packageManager": "yarn@4.0.2"
108
108
  }