@mikro-orm/core 7.2.8-dev.9 → 7.2.9-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/entity/EntityLoader.d.ts +1 -0
- package/entity/EntityLoader.js +25 -7
- package/package.json +1 -1
- package/serialization/EntitySerializer.js +4 -4
- package/serialization/EntityTransformer.js +4 -4
- package/serialization/SerializationContext.d.ts +2 -1
- package/serialization/SerializationContext.js +4 -3
- package/utils/Utils.js +1 -1
package/entity/EntityLoader.d.ts
CHANGED
package/entity/EntityLoader.js
CHANGED
|
@@ -186,7 +186,7 @@ export class EntityLoader {
|
|
|
186
186
|
if (prop.polymorphic && prop.polymorphTargets) {
|
|
187
187
|
return this.populatePolymorphic(entities, prop, options, !!ref);
|
|
188
188
|
}
|
|
189
|
-
const { items, partial } = await this.findChildren(options.filtered ?? entities, prop, populate, {
|
|
189
|
+
const { items, partial, partitions } = await this.findChildren(options.filtered ?? entities, prop, populate, {
|
|
190
190
|
...options,
|
|
191
191
|
where,
|
|
192
192
|
orderBy: mergedOrderBy,
|
|
@@ -194,6 +194,10 @@ export class EntityLoader {
|
|
|
194
194
|
const hasLimit = populate.limit != null;
|
|
195
195
|
const isPartial = partial || hasLimit;
|
|
196
196
|
const customOrder = mergedOrderBy.length > 0 || !!prop.orderBy || !!prop.targetMeta?.orderBy;
|
|
197
|
+
if (partitions) {
|
|
198
|
+
this.initializePartitions(filtered, items, field, partitions);
|
|
199
|
+
return items;
|
|
200
|
+
}
|
|
197
201
|
this.initializeCollections(filtered, prop, field, items, customOrder, isPartial, hasLimit);
|
|
198
202
|
return items;
|
|
199
203
|
}
|
|
@@ -336,6 +340,18 @@ export class EntityLoader {
|
|
|
336
340
|
}
|
|
337
341
|
}
|
|
338
342
|
}
|
|
343
|
+
initializePartitions(filtered, children, field, partitions) {
|
|
344
|
+
// a child belongs only to the owners whose slice returned it, not to every owner in its array
|
|
345
|
+
const key = (entity) => helper(entity).getSerializedPrimaryKey();
|
|
346
|
+
const owners = new Map(filtered.map(entity => [key(entity), []]));
|
|
347
|
+
const items = new Map(children.map(child => [key(child), child]));
|
|
348
|
+
for (const [owner, child] of partitions) {
|
|
349
|
+
owners.get('' + owner)?.push(items.get('' + child));
|
|
350
|
+
}
|
|
351
|
+
for (const entity of filtered) {
|
|
352
|
+
entity[field].hydrate(owners.get(key(entity)), true, true, true);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
339
355
|
async findChildren(entities, prop, populate, options, ref) {
|
|
340
356
|
const children = Utils.unique(this.getChildReferences(entities, prop, options, ref, populate));
|
|
341
357
|
const meta = prop.targetMeta;
|
|
@@ -434,11 +450,13 @@ export class EntityLoader {
|
|
|
434
450
|
visited: options.visited,
|
|
435
451
|
};
|
|
436
452
|
if (populate.limit != null) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
453
|
+
// the owners of an M:N without a pivot table are stored as an array, the driver slices per owner
|
|
454
|
+
const owners = prop.kind === ReferenceKind.MANY_TO_MANY && ownerProp ? ids : undefined;
|
|
455
|
+
findOptions._partitionLimit = { partitionBy: fk, limit: populate.limit, offset: populate.offset, owners };
|
|
456
|
+
// a cached result would not carry the per-owner partitions the driver writes back
|
|
457
|
+
if (owners) {
|
|
458
|
+
findOptions.cache = false;
|
|
459
|
+
}
|
|
442
460
|
}
|
|
443
461
|
const items = await this.#em.find(meta.class, where, findOptions);
|
|
444
462
|
// For targetKey relations, wire up loaded entities to parent references
|
|
@@ -501,7 +519,7 @@ export class EntityLoader {
|
|
|
501
519
|
this.#em.getUnitOfWork().unmarkAsLoaded(item);
|
|
502
520
|
}
|
|
503
521
|
}
|
|
504
|
-
return { items, partial };
|
|
522
|
+
return { items, partial, partitions: findOptions._partitionLimit?.partitions };
|
|
505
523
|
}
|
|
506
524
|
mergePrimaryCondition(ids, pk, options, meta, metadata, platform) {
|
|
507
525
|
const cond1 = QueryHelper.processWhere({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.9-dev.0",
|
|
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",
|
|
@@ -76,12 +76,12 @@ export class EntitySerializer {
|
|
|
76
76
|
const meta = wrapped.__meta;
|
|
77
77
|
let contextCreated = false;
|
|
78
78
|
options = prepareOptions(options);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
let root = wrapped.__serializationContext.root;
|
|
80
|
+
if (!root) {
|
|
81
|
+
root = new SerializationContext();
|
|
82
82
|
contextCreated = true;
|
|
83
83
|
}
|
|
84
|
-
|
|
84
|
+
SerializationContext.propagate(root, entity, (meta, prop) => meta.properties[prop]?.kind !== ReferenceKind.SCALAR);
|
|
85
85
|
const ret = {};
|
|
86
86
|
const props = new Set();
|
|
87
87
|
if (meta.serializedPrimaryKey && !meta.compositePK) {
|
|
@@ -21,12 +21,12 @@ export class EntityTransformer {
|
|
|
21
21
|
if (!wrapped) {
|
|
22
22
|
return entity;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
SerializationContext.
|
|
24
|
+
let root = wrapped.__serializationContext.root;
|
|
25
|
+
if (!root) {
|
|
26
|
+
root = new SerializationContext(wrapped.__serializationContext.populate, wrapped.__serializationContext.fields, wrapped.__serializationContext.exclude);
|
|
27
27
|
contextCreated = true;
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
SerializationContext.propagate(root, entity, isVisible);
|
|
30
30
|
const meta = wrapped.__meta;
|
|
31
31
|
const ret = {};
|
|
32
32
|
const props = new Set();
|
|
@@ -18,7 +18,8 @@ export declare class SerializationContext<T extends object> {
|
|
|
18
18
|
/** Cleans up the serialization context by removing root references from all tracked entities. */
|
|
19
19
|
close(): void;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* Propagates the context to the entity and its direct relations, so nested serialization calls pick it up.
|
|
22
|
+
* Runs for every serialized entity, so the context spreads along the serialized path instead of the whole graph.
|
|
22
23
|
*/
|
|
23
24
|
static propagate(root: SerializationContext<any>, entity: AnyEntity, isVisible: (meta: EntityMetadata, prop: string) => boolean): void;
|
|
24
25
|
/** Checks whether a property is explicitly listed in the populate hints for the current path. */
|
|
@@ -47,7 +47,8 @@ export class SerializationContext {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
50
|
+
* Propagates the context to the entity and its direct relations, so nested serialization calls pick it up.
|
|
51
|
+
* Runs for every serialized entity, so the context spreads along the serialized path instead of the whole graph.
|
|
51
52
|
*/
|
|
52
53
|
static propagate(root, entity, isVisible) {
|
|
53
54
|
root.register(entity);
|
|
@@ -59,14 +60,14 @@ export class SerializationContext {
|
|
|
59
60
|
const target = entity[key];
|
|
60
61
|
if (Utils.isEntity(target, true)) {
|
|
61
62
|
if (!target.__helper.__serializationContext.root) {
|
|
62
|
-
|
|
63
|
+
root.register(target);
|
|
63
64
|
}
|
|
64
65
|
continue;
|
|
65
66
|
}
|
|
66
67
|
if (Utils.isCollection(target)) {
|
|
67
68
|
for (const item of target.getItems(false)) {
|
|
68
69
|
if (!item.__helper.__serializationContext.root) {
|
|
69
|
-
|
|
70
|
+
root.register(item);
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
}
|
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.
|
|
156
|
+
static #ORM_VERSION = '7.2.9-dev.0';
|
|
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}`;
|