@mikro-orm/core 7.0.0-rc.2 → 7.0.0

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 (114) hide show
  1. package/EntityManager.d.ts +4 -16
  2. package/EntityManager.js +248 -181
  3. package/MikroORM.d.ts +4 -6
  4. package/MikroORM.js +24 -24
  5. package/README.md +5 -4
  6. package/cache/FileCacheAdapter.d.ts +1 -5
  7. package/cache/FileCacheAdapter.js +22 -24
  8. package/cache/GeneratedCacheAdapter.d.ts +1 -1
  9. package/cache/GeneratedCacheAdapter.js +6 -6
  10. package/cache/MemoryCacheAdapter.d.ts +1 -2
  11. package/cache/MemoryCacheAdapter.js +8 -8
  12. package/cache/index.d.ts +1 -1
  13. package/cache/index.js +0 -1
  14. package/connections/Connection.d.ts +1 -0
  15. package/connections/Connection.js +43 -14
  16. package/drivers/DatabaseDriver.d.ts +0 -2
  17. package/drivers/DatabaseDriver.js +28 -12
  18. package/drivers/IDatabaseDriver.d.ts +43 -0
  19. package/entity/Collection.d.ts +1 -9
  20. package/entity/Collection.js +124 -108
  21. package/entity/EntityAssigner.js +23 -11
  22. package/entity/EntityFactory.d.ts +1 -8
  23. package/entity/EntityFactory.js +79 -59
  24. package/entity/EntityHelper.js +25 -16
  25. package/entity/EntityLoader.d.ts +1 -3
  26. package/entity/EntityLoader.js +90 -60
  27. package/entity/Reference.d.ts +2 -3
  28. package/entity/Reference.js +48 -19
  29. package/entity/WrappedEntity.d.ts +4 -2
  30. package/entity/WrappedEntity.js +5 -1
  31. package/entity/defineEntity.d.ts +42 -85
  32. package/entity/utils.js +28 -26
  33. package/entity/validators.js +2 -1
  34. package/enums.d.ts +2 -1
  35. package/enums.js +13 -17
  36. package/errors.d.ts +11 -11
  37. package/errors.js +8 -8
  38. package/events/EventManager.d.ts +1 -4
  39. package/events/EventManager.js +26 -23
  40. package/events/index.d.ts +1 -1
  41. package/events/index.js +0 -1
  42. package/exceptions.js +9 -2
  43. package/hydration/ObjectHydrator.d.ts +1 -2
  44. package/hydration/ObjectHydrator.js +41 -27
  45. package/index.d.ts +1 -1
  46. package/index.js +1 -1
  47. package/logging/DefaultLogger.js +6 -7
  48. package/logging/Logger.d.ts +2 -1
  49. package/logging/colors.js +2 -5
  50. package/logging/index.d.ts +1 -1
  51. package/logging/index.js +0 -1
  52. package/metadata/EntitySchema.d.ts +3 -3
  53. package/metadata/EntitySchema.js +12 -2
  54. package/metadata/MetadataDiscovery.d.ts +1 -9
  55. package/metadata/MetadataDiscovery.js +251 -179
  56. package/metadata/MetadataProvider.js +26 -1
  57. package/metadata/MetadataStorage.d.ts +1 -5
  58. package/metadata/MetadataStorage.js +37 -39
  59. package/metadata/MetadataValidator.js +20 -5
  60. package/metadata/discover-entities.js +1 -1
  61. package/metadata/index.d.ts +1 -1
  62. package/metadata/index.js +0 -1
  63. package/metadata/types.d.ts +2 -2
  64. package/naming-strategy/AbstractNamingStrategy.js +6 -3
  65. package/naming-strategy/EntityCaseNamingStrategy.js +1 -1
  66. package/naming-strategy/index.d.ts +1 -1
  67. package/naming-strategy/index.js +0 -1
  68. package/not-supported.js +5 -1
  69. package/package.json +38 -38
  70. package/platforms/Platform.d.ts +24 -1
  71. package/platforms/Platform.js +106 -27
  72. package/serialization/EntitySerializer.js +8 -4
  73. package/serialization/EntityTransformer.js +4 -1
  74. package/serialization/SerializationContext.d.ts +4 -8
  75. package/serialization/SerializationContext.js +21 -16
  76. package/types/UuidType.d.ts +2 -0
  77. package/types/UuidType.js +14 -2
  78. package/types/index.d.ts +2 -1
  79. package/typings.d.ts +35 -24
  80. package/typings.js +9 -9
  81. package/unit-of-work/ChangeSet.js +4 -4
  82. package/unit-of-work/ChangeSetComputer.d.ts +1 -6
  83. package/unit-of-work/ChangeSetComputer.js +29 -27
  84. package/unit-of-work/ChangeSetPersister.d.ts +1 -9
  85. package/unit-of-work/ChangeSetPersister.js +63 -58
  86. package/unit-of-work/CommitOrderCalculator.d.ts +1 -4
  87. package/unit-of-work/CommitOrderCalculator.js +17 -15
  88. package/unit-of-work/IdentityMap.d.ts +2 -5
  89. package/unit-of-work/IdentityMap.js +18 -18
  90. package/unit-of-work/UnitOfWork.d.ts +12 -20
  91. package/unit-of-work/UnitOfWork.js +228 -191
  92. package/utils/AbstractMigrator.d.ts +2 -2
  93. package/utils/AbstractMigrator.js +10 -12
  94. package/utils/AbstractSchemaGenerator.js +2 -1
  95. package/utils/AsyncContext.js +1 -1
  96. package/utils/Configuration.d.ts +90 -189
  97. package/utils/Configuration.js +97 -77
  98. package/utils/Cursor.d.ts +3 -3
  99. package/utils/Cursor.js +8 -6
  100. package/utils/DataloaderUtils.js +15 -12
  101. package/utils/EntityComparator.d.ts +8 -15
  102. package/utils/EntityComparator.js +100 -92
  103. package/utils/QueryHelper.d.ts +16 -1
  104. package/utils/QueryHelper.js +108 -50
  105. package/utils/RawQueryFragment.d.ts +4 -4
  106. package/utils/RawQueryFragment.js +3 -2
  107. package/utils/TransactionManager.js +3 -3
  108. package/utils/Utils.d.ts +2 -2
  109. package/utils/Utils.js +39 -32
  110. package/utils/clone.js +5 -0
  111. package/utils/env-vars.js +6 -5
  112. package/utils/fs-utils.d.ts +3 -17
  113. package/utils/fs-utils.js +2 -5
  114. package/utils/upsert-utils.js +7 -4
@@ -7,13 +7,13 @@ import { ReferenceKind } from '../enums.js';
7
7
  import { Raw } from '../utils/RawQueryFragment.js';
8
8
  import { ValidationError } from '../errors.js';
9
9
  export class ObjectHydrator extends Hydrator {
10
- hydrators = {
10
+ #hydrators = {
11
11
  'full~true': new Map(),
12
12
  'full~false': new Map(),
13
13
  'reference~true': new Map(),
14
14
  'reference~false': new Map(),
15
15
  };
16
- tmpIndex = 0;
16
+ #tmpIndex = 0;
17
17
  /**
18
18
  * @inheritDoc
19
19
  */
@@ -41,7 +41,7 @@ export class ObjectHydrator extends Hydrator {
41
41
  */
42
42
  getEntityHydrator(meta, type, normalizeAccessors = false) {
43
43
  const key = `${type}~${normalizeAccessors}`;
44
- const exists = this.hydrators[key].get(meta.class);
44
+ const exists = this.#hydrators[key].get(meta.class);
45
45
  if (exists) {
46
46
  return exists;
47
47
  }
@@ -66,9 +66,12 @@ export class ObjectHydrator extends Hydrator {
66
66
  const hydrateScalar = (prop, path, dataKey) => {
67
67
  const entityKey = path.map(k => this.wrap(k)).join('');
68
68
  const tz = this.platform.getTimezone();
69
- const convertorKey = path.filter(k => !k.match(/\[idx_\d+]/)).map(k => this.safeKey(k)).join('_');
69
+ const convertorKey = path
70
+ .filter(k => !/\[idx_\d+]/.exec(k))
71
+ .map(k => this.safeKey(k))
72
+ .join('_');
70
73
  const ret = [];
71
- const idx = this.tmpIndex++;
74
+ const idx = this.#tmpIndex++;
72
75
  const nullVal = this.config.get('forceUndefined') ? 'undefined' : 'null';
73
76
  if (prop.getter && !prop.setter && prop.persist === false) {
74
77
  return [];
@@ -139,13 +142,15 @@ export class ObjectHydrator extends Hydrator {
139
142
  ret.push(` if (data${dataKey} === null) {\n entity${entityKey} = ${nullVal};`);
140
143
  ret.push(` } else if (typeof data${dataKey} !== 'undefined') {`);
141
144
  // For polymorphic: instanceof check; for regular: isPrimaryKey() check
142
- const pkCheck = prop.polymorphic ? `data${dataKey} instanceof PolymorphicRef` : `isPrimaryKey(data${dataKey}, true)`;
145
+ const pkCheck = prop.polymorphic
146
+ ? `data${dataKey} instanceof PolymorphicRef`
147
+ : `isPrimaryKey(data${dataKey}, true)`;
143
148
  ret.push(` if (${pkCheck}) {`);
144
149
  // When targetKey is set, pass the key option to createReference so it uses the alternate key
145
150
  const keyOption = prop.targetKey ? `, key: '${prop.targetKey}'` : '';
146
151
  if (prop.polymorphic) {
147
152
  // For polymorphic: target class from discriminator map, PK from data.id
148
- const discriminatorMapKey = this.safeKey(`discriminatorMap_${prop.name}_${this.tmpIndex++}`);
153
+ const discriminatorMapKey = this.safeKey(`discriminatorMap_${prop.name}_${this.#tmpIndex++}`);
149
154
  context.set(discriminatorMapKey, prop.discriminatorMap);
150
155
  ret.push(` const targetClass = ${discriminatorMapKey}[data${dataKey}.discriminator];`);
151
156
  ret.push(` if (!targetClass) throw new ValidationError(\`Unknown discriminator value '\${data${dataKey}.discriminator}' for polymorphic relation '${prop.name}'. Valid values: \${Object.keys(${discriminatorMapKey}).join(', ')}\`);`);
@@ -158,7 +163,7 @@ export class ObjectHydrator extends Hydrator {
158
163
  }
159
164
  else {
160
165
  // For regular: fixed target class, PK is the data itself
161
- const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.tmpIndex++}`);
166
+ const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.#tmpIndex++}`);
162
167
  context.set(targetKey, prop.targetMeta.class);
163
168
  if (prop.ref) {
164
169
  ret.push(` entity${entityKey} = Reference.create(factory.createReference(${targetKey}, data${dataKey}, { merge: true, convertCustomTypes, normalizeAccessors, schema${keyOption} }));`);
@@ -174,7 +179,7 @@ export class ObjectHydrator extends Hydrator {
174
179
  hydrateTargetExpr = `data${dataKey}.constructor`;
175
180
  }
176
181
  else {
177
- const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.tmpIndex++}`);
182
+ const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.#tmpIndex++}`);
178
183
  context.set(targetKey, prop.targetMeta.class);
179
184
  hydrateTargetExpr = targetKey;
180
185
  }
@@ -232,7 +237,10 @@ export class ObjectHydrator extends Hydrator {
232
237
  return ret;
233
238
  };
234
239
  const registerEmbeddedPrototype = (prop, path) => {
235
- const convertorKey = path.filter(k => !k.match(/\[idx_\d+]/)).map(k => this.safeKey(k)).join('_');
240
+ const convertorKey = path
241
+ .filter(k => !/\[idx_\d+]/.exec(k))
242
+ .map(k => this.safeKey(k))
243
+ .join('_');
236
244
  if (prop.targetMeta?.polymorphs) {
237
245
  prop.targetMeta.polymorphs.forEach(meta => {
238
246
  context.set(`prototype_${convertorKey}_${meta.className}`, meta.prototype);
@@ -279,7 +287,7 @@ export class ObjectHydrator extends Hydrator {
279
287
  else {
280
288
  ret.push(` const embeddedData = {`);
281
289
  for (const childProp of Object.values(prop.embeddedProps)) {
282
- const key = childProp.embedded[1].match(/^\w+$/) ? childProp.embedded[1] : `'${childProp.embedded[1]}'`;
290
+ const key = /^\w+$/.exec(childProp.embedded[1]) ? childProp.embedded[1] : `'${childProp.embedded[1]}'`;
283
291
  ret.push(` ${key}: data${this.wrap(childProp.name)},`);
284
292
  }
285
293
  ret.push(` };`);
@@ -297,7 +305,9 @@ export class ObjectHydrator extends Hydrator {
297
305
  meta.props
298
306
  .filter(p => p.embedded?.[0] === prop.name)
299
307
  .forEach(childProp => {
300
- const childDataKey = prop.object ? dataKey + this.wrap(childProp.embedded[1]) : this.wrap(childProp.name);
308
+ const childDataKey = prop.object
309
+ ? dataKey + this.wrap(childProp.embedded[1])
310
+ : this.wrap(childProp.name);
301
311
  const prop2 = childMeta.properties[childProp.embedded[1]];
302
312
  const prop3 = {
303
313
  ...prop2,
@@ -305,14 +315,15 @@ export class ObjectHydrator extends Hydrator {
305
315
  embedded: childProp.embedded,
306
316
  embeddedProps: childProp.embeddedProps,
307
317
  };
308
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
309
- ret.push(...hydrateProperty(prop3, childProp.object, [...path, childProp.embedded[1]], childDataKey).map(l => ' ' + l));
318
+ ret.push(
319
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define, no-use-before-define
320
+ ...hydrateProperty(prop3, childProp.object, [...path, childProp.embedded[1]], childDataKey).map(l => ' ' + l));
310
321
  });
311
322
  ret.push(` }`);
312
323
  });
313
324
  }
314
325
  else {
315
- const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.tmpIndex++}`);
326
+ const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.#tmpIndex++}`);
316
327
  context.set(targetKey, prop.targetMeta.class);
317
328
  ret.push(` if (entity${entityKey} == null) {`);
318
329
  ret.push(` entity${entityKey} = factory.createEmbeddable(${targetKey}, embeddedData, { newEntity, convertCustomTypes, normalizeAccessors });`);
@@ -321,8 +332,9 @@ export class ObjectHydrator extends Hydrator {
321
332
  .filter(p => p.embedded?.[0] === prop.name)
322
333
  .forEach(childProp => {
323
334
  const childDataKey = prop.object ? dataKey + this.wrap(childProp.embedded[1]) : this.wrap(childProp.name);
324
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
325
- ret.push(...hydrateProperty(childProp, prop.object, [...path, childProp.embedded[1]], childDataKey).map(l => ' ' + l));
335
+ ret.push(
336
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define, no-use-before-define
337
+ ...hydrateProperty(childProp, prop.object, [...path, childProp.embedded[1]], childDataKey).map(l => ' ' + l));
326
338
  });
327
339
  }
328
340
  /* v8 ignore next */
@@ -340,7 +352,7 @@ export class ObjectHydrator extends Hydrator {
340
352
  const hydrateEmbeddedArray = (prop, path, dataKey) => {
341
353
  const entityKey = path.map(k => this.wrap(k)).join('');
342
354
  const ret = [];
343
- const idx = this.tmpIndex++;
355
+ const idx = this.#tmpIndex++;
344
356
  registerEmbeddedPrototype(prop, path);
345
357
  parseObjectEmbeddable(prop, dataKey, ret);
346
358
  ret.push(` if (Array.isArray(data${dataKey})) {`);
@@ -353,7 +365,8 @@ export class ObjectHydrator extends Hydrator {
353
365
  };
354
366
  const hydrateProperty = (prop, object = prop.object, path = [prop.name], dataKey) => {
355
367
  const entityKey = path.map(k => this.wrap(k)).join('');
356
- dataKey = dataKey ?? (object ? entityKey : this.wrap(normalizeAccessors ? (prop.accessor ?? prop.name) : prop.name));
368
+ dataKey =
369
+ dataKey ?? (object ? entityKey : this.wrap(normalizeAccessors ? (prop.accessor ?? prop.name) : prop.name));
357
370
  const ret = [];
358
371
  if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) && !prop.mapToPk) {
359
372
  ret.push(...hydrateToOne(prop, dataKey, entityKey));
@@ -372,7 +385,8 @@ export class ObjectHydrator extends Hydrator {
372
385
  }
373
386
  }
374
387
  }
375
- else { // ReferenceKind.SCALAR
388
+ else {
389
+ // ReferenceKind.SCALAR
376
390
  ret.push(...hydrateScalar(prop, path, dataKey));
377
391
  }
378
392
  if (this.config.get('forceUndefined')) {
@@ -383,12 +397,12 @@ export class ObjectHydrator extends Hydrator {
383
397
  for (const prop of props) {
384
398
  lines.push(...hydrateProperty(prop));
385
399
  }
386
- const code = `// compiled hydrator for entity ${meta.className} (${type + normalizeAccessors ? ' normalized' : ''})\n`
387
- + `return function(entity, data, factory, newEntity, convertCustomTypes, schema, parentSchema, normalizeAccessors) {\n`
388
- + `${lines.join('\n')}\n}`;
400
+ const code = `// compiled hydrator for entity ${meta.className} (${type + normalizeAccessors ? ' normalized' : ''})\n` +
401
+ `return function(entity, data, factory, newEntity, convertCustomTypes, schema, parentSchema, normalizeAccessors) {\n` +
402
+ `${lines.join('\n')}\n}`;
389
403
  const fnKey = `hydrator-${meta.uniqueName}-${type}-${normalizeAccessors}`;
390
404
  const hydrator = Utils.createFunction(context, code, this.config.get('compiledFunctions'), fnKey);
391
- this.hydrators[key].set(meta.class, hydrator);
405
+ this.#hydrators[key].set(meta.class, hydrator);
392
406
  return hydrator;
393
407
  }
394
408
  createCollectionItemMapper(prop, context) {
@@ -401,7 +415,7 @@ export class ObjectHydrator extends Hydrator {
401
415
  lines.push(` value = { ...value, ['${prop2.name}']: Reference.wrapReference(entity, { ref: ${prop2.ref} }) };`);
402
416
  lines.push(` }`);
403
417
  }
404
- const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.tmpIndex++}`);
418
+ const targetKey = this.safeKey(`${prop.targetMeta.tableName}_${this.#tmpIndex++}`);
405
419
  context.set(targetKey, prop.targetMeta.class);
406
420
  lines.push(` if (isPrimaryKey(value, ${meta.compositePK})) return factory.createReference(${targetKey}, value, { convertCustomTypes, schema, normalizeAccessors, merge: true });`);
407
421
  lines.push(` if (value && value.__entity) return value;`);
@@ -410,10 +424,10 @@ export class ObjectHydrator extends Hydrator {
410
424
  return lines;
411
425
  }
412
426
  wrap(key) {
413
- if (key.match(/^\[.*]$/)) {
427
+ if (/^\[.*]$/.exec(key)) {
414
428
  return key;
415
429
  }
416
- return key.match(/^\w+$/) ? `.${key}` : `['${key}']`;
430
+ return /^\w+$/.exec(key) ? `.${key}` : `['${key}']`;
417
431
  }
418
432
  safeKey(key) {
419
433
  return key.replace(/\W/g, '_');
package/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * @packageDocumentation
3
3
  * @module core
4
4
  */
5
- export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, EntityName } from './typings.js';
5
+ export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, EntityName, } from './typings.js';
6
6
  export type { CompiledFunctions, Constructor, ConnectionType, Dictionary, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, InferEntityName, EntityData, Highlighter, MaybePromise, AnyEntity, EntityClass, EntityProperty, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, MigratorEvent, GetRepository, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, EntityDTOFlat, EntityDTOProp, SerializeDTO, MigrationDiff, GenerateOptions, FilterObject, IMigrationRunner, IEntityGenerator, ISeedManager, SeederObject, IMigratorStorage, RequiredEntityData, CheckCallback, IndexCallback, FormulaCallback, FormulaTable, SchemaTable, SchemaColumns, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, MigrationInfo, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, EntityDataValue, FilterKey, EntityType, FromEntityType, Selected, IsSubset, EntityProps, ExpandProperty, ExpandScalar, FilterItemValue, ExpandQuery, Scalar, ExpandHint, FilterValue, MergeLoaded, MergeSelected, TypeConfig, AnyString, ClearDatabaseOptions, CreateSchemaOptions, EnsureDatabaseOptions, UpdateSchemaOptions, DropSchemaOptions, RefreshDatabaseOptions, AutoPath, UnboxArray, MetadataProcessor, ImportsResolver, RequiredNullable, DefineConfig, Opt, Hidden, EntitySchemaWithMeta, InferEntity, CheckConstraint, GeneratedColumnCallback, FilterDef, EntityCtor, Subquery, PopulateHintOptions, Prefixes, } from './typings.js';
7
7
  export * from './enums.js';
8
8
  export * from './errors.js';
package/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @packageDocumentation
3
3
  * @module core
4
4
  */
5
- export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, EntityName } from './typings.js';
5
+ export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, EntityName, } from './typings.js';
6
6
  export * from './enums.js';
7
7
  export * from './errors.js';
8
8
  export * from './exceptions.js';
@@ -29,9 +29,7 @@ export class DefaultLogger {
29
29
  if (context?.level === 'warning') {
30
30
  message = colors.yellow(message);
31
31
  }
32
- const label = context?.label
33
- ? colors.cyan(`(${context.label}) `)
34
- : '';
32
+ const label = context?.label ? colors.cyan(`(${context.label}) `) : '';
35
33
  this.writer(colors.grey(`[${namespace}] `) + label + message);
36
34
  }
37
35
  /**
@@ -60,8 +58,8 @@ export class DefaultLogger {
60
58
  if (namespace === 'deprecated') {
61
59
  const { ignoreDeprecations = false } = this.options;
62
60
  return Array.isArray(ignoreDeprecations)
63
- /* v8 ignore next */
64
- ? !ignoreDeprecations.includes(context?.label ?? '')
61
+ ? /* v8 ignore next */
62
+ !ignoreDeprecations.includes(context?.label ?? '')
65
63
  : !ignoreDeprecations;
66
64
  }
67
65
  return !!debugMode && (!Array.isArray(debugMode) || debugMode.includes(namespace));
@@ -70,7 +68,8 @@ export class DefaultLogger {
70
68
  * @inheritDoc
71
69
  */
72
70
  logQuery(context) {
73
- if (!this.isEnabled('query', context)) {
71
+ const namespace = context.namespace ?? 'query';
72
+ if (!this.isEnabled(namespace, context)) {
74
73
  return;
75
74
  }
76
75
  /* v8 ignore next */
@@ -88,7 +87,7 @@ export class DefaultLogger {
88
87
  if (this.usesReplicas && context.connection) {
89
88
  msg += colors.cyan(` (via ${context.connection.type} connection '${context.connection.name}')`);
90
89
  }
91
- return this.log('query', msg, context);
90
+ return this.log(namespace, msg, context);
92
91
  }
93
92
  static create(options) {
94
93
  return new DefaultLogger(options);
@@ -22,10 +22,11 @@ export interface Logger {
22
22
  setDebugMode(debugMode: boolean | LoggerNamespace[]): void;
23
23
  isEnabled(namespace: LoggerNamespace, context?: LogContext): boolean;
24
24
  }
25
- export type LoggerNamespace = 'query' | 'query-params' | 'schema' | 'discovery' | 'info' | 'deprecated';
25
+ export type LoggerNamespace = 'query' | 'query-params' | 'schema' | 'discovery' | 'info' | 'deprecated' | 'slow-query';
26
26
  export interface LogContext extends Dictionary {
27
27
  query?: string;
28
28
  label?: string;
29
+ namespace?: LoggerNamespace;
29
30
  params?: readonly unknown[];
30
31
  took?: number;
31
32
  results?: number;
package/logging/colors.js CHANGED
@@ -1,10 +1,7 @@
1
1
  import { getEnv } from '../utils/env-vars.js';
2
2
  const bool = (k) => ['true', 't', '1'].includes(getEnv(k)?.toLowerCase() ?? '');
3
- const boolIfDefined = (k) => getEnv(k) != null ? bool(k) : true;
4
- const enabled = () => !bool('NO_COLOR')
5
- && !bool('MIKRO_ORM_NO_COLOR')
6
- && boolIfDefined('FORCE_COLOR')
7
- && boolIfDefined('MIKRO_ORM_COLORS');
3
+ const boolIfDefined = (k) => (getEnv(k) != null ? bool(k) : true);
4
+ const enabled = () => !bool('NO_COLOR') && !bool('MIKRO_ORM_NO_COLOR') && boolIfDefined('FORCE_COLOR') && boolIfDefined('MIKRO_ORM_COLORS');
8
5
  const wrap = (fn) => (text) => enabled() ? fn(text) : text;
9
6
  /** @internal */
10
7
  export const colors = {
@@ -1,5 +1,5 @@
1
1
  export * from './colors.js';
2
- export * from './Logger.js';
2
+ export type * from './Logger.js';
3
3
  export * from './DefaultLogger.js';
4
4
  export * from './SimpleLogger.js';
5
5
  export * from './inspect.js';
package/logging/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './colors.js';
2
- export * from './Logger.js';
3
2
  export * from './DefaultLogger.js';
4
3
  export * from './SimpleLogger.js';
5
4
  export * from './inspect.js';
@@ -1,6 +1,6 @@
1
1
  import { EntityMetadata, type AnyEntity, type EntityKey, type Constructor, type DeepPartial, type EntityName, type EntityProperty, type CleanKeys, type ExpandProperty, type IsNever, type EntityCtor } from '../typings.js';
2
2
  import { type EventType, ReferenceKind } from '../enums.js';
3
- import type { EventSubscriber } from '../events/EventSubscriber.js';
3
+ import type { EventArgs } from '../events/EventSubscriber.js';
4
4
  import { Type } from '../types/Type.js';
5
5
  import type { PropertyOptions, ManyToOneOptions, OneToOneOptions, OneToManyOptions, ManyToManyOptions, EmbeddedOptions, EnumOptions, PrimaryKeyOptions, SerializedPrimaryKeyOptions, IndexOptions, UniqueOptions } from './types.js';
6
6
  type TypeType = string | NumberConstructor | StringConstructor | BooleanConstructor | DateConstructor | ArrayConstructor | Constructor<Type<any>> | Type<any>;
@@ -47,7 +47,7 @@ export declare class EntitySchema<Entity = any, Base = never, Class extends Enti
47
47
  * When schema links the entity class via `class` option, this registry allows the lookup from opposite side,
48
48
  * so we can use the class in `entities` option just like the EntitySchema instance.
49
49
  */
50
- static REGISTRY: Map<Partial<any>, EntitySchema<any, never, EntityCtor<any>>>;
50
+ static REGISTRY: Map<AnyEntity, EntitySchema>;
51
51
  /** @internal Type-level marker for fast entity type inference */
52
52
  readonly '~entity': Entity;
53
53
  private readonly _meta;
@@ -108,6 +108,6 @@ export declare class EntitySchema<Entity = any, Base = never, Class extends Enti
108
108
  * });
109
109
  * ```
110
110
  */
111
- addHook<Event extends EventType | `${EventType}`, T extends Entity = Entity>(event: Event, handler: NonNullable<EventSubscriber<T>[Event]>): this;
111
+ addHook<T extends Entity = Entity>(event: EventType | `${EventType}`, handler: (args: EventArgs<T>) => void | Promise<void>): this;
112
112
  }
113
113
  export {};
@@ -34,7 +34,12 @@ export class EntitySchema {
34
34
  }
35
35
  addProperty(name, type, options = {}) {
36
36
  this.renameCompositeOptions(name, options);
37
- const prop = { name, kind: ReferenceKind.SCALAR, ...options, ...this.normalizeType(options, type) };
37
+ const prop = {
38
+ name,
39
+ kind: ReferenceKind.SCALAR,
40
+ ...options,
41
+ ...this.normalizeType(options, type),
42
+ };
38
43
  if (type && Type.isMappedType(type.prototype)) {
39
44
  prop.type = type;
40
45
  }
@@ -299,7 +304,12 @@ export class EntitySchema {
299
304
  }
300
305
  else if (options.entity) {
301
306
  const tmp = options.entity();
302
- type = options.type = Array.isArray(tmp) ? tmp.map(t => Utils.className(t)).sort().join(' | ') : Utils.className(tmp);
307
+ type = options.type = Array.isArray(tmp)
308
+ ? tmp
309
+ .map(t => Utils.className(t))
310
+ .sort()
311
+ .join(' | ')
312
+ : Utils.className(tmp);
303
313
  const target = tmp instanceof EntitySchema ? tmp.meta.class : tmp;
304
314
  return { type, target };
305
315
  }
@@ -4,15 +4,7 @@ import { MetadataStorage } from './MetadataStorage.js';
4
4
  import { EntitySchema } from './EntitySchema.js';
5
5
  import type { Platform } from '../platforms/Platform.js';
6
6
  export declare class MetadataDiscovery {
7
- private readonly metadata;
8
- private readonly platform;
9
- private readonly config;
10
- private readonly namingStrategy;
11
- private readonly metadataProvider;
12
- private readonly logger;
13
- private readonly schemaHelper;
14
- private readonly validator;
15
- private readonly discovered;
7
+ #private;
16
8
  constructor(metadata: MetadataStorage, platform: Platform, config: Configuration);
17
9
  discover(preferTs?: boolean): Promise<MetadataStorage>;
18
10
  discoverSync(): MetadataStorage;