@mikro-orm/core 7.0.0-rc.3 → 7.0.1-dev.0
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 +4 -6
- package/MikroORM.js +20 -20
- package/README.md +5 -4
- 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/cache/index.d.ts +1 -1
- package/cache/index.js +0 -1
- package/connections/Connection.d.ts +1 -0
- package/connections/Connection.js +27 -11
- package/drivers/DatabaseDriver.d.ts +0 -2
- package/drivers/DatabaseDriver.js +2 -4
- package/entity/Collection.d.ts +1 -9
- 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 +36 -39
- package/entity/Reference.d.ts +1 -2
- package/entity/Reference.js +11 -11
- package/entity/WrappedEntity.d.ts +4 -2
- package/entity/defineEntity.d.ts +18 -73
- package/enums.d.ts +2 -1
- package/enums.js +1 -0
- package/errors.d.ts +11 -11
- package/errors.js +3 -13
- package/events/EventManager.d.ts +1 -4
- package/events/EventManager.js +25 -22
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/exceptions.js +8 -6
- package/hydration/ObjectHydrator.d.ts +1 -2
- package/hydration/ObjectHydrator.js +16 -16
- package/logging/DefaultLogger.js +3 -2
- package/logging/Logger.d.ts +2 -1
- package/logging/colors.js +1 -1
- package/logging/index.d.ts +1 -1
- package/logging/index.js +0 -1
- package/metadata/EntitySchema.d.ts +1 -1
- package/metadata/MetadataDiscovery.d.ts +1 -9
- package/metadata/MetadataDiscovery.js +162 -149
- package/metadata/MetadataStorage.d.ts +1 -5
- package/metadata/MetadataStorage.js +36 -36
- package/metadata/discover-entities.js +1 -1
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/naming-strategy/AbstractNamingStrategy.js +1 -1
- package/naming-strategy/EntityCaseNamingStrategy.js +1 -1
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/package.json +1 -1
- package/platforms/Platform.d.ts +23 -1
- package/platforms/Platform.js +57 -4
- package/serialization/EntitySerializer.js +1 -1
- package/serialization/EntityTransformer.js +4 -1
- package/serialization/SerializationContext.d.ts +4 -8
- package/serialization/SerializationContext.js +20 -15
- package/types/UuidType.d.ts +2 -0
- package/types/UuidType.js +14 -2
- package/types/index.d.ts +2 -1
- package/typings.d.ts +12 -1
- 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 +52 -52
- 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 +182 -174
- package/utils/AbstractMigrator.d.ts +1 -1
- package/utils/AbstractMigrator.js +7 -7
- package/utils/Configuration.d.ts +90 -189
- package/utils/Configuration.js +94 -78
- package/utils/Cursor.d.ts +3 -3
- package/utils/Cursor.js +4 -4
- package/utils/EntityComparator.d.ts +8 -15
- package/utils/EntityComparator.js +49 -49
- package/utils/QueryHelper.d.ts +16 -1
- package/utils/QueryHelper.js +70 -24
- package/utils/RawQueryFragment.d.ts +4 -4
- package/utils/TransactionManager.js +1 -2
- package/utils/Utils.d.ts +1 -1
- package/utils/Utils.js +5 -4
- package/utils/clone.js +5 -0
- package/utils/fs-utils.d.ts +3 -17
- package/utils/fs-utils.js +1 -1
- package/utils/upsert-utils.js +1 -1
package/entity/Collection.js
CHANGED
|
@@ -7,24 +7,24 @@ import { QueryHelper } from '../utils/QueryHelper.js';
|
|
|
7
7
|
import { inspect } from '../logging/inspect.js';
|
|
8
8
|
export class Collection {
|
|
9
9
|
owner;
|
|
10
|
-
items = new Set();
|
|
11
|
-
initialized = true;
|
|
12
|
-
dirty = false;
|
|
13
|
-
partial = false; // mark partially loaded collections, propagation is disabled for those
|
|
14
|
-
snapshot = []; // used to create a diff of the collection at commit time, undefined marks overridden values so we need to wipe when flushing
|
|
15
|
-
readonly;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
#items = new Set();
|
|
11
|
+
#initialized = true;
|
|
12
|
+
#dirty = false;
|
|
13
|
+
#partial = false; // mark partially loaded collections, propagation is disabled for those
|
|
14
|
+
#snapshot = []; // used to create a diff of the collection at commit time, undefined marks overridden values so we need to wipe when flushing
|
|
15
|
+
#readonly;
|
|
16
|
+
#count;
|
|
17
|
+
#property;
|
|
18
|
+
#populated;
|
|
19
19
|
constructor(owner, items, initialized = true) {
|
|
20
20
|
this.owner = owner;
|
|
21
21
|
/* v8 ignore next */
|
|
22
22
|
if (items) {
|
|
23
23
|
let i = 0;
|
|
24
|
-
this
|
|
25
|
-
this
|
|
24
|
+
this.#items = new Set(items);
|
|
25
|
+
this.#items.forEach(item => (this[i++] = item));
|
|
26
26
|
}
|
|
27
|
-
this
|
|
27
|
+
this.#initialized = !!items || initialized;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Creates new Collection instance, assigns it to the owning entity and sets the items to it (propagating them to their inverse sides)
|
|
@@ -44,9 +44,9 @@ export class Collection {
|
|
|
44
44
|
*/
|
|
45
45
|
async load(options = {}) {
|
|
46
46
|
if (this.isInitialized(true) && !options.refresh) {
|
|
47
|
-
const em = this.getEntityManager(this
|
|
47
|
+
const em = this.getEntityManager(this.#items, false);
|
|
48
48
|
options = { ...options, filters: QueryHelper.mergePropertyFilters(this.property.filters, options.filters) };
|
|
49
|
-
await em?.populate(this
|
|
49
|
+
await em?.populate(this.#items, options.populate, options);
|
|
50
50
|
this.setSerializationContext(options);
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
@@ -75,19 +75,19 @@ export class Collection {
|
|
|
75
75
|
async loadCount(options = {}) {
|
|
76
76
|
options = typeof options === 'boolean' ? { refresh: options } : options;
|
|
77
77
|
const { refresh, where, ...countOptions } = options;
|
|
78
|
-
if (!refresh && !where && this
|
|
79
|
-
return this
|
|
78
|
+
if (!refresh && !where && this.#count != null) {
|
|
79
|
+
return this.#count;
|
|
80
80
|
}
|
|
81
81
|
const em = this.getEntityManager();
|
|
82
82
|
if (!em.getPlatform().usesPivotTable() &&
|
|
83
83
|
this.property.kind === ReferenceKind.MANY_TO_MANY &&
|
|
84
84
|
this.property.owner) {
|
|
85
|
-
return (this
|
|
85
|
+
return (this.#count = this.length);
|
|
86
86
|
}
|
|
87
87
|
const cond = this.createLoadCountCondition(where ?? {});
|
|
88
88
|
const count = await em.count(this.property.targetMeta.class, cond, countOptions);
|
|
89
89
|
if (!where) {
|
|
90
|
-
this
|
|
90
|
+
this.#count = count;
|
|
91
91
|
}
|
|
92
92
|
return count;
|
|
93
93
|
}
|
|
@@ -115,7 +115,7 @@ export class Collection {
|
|
|
115
115
|
this.hydrate(items, true);
|
|
116
116
|
this.setSerializationContext(options);
|
|
117
117
|
this.populated();
|
|
118
|
-
this
|
|
118
|
+
this.#readonly = true;
|
|
119
119
|
}
|
|
120
120
|
return items;
|
|
121
121
|
}
|
|
@@ -126,7 +126,7 @@ export class Collection {
|
|
|
126
126
|
if (check) {
|
|
127
127
|
this.checkInitialized();
|
|
128
128
|
}
|
|
129
|
-
return [...this
|
|
129
|
+
return [...this.#items];
|
|
130
130
|
}
|
|
131
131
|
toJSON() {
|
|
132
132
|
if (!this.isInitialized()) {
|
|
@@ -144,10 +144,10 @@ export class Collection {
|
|
|
144
144
|
const entity = Reference.unwrapReference(item);
|
|
145
145
|
if (!this.contains(entity, false)) {
|
|
146
146
|
this.incrementCount(1);
|
|
147
|
-
this[this
|
|
148
|
-
this
|
|
147
|
+
this[this.#items.size] = entity;
|
|
148
|
+
this.#items.add(entity);
|
|
149
149
|
added++;
|
|
150
|
-
this
|
|
150
|
+
this.#dirty = true;
|
|
151
151
|
this.propagate(entity, 'add');
|
|
152
152
|
}
|
|
153
153
|
}
|
|
@@ -166,7 +166,7 @@ export class Collection {
|
|
|
166
166
|
remove(entity, ...entities) {
|
|
167
167
|
if (entity instanceof Function) {
|
|
168
168
|
let removed = 0;
|
|
169
|
-
for (const item of this
|
|
169
|
+
for (const item of this.#items) {
|
|
170
170
|
if (entity(item)) {
|
|
171
171
|
removed += this.remove(item);
|
|
172
172
|
}
|
|
@@ -184,12 +184,12 @@ export class Collection {
|
|
|
184
184
|
continue;
|
|
185
185
|
}
|
|
186
186
|
const entity = Reference.unwrapReference(item);
|
|
187
|
-
if (this
|
|
187
|
+
if (this.#items.delete(entity)) {
|
|
188
188
|
this.incrementCount(-1);
|
|
189
|
-
delete this[this
|
|
189
|
+
delete this[this.#items.size]; // remove last item
|
|
190
190
|
this.propagate(entity, 'remove');
|
|
191
191
|
removed++;
|
|
192
|
-
this
|
|
192
|
+
this.#dirty = true;
|
|
193
193
|
}
|
|
194
194
|
if (this.property.orphanRemoval && em) {
|
|
195
195
|
em.getUnitOfWork().scheduleOrphanRemoval(entity);
|
|
@@ -199,7 +199,7 @@ export class Collection {
|
|
|
199
199
|
em.persist(entities);
|
|
200
200
|
}
|
|
201
201
|
if (removed > 0) {
|
|
202
|
-
Object.assign(this, [...this
|
|
202
|
+
Object.assign(this, [...this.#items]); // reassign array access
|
|
203
203
|
}
|
|
204
204
|
return removed;
|
|
205
205
|
}
|
|
@@ -208,11 +208,11 @@ export class Collection {
|
|
|
208
208
|
this.checkInitialized();
|
|
209
209
|
}
|
|
210
210
|
const entity = Reference.unwrapReference(item);
|
|
211
|
-
return this
|
|
211
|
+
return this.#items.has(entity);
|
|
212
212
|
}
|
|
213
213
|
count() {
|
|
214
214
|
this.checkInitialized();
|
|
215
|
-
return this
|
|
215
|
+
return this.#items.size;
|
|
216
216
|
}
|
|
217
217
|
isEmpty() {
|
|
218
218
|
this.checkInitialized();
|
|
@@ -222,18 +222,18 @@ export class Collection {
|
|
|
222
222
|
if (!this.isInitialized(true)) {
|
|
223
223
|
return false;
|
|
224
224
|
}
|
|
225
|
-
if (this
|
|
226
|
-
return this
|
|
225
|
+
if (this.#populated != null) {
|
|
226
|
+
return this.#populated;
|
|
227
227
|
}
|
|
228
228
|
return !!populated;
|
|
229
229
|
}
|
|
230
230
|
populated(populated = true) {
|
|
231
|
-
this
|
|
231
|
+
this.#populated = populated;
|
|
232
232
|
}
|
|
233
233
|
async init(options = {}) {
|
|
234
|
-
if (this
|
|
235
|
-
const items = [...this
|
|
236
|
-
this
|
|
234
|
+
if (this.#dirty) {
|
|
235
|
+
const items = [...this.#items];
|
|
236
|
+
this.#dirty = false;
|
|
237
237
|
await this.init(options);
|
|
238
238
|
items.forEach(i => this.add(i));
|
|
239
239
|
return this;
|
|
@@ -241,28 +241,28 @@ export class Collection {
|
|
|
241
241
|
const em = this.getEntityManager();
|
|
242
242
|
options = { ...options, filters: QueryHelper.mergePropertyFilters(this.property.filters, options.filters) };
|
|
243
243
|
if (options.dataloader ?? [DataloaderType.ALL, DataloaderType.COLLECTION].includes(em.config.getDataloaderType())) {
|
|
244
|
-
const order = [...this
|
|
244
|
+
const order = [...this.#items]; // copy order of references
|
|
245
245
|
const orderBy = QueryHelper.mergeOrderBy(options.orderBy, this.property.orderBy, this.property.targetMeta?.orderBy);
|
|
246
246
|
const customOrder = orderBy.length > 0;
|
|
247
247
|
const pivotTable = this.property.kind === ReferenceKind.MANY_TO_MANY && em.getPlatform().usesPivotTable();
|
|
248
248
|
const loader = await em.getDataLoader(pivotTable ? 'm:n' : '1:m');
|
|
249
249
|
const items = await loader.load([this, { ...options, orderBy }]);
|
|
250
250
|
if (this.property.kind === ReferenceKind.MANY_TO_MANY) {
|
|
251
|
-
this
|
|
252
|
-
this
|
|
251
|
+
this.#initialized = true;
|
|
252
|
+
this.#dirty = false;
|
|
253
253
|
if (!customOrder) {
|
|
254
254
|
this.reorderItems(items, order);
|
|
255
255
|
}
|
|
256
256
|
return this;
|
|
257
257
|
}
|
|
258
|
-
this
|
|
258
|
+
this.#items.clear();
|
|
259
259
|
let i = 0;
|
|
260
260
|
for (const item of items) {
|
|
261
|
-
this
|
|
261
|
+
this.#items.add(item);
|
|
262
262
|
this[i++] = item;
|
|
263
263
|
}
|
|
264
|
-
this
|
|
265
|
-
this
|
|
264
|
+
this.#initialized = true;
|
|
265
|
+
this.#dirty = false;
|
|
266
266
|
return this;
|
|
267
267
|
}
|
|
268
268
|
const populate = Array.isArray(options.populate)
|
|
@@ -311,7 +311,7 @@ export class Collection {
|
|
|
311
311
|
// we know there is at least one item as it was checked in load method
|
|
312
312
|
const pk = this.property.targetMeta.primaryKeys[0];
|
|
313
313
|
dict[pk] = { $in: [] };
|
|
314
|
-
this
|
|
314
|
+
this.#items.forEach(item => dict[pk].$in.push(helper(item).getPrimaryKey()));
|
|
315
315
|
}
|
|
316
316
|
else {
|
|
317
317
|
dict[this.property.mappedBy] = helper(this.owner).getPrimaryKey();
|
|
@@ -353,7 +353,7 @@ export class Collection {
|
|
|
353
353
|
}
|
|
354
354
|
}
|
|
355
355
|
validateModification(items) {
|
|
356
|
-
if (this
|
|
356
|
+
if (this.#readonly) {
|
|
357
357
|
throw ValidationError.cannotModifyReadonlyCollection(this.owner, this.property);
|
|
358
358
|
}
|
|
359
359
|
const check = (item) => {
|
|
@@ -378,7 +378,7 @@ export class Collection {
|
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
toArray() {
|
|
381
|
-
if (this
|
|
381
|
+
if (this.#items.size === 0) {
|
|
382
382
|
return [];
|
|
383
383
|
}
|
|
384
384
|
return this.map(item => wrap(item).toJSON());
|
|
@@ -411,28 +411,28 @@ export class Collection {
|
|
|
411
411
|
addWithoutPropagation(entity) {
|
|
412
412
|
if (!this.contains(entity, false)) {
|
|
413
413
|
this.incrementCount(1);
|
|
414
|
-
this[this
|
|
415
|
-
this
|
|
416
|
-
this
|
|
414
|
+
this[this.#items.size] = entity;
|
|
415
|
+
this.#items.add(entity);
|
|
416
|
+
this.#dirty = true;
|
|
417
417
|
}
|
|
418
418
|
}
|
|
419
419
|
set(items) {
|
|
420
|
-
if (!this
|
|
421
|
-
this
|
|
422
|
-
this
|
|
420
|
+
if (!this.#initialized) {
|
|
421
|
+
this.#initialized = true;
|
|
422
|
+
this.#snapshot = undefined;
|
|
423
423
|
}
|
|
424
424
|
if (this.compare(Utils.asArray(items).map(item => Reference.unwrapReference(item)))) {
|
|
425
425
|
return;
|
|
426
426
|
}
|
|
427
|
-
this.remove(this
|
|
427
|
+
this.remove(this.#items);
|
|
428
428
|
this.add(items);
|
|
429
429
|
}
|
|
430
430
|
compare(items) {
|
|
431
|
-
if (items.length !== this
|
|
431
|
+
if (items.length !== this.#items.size) {
|
|
432
432
|
return false;
|
|
433
433
|
}
|
|
434
434
|
let idx = 0;
|
|
435
|
-
for (const item of this
|
|
435
|
+
for (const item of this.#items) {
|
|
436
436
|
if (item !== items[idx++]) {
|
|
437
437
|
return false;
|
|
438
438
|
}
|
|
@@ -443,13 +443,13 @@ export class Collection {
|
|
|
443
443
|
* @internal
|
|
444
444
|
*/
|
|
445
445
|
hydrate(items, forcePropagate, partial) {
|
|
446
|
-
for (let i = 0; i < this
|
|
446
|
+
for (let i = 0; i < this.#items.size; i++) {
|
|
447
447
|
delete this[i];
|
|
448
448
|
}
|
|
449
|
-
this
|
|
450
|
-
this
|
|
451
|
-
this
|
|
452
|
-
this
|
|
449
|
+
this.#initialized = true;
|
|
450
|
+
this.#partial = !!partial;
|
|
451
|
+
this.#items.clear();
|
|
452
|
+
this.#count = 0;
|
|
453
453
|
this.add(items);
|
|
454
454
|
this.takeSnapshot(forcePropagate);
|
|
455
455
|
}
|
|
@@ -460,24 +460,24 @@ export class Collection {
|
|
|
460
460
|
* which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
|
|
461
461
|
*/
|
|
462
462
|
removeAll() {
|
|
463
|
-
if (!this
|
|
464
|
-
this
|
|
465
|
-
this
|
|
463
|
+
if (!this.#initialized) {
|
|
464
|
+
this.#initialized = true;
|
|
465
|
+
this.#snapshot = undefined;
|
|
466
466
|
}
|
|
467
|
-
this.remove(this
|
|
468
|
-
this
|
|
467
|
+
this.remove(this.#items);
|
|
468
|
+
this.#dirty = true;
|
|
469
469
|
}
|
|
470
470
|
/**
|
|
471
471
|
* @internal
|
|
472
472
|
*/
|
|
473
473
|
removeWithoutPropagation(entity) {
|
|
474
|
-
if (!this
|
|
474
|
+
if (!this.#items.delete(entity)) {
|
|
475
475
|
return;
|
|
476
476
|
}
|
|
477
477
|
this.incrementCount(-1);
|
|
478
|
-
delete this[this
|
|
479
|
-
Object.assign(this, [...this
|
|
480
|
-
this
|
|
478
|
+
delete this[this.#items.size];
|
|
479
|
+
Object.assign(this, [...this.#items]);
|
|
480
|
+
this.#dirty = true;
|
|
481
481
|
}
|
|
482
482
|
/**
|
|
483
483
|
* Extracts a slice of the collection items starting at position start to end (exclusive) of the collection.
|
|
@@ -486,9 +486,9 @@ export class Collection {
|
|
|
486
486
|
slice(start = 0, end) {
|
|
487
487
|
this.checkInitialized();
|
|
488
488
|
let index = 0;
|
|
489
|
-
end ??= this
|
|
489
|
+
end ??= this.#items.size;
|
|
490
490
|
const items = [];
|
|
491
|
-
for (const item of this
|
|
491
|
+
for (const item of this.#items) {
|
|
492
492
|
if (index === end) {
|
|
493
493
|
break;
|
|
494
494
|
}
|
|
@@ -504,7 +504,7 @@ export class Collection {
|
|
|
504
504
|
*/
|
|
505
505
|
exists(cb) {
|
|
506
506
|
this.checkInitialized();
|
|
507
|
-
for (const item of this
|
|
507
|
+
for (const item of this.#items) {
|
|
508
508
|
if (cb(item)) {
|
|
509
509
|
return true;
|
|
510
510
|
}
|
|
@@ -517,7 +517,7 @@ export class Collection {
|
|
|
517
517
|
find(cb) {
|
|
518
518
|
this.checkInitialized();
|
|
519
519
|
let index = 0;
|
|
520
|
-
for (const item of this
|
|
520
|
+
for (const item of this.#items) {
|
|
521
521
|
if (cb(item, index++)) {
|
|
522
522
|
return item;
|
|
523
523
|
}
|
|
@@ -531,7 +531,7 @@ export class Collection {
|
|
|
531
531
|
this.checkInitialized();
|
|
532
532
|
const items = [];
|
|
533
533
|
let index = 0;
|
|
534
|
-
for (const item of this
|
|
534
|
+
for (const item of this.#items) {
|
|
535
535
|
if (cb(item, index++)) {
|
|
536
536
|
items.push(item);
|
|
537
537
|
}
|
|
@@ -545,7 +545,7 @@ export class Collection {
|
|
|
545
545
|
this.checkInitialized();
|
|
546
546
|
const items = [];
|
|
547
547
|
let index = 0;
|
|
548
|
-
for (const item of this
|
|
548
|
+
for (const item of this.#items) {
|
|
549
549
|
items.push(mapper(item, index++));
|
|
550
550
|
}
|
|
551
551
|
return items;
|
|
@@ -556,7 +556,7 @@ export class Collection {
|
|
|
556
556
|
reduce(cb, initial = {}) {
|
|
557
557
|
this.checkInitialized();
|
|
558
558
|
let index = 0;
|
|
559
|
-
for (const item of this
|
|
559
|
+
for (const item of this.#items) {
|
|
560
560
|
initial = cb(initial, item, index++);
|
|
561
561
|
}
|
|
562
562
|
return initial;
|
|
@@ -572,10 +572,10 @@ export class Collection {
|
|
|
572
572
|
}, {});
|
|
573
573
|
}
|
|
574
574
|
isInitialized(fully = false) {
|
|
575
|
-
if (!this
|
|
576
|
-
return this
|
|
575
|
+
if (!this.#initialized || !fully) {
|
|
576
|
+
return this.#initialized;
|
|
577
577
|
}
|
|
578
|
-
for (const item of this
|
|
578
|
+
for (const item of this.#items) {
|
|
579
579
|
if (!helper(item).__initialized) {
|
|
580
580
|
return false;
|
|
581
581
|
}
|
|
@@ -583,13 +583,13 @@ export class Collection {
|
|
|
583
583
|
return true;
|
|
584
584
|
}
|
|
585
585
|
isDirty() {
|
|
586
|
-
return this
|
|
586
|
+
return this.#dirty;
|
|
587
587
|
}
|
|
588
588
|
isPartial() {
|
|
589
|
-
return this
|
|
589
|
+
return this.#partial;
|
|
590
590
|
}
|
|
591
591
|
setDirty(dirty = true) {
|
|
592
|
-
this
|
|
592
|
+
this.#dirty = dirty;
|
|
593
593
|
}
|
|
594
594
|
get length() {
|
|
595
595
|
return this.count();
|
|
@@ -603,10 +603,10 @@ export class Collection {
|
|
|
603
603
|
* @internal
|
|
604
604
|
*/
|
|
605
605
|
takeSnapshot(forcePropagate) {
|
|
606
|
-
this
|
|
607
|
-
this
|
|
606
|
+
this.#snapshot = [...this.#items];
|
|
607
|
+
this.#dirty = false;
|
|
608
608
|
if (this.property.owner || forcePropagate) {
|
|
609
|
-
this
|
|
609
|
+
this.#items.forEach(item => {
|
|
610
610
|
this.propagate(item, 'takeSnapshot');
|
|
611
611
|
});
|
|
612
612
|
}
|
|
@@ -615,29 +615,29 @@ export class Collection {
|
|
|
615
615
|
* @internal
|
|
616
616
|
*/
|
|
617
617
|
getSnapshot() {
|
|
618
|
-
return this
|
|
618
|
+
return this.#snapshot;
|
|
619
619
|
}
|
|
620
620
|
/**
|
|
621
621
|
* @internal
|
|
622
622
|
*/
|
|
623
623
|
get property() {
|
|
624
624
|
// cannot be typed to `EntityProperty<O, T>` as it causes issues in assignability of `Loaded` type
|
|
625
|
-
if (!this
|
|
625
|
+
if (!this.#property) {
|
|
626
626
|
const meta = wrap(this.owner, true).__meta;
|
|
627
627
|
/* v8 ignore next */
|
|
628
628
|
if (!meta) {
|
|
629
629
|
throw MetadataError.fromUnknownEntity(this.owner.constructor.name, 'Collection.property getter, maybe you just forgot to initialize the ORM?');
|
|
630
630
|
}
|
|
631
|
-
this
|
|
631
|
+
this.#property = meta.relations.find(prop => this.owner[prop.name] === this);
|
|
632
632
|
}
|
|
633
|
-
return this
|
|
633
|
+
return this.#property;
|
|
634
634
|
}
|
|
635
635
|
/**
|
|
636
636
|
* @internal
|
|
637
637
|
*/
|
|
638
638
|
set property(prop) {
|
|
639
639
|
// cannot be typed to `EntityProperty<O, T>` as it causes issues in assignability of `Loaded` type
|
|
640
|
-
this
|
|
640
|
+
this.#property = prop;
|
|
641
641
|
}
|
|
642
642
|
propagate(item, method) {
|
|
643
643
|
if (this.property.owner && this.property.inversedBy) {
|
|
@@ -696,26 +696,16 @@ export class Collection {
|
|
|
696
696
|
}
|
|
697
697
|
}
|
|
698
698
|
incrementCount(value) {
|
|
699
|
-
if (typeof this
|
|
700
|
-
this
|
|
699
|
+
if (typeof this.#count === 'number' && this.#initialized) {
|
|
700
|
+
this.#count += value;
|
|
701
701
|
}
|
|
702
702
|
}
|
|
703
703
|
/** @ignore */
|
|
704
704
|
[Symbol.for('nodejs.util.inspect.custom')](depth = 2) {
|
|
705
705
|
const object = { ...this };
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
'_property',
|
|
710
|
-
'_count',
|
|
711
|
-
'snapshot',
|
|
712
|
-
'_populated',
|
|
713
|
-
'_lazyInitialized',
|
|
714
|
-
'_em',
|
|
715
|
-
'readonly',
|
|
716
|
-
'partial',
|
|
717
|
-
];
|
|
718
|
-
hidden.forEach(k => delete object[k]);
|
|
706
|
+
delete object.owner;
|
|
707
|
+
object.initialized = this.#initialized;
|
|
708
|
+
object.dirty = this.#dirty;
|
|
719
709
|
const ret = inspect(object, { depth });
|
|
720
710
|
const name = `${this.constructor.name}<${this.property?.type ?? 'unknown'}>`;
|
|
721
711
|
return ret === '[Object]' ? `[${name}]` : name + ' ' + ret;
|
|
@@ -23,14 +23,7 @@ export interface FactoryOptions {
|
|
|
23
23
|
key?: string;
|
|
24
24
|
}
|
|
25
25
|
export declare class EntityFactory {
|
|
26
|
-
private
|
|
27
|
-
private readonly driver;
|
|
28
|
-
private readonly platform;
|
|
29
|
-
private readonly config;
|
|
30
|
-
private readonly metadata;
|
|
31
|
-
private readonly hydrator;
|
|
32
|
-
private readonly eventManager;
|
|
33
|
-
private readonly comparator;
|
|
26
|
+
#private;
|
|
34
27
|
constructor(em: EntityManager);
|
|
35
28
|
create<T extends object, P extends string = string>(entityName: EntityName<T>, data: EntityData<T>, options?: FactoryOptions): New<T, P>;
|
|
36
29
|
mergeData<T extends object>(meta: EntityMetadata<T>, entity: T, data: EntityData<T>, options?: FactoryOptions): void;
|