@mikro-orm/core 7.0.4 → 7.0.5-dev.1

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 (206) hide show
  1. package/EntityManager.d.ts +583 -884
  2. package/EntityManager.js +1895 -1922
  3. package/MikroORM.d.ts +74 -103
  4. package/MikroORM.js +179 -178
  5. package/README.md +1 -1
  6. package/cache/CacheAdapter.d.ts +36 -36
  7. package/cache/FileCacheAdapter.d.ts +24 -30
  8. package/cache/FileCacheAdapter.js +78 -80
  9. package/cache/GeneratedCacheAdapter.d.ts +20 -18
  10. package/cache/GeneratedCacheAdapter.js +30 -30
  11. package/cache/MemoryCacheAdapter.d.ts +20 -18
  12. package/cache/MemoryCacheAdapter.js +36 -35
  13. package/cache/NullCacheAdapter.d.ts +16 -16
  14. package/cache/NullCacheAdapter.js +24 -24
  15. package/connections/Connection.d.ts +84 -95
  16. package/connections/Connection.js +168 -165
  17. package/drivers/DatabaseDriver.d.ts +80 -186
  18. package/drivers/DatabaseDriver.js +443 -450
  19. package/drivers/IDatabaseDriver.d.ts +301 -440
  20. package/entity/BaseEntity.d.ts +83 -120
  21. package/entity/BaseEntity.js +43 -43
  22. package/entity/Collection.d.ts +179 -212
  23. package/entity/Collection.js +721 -727
  24. package/entity/EntityAssigner.d.ts +77 -88
  25. package/entity/EntityAssigner.js +230 -231
  26. package/entity/EntityFactory.d.ts +54 -66
  27. package/entity/EntityFactory.js +383 -425
  28. package/entity/EntityHelper.d.ts +22 -34
  29. package/entity/EntityHelper.js +267 -280
  30. package/entity/EntityIdentifier.d.ts +4 -4
  31. package/entity/EntityIdentifier.js +10 -10
  32. package/entity/EntityLoader.d.ts +72 -98
  33. package/entity/EntityLoader.js +723 -753
  34. package/entity/EntityRepository.d.ts +201 -316
  35. package/entity/EntityRepository.js +213 -213
  36. package/entity/PolymorphicRef.d.ts +5 -5
  37. package/entity/PolymorphicRef.js +10 -10
  38. package/entity/Reference.d.ts +82 -126
  39. package/entity/Reference.js +274 -278
  40. package/entity/WrappedEntity.d.ts +72 -115
  41. package/entity/WrappedEntity.js +166 -168
  42. package/entity/defineEntity.d.ts +636 -1315
  43. package/entity/defineEntity.js +518 -527
  44. package/entity/utils.d.ts +3 -13
  45. package/entity/utils.js +73 -71
  46. package/entity/validators.js +43 -43
  47. package/entity/wrap.js +8 -8
  48. package/enums.d.ts +253 -258
  49. package/enums.js +252 -251
  50. package/errors.d.ts +72 -114
  51. package/errors.js +253 -350
  52. package/events/EventManager.d.ts +14 -26
  53. package/events/EventManager.js +77 -79
  54. package/events/EventSubscriber.d.ts +29 -29
  55. package/events/TransactionEventBroadcaster.d.ts +8 -15
  56. package/events/TransactionEventBroadcaster.js +14 -14
  57. package/exceptions.d.ts +40 -23
  58. package/exceptions.js +52 -35
  59. package/hydration/Hydrator.d.ts +17 -42
  60. package/hydration/Hydrator.js +43 -43
  61. package/hydration/ObjectHydrator.d.ts +17 -50
  62. package/hydration/ObjectHydrator.js +416 -481
  63. package/index.d.ts +2 -116
  64. package/index.js +1 -10
  65. package/logging/DefaultLogger.d.ts +32 -34
  66. package/logging/DefaultLogger.js +86 -86
  67. package/logging/Logger.d.ts +41 -41
  68. package/logging/SimpleLogger.d.ts +11 -13
  69. package/logging/SimpleLogger.js +22 -22
  70. package/logging/colors.d.ts +6 -6
  71. package/logging/colors.js +10 -11
  72. package/logging/inspect.js +7 -7
  73. package/metadata/EntitySchema.d.ts +127 -211
  74. package/metadata/EntitySchema.js +398 -397
  75. package/metadata/MetadataDiscovery.d.ts +114 -114
  76. package/metadata/MetadataDiscovery.js +1870 -1951
  77. package/metadata/MetadataProvider.d.ts +21 -24
  78. package/metadata/MetadataProvider.js +84 -82
  79. package/metadata/MetadataStorage.d.ts +32 -38
  80. package/metadata/MetadataStorage.js +118 -118
  81. package/metadata/MetadataValidator.d.ts +39 -39
  82. package/metadata/MetadataValidator.js +338 -381
  83. package/metadata/discover-entities.d.ts +2 -5
  84. package/metadata/discover-entities.js +37 -35
  85. package/metadata/types.d.ts +531 -615
  86. package/naming-strategy/AbstractNamingStrategy.d.ts +39 -54
  87. package/naming-strategy/AbstractNamingStrategy.js +85 -90
  88. package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
  89. package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
  90. package/naming-strategy/MongoNamingStrategy.d.ts +6 -6
  91. package/naming-strategy/MongoNamingStrategy.js +18 -18
  92. package/naming-strategy/NamingStrategy.d.ts +99 -109
  93. package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
  94. package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
  95. package/not-supported.js +4 -7
  96. package/package.json +1 -1
  97. package/platforms/ExceptionConverter.d.ts +1 -1
  98. package/platforms/ExceptionConverter.js +4 -4
  99. package/platforms/Platform.d.ts +301 -310
  100. package/platforms/Platform.js +640 -663
  101. package/serialization/EntitySerializer.d.ts +26 -49
  102. package/serialization/EntitySerializer.js +218 -224
  103. package/serialization/EntityTransformer.d.ts +6 -10
  104. package/serialization/EntityTransformer.js +217 -219
  105. package/serialization/SerializationContext.d.ts +23 -27
  106. package/serialization/SerializationContext.js +105 -105
  107. package/types/ArrayType.d.ts +8 -8
  108. package/types/ArrayType.js +33 -33
  109. package/types/BigIntType.d.ts +10 -17
  110. package/types/BigIntType.js +37 -37
  111. package/types/BlobType.d.ts +3 -3
  112. package/types/BlobType.js +13 -13
  113. package/types/BooleanType.d.ts +4 -4
  114. package/types/BooleanType.js +12 -12
  115. package/types/CharacterType.d.ts +2 -2
  116. package/types/CharacterType.js +6 -6
  117. package/types/DateTimeType.d.ts +5 -5
  118. package/types/DateTimeType.js +15 -15
  119. package/types/DateType.d.ts +5 -5
  120. package/types/DateType.js +15 -15
  121. package/types/DecimalType.d.ts +7 -7
  122. package/types/DecimalType.js +26 -26
  123. package/types/DoubleType.d.ts +3 -3
  124. package/types/DoubleType.js +12 -12
  125. package/types/EnumArrayType.d.ts +5 -5
  126. package/types/EnumArrayType.js +24 -24
  127. package/types/EnumType.d.ts +3 -3
  128. package/types/EnumType.js +11 -11
  129. package/types/FloatType.d.ts +3 -3
  130. package/types/FloatType.js +9 -9
  131. package/types/IntegerType.d.ts +3 -3
  132. package/types/IntegerType.js +9 -9
  133. package/types/IntervalType.d.ts +4 -4
  134. package/types/IntervalType.js +12 -12
  135. package/types/JsonType.d.ts +8 -8
  136. package/types/JsonType.js +32 -32
  137. package/types/MediumIntType.d.ts +1 -1
  138. package/types/MediumIntType.js +3 -3
  139. package/types/SmallIntType.d.ts +3 -3
  140. package/types/SmallIntType.js +9 -9
  141. package/types/StringType.d.ts +4 -4
  142. package/types/StringType.js +12 -12
  143. package/types/TextType.d.ts +3 -3
  144. package/types/TextType.js +9 -9
  145. package/types/TimeType.d.ts +5 -5
  146. package/types/TimeType.js +17 -17
  147. package/types/TinyIntType.d.ts +3 -3
  148. package/types/TinyIntType.js +10 -10
  149. package/types/Type.d.ts +79 -83
  150. package/types/Type.js +82 -82
  151. package/types/Uint8ArrayType.d.ts +4 -4
  152. package/types/Uint8ArrayType.js +21 -21
  153. package/types/UnknownType.d.ts +4 -4
  154. package/types/UnknownType.js +12 -12
  155. package/types/UuidType.d.ts +5 -5
  156. package/types/UuidType.js +19 -19
  157. package/types/index.d.ts +49 -75
  158. package/types/index.js +26 -52
  159. package/typings.d.ts +737 -1250
  160. package/typings.js +231 -244
  161. package/unit-of-work/ChangeSet.d.ts +26 -26
  162. package/unit-of-work/ChangeSet.js +56 -56
  163. package/unit-of-work/ChangeSetComputer.d.ts +12 -12
  164. package/unit-of-work/ChangeSetComputer.js +170 -178
  165. package/unit-of-work/ChangeSetPersister.d.ts +44 -63
  166. package/unit-of-work/ChangeSetPersister.js +421 -442
  167. package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
  168. package/unit-of-work/CommitOrderCalculator.js +88 -89
  169. package/unit-of-work/IdentityMap.d.ts +31 -31
  170. package/unit-of-work/IdentityMap.js +105 -105
  171. package/unit-of-work/UnitOfWork.d.ts +141 -181
  172. package/unit-of-work/UnitOfWork.js +1183 -1200
  173. package/utils/AbstractMigrator.d.ts +91 -111
  174. package/utils/AbstractMigrator.js +275 -275
  175. package/utils/AbstractSchemaGenerator.d.ts +34 -43
  176. package/utils/AbstractSchemaGenerator.js +122 -121
  177. package/utils/AsyncContext.d.ts +3 -3
  178. package/utils/AsyncContext.js +35 -34
  179. package/utils/Configuration.d.ts +808 -852
  180. package/utils/Configuration.js +344 -359
  181. package/utils/Cursor.d.ts +22 -40
  182. package/utils/Cursor.js +127 -135
  183. package/utils/DataloaderUtils.d.ts +43 -58
  184. package/utils/DataloaderUtils.js +198 -203
  185. package/utils/EntityComparator.d.ts +81 -98
  186. package/utils/EntityComparator.js +732 -828
  187. package/utils/NullHighlighter.d.ts +1 -1
  188. package/utils/NullHighlighter.js +3 -3
  189. package/utils/QueryHelper.d.ts +51 -79
  190. package/utils/QueryHelper.js +361 -372
  191. package/utils/RawQueryFragment.d.ts +34 -50
  192. package/utils/RawQueryFragment.js +105 -107
  193. package/utils/RequestContext.d.ts +32 -32
  194. package/utils/RequestContext.js +53 -52
  195. package/utils/TransactionContext.d.ts +16 -16
  196. package/utils/TransactionContext.js +27 -27
  197. package/utils/TransactionManager.d.ts +58 -58
  198. package/utils/TransactionManager.js +197 -199
  199. package/utils/Utils.d.ts +145 -204
  200. package/utils/Utils.js +812 -812
  201. package/utils/clone.js +113 -104
  202. package/utils/env-vars.js +88 -90
  203. package/utils/fs-utils.d.ts +15 -15
  204. package/utils/fs-utils.js +181 -180
  205. package/utils/upsert-utils.d.ts +5 -20
  206. package/utils/upsert-utils.js +116 -114
package/index.d.ts CHANGED
@@ -2,122 +2,8 @@
2
2
  * @packageDocumentation
3
3
  * @module core
4
4
  */
5
- export {
6
- EntityMetadata,
7
- PrimaryKeyProp,
8
- EntityRepositoryType,
9
- OptionalProps,
10
- EagerProps,
11
- HiddenProps,
12
- Config,
13
- EntityName,
14
- } from './typings.js';
15
- export type {
16
- CompiledFunctions,
17
- Constructor,
18
- ConnectionType,
19
- Dictionary,
20
- Primary,
21
- IPrimaryKey,
22
- ObjectQuery,
23
- FilterQuery,
24
- IWrappedEntity,
25
- InferEntityName,
26
- EntityData,
27
- Highlighter,
28
- MaybePromise,
29
- AnyEntity,
30
- EntityClass,
31
- EntityProperty,
32
- PopulateOptions,
33
- Populate,
34
- Loaded,
35
- New,
36
- LoadedReference,
37
- LoadedCollection,
38
- IMigrator,
39
- IMigrationGenerator,
40
- MigratorEvent,
41
- GetRepository,
42
- MigrationObject,
43
- DeepPartial,
44
- PrimaryProperty,
45
- Cast,
46
- IsUnknown,
47
- EntityDictionary,
48
- EntityDTO,
49
- EntityDTOFlat,
50
- EntityDTOProp,
51
- SerializeDTO,
52
- MigrationDiff,
53
- GenerateOptions,
54
- FilterObject,
55
- IMigrationRunner,
56
- IEntityGenerator,
57
- ISeedManager,
58
- SeederObject,
59
- IMigratorStorage,
60
- RequiredEntityData,
61
- CheckCallback,
62
- IndexCallback,
63
- FormulaCallback,
64
- FormulaTable,
65
- SchemaTable,
66
- SchemaColumns,
67
- SimpleColumnMeta,
68
- Rel,
69
- Ref,
70
- ScalarRef,
71
- EntityRef,
72
- ISchemaGenerator,
73
- MigrationInfo,
74
- MigrateOptions,
75
- MigrationResult,
76
- MigrationRow,
77
- EntityKey,
78
- EntityValue,
79
- EntityDataValue,
80
- FilterKey,
81
- EntityType,
82
- FromEntityType,
83
- Selected,
84
- IsSubset,
85
- EntityProps,
86
- ExpandProperty,
87
- ExpandScalar,
88
- FilterItemValue,
89
- ExpandQuery,
90
- Scalar,
91
- ExpandHint,
92
- FilterValue,
93
- MergeLoaded,
94
- MergeSelected,
95
- TypeConfig,
96
- AnyString,
97
- ClearDatabaseOptions,
98
- CreateSchemaOptions,
99
- EnsureDatabaseOptions,
100
- UpdateSchemaOptions,
101
- DropSchemaOptions,
102
- RefreshDatabaseOptions,
103
- AutoPath,
104
- UnboxArray,
105
- MetadataProcessor,
106
- ImportsResolver,
107
- RequiredNullable,
108
- DefineConfig,
109
- Opt,
110
- Hidden,
111
- EntitySchemaWithMeta,
112
- InferEntity,
113
- CheckConstraint,
114
- GeneratedColumnCallback,
115
- FilterDef,
116
- EntityCtor,
117
- Subquery,
118
- PopulateHintOptions,
119
- Prefixes,
120
- } from './typings.js';
5
+ export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, EntityName, } from './typings.js';
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';
121
7
  export * from './enums.js';
122
8
  export * from './errors.js';
123
9
  export * from './exceptions.js';
package/index.js CHANGED
@@ -2,16 +2,7 @@
2
2
  * @packageDocumentation
3
3
  * @module core
4
4
  */
5
- export {
6
- EntityMetadata,
7
- PrimaryKeyProp,
8
- EntityRepositoryType,
9
- OptionalProps,
10
- EagerProps,
11
- HiddenProps,
12
- Config,
13
- EntityName,
14
- } from './typings.js';
5
+ export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, EntityName, } from './typings.js';
15
6
  export * from './enums.js';
16
7
  export * from './errors.js';
17
8
  export * from './exceptions.js';
@@ -1,38 +1,36 @@
1
1
  import type { Logger, LoggerNamespace, LogContext, LoggerOptions } from './Logger.js';
2
2
  /** Default logger implementation with colored output, query formatting, and namespace-based filtering. */
3
3
  export declare class DefaultLogger implements Logger {
4
- private readonly options;
5
- debugMode: boolean | LoggerNamespace[];
6
- readonly writer: (message: string) => void;
7
- private readonly usesReplicas?;
8
- private readonly highlighter?;
9
- constructor(options: LoggerOptions);
10
- /**
11
- * @inheritDoc
12
- */
13
- log(namespace: LoggerNamespace, message: string, context?: LogContext): void;
14
- /**
15
- * @inheritDoc
16
- */
17
- error(namespace: LoggerNamespace, message: string, context?: LogContext): void;
18
- /**
19
- * @inheritDoc
20
- */
21
- warn(namespace: LoggerNamespace, message: string, context?: LogContext): void;
22
- /**
23
- * @inheritDoc
24
- */
25
- setDebugMode(debugMode: boolean | LoggerNamespace[]): void;
26
- /** Checks whether logging is enabled for the given namespace, considering context overrides. */
27
- isEnabled(namespace: LoggerNamespace, context?: LogContext): boolean;
28
- /**
29
- * @inheritDoc
30
- */
31
- logQuery(
32
- context: {
33
- query: string;
34
- } & LogContext,
35
- ): void;
36
- /** Factory method for creating a new DefaultLogger instance. */
37
- static create(this: void, options: LoggerOptions): DefaultLogger;
4
+ private readonly options;
5
+ debugMode: boolean | LoggerNamespace[];
6
+ readonly writer: (message: string) => void;
7
+ private readonly usesReplicas?;
8
+ private readonly highlighter?;
9
+ constructor(options: LoggerOptions);
10
+ /**
11
+ * @inheritDoc
12
+ */
13
+ log(namespace: LoggerNamespace, message: string, context?: LogContext): void;
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ error(namespace: LoggerNamespace, message: string, context?: LogContext): void;
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ warn(namespace: LoggerNamespace, message: string, context?: LogContext): void;
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ setDebugMode(debugMode: boolean | LoggerNamespace[]): void;
26
+ /** Checks whether logging is enabled for the given namespace, considering context overrides. */
27
+ isEnabled(namespace: LoggerNamespace, context?: LogContext): boolean;
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ logQuery(context: {
32
+ query: string;
33
+ } & LogContext): void;
34
+ /** Factory method for creating a new DefaultLogger instance. */
35
+ static create(this: void, options: LoggerOptions): DefaultLogger;
38
36
  }
@@ -1,98 +1,98 @@
1
1
  import { colors } from './colors.js';
2
2
  /** Default logger implementation with colored output, query formatting, and namespace-based filtering. */
3
3
  export class DefaultLogger {
4
- options;
5
- debugMode;
6
- writer;
7
- usesReplicas;
8
- highlighter;
9
- constructor(options) {
10
- this.options = options;
11
- this.debugMode = this.options.debugMode ?? false;
12
- this.writer = this.options.writer;
13
- this.usesReplicas = this.options.usesReplicas;
14
- this.highlighter = this.options.highlighter;
15
- }
16
- /**
17
- * @inheritDoc
18
- */
19
- log(namespace, message, context) {
20
- if (!this.isEnabled(namespace, context)) {
21
- return;
4
+ options;
5
+ debugMode;
6
+ writer;
7
+ usesReplicas;
8
+ highlighter;
9
+ constructor(options) {
10
+ this.options = options;
11
+ this.debugMode = this.options.debugMode ?? false;
12
+ this.writer = this.options.writer;
13
+ this.usesReplicas = this.options.usesReplicas;
14
+ this.highlighter = this.options.highlighter;
22
15
  }
23
- // clean up the whitespace
24
- message = message.replace(/\n/g, '').replace(/ +/g, ' ').trim();
25
- // use red for error levels
26
- if (context?.level === 'error') {
27
- message = colors.red(message);
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ log(namespace, message, context) {
20
+ if (!this.isEnabled(namespace, context)) {
21
+ return;
22
+ }
23
+ // clean up the whitespace
24
+ message = message.replace(/\n/g, '').replace(/ +/g, ' ').trim();
25
+ // use red for error levels
26
+ if (context?.level === 'error') {
27
+ message = colors.red(message);
28
+ }
29
+ // use yellow for warning levels
30
+ if (context?.level === 'warning') {
31
+ message = colors.yellow(message);
32
+ }
33
+ const label = context?.label ? colors.cyan(`(${context.label}) `) : '';
34
+ this.writer(colors.grey(`[${namespace}] `) + label + message);
28
35
  }
29
- // use yellow for warning levels
30
- if (context?.level === 'warning') {
31
- message = colors.yellow(message);
36
+ /**
37
+ * @inheritDoc
38
+ */
39
+ error(namespace, message, context) {
40
+ this.log(namespace, message, { ...context, level: 'error' });
32
41
  }
33
- const label = context?.label ? colors.cyan(`(${context.label}) `) : '';
34
- this.writer(colors.grey(`[${namespace}] `) + label + message);
35
- }
36
- /**
37
- * @inheritDoc
38
- */
39
- error(namespace, message, context) {
40
- this.log(namespace, message, { ...context, level: 'error' });
41
- }
42
- /**
43
- * @inheritDoc
44
- */
45
- warn(namespace, message, context) {
46
- this.log(namespace, message, { ...context, level: 'warning' });
47
- }
48
- /**
49
- * @inheritDoc
50
- */
51
- setDebugMode(debugMode) {
52
- this.debugMode = debugMode;
53
- }
54
- /** Checks whether logging is enabled for the given namespace, considering context overrides. */
55
- isEnabled(namespace, context) {
56
- if (context?.enabled !== undefined) {
57
- return context.enabled;
42
+ /**
43
+ * @inheritDoc
44
+ */
45
+ warn(namespace, message, context) {
46
+ this.log(namespace, message, { ...context, level: 'warning' });
58
47
  }
59
- const debugMode = context?.debugMode ?? this.debugMode;
60
- if (namespace === 'deprecated') {
61
- const { ignoreDeprecations = false } = this.options;
62
- return Array.isArray(ignoreDeprecations)
63
- ? /* v8 ignore next */
64
- !ignoreDeprecations.includes(context?.label ?? '')
65
- : !ignoreDeprecations;
48
+ /**
49
+ * @inheritDoc
50
+ */
51
+ setDebugMode(debugMode) {
52
+ this.debugMode = debugMode;
66
53
  }
67
- return !!debugMode && (!Array.isArray(debugMode) || debugMode.includes(namespace));
68
- }
69
- /**
70
- * @inheritDoc
71
- */
72
- logQuery(context) {
73
- const namespace = context.namespace ?? 'query';
74
- if (!this.isEnabled(namespace, context)) {
75
- return;
54
+ /** Checks whether logging is enabled for the given namespace, considering context overrides. */
55
+ isEnabled(namespace, context) {
56
+ if (context?.enabled !== undefined) {
57
+ return context.enabled;
58
+ }
59
+ const debugMode = context?.debugMode ?? this.debugMode;
60
+ if (namespace === 'deprecated') {
61
+ const { ignoreDeprecations = false } = this.options;
62
+ return Array.isArray(ignoreDeprecations)
63
+ ? /* v8 ignore next */
64
+ !ignoreDeprecations.includes(context?.label ?? '')
65
+ : !ignoreDeprecations;
66
+ }
67
+ return !!debugMode && (!Array.isArray(debugMode) || debugMode.includes(namespace));
76
68
  }
77
- /* v8 ignore next */
78
- let msg = this.highlighter?.highlight(context.query) ?? context.query;
79
- if (context.took != null) {
80
- const meta = [`took ${context.took} ms`];
81
- if (context.results != null) {
82
- meta.push(`${context.results} result${context.results === 0 || context.results > 1 ? 's' : ''}`);
83
- }
84
- if (context.affected != null) {
85
- meta.push(`${context.affected} row${context.affected === 0 || context.affected > 1 ? 's' : ''} affected`);
86
- }
87
- msg += colors.grey(` [${meta.join(', ')}]`);
69
+ /**
70
+ * @inheritDoc
71
+ */
72
+ logQuery(context) {
73
+ const namespace = context.namespace ?? 'query';
74
+ if (!this.isEnabled(namespace, context)) {
75
+ return;
76
+ }
77
+ /* v8 ignore next */
78
+ let msg = this.highlighter?.highlight(context.query) ?? context.query;
79
+ if (context.took != null) {
80
+ const meta = [`took ${context.took} ms`];
81
+ if (context.results != null) {
82
+ meta.push(`${context.results} result${context.results === 0 || context.results > 1 ? 's' : ''}`);
83
+ }
84
+ if (context.affected != null) {
85
+ meta.push(`${context.affected} row${context.affected === 0 || context.affected > 1 ? 's' : ''} affected`);
86
+ }
87
+ msg += colors.grey(` [${meta.join(', ')}]`);
88
+ }
89
+ if (this.usesReplicas && context.connection) {
90
+ msg += colors.cyan(` (via ${context.connection.type} connection '${context.connection.name}')`);
91
+ }
92
+ return this.log(namespace, msg, context);
88
93
  }
89
- if (this.usesReplicas && context.connection) {
90
- msg += colors.cyan(` (via ${context.connection.type} connection '${context.connection.name}')`);
94
+ /** Factory method for creating a new DefaultLogger instance. */
95
+ static create(options) {
96
+ return new DefaultLogger(options);
91
97
  }
92
- return this.log(namespace, msg, context);
93
- }
94
- /** Factory method for creating a new DefaultLogger instance. */
95
- static create(options) {
96
- return new DefaultLogger(options);
97
- }
98
98
  }
@@ -1,55 +1,55 @@
1
1
  import type { AnyString, Dictionary, Highlighter } from '../typings.js';
2
2
  /** Interface for ORM logging, supporting namespaced log levels and query logging. */
3
3
  export interface Logger {
4
- /**
5
- * Logs a message inside given namespace.
6
- */
7
- log(namespace: LoggerNamespace | AnyString, message: string, context?: LogContext): void;
8
- /**
9
- * Logs error message inside given namespace.
10
- */
11
- error(namespace: LoggerNamespace | AnyString, message: string, context?: LogContext): void;
12
- /**
13
- * Logs warning message inside given namespace.
14
- */
15
- warn(namespace: LoggerNamespace | AnyString, message: string, context?: LogContext): void;
16
- /**
17
- * Logs a message inside given namespace.
18
- */
19
- logQuery(context: LogContext): void;
20
- /**
21
- * Sets active namespaces. Pass `true` to enable all logging.
22
- */
23
- setDebugMode(debugMode: boolean | LoggerNamespace[]): void;
24
- /** Checks whether logging is enabled for the given namespace. */
25
- isEnabled(namespace: LoggerNamespace, context?: LogContext): boolean;
4
+ /**
5
+ * Logs a message inside given namespace.
6
+ */
7
+ log(namespace: LoggerNamespace | AnyString, message: string, context?: LogContext): void;
8
+ /**
9
+ * Logs error message inside given namespace.
10
+ */
11
+ error(namespace: LoggerNamespace | AnyString, message: string, context?: LogContext): void;
12
+ /**
13
+ * Logs warning message inside given namespace.
14
+ */
15
+ warn(namespace: LoggerNamespace | AnyString, message: string, context?: LogContext): void;
16
+ /**
17
+ * Logs a message inside given namespace.
18
+ */
19
+ logQuery(context: LogContext): void;
20
+ /**
21
+ * Sets active namespaces. Pass `true` to enable all logging.
22
+ */
23
+ setDebugMode(debugMode: boolean | LoggerNamespace[]): void;
24
+ /** Checks whether logging is enabled for the given namespace. */
25
+ isEnabled(namespace: LoggerNamespace, context?: LogContext): boolean;
26
26
  }
27
27
  /** Available logging namespaces that can be individually enabled or disabled. */
28
28
  export type LoggerNamespace = 'query' | 'query-params' | 'schema' | 'discovery' | 'info' | 'deprecated' | 'slow-query';
29
29
  /** Contextual metadata passed alongside log messages, including query details and timing. */
30
30
  export interface LogContext extends Dictionary {
31
- query?: string;
32
- label?: string;
33
- namespace?: LoggerNamespace;
34
- params?: readonly unknown[];
35
- took?: number;
36
- results?: number;
37
- affected?: number;
38
- level?: 'info' | 'warning' | 'error';
39
- enabled?: boolean;
40
- debugMode?: LoggerNamespace[];
41
- connection?: {
42
- type?: string;
43
- name?: string;
44
- };
31
+ query?: string;
32
+ label?: string;
33
+ namespace?: LoggerNamespace;
34
+ params?: readonly unknown[];
35
+ took?: number;
36
+ results?: number;
37
+ affected?: number;
38
+ level?: 'info' | 'warning' | 'error';
39
+ enabled?: boolean;
40
+ debugMode?: LoggerNamespace[];
41
+ connection?: {
42
+ type?: string;
43
+ name?: string;
44
+ };
45
45
  }
46
46
  /** Options for constructing a Logger instance. */
47
47
  export interface LoggerOptions {
48
- writer: (message: string) => void;
49
- debugMode?: boolean | LoggerNamespace[];
50
- ignoreDeprecations?: boolean | string[];
51
- highlighter?: Highlighter;
52
- usesReplicas?: boolean;
48
+ writer: (message: string) => void;
49
+ debugMode?: boolean | LoggerNamespace[];
50
+ ignoreDeprecations?: boolean | string[];
51
+ highlighter?: Highlighter;
52
+ usesReplicas?: boolean;
53
53
  }
54
54
  /**
55
55
  * Logger options to modify format output and overrides, including a label and additional properties that can be accessed by custom loggers.
@@ -4,17 +4,15 @@ import { DefaultLogger } from './DefaultLogger.js';
4
4
  * A basic logger that provides fully formatted output without color
5
5
  */
6
6
  export declare class SimpleLogger extends DefaultLogger {
7
- /**
8
- * @inheritDoc
9
- */
10
- log(namespace: LoggerNamespace, message: string, context?: LogContext): void;
11
- /**
12
- * @inheritDoc
13
- */
14
- logQuery(
15
- context: {
16
- query: string;
17
- } & LogContext,
18
- ): void;
19
- static create(this: void, options: LoggerOptions): SimpleLogger;
7
+ /**
8
+ * @inheritDoc
9
+ */
10
+ log(namespace: LoggerNamespace, message: string, context?: LogContext): void;
11
+ /**
12
+ * @inheritDoc
13
+ */
14
+ logQuery(context: {
15
+ query: string;
16
+ } & LogContext): void;
17
+ static create(this: void, options: LoggerOptions): SimpleLogger;
20
18
  }
@@ -3,28 +3,28 @@ import { DefaultLogger } from './DefaultLogger.js';
3
3
  * A basic logger that provides fully formatted output without color
4
4
  */
5
5
  export class SimpleLogger extends DefaultLogger {
6
- /**
7
- * @inheritDoc
8
- */
9
- log(namespace, message, context) {
10
- if (!this.isEnabled(namespace, context)) {
11
- return;
6
+ /**
7
+ * @inheritDoc
8
+ */
9
+ log(namespace, message, context) {
10
+ if (!this.isEnabled(namespace, context)) {
11
+ return;
12
+ }
13
+ // clean up the whitespace
14
+ message = message.replace(/\n/g, '').replace(/ +/g, ' ').trim();
15
+ const label = context?.label ? `(${context.label}) ` : '';
16
+ this.writer(`[${namespace}] ${label}${message}`);
12
17
  }
13
- // clean up the whitespace
14
- message = message.replace(/\n/g, '').replace(/ +/g, ' ').trim();
15
- const label = context?.label ? `(${context.label}) ` : '';
16
- this.writer(`[${namespace}] ${label}${message}`);
17
- }
18
- /**
19
- * @inheritDoc
20
- */
21
- logQuery(context) {
22
- if (!this.isEnabled('query', context)) {
23
- return;
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ logQuery(context) {
22
+ if (!this.isEnabled('query', context)) {
23
+ return;
24
+ }
25
+ return this.log('query', context.query, context);
26
+ }
27
+ static create(options) {
28
+ return new SimpleLogger(options);
24
29
  }
25
- return this.log('query', context.query, context);
26
- }
27
- static create(options) {
28
- return new SimpleLogger(options);
29
- }
30
30
  }
@@ -1,9 +1,9 @@
1
1
  /** @internal */
2
2
  export declare const colors: {
3
- red: (text: string) => string;
4
- green: (text: string) => string;
5
- yellow: (text: string) => string;
6
- grey: (text: string) => string;
7
- cyan: (text: string) => string;
8
- enabled: () => boolean;
3
+ red: (text: string) => string;
4
+ green: (text: string) => string;
5
+ yellow: (text: string) => string;
6
+ grey: (text: string) => string;
7
+ cyan: (text: string) => string;
8
+ enabled: () => boolean;
9
9
  };
package/logging/colors.js CHANGED
@@ -1,15 +1,14 @@
1
1
  import { getEnv } from '../utils/env-vars.js';
2
- const bool = k => ['true', 't', '1'].includes(getEnv(k)?.toLowerCase() ?? '');
3
- const boolIfDefined = k => (getEnv(k) != null ? bool(k) : true);
4
- const enabled = () =>
5
- !bool('NO_COLOR') && !bool('MIKRO_ORM_NO_COLOR') && boolIfDefined('FORCE_COLOR') && boolIfDefined('MIKRO_ORM_COLORS');
6
- const wrap = fn => text => (enabled() ? fn(text) : text);
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') && !bool('MIKRO_ORM_NO_COLOR') && boolIfDefined('FORCE_COLOR') && boolIfDefined('MIKRO_ORM_COLORS');
5
+ const wrap = (fn) => (text) => enabled() ? fn(text) : text;
7
6
  /** @internal */
8
7
  export const colors = {
9
- red: wrap(text => `\x1B[31m${text}\x1B[39m`),
10
- green: wrap(text => `\x1B[32m${text}\x1B[39m`),
11
- yellow: wrap(text => `\x1B[33m${text}\x1B[39m`),
12
- grey: wrap(text => `\x1B[90m${text}\x1B[39m`),
13
- cyan: wrap(text => `\x1B[36m${text}\x1B[39m`),
14
- enabled,
8
+ red: wrap((text) => `\x1B[31m${text}\x1B[39m`),
9
+ green: wrap((text) => `\x1B[32m${text}\x1B[39m`),
10
+ yellow: wrap((text) => `\x1B[33m${text}\x1B[39m`),
11
+ grey: wrap((text) => `\x1B[90m${text}\x1B[39m`),
12
+ cyan: wrap((text) => `\x1B[36m${text}\x1B[39m`),
13
+ enabled,
15
14
  };
@@ -1,11 +1,11 @@
1
1
  let nodeInspect;
2
2
  /** @internal */
3
3
  export function inspect(value, options) {
4
- nodeInspect ??= globalThis.process?.getBuiltinModule?.('node:util').inspect;
5
- /* v8 ignore else */
6
- if (nodeInspect) {
7
- return nodeInspect(value, options);
8
- }
9
- /* v8 ignore next */
10
- return JSON.stringify(value, null, 2);
4
+ nodeInspect ??= globalThis.process?.getBuiltinModule?.('node:util').inspect;
5
+ /* v8 ignore else */
6
+ if (nodeInspect) {
7
+ return nodeInspect(value, options);
8
+ }
9
+ /* v8 ignore next */
10
+ return JSON.stringify(value, null, 2);
11
11
  }