@mikro-orm/core 7.0.0-dev.321 → 7.0.0-dev.322
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/EntityManager.d.ts +2 -15
- package/EntityManager.js +155 -152
- package/MikroORM.d.ts +1 -3
- package/MikroORM.js +20 -20
- package/cache/FileCacheAdapter.d.ts +1 -5
- package/cache/FileCacheAdapter.js +22 -22
- package/cache/GeneratedCacheAdapter.d.ts +1 -1
- package/cache/GeneratedCacheAdapter.js +6 -6
- package/cache/MemoryCacheAdapter.d.ts +1 -2
- package/cache/MemoryCacheAdapter.js +8 -8
- package/entity/Collection.d.ts +2 -10
- package/entity/Collection.js +95 -105
- package/entity/EntityFactory.d.ts +1 -8
- package/entity/EntityFactory.js +48 -48
- package/entity/EntityLoader.d.ts +1 -3
- package/entity/EntityLoader.js +33 -34
- package/entity/Reference.d.ts +1 -2
- package/entity/Reference.js +11 -11
- package/events/EventManager.d.ts +1 -4
- package/events/EventManager.js +21 -21
- package/hydration/ObjectHydrator.d.ts +1 -2
- package/hydration/ObjectHydrator.js +11 -11
- package/metadata/MetadataDiscovery.d.ts +1 -9
- package/metadata/MetadataDiscovery.js +147 -144
- package/metadata/MetadataStorage.d.ts +1 -5
- package/metadata/MetadataStorage.js +36 -36
- package/package.json +1 -1
- package/serialization/SerializationContext.d.ts +2 -6
- package/serialization/SerializationContext.js +14 -14
- package/unit-of-work/ChangeSetComputer.d.ts +1 -6
- package/unit-of-work/ChangeSetComputer.js +21 -21
- package/unit-of-work/ChangeSetPersister.d.ts +1 -9
- package/unit-of-work/ChangeSetPersister.js +51 -51
- package/unit-of-work/CommitOrderCalculator.d.ts +1 -4
- package/unit-of-work/CommitOrderCalculator.js +13 -13
- package/unit-of-work/IdentityMap.d.ts +2 -5
- package/unit-of-work/IdentityMap.js +18 -18
- package/unit-of-work/UnitOfWork.d.ts +5 -19
- package/unit-of-work/UnitOfWork.js +181 -173
- package/utils/AbstractMigrator.d.ts +1 -1
- package/utils/AbstractMigrator.js +6 -6
- package/utils/Configuration.d.ts +1 -6
- package/utils/Configuration.js +78 -78
- package/utils/Cursor.d.ts +1 -1
- package/utils/Cursor.js +3 -3
- package/utils/EntityComparator.d.ts +2 -11
- package/utils/EntityComparator.js +44 -44
- package/utils/TransactionManager.js +1 -2
- package/utils/Utils.js +1 -1
- package/utils/clone.js +1 -1
|
@@ -6,20 +6,20 @@ import { Raw } from './RawQueryFragment.js';
|
|
|
6
6
|
import { EntityIdentifier } from '../entity/EntityIdentifier.js';
|
|
7
7
|
import { PolymorphicRef } from '../entity/PolymorphicRef.js';
|
|
8
8
|
export class EntityComparator {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
#comparators = new Map();
|
|
10
|
+
#mappers = new Map();
|
|
11
|
+
#snapshotGenerators = new Map();
|
|
12
|
+
#pkGetters = new Map();
|
|
13
|
+
#pkGettersConverted = new Map();
|
|
14
|
+
#pkSerializers = new Map();
|
|
15
|
+
#tmpIndex = 0;
|
|
16
|
+
#metadata;
|
|
17
|
+
#platform;
|
|
18
|
+
#config;
|
|
19
19
|
constructor(metadata, platform, config) {
|
|
20
|
-
this
|
|
21
|
-
this
|
|
22
|
-
this
|
|
20
|
+
this.#metadata = metadata;
|
|
21
|
+
this.#platform = platform;
|
|
22
|
+
this.#config = config;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Computes difference between two entities.
|
|
@@ -51,7 +51,7 @@ export class EntityComparator {
|
|
|
51
51
|
* @internal Highly performance-sensitive method.
|
|
52
52
|
*/
|
|
53
53
|
getPkGetter(meta) {
|
|
54
|
-
const exists = this
|
|
54
|
+
const exists = this.#pkGetters.get(meta);
|
|
55
55
|
/* v8 ignore next */
|
|
56
56
|
if (exists) {
|
|
57
57
|
return exists;
|
|
@@ -93,15 +93,15 @@ export class EntityComparator {
|
|
|
93
93
|
}
|
|
94
94
|
const code = `// compiled pk getter for entity ${meta.className}\n` + `return function(entity) {\n${lines.join('\n')}\n}`;
|
|
95
95
|
const fnKey = `pkGetter-${meta.uniqueName}`;
|
|
96
|
-
const pkSerializer = Utils.createFunction(context, code, this
|
|
97
|
-
this
|
|
96
|
+
const pkSerializer = Utils.createFunction(context, code, this.#config?.get('compiledFunctions'), fnKey);
|
|
97
|
+
this.#pkGetters.set(meta, pkSerializer);
|
|
98
98
|
return pkSerializer;
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
101
|
* @internal Highly performance-sensitive method.
|
|
102
102
|
*/
|
|
103
103
|
getPkGetterConverted(meta) {
|
|
104
|
-
const exists = this
|
|
104
|
+
const exists = this.#pkGettersConverted.get(meta);
|
|
105
105
|
/* v8 ignore next */
|
|
106
106
|
if (exists) {
|
|
107
107
|
return exists;
|
|
@@ -144,22 +144,22 @@ export class EntityComparator {
|
|
|
144
144
|
const code = `// compiled pk getter (with converted custom types) for entity ${meta.className}\n` +
|
|
145
145
|
`return function(entity) {\n${lines.join('\n')}\n}`;
|
|
146
146
|
const fnKey = `pkGetterConverted-${meta.uniqueName}`;
|
|
147
|
-
const pkSerializer = Utils.createFunction(context, code, this
|
|
148
|
-
this
|
|
147
|
+
const pkSerializer = Utils.createFunction(context, code, this.#config?.get('compiledFunctions'), fnKey);
|
|
148
|
+
this.#pkGettersConverted.set(meta, pkSerializer);
|
|
149
149
|
return pkSerializer;
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
152
152
|
* @internal Highly performance-sensitive method.
|
|
153
153
|
*/
|
|
154
154
|
getPkSerializer(meta) {
|
|
155
|
-
const exists = this
|
|
155
|
+
const exists = this.#pkSerializers.get(meta);
|
|
156
156
|
/* v8 ignore next */
|
|
157
157
|
if (exists) {
|
|
158
158
|
return exists;
|
|
159
159
|
}
|
|
160
160
|
const lines = [];
|
|
161
161
|
const context = new Map();
|
|
162
|
-
context.set('getCompositeKeyValue', (val) => Utils.flatten(Utils.getCompositeKeyValue(val, meta, 'convertToDatabaseValue', this
|
|
162
|
+
context.set('getCompositeKeyValue', (val) => Utils.flatten(Utils.getCompositeKeyValue(val, meta, 'convertToDatabaseValue', this.#platform)));
|
|
163
163
|
context.set('getPrimaryKeyHash', (val) => Utils.getPrimaryKeyHash(Utils.asArray(val)));
|
|
164
164
|
if (meta.primaryKeys.length > 1) {
|
|
165
165
|
lines.push(` const pks = entity.__helper.__pk ? getCompositeKeyValue(entity.__helper.__pk) : [`);
|
|
@@ -186,7 +186,7 @@ export class EntityComparator {
|
|
|
186
186
|
}
|
|
187
187
|
else if (prop.customType) {
|
|
188
188
|
const convertorKey = this.registerCustomType(meta.properties[pk], context);
|
|
189
|
-
const idx = this
|
|
189
|
+
const idx = this.#tmpIndex++;
|
|
190
190
|
lines.push(` const val_${idx} = convertToDatabaseValue_${convertorKey}(entity${this.wrap(pk)});`);
|
|
191
191
|
lines.push(` return getPrimaryKeyHash(val_${idx});`);
|
|
192
192
|
}
|
|
@@ -196,23 +196,23 @@ export class EntityComparator {
|
|
|
196
196
|
}
|
|
197
197
|
const code = `// compiled pk serializer for entity ${meta.className}\n` + `return function(entity) {\n${lines.join('\n')}\n}`;
|
|
198
198
|
const fnKey = `pkSerializer-${meta.uniqueName}`;
|
|
199
|
-
const pkSerializer = Utils.createFunction(context, code, this
|
|
200
|
-
this
|
|
199
|
+
const pkSerializer = Utils.createFunction(context, code, this.#config?.get('compiledFunctions'), fnKey);
|
|
200
|
+
this.#pkSerializers.set(meta, pkSerializer);
|
|
201
201
|
return pkSerializer;
|
|
202
202
|
}
|
|
203
203
|
/**
|
|
204
204
|
* @internal Highly performance-sensitive method.
|
|
205
205
|
*/
|
|
206
206
|
getSnapshotGenerator(entityName) {
|
|
207
|
-
const meta = this
|
|
208
|
-
const exists = this
|
|
207
|
+
const meta = this.#metadata.find(entityName);
|
|
208
|
+
const exists = this.#snapshotGenerators.get(meta);
|
|
209
209
|
if (exists) {
|
|
210
210
|
return exists;
|
|
211
211
|
}
|
|
212
212
|
const lines = [];
|
|
213
213
|
const context = new Map();
|
|
214
214
|
context.set('clone', clone);
|
|
215
|
-
context.set('cloneEmbeddable', (o) => this
|
|
215
|
+
context.set('cloneEmbeddable', (o) => this.#platform.cloneEmbeddable(o)); // do not clone prototypes
|
|
216
216
|
if (meta.root.inheritanceType === 'sti' && meta.discriminatorValue) {
|
|
217
217
|
lines.push(` ret${this.wrap(meta.root.discriminatorColumn)} = '${meta.discriminatorValue}'`);
|
|
218
218
|
}
|
|
@@ -226,8 +226,8 @@ export class EntityComparator {
|
|
|
226
226
|
.forEach(prop => lines.push(this.getPropertySnapshot(meta, prop, context, this.wrap(prop.name), this.wrap(prop.name), [prop.name])));
|
|
227
227
|
const code = `return function(entity) {\n const ret = {};\n${lines.join('\n')}\n return ret;\n}`;
|
|
228
228
|
const fnKey = `snapshotGenerator-${meta.uniqueName}`;
|
|
229
|
-
const snapshotGenerator = Utils.createFunction(context, code, this
|
|
230
|
-
this
|
|
229
|
+
const snapshotGenerator = Utils.createFunction(context, code, this.#config?.get('compiledFunctions'), fnKey);
|
|
230
|
+
this.#snapshotGenerators.set(meta, snapshotGenerator);
|
|
231
231
|
return snapshotGenerator;
|
|
232
232
|
}
|
|
233
233
|
/**
|
|
@@ -278,14 +278,14 @@ export class EntityComparator {
|
|
|
278
278
|
* @internal Highly performance-sensitive method.
|
|
279
279
|
*/
|
|
280
280
|
getResultMapper(meta) {
|
|
281
|
-
const exists = this
|
|
281
|
+
const exists = this.#mappers.get(meta);
|
|
282
282
|
if (exists) {
|
|
283
283
|
return exists;
|
|
284
284
|
}
|
|
285
285
|
const lines = [];
|
|
286
286
|
const context = new Map();
|
|
287
287
|
context.set('PolymorphicRef', PolymorphicRef);
|
|
288
|
-
const tz = this
|
|
288
|
+
const tz = this.#platform.getTimezone();
|
|
289
289
|
const parseDate = (key, value, padding = '') => {
|
|
290
290
|
lines.push(`${padding} if (${value} == null || ${value} instanceof Date) {`);
|
|
291
291
|
lines.push(`${padding} ${key} = ${value};`);
|
|
@@ -345,15 +345,15 @@ export class EntityComparator {
|
|
|
345
345
|
lines.push(`${padding} ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
|
|
346
346
|
lines.push(`${padding} }`);
|
|
347
347
|
}
|
|
348
|
-
else if (prop.runtimeType === 'Date' && !this
|
|
348
|
+
else if (prop.runtimeType === 'Date' && !this.#platform.isNumericProperty(prop)) {
|
|
349
349
|
lines.push(`${padding} if (typeof ${this.propName(prop.fieldNames[0])} !== 'undefined') {`);
|
|
350
|
-
context.set('parseDate', (value) => this
|
|
350
|
+
context.set('parseDate', (value) => this.#platform.parseDate(value));
|
|
351
351
|
parseDate('ret' + this.wrap(prop.name), this.propName(prop.fieldNames[0]), padding);
|
|
352
352
|
lines.push(`${padding} ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
|
|
353
353
|
lines.push(`${padding} }`);
|
|
354
354
|
}
|
|
355
355
|
else if (prop.kind === ReferenceKind.EMBEDDED && (prop.object || meta.embeddable)) {
|
|
356
|
-
const idx = this
|
|
356
|
+
const idx = this.#tmpIndex++;
|
|
357
357
|
context.set(`mapEmbeddedResult_${idx}`, (data) => {
|
|
358
358
|
const item = parseJsonSafe(data);
|
|
359
359
|
if (Array.isArray(item)) {
|
|
@@ -392,8 +392,8 @@ export class EntityComparator {
|
|
|
392
392
|
const code = `// compiled mapper for entity ${meta.className}\n` +
|
|
393
393
|
`return function(result) {\n const ret = {};\n${lines.join('\n')}\n return ret;\n}`;
|
|
394
394
|
const fnKey = `resultMapper-${meta.uniqueName}`;
|
|
395
|
-
const resultMapper = Utils.createFunction(context, code, this
|
|
396
|
-
this
|
|
395
|
+
const resultMapper = Utils.createFunction(context, code, this.#config?.get('compiledFunctions'), fnKey);
|
|
396
|
+
this.#mappers.set(meta, resultMapper);
|
|
397
397
|
return resultMapper;
|
|
398
398
|
}
|
|
399
399
|
getPropertyCondition(path) {
|
|
@@ -419,7 +419,7 @@ export class EntityComparator {
|
|
|
419
419
|
const entityKey = path.map(k => this.wrap(k)).join('');
|
|
420
420
|
const ret = [];
|
|
421
421
|
const padding = ' '.repeat(level * 2);
|
|
422
|
-
const idx = this
|
|
422
|
+
const idx = this.#tmpIndex++;
|
|
423
423
|
ret.push(`${padding}if (Array.isArray(entity${entityKey})) {`);
|
|
424
424
|
ret.push(`${padding} ret${dataKey} = [];`);
|
|
425
425
|
ret.push(`${padding} entity${entityKey}.forEach((_, idx_${idx}) => {`);
|
|
@@ -517,7 +517,7 @@ export class EntityComparator {
|
|
|
517
517
|
if (Raw.isKnownFragment(val)) {
|
|
518
518
|
return val;
|
|
519
519
|
}
|
|
520
|
-
return prop.customType.convertToDatabaseValue(val, this
|
|
520
|
+
return prop.customType.convertToDatabaseValue(val, this.#platform, { mode: 'serialization' });
|
|
521
521
|
});
|
|
522
522
|
return convertorKey;
|
|
523
523
|
}
|
|
@@ -602,7 +602,7 @@ export class EntityComparator {
|
|
|
602
602
|
return (ret + ` ret${dataKey} = clone(convertToDatabaseValue_${convertorKey}(entity${entityKey}${unwrap}));\n }\n`);
|
|
603
603
|
}
|
|
604
604
|
if (prop.runtimeType === 'Date') {
|
|
605
|
-
context.set('processDateProperty', this
|
|
605
|
+
context.set('processDateProperty', this.#platform.processDateProperty.bind(this.#platform));
|
|
606
606
|
return ret + ` ret${dataKey} = clone(processDateProperty(entity${entityKey}${unwrap}));\n }\n`;
|
|
607
607
|
}
|
|
608
608
|
return ret + ` ret${dataKey} = clone(entity${entityKey}${unwrap});\n }\n`;
|
|
@@ -611,8 +611,8 @@ export class EntityComparator {
|
|
|
611
611
|
* @internal Highly performance-sensitive method.
|
|
612
612
|
*/
|
|
613
613
|
getEntityComparator(entityName) {
|
|
614
|
-
const meta = this
|
|
615
|
-
const exists = this
|
|
614
|
+
const meta = this.#metadata.find(entityName);
|
|
615
|
+
const exists = this.#comparators.get(meta);
|
|
616
616
|
if (exists) {
|
|
617
617
|
return exists;
|
|
618
618
|
}
|
|
@@ -637,8 +637,8 @@ export class EntityComparator {
|
|
|
637
637
|
const code = `// compiled comparator for entity ${meta.className}\n` +
|
|
638
638
|
`return function(last, current, options) {\n const diff = {};\n${lines.join('\n')}\n return diff;\n}`;
|
|
639
639
|
const fnKey = `comparator-${meta.uniqueName}`;
|
|
640
|
-
const comparator = Utils.createFunction(context, code, this
|
|
641
|
-
this
|
|
640
|
+
const comparator = Utils.createFunction(context, code, this.#config?.get('compiledFunctions'), fnKey);
|
|
641
|
+
this.#comparators.set(meta, comparator);
|
|
642
642
|
return comparator;
|
|
643
643
|
}
|
|
644
644
|
getGenericComparator(prop, cond) {
|
|
@@ -669,7 +669,7 @@ export class EntityComparator {
|
|
|
669
669
|
}
|
|
670
670
|
if (prop.customType) {
|
|
671
671
|
if (prop.customType.compareValues) {
|
|
672
|
-
const idx = this
|
|
672
|
+
const idx = this.#tmpIndex++;
|
|
673
673
|
context.set(`compareValues_${idx}`, (a, b) => {
|
|
674
674
|
if (Raw.isKnownFragment(a) || Raw.isKnownFragment(b)) {
|
|
675
675
|
return Raw.getKnownFragment(a) === Raw.getKnownFragment(b);
|
|
@@ -160,8 +160,7 @@ export class TransactionManager {
|
|
|
160
160
|
for (const entity of fork.getUnitOfWork(false).getIdentityMap()) {
|
|
161
161
|
const wrapped = helper(entity);
|
|
162
162
|
const meta = wrapped.__meta;
|
|
163
|
-
|
|
164
|
-
const parentEntity = parentUoW.getById(meta.class, wrapped.getPrimaryKey(), parent['_schema'], true);
|
|
163
|
+
const parentEntity = parentUoW.getById(meta.class, wrapped.getPrimaryKey(), parent.schema, true);
|
|
165
164
|
if (parentEntity && parentEntity !== entity) {
|
|
166
165
|
const parentWrapped = helper(parentEntity);
|
|
167
166
|
parentWrapped.__data = wrapped.__data;
|
package/utils/Utils.js
CHANGED
|
@@ -123,7 +123,7 @@ export function parseJsonSafe(value) {
|
|
|
123
123
|
}
|
|
124
124
|
export class Utils {
|
|
125
125
|
static PK_SEPARATOR = '~~~';
|
|
126
|
-
static #ORM_VERSION = '7.0.0-dev.
|
|
126
|
+
static #ORM_VERSION = '7.0.0-dev.322';
|
|
127
127
|
/**
|
|
128
128
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
129
129
|
*/
|
package/utils/clone.js
CHANGED