@mikro-orm/nestjs 5.2.1 → 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.
- package/mikro-orm-core.module.js +4 -1
- package/mikro-orm-middleware.module.js +2 -1
- package/mikro-orm.entities.storage.d.ts +7 -0
- package/mikro-orm.entities.storage.js +14 -5
- package/mikro-orm.middleware.js +2 -1
- package/mikro-orm.module.js +2 -1
- package/mikro-orm.providers.js +1 -1
- package/multiple-mikro-orm.middleware.js +2 -1
- package/package.json +5 -5
package/mikro-orm-core.module.js
CHANGED
|
@@ -44,6 +44,7 @@ const mikro_orm_common_1 = require("./mikro-orm.common");
|
|
|
44
44
|
const mikro_orm_providers_1 = require("./mikro-orm.providers");
|
|
45
45
|
const mikro_orm_middleware_1 = require("./mikro-orm.middleware");
|
|
46
46
|
const middleware_helper_1 = require("./middleware.helper");
|
|
47
|
+
const mikro_orm_entities_storage_1 = require("./mikro-orm.entities.storage");
|
|
47
48
|
async function tryRequire(name) {
|
|
48
49
|
try {
|
|
49
50
|
return await Promise.resolve(`${name}`).then(s => __importStar(require(s)));
|
|
@@ -52,7 +53,7 @@ async function tryRequire(name) {
|
|
|
52
53
|
return undefined; // ignore, optional dependency
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
|
-
let MikroOrmCoreModule =
|
|
56
|
+
let MikroOrmCoreModule = MikroOrmCoreModule_1 = class MikroOrmCoreModule {
|
|
56
57
|
constructor(options, moduleRef) {
|
|
57
58
|
this.options = options;
|
|
58
59
|
this.moduleRef = moduleRef;
|
|
@@ -134,6 +135,7 @@ let MikroOrmCoreModule = exports.MikroOrmCoreModule = MikroOrmCoreModule_1 = cla
|
|
|
134
135
|
const orm = this.moduleRef.get(token);
|
|
135
136
|
if (orm) {
|
|
136
137
|
await orm.close();
|
|
138
|
+
mikro_orm_entities_storage_1.MikroOrmEntitiesStorage.clearLater();
|
|
137
139
|
}
|
|
138
140
|
mikro_orm_common_1.CONTEXT_NAMES.length = 0;
|
|
139
141
|
}
|
|
@@ -156,6 +158,7 @@ let MikroOrmCoreModule = exports.MikroOrmCoreModule = MikroOrmCoreModule_1 = cla
|
|
|
156
158
|
return contextName;
|
|
157
159
|
}
|
|
158
160
|
};
|
|
161
|
+
exports.MikroOrmCoreModule = MikroOrmCoreModule;
|
|
159
162
|
exports.MikroOrmCoreModule = MikroOrmCoreModule = MikroOrmCoreModule_1 = __decorate([
|
|
160
163
|
(0, common_1.Global)(),
|
|
161
164
|
(0, common_1.Module)({}),
|
|
@@ -18,7 +18,7 @@ const common_1 = require("@nestjs/common");
|
|
|
18
18
|
const mikro_orm_common_1 = require("./mikro-orm.common");
|
|
19
19
|
const multiple_mikro_orm_middleware_1 = require("./multiple-mikro-orm.middleware");
|
|
20
20
|
const middleware_helper_1 = require("./middleware.helper");
|
|
21
|
-
let MikroOrmMiddlewareModule =
|
|
21
|
+
let MikroOrmMiddlewareModule = MikroOrmMiddlewareModule_1 = class MikroOrmMiddlewareModule {
|
|
22
22
|
constructor(options) {
|
|
23
23
|
this.options = options;
|
|
24
24
|
}
|
|
@@ -46,6 +46,7 @@ let MikroOrmMiddlewareModule = exports.MikroOrmMiddlewareModule = MikroOrmMiddle
|
|
|
46
46
|
.forRoutes({ path: (0, middleware_helper_1.forRoutesPath)(this.options, consumer), method: common_1.RequestMethod.ALL });
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
+
exports.MikroOrmMiddlewareModule = MikroOrmMiddlewareModule;
|
|
49
50
|
exports.MikroOrmMiddlewareModule = MikroOrmMiddlewareModule = MikroOrmMiddlewareModule_1 = __decorate([
|
|
50
51
|
(0, common_1.Global)(),
|
|
51
52
|
(0, common_1.Module)({}),
|
|
@@ -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();
|
|
@@ -14,12 +18,17 @@ class MikroOrmEntitiesStorage {
|
|
|
14
18
|
return this.storage.get(contextName)?.values() || [];
|
|
15
19
|
}
|
|
16
20
|
static clear(contextName = 'default') {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
this.storage.get(contextName)?.clear();
|
|
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;
|
|
22
30
|
}
|
|
23
31
|
}
|
|
24
32
|
exports.MikroOrmEntitiesStorage = MikroOrmEntitiesStorage;
|
|
25
33
|
MikroOrmEntitiesStorage.storage = new Map();
|
|
34
|
+
MikroOrmEntitiesStorage.shouldClear = false;
|
package/mikro-orm.middleware.js
CHANGED
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.MikroOrmMiddleware = void 0;
|
|
13
13
|
const core_1 = require("@mikro-orm/core");
|
|
14
14
|
const common_1 = require("@nestjs/common");
|
|
15
|
-
let MikroOrmMiddleware =
|
|
15
|
+
let MikroOrmMiddleware = class MikroOrmMiddleware {
|
|
16
16
|
constructor(orm) {
|
|
17
17
|
this.orm = orm;
|
|
18
18
|
}
|
|
@@ -20,6 +20,7 @@ let MikroOrmMiddleware = exports.MikroOrmMiddleware = class MikroOrmMiddleware {
|
|
|
20
20
|
core_1.RequestContext.create(this.orm.em, next);
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
|
+
exports.MikroOrmMiddleware = MikroOrmMiddleware;
|
|
23
24
|
exports.MikroOrmMiddleware = MikroOrmMiddleware = __decorate([
|
|
24
25
|
(0, common_1.Injectable)(),
|
|
25
26
|
__metadata("design:paramtypes", [core_1.MikroORM])
|
package/mikro-orm.module.js
CHANGED
|
@@ -14,7 +14,7 @@ const mikro_orm_providers_1 = require("./mikro-orm.providers");
|
|
|
14
14
|
const mikro_orm_core_module_1 = require("./mikro-orm-core.module");
|
|
15
15
|
const mikro_orm_middleware_module_1 = require("./mikro-orm-middleware.module");
|
|
16
16
|
const mikro_orm_entities_storage_1 = require("./mikro-orm.entities.storage");
|
|
17
|
-
let MikroOrmModule =
|
|
17
|
+
let MikroOrmModule = MikroOrmModule_1 = class MikroOrmModule {
|
|
18
18
|
/**
|
|
19
19
|
* Clears the entity storage. This is useful for testing purposes, when you want to isolate the tests.
|
|
20
20
|
* Keep in mind that this should be called when using a test runner that keeps the context alive between tests (like Vitest with threads disabled).
|
|
@@ -56,6 +56,7 @@ let MikroOrmModule = exports.MikroOrmModule = MikroOrmModule_1 = class MikroOrmM
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
|
+
exports.MikroOrmModule = MikroOrmModule;
|
|
59
60
|
exports.MikroOrmModule = MikroOrmModule = MikroOrmModule_1 = __decorate([
|
|
60
61
|
(0, common_1.Module)({})
|
|
61
62
|
], MikroOrmModule);
|
package/mikro-orm.providers.js
CHANGED
|
@@ -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
|
}
|
|
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.MultipleMikroOrmMiddleware = void 0;
|
|
16
16
|
const core_1 = require("@mikro-orm/core");
|
|
17
17
|
const common_1 = require("@nestjs/common");
|
|
18
|
-
let MultipleMikroOrmMiddleware =
|
|
18
|
+
let MultipleMikroOrmMiddleware = class MultipleMikroOrmMiddleware {
|
|
19
19
|
constructor(orm) {
|
|
20
20
|
this.orm = orm;
|
|
21
21
|
}
|
|
@@ -23,6 +23,7 @@ let MultipleMikroOrmMiddleware = exports.MultipleMikroOrmMiddleware = class Mult
|
|
|
23
23
|
core_1.RequestContext.create(this.orm.map(orm => orm.em), next);
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
+
exports.MultipleMikroOrmMiddleware = MultipleMikroOrmMiddleware;
|
|
26
27
|
exports.MultipleMikroOrmMiddleware = MultipleMikroOrmMiddleware = __decorate([
|
|
27
28
|
(0, common_1.Injectable)(),
|
|
28
29
|
__param(0, (0, common_1.Inject)('MikroORMs')),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/nestjs",
|
|
3
|
-
"version": "5.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": "^
|
|
60
|
-
"conventional-changelog-cli": "^
|
|
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.
|
|
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@
|
|
107
|
+
"packageManager": "yarn@4.0.2"
|
|
108
108
|
}
|