@mikro-orm/core 7.0.4-dev.8 → 7.0.4
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 +884 -583
- package/EntityManager.js +1922 -1895
- package/MikroORM.d.ts +103 -74
- package/MikroORM.js +178 -179
- package/README.md +1 -1
- package/cache/CacheAdapter.d.ts +36 -36
- package/cache/FileCacheAdapter.d.ts +30 -24
- package/cache/FileCacheAdapter.js +80 -78
- package/cache/GeneratedCacheAdapter.d.ts +18 -20
- package/cache/GeneratedCacheAdapter.js +30 -30
- package/cache/MemoryCacheAdapter.d.ts +18 -20
- package/cache/MemoryCacheAdapter.js +35 -36
- package/cache/NullCacheAdapter.d.ts +16 -16
- package/cache/NullCacheAdapter.js +24 -24
- package/connections/Connection.d.ts +95 -84
- package/connections/Connection.js +165 -168
- package/drivers/DatabaseDriver.d.ts +186 -80
- package/drivers/DatabaseDriver.js +450 -443
- package/drivers/IDatabaseDriver.d.ts +440 -301
- package/entity/BaseEntity.d.ts +120 -83
- package/entity/BaseEntity.js +43 -43
- package/entity/Collection.d.ts +212 -179
- package/entity/Collection.js +727 -721
- package/entity/EntityAssigner.d.ts +88 -77
- package/entity/EntityAssigner.js +231 -230
- package/entity/EntityFactory.d.ts +66 -54
- package/entity/EntityFactory.js +425 -383
- package/entity/EntityHelper.d.ts +34 -22
- package/entity/EntityHelper.js +280 -267
- package/entity/EntityIdentifier.d.ts +4 -4
- package/entity/EntityIdentifier.js +10 -10
- package/entity/EntityLoader.d.ts +98 -72
- package/entity/EntityLoader.js +753 -723
- package/entity/EntityRepository.d.ts +316 -201
- package/entity/EntityRepository.js +213 -213
- package/entity/PolymorphicRef.d.ts +5 -5
- package/entity/PolymorphicRef.js +10 -10
- package/entity/Reference.d.ts +126 -82
- package/entity/Reference.js +278 -274
- package/entity/WrappedEntity.d.ts +115 -72
- package/entity/WrappedEntity.js +168 -166
- package/entity/defineEntity.d.ts +1315 -636
- package/entity/defineEntity.js +527 -518
- package/entity/utils.d.ts +13 -3
- package/entity/utils.js +71 -73
- package/entity/validators.js +43 -43
- package/entity/wrap.js +8 -8
- package/enums.d.ts +258 -253
- package/enums.js +251 -252
- package/errors.d.ts +114 -72
- package/errors.js +350 -253
- package/events/EventManager.d.ts +26 -14
- package/events/EventManager.js +79 -77
- package/events/EventSubscriber.d.ts +29 -29
- package/events/TransactionEventBroadcaster.d.ts +15 -8
- package/events/TransactionEventBroadcaster.js +14 -14
- package/exceptions.d.ts +23 -40
- package/exceptions.js +35 -52
- package/hydration/Hydrator.d.ts +42 -17
- package/hydration/Hydrator.js +43 -43
- package/hydration/ObjectHydrator.d.ts +50 -17
- package/hydration/ObjectHydrator.js +481 -416
- package/index.d.ts +116 -2
- package/index.js +10 -1
- package/logging/DefaultLogger.d.ts +34 -32
- package/logging/DefaultLogger.js +86 -86
- package/logging/Logger.d.ts +41 -41
- package/logging/SimpleLogger.d.ts +13 -11
- package/logging/SimpleLogger.js +22 -22
- package/logging/colors.d.ts +6 -6
- package/logging/colors.js +11 -10
- package/logging/inspect.js +7 -7
- package/metadata/EntitySchema.d.ts +211 -127
- package/metadata/EntitySchema.js +397 -398
- package/metadata/MetadataDiscovery.d.ts +114 -114
- package/metadata/MetadataDiscovery.js +1951 -1863
- package/metadata/MetadataProvider.d.ts +24 -21
- package/metadata/MetadataProvider.js +82 -84
- package/metadata/MetadataStorage.d.ts +38 -32
- package/metadata/MetadataStorage.js +118 -118
- package/metadata/MetadataValidator.d.ts +39 -39
- package/metadata/MetadataValidator.js +381 -338
- package/metadata/discover-entities.d.ts +5 -2
- package/metadata/discover-entities.js +35 -27
- package/metadata/types.d.ts +615 -531
- package/naming-strategy/AbstractNamingStrategy.d.ts +54 -39
- package/naming-strategy/AbstractNamingStrategy.js +90 -85
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
- package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
- package/naming-strategy/MongoNamingStrategy.d.ts +6 -6
- package/naming-strategy/MongoNamingStrategy.js +18 -18
- package/naming-strategy/NamingStrategy.d.ts +109 -99
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
- package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
- package/not-supported.js +7 -4
- package/package.json +1 -1
- package/platforms/ExceptionConverter.d.ts +1 -1
- package/platforms/ExceptionConverter.js +4 -4
- package/platforms/Platform.d.ts +310 -299
- package/platforms/Platform.js +663 -636
- package/serialization/EntitySerializer.d.ts +49 -26
- package/serialization/EntitySerializer.js +224 -218
- package/serialization/EntityTransformer.d.ts +10 -6
- package/serialization/EntityTransformer.js +219 -217
- package/serialization/SerializationContext.d.ts +27 -23
- package/serialization/SerializationContext.js +105 -105
- package/types/ArrayType.d.ts +8 -8
- package/types/ArrayType.js +33 -33
- package/types/BigIntType.d.ts +17 -10
- package/types/BigIntType.js +37 -37
- package/types/BlobType.d.ts +3 -3
- package/types/BlobType.js +13 -13
- package/types/BooleanType.d.ts +4 -4
- package/types/BooleanType.js +12 -12
- package/types/CharacterType.d.ts +2 -2
- package/types/CharacterType.js +6 -6
- package/types/DateTimeType.d.ts +5 -5
- package/types/DateTimeType.js +15 -15
- package/types/DateType.d.ts +5 -5
- package/types/DateType.js +15 -15
- package/types/DecimalType.d.ts +7 -7
- package/types/DecimalType.js +26 -26
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +12 -12
- package/types/EnumArrayType.d.ts +5 -5
- package/types/EnumArrayType.js +24 -24
- package/types/EnumType.d.ts +3 -3
- package/types/EnumType.js +11 -11
- package/types/FloatType.d.ts +3 -3
- package/types/FloatType.js +9 -9
- package/types/IntegerType.d.ts +3 -3
- package/types/IntegerType.js +9 -9
- package/types/IntervalType.d.ts +4 -4
- package/types/IntervalType.js +12 -12
- package/types/JsonType.d.ts +8 -8
- package/types/JsonType.js +32 -32
- package/types/MediumIntType.d.ts +1 -1
- package/types/MediumIntType.js +3 -3
- package/types/SmallIntType.d.ts +3 -3
- package/types/SmallIntType.js +9 -9
- package/types/StringType.d.ts +4 -4
- package/types/StringType.js +12 -12
- package/types/TextType.d.ts +3 -3
- package/types/TextType.js +9 -9
- package/types/TimeType.d.ts +5 -5
- package/types/TimeType.js +17 -17
- package/types/TinyIntType.d.ts +3 -3
- package/types/TinyIntType.js +10 -10
- package/types/Type.d.ts +83 -79
- package/types/Type.js +82 -82
- package/types/Uint8ArrayType.d.ts +4 -4
- package/types/Uint8ArrayType.js +21 -21
- package/types/UnknownType.d.ts +4 -4
- package/types/UnknownType.js +12 -12
- package/types/UuidType.d.ts +5 -5
- package/types/UuidType.js +19 -19
- package/types/index.d.ts +75 -49
- package/types/index.js +52 -26
- package/typings.d.ts +1250 -737
- package/typings.js +244 -231
- package/unit-of-work/ChangeSet.d.ts +26 -26
- package/unit-of-work/ChangeSet.js +56 -56
- package/unit-of-work/ChangeSetComputer.d.ts +12 -12
- package/unit-of-work/ChangeSetComputer.js +178 -170
- package/unit-of-work/ChangeSetPersister.d.ts +63 -44
- package/unit-of-work/ChangeSetPersister.js +442 -421
- package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
- package/unit-of-work/CommitOrderCalculator.js +89 -88
- package/unit-of-work/IdentityMap.d.ts +31 -31
- package/unit-of-work/IdentityMap.js +105 -105
- package/unit-of-work/UnitOfWork.d.ts +181 -141
- package/unit-of-work/UnitOfWork.js +1200 -1183
- package/utils/AbstractMigrator.d.ts +111 -91
- package/utils/AbstractMigrator.js +275 -275
- package/utils/AbstractSchemaGenerator.d.ts +43 -34
- package/utils/AbstractSchemaGenerator.js +121 -122
- package/utils/AsyncContext.d.ts +3 -3
- package/utils/AsyncContext.js +34 -35
- package/utils/Configuration.d.ts +852 -808
- package/utils/Configuration.js +359 -344
- package/utils/Cursor.d.ts +40 -22
- package/utils/Cursor.js +135 -127
- package/utils/DataloaderUtils.d.ts +58 -43
- package/utils/DataloaderUtils.js +203 -198
- package/utils/EntityComparator.d.ts +98 -81
- package/utils/EntityComparator.js +828 -728
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +3 -3
- package/utils/QueryHelper.d.ts +79 -51
- package/utils/QueryHelper.js +372 -361
- package/utils/RawQueryFragment.d.ts +50 -34
- package/utils/RawQueryFragment.js +107 -105
- package/utils/RequestContext.d.ts +32 -32
- package/utils/RequestContext.js +52 -53
- package/utils/TransactionContext.d.ts +16 -16
- package/utils/TransactionContext.js +27 -27
- package/utils/TransactionManager.d.ts +58 -58
- package/utils/TransactionManager.js +199 -197
- package/utils/Utils.d.ts +204 -145
- package/utils/Utils.js +812 -810
- package/utils/clone.js +104 -113
- package/utils/env-vars.js +90 -88
- package/utils/fs-utils.d.ts +15 -15
- package/utils/fs-utils.js +180 -181
- package/utils/upsert-utils.d.ts +20 -5
- package/utils/upsert-utils.js +114 -116
package/typings.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReferenceKind
|
|
1
|
+
import { ReferenceKind } from './enums.js';
|
|
2
2
|
import { Reference } from './entity/Reference.js';
|
|
3
3
|
import { EntityHelper } from './entity/EntityHelper.js';
|
|
4
4
|
import { helper } from './entity/wrap.js';
|
|
@@ -25,250 +25,263 @@ export const EntityName = Symbol('EntityName');
|
|
|
25
25
|
* Created during metadata discovery and used throughout the ORM lifecycle.
|
|
26
26
|
*/
|
|
27
27
|
export class EntityMetadata {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this.class = Class;
|
|
49
|
-
}
|
|
28
|
+
static counter = 0;
|
|
29
|
+
_id = 1000 * EntityMetadata.counter++; // keep the id >= 1000 to allow computing cache keys by simple addition
|
|
30
|
+
propertyOrder = new Map();
|
|
31
|
+
constructor(meta = {}) {
|
|
32
|
+
this.properties = {};
|
|
33
|
+
this.props = [];
|
|
34
|
+
this.primaryKeys = [];
|
|
35
|
+
this.filters = {};
|
|
36
|
+
this.hooks = {};
|
|
37
|
+
this.indexes = [];
|
|
38
|
+
this.uniques = [];
|
|
39
|
+
this.checks = [];
|
|
40
|
+
this.referencingProperties = [];
|
|
41
|
+
this.concurrencyCheckKeys = new Set();
|
|
42
|
+
Object.assign(this, meta);
|
|
43
|
+
const name = meta.className ?? meta.name;
|
|
44
|
+
if (!this.class && name) {
|
|
45
|
+
const Class =
|
|
46
|
+
this.extends === BaseEntity ? { [name]: class extends BaseEntity {} }[name] : { [name]: class {} }[name];
|
|
47
|
+
this.class = Class;
|
|
50
48
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
}
|
|
50
|
+
addProperty(prop) {
|
|
51
|
+
this.properties[prop.name] = prop;
|
|
52
|
+
this.propertyOrder.set(prop.name, this.props.length);
|
|
53
|
+
this.sync();
|
|
54
|
+
}
|
|
55
|
+
removeProperty(name, sync = true) {
|
|
56
|
+
delete this.properties[name];
|
|
57
|
+
this.propertyOrder.delete(name);
|
|
58
|
+
if (sync) {
|
|
59
|
+
this.sync();
|
|
55
60
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
}
|
|
62
|
+
getPrimaryProps(flatten = false) {
|
|
63
|
+
const pks = this.primaryKeys.map(pk => this.properties[pk]);
|
|
64
|
+
if (flatten) {
|
|
65
|
+
return pks.flatMap(pk => {
|
|
66
|
+
if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(pk.kind)) {
|
|
67
|
+
return pk.targetMeta.getPrimaryProps(true);
|
|
61
68
|
}
|
|
69
|
+
return [pk];
|
|
70
|
+
});
|
|
62
71
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
return pks;
|
|
73
|
+
}
|
|
74
|
+
getPrimaryProp() {
|
|
75
|
+
return this.properties[this.primaryKeys[0]];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Creates a mapping from property names to field names.
|
|
79
|
+
* @param alias - Optional alias to prefix field names. Can be a string (same for all) or a function (per-property).
|
|
80
|
+
* When provided, also adds toString() returning the alias for backwards compatibility with formulas.
|
|
81
|
+
* @param toStringAlias - Optional alias to return from toString(). Defaults to `alias` when it's a string.
|
|
82
|
+
*/
|
|
83
|
+
createColumnMappingObject(alias, toStringAlias) {
|
|
84
|
+
const resolveAlias = typeof alias === 'function' ? alias : () => alias;
|
|
85
|
+
const defaultAlias = toStringAlias ?? (typeof alias === 'string' ? alias : undefined);
|
|
86
|
+
const result = Object.values(this.properties).reduce((o, prop) => {
|
|
87
|
+
if (prop.fieldNames) {
|
|
88
|
+
const propAlias = resolveAlias(prop);
|
|
89
|
+
o[prop.name] = propAlias ? `${propAlias}.${prop.fieldNames[0]}` : prop.fieldNames[0];
|
|
90
|
+
}
|
|
91
|
+
return o;
|
|
92
|
+
}, {});
|
|
93
|
+
// Add toString() for backwards compatibility when alias is provided
|
|
94
|
+
Object.defineProperty(result, 'toString', {
|
|
95
|
+
value: () => defaultAlias ?? '',
|
|
96
|
+
enumerable: false,
|
|
97
|
+
});
|
|
98
|
+
// Wrap in Proxy to detect old formula signature usage where the first param was FormulaTable.
|
|
99
|
+
// If user accesses `.alias` or `.qualifiedName` (FormulaTable-only properties), warn them.
|
|
100
|
+
const warnedProps = new Set(['alias', 'qualifiedName']);
|
|
101
|
+
return new Proxy(result, {
|
|
102
|
+
get(target, prop, receiver) {
|
|
103
|
+
if (typeof prop === 'string' && warnedProps.has(prop) && !(prop in target)) {
|
|
104
|
+
// eslint-disable-next-line no-console
|
|
105
|
+
console.warn(
|
|
106
|
+
`[MikroORM] Detected old formula callback signature. The first parameter is now 'columns', not 'table'. ` +
|
|
107
|
+
`Accessing '.${prop}' on the columns object will return undefined. ` +
|
|
108
|
+
`Update your formula: formula(cols => quote\`\${cols.propName} ...\`). See the v7 upgrade guide.`,
|
|
109
|
+
);
|
|
72
110
|
}
|
|
73
|
-
return
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
111
|
+
return Reflect.get(target, prop, receiver);
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Creates a column mapping for schema callbacks (indexes, checks, generated columns).
|
|
117
|
+
* For TPT entities, only includes properties that belong to the current table (ownProps).
|
|
118
|
+
*/
|
|
119
|
+
createSchemaColumnMappingObject() {
|
|
120
|
+
// For TPT entities, only include properties that belong to this entity's table
|
|
121
|
+
const props = this.inheritanceType === 'tpt' && this.ownProps ? this.ownProps : Object.values(this.properties);
|
|
122
|
+
return props.reduce((o, prop) => {
|
|
123
|
+
if (prop.fieldNames) {
|
|
124
|
+
o[prop.name] = prop.fieldNames[0];
|
|
125
|
+
}
|
|
126
|
+
return o;
|
|
127
|
+
}, {});
|
|
128
|
+
}
|
|
129
|
+
get tableName() {
|
|
130
|
+
return this.collection;
|
|
131
|
+
}
|
|
132
|
+
set tableName(name) {
|
|
133
|
+
this.collection = name;
|
|
134
|
+
}
|
|
135
|
+
get uniqueName() {
|
|
136
|
+
return this.tableName + '_' + this._id;
|
|
137
|
+
}
|
|
138
|
+
sync(initIndexes = false, config) {
|
|
139
|
+
this.root ??= this;
|
|
140
|
+
const props = Object.values(this.properties).sort(
|
|
141
|
+
(a, b) => this.propertyOrder.get(a.name) - this.propertyOrder.get(b.name),
|
|
142
|
+
);
|
|
143
|
+
this.props = [...props.filter(p => p.primary), ...props.filter(p => !p.primary)];
|
|
144
|
+
this.relations = this.props.filter(
|
|
145
|
+
prop =>
|
|
146
|
+
typeof prop.kind !== 'undefined' && prop.kind !== ReferenceKind.SCALAR && prop.kind !== ReferenceKind.EMBEDDED,
|
|
147
|
+
);
|
|
148
|
+
this.bidirectionalRelations = this.relations.filter(prop => prop.mappedBy || prop.inversedBy);
|
|
149
|
+
this.uniqueProps = this.props.filter(prop => prop.unique);
|
|
150
|
+
this.getterProps = this.props.filter(prop => prop.getter);
|
|
151
|
+
this.comparableProps = this.props.filter(prop => EntityComparator.isComparable(prop, this));
|
|
152
|
+
this.validateProps = this.props.filter(prop => {
|
|
153
|
+
if (prop.inherited || (prop.persist === false && prop.userDefined !== false)) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
return prop.kind === ReferenceKind.SCALAR && ['string', 'number', 'boolean', 'Date'].includes(prop.type);
|
|
157
|
+
});
|
|
158
|
+
this.hydrateProps = this.props.filter(prop => {
|
|
159
|
+
// `prop.userDefined` is either `undefined` or `false`
|
|
160
|
+
const discriminator = this.root.discriminatorColumn === prop.name && prop.userDefined === false;
|
|
161
|
+
// even if we don't have a setter, do not ignore value from database!
|
|
162
|
+
const onlyGetter = prop.getter && !prop.setter && prop.persist === false;
|
|
163
|
+
return !prop.inherited && prop.hydrate !== false && !discriminator && !prop.embedded && !onlyGetter;
|
|
164
|
+
});
|
|
165
|
+
this.trackingProps = this.hydrateProps.filter(prop => {
|
|
166
|
+
return !prop.getter && !prop.setter && [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind);
|
|
167
|
+
});
|
|
168
|
+
this.selfReferencing = this.relations.some(prop => {
|
|
169
|
+
return this.root.uniqueName === prop.targetMeta?.root.uniqueName;
|
|
170
|
+
});
|
|
171
|
+
this.hasUniqueProps = this.uniques.length + this.uniqueProps.length > 0;
|
|
172
|
+
// Normalize object-form `view` option: `view: { materialized: true, withData: false }`
|
|
173
|
+
// into flat metadata fields (`view: true`, `materialized: true`, `withData: false`).
|
|
174
|
+
if (typeof this.view === 'object') {
|
|
175
|
+
this.materialized = this.view.materialized;
|
|
176
|
+
this.withData = this.view.withData;
|
|
177
|
+
this.view = true;
|
|
77
178
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
value: () => defaultAlias ?? '',
|
|
97
|
-
enumerable: false,
|
|
98
|
-
});
|
|
99
|
-
// Wrap in Proxy to detect old formula signature usage where the first param was FormulaTable.
|
|
100
|
-
// If user accesses `.alias` or `.qualifiedName` (FormulaTable-only properties), warn them.
|
|
101
|
-
const warnedProps = new Set(['alias', 'qualifiedName']);
|
|
102
|
-
return new Proxy(result, {
|
|
103
|
-
get(target, prop, receiver) {
|
|
104
|
-
if (typeof prop === 'string' && warnedProps.has(prop) && !(prop in target)) {
|
|
105
|
-
// eslint-disable-next-line no-console
|
|
106
|
-
console.warn(`[MikroORM] Detected old formula callback signature. The first parameter is now 'columns', not 'table'. ` +
|
|
107
|
-
`Accessing '.${prop}' on the columns object will return undefined. ` +
|
|
108
|
-
`Update your formula: formula(cols => quote\`\${cols.propName} ...\`). See the v7 upgrade guide.`);
|
|
109
|
-
}
|
|
110
|
-
return Reflect.get(target, prop, receiver);
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Creates a column mapping for schema callbacks (indexes, checks, generated columns).
|
|
116
|
-
* For TPT entities, only includes properties that belong to the current table (ownProps).
|
|
117
|
-
*/
|
|
118
|
-
createSchemaColumnMappingObject() {
|
|
119
|
-
// For TPT entities, only include properties that belong to this entity's table
|
|
120
|
-
const props = this.inheritanceType === 'tpt' && this.ownProps ? this.ownProps : Object.values(this.properties);
|
|
121
|
-
return props.reduce((o, prop) => {
|
|
122
|
-
if (prop.fieldNames) {
|
|
123
|
-
o[prop.name] = prop.fieldNames[0];
|
|
124
|
-
}
|
|
125
|
-
return o;
|
|
126
|
-
}, {});
|
|
179
|
+
// If `view` is set, this is a database view entity (not a virtual entity).
|
|
180
|
+
// Virtual entities evaluate expressions at query time, view entities create actual database views.
|
|
181
|
+
this.virtual = !!this.expression && !this.view;
|
|
182
|
+
if (config) {
|
|
183
|
+
for (const prop of this.props) {
|
|
184
|
+
if (prop.enum && !prop.nativeEnumName && prop.items?.every(item => typeof item === 'string')) {
|
|
185
|
+
const name = config.getNamingStrategy().indexName(this.tableName, prop.fieldNames, 'check');
|
|
186
|
+
const exists = this.checks.findIndex(check => check.name === name);
|
|
187
|
+
if (exists !== -1) {
|
|
188
|
+
this.checks.splice(exists, 1);
|
|
189
|
+
}
|
|
190
|
+
this.checks.push({
|
|
191
|
+
name,
|
|
192
|
+
property: prop.name,
|
|
193
|
+
expression: `${config.getPlatform().quoteIdentifier(prop.fieldNames[0])} in ('${prop.items.join("', '")}')`,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
127
197
|
}
|
|
128
|
-
|
|
129
|
-
|
|
198
|
+
this.checks = Utils.removeDuplicates(this.checks);
|
|
199
|
+
this.indexes = Utils.removeDuplicates(this.indexes);
|
|
200
|
+
this.uniques = Utils.removeDuplicates(this.uniques);
|
|
201
|
+
for (const hook of Utils.keys(this.hooks)) {
|
|
202
|
+
this.hooks[hook] = Utils.removeDuplicates(this.hooks[hook]);
|
|
130
203
|
}
|
|
131
|
-
|
|
132
|
-
|
|
204
|
+
if (this.virtual || this.view) {
|
|
205
|
+
this.readonly = true;
|
|
133
206
|
}
|
|
134
|
-
|
|
135
|
-
|
|
207
|
+
if (initIndexes && this.name) {
|
|
208
|
+
this.props.forEach(prop => this.initIndexes(prop));
|
|
136
209
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
// into flat metadata fields (`view: true`, `materialized: true`, `withData: false`).
|
|
168
|
-
if (typeof this.view === 'object') {
|
|
169
|
-
this.materialized = this.view.materialized;
|
|
170
|
-
this.withData = this.view.withData;
|
|
171
|
-
this.view = true;
|
|
172
|
-
}
|
|
173
|
-
// If `view` is set, this is a database view entity (not a virtual entity).
|
|
174
|
-
// Virtual entities evaluate expressions at query time, view entities create actual database views.
|
|
175
|
-
this.virtual = !!this.expression && !this.view;
|
|
176
|
-
if (config) {
|
|
177
|
-
for (const prop of this.props) {
|
|
178
|
-
if (prop.enum && !prop.nativeEnumName && prop.items?.every(item => typeof item === 'string')) {
|
|
179
|
-
const name = config.getNamingStrategy().indexName(this.tableName, prop.fieldNames, 'check');
|
|
180
|
-
const exists = this.checks.findIndex(check => check.name === name);
|
|
181
|
-
if (exists !== -1) {
|
|
182
|
-
this.checks.splice(exists, 1);
|
|
183
|
-
}
|
|
184
|
-
this.checks.push({
|
|
185
|
-
name,
|
|
186
|
-
property: prop.name,
|
|
187
|
-
expression: `${config.getPlatform().quoteIdentifier(prop.fieldNames[0])} in ('${prop.items.join("', '")}')`,
|
|
188
|
-
});
|
|
210
|
+
this.definedProperties = this.trackingProps.reduce(
|
|
211
|
+
(o, prop) => {
|
|
212
|
+
const hasInverse = (prop.inversedBy || prop.mappedBy) && !prop.mapToPk;
|
|
213
|
+
if (hasInverse) {
|
|
214
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
215
|
+
const meta = this;
|
|
216
|
+
o[prop.name] = {
|
|
217
|
+
get() {
|
|
218
|
+
return this.__helper.__data[prop.name];
|
|
219
|
+
},
|
|
220
|
+
set(val) {
|
|
221
|
+
const wrapped = this.__helper;
|
|
222
|
+
const hydrator = wrapped.hydrator;
|
|
223
|
+
const entity = Reference.unwrapReference(val ?? wrapped.__data[prop.name]);
|
|
224
|
+
const old = Reference.unwrapReference(wrapped.__data[prop.name]);
|
|
225
|
+
if (
|
|
226
|
+
old &&
|
|
227
|
+
old !== entity &&
|
|
228
|
+
prop.kind === ReferenceKind.MANY_TO_ONE &&
|
|
229
|
+
prop.inversedBy &&
|
|
230
|
+
old[prop.inversedBy]
|
|
231
|
+
) {
|
|
232
|
+
old[prop.inversedBy].removeWithoutPropagation(this);
|
|
233
|
+
}
|
|
234
|
+
wrapped.__data[prop.name] = Reference.wrapReference(val, prop);
|
|
235
|
+
// when propagation from inside hydration, we set the FK to the entity data immediately
|
|
236
|
+
if (val && hydrator.isRunning() && wrapped.__originalEntityData && prop.owner) {
|
|
237
|
+
const targetMeta = prop.targetMeta ?? helper(entity)?.__meta;
|
|
238
|
+
if (targetMeta) {
|
|
239
|
+
wrapped.__originalEntityData[prop.name] = Utils.getPrimaryKeyValues(val, targetMeta, true);
|
|
189
240
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
this.hooks[hook] = Utils.removeDuplicates(this.hooks[hook]);
|
|
197
|
-
}
|
|
198
|
-
if (this.virtual || this.view) {
|
|
199
|
-
this.readonly = true;
|
|
200
|
-
}
|
|
201
|
-
if (initIndexes && this.name) {
|
|
202
|
-
this.props.forEach(prop => this.initIndexes(prop));
|
|
241
|
+
}
|
|
242
|
+
EntityHelper.propagate(meta, entity, this, prop, Reference.unwrapReference(val), old);
|
|
243
|
+
},
|
|
244
|
+
enumerable: true,
|
|
245
|
+
configurable: true,
|
|
246
|
+
};
|
|
203
247
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
old !== entity &&
|
|
220
|
-
prop.kind === ReferenceKind.MANY_TO_ONE &&
|
|
221
|
-
prop.inversedBy &&
|
|
222
|
-
old[prop.inversedBy]) {
|
|
223
|
-
old[prop.inversedBy].removeWithoutPropagation(this);
|
|
224
|
-
}
|
|
225
|
-
wrapped.__data[prop.name] = Reference.wrapReference(val, prop);
|
|
226
|
-
// when propagation from inside hydration, we set the FK to the entity data immediately
|
|
227
|
-
if (val && hydrator.isRunning() && wrapped.__originalEntityData && prop.owner) {
|
|
228
|
-
const targetMeta = prop.targetMeta ?? helper(entity)?.__meta;
|
|
229
|
-
if (targetMeta) {
|
|
230
|
-
wrapped.__originalEntityData[prop.name] = Utils.getPrimaryKeyValues(val, targetMeta, true);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
EntityHelper.propagate(meta, entity, this, prop, Reference.unwrapReference(val), old);
|
|
234
|
-
},
|
|
235
|
-
enumerable: true,
|
|
236
|
-
configurable: true,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
return o;
|
|
240
|
-
}, { __gettersDefined: { value: true, enumerable: false } });
|
|
248
|
+
return o;
|
|
249
|
+
},
|
|
250
|
+
{ __gettersDefined: { value: true, enumerable: false } },
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
initIndexes(prop) {
|
|
254
|
+
const simpleIndex = this.indexes.find(
|
|
255
|
+
index => index.properties === prop.name && !index.options && !index.type && !index.expression,
|
|
256
|
+
);
|
|
257
|
+
const simpleUnique = this.uniques.find(index => index.properties === prop.name && !index.options);
|
|
258
|
+
const owner = prop.kind === ReferenceKind.MANY_TO_ONE;
|
|
259
|
+
if (!prop.index && simpleIndex) {
|
|
260
|
+
Utils.defaultValue(simpleIndex, 'name', true);
|
|
261
|
+
prop.index = simpleIndex.name;
|
|
262
|
+
this.indexes.splice(this.indexes.indexOf(simpleIndex), 1);
|
|
241
263
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (!prop.index && simpleIndex) {
|
|
247
|
-
Utils.defaultValue(simpleIndex, 'name', true);
|
|
248
|
-
prop.index = simpleIndex.name;
|
|
249
|
-
this.indexes.splice(this.indexes.indexOf(simpleIndex), 1);
|
|
250
|
-
}
|
|
251
|
-
if (!prop.unique && simpleUnique) {
|
|
252
|
-
Utils.defaultValue(simpleUnique, 'name', true);
|
|
253
|
-
prop.unique = simpleUnique.name;
|
|
254
|
-
this.uniques.splice(this.uniques.indexOf(simpleUnique), 1);
|
|
255
|
-
}
|
|
256
|
-
if (prop.index && owner && prop.fieldNames.length > 1) {
|
|
257
|
-
this.indexes.push({ properties: prop.name });
|
|
258
|
-
prop.index = false;
|
|
259
|
-
}
|
|
260
|
-
/* v8 ignore next */
|
|
261
|
-
if (owner && prop.fieldNames.length > 1 && prop.unique) {
|
|
262
|
-
this.uniques.push({ properties: prop.name });
|
|
263
|
-
prop.unique = false;
|
|
264
|
-
}
|
|
264
|
+
if (!prop.unique && simpleUnique) {
|
|
265
|
+
Utils.defaultValue(simpleUnique, 'name', true);
|
|
266
|
+
prop.unique = simpleUnique.name;
|
|
267
|
+
this.uniques.splice(this.uniques.indexOf(simpleUnique), 1);
|
|
265
268
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
+
if (prop.index && owner && prop.fieldNames.length > 1) {
|
|
270
|
+
this.indexes.push({ properties: prop.name });
|
|
271
|
+
prop.index = false;
|
|
269
272
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
+
/* v8 ignore next */
|
|
274
|
+
if (owner && prop.fieldNames.length > 1 && prop.unique) {
|
|
275
|
+
this.uniques.push({ properties: prop.name });
|
|
276
|
+
prop.unique = false;
|
|
273
277
|
}
|
|
278
|
+
}
|
|
279
|
+
/** @internal */
|
|
280
|
+
clone() {
|
|
281
|
+
return this;
|
|
282
|
+
}
|
|
283
|
+
/** @ignore */
|
|
284
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
285
|
+
return `[${this.constructor.name}<${this.className}>]`;
|
|
286
|
+
}
|
|
274
287
|
}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
import type { EntityData, EntityMetadata, EntityDictionary, Primary } from '../typings.js';
|
|
2
2
|
/** Represents a pending change (create, update, or delete) for a single entity. */
|
|
3
3
|
export declare class ChangeSet<T extends object> {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
entity: T;
|
|
5
|
+
type: ChangeSetType;
|
|
6
|
+
payload: EntityDictionary<T>;
|
|
7
|
+
meta: EntityMetadata<T>;
|
|
8
|
+
private primaryKey?;
|
|
9
|
+
private serializedPrimaryKey?;
|
|
10
|
+
constructor(entity: T, type: ChangeSetType, payload: EntityDictionary<T>, meta: EntityMetadata<T>);
|
|
11
|
+
/** Returns the primary key of the entity, optionally as an object for composite keys. */
|
|
12
|
+
getPrimaryKey(object?: boolean): Primary<T> | null;
|
|
13
|
+
/** Returns the serialized (string) form of the primary key. */
|
|
14
|
+
getSerializedPrimaryKey(): string | null;
|
|
15
15
|
}
|
|
16
16
|
export interface ChangeSet<T> {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
meta: EntityMetadata<T>;
|
|
18
|
+
rootMeta: EntityMetadata<T>;
|
|
19
|
+
schema?: string;
|
|
20
|
+
type: ChangeSetType;
|
|
21
|
+
entity: T;
|
|
22
|
+
payload: EntityDictionary<T>;
|
|
23
|
+
persisted: boolean;
|
|
24
|
+
originalEntity?: EntityData<T>;
|
|
25
|
+
/** For TPT: changesets for parent tables, ordered from immediate parent to root */
|
|
26
|
+
tptChangeSets?: ChangeSet<T>[];
|
|
27
27
|
}
|
|
28
28
|
/** Enumeration of change set operation types. */
|
|
29
29
|
export declare enum ChangeSetType {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
CREATE = 'create',
|
|
31
|
+
UPDATE = 'update',
|
|
32
|
+
DELETE = 'delete',
|
|
33
|
+
UPDATE_EARLY = 'update_early',
|
|
34
|
+
DELETE_EARLY = 'delete_early',
|
|
35
35
|
}
|