@mikro-orm/core 7.0.0-dev.1 → 7.0.0-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/EntityManager.d.ts +25 -16
- package/EntityManager.js +219 -209
- 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 +2 -2
- package/decorators/Check.js +5 -8
- package/decorators/CreateRequestContext.d.ts +1 -1
- package/decorators/CreateRequestContext.js +13 -14
- package/decorators/Embeddable.d.ts +5 -5
- package/decorators/Embeddable.js +4 -7
- package/decorators/Embedded.d.ts +3 -3
- package/decorators/Embedded.js +10 -12
- package/decorators/Entity.d.ts +6 -6
- package/decorators/Entity.js +5 -9
- package/decorators/Enum.d.ts +3 -3
- 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 -3
- package/decorators/Formula.js +7 -10
- package/decorators/Indexed.d.ts +10 -8
- package/decorators/Indexed.js +7 -11
- package/decorators/ManyToMany.d.ts +4 -4
- package/decorators/ManyToMany.js +10 -12
- package/decorators/ManyToOne.d.ts +4 -4
- package/decorators/ManyToOne.js +10 -12
- package/decorators/OneToMany.d.ts +6 -6
- package/decorators/OneToMany.js +11 -14
- package/decorators/OneToOne.d.ts +4 -4
- package/decorators/OneToOne.js +4 -7
- package/decorators/PrimaryKey.d.ts +3 -4
- package/decorators/PrimaryKey.js +10 -13
- package/decorators/Property.d.ts +6 -6
- 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 +16 -13
- package/drivers/IDatabaseDriver.js +1 -4
- package/drivers/index.d.ts +2 -2
- package/drivers/index.js +2 -18
- package/entity/ArrayCollection.d.ts +3 -3
- package/entity/ArrayCollection.js +38 -35
- package/entity/BaseEntity.d.ts +6 -6
- package/entity/BaseEntity.js +17 -21
- package/entity/Collection.d.ts +6 -7
- package/entity/Collection.js +47 -51
- package/entity/EntityAssigner.d.ts +2 -2
- package/entity/EntityAssigner.js +58 -63
- package/entity/EntityFactory.d.ts +3 -3
- package/entity/EntityFactory.js +62 -63
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +44 -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 +106 -98
- 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 +4 -8
- 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 +8 -5
- 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 +26 -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 +14 -6
- package/metadata/EntitySchema.js +41 -45
- package/metadata/MetadataDiscovery.d.ts +7 -7
- package/metadata/MetadataDiscovery.js +181 -180
- 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 +52 -55
- 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 +6 -15
- 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 +4 -3
- package/types/BigIntType.js +6 -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 +33 -28
- package/typings.js +37 -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 +51 -48
- 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 +193 -178
- 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 +12 -13
- 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 +6 -6
- 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 +109 -97
- 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 +22 -25
- 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 +96 -95
- 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,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const JsonType_1 = require("../types/JsonType");
|
|
8
|
-
const RawQueryFragment_1 = require("./RawQueryFragment");
|
|
9
|
-
class EntityComparator {
|
|
1
|
+
import { clone } from './clone.js';
|
|
2
|
+
import { ReferenceKind } from '../enums.js';
|
|
3
|
+
import { compareArrays, compareBooleans, compareBuffers, compareObjects, equals, parseJsonSafe, Utils } from './Utils.js';
|
|
4
|
+
import { JsonType } from '../types/JsonType.js';
|
|
5
|
+
import { RawQueryFragment } from './RawQueryFragment.js';
|
|
6
|
+
export class EntityComparator {
|
|
10
7
|
metadata;
|
|
11
8
|
platform;
|
|
12
9
|
comparators = new Map();
|
|
@@ -25,11 +22,11 @@ class EntityComparator {
|
|
|
25
22
|
*/
|
|
26
23
|
diffEntities(entityName, a, b) {
|
|
27
24
|
const comparator = this.getEntityComparator(entityName);
|
|
28
|
-
return
|
|
25
|
+
return Utils.callCompiledFunction(comparator, a, b);
|
|
29
26
|
}
|
|
30
27
|
matching(entityName, a, b) {
|
|
31
28
|
const diff = this.diffEntities(entityName, a, b);
|
|
32
|
-
return
|
|
29
|
+
return Utils.getObjectKeysSize(diff) === 0;
|
|
33
30
|
}
|
|
34
31
|
/**
|
|
35
32
|
* Removes ORM specific code from entities and prepares it for serializing. Used before change set computation.
|
|
@@ -37,21 +34,21 @@ class EntityComparator {
|
|
|
37
34
|
*/
|
|
38
35
|
prepareEntity(entity) {
|
|
39
36
|
const generator = this.getSnapshotGenerator(entity.constructor.name);
|
|
40
|
-
return
|
|
37
|
+
return Utils.callCompiledFunction(generator, entity);
|
|
41
38
|
}
|
|
42
39
|
/**
|
|
43
40
|
* Maps database columns to properties.
|
|
44
41
|
*/
|
|
45
42
|
mapResult(entityName, result) {
|
|
46
43
|
const mapper = this.getResultMapper(entityName);
|
|
47
|
-
return
|
|
44
|
+
return Utils.callCompiledFunction(mapper, result);
|
|
48
45
|
}
|
|
49
46
|
/**
|
|
50
47
|
* @internal Highly performance-sensitive method.
|
|
51
48
|
*/
|
|
52
49
|
getPkGetter(meta) {
|
|
53
50
|
const exists = this.pkGetters.get(meta.className);
|
|
54
|
-
/*
|
|
51
|
+
/* v8 ignore next 3 */
|
|
55
52
|
if (exists) {
|
|
56
53
|
return exists;
|
|
57
54
|
}
|
|
@@ -60,7 +57,7 @@ class EntityComparator {
|
|
|
60
57
|
if (meta.primaryKeys.length > 1) {
|
|
61
58
|
lines.push(` const cond = {`);
|
|
62
59
|
meta.primaryKeys.forEach(pk => {
|
|
63
|
-
if (meta.properties[pk].kind !==
|
|
60
|
+
if (meta.properties[pk].kind !== ReferenceKind.SCALAR) {
|
|
64
61
|
lines.push(` ${pk}: (entity${this.wrap(pk)} != null && (entity${this.wrap(pk)}.__entity || entity${this.wrap(pk)}.__reference)) ? entity${this.wrap(pk)}.__helper.getPrimaryKey() : entity${this.wrap(pk)},`);
|
|
65
62
|
}
|
|
66
63
|
else {
|
|
@@ -73,11 +70,11 @@ class EntityComparator {
|
|
|
73
70
|
}
|
|
74
71
|
else {
|
|
75
72
|
const pk = meta.primaryKeys[0];
|
|
76
|
-
if (meta.properties[pk].kind !==
|
|
73
|
+
if (meta.properties[pk].kind !== ReferenceKind.SCALAR) {
|
|
77
74
|
lines.push(` if (entity${this.wrap(pk)} != null && (entity${this.wrap(pk)}.__entity || entity${this.wrap(pk)}.__reference)) {`);
|
|
78
75
|
lines.push(` const pk = entity${this.wrap(pk)}.__helper.getPrimaryKey();`);
|
|
79
76
|
if (meta.properties[pk].targetMeta.compositePK) {
|
|
80
|
-
lines.push(` if (typeof pk === 'object') {`);
|
|
77
|
+
lines.push(` if (typeof pk === 'object' && pk != null) {`);
|
|
81
78
|
lines.push(` return [`);
|
|
82
79
|
for (const childPK of meta.properties[pk].targetMeta.primaryKeys) {
|
|
83
80
|
lines.push(` pk${this.wrap(childPK)},`);
|
|
@@ -92,7 +89,7 @@ class EntityComparator {
|
|
|
92
89
|
}
|
|
93
90
|
const code = `// compiled pk serializer for entity ${meta.className}\n`
|
|
94
91
|
+ `return function(entity) {\n${lines.join('\n')}\n}`;
|
|
95
|
-
const pkSerializer =
|
|
92
|
+
const pkSerializer = Utils.createFunction(context, code);
|
|
96
93
|
this.pkGetters.set(meta.className, pkSerializer);
|
|
97
94
|
return pkSerializer;
|
|
98
95
|
}
|
|
@@ -101,7 +98,7 @@ class EntityComparator {
|
|
|
101
98
|
*/
|
|
102
99
|
getPkGetterConverted(meta) {
|
|
103
100
|
const exists = this.pkGettersConverted.get(meta.className);
|
|
104
|
-
/*
|
|
101
|
+
/* v8 ignore next 3 */
|
|
105
102
|
if (exists) {
|
|
106
103
|
return exists;
|
|
107
104
|
}
|
|
@@ -110,7 +107,7 @@ class EntityComparator {
|
|
|
110
107
|
if (meta.primaryKeys.length > 1) {
|
|
111
108
|
lines.push(` const cond = {`);
|
|
112
109
|
meta.primaryKeys.forEach(pk => {
|
|
113
|
-
if (meta.properties[pk].kind !==
|
|
110
|
+
if (meta.properties[pk].kind !== ReferenceKind.SCALAR) {
|
|
114
111
|
lines.push(` ${pk}: (entity${this.wrap(pk)} != null && (entity${this.wrap(pk)}.__entity || entity${this.wrap(pk)}.__reference)) ? entity${this.wrap(pk)}.__helper.getPrimaryKey(true) : entity${this.wrap(pk)},`);
|
|
115
112
|
}
|
|
116
113
|
else {
|
|
@@ -129,7 +126,7 @@ class EntityComparator {
|
|
|
129
126
|
}
|
|
130
127
|
else {
|
|
131
128
|
const pk = meta.primaryKeys[0];
|
|
132
|
-
if (meta.properties[pk].kind !==
|
|
129
|
+
if (meta.properties[pk].kind !== ReferenceKind.SCALAR) {
|
|
133
130
|
lines.push(` if (entity${this.wrap(pk)} != null && (entity${this.wrap(pk)}.__entity || entity${this.wrap(pk)}.__reference)) return entity${this.wrap(pk)}.__helper.getPrimaryKey(true);`);
|
|
134
131
|
}
|
|
135
132
|
if (meta.properties[pk].customType) {
|
|
@@ -142,7 +139,7 @@ class EntityComparator {
|
|
|
142
139
|
}
|
|
143
140
|
const code = `// compiled pk getter (with converted custom types) for entity ${meta.className}\n`
|
|
144
141
|
+ `return function(entity) {\n${lines.join('\n')}\n}`;
|
|
145
|
-
const pkSerializer =
|
|
142
|
+
const pkSerializer = Utils.createFunction(context, code);
|
|
146
143
|
this.pkGettersConverted.set(meta.className, pkSerializer);
|
|
147
144
|
return pkSerializer;
|
|
148
145
|
}
|
|
@@ -151,17 +148,17 @@ class EntityComparator {
|
|
|
151
148
|
*/
|
|
152
149
|
getPkSerializer(meta) {
|
|
153
150
|
const exists = this.pkSerializers.get(meta.className);
|
|
154
|
-
/*
|
|
151
|
+
/* v8 ignore next 3 */
|
|
155
152
|
if (exists) {
|
|
156
153
|
return exists;
|
|
157
154
|
}
|
|
158
155
|
const lines = [];
|
|
159
156
|
const context = new Map();
|
|
160
|
-
context.set('getCompositeKeyValue', (val) =>
|
|
157
|
+
context.set('getCompositeKeyValue', (val) => Utils.flatten(Utils.getCompositeKeyValue(val, meta, 'convertToDatabaseValue', this.platform)));
|
|
161
158
|
if (meta.primaryKeys.length > 1) {
|
|
162
159
|
lines.push(` const pks = entity.__helper.__pk ? getCompositeKeyValue(entity.__helper.__pk) : [`);
|
|
163
160
|
meta.primaryKeys.forEach(pk => {
|
|
164
|
-
if (meta.properties[pk].kind !==
|
|
161
|
+
if (meta.properties[pk].kind !== ReferenceKind.SCALAR) {
|
|
165
162
|
lines.push(` (entity${this.wrap(pk)} != null && (entity${this.wrap(pk)}.__entity || entity${this.wrap(pk)}.__reference)) ? entity${this.wrap(pk)}.__helper.getSerializedPrimaryKey() : entity${this.wrap(pk)},`);
|
|
166
163
|
}
|
|
167
164
|
else {
|
|
@@ -169,11 +166,11 @@ class EntityComparator {
|
|
|
169
166
|
}
|
|
170
167
|
});
|
|
171
168
|
lines.push(` ];`);
|
|
172
|
-
lines.push(` return pks.join('${
|
|
169
|
+
lines.push(` return pks.join('${Utils.PK_SEPARATOR}');`);
|
|
173
170
|
}
|
|
174
171
|
else {
|
|
175
172
|
const pk = meta.primaryKeys[0];
|
|
176
|
-
if (meta.properties[pk].kind !==
|
|
173
|
+
if (meta.properties[pk].kind !== ReferenceKind.SCALAR) {
|
|
177
174
|
lines.push(` if (entity${this.wrap(pk)} != null && (entity${this.wrap(pk)}.__entity || entity${this.wrap(pk)}.__reference)) return entity${this.wrap(pk)}.__helper.getSerializedPrimaryKey();`);
|
|
178
175
|
}
|
|
179
176
|
const serializedPrimaryKey = meta.props.find(p => p.serializedPrimaryKey);
|
|
@@ -184,7 +181,7 @@ class EntityComparator {
|
|
|
184
181
|
}
|
|
185
182
|
const code = `// compiled pk serializer for entity ${meta.className}\n`
|
|
186
183
|
+ `return function(entity) {\n${lines.join('\n')}\n}`;
|
|
187
|
-
const pkSerializer =
|
|
184
|
+
const pkSerializer = Utils.createFunction(context, code);
|
|
188
185
|
this.pkSerializers.set(meta.className, pkSerializer);
|
|
189
186
|
return pkSerializer;
|
|
190
187
|
}
|
|
@@ -199,7 +196,7 @@ class EntityComparator {
|
|
|
199
196
|
const meta = this.metadata.find(entityName);
|
|
200
197
|
const lines = [];
|
|
201
198
|
const context = new Map();
|
|
202
|
-
context.set('clone',
|
|
199
|
+
context.set('clone', clone);
|
|
203
200
|
context.set('cloneEmbeddable', (o) => this.platform.cloneEmbeddable(o)); // do not clone prototypes
|
|
204
201
|
if (meta.discriminatorValue) {
|
|
205
202
|
lines.push(` ret${this.wrap(meta.root.discriminatorColumn)} = '${meta.discriminatorValue}'`);
|
|
@@ -209,11 +206,11 @@ class EntityComparator {
|
|
|
209
206
|
meta.comparableProps
|
|
210
207
|
.filter(prop => {
|
|
211
208
|
const root = getRootProperty(prop);
|
|
212
|
-
return prop === root || root.kind !==
|
|
209
|
+
return prop === root || root.kind !== ReferenceKind.EMBEDDED;
|
|
213
210
|
})
|
|
214
211
|
.forEach(prop => lines.push(this.getPropertySnapshot(meta, prop, context, this.wrap(prop.name), this.wrap(prop.name), [prop.name])));
|
|
215
212
|
const code = `return function(entity) {\n const ret = {};\n${lines.join('\n')}\n return ret;\n}`;
|
|
216
|
-
const snapshotGenerator =
|
|
213
|
+
const snapshotGenerator = Utils.createFunction(context, code);
|
|
217
214
|
this.snapshotGenerators.set(entityName, snapshotGenerator);
|
|
218
215
|
return snapshotGenerator;
|
|
219
216
|
}
|
|
@@ -289,60 +286,76 @@ class EntityComparator {
|
|
|
289
286
|
lines.push(`${padding} }`);
|
|
290
287
|
};
|
|
291
288
|
lines.push(` const mapped = {};`);
|
|
292
|
-
meta
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
289
|
+
const mapEntityProperties = (meta, padding = '') => {
|
|
290
|
+
for (const prop of meta.props) {
|
|
291
|
+
if (!prop.fieldNames) {
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (prop.targetMeta && prop.fieldNames.length > 1) {
|
|
295
|
+
lines.push(`${padding} if (${prop.fieldNames.map(field => `typeof ${this.propName(field)} === 'undefined'`).join(' && ')}) {`);
|
|
296
|
+
lines.push(`${padding} } else if (${prop.fieldNames.map(field => `${this.propName(field)} != null`).join(' && ')}) {`);
|
|
297
|
+
lines.push(`${padding} ret${this.wrap(prop.name)} = ${this.createCompositeKeyArray(prop)};`);
|
|
298
|
+
lines.push(...prop.fieldNames.map(field => `${padding} ${this.propName(field, 'mapped')} = true;`));
|
|
299
|
+
lines.push(`${padding} } else if (${prop.fieldNames.map(field => `${this.propName(field)} == null`).join(' && ')}) {\n ret${this.wrap(prop.name)} = null;`);
|
|
300
|
+
lines.push(...prop.fieldNames.map(field => `${padding} ${this.propName(field, 'mapped')} = true;`), ' }');
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
if (prop.embedded && (meta.embeddable || meta.properties[prop.embedded[0]].object)) {
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
if (prop.runtimeType === 'boolean') {
|
|
307
|
+
lines.push(`${padding} if (typeof ${this.propName(prop.fieldNames[0])} !== 'undefined') {`);
|
|
308
|
+
lines.push(`${padding} ret${this.wrap(prop.name)} = ${this.propName(prop.fieldNames[0])} == null ? ${this.propName(prop.fieldNames[0])} : !!${this.propName(prop.fieldNames[0])};`);
|
|
309
|
+
lines.push(`${padding} ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
|
|
310
|
+
lines.push(`${padding} }`);
|
|
311
|
+
}
|
|
312
|
+
else if (prop.runtimeType === 'Date' && !this.platform.isNumericProperty(prop)) {
|
|
313
|
+
lines.push(`${padding} if (typeof ${this.propName(prop.fieldNames[0])} !== 'undefined') {`);
|
|
314
|
+
context.set('parseDate', (value) => this.platform.parseDate(value));
|
|
315
|
+
parseDate('ret' + this.wrap(prop.name), this.propName(prop.fieldNames[0]), padding);
|
|
316
|
+
lines.push(`${padding} ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
|
|
317
|
+
lines.push(`${padding} }`);
|
|
318
|
+
}
|
|
319
|
+
else if (prop.kind === ReferenceKind.EMBEDDED && (prop.object || meta.embeddable)) {
|
|
320
|
+
const idx = this.tmpIndex++;
|
|
321
|
+
context.set(`mapEmbeddedResult_${idx}`, (data) => {
|
|
322
|
+
const item = parseJsonSafe(data);
|
|
323
|
+
if (Array.isArray(item)) {
|
|
324
|
+
return item.map(row => row == null ? row : this.getResultMapper(prop.type)(row));
|
|
325
|
+
}
|
|
326
|
+
return item == null ? item : this.getResultMapper(prop.type)(item);
|
|
327
|
+
});
|
|
328
|
+
lines.push(`${padding} if (typeof ${this.propName(prop.fieldNames[0])} !== 'undefined') {`);
|
|
329
|
+
lines.push(`${padding} ret${this.wrap(prop.name)} = ${this.propName(prop.fieldNames[0])} == null ? ${this.propName(prop.fieldNames[0])} : mapEmbeddedResult_${idx}(${this.propName(prop.fieldNames[0])});`);
|
|
330
|
+
lines.push(`${padding} ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
|
|
331
|
+
lines.push(`${padding} }`);
|
|
332
|
+
}
|
|
333
|
+
else if (prop.kind !== ReferenceKind.EMBEDDED) {
|
|
334
|
+
lines.push(`${padding} if (typeof ${this.propName(prop.fieldNames[0])} !== 'undefined') {`);
|
|
335
|
+
lines.push(`${padding} ret${this.wrap(prop.name)} = ${this.propName(prop.fieldNames[0])};`);
|
|
336
|
+
lines.push(`${padding} ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
|
|
337
|
+
lines.push(`${padding} }`);
|
|
338
|
+
}
|
|
334
339
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
340
|
+
};
|
|
341
|
+
if (meta.polymorphs && meta.discriminatorColumn) {
|
|
342
|
+
for (const polymorph of meta.polymorphs) {
|
|
343
|
+
const first = polymorph === meta.polymorphs[0];
|
|
344
|
+
lines.push(` ${first ? '' : 'else '}if (${this.propName(meta.discriminatorColumn)} == '${polymorph.discriminatorValue}') {`);
|
|
345
|
+
mapEntityProperties(polymorph, ' ');
|
|
339
346
|
lines.push(` }`);
|
|
340
347
|
}
|
|
341
|
-
|
|
348
|
+
lines.push(` else {`);
|
|
349
|
+
mapEntityProperties(meta, ' ');
|
|
350
|
+
lines.push(` }`);
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
mapEntityProperties(meta);
|
|
354
|
+
}
|
|
342
355
|
lines.push(` for (let k in result) { if (Object.hasOwn(result, k) && !mapped[k]) ret[k] = result[k]; }`);
|
|
343
356
|
const code = `// compiled mapper for entity ${meta.className}\n`
|
|
344
357
|
+ `return function(result) {\n const ret = {};\n${lines.join('\n')}\n return ret;\n}`;
|
|
345
|
-
const resultMapper =
|
|
358
|
+
const resultMapper = Utils.createFunction(context, code);
|
|
346
359
|
this.mappers.set(entityName, resultMapper);
|
|
347
360
|
return resultMapper;
|
|
348
361
|
}
|
|
@@ -408,7 +421,7 @@ class EntityComparator {
|
|
|
408
421
|
if (!childProp.customType) {
|
|
409
422
|
return false;
|
|
410
423
|
}
|
|
411
|
-
if (childProp.customType instanceof
|
|
424
|
+
if (childProp.customType instanceof JsonType) {
|
|
412
425
|
return !prop.object;
|
|
413
426
|
}
|
|
414
427
|
return true;
|
|
@@ -419,10 +432,10 @@ class EntityComparator {
|
|
|
419
432
|
const childDataKey = meta.embeddable || prop.object ? dataKey + this.wrap(childProp.embedded[1]) : this.wrap(childProp.name);
|
|
420
433
|
const childEntityKey = [...path, childProp.embedded[1]].map(k => this.wrap(k)).join('');
|
|
421
434
|
const childCond = `typeof entity${childEntityKey} !== 'undefined'`;
|
|
422
|
-
if (childProp.kind ===
|
|
435
|
+
if (childProp.kind === ReferenceKind.EMBEDDED) {
|
|
423
436
|
return this.getPropertySnapshot(meta, childProp, context, childDataKey, childEntityKey, [...path, childProp.embedded[1]], level + 1, prop.object);
|
|
424
437
|
}
|
|
425
|
-
if (childProp.kind !==
|
|
438
|
+
if (childProp.kind !== ReferenceKind.SCALAR) {
|
|
426
439
|
return this.getPropertySnapshot(meta, childProp, context, childDataKey, childEntityKey, [...path, childProp.embedded[1]], level, prop.object)
|
|
427
440
|
.split('\n').map(l => padding + l).join('\n');
|
|
428
441
|
}
|
|
@@ -443,8 +456,8 @@ class EntityComparator {
|
|
|
443
456
|
registerCustomType(prop, context) {
|
|
444
457
|
const convertorKey = this.safeKey(prop.name);
|
|
445
458
|
context.set(`convertToDatabaseValue_${convertorKey}`, (val) => {
|
|
446
|
-
/*
|
|
447
|
-
if (
|
|
459
|
+
/* v8 ignore next 3 */
|
|
460
|
+
if (RawQueryFragment.isKnownFragment(val)) {
|
|
448
461
|
return val;
|
|
449
462
|
}
|
|
450
463
|
return prop.customType.convertToDatabaseValue(val, this.platform, { mode: 'serialization' });
|
|
@@ -457,13 +470,13 @@ class EntityComparator {
|
|
|
457
470
|
if (['number', 'string', 'boolean'].includes(prop.type.toLowerCase())) {
|
|
458
471
|
return ret + ` ret${dataKey} = entity${entityKey}${unwrap};\n }\n`;
|
|
459
472
|
}
|
|
460
|
-
if (prop.kind ===
|
|
473
|
+
if (prop.kind === ReferenceKind.EMBEDDED) {
|
|
461
474
|
if (prop.array) {
|
|
462
475
|
return this.getEmbeddedArrayPropertySnapshot(meta, prop, context, level, path, dataKey) + '\n';
|
|
463
476
|
}
|
|
464
477
|
return this.getEmbeddedPropertySnapshot(meta, prop, context, level, path, dataKey, object) + '\n';
|
|
465
478
|
}
|
|
466
|
-
if (prop.kind ===
|
|
479
|
+
if (prop.kind === ReferenceKind.ONE_TO_ONE || prop.kind === ReferenceKind.MANY_TO_ONE) {
|
|
467
480
|
if (prop.mapToPk) {
|
|
468
481
|
if (prop.customType) {
|
|
469
482
|
const convertorKey = this.registerCustomType(prop, context);
|
|
@@ -475,7 +488,7 @@ class EntityComparator {
|
|
|
475
488
|
}
|
|
476
489
|
else {
|
|
477
490
|
const toArray = (val) => {
|
|
478
|
-
if (
|
|
491
|
+
if (Utils.isPlainObject(val)) {
|
|
479
492
|
return Object.values(val).map(v => toArray(v));
|
|
480
493
|
}
|
|
481
494
|
return val;
|
|
@@ -513,17 +526,17 @@ class EntityComparator {
|
|
|
513
526
|
const meta = this.metadata.find(entityName);
|
|
514
527
|
const lines = [];
|
|
515
528
|
const context = new Map();
|
|
516
|
-
context.set('compareArrays',
|
|
517
|
-
context.set('compareBooleans',
|
|
518
|
-
context.set('compareBuffers',
|
|
519
|
-
context.set('compareObjects',
|
|
520
|
-
context.set('equals',
|
|
529
|
+
context.set('compareArrays', compareArrays);
|
|
530
|
+
context.set('compareBooleans', compareBooleans);
|
|
531
|
+
context.set('compareBuffers', compareBuffers);
|
|
532
|
+
context.set('compareObjects', compareObjects);
|
|
533
|
+
context.set('equals', equals);
|
|
521
534
|
meta.comparableProps.forEach(prop => {
|
|
522
535
|
lines.push(this.getPropertyComparator(prop, context));
|
|
523
536
|
});
|
|
524
537
|
const code = `// compiled comparator for entity ${meta.className}\n`
|
|
525
538
|
+ `return function(last, current) {\n const diff = {};\n${lines.join('\n')}\n return diff;\n}`;
|
|
526
|
-
const comparator =
|
|
539
|
+
const comparator = Utils.createFunction(context, code);
|
|
527
540
|
this.comparators.set(entityName, comparator);
|
|
528
541
|
return comparator;
|
|
529
542
|
}
|
|
@@ -537,7 +550,7 @@ class EntityComparator {
|
|
|
537
550
|
}
|
|
538
551
|
getPropertyComparator(prop, context) {
|
|
539
552
|
let type = prop.type.toLowerCase();
|
|
540
|
-
if (prop.kind !==
|
|
553
|
+
if (prop.kind !== ReferenceKind.SCALAR && prop.kind !== ReferenceKind.EMBEDDED) {
|
|
541
554
|
const meta2 = this.metadata.find(prop.type);
|
|
542
555
|
if (meta2.primaryKeys.length > 1) {
|
|
543
556
|
type = 'array';
|
|
@@ -595,10 +608,9 @@ class EntityComparator {
|
|
|
595
608
|
*/
|
|
596
609
|
static isComparable(prop, root) {
|
|
597
610
|
const virtual = prop.persist === false || prop.generated;
|
|
598
|
-
const inverse = prop.kind ===
|
|
611
|
+
const inverse = prop.kind === ReferenceKind.ONE_TO_ONE && !prop.owner;
|
|
599
612
|
const discriminator = prop.name === root.discriminatorColumn;
|
|
600
|
-
const collection = prop.kind ===
|
|
613
|
+
const collection = prop.kind === ReferenceKind.ONE_TO_MANY || prop.kind === ReferenceKind.MANY_TO_MANY;
|
|
601
614
|
return !virtual && !collection && !inverse && !discriminator && !prop.version;
|
|
602
615
|
}
|
|
603
616
|
}
|
|
604
|
-
exports.EntityComparator = EntityComparator;
|
package/utils/NullHighlighter.js
CHANGED
package/utils/QueryHelper.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Dictionary, EntityMetadata, EntityProperty, FilterDef, FilterQuery } from '../typings';
|
|
2
|
-
import type { Platform } from '../platforms';
|
|
3
|
-
import type { MetadataStorage } from '../metadata/MetadataStorage';
|
|
1
|
+
import type { Dictionary, EntityMetadata, EntityProperty, FilterDef, FilterQuery } from '../typings.js';
|
|
2
|
+
import type { Platform } from '../platforms/Platform.js';
|
|
3
|
+
import type { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
4
4
|
export declare class QueryHelper {
|
|
5
5
|
static readonly SUPPORTED_OPERATORS: string[];
|
|
6
6
|
static processParams(params: unknown): any;
|