@mikro-orm/core 7.0.0-dev.32 → 7.0.0-dev.321
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 +71 -63
- package/EntityManager.js +365 -283
- package/MikroORM.d.ts +44 -35
- package/MikroORM.js +109 -142
- package/README.md +7 -4
- package/cache/FileCacheAdapter.d.ts +1 -2
- package/cache/FileCacheAdapter.js +19 -14
- package/cache/GeneratedCacheAdapter.d.ts +0 -1
- package/cache/GeneratedCacheAdapter.js +0 -2
- package/cache/index.d.ts +1 -2
- package/cache/index.js +0 -2
- package/connections/Connection.d.ts +12 -5
- package/connections/Connection.js +37 -15
- package/drivers/DatabaseDriver.d.ts +25 -18
- package/drivers/DatabaseDriver.js +144 -45
- package/drivers/IDatabaseDriver.d.ts +118 -23
- package/entity/BaseEntity.d.ts +63 -4
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +101 -29
- package/entity/Collection.js +473 -115
- package/entity/EntityAssigner.js +37 -25
- package/entity/EntityFactory.d.ts +7 -1
- package/entity/EntityFactory.js +116 -64
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +69 -27
- package/entity/EntityLoader.d.ts +11 -10
- package/entity/EntityLoader.js +264 -102
- package/entity/EntityRepository.d.ts +28 -8
- package/entity/EntityRepository.js +8 -2
- package/entity/PolymorphicRef.d.ts +12 -0
- package/entity/PolymorphicRef.js +18 -0
- package/entity/Reference.d.ts +2 -6
- package/entity/Reference.js +52 -19
- package/entity/WrappedEntity.d.ts +3 -8
- package/entity/WrappedEntity.js +6 -7
- package/entity/defineEntity.d.ts +525 -311
- package/entity/defineEntity.js +134 -290
- package/entity/index.d.ts +2 -2
- package/entity/index.js +2 -2
- package/entity/utils.d.ts +6 -1
- package/entity/utils.js +46 -11
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +66 -0
- package/enums.d.ts +8 -6
- package/enums.js +13 -17
- package/errors.d.ts +20 -10
- package/errors.js +63 -31
- package/events/EventManager.d.ts +2 -1
- package/events/EventManager.js +24 -13
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/exceptions.js +9 -2
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +4 -4
- package/hydration/ObjectHydrator.js +105 -46
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +3 -4
- package/logging/SimpleLogger.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +5 -7
- package/logging/index.d.ts +2 -1
- package/logging/index.js +1 -1
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +11 -0
- package/metadata/EntitySchema.d.ts +47 -23
- package/metadata/EntitySchema.js +103 -34
- package/metadata/MetadataDiscovery.d.ts +64 -9
- package/metadata/MetadataDiscovery.js +867 -354
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +71 -2
- package/metadata/MetadataStorage.d.ts +13 -11
- package/metadata/MetadataStorage.js +72 -41
- package/metadata/MetadataValidator.d.ts +32 -9
- package/metadata/MetadataValidator.js +214 -44
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/metadata/types.d.ts +577 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
- package/naming-strategy/AbstractNamingStrategy.js +26 -5
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
- package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
- package/naming-strategy/MongoNamingStrategy.js +6 -6
- package/naming-strategy/NamingStrategy.d.ts +28 -4
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/not-supported.d.ts +2 -0
- package/not-supported.js +8 -0
- package/package.json +47 -36
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +33 -15
- package/platforms/Platform.js +125 -69
- package/serialization/EntitySerializer.d.ts +6 -3
- package/serialization/EntitySerializer.js +53 -29
- package/serialization/EntityTransformer.js +33 -21
- package/serialization/SerializationContext.d.ts +6 -6
- package/serialization/SerializationContext.js +4 -4
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.js +1 -1
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +1 -0
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.js +2 -2
- package/types/DoubleType.js +1 -1
- package/types/EnumArrayType.js +1 -2
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/TinyIntType.js +1 -1
- package/types/Type.d.ts +2 -4
- package/types/Type.js +3 -3
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +1 -4
- package/types/UuidType.d.ts +2 -0
- package/types/UuidType.js +14 -2
- package/types/index.d.ts +3 -2
- package/typings.d.ts +427 -170
- package/typings.js +100 -45
- package/unit-of-work/ChangeSet.d.ts +4 -6
- package/unit-of-work/ChangeSet.js +8 -9
- package/unit-of-work/ChangeSetComputer.d.ts +3 -8
- package/unit-of-work/ChangeSetComputer.js +49 -26
- package/unit-of-work/ChangeSetPersister.d.ts +13 -12
- package/unit-of-work/ChangeSetPersister.js +107 -44
- package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
- package/unit-of-work/CommitOrderCalculator.js +17 -15
- package/unit-of-work/IdentityMap.d.ts +12 -0
- package/unit-of-work/IdentityMap.js +39 -1
- package/unit-of-work/UnitOfWork.d.ts +34 -4
- package/unit-of-work/UnitOfWork.js +294 -107
- package/utils/AbstractMigrator.d.ts +101 -0
- package/utils/AbstractMigrator.js +303 -0
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +30 -18
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +796 -211
- package/utils/Configuration.js +160 -197
- package/utils/ConfigurationLoader.d.ts +1 -52
- package/utils/ConfigurationLoader.js +1 -330
- package/utils/Cursor.d.ts +0 -3
- package/utils/Cursor.js +29 -14
- package/utils/DataloaderUtils.d.ts +10 -5
- package/utils/DataloaderUtils.js +42 -22
- package/utils/EntityComparator.d.ts +16 -9
- package/utils/EntityComparator.js +202 -96
- package/utils/QueryHelper.d.ts +34 -7
- package/utils/QueryHelper.js +183 -72
- package/utils/RawQueryFragment.d.ts +28 -34
- package/utils/RawQueryFragment.js +37 -72
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.js +11 -7
- package/utils/Utils.d.ts +16 -127
- package/utils/Utils.js +106 -401
- package/utils/clone.js +13 -23
- package/utils/env-vars.d.ts +7 -0
- package/utils/env-vars.js +98 -0
- package/utils/fs-utils.d.ts +34 -0
- package/utils/fs-utils.js +193 -0
- package/utils/index.d.ts +1 -3
- package/utils/index.js +1 -3
- package/utils/upsert-utils.d.ts +9 -4
- package/utils/upsert-utils.js +51 -5
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -13
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -32
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -11
- package/decorators/Embedded.d.ts +0 -12
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -33
- package/decorators/Entity.js +0 -12
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -16
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -8
- package/decorators/Formula.d.ts +0 -4
- package/decorators/Formula.js +0 -15
- package/decorators/Indexed.d.ts +0 -19
- package/decorators/Indexed.js +0 -20
- package/decorators/ManyToMany.d.ts +0 -42
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -34
- package/decorators/ManyToOne.js +0 -14
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -17
- package/decorators/OneToOne.d.ts +0 -28
- package/decorators/OneToOne.js +0 -7
- package/decorators/PrimaryKey.d.ts +0 -8
- package/decorators/PrimaryKey.js +0 -20
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -32
- package/decorators/Transactional.d.ts +0 -14
- package/decorators/Transactional.js +0 -28
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -47
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -17
- package/entity/ArrayCollection.d.ts +0 -118
- package/entity/ArrayCollection.js +0 -407
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -150
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -44
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -28
package/platforms/Platform.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { clone } from '../utils/clone.js';
|
|
3
2
|
import { EntityRepository } from '../entity/EntityRepository.js';
|
|
4
3
|
import { UnderscoreNamingStrategy } from '../naming-strategy/UnderscoreNamingStrategy.js';
|
|
5
4
|
import { ExceptionConverter } from './ExceptionConverter.js';
|
|
6
|
-
import { ArrayType, BigIntType, BlobType,
|
|
5
|
+
import { ArrayType, BigIntType, BlobType, BooleanType, CharacterType, DateTimeType, DateType, DecimalType, DoubleType, EnumType, FloatType, IntegerType, IntervalType, JsonType, MediumIntType, SmallIntType, StringType, TextType, TimeType, TinyIntType, Type, Uint8ArrayType, UnknownType, UuidType, } from '../types/index.js';
|
|
7
6
|
import { parseJsonSafe, Utils } from '../utils/Utils.js';
|
|
8
7
|
import { ReferenceKind } from '../enums.js';
|
|
9
|
-
import {
|
|
8
|
+
import { Raw } from '../utils/RawQueryFragment.js';
|
|
10
9
|
export const JsonProperty = Symbol('JsonProperty');
|
|
11
10
|
export class Platform {
|
|
12
11
|
exceptionConverter = new ExceptionConverter();
|
|
@@ -42,15 +41,15 @@ export class Platform {
|
|
|
42
41
|
usesEnumCheckConstraints() {
|
|
43
42
|
return false;
|
|
44
43
|
}
|
|
44
|
+
supportsMaterializedViews() {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
45
47
|
getSchemaHelper() {
|
|
46
48
|
return undefined;
|
|
47
49
|
}
|
|
48
50
|
indexForeignKeys() {
|
|
49
51
|
return false;
|
|
50
52
|
}
|
|
51
|
-
allowsMultiInsert() {
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
53
|
/**
|
|
55
54
|
* Whether or not the driver supports retuning list of created PKs back when multi-inserting
|
|
56
55
|
*/
|
|
@@ -78,15 +77,6 @@ export class Platform {
|
|
|
78
77
|
denormalizePrimaryKey(data) {
|
|
79
78
|
return data;
|
|
80
79
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Used when serializing via toObject and toJSON methods, allows to use different PK field name (like `id` instead of `_id`)
|
|
83
|
-
*/
|
|
84
|
-
getSerializedPrimaryKeyField(field) {
|
|
85
|
-
return field;
|
|
86
|
-
}
|
|
87
|
-
usesDifferentSerializedPrimaryKey() {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
80
|
/**
|
|
91
81
|
* Returns the SQL specific for the platform to get the current timestamp
|
|
92
82
|
*/
|
|
@@ -114,6 +104,11 @@ export class Platform {
|
|
|
114
104
|
getRegExpOperator(val, flags) {
|
|
115
105
|
return 'regexp';
|
|
116
106
|
}
|
|
107
|
+
mapRegExpCondition(mappedKey, value) {
|
|
108
|
+
const operator = this.getRegExpOperator(value.$re, value.$flags);
|
|
109
|
+
const quotedKey = this.quoteIdentifier(mappedKey);
|
|
110
|
+
return { sql: `${quotedKey} ${operator} ?`, params: [value.$re] };
|
|
111
|
+
}
|
|
117
112
|
getRegExpValue(val) {
|
|
118
113
|
if (val.flags.includes('i')) {
|
|
119
114
|
return { $re: `(?i)${val.source}` };
|
|
@@ -123,7 +118,7 @@ export class Platform {
|
|
|
123
118
|
isAllowedTopLevelOperator(operator) {
|
|
124
119
|
return operator === '$not';
|
|
125
120
|
}
|
|
126
|
-
|
|
121
|
+
convertVersionValue(value, prop) {
|
|
127
122
|
return value;
|
|
128
123
|
}
|
|
129
124
|
getDefaultVersionLength() {
|
|
@@ -133,7 +128,7 @@ export class Platform {
|
|
|
133
128
|
return true;
|
|
134
129
|
}
|
|
135
130
|
isBigIntProperty(prop) {
|
|
136
|
-
return prop.columnTypes
|
|
131
|
+
return prop.columnTypes?.[0] === 'bigint';
|
|
137
132
|
}
|
|
138
133
|
getDefaultSchemaName() {
|
|
139
134
|
return undefined;
|
|
@@ -166,10 +161,10 @@ export class Platform {
|
|
|
166
161
|
return 'interval' + (column.length ? `(${column.length})` : '');
|
|
167
162
|
}
|
|
168
163
|
getTextTypeDeclarationSQL(_column) {
|
|
169
|
-
return
|
|
164
|
+
return 'text';
|
|
170
165
|
}
|
|
171
166
|
getEnumTypeDeclarationSQL(column) {
|
|
172
|
-
if (column.items?.every(item =>
|
|
167
|
+
if (column.items?.every(item => typeof item === 'string')) {
|
|
173
168
|
return `enum('${column.items.join("','")}')`;
|
|
174
169
|
}
|
|
175
170
|
return this.getTinyIntTypeDeclarationSQL(column);
|
|
@@ -190,7 +185,7 @@ export class Platform {
|
|
|
190
185
|
return this.getVarcharTypeDeclarationSQL(column);
|
|
191
186
|
}
|
|
192
187
|
extractSimpleType(type) {
|
|
193
|
-
return
|
|
188
|
+
return /[^(), ]+/.exec(type.toLowerCase())[0];
|
|
194
189
|
}
|
|
195
190
|
/**
|
|
196
191
|
* This should be used only to compare types, it can strip some information like the length.
|
|
@@ -208,43 +203,76 @@ export class Platform {
|
|
|
208
203
|
}
|
|
209
204
|
switch (this.extractSimpleType(type)) {
|
|
210
205
|
case 'character':
|
|
211
|
-
case 'char':
|
|
206
|
+
case 'char':
|
|
207
|
+
return Type.getType(CharacterType);
|
|
212
208
|
case 'string':
|
|
213
|
-
case 'varchar':
|
|
214
|
-
|
|
215
|
-
case '
|
|
209
|
+
case 'varchar':
|
|
210
|
+
return Type.getType(StringType);
|
|
211
|
+
case 'interval':
|
|
212
|
+
return Type.getType(IntervalType);
|
|
213
|
+
case 'text':
|
|
214
|
+
return Type.getType(TextType);
|
|
216
215
|
case 'int':
|
|
217
|
-
case 'number':
|
|
218
|
-
|
|
219
|
-
case '
|
|
220
|
-
|
|
221
|
-
case '
|
|
222
|
-
|
|
223
|
-
case '
|
|
224
|
-
|
|
216
|
+
case 'number':
|
|
217
|
+
return Type.getType(IntegerType);
|
|
218
|
+
case 'bigint':
|
|
219
|
+
return Type.getType(BigIntType);
|
|
220
|
+
case 'smallint':
|
|
221
|
+
return Type.getType(SmallIntType);
|
|
222
|
+
case 'tinyint':
|
|
223
|
+
return Type.getType(TinyIntType);
|
|
224
|
+
case 'mediumint':
|
|
225
|
+
return Type.getType(MediumIntType);
|
|
226
|
+
case 'float':
|
|
227
|
+
return Type.getType(FloatType);
|
|
228
|
+
case 'double':
|
|
229
|
+
return Type.getType(DoubleType);
|
|
230
|
+
case 'integer':
|
|
231
|
+
return Type.getType(IntegerType);
|
|
225
232
|
case 'decimal':
|
|
226
|
-
case 'numeric':
|
|
227
|
-
|
|
233
|
+
case 'numeric':
|
|
234
|
+
return Type.getType(DecimalType);
|
|
235
|
+
case 'boolean':
|
|
236
|
+
return Type.getType(BooleanType);
|
|
228
237
|
case 'blob':
|
|
229
|
-
case 'buffer':
|
|
230
|
-
|
|
231
|
-
case '
|
|
232
|
-
|
|
238
|
+
case 'buffer':
|
|
239
|
+
return Type.getType(BlobType);
|
|
240
|
+
case 'uint8array':
|
|
241
|
+
return Type.getType(Uint8ArrayType);
|
|
242
|
+
case 'uuid':
|
|
243
|
+
return Type.getType(UuidType);
|
|
244
|
+
case 'date':
|
|
245
|
+
return Type.getType(DateType);
|
|
233
246
|
case 'datetime':
|
|
234
|
-
case 'timestamp':
|
|
235
|
-
|
|
247
|
+
case 'timestamp':
|
|
248
|
+
return Type.getType(DateTimeType);
|
|
249
|
+
case 'time':
|
|
250
|
+
return Type.getType(TimeType);
|
|
236
251
|
case 'object':
|
|
237
|
-
case 'json':
|
|
238
|
-
|
|
239
|
-
|
|
252
|
+
case 'json':
|
|
253
|
+
return Type.getType(JsonType);
|
|
254
|
+
case 'enum':
|
|
255
|
+
return Type.getType(EnumType);
|
|
256
|
+
default:
|
|
257
|
+
return Type.getType(UnknownType);
|
|
240
258
|
}
|
|
241
259
|
}
|
|
242
260
|
supportsMultipleCascadePaths() {
|
|
243
261
|
return true;
|
|
244
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* Returns true if the platform supports ON UPDATE foreign key rules.
|
|
265
|
+
* Oracle doesn't support ON UPDATE rules.
|
|
266
|
+
*/
|
|
267
|
+
supportsOnUpdate() {
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
245
270
|
supportsMultipleStatements() {
|
|
246
271
|
return this.config.get('multipleStatements');
|
|
247
272
|
}
|
|
273
|
+
supportsUnionWhere() {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
248
276
|
getArrayDeclarationSQL() {
|
|
249
277
|
return 'text';
|
|
250
278
|
}
|
|
@@ -269,7 +297,32 @@ export class Platform {
|
|
|
269
297
|
getSearchJsonPropertyKey(path, type, aliased, value) {
|
|
270
298
|
return path.join('.');
|
|
271
299
|
}
|
|
272
|
-
|
|
300
|
+
processJsonCondition(o, value, path, alias) {
|
|
301
|
+
if (Utils.isPlainObject(value) && !Object.keys(value).some(k => Utils.isOperator(k))) {
|
|
302
|
+
Utils.keys(value).forEach(k => {
|
|
303
|
+
this.processJsonCondition(o, value[k], [...path, k], alias);
|
|
304
|
+
});
|
|
305
|
+
return o;
|
|
306
|
+
}
|
|
307
|
+
if (path.length === 1) {
|
|
308
|
+
o[path[0]] = value;
|
|
309
|
+
return o;
|
|
310
|
+
}
|
|
311
|
+
const type = this.getJsonValueType(value);
|
|
312
|
+
const k = this.getSearchJsonPropertyKey(path, type, alias, value);
|
|
313
|
+
o[k] = value;
|
|
314
|
+
return o;
|
|
315
|
+
}
|
|
316
|
+
getJsonValueType(value) {
|
|
317
|
+
if (Array.isArray(value)) {
|
|
318
|
+
return typeof value[0];
|
|
319
|
+
}
|
|
320
|
+
if (Utils.isPlainObject(value) && Object.keys(value).every(k => Utils.isOperator(k))) {
|
|
321
|
+
return this.getJsonValueType(Object.values(value)[0]);
|
|
322
|
+
}
|
|
323
|
+
return typeof value;
|
|
324
|
+
}
|
|
325
|
+
/* v8 ignore next */
|
|
273
326
|
getJsonIndexDefinition(index) {
|
|
274
327
|
return index.columnNames;
|
|
275
328
|
}
|
|
@@ -288,11 +341,7 @@ export class Platform {
|
|
|
288
341
|
convertJsonToDatabaseValue(value, context) {
|
|
289
342
|
return JSON.stringify(value);
|
|
290
343
|
}
|
|
291
|
-
convertJsonToJSValue(value,
|
|
292
|
-
const isObjectEmbedded = prop.embedded && prop.object;
|
|
293
|
-
if ((this.convertsJsonAutomatically() || isObjectEmbedded) && ['json', 'jsonb', this.getJsonDeclarationSQL()].includes(prop.columnTypes[0])) {
|
|
294
|
-
return value;
|
|
295
|
-
}
|
|
344
|
+
convertJsonToJSValue(value, context) {
|
|
296
345
|
return parseJsonSafe(value);
|
|
297
346
|
}
|
|
298
347
|
convertDateToJSValue(value) {
|
|
@@ -304,9 +353,25 @@ export class Platform {
|
|
|
304
353
|
convertIntervalToDatabaseValue(value) {
|
|
305
354
|
return value;
|
|
306
355
|
}
|
|
356
|
+
usesAsKeyword() {
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Determines how UUID values are compared in the change set tracking.
|
|
361
|
+
* Return `'string'` for inline string comparison (fast), or `'any'` for deep comparison via type methods.
|
|
362
|
+
*/
|
|
363
|
+
compareUuids() {
|
|
364
|
+
return 'string';
|
|
365
|
+
}
|
|
366
|
+
convertUuidToJSValue(value) {
|
|
367
|
+
return value;
|
|
368
|
+
}
|
|
369
|
+
convertUuidToDatabaseValue(value) {
|
|
370
|
+
return value;
|
|
371
|
+
}
|
|
307
372
|
parseDate(value) {
|
|
308
373
|
const date = new Date(value);
|
|
309
|
-
/* v8 ignore next
|
|
374
|
+
/* v8 ignore next */
|
|
310
375
|
if (isNaN(date.getTime())) {
|
|
311
376
|
return value;
|
|
312
377
|
}
|
|
@@ -336,19 +401,10 @@ export class Platform {
|
|
|
336
401
|
if (extension) {
|
|
337
402
|
return extension;
|
|
338
403
|
}
|
|
339
|
-
/* v8 ignore next
|
|
340
|
-
|
|
341
|
-
module: moduleName,
|
|
342
|
-
warning: `Please install ${moduleName} package.`,
|
|
343
|
-
});
|
|
344
|
-
/* v8 ignore next 3 */
|
|
345
|
-
if (module) {
|
|
346
|
-
return this.config.getCachedService(module[extensionName], em);
|
|
347
|
-
}
|
|
348
|
-
/* v8 ignore next 2 */
|
|
349
|
-
throw new Error(`${extensionName} extension not registered.`);
|
|
404
|
+
/* v8 ignore next */
|
|
405
|
+
throw new Error(`${extensionName} extension not registered. Provide it in the ORM config, or use the async \`MikroORM.init()\` method to load extensions automatically.`);
|
|
350
406
|
}
|
|
351
|
-
/* v8 ignore next
|
|
407
|
+
/* v8 ignore next: kept for type inference only */
|
|
352
408
|
getSchemaGenerator(driver, em) {
|
|
353
409
|
throw new Error(`${driver.constructor.name} does not support SchemaGenerator`);
|
|
354
410
|
}
|
|
@@ -356,7 +412,7 @@ export class Platform {
|
|
|
356
412
|
return value;
|
|
357
413
|
}
|
|
358
414
|
quoteIdentifier(id, quote = '`') {
|
|
359
|
-
const raw =
|
|
415
|
+
const raw = Raw.getKnownFragment(id);
|
|
360
416
|
if (raw) {
|
|
361
417
|
return this.formatQuery(raw.sql, raw.params);
|
|
362
418
|
}
|
|
@@ -365,7 +421,7 @@ export class Platform {
|
|
|
365
421
|
quoteValue(value) {
|
|
366
422
|
return value;
|
|
367
423
|
}
|
|
368
|
-
/* v8 ignore next
|
|
424
|
+
/* v8 ignore next */
|
|
369
425
|
escape(value) {
|
|
370
426
|
return value;
|
|
371
427
|
}
|
|
@@ -377,7 +433,7 @@ export class Platform {
|
|
|
377
433
|
let j = 0;
|
|
378
434
|
let pos = 0;
|
|
379
435
|
let ret = '';
|
|
380
|
-
if (sql
|
|
436
|
+
if (sql.startsWith('?')) {
|
|
381
437
|
if (sql[1] === '?') {
|
|
382
438
|
ret += this.quoteIdentifier(params[j++]);
|
|
383
439
|
pos = 2;
|
|
@@ -455,7 +511,7 @@ export class Platform {
|
|
|
455
511
|
isPopulated(key, populate) {
|
|
456
512
|
return populate === true || (populate !== false && populate.some(p => p.field === key || p.all));
|
|
457
513
|
}
|
|
458
|
-
shouldHaveColumn(prop, populate, exclude, includeFormulas = true) {
|
|
514
|
+
shouldHaveColumn(prop, populate, exclude, includeFormulas = true, ignoreInlineEmbeddables = true) {
|
|
459
515
|
if (exclude?.includes(prop.name)) {
|
|
460
516
|
return false;
|
|
461
517
|
}
|
|
@@ -475,7 +531,7 @@ export class Platform {
|
|
|
475
531
|
return true;
|
|
476
532
|
}
|
|
477
533
|
if (prop.kind === ReferenceKind.EMBEDDED) {
|
|
478
|
-
return
|
|
534
|
+
return prop.object || ignoreInlineEmbeddables;
|
|
479
535
|
}
|
|
480
536
|
return prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner;
|
|
481
537
|
}
|
|
@@ -522,9 +578,9 @@ export class Platform {
|
|
|
522
578
|
clone() {
|
|
523
579
|
return this;
|
|
524
580
|
}
|
|
525
|
-
/* v8 ignore next 4 */
|
|
526
581
|
/** @ignore */
|
|
527
|
-
|
|
582
|
+
/* v8 ignore next */
|
|
583
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
528
584
|
return `[${this.constructor.name}]`;
|
|
529
585
|
}
|
|
530
586
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { ArrayElement, AutoPath, CleanTypeConfig,
|
|
1
|
+
import type { ArrayElement, AutoPath, CleanTypeConfig, SerializeDTO, FromEntityType, TypeConfig, UnboxArray } from '../typings.js';
|
|
2
2
|
import { type PopulatePath } from '../enums.js';
|
|
3
3
|
export declare class EntitySerializer {
|
|
4
|
-
static serialize<T extends object, P extends string = never, E extends string = never>(entity: T, options?: SerializeOptions<T, P, E>):
|
|
4
|
+
static serialize<T extends object, P extends string = never, E extends string = never>(entity: T, options?: SerializeOptions<T, P, E>): SerializeDTO<T, P, E>;
|
|
5
5
|
private static propertyName;
|
|
6
6
|
private static processProperty;
|
|
7
|
+
private static processCustomType;
|
|
7
8
|
private static extractChildOptions;
|
|
8
9
|
private static processEntity;
|
|
9
10
|
private static processCollection;
|
|
@@ -23,6 +24,8 @@ export interface SerializeOptions<T, P extends string = never, E extends string
|
|
|
23
24
|
skipNull?: boolean;
|
|
24
25
|
/** Only include properties for a specific group. If a property does not specify any group, it will be included, otherwise only properties with a matching group are included. */
|
|
25
26
|
groups?: string[];
|
|
27
|
+
/** Convert custom types to their database representation. By default, the `Type.toJSON` method is invoked instead. */
|
|
28
|
+
convertCustomTypes?: boolean;
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
28
31
|
* Converts entity instance to POJO, converting the `Collection`s to arrays and unwrapping the `Reference` wrapper, while respecting the serialization options.
|
|
@@ -36,4 +39,4 @@ export interface SerializeOptions<T, P extends string = never, E extends string
|
|
|
36
39
|
* const dto2 = wrap(user).serialize({ exclude: ['id', 'email'], forceObject: true });
|
|
37
40
|
* ```
|
|
38
41
|
*/
|
|
39
|
-
export declare function serialize<Entity extends object, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Populate extends string = never, Exclude extends string = never, Config extends TypeConfig = never>(entity: Entity, options?: Config & SerializeOptions<UnboxArray<Entity>, Populate, Exclude>): Naked extends object[] ?
|
|
42
|
+
export declare function serialize<Entity extends object, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Populate extends string = never, Exclude extends string = never, Config extends TypeConfig = never>(entity: Entity, options?: Config & SerializeOptions<UnboxArray<Entity>, Populate, Exclude>): Naked extends object[] ? SerializeDTO<ArrayElement<Naked>, Populate, Exclude, CleanTypeConfig<Config>>[] : SerializeDTO<Naked, Populate, Exclude, CleanTypeConfig<Config>>;
|
|
@@ -9,18 +9,20 @@ function isVisible(meta, propName, options) {
|
|
|
9
9
|
if (options.groups && prop?.groups) {
|
|
10
10
|
return prop.groups.some(g => options.groups.includes(g));
|
|
11
11
|
}
|
|
12
|
-
if (Array.isArray(options.populate) &&
|
|
12
|
+
if (Array.isArray(options.populate) &&
|
|
13
|
+
options.populate?.find(item => item === propName || item.startsWith(propName + '.') || item === '*')) {
|
|
13
14
|
return true;
|
|
14
15
|
}
|
|
15
16
|
if (options.exclude?.find(item => item === propName)) {
|
|
16
17
|
return false;
|
|
17
18
|
}
|
|
18
19
|
const visible = prop && !(prop.hidden && !options.includeHidden);
|
|
19
|
-
const prefixed = prop && !prop.primary && propName.startsWith('_'); // ignore prefixed properties, if it's not a PK
|
|
20
|
+
const prefixed = prop && !prop.primary && !prop.accessor && propName.startsWith('_'); // ignore prefixed properties, if it's not a PK
|
|
20
21
|
return visible && !prefixed;
|
|
21
22
|
}
|
|
22
23
|
function isPopulated(propName, options) {
|
|
23
|
-
if (typeof options.populate !== 'boolean' &&
|
|
24
|
+
if (typeof options.populate !== 'boolean' &&
|
|
25
|
+
options.populate?.find(item => item === propName || item.startsWith(propName + '.') || item === '*')) {
|
|
24
26
|
return true;
|
|
25
27
|
}
|
|
26
28
|
if (typeof options.populate === 'boolean') {
|
|
@@ -41,23 +43,41 @@ export class EntitySerializer {
|
|
|
41
43
|
}
|
|
42
44
|
const root = wrapped.__serializationContext.root;
|
|
43
45
|
const ret = {};
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
+
const props = new Set();
|
|
47
|
+
if (meta.serializedPrimaryKey && !meta.compositePK) {
|
|
48
|
+
props.add(meta.serializedPrimaryKey);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
meta.primaryKeys.forEach(pk => props.add(pk));
|
|
52
|
+
}
|
|
53
|
+
if (wrapped.isInitialized() || !wrapped.hasPrimaryKey()) {
|
|
54
|
+
const entityKeys = new Set(Object.keys(entity));
|
|
55
|
+
for (const prop of meta.props) {
|
|
56
|
+
if (entityKeys.has(prop.name) || (prop.getter && prop.accessor === prop.name)) {
|
|
57
|
+
props.add(prop.name);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (const key of entityKeys) {
|
|
61
|
+
if (!meta.properties[key]) {
|
|
62
|
+
props.add(key);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
46
66
|
const visited = root.visited.has(entity);
|
|
47
67
|
if (!visited) {
|
|
48
68
|
root.visited.add(entity);
|
|
49
69
|
}
|
|
50
|
-
for (const prop of
|
|
70
|
+
for (const prop of props) {
|
|
51
71
|
if (!isVisible(meta, prop, options)) {
|
|
52
72
|
continue;
|
|
53
73
|
}
|
|
54
|
-
const cycle = root.visit(meta.
|
|
74
|
+
const cycle = root.visit(meta.class, prop);
|
|
55
75
|
if (cycle && visited) {
|
|
56
76
|
continue;
|
|
57
77
|
}
|
|
58
78
|
const val = this.processProperty(prop, entity, options);
|
|
59
79
|
if (!cycle) {
|
|
60
|
-
root.leave(meta.
|
|
80
|
+
root.leave(meta.class, prop);
|
|
61
81
|
}
|
|
62
82
|
if (options.skipNull && Utils.isPlainObject(val)) {
|
|
63
83
|
Utils.dropUndefinedProperties(val, null);
|
|
@@ -67,7 +87,7 @@ export class EntitySerializer {
|
|
|
67
87
|
}
|
|
68
88
|
const visible = typeof val !== 'undefined' && !(val === null && options.skipNull);
|
|
69
89
|
if (visible) {
|
|
70
|
-
ret[this.propertyName(meta, prop
|
|
90
|
+
ret[this.propertyName(meta, prop)] = val;
|
|
71
91
|
}
|
|
72
92
|
}
|
|
73
93
|
if (contextCreated) {
|
|
@@ -81,26 +101,26 @@ export class EntitySerializer {
|
|
|
81
101
|
if (prop.getterName != null) {
|
|
82
102
|
const visible = entity[prop.getterName] instanceof Function && isVisible(meta, prop.name, options);
|
|
83
103
|
if (visible) {
|
|
84
|
-
ret[this.propertyName(meta, prop.name
|
|
104
|
+
ret[this.propertyName(meta, prop.name)] = this.processProperty(prop.getterName, entity, options);
|
|
85
105
|
}
|
|
86
106
|
}
|
|
87
107
|
else {
|
|
88
108
|
// decorated getters
|
|
89
109
|
const visible = typeof entity[prop.name] !== 'undefined' && isVisible(meta, prop.name, options);
|
|
90
110
|
if (visible) {
|
|
91
|
-
ret[this.propertyName(meta, prop.name
|
|
111
|
+
ret[this.propertyName(meta, prop.name)] = this.processProperty(prop.name, entity, options);
|
|
92
112
|
}
|
|
93
113
|
}
|
|
94
114
|
}
|
|
95
115
|
return ret;
|
|
96
116
|
}
|
|
97
|
-
static propertyName(meta, prop
|
|
98
|
-
/* v8 ignore next
|
|
117
|
+
static propertyName(meta, prop) {
|
|
118
|
+
/* v8 ignore next */
|
|
99
119
|
if (meta.properties[prop]?.serializedName) {
|
|
100
120
|
return meta.properties[prop].serializedName;
|
|
101
121
|
}
|
|
102
|
-
if (meta.properties[prop]?.primary &&
|
|
103
|
-
return
|
|
122
|
+
if (meta.properties[prop]?.primary && meta.serializedPrimaryKey) {
|
|
123
|
+
return meta.serializedPrimaryKey;
|
|
104
124
|
}
|
|
105
125
|
return prop;
|
|
106
126
|
}
|
|
@@ -119,7 +139,7 @@ export class EntitySerializer {
|
|
|
119
139
|
}
|
|
120
140
|
return returnValue;
|
|
121
141
|
}
|
|
122
|
-
/* v8 ignore next
|
|
142
|
+
/* v8 ignore next */
|
|
123
143
|
if (!options.ignoreSerializers && serializer) {
|
|
124
144
|
return serializer(value);
|
|
125
145
|
}
|
|
@@ -132,7 +152,7 @@ export class EntitySerializer {
|
|
|
132
152
|
if (Utils.isScalarReference(value)) {
|
|
133
153
|
return value.unwrap();
|
|
134
154
|
}
|
|
135
|
-
/* v8 ignore next
|
|
155
|
+
/* v8 ignore next */
|
|
136
156
|
if (property?.kind === ReferenceKind.EMBEDDED) {
|
|
137
157
|
if (Array.isArray(value)) {
|
|
138
158
|
return value.map(item => helper(item).toJSON());
|
|
@@ -141,16 +161,26 @@ export class EntitySerializer {
|
|
|
141
161
|
return helper(value).toJSON();
|
|
142
162
|
}
|
|
143
163
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return customType.toJSON(value, wrapped.__platform);
|
|
164
|
+
if (property.customType) {
|
|
165
|
+
return this.processCustomType(value, property, wrapped.__platform, options.convertCustomTypes);
|
|
147
166
|
}
|
|
148
167
|
return wrapped.__platform.normalizePrimaryKey(value);
|
|
149
168
|
}
|
|
169
|
+
static processCustomType(value, prop, platform, convertCustomTypes) {
|
|
170
|
+
if (!prop.customType) {
|
|
171
|
+
return value;
|
|
172
|
+
}
|
|
173
|
+
if (convertCustomTypes) {
|
|
174
|
+
return prop.customType.convertToDatabaseValue(value, platform, { mode: 'serialization' });
|
|
175
|
+
}
|
|
176
|
+
return prop.customType.toJSON(value, platform);
|
|
177
|
+
}
|
|
150
178
|
static extractChildOptions(options, prop) {
|
|
151
179
|
return {
|
|
152
180
|
...options,
|
|
153
|
-
populate: Array.isArray(options.populate)
|
|
181
|
+
populate: Array.isArray(options.populate)
|
|
182
|
+
? Utils.extractChildElements(options.populate, prop, '*')
|
|
183
|
+
: options.populate,
|
|
154
184
|
exclude: Array.isArray(options.exclude) ? Utils.extractChildElements(options.exclude, prop) : options.exclude,
|
|
155
185
|
};
|
|
156
186
|
}
|
|
@@ -165,10 +195,7 @@ export class EntitySerializer {
|
|
|
165
195
|
if (expand) {
|
|
166
196
|
return this.serialize(child, childOptions);
|
|
167
197
|
}
|
|
168
|
-
|
|
169
|
-
if (prop.customType) {
|
|
170
|
-
pk = prop.customType.toJSON(pk, wrapped.__platform);
|
|
171
|
-
}
|
|
198
|
+
const pk = this.processCustomType(wrapped.getPrimaryKey(), prop, wrapped.__platform, options.convertCustomTypes);
|
|
172
199
|
if (options.forceObject || wrapped.__config.get('serialization').forceObject) {
|
|
173
200
|
return Utils.primaryKeyToObject(meta, pk, visible);
|
|
174
201
|
}
|
|
@@ -192,10 +219,7 @@ export class EntitySerializer {
|
|
|
192
219
|
if (populated || !wrapped.__managed) {
|
|
193
220
|
return this.serialize(item, this.extractChildOptions(options, prop.name));
|
|
194
221
|
}
|
|
195
|
-
|
|
196
|
-
if (prop.customType) {
|
|
197
|
-
pk = prop.customType.toJSON(pk, wrapped.__platform);
|
|
198
|
-
}
|
|
222
|
+
const pk = this.processCustomType(wrapped.getPrimaryKey(), prop, wrapped.__platform, options.convertCustomTypes);
|
|
199
223
|
if (options.forceObject || wrapped.__config.get('serialization').forceObject) {
|
|
200
224
|
return Utils.primaryKeyToObject(wrapped.__meta, pk);
|
|
201
225
|
}
|