@mikro-orm/core 6.4.2-dev.1 → 6.4.2-dev.10
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/drivers/DatabaseDriver.d.ts +1 -1
- package/drivers/DatabaseDriver.js +10 -4
- package/entity/EntityLoader.js +1 -1
- package/errors.d.ts +1 -0
- package/errors.js +3 -0
- package/metadata/MetadataDiscovery.js +4 -5
- package/package.json +2 -2
- package/unit-of-work/UnitOfWork.js +8 -2
- package/utils/Cursor.js +1 -2
|
@@ -47,7 +47,7 @@ export declare abstract class DatabaseDriver<C extends Connection> implements ID
|
|
|
47
47
|
orderBy: OrderDefinition<T>[];
|
|
48
48
|
where: FilterQuery<T>;
|
|
49
49
|
};
|
|
50
|
-
protected createCursorCondition<T extends object>(definition: (readonly [keyof T & string, QueryOrder])[], offsets: Dictionary[], inverse: boolean): FilterQuery<T>;
|
|
50
|
+
protected createCursorCondition<T extends object>(definition: (readonly [keyof T & string, QueryOrder])[], offsets: Dictionary[], inverse: boolean, meta: EntityMetadata<T>): FilterQuery<T>;
|
|
51
51
|
/** @internal */
|
|
52
52
|
mapDataToFieldNames(data: Dictionary, stringifyJsonArrays: boolean, properties?: Record<string, EntityProperty>, convertCustomTypes?: boolean, object?: boolean): Dictionary;
|
|
53
53
|
protected inlineEmbeddables<T extends object>(meta: EntityMetadata<T>, data: T, where?: boolean): void;
|
|
@@ -125,7 +125,7 @@ class DatabaseDriver {
|
|
|
125
125
|
/* istanbul ignore next */
|
|
126
126
|
const offsets = def ? utils_1.Cursor.decode(def) : [];
|
|
127
127
|
if (definition.length === offsets.length) {
|
|
128
|
-
return this.createCursorCondition(definition, offsets, inverse);
|
|
128
|
+
return this.createCursorCondition(definition, offsets, inverse, meta);
|
|
129
129
|
}
|
|
130
130
|
/* istanbul ignore next */
|
|
131
131
|
return {};
|
|
@@ -157,11 +157,17 @@ class DatabaseDriver {
|
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
159
|
/* istanbul ignore next */
|
|
160
|
-
createCursorCondition(definition, offsets, inverse) {
|
|
160
|
+
createCursorCondition(definition, offsets, inverse, meta) {
|
|
161
161
|
const createCondition = (prop, direction, offset, eq = false) => {
|
|
162
|
+
if (offset === null) {
|
|
163
|
+
throw errors_1.CursorError.missingValue(meta.className, prop);
|
|
164
|
+
}
|
|
162
165
|
if (utils_1.Utils.isPlainObject(direction)) {
|
|
163
166
|
const value = utils_1.Utils.keys(direction).reduce((o, key) => {
|
|
164
|
-
|
|
167
|
+
if (utils_1.Utils.isEmpty(offset[key])) {
|
|
168
|
+
throw errors_1.CursorError.missingValue(meta.className, `${prop}.${key}`);
|
|
169
|
+
}
|
|
170
|
+
Object.assign(o, createCondition(key, direction[key], offset[key], eq));
|
|
165
171
|
return o;
|
|
166
172
|
}, {});
|
|
167
173
|
return ({ [prop]: value });
|
|
@@ -180,7 +186,7 @@ class DatabaseDriver {
|
|
|
180
186
|
...createCondition(prop, direction, offset, true),
|
|
181
187
|
$or: [
|
|
182
188
|
createCondition(prop, direction, offset),
|
|
183
|
-
this.createCursorCondition(otherOrders, otherOffsets, inverse),
|
|
189
|
+
this.createCursorCondition(otherOrders, otherOffsets, inverse, meta),
|
|
184
190
|
],
|
|
185
191
|
};
|
|
186
192
|
}
|
package/entity/EntityLoader.js
CHANGED
|
@@ -147,7 +147,7 @@ class EntityLoader {
|
|
|
147
147
|
return this.findChildrenFromPivotTable(filtered, prop, options, innerOrderBy, populate, !!ref);
|
|
148
148
|
}
|
|
149
149
|
const where = await this.extractChildCondition(options, prop);
|
|
150
|
-
const data = await this.findChildren(entities, prop, populate, { ...options, where, orderBy: innerOrderBy }, !!ref);
|
|
150
|
+
const data = await this.findChildren(entities, prop, populate, { ...options, where, orderBy: innerOrderBy }, !!(ref || prop.mapToPk));
|
|
151
151
|
this.initializeCollections(filtered, prop, field, data, innerOrderBy.length > 0);
|
|
152
152
|
return data;
|
|
153
153
|
}
|
package/errors.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export declare class ValidationError<T extends AnyEntity = AnyEntity> extends Er
|
|
|
28
28
|
}
|
|
29
29
|
export declare class CursorError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
|
|
30
30
|
static entityNotPopulated(entity: AnyEntity, prop: string): ValidationError;
|
|
31
|
+
static missingValue(entityName: string, prop: string): ValidationError;
|
|
31
32
|
}
|
|
32
33
|
export declare class OptimisticLockError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
|
|
33
34
|
static notVersioned(meta: EntityMetadata): OptimisticLockError;
|
package/errors.js
CHANGED
|
@@ -107,6 +107,9 @@ class CursorError extends ValidationError {
|
|
|
107
107
|
static entityNotPopulated(entity, prop) {
|
|
108
108
|
return new CursorError(`Cannot create cursor, value for '${entity.constructor.name}.${prop}' is missing.`);
|
|
109
109
|
}
|
|
110
|
+
static missingValue(entityName, prop) {
|
|
111
|
+
return new CursorError(`Invalid cursor condition, value for '${entityName}.${prop}' is missing.`);
|
|
112
|
+
}
|
|
110
113
|
}
|
|
111
114
|
exports.CursorError = CursorError;
|
|
112
115
|
class OptimisticLockError extends ValidationError {
|
|
@@ -501,11 +501,10 @@ class MetadataDiscovery {
|
|
|
501
501
|
}
|
|
502
502
|
findReferencingProperties(meta, metadata) {
|
|
503
503
|
for (const meta2 of metadata) {
|
|
504
|
-
const prop2
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
meta.referencingProperties.push({ meta: meta2, prop: prop2 });
|
|
504
|
+
for (const prop2 of meta2.relations) {
|
|
505
|
+
if (prop2.kind !== enums_1.ReferenceKind.SCALAR && prop2.type === meta.className) {
|
|
506
|
+
meta.referencingProperties.push({ meta: meta2, prop: prop2 });
|
|
507
|
+
}
|
|
509
508
|
}
|
|
510
509
|
}
|
|
511
510
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.4.2-dev.
|
|
3
|
+
"version": "6.4.2-dev.10",
|
|
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
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"esprima": "4.0.1",
|
|
65
65
|
"fs-extra": "11.2.0",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.4.2-dev.
|
|
67
|
+
"mikro-orm": "6.4.2-dev.10",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -348,6 +348,7 @@ class UnitOfWork {
|
|
|
348
348
|
unsetIdentity(entity) {
|
|
349
349
|
this.identityMap.delete(entity);
|
|
350
350
|
const wrapped = (0, entity_1.helper)(entity);
|
|
351
|
+
const serializedPK = wrapped.getSerializedPrimaryKey();
|
|
351
352
|
// remove references of this entity in all managed entities, otherwise flushing could reinsert the entity
|
|
352
353
|
for (const { meta, prop } of wrapped.__meta.referencingProperties) {
|
|
353
354
|
for (const referrer of this.identityMap.getStore(meta).values()) {
|
|
@@ -355,8 +356,13 @@ class UnitOfWork {
|
|
|
355
356
|
if (Utils_1.Utils.isCollection(rel)) {
|
|
356
357
|
rel.removeWithoutPropagation(entity);
|
|
357
358
|
}
|
|
358
|
-
else if (rel === entity) {
|
|
359
|
-
|
|
359
|
+
else if (rel && (prop.mapToPk ? (0, entity_1.helper)(this.em.getReference(prop.type, rel)).getSerializedPrimaryKey() === serializedPK : rel === entity)) {
|
|
360
|
+
if (prop.formula) {
|
|
361
|
+
delete referrer[prop.name];
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
delete (0, entity_1.helper)(referrer).__data[prop.name];
|
|
365
|
+
}
|
|
360
366
|
}
|
|
361
367
|
}
|
|
362
368
|
}
|
package/utils/Cursor.js
CHANGED
|
@@ -98,11 +98,10 @@ class Cursor {
|
|
|
98
98
|
from(entity) {
|
|
99
99
|
const processEntity = (entity, prop, direction, object = false) => {
|
|
100
100
|
if (Utils_1.Utils.isPlainObject(direction)) {
|
|
101
|
-
|
|
101
|
+
return Utils_1.Utils.keys(direction).reduce((o, key) => {
|
|
102
102
|
Object.assign(o, processEntity(Reference_1.Reference.unwrapReference(entity[prop]), key, direction[key], true));
|
|
103
103
|
return o;
|
|
104
104
|
}, {});
|
|
105
|
-
return ({ [prop]: value });
|
|
106
105
|
}
|
|
107
106
|
if (entity[prop] == null) {
|
|
108
107
|
throw errors_1.CursorError.entityNotPopulated(entity, prop);
|