@mikro-orm/core 7.2.2-dev.20 → 7.2.2-dev.22
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.2.2-dev.
|
|
3
|
+
"version": "7.2.2-dev.22",
|
|
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
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -207,7 +207,7 @@ export class ChangeSetPersister {
|
|
|
207
207
|
const keys = meta.getOwnConcurrencyCheckKeys();
|
|
208
208
|
for (const key of keys) {
|
|
209
209
|
cond[key] = changeSet.originalEntity[key];
|
|
210
|
-
if (changeSet.payload
|
|
210
|
+
if (Object.hasOwn(changeSet.payload, key)) {
|
|
211
211
|
tmp.push(key);
|
|
212
212
|
}
|
|
213
213
|
}
|
|
@@ -322,17 +322,19 @@ export class ChangeSetPersister {
|
|
|
322
322
|
}
|
|
323
323
|
// skip entity references as they don't have version values loaded
|
|
324
324
|
changeSets = changeSets.filter(cs => helper(cs.entity).__initialized);
|
|
325
|
-
const
|
|
325
|
+
const fields = meta.primaryKeys.concat(...concurrencyCheckKeys);
|
|
326
326
|
const $or = changeSets.map(cs => {
|
|
327
|
-
const cond = Utils.getPrimaryKeyCond(cs.originalEntity, primaryKeys);
|
|
327
|
+
const cond = Utils.getPrimaryKeyCond(cs.originalEntity, meta.primaryKeys);
|
|
328
|
+
for (const key of concurrencyCheckKeys) {
|
|
329
|
+
cond[key] = cs.originalEntity[key];
|
|
330
|
+
}
|
|
328
331
|
if (meta.ownsVersionProperty()) {
|
|
329
|
-
// @ts-ignore
|
|
330
332
|
cond[meta.versionProperty] = this.#platform.convertVersionValue(cs.entity[meta.versionProperty], meta.properties[meta.versionProperty]);
|
|
331
333
|
}
|
|
332
334
|
return cond;
|
|
333
335
|
});
|
|
334
336
|
options = this.prepareOptions(meta, options, {
|
|
335
|
-
fields
|
|
337
|
+
fields,
|
|
336
338
|
orderBy: meta.primaryKeys.reduce((o, pk) => {
|
|
337
339
|
o[pk] = 'asc';
|
|
338
340
|
return o;
|
|
@@ -344,8 +346,8 @@ export class ChangeSetPersister {
|
|
|
344
346
|
if (res.length !== changeSets.length) {
|
|
345
347
|
// a FK pointing to a composite PK is an array, so the values need to be compared deeply
|
|
346
348
|
const compare = (a, b, keys) => keys.every(k => equals(a[k], b[k]));
|
|
347
|
-
const entity = changeSets.find(
|
|
348
|
-
return !res.some(row => compare(
|
|
349
|
+
const entity = changeSets.find((_, index) => {
|
|
350
|
+
return !res.some(row => compare($or[index], row, meta.primaryKeys));
|
|
349
351
|
}).entity;
|
|
350
352
|
throw OptimisticLockError.lockFailed(entity);
|
|
351
353
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { EntityManager } from '../EntityManager.js';
|
|
2
2
|
/** Uses `AsyncLocalStorage` to maintain a transaction-scoped EntityManager context across async operations. */
|
|
3
3
|
export declare class TransactionContext {
|
|
4
|
+
#private;
|
|
4
5
|
readonly em: EntityManager;
|
|
5
6
|
private static storage;
|
|
6
7
|
readonly id: number;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
var _a;
|
|
1
2
|
import { createAsyncContext } from './AsyncContext.js';
|
|
2
3
|
/** Uses `AsyncLocalStorage` to maintain a transaction-scoped EntityManager context across async operations. */
|
|
3
4
|
export class TransactionContext {
|
|
4
5
|
em;
|
|
5
6
|
static storage = createAsyncContext();
|
|
7
|
+
#parent = _a.currentTransactionContext();
|
|
6
8
|
id;
|
|
7
9
|
constructor(em) {
|
|
8
10
|
this.em = em;
|
|
@@ -12,7 +14,7 @@ export class TransactionContext {
|
|
|
12
14
|
* Creates new TransactionContext instance and runs the code inside its domain.
|
|
13
15
|
*/
|
|
14
16
|
static create(em, next) {
|
|
15
|
-
const context = new
|
|
17
|
+
const context = new _a(em);
|
|
16
18
|
return this.storage.run(context, next);
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
@@ -25,7 +27,11 @@ export class TransactionContext {
|
|
|
25
27
|
* Returns current EntityManager (if available).
|
|
26
28
|
*/
|
|
27
29
|
static getEntityManager(name = 'default') {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
let context = _a.currentTransactionContext();
|
|
31
|
+
while (context && context.em.name !== name) {
|
|
32
|
+
context = context.#parent;
|
|
33
|
+
}
|
|
34
|
+
return context?.em;
|
|
30
35
|
}
|
|
31
36
|
}
|
|
37
|
+
_a = TransactionContext;
|
|
@@ -81,10 +81,10 @@ export class TransactionManager {
|
|
|
81
81
|
*/
|
|
82
82
|
async executeWithoutTransaction(em, cb, options) {
|
|
83
83
|
const suspended = this.suspendTransaction(em);
|
|
84
|
-
const fork = this.createFork(em,
|
|
84
|
+
const fork = this.createFork(em, options);
|
|
85
85
|
const propagateToUpperContext = this.shouldPropagateToUpperContext(em);
|
|
86
86
|
try {
|
|
87
|
-
return await this.executeTransactionFlow(fork, cb, propagateToUpperContext, em);
|
|
87
|
+
return await TransactionContext.create(fork, () => this.executeTransactionFlow(fork, cb, propagateToUpperContext, em));
|
|
88
88
|
}
|
|
89
89
|
finally {
|
|
90
90
|
this.resumeTransaction(em, suspended);
|
package/utils/Utils.js
CHANGED
|
@@ -153,7 +153,7 @@ export function parseJsonSafe(value) {
|
|
|
153
153
|
/** Collection of general-purpose utility methods used throughout the ORM. */
|
|
154
154
|
export class Utils {
|
|
155
155
|
static PK_SEPARATOR = '~~~';
|
|
156
|
-
static #ORM_VERSION = '7.2.2-dev.
|
|
156
|
+
static #ORM_VERSION = '7.2.2-dev.22';
|
|
157
157
|
/** Default session variable name backing an RLS filter argument (`current_setting('mikro.<filter>.<arg>')`). */
|
|
158
158
|
static getRlsSettingName(filterName, argName) {
|
|
159
159
|
return `mikro.${filterName}.${argName}`;
|