@mikro-orm/core 7.0.0-dev.0 → 7.0.0-dev.2
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 +18 -13
- package/EntityManager.js +202 -202
- package/MikroORM.d.ts +7 -6
- package/MikroORM.js +33 -45
- package/cache/CacheAdapter.js +1 -2
- package/cache/FileCacheAdapter.d.ts +1 -1
- package/cache/FileCacheAdapter.js +18 -26
- package/cache/GeneratedCacheAdapter.d.ts +2 -2
- package/cache/GeneratedCacheAdapter.js +1 -5
- package/cache/MemoryCacheAdapter.d.ts +1 -1
- package/cache/MemoryCacheAdapter.js +1 -5
- package/cache/NullCacheAdapter.d.ts +1 -1
- package/cache/NullCacheAdapter.js +1 -5
- package/cache/index.d.ts +5 -5
- package/cache/index.js +5 -21
- package/connections/Connection.d.ts +7 -7
- package/connections/Connection.js +8 -12
- package/connections/index.d.ts +1 -1
- package/connections/index.js +1 -17
- package/decorators/Check.d.ts +1 -1
- package/decorators/Check.js +5 -8
- package/decorators/CreateRequestContext.d.ts +1 -1
- package/decorators/CreateRequestContext.js +9 -13
- package/decorators/Embeddable.d.ts +1 -1
- package/decorators/Embeddable.js +3 -6
- package/decorators/Embedded.d.ts +1 -1
- package/decorators/Embedded.js +10 -12
- package/decorators/Entity.d.ts +2 -2
- package/decorators/Entity.js +5 -8
- package/decorators/Enum.d.ts +2 -2
- package/decorators/Enum.js +7 -10
- package/decorators/Filter.d.ts +1 -1
- package/decorators/Filter.js +3 -6
- package/decorators/Formula.d.ts +2 -2
- package/decorators/Formula.js +7 -10
- package/decorators/Indexed.d.ts +2 -2
- package/decorators/Indexed.js +6 -10
- package/decorators/ManyToMany.d.ts +3 -3
- package/decorators/ManyToMany.js +10 -12
- package/decorators/ManyToOne.d.ts +3 -3
- package/decorators/ManyToOne.js +10 -12
- package/decorators/OneToMany.d.ts +3 -3
- package/decorators/OneToMany.js +11 -14
- package/decorators/OneToOne.d.ts +4 -4
- package/decorators/OneToOne.js +4 -7
- package/decorators/PrimaryKey.d.ts +2 -2
- package/decorators/PrimaryKey.js +10 -13
- package/decorators/Property.d.ts +5 -5
- package/decorators/Property.js +10 -12
- package/decorators/Transactional.d.ts +2 -2
- package/decorators/Transactional.js +7 -10
- package/decorators/hooks.js +23 -35
- package/decorators/index.d.ts +17 -17
- package/decorators/index.js +17 -36
- package/drivers/DatabaseDriver.d.ts +13 -12
- package/drivers/DatabaseDriver.js +60 -64
- package/drivers/IDatabaseDriver.d.ts +12 -12
- package/drivers/IDatabaseDriver.js +1 -4
- package/drivers/index.d.ts +2 -2
- package/drivers/index.js +2 -18
- package/entity/ArrayCollection.d.ts +2 -2
- package/entity/ArrayCollection.js +29 -33
- package/entity/BaseEntity.d.ts +6 -6
- package/entity/BaseEntity.js +17 -21
- package/entity/Collection.d.ts +6 -6
- package/entity/Collection.js +40 -44
- package/entity/EntityAssigner.d.ts +2 -2
- package/entity/EntityAssigner.js +58 -63
- package/entity/EntityFactory.d.ts +3 -3
- package/entity/EntityFactory.js +58 -62
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +41 -45
- package/entity/EntityIdentifier.d.ts +1 -1
- package/entity/EntityIdentifier.js +1 -5
- package/entity/EntityLoader.d.ts +5 -5
- package/entity/EntityLoader.js +92 -96
- package/entity/EntityRepository.d.ts +7 -7
- package/entity/EntityRepository.js +7 -11
- package/entity/EntityValidator.d.ts +1 -1
- package/entity/EntityValidator.js +25 -29
- package/entity/Reference.d.ts +2 -2
- package/entity/Reference.js +35 -42
- package/entity/WrappedEntity.d.ts +12 -12
- package/entity/WrappedEntity.js +23 -27
- package/entity/index.d.ts +13 -13
- package/entity/index.js +13 -29
- package/entity/utils.d.ts +1 -1
- package/entity/utils.js +9 -12
- package/entity/wrap.d.ts +1 -1
- package/entity/wrap.js +2 -6
- package/enums.d.ts +3 -3
- package/enums.js +37 -41
- package/errors.d.ts +1 -1
- package/errors.js +15 -24
- package/events/EventManager.d.ts +3 -3
- package/events/EventManager.js +8 -12
- package/events/EventSubscriber.d.ts +5 -4
- package/events/EventSubscriber.js +1 -2
- package/events/TransactionEventBroadcaster.d.ts +3 -3
- package/events/TransactionEventBroadcaster.js +1 -5
- package/events/index.d.ts +3 -3
- package/events/index.js +3 -19
- package/exceptions.js +18 -39
- package/hydration/Hydrator.d.ts +5 -5
- package/hydration/Hydrator.js +3 -6
- package/hydration/ObjectHydrator.d.ts +3 -3
- package/hydration/ObjectHydrator.js +25 -28
- package/hydration/index.d.ts +2 -2
- package/hydration/index.js +2 -18
- package/index.d.ts +21 -21
- package/index.js +21 -46
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +9 -13
- package/logging/Logger.d.ts +1 -1
- package/logging/Logger.js +1 -2
- package/logging/SimpleLogger.d.ts +2 -2
- package/logging/SimpleLogger.js +2 -6
- package/logging/colors.js +1 -5
- package/logging/index.d.ts +4 -4
- package/logging/index.js +4 -20
- package/metadata/EntitySchema.d.ts +12 -4
- package/metadata/EntitySchema.js +41 -45
- package/metadata/MetadataDiscovery.d.ts +7 -7
- package/metadata/MetadataDiscovery.js +174 -177
- package/metadata/MetadataProvider.d.ts +2 -2
- package/metadata/MetadataProvider.js +4 -7
- package/metadata/MetadataStorage.d.ts +2 -2
- package/metadata/MetadataStorage.js +15 -19
- package/metadata/MetadataValidator.d.ts +4 -4
- package/metadata/MetadataValidator.js +49 -53
- package/metadata/ReflectMetadataProvider.d.ts +2 -2
- package/metadata/ReflectMetadataProvider.js +8 -12
- package/metadata/index.d.ts +6 -6
- package/metadata/index.js +6 -22
- package/naming-strategy/AbstractNamingStrategy.d.ts +2 -2
- package/naming-strategy/AbstractNamingStrategy.js +4 -8
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +1 -1
- package/naming-strategy/EntityCaseNamingStrategy.js +2 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +1 -1
- package/naming-strategy/MongoNamingStrategy.js +2 -6
- package/naming-strategy/NamingStrategy.d.ts +1 -1
- package/naming-strategy/NamingStrategy.js +1 -2
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -1
- package/naming-strategy/UnderscoreNamingStrategy.js +2 -6
- package/naming-strategy/index.d.ts +5 -5
- package/naming-strategy/index.js +5 -21
- package/package.json +5 -14
- package/platforms/ExceptionConverter.d.ts +2 -2
- package/platforms/ExceptionConverter.js +4 -8
- package/platforms/Platform.d.ts +10 -10
- package/platforms/Platform.js +57 -61
- package/platforms/index.d.ts +2 -2
- package/platforms/index.js +2 -18
- package/serialization/EntitySerializer.d.ts +2 -2
- package/serialization/EntitySerializer.js +36 -41
- package/serialization/EntityTransformer.d.ts +1 -1
- package/serialization/EntityTransformer.js +27 -31
- package/serialization/SerializationContext.d.ts +2 -2
- package/serialization/SerializationContext.js +10 -14
- package/serialization/index.d.ts +3 -3
- package/serialization/index.js +3 -19
- package/types/ArrayType.d.ts +3 -3
- package/types/ArrayType.js +7 -11
- package/types/BigIntType.d.ts +3 -3
- package/types/BigIntType.js +3 -6
- package/types/BlobType.d.ts +3 -3
- package/types/BlobType.js +2 -8
- package/types/BooleanType.d.ts +3 -3
- package/types/BooleanType.js +2 -6
- package/types/CharacterType.d.ts +3 -3
- package/types/CharacterType.js +2 -6
- package/types/DateTimeType.d.ts +3 -3
- package/types/DateTimeType.js +2 -6
- package/types/DateType.d.ts +3 -3
- package/types/DateType.js +2 -6
- package/types/DecimalType.d.ts +3 -3
- package/types/DecimalType.js +4 -7
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +3 -6
- package/types/EnumArrayType.d.ts +4 -4
- package/types/EnumArrayType.js +5 -10
- package/types/EnumType.d.ts +3 -3
- package/types/EnumType.js +2 -6
- package/types/FloatType.d.ts +3 -3
- package/types/FloatType.js +2 -6
- package/types/IntegerType.d.ts +3 -3
- package/types/IntegerType.js +2 -6
- package/types/IntervalType.d.ts +3 -3
- package/types/IntervalType.js +2 -6
- package/types/JsonType.d.ts +3 -3
- package/types/JsonType.js +2 -6
- package/types/MediumIntType.d.ts +3 -3
- package/types/MediumIntType.js +2 -6
- package/types/SmallIntType.d.ts +3 -3
- package/types/SmallIntType.js +2 -6
- package/types/StringType.d.ts +3 -3
- package/types/StringType.js +2 -6
- package/types/TextType.d.ts +3 -3
- package/types/TextType.js +2 -6
- package/types/TimeType.d.ts +3 -3
- package/types/TimeType.js +4 -8
- package/types/TinyIntType.d.ts +3 -3
- package/types/TinyIntType.js +3 -6
- package/types/Type.d.ts +2 -2
- package/types/Type.js +5 -9
- package/types/Uint8ArrayType.d.ts +3 -3
- package/types/Uint8ArrayType.js +3 -9
- package/types/UnknownType.d.ts +3 -3
- package/types/UnknownType.js +2 -6
- package/types/UuidType.d.ts +3 -3
- package/types/UuidType.js +2 -6
- package/types/index.d.ts +25 -25
- package/types/index.js +52 -79
- package/typings.d.ts +22 -20
- package/typings.js +34 -38
- package/unit-of-work/ChangeSet.d.ts +1 -1
- package/unit-of-work/ChangeSet.js +13 -17
- package/unit-of-work/ChangeSetComputer.d.ts +8 -7
- package/unit-of-work/ChangeSetComputer.js +26 -30
- package/unit-of-work/ChangeSetPersister.d.ts +7 -6
- package/unit-of-work/ChangeSetPersister.js +44 -47
- package/unit-of-work/CommitOrderCalculator.d.ts +1 -1
- package/unit-of-work/CommitOrderCalculator.js +6 -10
- package/unit-of-work/IdentityMap.d.ts +1 -1
- package/unit-of-work/IdentityMap.js +1 -5
- package/unit-of-work/UnitOfWork.d.ts +8 -7
- package/unit-of-work/UnitOfWork.js +171 -172
- package/unit-of-work/index.d.ts +6 -6
- package/unit-of-work/index.js +6 -22
- package/utils/AbstractSchemaGenerator.d.ts +6 -6
- package/utils/AbstractSchemaGenerator.js +7 -11
- package/utils/Configuration.d.ts +26 -27
- package/utils/Configuration.js +50 -55
- package/utils/ConfigurationLoader.d.ts +9 -8
- package/utils/ConfigurationLoader.js +71 -86
- package/utils/Cursor.d.ts +3 -3
- package/utils/Cursor.js +22 -25
- package/utils/DataloaderUtils.d.ts +4 -4
- package/utils/DataloaderUtils.js +12 -16
- package/utils/EntityComparator.d.ts +2 -2
- package/utils/EntityComparator.js +48 -52
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +1 -5
- package/utils/QueryHelper.d.ts +3 -3
- package/utils/QueryHelper.js +47 -51
- package/utils/RawQueryFragment.d.ts +1 -1
- package/utils/RawQueryFragment.js +16 -24
- package/utils/RequestContext.d.ts +2 -2
- package/utils/RequestContext.js +3 -7
- package/utils/TransactionContext.d.ts +1 -1
- package/utils/TransactionContext.js +4 -8
- package/utils/Utils.d.ts +16 -12
- package/utils/Utils.js +89 -93
- package/utils/clone.js +8 -11
- package/utils/index.d.ts +13 -13
- package/utils/index.js +13 -29
- package/utils/resolveContextProvider.d.ts +3 -3
- package/utils/resolveContextProvider.js +9 -12
- package/utils/upsert-utils.d.ts +3 -3
- package/utils/upsert-utils.js +5 -9
- package/index.mjs +0 -199
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const enums_1 = require("../enums");
|
|
10
|
-
class ChangeSetPersister {
|
|
1
|
+
import { EntityIdentifier } from '../entity/EntityIdentifier.js';
|
|
2
|
+
import { helper } from '../entity/wrap.js';
|
|
3
|
+
import { ChangeSetType } from './ChangeSet.js';
|
|
4
|
+
import { isRaw } from '../utils/RawQueryFragment.js';
|
|
5
|
+
import { Utils } from '../utils/Utils.js';
|
|
6
|
+
import { OptimisticLockError } from '../errors.js';
|
|
7
|
+
import { ReferenceKind } from '../enums.js';
|
|
8
|
+
export class ChangeSetPersister {
|
|
11
9
|
driver;
|
|
12
10
|
metadata;
|
|
13
11
|
hydrator;
|
|
@@ -60,7 +58,7 @@ class ChangeSetPersister {
|
|
|
60
58
|
}
|
|
61
59
|
const size = this.config.get('batchSize');
|
|
62
60
|
const meta = changeSets[0].meta;
|
|
63
|
-
const pk =
|
|
61
|
+
const pk = Utils.getPrimaryKeyHash(meta.primaryKeys);
|
|
64
62
|
for (let i = 0; i < changeSets.length; i += size) {
|
|
65
63
|
const chunk = changeSets.slice(i, i + size);
|
|
66
64
|
const pks = chunk.map(cs => cs.getPrimaryKey());
|
|
@@ -86,12 +84,12 @@ class ChangeSetPersister {
|
|
|
86
84
|
for (const prop of meta.relations) {
|
|
87
85
|
this.processProperty(changeSet, prop);
|
|
88
86
|
}
|
|
89
|
-
if (changeSet.type ===
|
|
87
|
+
if (changeSet.type === ChangeSetType.CREATE && this.config.get('validateRequired')) {
|
|
90
88
|
this.validator.validateRequired(changeSet.entity);
|
|
91
89
|
}
|
|
92
90
|
}
|
|
93
91
|
async persistNewEntity(meta, changeSet, options) {
|
|
94
|
-
const wrapped =
|
|
92
|
+
const wrapped = helper(changeSet.entity);
|
|
95
93
|
options = this.propagateSchemaFromMetadata(meta, options, {
|
|
96
94
|
convertCustomTypes: false,
|
|
97
95
|
});
|
|
@@ -133,7 +131,7 @@ class ChangeSetPersister {
|
|
|
133
131
|
const res = await this.driver.nativeInsertMany(meta.className, changeSets.map(cs => cs.payload), options);
|
|
134
132
|
for (let i = 0; i < changeSets.length; i++) {
|
|
135
133
|
const changeSet = changeSets[i];
|
|
136
|
-
const wrapped =
|
|
134
|
+
const wrapped = helper(changeSet.entity);
|
|
137
135
|
if (!wrapped.hasPrimaryKey()) {
|
|
138
136
|
const field = meta.getPrimaryProps()[0].fieldNames[0];
|
|
139
137
|
this.mapPrimaryKey(meta, res.rows[i][field], changeSet);
|
|
@@ -172,7 +170,7 @@ class ChangeSetPersister {
|
|
|
172
170
|
}
|
|
173
171
|
}
|
|
174
172
|
if (tmp.length === 0 && meta.concurrencyCheckKeys.size > 0) {
|
|
175
|
-
throw
|
|
173
|
+
throw OptimisticLockError.lockFailed(changeSet.entity);
|
|
176
174
|
}
|
|
177
175
|
}
|
|
178
176
|
async persistManagedEntitiesBatch(meta, changeSets, options) {
|
|
@@ -191,10 +189,10 @@ class ChangeSetPersister {
|
|
|
191
189
|
}
|
|
192
190
|
const res = await this.driver.nativeUpdateMany(meta.className, cond, payload, options);
|
|
193
191
|
const map = new Map();
|
|
194
|
-
res.rows?.forEach(item => map.set(
|
|
192
|
+
res.rows?.forEach(item => map.set(Utils.getCompositeKeyHash(item, meta, true, this.platform, true), item));
|
|
195
193
|
for (const changeSet of changeSets) {
|
|
196
194
|
if (res.rows) {
|
|
197
|
-
const row = map.get(
|
|
195
|
+
const row = map.get(helper(changeSet.entity).getSerializedPrimaryKey());
|
|
198
196
|
this.mapReturnedValues(changeSet.entity, changeSet.payload, row, meta);
|
|
199
197
|
}
|
|
200
198
|
changeSet.persisted = true;
|
|
@@ -203,7 +201,7 @@ class ChangeSetPersister {
|
|
|
203
201
|
mapPrimaryKey(meta, value, changeSet) {
|
|
204
202
|
const prop = meta.properties[meta.primaryKeys[0]];
|
|
205
203
|
const insertId = prop.customType ? prop.customType.convertToJSValue(value, this.platform) : value;
|
|
206
|
-
const wrapped =
|
|
204
|
+
const wrapped = helper(changeSet.entity);
|
|
207
205
|
if (!wrapped.hasPrimaryKey()) {
|
|
208
206
|
wrapped.setPrimaryKey(insertId);
|
|
209
207
|
}
|
|
@@ -218,17 +216,17 @@ class ChangeSetPersister {
|
|
|
218
216
|
* Sets populate flag to new entities so they are serialized like if they were loaded from the db
|
|
219
217
|
*/
|
|
220
218
|
markAsPopulated(changeSet, meta) {
|
|
221
|
-
|
|
219
|
+
helper(changeSet.entity).__schema = this.driver.getSchemaName(meta, changeSet);
|
|
222
220
|
if (!this.config.get('populateAfterFlush')) {
|
|
223
221
|
return;
|
|
224
222
|
}
|
|
225
|
-
|
|
223
|
+
helper(changeSet.entity).populated();
|
|
226
224
|
meta.relations.forEach(prop => {
|
|
227
225
|
const value = changeSet.entity[prop.name];
|
|
228
|
-
if (
|
|
226
|
+
if (Utils.isEntity(value, true)) {
|
|
229
227
|
value.__helper.populated();
|
|
230
228
|
}
|
|
231
|
-
else if (
|
|
229
|
+
else if (Utils.isCollection(value)) {
|
|
232
230
|
value.populated();
|
|
233
231
|
}
|
|
234
232
|
});
|
|
@@ -252,9 +250,9 @@ class ChangeSetPersister {
|
|
|
252
250
|
return;
|
|
253
251
|
}
|
|
254
252
|
// skip entity references as they don't have version values loaded
|
|
255
|
-
changeSets = changeSets.filter(cs =>
|
|
253
|
+
changeSets = changeSets.filter(cs => helper(cs.entity).__initialized);
|
|
256
254
|
const $or = changeSets.map(cs => {
|
|
257
|
-
const cond =
|
|
255
|
+
const cond = Utils.getPrimaryKeyCond(cs.originalEntity, meta.primaryKeys.concat(...meta.concurrencyCheckKeys));
|
|
258
256
|
if (meta.versionProperty) {
|
|
259
257
|
// @ts-ignore
|
|
260
258
|
cond[meta.versionProperty] = this.platform.quoteVersionValue(cs.entity[meta.versionProperty], meta.properties[meta.versionProperty]);
|
|
@@ -269,14 +267,14 @@ class ChangeSetPersister {
|
|
|
269
267
|
if (res.length !== changeSets.length) {
|
|
270
268
|
const compare = (a, b, keys) => keys.every(k => a[k] === b[k]);
|
|
271
269
|
const entity = changeSets.find(cs => {
|
|
272
|
-
return !res.some(row => compare(
|
|
270
|
+
return !res.some(row => compare(Utils.getPrimaryKeyCond(cs.entity, primaryKeys), row, primaryKeys));
|
|
273
271
|
}).entity;
|
|
274
|
-
throw
|
|
272
|
+
throw OptimisticLockError.lockFailed(entity);
|
|
275
273
|
}
|
|
276
274
|
}
|
|
277
275
|
checkOptimisticLock(meta, changeSet, res) {
|
|
278
276
|
if ((meta.versionProperty || meta.concurrencyCheckKeys.size > 0) && res && !res.affectedRows) {
|
|
279
|
-
throw
|
|
277
|
+
throw OptimisticLockError.lockFailed(changeSet.entity);
|
|
280
278
|
}
|
|
281
279
|
}
|
|
282
280
|
/**
|
|
@@ -285,18 +283,18 @@ class ChangeSetPersister {
|
|
|
285
283
|
*/
|
|
286
284
|
async reloadVersionValues(meta, changeSets, options) {
|
|
287
285
|
const reloadProps = meta.versionProperty && !this.usesReturningStatement ? [meta.properties[meta.versionProperty]] : [];
|
|
288
|
-
if (changeSets[0].type ===
|
|
286
|
+
if (changeSets[0].type === ChangeSetType.CREATE) {
|
|
289
287
|
// do not reload things that already had a runtime value
|
|
290
288
|
meta.props
|
|
291
289
|
.filter(prop => prop.persist !== false && (prop.autoincrement || prop.generated || prop.defaultRaw))
|
|
292
|
-
.filter(prop => (changeSets[0].entity[prop.name] == null && prop.defaultRaw !== 'null') ||
|
|
290
|
+
.filter(prop => (changeSets[0].entity[prop.name] == null && prop.defaultRaw !== 'null') || isRaw(changeSets[0].entity[prop.name]))
|
|
293
291
|
.forEach(prop => reloadProps.push(prop));
|
|
294
292
|
}
|
|
295
|
-
if (changeSets[0].type ===
|
|
293
|
+
if (changeSets[0].type === ChangeSetType.UPDATE) {
|
|
296
294
|
const returning = new Set();
|
|
297
295
|
changeSets.forEach(cs => {
|
|
298
|
-
|
|
299
|
-
if (
|
|
296
|
+
Utils.keys(cs.payload).forEach(k => {
|
|
297
|
+
if (isRaw(cs.payload[k]) && isRaw(cs.entity[k])) {
|
|
300
298
|
returning.add(meta.properties[k]);
|
|
301
299
|
}
|
|
302
300
|
});
|
|
@@ -313,22 +311,22 @@ class ChangeSetPersister {
|
|
|
313
311
|
return;
|
|
314
312
|
}
|
|
315
313
|
reloadProps.unshift(...meta.getPrimaryProps());
|
|
316
|
-
const pk =
|
|
314
|
+
const pk = Utils.getPrimaryKeyHash(meta.primaryKeys);
|
|
317
315
|
const pks = changeSets.map(cs => {
|
|
318
|
-
const val =
|
|
319
|
-
if (
|
|
320
|
-
return
|
|
316
|
+
const val = helper(cs.entity).getPrimaryKey(true);
|
|
317
|
+
if (Utils.isPlainObject(val)) {
|
|
318
|
+
return Utils.getCompositeKeyValue(val, meta, false, this.platform);
|
|
321
319
|
}
|
|
322
320
|
return val;
|
|
323
321
|
});
|
|
324
322
|
options = this.propagateSchemaFromMetadata(meta, options, {
|
|
325
|
-
fields:
|
|
323
|
+
fields: Utils.unique(reloadProps.map(prop => prop.name)),
|
|
326
324
|
});
|
|
327
325
|
const data = await this.driver.find(meta.className, { [pk]: { $in: pks } }, options);
|
|
328
326
|
const map = new Map();
|
|
329
|
-
data.forEach(item => map.set(
|
|
327
|
+
data.forEach(item => map.set(Utils.getCompositeKeyHash(item, meta, true, this.platform, true), item));
|
|
330
328
|
for (const changeSet of changeSets) {
|
|
331
|
-
const data = map.get(
|
|
329
|
+
const data = map.get(helper(changeSet.entity).getSerializedPrimaryKey());
|
|
332
330
|
this.hydrator.hydrate(changeSet.entity, meta, data, this.factory, 'full', false, true);
|
|
333
331
|
Object.assign(changeSet.payload, data); // merge to the changeset payload, so it gets saved to the entity snapshot
|
|
334
332
|
}
|
|
@@ -336,21 +334,21 @@ class ChangeSetPersister {
|
|
|
336
334
|
processProperty(changeSet, prop) {
|
|
337
335
|
const meta = this.metadata.find(changeSet.name);
|
|
338
336
|
const value = changeSet.payload[prop.name]; // for inline embeddables
|
|
339
|
-
if (value instanceof
|
|
337
|
+
if (value instanceof EntityIdentifier) {
|
|
340
338
|
changeSet.payload[prop.name] = value.getValue();
|
|
341
339
|
return;
|
|
342
340
|
}
|
|
343
|
-
if (prop.kind ===
|
|
344
|
-
changeSet.payload[prop.name] = value.map(val => val instanceof
|
|
341
|
+
if (prop.kind === ReferenceKind.MANY_TO_MANY && Array.isArray(value)) {
|
|
342
|
+
changeSet.payload[prop.name] = value.map(val => val instanceof EntityIdentifier ? val.getValue() : val);
|
|
345
343
|
return;
|
|
346
344
|
}
|
|
347
345
|
if (prop.name in changeSet.payload) {
|
|
348
346
|
return;
|
|
349
347
|
}
|
|
350
|
-
const values =
|
|
348
|
+
const values = Utils.unwrapProperty(changeSet.payload, meta, prop, true); // for object embeddables
|
|
351
349
|
values.forEach(([value, indexes]) => {
|
|
352
|
-
if (value instanceof
|
|
353
|
-
|
|
350
|
+
if (value instanceof EntityIdentifier) {
|
|
351
|
+
Utils.setPayloadProperty(changeSet.payload, meta, prop, value.getValue(), indexes);
|
|
354
352
|
}
|
|
355
353
|
});
|
|
356
354
|
}
|
|
@@ -360,7 +358,7 @@ class ChangeSetPersister {
|
|
|
360
358
|
* We do need to map to the change set payload too, as it will be used in the originalEntityData for new entities.
|
|
361
359
|
*/
|
|
362
360
|
mapReturnedValues(entity, payload, row, meta, upsert = false) {
|
|
363
|
-
if ((!this.usesReturningStatement && !upsert) || !row || !
|
|
361
|
+
if ((!this.usesReturningStatement && !upsert) || !row || !Utils.hasObjectKeys(row)) {
|
|
364
362
|
return;
|
|
365
363
|
}
|
|
366
364
|
const mapped = this.comparator.mapResult(meta.className, row);
|
|
@@ -377,4 +375,3 @@ class ChangeSetPersister {
|
|
|
377
375
|
Object.assign(payload, mapped);
|
|
378
376
|
}
|
|
379
377
|
}
|
|
380
|
-
exports.ChangeSetPersister = ChangeSetPersister;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.CommitOrderCalculator = exports.NodeState = void 0;
|
|
4
|
-
const enums_1 = require("../enums");
|
|
5
|
-
var NodeState;
|
|
1
|
+
import { ReferenceKind } from '../enums.js';
|
|
2
|
+
export var NodeState;
|
|
6
3
|
(function (NodeState) {
|
|
7
4
|
NodeState[NodeState["NOT_VISITED"] = 0] = "NOT_VISITED";
|
|
8
5
|
NodeState[NodeState["IN_PROGRESS"] = 1] = "IN_PROGRESS";
|
|
9
6
|
NodeState[NodeState["VISITED"] = 2] = "VISITED";
|
|
10
|
-
})(NodeState || (
|
|
7
|
+
})(NodeState || (NodeState = {}));
|
|
11
8
|
/**
|
|
12
9
|
* CommitOrderCalculator implements topological sorting, which is an ordering
|
|
13
10
|
* algorithm for directed graphs (DG) and/or directed acyclic graphs (DAG) by
|
|
@@ -18,7 +15,7 @@ var NodeState;
|
|
|
18
15
|
* Based on https://github.com/doctrine/orm/blob/master/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php
|
|
19
16
|
* @internal
|
|
20
17
|
*/
|
|
21
|
-
class CommitOrderCalculator {
|
|
18
|
+
export class CommitOrderCalculator {
|
|
22
19
|
/** Matrix of nodes, keys are provided hashes and values are the node definition objects. */
|
|
23
20
|
nodes = {};
|
|
24
21
|
/** Volatile variable holding calculated nodes during sorting process. */
|
|
@@ -42,8 +39,8 @@ class CommitOrderCalculator {
|
|
|
42
39
|
this.nodes[from].dependencies[to] = { from, to, weight };
|
|
43
40
|
}
|
|
44
41
|
discoverProperty(prop, entityName) {
|
|
45
|
-
const toOneOwner = (prop.kind ===
|
|
46
|
-
const toManyOwner = prop.kind ===
|
|
42
|
+
const toOneOwner = (prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner) || prop.kind === ReferenceKind.MANY_TO_ONE;
|
|
43
|
+
const toManyOwner = prop.kind === ReferenceKind.MANY_TO_MANY && prop.owner && !prop.pivotEntity;
|
|
47
44
|
if (!toOneOwner && !toManyOwner) {
|
|
48
45
|
return;
|
|
49
46
|
}
|
|
@@ -110,4 +107,3 @@ class CommitOrderCalculator {
|
|
|
110
107
|
this.sortedNodeList.push(target.hash);
|
|
111
108
|
}
|
|
112
109
|
}
|
|
113
|
-
exports.CommitOrderCalculator = CommitOrderCalculator;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IdentityMap = void 0;
|
|
4
|
-
class IdentityMap {
|
|
1
|
+
export class IdentityMap {
|
|
5
2
|
defaultSchema;
|
|
6
3
|
constructor(defaultSchema) {
|
|
7
4
|
this.defaultSchema = defaultSchema;
|
|
@@ -73,4 +70,3 @@ class IdentityMap {
|
|
|
73
70
|
return hash;
|
|
74
71
|
}
|
|
75
72
|
}
|
|
76
|
-
exports.IdentityMap = IdentityMap;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { AnyEntity, EntityData, EntityMetadata, EntityProperty, FilterQuery, Primary } from '../typings';
|
|
2
|
-
import { Collection
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
1
|
+
import type { AnyEntity, EntityData, EntityMetadata, EntityProperty, FilterQuery, Primary } from '../typings.js';
|
|
2
|
+
import { Collection } from '../entity/Collection.js';
|
|
3
|
+
import { Reference } from '../entity/Reference.js';
|
|
4
|
+
import { ChangeSet, ChangeSetType } from './ChangeSet.js';
|
|
5
|
+
import { ChangeSetPersister } from './ChangeSetPersister.js';
|
|
6
|
+
import type { EntityManager } from '../EntityManager.js';
|
|
7
|
+
import { IdentityMap } from './IdentityMap.js';
|
|
8
|
+
import type { LockOptions } from '../drivers/IDatabaseDriver.js';
|
|
8
9
|
export declare class UnitOfWork {
|
|
9
10
|
private readonly em;
|
|
10
11
|
/** map of references to managed entities */
|