@mikro-orm/core 7.0.0-dev.1 → 7.0.0-dev.11
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
package/entity/EntityLoader.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const RawQueryFragment_1 = require("../utils/RawQueryFragment");
|
|
11
|
-
const utils_1 = require("./utils");
|
|
12
|
-
class EntityLoader {
|
|
1
|
+
import { QueryHelper } from '../utils/QueryHelper.js';
|
|
2
|
+
import { Utils } from '../utils/Utils.js';
|
|
3
|
+
import { ValidationError } from '../errors.js';
|
|
4
|
+
import { LoadStrategy, PopulatePath, ReferenceKind, } from '../enums.js';
|
|
5
|
+
import { Reference } from './Reference.js';
|
|
6
|
+
import { helper } from './wrap.js';
|
|
7
|
+
import { raw, RawQueryFragment } from '../utils/RawQueryFragment.js';
|
|
8
|
+
import { expandDotPaths } from './utils.js';
|
|
9
|
+
export class EntityLoader {
|
|
13
10
|
em;
|
|
14
11
|
metadata;
|
|
15
12
|
driver;
|
|
@@ -23,15 +20,15 @@ class EntityLoader {
|
|
|
23
20
|
* This will execute one query for each relation, that will populate it on all the specified entities.
|
|
24
21
|
*/
|
|
25
22
|
async populate(entityName, entities, populate, options) {
|
|
26
|
-
if (entities.length === 0 ||
|
|
23
|
+
if (entities.length === 0 || Utils.isEmpty(populate)) {
|
|
27
24
|
return this.setSerializationContext(entities, populate, options);
|
|
28
25
|
}
|
|
29
26
|
const meta = this.metadata.find(entityName);
|
|
30
27
|
if (entities.some(e => !e.__helper)) {
|
|
31
|
-
const entity = entities.find(e => !
|
|
32
|
-
throw
|
|
28
|
+
const entity = entities.find(e => !Utils.isEntity(e));
|
|
29
|
+
throw ValidationError.notDiscoveredEntity(entity, meta, 'populate');
|
|
33
30
|
}
|
|
34
|
-
const references = entities.filter(e => !
|
|
31
|
+
const references = entities.filter(e => !helper(e).isInitialized());
|
|
35
32
|
const visited = options.visited ??= new Set();
|
|
36
33
|
options.where ??= {};
|
|
37
34
|
options.orderBy ??= {};
|
|
@@ -45,9 +42,9 @@ class EntityLoader {
|
|
|
45
42
|
}
|
|
46
43
|
populate = this.normalizePopulate(entityName, populate, options.strategy, options.lookup);
|
|
47
44
|
const invalid = populate.find(({ field }) => !this.em.canPopulate(entityName, field));
|
|
48
|
-
/*
|
|
45
|
+
/* v8 ignore next 3 */
|
|
49
46
|
if (options.validate && invalid) {
|
|
50
|
-
throw
|
|
47
|
+
throw ValidationError.invalidPropertyName(entityName, invalid.field);
|
|
51
48
|
}
|
|
52
49
|
this.setSerializationContext(entities, populate, options);
|
|
53
50
|
for (const entity of entities) {
|
|
@@ -62,25 +59,25 @@ class EntityLoader {
|
|
|
62
59
|
}
|
|
63
60
|
normalizePopulate(entityName, populate, strategy, lookup = true) {
|
|
64
61
|
const meta = this.metadata.find(entityName);
|
|
65
|
-
let normalized =
|
|
66
|
-
return typeof field === 'boolean' || field.field ===
|
|
62
|
+
let normalized = Utils.asArray(populate).map(field => {
|
|
63
|
+
return typeof field === 'boolean' || field.field === PopulatePath.ALL ? { all: !!field, field: meta.primaryKeys[0] } : field;
|
|
67
64
|
});
|
|
68
65
|
if (normalized.some(p => p.all)) {
|
|
69
66
|
normalized = this.lookupAllRelationships(entityName);
|
|
70
67
|
}
|
|
71
68
|
// convert nested `field` with dot syntax to PopulateOptions with `children` array
|
|
72
|
-
|
|
69
|
+
expandDotPaths(meta, normalized, true);
|
|
73
70
|
if (lookup && populate !== false) {
|
|
74
71
|
normalized = this.lookupEagerLoadedRelationships(entityName, normalized, strategy);
|
|
75
72
|
// convert nested `field` with dot syntax produced by eager relations
|
|
76
|
-
|
|
73
|
+
expandDotPaths(meta, normalized, true);
|
|
77
74
|
}
|
|
78
75
|
// merge same fields
|
|
79
76
|
return this.mergeNestedPopulate(normalized);
|
|
80
77
|
}
|
|
81
78
|
setSerializationContext(entities, populate, options) {
|
|
82
79
|
for (const entity of entities) {
|
|
83
|
-
|
|
80
|
+
helper(entity).setSerializationContext({
|
|
84
81
|
populate,
|
|
85
82
|
fields: options.fields,
|
|
86
83
|
exclude: options.exclude,
|
|
@@ -93,7 +90,7 @@ class EntityLoader {
|
|
|
93
90
|
*/
|
|
94
91
|
mergeNestedPopulate(populate) {
|
|
95
92
|
const tmp = populate.reduce((ret, item) => {
|
|
96
|
-
if (item.field ===
|
|
93
|
+
if (item.field === PopulatePath.ALL) {
|
|
97
94
|
return ret;
|
|
98
95
|
}
|
|
99
96
|
if (!ret[item.field]) {
|
|
@@ -122,13 +119,13 @@ class EntityLoader {
|
|
|
122
119
|
const [field, ref] = populate.field.split(':', 2);
|
|
123
120
|
const meta = this.metadata.find(entityName);
|
|
124
121
|
const prop = meta.properties[field];
|
|
125
|
-
if (prop.kind ===
|
|
122
|
+
if (prop.kind === ReferenceKind.MANY_TO_MANY && prop.owner && !this.driver.getPlatform().usesPivotTable()) {
|
|
126
123
|
const filtered = entities.filter(e => !e[prop.name]?.isInitialized());
|
|
127
124
|
if (filtered.length > 0) {
|
|
128
125
|
await this.populateScalar(meta, filtered, { ...options, fields: [prop.name] });
|
|
129
126
|
}
|
|
130
127
|
}
|
|
131
|
-
if (prop.kind ===
|
|
128
|
+
if (prop.kind === ReferenceKind.SCALAR && prop.lazy) {
|
|
132
129
|
const filtered = entities.filter(e => options.refresh || (prop.ref ? !e[prop.name]?.isInitialized() : e[prop.name] === undefined));
|
|
133
130
|
if (options.ignoreLazyScalarProperties || filtered.length === 0) {
|
|
134
131
|
return entities;
|
|
@@ -136,14 +133,14 @@ class EntityLoader {
|
|
|
136
133
|
await this.populateScalar(meta, filtered, { ...options, fields: [prop.name] });
|
|
137
134
|
return entities;
|
|
138
135
|
}
|
|
139
|
-
if (prop.kind ===
|
|
136
|
+
if (prop.kind === ReferenceKind.EMBEDDED) {
|
|
140
137
|
return [];
|
|
141
138
|
}
|
|
142
139
|
const filtered = this.filterCollections(entities, field, options, ref);
|
|
143
|
-
const innerOrderBy =
|
|
144
|
-
.filter(orderBy => (Array.isArray(orderBy[prop.name]) && orderBy[prop.name].length > 0) ||
|
|
140
|
+
const innerOrderBy = Utils.asArray(options.orderBy)
|
|
141
|
+
.filter(orderBy => (Array.isArray(orderBy[prop.name]) && orderBy[prop.name].length > 0) || Utils.isObject(orderBy[prop.name]))
|
|
145
142
|
.flatMap(orderBy => orderBy[prop.name]);
|
|
146
|
-
if (prop.kind ===
|
|
143
|
+
if (prop.kind === ReferenceKind.MANY_TO_MANY && this.driver.getPlatform().usesPivotTable()) {
|
|
147
144
|
return this.findChildrenFromPivotTable(filtered, prop, options, innerOrderBy, populate, !!ref);
|
|
148
145
|
}
|
|
149
146
|
const where = await this.extractChildCondition(options, prop);
|
|
@@ -152,8 +149,8 @@ class EntityLoader {
|
|
|
152
149
|
return data;
|
|
153
150
|
}
|
|
154
151
|
async populateScalar(meta, filtered, options) {
|
|
155
|
-
const pk =
|
|
156
|
-
const ids =
|
|
152
|
+
const pk = Utils.getPrimaryKeyHash(meta.primaryKeys);
|
|
153
|
+
const ids = Utils.unique(filtered.map(e => Utils.getPrimaryKeyValues(e, meta.primaryKeys, true)));
|
|
157
154
|
const where = this.mergePrimaryCondition(ids, pk, options, meta, this.metadata, this.driver.getPlatform());
|
|
158
155
|
const { filters, convertCustomTypes, lockMode, strategy, populateWhere, connectionType, logging, fields } = options;
|
|
159
156
|
await this.em.find(meta.className, where, {
|
|
@@ -163,10 +160,10 @@ class EntityLoader {
|
|
|
163
160
|
});
|
|
164
161
|
}
|
|
165
162
|
initializeCollections(filtered, prop, field, children, customOrder) {
|
|
166
|
-
if (prop.kind ===
|
|
163
|
+
if (prop.kind === ReferenceKind.ONE_TO_MANY) {
|
|
167
164
|
this.initializeOneToMany(filtered, children, prop, field);
|
|
168
165
|
}
|
|
169
|
-
if (prop.kind ===
|
|
166
|
+
if (prop.kind === ReferenceKind.MANY_TO_MANY && !this.driver.getPlatform().usesPivotTable()) {
|
|
170
167
|
this.initializeManyToMany(filtered, children, prop, field, customOrder);
|
|
171
168
|
}
|
|
172
169
|
}
|
|
@@ -174,18 +171,18 @@ class EntityLoader {
|
|
|
174
171
|
const mapToPk = prop.targetMeta.properties[prop.mappedBy].mapToPk;
|
|
175
172
|
const map = {};
|
|
176
173
|
for (const entity of filtered) {
|
|
177
|
-
const key =
|
|
174
|
+
const key = helper(entity).getSerializedPrimaryKey();
|
|
178
175
|
map[key] = [];
|
|
179
176
|
}
|
|
180
177
|
for (const child of children) {
|
|
181
178
|
const pk = child.__helper.__data[prop.mappedBy] ?? child[prop.mappedBy];
|
|
182
179
|
if (pk) {
|
|
183
|
-
const key =
|
|
180
|
+
const key = helper(mapToPk ? this.em.getReference(prop.type, pk) : pk).getSerializedPrimaryKey();
|
|
184
181
|
map[key]?.push(child);
|
|
185
182
|
}
|
|
186
183
|
}
|
|
187
184
|
for (const entity of filtered) {
|
|
188
|
-
const key =
|
|
185
|
+
const key = helper(entity).getSerializedPrimaryKey();
|
|
189
186
|
entity[field].hydrate(map[key]);
|
|
190
187
|
}
|
|
191
188
|
}
|
|
@@ -210,12 +207,12 @@ class EntityLoader {
|
|
|
210
207
|
async findChildren(entities, prop, populate, options, ref) {
|
|
211
208
|
const children = this.getChildReferences(entities, prop, options, ref);
|
|
212
209
|
const meta = prop.targetMeta;
|
|
213
|
-
let fk =
|
|
210
|
+
let fk = Utils.getPrimaryKeyHash(meta.primaryKeys);
|
|
214
211
|
let schema = options.schema;
|
|
215
|
-
if (prop.kind ===
|
|
212
|
+
if (prop.kind === ReferenceKind.ONE_TO_MANY || (prop.kind === ReferenceKind.MANY_TO_MANY && !prop.owner)) {
|
|
216
213
|
fk = meta.properties[prop.mappedBy].name;
|
|
217
214
|
}
|
|
218
|
-
if (prop.kind ===
|
|
215
|
+
if (prop.kind === ReferenceKind.ONE_TO_ONE && !prop.owner && !ref) {
|
|
219
216
|
children.length = 0;
|
|
220
217
|
fk = meta.properties[prop.mappedBy].name;
|
|
221
218
|
children.push(...this.filterByReferences(entities, prop.name, options.refresh));
|
|
@@ -223,10 +220,10 @@ class EntityLoader {
|
|
|
223
220
|
if (children.length === 0) {
|
|
224
221
|
return [];
|
|
225
222
|
}
|
|
226
|
-
if (!schema && [
|
|
223
|
+
if (!schema && [ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(prop.kind)) {
|
|
227
224
|
schema = children.find(e => e.__helper.__schema)?.__helper.__schema;
|
|
228
225
|
}
|
|
229
|
-
const ids =
|
|
226
|
+
const ids = Utils.unique(children.map(e => e.__helper.getPrimaryKey()));
|
|
230
227
|
let where = this.mergePrimaryCondition(ids, fk, options, meta, this.metadata, this.driver.getPlatform());
|
|
231
228
|
const fields = this.buildFields(options.fields, prop, ref);
|
|
232
229
|
/* eslint-disable prefer-const */
|
|
@@ -235,16 +232,16 @@ class EntityLoader {
|
|
|
235
232
|
if (typeof populateWhere === 'object') {
|
|
236
233
|
populateWhere = await this.extractChildCondition({ where: populateWhere }, prop);
|
|
237
234
|
}
|
|
238
|
-
if (!
|
|
235
|
+
if (!Utils.isEmpty(prop.where)) {
|
|
239
236
|
where = { $and: [where, prop.where] };
|
|
240
237
|
}
|
|
241
238
|
const propOrderBy = [];
|
|
242
239
|
if (prop.orderBy) {
|
|
243
|
-
for (const item of
|
|
244
|
-
for (const field of
|
|
245
|
-
const rawField =
|
|
240
|
+
for (const item of Utils.asArray(prop.orderBy)) {
|
|
241
|
+
for (const field of Utils.keys(item)) {
|
|
242
|
+
const rawField = RawQueryFragment.getKnownFragment(field, false);
|
|
246
243
|
if (rawField) {
|
|
247
|
-
const raw2 =
|
|
244
|
+
const raw2 = raw(rawField.sql, rawField.params);
|
|
248
245
|
propOrderBy.push({ [raw2.toString()]: item[field] });
|
|
249
246
|
continue;
|
|
250
247
|
}
|
|
@@ -252,11 +249,15 @@ class EntityLoader {
|
|
|
252
249
|
}
|
|
253
250
|
}
|
|
254
251
|
}
|
|
252
|
+
const orderBy = [...Utils.asArray(options.orderBy), ...propOrderBy].filter((order, idx, array) => {
|
|
253
|
+
// skip consecutive ordering with the same key to get around mongo issues
|
|
254
|
+
return idx === 0 || !Utils.equals(Object.keys(array[idx - 1]), Object.keys(order));
|
|
255
|
+
});
|
|
255
256
|
const items = await this.em.find(prop.type, where, {
|
|
256
257
|
filters, convertCustomTypes, lockMode, populateWhere, logging,
|
|
257
|
-
orderBy
|
|
258
|
+
orderBy,
|
|
258
259
|
populate: populate.children ?? populate.all ?? [],
|
|
259
|
-
exclude: Array.isArray(options.exclude) ?
|
|
260
|
+
exclude: Array.isArray(options.exclude) ? Utils.extractChildElements(options.exclude, prop.name) : options.exclude,
|
|
260
261
|
strategy, fields, schema, connectionType,
|
|
261
262
|
// @ts-ignore not a public option, will be propagated to the populate call
|
|
262
263
|
refresh: refresh && !children.every(item => options.visited.has(item)),
|
|
@@ -264,8 +265,8 @@ class EntityLoader {
|
|
|
264
265
|
visited: options.visited,
|
|
265
266
|
});
|
|
266
267
|
for (const item of items) {
|
|
267
|
-
if (ref && !
|
|
268
|
-
|
|
268
|
+
if (ref && !helper(item).__onLoadFired) {
|
|
269
|
+
helper(item).__initialized = false;
|
|
269
270
|
// eslint-disable-next-line dot-notation
|
|
270
271
|
this.em.getUnitOfWork()['loadedEntities'].delete(item);
|
|
271
272
|
}
|
|
@@ -273,9 +274,9 @@ class EntityLoader {
|
|
|
273
274
|
return items;
|
|
274
275
|
}
|
|
275
276
|
mergePrimaryCondition(ids, pk, options, meta, metadata, platform) {
|
|
276
|
-
const cond1 =
|
|
277
|
+
const cond1 = QueryHelper.processWhere({ where: { [pk]: { $in: ids } }, entityName: meta.className, metadata, platform, convertCustomTypes: !options.convertCustomTypes });
|
|
277
278
|
const where = { ...options.where };
|
|
278
|
-
|
|
279
|
+
Utils.dropUndefinedProperties(where);
|
|
279
280
|
return where[pk]
|
|
280
281
|
? { $and: [cond1, where] }
|
|
281
282
|
: { ...cond1, ...where };
|
|
@@ -283,7 +284,7 @@ class EntityLoader {
|
|
|
283
284
|
async populateField(entityName, entities, populate, options) {
|
|
284
285
|
const field = populate.field.split(':')[0];
|
|
285
286
|
const prop = this.metadata.find(entityName).properties[field];
|
|
286
|
-
if (prop.kind ===
|
|
287
|
+
if (prop.kind === ReferenceKind.SCALAR && !prop.lazy) {
|
|
287
288
|
return;
|
|
288
289
|
}
|
|
289
290
|
const populated = await this.populateMany(entityName, entities, populate, options);
|
|
@@ -293,29 +294,36 @@ class EntityLoader {
|
|
|
293
294
|
const children = [];
|
|
294
295
|
for (const entity of entities) {
|
|
295
296
|
const ref = entity[field];
|
|
296
|
-
if (
|
|
297
|
+
if (Utils.isEntity(ref)) {
|
|
297
298
|
children.push(ref);
|
|
298
299
|
}
|
|
299
|
-
else if (
|
|
300
|
+
else if (Reference.isReference(ref)) {
|
|
300
301
|
children.push(ref.unwrap());
|
|
301
302
|
}
|
|
302
|
-
else if (
|
|
303
|
+
else if (Utils.isCollection(ref)) {
|
|
303
304
|
children.push(...ref.getItems());
|
|
304
305
|
}
|
|
305
|
-
else if (ref && prop.kind ===
|
|
306
|
-
children.push(...
|
|
306
|
+
else if (ref && prop.kind === ReferenceKind.EMBEDDED) {
|
|
307
|
+
children.push(...Utils.asArray(ref));
|
|
307
308
|
}
|
|
308
309
|
}
|
|
309
310
|
if (populated.length === 0 && !populate.children) {
|
|
310
311
|
return;
|
|
311
312
|
}
|
|
312
313
|
const fields = this.buildFields(options.fields, prop);
|
|
313
|
-
const innerOrderBy =
|
|
314
|
-
.filter(orderBy =>
|
|
314
|
+
const innerOrderBy = Utils.asArray(options.orderBy)
|
|
315
|
+
.filter(orderBy => Utils.isObject(orderBy[prop.name]))
|
|
315
316
|
.map(orderBy => orderBy[prop.name]);
|
|
316
|
-
const { refresh, filters, ignoreLazyScalarProperties, populateWhere, connectionType, logging } = options;
|
|
317
|
-
const exclude = Array.isArray(options.exclude) ?
|
|
318
|
-
const
|
|
317
|
+
const { refresh, filters, ignoreLazyScalarProperties, populateWhere, connectionType, logging, schema } = options;
|
|
318
|
+
const exclude = Array.isArray(options.exclude) ? Utils.extractChildElements(options.exclude, prop.name) : options.exclude;
|
|
319
|
+
const visited = options.visited;
|
|
320
|
+
for (const entity of entities) {
|
|
321
|
+
visited.delete(entity);
|
|
322
|
+
}
|
|
323
|
+
const filtered = Utils.unique(children.filter(e => !visited.has(e)));
|
|
324
|
+
for (const entity of entities) {
|
|
325
|
+
visited.add(entity);
|
|
326
|
+
}
|
|
319
327
|
await this.populate(prop.type, filtered, populate.children ?? populate.all, {
|
|
320
328
|
where: await this.extractChildCondition(options, prop, false),
|
|
321
329
|
orderBy: innerOrderBy,
|
|
@@ -328,6 +336,7 @@ class EntityLoader {
|
|
|
328
336
|
populateWhere,
|
|
329
337
|
connectionType,
|
|
330
338
|
logging,
|
|
339
|
+
schema,
|
|
331
340
|
// @ts-ignore not a public option, will be propagated to the populate call
|
|
332
341
|
refresh: refresh && !filtered.every(item => options.visited.has(item)),
|
|
333
342
|
// @ts-ignore not a public option, will be propagated to the populate call
|
|
@@ -339,7 +348,7 @@ class EntityLoader {
|
|
|
339
348
|
const refresh = options.refresh;
|
|
340
349
|
let where = await this.extractChildCondition(options, prop, true);
|
|
341
350
|
const fields = this.buildFields(options.fields, prop);
|
|
342
|
-
const exclude = Array.isArray(options.exclude) ?
|
|
351
|
+
const exclude = Array.isArray(options.exclude) ? Utils.extractChildElements(options.exclude, prop.name) : options.exclude;
|
|
343
352
|
const options2 = { ...options };
|
|
344
353
|
delete options2.limit;
|
|
345
354
|
delete options2.offset;
|
|
@@ -347,9 +356,9 @@ class EntityLoader {
|
|
|
347
356
|
options2.exclude = exclude;
|
|
348
357
|
options2.populate = (populate?.children ?? []);
|
|
349
358
|
if (prop.customType) {
|
|
350
|
-
ids.forEach((id, idx) => ids[idx] =
|
|
359
|
+
ids.forEach((id, idx) => ids[idx] = QueryHelper.processCustomType(prop, id, this.driver.getPlatform()));
|
|
351
360
|
}
|
|
352
|
-
if (!
|
|
361
|
+
if (!Utils.isEmpty(prop.where)) {
|
|
353
362
|
where = { $and: [where, prop.where] };
|
|
354
363
|
}
|
|
355
364
|
const map = await this.driver.loadFromPivotTable(prop, ids, where, orderBy, this.em.getTransactionContext(), options2, pivotJoin);
|
|
@@ -377,19 +386,19 @@ class EntityLoader {
|
|
|
377
386
|
}
|
|
378
387
|
async extractChildCondition(options, prop, filters = false) {
|
|
379
388
|
const where = options.where;
|
|
380
|
-
const subCond =
|
|
389
|
+
const subCond = Utils.isPlainObject(where[prop.name]) ? where[prop.name] : {};
|
|
381
390
|
const meta2 = this.metadata.find(prop.type);
|
|
382
391
|
if (!meta2) {
|
|
383
392
|
return {};
|
|
384
393
|
}
|
|
385
|
-
const pk =
|
|
394
|
+
const pk = Utils.getPrimaryKeyHash(meta2.primaryKeys);
|
|
386
395
|
['$and', '$or'].forEach(op => {
|
|
387
396
|
if (where[op]) {
|
|
388
397
|
const child = where[op]
|
|
389
398
|
.map((cond) => cond[prop.name])
|
|
390
|
-
.filter((sub) => sub != null && !(
|
|
399
|
+
.filter((sub) => sub != null && !(Utils.isPlainObject(sub) && Object.keys(sub).every(key => Utils.isOperator(key, false))))
|
|
391
400
|
.map((cond) => {
|
|
392
|
-
if (
|
|
401
|
+
if (Utils.isPrimaryKey(cond)) {
|
|
393
402
|
return { [pk]: cond };
|
|
394
403
|
}
|
|
395
404
|
return cond;
|
|
@@ -399,7 +408,7 @@ class EntityLoader {
|
|
|
399
408
|
}
|
|
400
409
|
}
|
|
401
410
|
});
|
|
402
|
-
const operators = Object.keys(subCond).filter(key =>
|
|
411
|
+
const operators = Object.keys(subCond).filter(key => Utils.isOperator(key, false));
|
|
403
412
|
if (operators.length > 0) {
|
|
404
413
|
operators.forEach(op => {
|
|
405
414
|
subCond[pk] ??= {};
|
|
@@ -417,8 +426,8 @@ class EntityLoader {
|
|
|
417
426
|
fields = prop.targetMeta.primaryKeys.map(targetPkName => `${prop.name}.${targetPkName}`);
|
|
418
427
|
}
|
|
419
428
|
const ret = fields.reduce((ret, f) => {
|
|
420
|
-
if (
|
|
421
|
-
|
|
429
|
+
if (Utils.isPlainObject(f)) {
|
|
430
|
+
Utils.keys(f)
|
|
422
431
|
.filter(ff => ff === prop.name)
|
|
423
432
|
.forEach(ff => ret.push(...f[ff]));
|
|
424
433
|
}
|
|
@@ -426,7 +435,7 @@ class EntityLoader {
|
|
|
426
435
|
const parts = f.toString().split('.');
|
|
427
436
|
const propName = parts.shift();
|
|
428
437
|
const childPropName = parts.join('.');
|
|
429
|
-
/*
|
|
438
|
+
/* v8 ignore next 3 */
|
|
430
439
|
if (propName === prop.name) {
|
|
431
440
|
ret.push(childPropName);
|
|
432
441
|
}
|
|
@@ -437,7 +446,7 @@ class EntityLoader {
|
|
|
437
446
|
return undefined;
|
|
438
447
|
}
|
|
439
448
|
// we need to automatically select the FKs too, e.g. for 1:m relations to be able to wire them with the items
|
|
440
|
-
if (prop.kind ===
|
|
449
|
+
if (prop.kind === ReferenceKind.ONE_TO_MANY || prop.kind === ReferenceKind.MANY_TO_MANY) {
|
|
441
450
|
const owner = prop.targetMeta.properties[prop.mappedBy];
|
|
442
451
|
if (owner && !ret.includes(owner.name)) {
|
|
443
452
|
ret.push(owner.name);
|
|
@@ -448,16 +457,16 @@ class EntityLoader {
|
|
|
448
457
|
getChildReferences(entities, prop, options, ref) {
|
|
449
458
|
const filtered = this.filterCollections(entities, prop.name, options, ref);
|
|
450
459
|
const children = [];
|
|
451
|
-
if (prop.kind ===
|
|
460
|
+
if (prop.kind === ReferenceKind.ONE_TO_MANY) {
|
|
452
461
|
children.push(...filtered.map(e => e[prop.name].owner));
|
|
453
462
|
}
|
|
454
|
-
else if (prop.kind ===
|
|
463
|
+
else if (prop.kind === ReferenceKind.MANY_TO_MANY && prop.owner) {
|
|
455
464
|
children.push(...filtered.reduce((a, b) => {
|
|
456
465
|
a.push(...b[prop.name].getItems());
|
|
457
466
|
return a;
|
|
458
467
|
}, []));
|
|
459
468
|
}
|
|
460
|
-
else if (prop.kind ===
|
|
469
|
+
else if (prop.kind === ReferenceKind.MANY_TO_MANY) { // inverse side
|
|
461
470
|
children.push(...filtered);
|
|
462
471
|
}
|
|
463
472
|
else { // MANY_TO_ONE or ONE_TO_ONE
|
|
@@ -469,39 +478,39 @@ class EntityLoader {
|
|
|
469
478
|
if (options.refresh) {
|
|
470
479
|
return entities.filter(e => e[field]);
|
|
471
480
|
}
|
|
472
|
-
return entities.filter(e =>
|
|
481
|
+
return entities.filter(e => Utils.isCollection(e[field]) && !e[field].isInitialized(!ref));
|
|
473
482
|
}
|
|
474
483
|
isPropertyLoaded(entity, field) {
|
|
475
484
|
if (!entity || field === '*') {
|
|
476
485
|
return true;
|
|
477
486
|
}
|
|
478
|
-
const wrapped =
|
|
487
|
+
const wrapped = helper(entity);
|
|
479
488
|
if (!field.includes('.')) {
|
|
480
489
|
return wrapped.__loadedProperties.has(field);
|
|
481
490
|
}
|
|
482
491
|
const [f, ...r] = field.split('.');
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
492
|
+
/* v8 ignore next 3 */
|
|
493
|
+
if (!wrapped.__loadedProperties.has(f) || !wrapped.__meta.properties[f]?.targetMeta) {
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
if ([ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(wrapped.__meta.properties[f].kind)) {
|
|
497
|
+
return entity[f].getItems(false).every((item) => this.isPropertyLoaded(item, r.join('.')));
|
|
488
498
|
}
|
|
489
|
-
|
|
490
|
-
return false;
|
|
499
|
+
return this.isPropertyLoaded(entity[f], r.join('.'));
|
|
491
500
|
}
|
|
492
501
|
filterReferences(entities, field, options, ref) {
|
|
493
502
|
if (ref) {
|
|
494
503
|
return [];
|
|
495
504
|
}
|
|
496
|
-
const children = entities.filter(e =>
|
|
505
|
+
const children = entities.filter(e => Utils.isEntity(e[field], true));
|
|
497
506
|
if (options.refresh) {
|
|
498
|
-
return children.map(e =>
|
|
507
|
+
return children.map(e => Reference.unwrapReference(e[field]));
|
|
499
508
|
}
|
|
500
509
|
if (options.fields) {
|
|
501
510
|
return children
|
|
502
|
-
.map(e =>
|
|
511
|
+
.map(e => Reference.unwrapReference(e[field]))
|
|
503
512
|
.filter(target => {
|
|
504
|
-
const wrapped =
|
|
513
|
+
const wrapped = helper(target);
|
|
505
514
|
const childFields = options.fields
|
|
506
515
|
.filter(f => f.startsWith(`${field}.`))
|
|
507
516
|
.map(f => f.substring(field.length + 1));
|
|
@@ -510,14 +519,14 @@ class EntityLoader {
|
|
|
510
519
|
}
|
|
511
520
|
return children
|
|
512
521
|
.filter(e => !e[field].__helper.__initialized)
|
|
513
|
-
.map(e =>
|
|
522
|
+
.map(e => Reference.unwrapReference(e[field]));
|
|
514
523
|
}
|
|
515
524
|
filterByReferences(entities, field, refresh) {
|
|
516
|
-
/*
|
|
525
|
+
/* v8 ignore next 3 */
|
|
517
526
|
if (refresh) {
|
|
518
527
|
return entities;
|
|
519
528
|
}
|
|
520
|
-
return entities.filter(e => !e[field]?.__helper?.__initialized);
|
|
529
|
+
return entities.filter(e => e[field] !== null && !e[field]?.__helper?.__initialized);
|
|
521
530
|
}
|
|
522
531
|
lookupAllRelationships(entityName) {
|
|
523
532
|
const ret = [];
|
|
@@ -526,7 +535,7 @@ class EntityLoader {
|
|
|
526
535
|
ret.push({
|
|
527
536
|
field: this.getRelationName(meta, prop),
|
|
528
537
|
// force select-in strategy when populating all relations as otherwise we could cause infinite loops when self-referencing
|
|
529
|
-
strategy:
|
|
538
|
+
strategy: LoadStrategy.SELECT_IN,
|
|
530
539
|
// no need to look up populate children recursively as we just pass `all: true` here
|
|
531
540
|
all: true,
|
|
532
541
|
});
|
|
@@ -569,11 +578,10 @@ class EntityLoader {
|
|
|
569
578
|
ret.push({
|
|
570
579
|
field: prefixed,
|
|
571
580
|
// enforce select-in strategy for self-referencing relations
|
|
572
|
-
strategy: selfReferencing ?
|
|
581
|
+
strategy: selfReferencing ? LoadStrategy.SELECT_IN : strategy ?? prop.strategy,
|
|
573
582
|
});
|
|
574
583
|
}
|
|
575
584
|
});
|
|
576
585
|
return ret;
|
|
577
586
|
}
|
|
578
587
|
}
|
|
579
|
-
exports.EntityLoader = EntityLoader;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { PopulatePath } from '../enums';
|
|
2
|
-
import type { CreateOptions, EntityManager, MergeOptions } from '../EntityManager';
|
|
3
|
-
import type { AssignOptions } from './EntityAssigner';
|
|
4
|
-
import type { EntityData, EntityName, Primary, Loaded, FilterQuery, EntityDictionary, AutoPath, RequiredEntityData, Ref, EntityType, EntityDTO, MergeSelected, FromEntityType, IsSubset, MergeLoaded, ArrayElement } from '../typings';
|
|
5
|
-
import type { CountOptions, DeleteOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions, GetReferenceOptions, NativeInsertUpdateOptions, UpdateOptions, UpsertManyOptions, UpsertOptions } from '../drivers/IDatabaseDriver';
|
|
6
|
-
import type { EntityLoaderOptions } from './EntityLoader';
|
|
7
|
-
import type { Cursor } from '../utils/Cursor';
|
|
1
|
+
import type { PopulatePath } from '../enums.js';
|
|
2
|
+
import type { CreateOptions, EntityManager, MergeOptions } from '../EntityManager.js';
|
|
3
|
+
import type { AssignOptions } from './EntityAssigner.js';
|
|
4
|
+
import type { EntityData, EntityName, Primary, Loaded, FilterQuery, EntityDictionary, AutoPath, RequiredEntityData, Ref, EntityType, EntityDTO, MergeSelected, FromEntityType, IsSubset, MergeLoaded, ArrayElement } from '../typings.js';
|
|
5
|
+
import type { CountOptions, DeleteOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions, GetReferenceOptions, NativeInsertUpdateOptions, UpdateOptions, UpsertManyOptions, UpsertOptions } from '../drivers/IDatabaseDriver.js';
|
|
6
|
+
import type { EntityLoaderOptions } from './EntityLoader.js';
|
|
7
|
+
import type { Cursor } from '../utils/Cursor.js';
|
|
8
8
|
export declare class EntityRepository<Entity extends object> {
|
|
9
9
|
protected readonly em: EntityManager;
|
|
10
10
|
protected readonly entityName: EntityName<Entity>;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const errors_1 = require("../errors");
|
|
5
|
-
const Utils_1 = require("../utils/Utils");
|
|
6
|
-
class EntityRepository {
|
|
1
|
+
import { ValidationError } from '../errors.js';
|
|
2
|
+
import { Utils } from '../utils/Utils.js';
|
|
3
|
+
export class EntityRepository {
|
|
7
4
|
em;
|
|
8
5
|
entityName;
|
|
9
6
|
constructor(em, entityName) {
|
|
@@ -191,7 +188,7 @@ class EntityRepository {
|
|
|
191
188
|
return this.getEntityManager().count(this.entityName, where, options);
|
|
192
189
|
}
|
|
193
190
|
getEntityName() {
|
|
194
|
-
return
|
|
191
|
+
return Utils.className(this.entityName);
|
|
195
192
|
}
|
|
196
193
|
/**
|
|
197
194
|
* Returns the underlying EntityManager instance
|
|
@@ -200,15 +197,14 @@ class EntityRepository {
|
|
|
200
197
|
return this.em;
|
|
201
198
|
}
|
|
202
199
|
validateRepositoryType(entities, method) {
|
|
203
|
-
entities =
|
|
200
|
+
entities = Utils.asArray(entities);
|
|
204
201
|
if (entities.length === 0) {
|
|
205
202
|
return;
|
|
206
203
|
}
|
|
207
204
|
const entityName = entities[0].constructor.name;
|
|
208
|
-
const repoType =
|
|
205
|
+
const repoType = Utils.className(this.entityName);
|
|
209
206
|
if (entityName && repoType !== entityName) {
|
|
210
|
-
throw
|
|
207
|
+
throw ValidationError.fromWrongRepositoryType(entityName, repoType, method);
|
|
211
208
|
}
|
|
212
209
|
}
|
|
213
210
|
}
|
|
214
|
-
exports.EntityRepository = EntityRepository;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EntityData, EntityMetadata, EntityProperty, FilterQuery } from '../typings';
|
|
1
|
+
import type { EntityData, EntityMetadata, EntityProperty, FilterQuery } from '../typings.js';
|
|
2
2
|
export declare class EntityValidator {
|
|
3
3
|
private strict;
|
|
4
4
|
KNOWN_TYPES: Set<string>;
|