@mikro-orm/core 7.0.6-dev.6 → 7.0.6-dev.8
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/Collection.d.ts +1 -0
- package/entity/Collection.js +5 -1
- package/entity/EntityFactory.js +1 -1
- package/entity/EntityHelper.d.ts +1 -0
- package/entity/EntityHelper.js +5 -1
- package/entity/Reference.d.ts +1 -0
- package/entity/Reference.js +8 -3
- package/hydration/ObjectHydrator.js +5 -2
- package/package.json +1 -1
- package/utils/EntityComparator.js +9 -6
- package/utils/RawQueryFragment.js +3 -4
- package/utils/Utils.d.ts +3 -3
- package/utils/Utils.js +14 -8
- package/utils/clone.js +1 -0
package/entity/Collection.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare class Collection<T extends object, O extends object = object> {
|
|
|
21
21
|
/**
|
|
22
22
|
* Creates new Collection instance, assigns it to the owning entity and sets the items to it (propagating them to their inverse sides)
|
|
23
23
|
*/
|
|
24
|
+
static isCollection<T extends object, O extends object>(item: any): item is Collection<T, O>;
|
|
24
25
|
static create<T extends object, O extends object = object>(owner: O, prop: EntityKey<O>, items: undefined | T[], initialized: boolean): Collection<T, O>;
|
|
25
26
|
/**
|
|
26
27
|
* Ensures the collection is loaded first (without reloading it if it already is loaded).
|
package/entity/Collection.js
CHANGED
|
@@ -5,6 +5,7 @@ import { Reference } from './Reference.js';
|
|
|
5
5
|
import { helper, wrap } from './wrap.js';
|
|
6
6
|
import { QueryHelper } from '../utils/QueryHelper.js';
|
|
7
7
|
import { inspect } from '../logging/inspect.js';
|
|
8
|
+
const collectionSymbol = Symbol('Collection');
|
|
8
9
|
/** Represents a to-many relation (1:m or m:n) as an iterable, managed collection of entities. */
|
|
9
10
|
export class Collection {
|
|
10
11
|
owner;
|
|
@@ -19,6 +20,7 @@ export class Collection {
|
|
|
19
20
|
#populated;
|
|
20
21
|
constructor(owner, items, initialized = true) {
|
|
21
22
|
this.owner = owner;
|
|
23
|
+
Object.defineProperty(this, collectionSymbol, { value: true, enumerable: false });
|
|
22
24
|
/* v8 ignore next */
|
|
23
25
|
if (items) {
|
|
24
26
|
let i = 0;
|
|
@@ -30,6 +32,9 @@ export class Collection {
|
|
|
30
32
|
/**
|
|
31
33
|
* Creates new Collection instance, assigns it to the owning entity and sets the items to it (propagating them to their inverse sides)
|
|
32
34
|
*/
|
|
35
|
+
static isCollection(item) {
|
|
36
|
+
return item != null && Object.hasOwn(item, collectionSymbol);
|
|
37
|
+
}
|
|
33
38
|
static create(owner, prop, items, initialized) {
|
|
34
39
|
const coll = new Collection(owner, undefined, initialized);
|
|
35
40
|
coll.property = helper(owner).__meta.properties[prop];
|
|
@@ -737,5 +742,4 @@ Object.defineProperties(Collection.prototype, {
|
|
|
737
742
|
return () => this;
|
|
738
743
|
},
|
|
739
744
|
},
|
|
740
|
-
__collection: { value: true, enumerable: false, writable: false },
|
|
741
745
|
});
|
package/entity/EntityFactory.js
CHANGED
|
@@ -30,7 +30,7 @@ export class EntityFactory {
|
|
|
30
30
|
create(entityName, data, options = {}) {
|
|
31
31
|
data = Reference.unwrapReference(data);
|
|
32
32
|
options.initialized ??= true;
|
|
33
|
-
if (data
|
|
33
|
+
if (EntityHelper.isEntity(data)) {
|
|
34
34
|
return data;
|
|
35
35
|
}
|
|
36
36
|
const meta = this.#metadata.get(entityName);
|
package/entity/EntityHelper.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { type EntityMetadata, type EntityProperty, type IHydrator } from '../typ
|
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
6
|
export declare class EntityHelper {
|
|
7
|
+
static isEntity(data: any): boolean;
|
|
7
8
|
static decorate<T extends object>(meta: EntityMetadata<T>, em: EntityManager): void;
|
|
8
9
|
/**
|
|
9
10
|
* As a performance optimization, we create entity state methods lazily. We first add
|
package/entity/EntityHelper.js
CHANGED
|
@@ -7,10 +7,14 @@ import { ReferenceKind } from '../enums.js';
|
|
|
7
7
|
import { helper } from './wrap.js';
|
|
8
8
|
import { inspect } from '../logging/inspect.js';
|
|
9
9
|
import { getEnv } from '../utils/env-vars.js';
|
|
10
|
+
const entitySymbol = Symbol('Entity');
|
|
10
11
|
/**
|
|
11
12
|
* @internal
|
|
12
13
|
*/
|
|
13
14
|
export class EntityHelper {
|
|
15
|
+
static isEntity(data) {
|
|
16
|
+
return data != null && typeof data === 'object' && !!data[entitySymbol];
|
|
17
|
+
}
|
|
14
18
|
static decorate(meta, em) {
|
|
15
19
|
const fork = em.fork(); // use fork so we can access `EntityFactory`
|
|
16
20
|
const serializedPrimaryKey = meta.props.find(p => p.serializedPrimaryKey);
|
|
@@ -58,7 +62,7 @@ export class EntityHelper {
|
|
|
58
62
|
// oxfmt-ignore
|
|
59
63
|
const helperParams = meta.embeddable || meta.virtual ? [] : [em.getComparator().getPkGetter(meta), em.getComparator().getPkSerializer(meta), em.getComparator().getPkGetterConverted(meta)];
|
|
60
64
|
Object.defineProperties(prototype, {
|
|
61
|
-
|
|
65
|
+
[entitySymbol]: { value: !meta.embeddable, enumerable: false, configurable: true },
|
|
62
66
|
__meta: { value: meta, configurable: true },
|
|
63
67
|
__config: { value: em.config, configurable: true },
|
|
64
68
|
__platform: { value: em.getPlatform(), configurable: true },
|
package/entity/Reference.d.ts
CHANGED
|
@@ -78,6 +78,7 @@ export declare class ScalarReference<Value> {
|
|
|
78
78
|
unwrap(): Value | undefined;
|
|
79
79
|
/** Returns whether the scalar value has been loaded. */
|
|
80
80
|
isInitialized(): boolean;
|
|
81
|
+
static isScalarReference(data: any): data is ScalarReference<any>;
|
|
81
82
|
}
|
|
82
83
|
/** Options for `Reference.load()` to control how the referenced entity is loaded. */
|
|
83
84
|
export interface LoadReferenceOptions<T extends object, P extends string = never, F extends string = never, E extends string = never> extends FindOneOptions<T, P, F, E> {
|
package/entity/Reference.js
CHANGED
|
@@ -4,12 +4,15 @@ import { Utils } from '../utils/Utils.js';
|
|
|
4
4
|
import { QueryHelper } from '../utils/QueryHelper.js';
|
|
5
5
|
import { NotFoundError } from '../errors.js';
|
|
6
6
|
import { inspect } from '../logging/inspect.js';
|
|
7
|
+
const referenceSymbol = Symbol('Reference');
|
|
8
|
+
const scalarReferenceSymbol = Symbol('ScalarReference');
|
|
7
9
|
/** Wrapper around an entity that provides lazy loading capabilities and identity-preserving reference semantics. */
|
|
8
10
|
export class Reference {
|
|
9
11
|
entity;
|
|
10
12
|
property;
|
|
11
13
|
constructor(entity) {
|
|
12
14
|
this.entity = entity;
|
|
15
|
+
Object.defineProperty(this, referenceSymbol, { value: true, enumerable: false });
|
|
13
16
|
this.set(entity);
|
|
14
17
|
const meta = helper(this.entity).__meta;
|
|
15
18
|
meta.primaryKeys.forEach(primaryKey => {
|
|
@@ -63,7 +66,7 @@ export class Reference {
|
|
|
63
66
|
* Checks whether the argument is instance of `Reference` wrapper.
|
|
64
67
|
*/
|
|
65
68
|
static isReference(data) {
|
|
66
|
-
return data &&
|
|
69
|
+
return data != null && Object.hasOwn(data, referenceSymbol);
|
|
67
70
|
}
|
|
68
71
|
/**
|
|
69
72
|
* Wraps the entity in a `Reference` wrapper if the property is defined as `ref`.
|
|
@@ -179,6 +182,7 @@ export class ScalarReference {
|
|
|
179
182
|
#initialized;
|
|
180
183
|
constructor(value, initialized = value != null) {
|
|
181
184
|
this.value = value;
|
|
185
|
+
Object.defineProperty(this, scalarReferenceSymbol, { value: true, enumerable: false });
|
|
182
186
|
this.#initialized = initialized;
|
|
183
187
|
}
|
|
184
188
|
/**
|
|
@@ -228,6 +232,9 @@ export class ScalarReference {
|
|
|
228
232
|
isInitialized() {
|
|
229
233
|
return this.#initialized;
|
|
230
234
|
}
|
|
235
|
+
static isScalarReference(data) {
|
|
236
|
+
return data != null && typeof data === 'object' && Object.hasOwn(data, scalarReferenceSymbol);
|
|
237
|
+
}
|
|
231
238
|
/** @ignore */
|
|
232
239
|
/* v8 ignore next */
|
|
233
240
|
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
@@ -235,7 +242,6 @@ export class ScalarReference {
|
|
|
235
242
|
}
|
|
236
243
|
}
|
|
237
244
|
Object.defineProperties(Reference.prototype, {
|
|
238
|
-
__reference: { value: true, enumerable: false },
|
|
239
245
|
__meta: {
|
|
240
246
|
get() {
|
|
241
247
|
return this.entity.__meta;
|
|
@@ -263,7 +269,6 @@ Object.defineProperties(Reference.prototype, {
|
|
|
263
269
|
},
|
|
264
270
|
});
|
|
265
271
|
Object.defineProperties(ScalarReference.prototype, {
|
|
266
|
-
__scalarReference: { value: true, enumerable: false },
|
|
267
272
|
$: {
|
|
268
273
|
get() {
|
|
269
274
|
return this.value;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Hydrator } from './Hydrator.js';
|
|
2
2
|
import { Collection } from '../entity/Collection.js';
|
|
3
3
|
import { Reference, ScalarReference } from '../entity/Reference.js';
|
|
4
|
+
import { EntityHelper } from '../entity/EntityHelper.js';
|
|
4
5
|
import { PolymorphicRef } from '../entity/PolymorphicRef.js';
|
|
5
6
|
import { parseJsonSafe, Utils } from '../utils/Utils.js';
|
|
6
7
|
import { ReferenceKind } from '../enums.js';
|
|
@@ -50,6 +51,8 @@ export class ObjectHydrator extends Hydrator {
|
|
|
50
51
|
const context = new Map();
|
|
51
52
|
const props = this.getProperties(meta, type);
|
|
52
53
|
context.set('isPrimaryKey', Utils.isPrimaryKey);
|
|
54
|
+
context.set('isEntity', EntityHelper.isEntity);
|
|
55
|
+
context.set('isScalarReference', ScalarReference.isScalarReference);
|
|
53
56
|
context.set('Collection', Collection);
|
|
54
57
|
context.set('Reference', Reference);
|
|
55
58
|
context.set('PolymorphicRef', PolymorphicRef);
|
|
@@ -122,7 +125,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
122
125
|
ret.push(` entity${entityKey} = data${dataKey};`);
|
|
123
126
|
}
|
|
124
127
|
if (prop.ref) {
|
|
125
|
-
ret.push(` const value = entity${entityKey}
|
|
128
|
+
ret.push(` const value = isScalarReference(entity${entityKey}) ? entity${entityKey}.unwrap() : entity${entityKey};`);
|
|
126
129
|
ret.push(` entity${entityKey} = oldValue_${idx} ?? new ScalarReference(value);`);
|
|
127
130
|
ret.push(` entity${entityKey}.bind(entity, '${prop.name}');`);
|
|
128
131
|
ret.push(` entity${entityKey}.set(value);`);
|
|
@@ -419,7 +422,7 @@ export class ObjectHydrator extends Hydrator {
|
|
|
419
422
|
const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.#tmpIndex++}`);
|
|
420
423
|
context.set(targetKey, prop.targetMeta.class);
|
|
421
424
|
lines.push(` if (isPrimaryKey(value, ${meta.compositePK})) return factory.createReference(${targetKey}, value, { convertCustomTypes, schema, normalizeAccessors, merge: true });`);
|
|
422
|
-
lines.push(` if (value && value
|
|
425
|
+
lines.push(` if (value && isEntity(value)) return value;`);
|
|
423
426
|
lines.push(` return factory.create(${targetKey}, value, { newEntity, convertCustomTypes, schema, normalizeAccessors, merge: true });`);
|
|
424
427
|
lines.push(` }`);
|
|
425
428
|
return lines;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.0.6-dev.
|
|
3
|
+
"version": "7.0.6-dev.8",
|
|
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",
|
|
@@ -60,11 +60,12 @@ export class EntityComparator {
|
|
|
60
60
|
}
|
|
61
61
|
const lines = [];
|
|
62
62
|
const context = new Map();
|
|
63
|
+
context.set('isEntityOrRef', (val) => Utils.isEntity(val, true));
|
|
63
64
|
if (meta.primaryKeys.length > 1) {
|
|
64
65
|
lines.push(` const cond = {`);
|
|
65
66
|
meta.primaryKeys.forEach(pk => {
|
|
66
67
|
if (meta.properties[pk].kind !== ReferenceKind.SCALAR) {
|
|
67
|
-
lines.push(` ${pk}: (entity${this.wrap(pk)} != null && (entity${this.wrap(pk)}
|
|
68
|
+
lines.push(` ${pk}: (entity${this.wrap(pk)} != null && isEntityOrRef(entity${this.wrap(pk)})) ? entity${this.wrap(pk)}.__helper.getPrimaryKey() : entity${this.wrap(pk)},`);
|
|
68
69
|
}
|
|
69
70
|
else {
|
|
70
71
|
lines.push(` ${pk}: entity${this.wrap(pk)},`);
|
|
@@ -77,7 +78,7 @@ export class EntityComparator {
|
|
|
77
78
|
else {
|
|
78
79
|
const pk = meta.primaryKeys[0];
|
|
79
80
|
if (meta.properties[pk].kind !== ReferenceKind.SCALAR) {
|
|
80
|
-
lines.push(` if (entity${this.wrap(pk)} != null && (entity${this.wrap(pk)}
|
|
81
|
+
lines.push(` if (entity${this.wrap(pk)} != null && isEntityOrRef(entity${this.wrap(pk)})) {`);
|
|
81
82
|
lines.push(` const pk = entity${this.wrap(pk)}.__helper.getPrimaryKey();`);
|
|
82
83
|
if (meta.properties[pk].targetMeta.compositePK) {
|
|
83
84
|
lines.push(` if (typeof pk === 'object' && pk != null) {`);
|
|
@@ -110,11 +111,12 @@ export class EntityComparator {
|
|
|
110
111
|
}
|
|
111
112
|
const lines = [];
|
|
112
113
|
const context = new Map();
|
|
114
|
+
context.set('isEntityOrRef', (val) => Utils.isEntity(val, true));
|
|
113
115
|
if (meta.primaryKeys.length > 1) {
|
|
114
116
|
lines.push(` const cond = {`);
|
|
115
117
|
meta.primaryKeys.forEach(pk => {
|
|
116
118
|
if (meta.properties[pk].kind !== ReferenceKind.SCALAR) {
|
|
117
|
-
lines.push(` ${pk}: (entity${this.wrap(pk)} != null && (entity${this.wrap(pk)}
|
|
119
|
+
lines.push(` ${pk}: (entity${this.wrap(pk)} != null && isEntityOrRef(entity${this.wrap(pk)})) ? entity${this.wrap(pk)}.__helper.getPrimaryKey(true) : entity${this.wrap(pk)},`);
|
|
118
120
|
}
|
|
119
121
|
else {
|
|
120
122
|
if (meta.properties[pk].customType) {
|
|
@@ -133,7 +135,7 @@ export class EntityComparator {
|
|
|
133
135
|
else {
|
|
134
136
|
const pk = meta.primaryKeys[0];
|
|
135
137
|
if (meta.properties[pk].kind !== ReferenceKind.SCALAR) {
|
|
136
|
-
lines.push(` if (entity${this.wrap(pk)} != null && (entity${this.wrap(pk)}
|
|
138
|
+
lines.push(` if (entity${this.wrap(pk)} != null && isEntityOrRef(entity${this.wrap(pk)})) return entity${this.wrap(pk)}.__helper.getPrimaryKey(true);`);
|
|
137
139
|
}
|
|
138
140
|
if (meta.properties[pk].customType) {
|
|
139
141
|
const convertorKey = this.registerCustomType(meta.properties[pk], context);
|
|
@@ -161,13 +163,14 @@ export class EntityComparator {
|
|
|
161
163
|
}
|
|
162
164
|
const lines = [];
|
|
163
165
|
const context = new Map();
|
|
166
|
+
context.set('isEntityOrRef', (val) => Utils.isEntity(val, true));
|
|
164
167
|
context.set('getCompositeKeyValue', (val) => Utils.flatten(Utils.getCompositeKeyValue(val, meta, 'convertToDatabaseValue', this.#platform)));
|
|
165
168
|
context.set('getPrimaryKeyHash', (val) => Utils.getPrimaryKeyHash(Utils.asArray(val)));
|
|
166
169
|
if (meta.primaryKeys.length > 1) {
|
|
167
170
|
lines.push(` const pks = entity.__helper.__pk ? getCompositeKeyValue(entity.__helper.__pk) : [`);
|
|
168
171
|
meta.primaryKeys.forEach(pk => {
|
|
169
172
|
if (meta.properties[pk].kind !== ReferenceKind.SCALAR) {
|
|
170
|
-
lines.push(` (entity${this.wrap(pk)} != null && (entity${this.wrap(pk)}
|
|
173
|
+
lines.push(` (entity${this.wrap(pk)} != null && isEntityOrRef(entity${this.wrap(pk)})) ? entity${this.wrap(pk)}.__helper.getSerializedPrimaryKey() : entity${this.wrap(pk)},`);
|
|
171
174
|
}
|
|
172
175
|
else {
|
|
173
176
|
lines.push(` entity${this.wrap(pk)},`);
|
|
@@ -180,7 +183,7 @@ export class EntityComparator {
|
|
|
180
183
|
const pk = meta.primaryKeys[0];
|
|
181
184
|
const prop = meta.properties[pk];
|
|
182
185
|
if (prop.kind !== ReferenceKind.SCALAR) {
|
|
183
|
-
lines.push(` if (entity${this.wrap(pk)} != null && (entity${this.wrap(pk)}
|
|
186
|
+
lines.push(` if (entity${this.wrap(pk)} != null && isEntityOrRef(entity${this.wrap(pk)})) return entity${this.wrap(pk)}.__helper.getSerializedPrimaryKey();`);
|
|
184
187
|
}
|
|
185
188
|
const serializedPrimaryKey = meta.props.find(p => p.serializedPrimaryKey);
|
|
186
189
|
if (serializedPrimaryKey) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Utils } from './Utils.js';
|
|
2
|
+
const rawSymbol = Symbol('RawQueryFragment');
|
|
2
3
|
/** Represents a raw SQL fragment with optional parameters, usable as both a value and an object key via Symbol coercion. */
|
|
3
4
|
export class RawQueryFragment {
|
|
4
5
|
sql;
|
|
@@ -8,6 +9,7 @@ export class RawQueryFragment {
|
|
|
8
9
|
constructor(sql, params = []) {
|
|
9
10
|
this.sql = sql;
|
|
10
11
|
this.params = params;
|
|
12
|
+
Object.defineProperty(this, rawSymbol, { value: true, enumerable: false });
|
|
11
13
|
}
|
|
12
14
|
/** Returns a unique symbol key for this fragment, creating and caching it on first access. */
|
|
13
15
|
get key() {
|
|
@@ -74,12 +76,9 @@ export class RawQueryFragment {
|
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
export { RawQueryFragment as Raw };
|
|
77
|
-
Object.defineProperties(RawQueryFragment.prototype, {
|
|
78
|
-
__raw: { value: true, enumerable: false },
|
|
79
|
-
});
|
|
80
79
|
/** Checks whether the given value is a `RawQueryFragment` instance. */
|
|
81
80
|
export function isRaw(value) {
|
|
82
|
-
return typeof value === 'object' && value !== null &&
|
|
81
|
+
return typeof value === 'object' && value !== null && Object.hasOwn(value, rawSymbol);
|
|
83
82
|
}
|
|
84
83
|
/** @internal */
|
|
85
84
|
export const ALIAS_REPLACEMENT = '[::alias::]';
|
package/utils/Utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CompiledFunctions, Dictionary, EntityData, EntityDictionary, EntityKey, EntityMetadata, EntityName, EntityProperty, Primary } from '../typings.js';
|
|
2
|
-
import type { Collection } from '../entity/Collection.js';
|
|
3
2
|
import type { Platform } from '../platforms/Platform.js';
|
|
4
|
-
import {
|
|
3
|
+
import { ScalarReference } from '../entity/Reference.js';
|
|
4
|
+
import { Collection } from '../entity/Collection.js';
|
|
5
5
|
import { type RawQueryFragmentSymbol } from './RawQueryFragment.js';
|
|
6
6
|
/** Deeply compares two objects for equality, handling dates, regexes, and raw fragments. */
|
|
7
7
|
export declare function compareObjects(a: any, b: any): boolean;
|
|
@@ -108,7 +108,7 @@ export declare class Utils {
|
|
|
108
108
|
/**
|
|
109
109
|
* Checks whether given object is a scalar reference.
|
|
110
110
|
*/
|
|
111
|
-
static isScalarReference<T = unknown>(data: any
|
|
111
|
+
static isScalarReference<T = unknown>(data: any): data is ScalarReference<any> & {};
|
|
112
112
|
/**
|
|
113
113
|
* Checks whether the argument is empty (array without items, object without keys or falsy value).
|
|
114
114
|
*/
|
package/utils/Utils.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { clone } from './clone.js';
|
|
2
2
|
import { GroupOperator, PlainObject, QueryOperator, ReferenceKind } from '../enums.js';
|
|
3
3
|
import { helper } from '../entity/wrap.js';
|
|
4
|
-
import {
|
|
4
|
+
import { Reference, ScalarReference } from '../entity/Reference.js';
|
|
5
|
+
import { Collection } from '../entity/Collection.js';
|
|
6
|
+
import { EntityHelper } from '../entity/EntityHelper.js';
|
|
7
|
+
import { Raw, isRaw } from './RawQueryFragment.js';
|
|
5
8
|
function compareConstructors(a, b) {
|
|
6
9
|
if (a.constructor === b.constructor) {
|
|
7
10
|
return true;
|
|
@@ -22,7 +25,7 @@ export function compareObjects(a, b) {
|
|
|
22
25
|
if (!a || !b || typeof a !== 'object' || typeof b !== 'object' || !compareConstructors(a, b)) {
|
|
23
26
|
return false;
|
|
24
27
|
}
|
|
25
|
-
if (a
|
|
28
|
+
if (isRaw(a) && isRaw(b)) {
|
|
26
29
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
27
30
|
return a.sql === b.sql && compareArrays(a.params, b.params);
|
|
28
31
|
}
|
|
@@ -129,7 +132,7 @@ export function parseJsonSafe(value) {
|
|
|
129
132
|
/** Collection of general-purpose utility methods used throughout the ORM. */
|
|
130
133
|
export class Utils {
|
|
131
134
|
static PK_SEPARATOR = '~~~';
|
|
132
|
-
static #ORM_VERSION = '7.0.6-dev.
|
|
135
|
+
static #ORM_VERSION = '7.0.6-dev.8';
|
|
133
136
|
/**
|
|
134
137
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
135
138
|
*/
|
|
@@ -220,6 +223,9 @@ export class Utils {
|
|
|
220
223
|
const source = sources.shift();
|
|
221
224
|
if (Utils.isObject(target) && Utils.isPlainObject(source)) {
|
|
222
225
|
for (const [key, value] of Object.entries(source)) {
|
|
226
|
+
if (['__proto__', 'constructor', 'prototype'].includes(key)) {
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
223
229
|
if (ignoreUndefined && typeof value === 'undefined') {
|
|
224
230
|
continue;
|
|
225
231
|
}
|
|
@@ -500,16 +506,16 @@ export class Utils {
|
|
|
500
506
|
if (!Utils.isObject(data)) {
|
|
501
507
|
return false;
|
|
502
508
|
}
|
|
503
|
-
if (allowReference &&
|
|
509
|
+
if (allowReference && Reference.isReference(data)) {
|
|
504
510
|
return true;
|
|
505
511
|
}
|
|
506
|
-
return
|
|
512
|
+
return EntityHelper.isEntity(data);
|
|
507
513
|
}
|
|
508
514
|
/**
|
|
509
515
|
* Checks whether given object is a scalar reference.
|
|
510
516
|
*/
|
|
511
|
-
static isScalarReference(data
|
|
512
|
-
return
|
|
517
|
+
static isScalarReference(data) {
|
|
518
|
+
return ScalarReference.isScalarReference(data);
|
|
513
519
|
}
|
|
514
520
|
/**
|
|
515
521
|
* Checks whether the argument is empty (array without items, object without keys or falsy value).
|
|
@@ -596,7 +602,7 @@ export class Utils {
|
|
|
596
602
|
return ret;
|
|
597
603
|
}
|
|
598
604
|
static isCollection(item) {
|
|
599
|
-
return item
|
|
605
|
+
return Collection.isCollection(item);
|
|
600
606
|
}
|
|
601
607
|
// FNV-1a 64-bit
|
|
602
608
|
static hash(data, length) {
|
package/utils/clone.js
CHANGED
|
@@ -120,6 +120,7 @@ export function clone(parent, respectCustomCloneMethod = true) {
|
|
|
120
120
|
const symbol = symbols[i];
|
|
121
121
|
const descriptor = Object.getOwnPropertyDescriptor(parent, symbol);
|
|
122
122
|
if (descriptor && !descriptor.enumerable) {
|
|
123
|
+
Object.defineProperty(child, symbol, { ...descriptor, value: _clone(descriptor.value) });
|
|
123
124
|
continue;
|
|
124
125
|
}
|
|
125
126
|
child[symbol] = _clone(parent[symbol]);
|