@mikro-orm/core 6.3.3-dev.11 → 6.3.3-dev.12
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.
|
@@ -6,6 +6,7 @@ const MikroORM_1 = require("../MikroORM");
|
|
|
6
6
|
const RequestContext_1 = require("../utils/RequestContext");
|
|
7
7
|
const EntityManager_1 = require("../EntityManager");
|
|
8
8
|
const EntityRepository_1 = require("../entity/EntityRepository");
|
|
9
|
+
const TransactionContext_1 = require("../utils/TransactionContext");
|
|
9
10
|
function CreateRequestContext(getContext, respectExistingContext = false) {
|
|
10
11
|
return function (target, propertyKey, descriptor) {
|
|
11
12
|
const originalMethod = descriptor.value;
|
|
@@ -14,6 +15,10 @@ function CreateRequestContext(getContext, respectExistingContext = false) {
|
|
|
14
15
|
if (respectExistingContext && RequestContext_1.RequestContext.currentRequestContext()) {
|
|
15
16
|
return originalMethod.apply(this, args);
|
|
16
17
|
}
|
|
18
|
+
// If we are inside explicit transaction context, we need to create another tx context.
|
|
19
|
+
// Otherwise, the outer tx context would be preferred.
|
|
20
|
+
const txContext = TransactionContext_1.TransactionContext.currentTransactionContext();
|
|
21
|
+
const provider = txContext ? TransactionContext_1.TransactionContext : RequestContext_1.RequestContext;
|
|
17
22
|
/* istanbul ignore next */
|
|
18
23
|
let orm;
|
|
19
24
|
let em;
|
|
@@ -29,23 +34,25 @@ function CreateRequestContext(getContext, respectExistingContext = false) {
|
|
|
29
34
|
orm = await this.orm;
|
|
30
35
|
em = await this.em;
|
|
31
36
|
}
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
const create = async (em) => {
|
|
38
|
+
if (txContext) {
|
|
39
|
+
em = em.fork({ useContext: true });
|
|
40
|
+
}
|
|
41
|
+
return await provider.create(em, () => {
|
|
34
42
|
return originalMethod.apply(this, args);
|
|
35
43
|
});
|
|
44
|
+
};
|
|
45
|
+
if (em instanceof EntityManager_1.EntityManager) {
|
|
46
|
+
return await create(em);
|
|
36
47
|
}
|
|
37
48
|
if (orm instanceof EntityRepository_1.EntityRepository) {
|
|
38
|
-
return await
|
|
39
|
-
return originalMethod.apply(this, args);
|
|
40
|
-
});
|
|
49
|
+
return await create(orm.getEntityManager());
|
|
41
50
|
}
|
|
42
51
|
if (!(orm instanceof MikroORM_1.MikroORM)) {
|
|
43
52
|
const name = respectExistingContext ? 'EnsureRequestContext' : 'CreateRequestContext';
|
|
44
53
|
throw new Error(`@${name}() decorator can only be applied to methods of classes with \`orm: MikroORM\` property, \`em: EntityManager\` property, or with a callback parameter like \`@${name}(() => orm)\` that returns one of those types. The parameter will contain a reference to current \`this\`. Returning an EntityRepository from it is also supported.`);
|
|
45
54
|
}
|
|
46
|
-
return await
|
|
47
|
-
return originalMethod.apply(this, args);
|
|
48
|
-
});
|
|
55
|
+
return await create(orm.em);
|
|
49
56
|
};
|
|
50
57
|
return descriptor;
|
|
51
58
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.3.3-dev.
|
|
3
|
+
"version": "6.3.3-dev.12",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"esprima": "4.0.1",
|
|
65
65
|
"fs-extra": "11.2.0",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.3.3-dev.
|
|
67
|
+
"mikro-orm": "6.3.3-dev.12",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|