@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.
Files changed (216) hide show
  1. package/EntityManager.d.ts +71 -63
  2. package/EntityManager.js +365 -283
  3. package/MikroORM.d.ts +44 -35
  4. package/MikroORM.js +109 -142
  5. package/README.md +7 -4
  6. package/cache/FileCacheAdapter.d.ts +1 -2
  7. package/cache/FileCacheAdapter.js +19 -14
  8. package/cache/GeneratedCacheAdapter.d.ts +0 -1
  9. package/cache/GeneratedCacheAdapter.js +0 -2
  10. package/cache/index.d.ts +1 -2
  11. package/cache/index.js +0 -2
  12. package/connections/Connection.d.ts +12 -5
  13. package/connections/Connection.js +37 -15
  14. package/drivers/DatabaseDriver.d.ts +25 -18
  15. package/drivers/DatabaseDriver.js +144 -45
  16. package/drivers/IDatabaseDriver.d.ts +118 -23
  17. package/entity/BaseEntity.d.ts +63 -4
  18. package/entity/BaseEntity.js +0 -3
  19. package/entity/Collection.d.ts +101 -29
  20. package/entity/Collection.js +473 -115
  21. package/entity/EntityAssigner.js +37 -25
  22. package/entity/EntityFactory.d.ts +7 -1
  23. package/entity/EntityFactory.js +116 -64
  24. package/entity/EntityHelper.d.ts +2 -2
  25. package/entity/EntityHelper.js +69 -27
  26. package/entity/EntityLoader.d.ts +11 -10
  27. package/entity/EntityLoader.js +264 -102
  28. package/entity/EntityRepository.d.ts +28 -8
  29. package/entity/EntityRepository.js +8 -2
  30. package/entity/PolymorphicRef.d.ts +12 -0
  31. package/entity/PolymorphicRef.js +18 -0
  32. package/entity/Reference.d.ts +2 -6
  33. package/entity/Reference.js +52 -19
  34. package/entity/WrappedEntity.d.ts +3 -8
  35. package/entity/WrappedEntity.js +6 -7
  36. package/entity/defineEntity.d.ts +525 -311
  37. package/entity/defineEntity.js +134 -290
  38. package/entity/index.d.ts +2 -2
  39. package/entity/index.js +2 -2
  40. package/entity/utils.d.ts +6 -1
  41. package/entity/utils.js +46 -11
  42. package/entity/validators.d.ts +11 -0
  43. package/entity/validators.js +66 -0
  44. package/enums.d.ts +8 -6
  45. package/enums.js +13 -17
  46. package/errors.d.ts +20 -10
  47. package/errors.js +63 -31
  48. package/events/EventManager.d.ts +2 -1
  49. package/events/EventManager.js +24 -13
  50. package/events/index.d.ts +1 -1
  51. package/events/index.js +0 -1
  52. package/exceptions.js +9 -2
  53. package/hydration/Hydrator.js +1 -2
  54. package/hydration/ObjectHydrator.d.ts +4 -4
  55. package/hydration/ObjectHydrator.js +105 -46
  56. package/index.d.ts +2 -2
  57. package/index.js +1 -2
  58. package/logging/DefaultLogger.d.ts +1 -1
  59. package/logging/DefaultLogger.js +3 -4
  60. package/logging/SimpleLogger.d.ts +1 -1
  61. package/logging/colors.d.ts +1 -1
  62. package/logging/colors.js +5 -7
  63. package/logging/index.d.ts +2 -1
  64. package/logging/index.js +1 -1
  65. package/logging/inspect.d.ts +2 -0
  66. package/logging/inspect.js +11 -0
  67. package/metadata/EntitySchema.d.ts +47 -23
  68. package/metadata/EntitySchema.js +103 -34
  69. package/metadata/MetadataDiscovery.d.ts +64 -9
  70. package/metadata/MetadataDiscovery.js +867 -354
  71. package/metadata/MetadataProvider.d.ts +11 -2
  72. package/metadata/MetadataProvider.js +71 -2
  73. package/metadata/MetadataStorage.d.ts +13 -11
  74. package/metadata/MetadataStorage.js +72 -41
  75. package/metadata/MetadataValidator.d.ts +32 -9
  76. package/metadata/MetadataValidator.js +214 -44
  77. package/metadata/discover-entities.d.ts +5 -0
  78. package/metadata/discover-entities.js +40 -0
  79. package/metadata/index.d.ts +1 -1
  80. package/metadata/index.js +0 -1
  81. package/metadata/types.d.ts +577 -0
  82. package/metadata/types.js +1 -0
  83. package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
  84. package/naming-strategy/AbstractNamingStrategy.js +26 -5
  85. package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
  86. package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
  87. package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
  88. package/naming-strategy/MongoNamingStrategy.js +6 -6
  89. package/naming-strategy/NamingStrategy.d.ts +28 -4
  90. package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
  91. package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
  92. package/naming-strategy/index.d.ts +1 -1
  93. package/naming-strategy/index.js +0 -1
  94. package/not-supported.d.ts +2 -0
  95. package/not-supported.js +8 -0
  96. package/package.json +47 -36
  97. package/platforms/ExceptionConverter.js +1 -1
  98. package/platforms/Platform.d.ts +33 -15
  99. package/platforms/Platform.js +125 -69
  100. package/serialization/EntitySerializer.d.ts +6 -3
  101. package/serialization/EntitySerializer.js +53 -29
  102. package/serialization/EntityTransformer.js +33 -21
  103. package/serialization/SerializationContext.d.ts +6 -6
  104. package/serialization/SerializationContext.js +4 -4
  105. package/types/ArrayType.d.ts +1 -1
  106. package/types/ArrayType.js +2 -3
  107. package/types/BigIntType.js +1 -1
  108. package/types/BlobType.d.ts +0 -1
  109. package/types/BlobType.js +0 -3
  110. package/types/BooleanType.d.ts +1 -0
  111. package/types/BooleanType.js +3 -0
  112. package/types/DecimalType.js +2 -2
  113. package/types/DoubleType.js +1 -1
  114. package/types/EnumArrayType.js +1 -2
  115. package/types/JsonType.d.ts +1 -1
  116. package/types/JsonType.js +7 -2
  117. package/types/TinyIntType.js +1 -1
  118. package/types/Type.d.ts +2 -4
  119. package/types/Type.js +3 -3
  120. package/types/Uint8ArrayType.d.ts +0 -1
  121. package/types/Uint8ArrayType.js +1 -4
  122. package/types/UuidType.d.ts +2 -0
  123. package/types/UuidType.js +14 -2
  124. package/types/index.d.ts +3 -2
  125. package/typings.d.ts +427 -170
  126. package/typings.js +100 -45
  127. package/unit-of-work/ChangeSet.d.ts +4 -6
  128. package/unit-of-work/ChangeSet.js +8 -9
  129. package/unit-of-work/ChangeSetComputer.d.ts +3 -8
  130. package/unit-of-work/ChangeSetComputer.js +49 -26
  131. package/unit-of-work/ChangeSetPersister.d.ts +13 -12
  132. package/unit-of-work/ChangeSetPersister.js +107 -44
  133. package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
  134. package/unit-of-work/CommitOrderCalculator.js +17 -15
  135. package/unit-of-work/IdentityMap.d.ts +12 -0
  136. package/unit-of-work/IdentityMap.js +39 -1
  137. package/unit-of-work/UnitOfWork.d.ts +34 -4
  138. package/unit-of-work/UnitOfWork.js +294 -107
  139. package/utils/AbstractMigrator.d.ts +101 -0
  140. package/utils/AbstractMigrator.js +303 -0
  141. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  142. package/utils/AbstractSchemaGenerator.js +30 -18
  143. package/utils/AsyncContext.d.ts +6 -0
  144. package/utils/AsyncContext.js +42 -0
  145. package/utils/Configuration.d.ts +796 -211
  146. package/utils/Configuration.js +160 -197
  147. package/utils/ConfigurationLoader.d.ts +1 -52
  148. package/utils/ConfigurationLoader.js +1 -330
  149. package/utils/Cursor.d.ts +0 -3
  150. package/utils/Cursor.js +29 -14
  151. package/utils/DataloaderUtils.d.ts +10 -5
  152. package/utils/DataloaderUtils.js +42 -22
  153. package/utils/EntityComparator.d.ts +16 -9
  154. package/utils/EntityComparator.js +202 -96
  155. package/utils/QueryHelper.d.ts +34 -7
  156. package/utils/QueryHelper.js +183 -72
  157. package/utils/RawQueryFragment.d.ts +28 -34
  158. package/utils/RawQueryFragment.js +37 -72
  159. package/utils/RequestContext.js +2 -2
  160. package/utils/TransactionContext.js +2 -2
  161. package/utils/TransactionManager.js +11 -7
  162. package/utils/Utils.d.ts +16 -127
  163. package/utils/Utils.js +106 -401
  164. package/utils/clone.js +13 -23
  165. package/utils/env-vars.d.ts +7 -0
  166. package/utils/env-vars.js +98 -0
  167. package/utils/fs-utils.d.ts +34 -0
  168. package/utils/fs-utils.js +193 -0
  169. package/utils/index.d.ts +1 -3
  170. package/utils/index.js +1 -3
  171. package/utils/upsert-utils.d.ts +9 -4
  172. package/utils/upsert-utils.js +51 -5
  173. package/decorators/Check.d.ts +0 -3
  174. package/decorators/Check.js +0 -13
  175. package/decorators/CreateRequestContext.d.ts +0 -3
  176. package/decorators/CreateRequestContext.js +0 -32
  177. package/decorators/Embeddable.d.ts +0 -8
  178. package/decorators/Embeddable.js +0 -11
  179. package/decorators/Embedded.d.ts +0 -12
  180. package/decorators/Embedded.js +0 -18
  181. package/decorators/Entity.d.ts +0 -33
  182. package/decorators/Entity.js +0 -12
  183. package/decorators/Enum.d.ts +0 -9
  184. package/decorators/Enum.js +0 -16
  185. package/decorators/Filter.d.ts +0 -2
  186. package/decorators/Filter.js +0 -8
  187. package/decorators/Formula.d.ts +0 -4
  188. package/decorators/Formula.js +0 -15
  189. package/decorators/Indexed.d.ts +0 -19
  190. package/decorators/Indexed.js +0 -20
  191. package/decorators/ManyToMany.d.ts +0 -42
  192. package/decorators/ManyToMany.js +0 -14
  193. package/decorators/ManyToOne.d.ts +0 -34
  194. package/decorators/ManyToOne.js +0 -14
  195. package/decorators/OneToMany.d.ts +0 -28
  196. package/decorators/OneToMany.js +0 -17
  197. package/decorators/OneToOne.d.ts +0 -28
  198. package/decorators/OneToOne.js +0 -7
  199. package/decorators/PrimaryKey.d.ts +0 -8
  200. package/decorators/PrimaryKey.js +0 -20
  201. package/decorators/Property.d.ts +0 -250
  202. package/decorators/Property.js +0 -32
  203. package/decorators/Transactional.d.ts +0 -14
  204. package/decorators/Transactional.js +0 -28
  205. package/decorators/hooks.d.ts +0 -16
  206. package/decorators/hooks.js +0 -47
  207. package/decorators/index.d.ts +0 -17
  208. package/decorators/index.js +0 -17
  209. package/entity/ArrayCollection.d.ts +0 -118
  210. package/entity/ArrayCollection.js +0 -407
  211. package/entity/EntityValidator.d.ts +0 -19
  212. package/entity/EntityValidator.js +0 -150
  213. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  214. package/metadata/ReflectMetadataProvider.js +0 -44
  215. package/utils/resolveContextProvider.d.ts +0 -10
  216. package/utils/resolveContextProvider.js +0 -28
@@ -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, Uint8ArrayType, BooleanType, CharacterType, DateType, DecimalType, DoubleType, JsonType, SmallIntType, TimeType, TinyIntType, Type, UuidType, StringType, IntegerType, FloatType, DateTimeType, TextType, EnumType, UnknownType, MediumIntType, IntervalType, } from '../types/index.js';
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 { RawQueryFragment } from '../utils/RawQueryFragment.js';
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
- quoteVersionValue(value, prop) {
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 && prop.columnTypes[0] === 'bigint';
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 `text`;
164
+ return 'text';
170
165
  }
171
166
  getEnumTypeDeclarationSQL(column) {
172
- if (column.items?.every(item => Utils.isString(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 type.toLowerCase().match(/[^(), ]+/)[0];
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': return Type.getType(CharacterType);
206
+ case 'char':
207
+ return Type.getType(CharacterType);
212
208
  case 'string':
213
- case 'varchar': return Type.getType(StringType);
214
- case 'interval': return Type.getType(IntervalType);
215
- case 'text': return Type.getType(TextType);
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': return Type.getType(IntegerType);
218
- case 'bigint': return Type.getType(BigIntType);
219
- case 'smallint': return Type.getType(SmallIntType);
220
- case 'tinyint': return Type.getType(TinyIntType);
221
- case 'mediumint': return Type.getType(MediumIntType);
222
- case 'float': return Type.getType(FloatType);
223
- case 'double': return Type.getType(DoubleType);
224
- case 'integer': return Type.getType(IntegerType);
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': return Type.getType(DecimalType);
227
- case 'boolean': return Type.getType(BooleanType);
233
+ case 'numeric':
234
+ return Type.getType(DecimalType);
235
+ case 'boolean':
236
+ return Type.getType(BooleanType);
228
237
  case 'blob':
229
- case 'buffer': return Type.getType(BlobType);
230
- case 'uint8array': return Type.getType(Uint8ArrayType);
231
- case 'uuid': return Type.getType(UuidType);
232
- case 'date': return Type.getType(DateType);
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': return Type.getType(DateTimeType);
235
- case 'time': return Type.getType(TimeType);
247
+ case 'timestamp':
248
+ return Type.getType(DateTimeType);
249
+ case 'time':
250
+ return Type.getType(TimeType);
236
251
  case 'object':
237
- case 'json': return Type.getType(JsonType);
238
- case 'enum': return Type.getType(EnumType);
239
- default: return Type.getType(UnknownType);
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
- /* v8 ignore next 3 */
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, prop) {
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 3 */
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 4 */
340
- const module = Utils.tryRequire({
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 3: kept for type inference only */
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 = RawQueryFragment.getKnownFragment(id);
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 3 */
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[0] === '?') {
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 !!prop.object;
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
- [inspect.custom]() {
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, EntityDTO, FromEntityType, Loaded, TypeConfig, UnboxArray } from '../typings.js';
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>): EntityDTO<Loaded<T, P>>;
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[] ? EntityDTO<Loaded<ArrayElement<Naked>, Populate>, CleanTypeConfig<Config>>[] : EntityDTO<Loaded<Naked, Populate>, CleanTypeConfig<Config>>;
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) && options.populate?.find(item => item === propName || item.startsWith(propName + '.') || item === '*')) {
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' && options.populate?.find(item => item === propName || item.startsWith(propName + '.') || item === '*')) {
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 keys = new Set(meta.primaryKeys);
45
- Utils.keys(entity).forEach(prop => keys.add(prop));
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 keys) {
70
+ for (const prop of props) {
51
71
  if (!isVisible(meta, prop, options)) {
52
72
  continue;
53
73
  }
54
- const cycle = root.visit(meta.className, prop);
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.className, prop);
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, wrapped.__platform)] = val;
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, wrapped.__platform)] = this.processProperty(prop.getterName, entity, options);
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, wrapped.__platform)] = this.processProperty(prop.name, entity, options);
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, platform) {
98
- /* v8 ignore next 3 */
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 && platform) {
103
- return platform.getSerializedPrimaryKeyField(prop);
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 3 */
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 9 */
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
- const customType = property?.customType;
145
- if (customType) {
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) ? Utils.extractChildElements(options.populate, prop, '*') : 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
- let pk = wrapped.getPrimaryKey();
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
- let pk = wrapped.getPrimaryKey();
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
  }