@mikro-orm/core 7.0.4-dev.9 → 7.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/EntityManager.d.ts +884 -583
  2. package/EntityManager.js +1922 -1895
  3. package/MikroORM.d.ts +103 -74
  4. package/MikroORM.js +178 -179
  5. package/README.md +1 -1
  6. package/cache/CacheAdapter.d.ts +36 -36
  7. package/cache/FileCacheAdapter.d.ts +30 -24
  8. package/cache/FileCacheAdapter.js +80 -78
  9. package/cache/GeneratedCacheAdapter.d.ts +18 -20
  10. package/cache/GeneratedCacheAdapter.js +30 -30
  11. package/cache/MemoryCacheAdapter.d.ts +18 -20
  12. package/cache/MemoryCacheAdapter.js +35 -36
  13. package/cache/NullCacheAdapter.d.ts +16 -16
  14. package/cache/NullCacheAdapter.js +24 -24
  15. package/connections/Connection.d.ts +95 -84
  16. package/connections/Connection.js +165 -168
  17. package/drivers/DatabaseDriver.d.ts +186 -80
  18. package/drivers/DatabaseDriver.js +450 -443
  19. package/drivers/IDatabaseDriver.d.ts +440 -301
  20. package/entity/BaseEntity.d.ts +120 -83
  21. package/entity/BaseEntity.js +43 -43
  22. package/entity/Collection.d.ts +212 -179
  23. package/entity/Collection.js +727 -721
  24. package/entity/EntityAssigner.d.ts +88 -77
  25. package/entity/EntityAssigner.js +231 -230
  26. package/entity/EntityFactory.d.ts +66 -54
  27. package/entity/EntityFactory.js +425 -383
  28. package/entity/EntityHelper.d.ts +34 -22
  29. package/entity/EntityHelper.js +280 -267
  30. package/entity/EntityIdentifier.d.ts +4 -4
  31. package/entity/EntityIdentifier.js +10 -10
  32. package/entity/EntityLoader.d.ts +98 -72
  33. package/entity/EntityLoader.js +753 -723
  34. package/entity/EntityRepository.d.ts +316 -201
  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 +126 -82
  39. package/entity/Reference.js +278 -274
  40. package/entity/WrappedEntity.d.ts +115 -72
  41. package/entity/WrappedEntity.js +168 -166
  42. package/entity/defineEntity.d.ts +1315 -636
  43. package/entity/defineEntity.js +527 -518
  44. package/entity/utils.d.ts +13 -3
  45. package/entity/utils.js +71 -73
  46. package/entity/validators.js +43 -43
  47. package/entity/wrap.js +8 -8
  48. package/enums.d.ts +258 -253
  49. package/enums.js +251 -252
  50. package/errors.d.ts +114 -72
  51. package/errors.js +350 -253
  52. package/events/EventManager.d.ts +26 -14
  53. package/events/EventManager.js +79 -77
  54. package/events/EventSubscriber.d.ts +29 -29
  55. package/events/TransactionEventBroadcaster.d.ts +15 -8
  56. package/events/TransactionEventBroadcaster.js +14 -14
  57. package/exceptions.d.ts +23 -40
  58. package/exceptions.js +35 -52
  59. package/hydration/Hydrator.d.ts +42 -17
  60. package/hydration/Hydrator.js +43 -43
  61. package/hydration/ObjectHydrator.d.ts +50 -17
  62. package/hydration/ObjectHydrator.js +481 -416
  63. package/index.d.ts +116 -2
  64. package/index.js +10 -1
  65. package/logging/DefaultLogger.d.ts +34 -32
  66. package/logging/DefaultLogger.js +86 -86
  67. package/logging/Logger.d.ts +41 -41
  68. package/logging/SimpleLogger.d.ts +13 -11
  69. package/logging/SimpleLogger.js +22 -22
  70. package/logging/colors.d.ts +6 -6
  71. package/logging/colors.js +11 -10
  72. package/logging/inspect.js +7 -7
  73. package/metadata/EntitySchema.d.ts +211 -127
  74. package/metadata/EntitySchema.js +397 -398
  75. package/metadata/MetadataDiscovery.d.ts +114 -114
  76. package/metadata/MetadataDiscovery.js +1951 -1863
  77. package/metadata/MetadataProvider.d.ts +24 -21
  78. package/metadata/MetadataProvider.js +82 -84
  79. package/metadata/MetadataStorage.d.ts +38 -32
  80. package/metadata/MetadataStorage.js +118 -118
  81. package/metadata/MetadataValidator.d.ts +39 -39
  82. package/metadata/MetadataValidator.js +381 -338
  83. package/metadata/discover-entities.d.ts +5 -2
  84. package/metadata/discover-entities.js +35 -27
  85. package/metadata/types.d.ts +615 -531
  86. package/naming-strategy/AbstractNamingStrategy.d.ts +54 -39
  87. package/naming-strategy/AbstractNamingStrategy.js +90 -85
  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 +109 -99
  93. package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
  94. package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
  95. package/not-supported.js +7 -4
  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 +310 -299
  100. package/platforms/Platform.js +663 -636
  101. package/serialization/EntitySerializer.d.ts +49 -26
  102. package/serialization/EntitySerializer.js +224 -218
  103. package/serialization/EntityTransformer.d.ts +10 -6
  104. package/serialization/EntityTransformer.js +219 -217
  105. package/serialization/SerializationContext.d.ts +27 -23
  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 +17 -10
  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 +83 -79
  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 +75 -49
  158. package/types/index.js +52 -26
  159. package/typings.d.ts +1250 -737
  160. package/typings.js +244 -231
  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 +178 -170
  165. package/unit-of-work/ChangeSetPersister.d.ts +63 -44
  166. package/unit-of-work/ChangeSetPersister.js +442 -421
  167. package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
  168. package/unit-of-work/CommitOrderCalculator.js +89 -88
  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 +181 -141
  172. package/unit-of-work/UnitOfWork.js +1200 -1183
  173. package/utils/AbstractMigrator.d.ts +111 -91
  174. package/utils/AbstractMigrator.js +275 -275
  175. package/utils/AbstractSchemaGenerator.d.ts +43 -34
  176. package/utils/AbstractSchemaGenerator.js +121 -122
  177. package/utils/AsyncContext.d.ts +3 -3
  178. package/utils/AsyncContext.js +34 -35
  179. package/utils/Configuration.d.ts +852 -808
  180. package/utils/Configuration.js +359 -344
  181. package/utils/Cursor.d.ts +40 -22
  182. package/utils/Cursor.js +135 -127
  183. package/utils/DataloaderUtils.d.ts +58 -43
  184. package/utils/DataloaderUtils.js +203 -198
  185. package/utils/EntityComparator.d.ts +98 -81
  186. package/utils/EntityComparator.js +828 -728
  187. package/utils/NullHighlighter.d.ts +1 -1
  188. package/utils/NullHighlighter.js +3 -3
  189. package/utils/QueryHelper.d.ts +79 -51
  190. package/utils/QueryHelper.js +372 -361
  191. package/utils/RawQueryFragment.d.ts +50 -34
  192. package/utils/RawQueryFragment.js +107 -105
  193. package/utils/RequestContext.d.ts +32 -32
  194. package/utils/RequestContext.js +52 -53
  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 +199 -197
  199. package/utils/Utils.d.ts +204 -145
  200. package/utils/Utils.js +812 -810
  201. package/utils/clone.js +104 -113
  202. package/utils/env-vars.js +90 -88
  203. package/utils/fs-utils.d.ts +15 -15
  204. package/utils/fs-utils.js +180 -181
  205. package/utils/upsert-utils.d.ts +20 -5
  206. package/utils/upsert-utils.js +114 -116
package/index.d.ts CHANGED
@@ -2,8 +2,122 @@
2
2
  * @packageDocumentation
3
3
  * @module core
4
4
  */
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';
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';
7
121
  export * from './enums.js';
8
122
  export * from './errors.js';
9
123
  export * from './exceptions.js';
package/index.js CHANGED
@@ -2,7 +2,16 @@
2
2
  * @packageDocumentation
3
3
  * @module core
4
4
  */
5
- export { EntityMetadata, PrimaryKeyProp, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, EntityName, } from './typings.js';
5
+ export {
6
+ EntityMetadata,
7
+ PrimaryKeyProp,
8
+ EntityRepositoryType,
9
+ OptionalProps,
10
+ EagerProps,
11
+ HiddenProps,
12
+ Config,
13
+ EntityName,
14
+ } from './typings.js';
6
15
  export * from './enums.js';
7
16
  export * from './errors.js';
8
17
  export * from './exceptions.js';
@@ -1,36 +1,38 @@
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(context: {
32
- query: string;
33
- } & LogContext): void;
34
- /** Factory method for creating a new DefaultLogger instance. */
35
- 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(
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;
36
38
  }
@@ -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;
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;
15
22
  }
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);
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);
35
28
  }
36
- /**
37
- * @inheritDoc
38
- */
39
- error(namespace, message, context) {
40
- this.log(namespace, message, { ...context, level: 'error' });
29
+ // use yellow for warning levels
30
+ if (context?.level === 'warning') {
31
+ message = colors.yellow(message);
41
32
  }
42
- /**
43
- * @inheritDoc
44
- */
45
- warn(namespace, message, context) {
46
- this.log(namespace, message, { ...context, level: 'warning' });
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;
47
58
  }
48
- /**
49
- * @inheritDoc
50
- */
51
- setDebugMode(debugMode) {
52
- this.debugMode = debugMode;
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;
53
66
  }
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));
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;
68
76
  }
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);
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(', ')}]`);
93
88
  }
94
- /** Factory method for creating a new DefaultLogger instance. */
95
- static create(options) {
96
- return new DefaultLogger(options);
89
+ if (this.usesReplicas && context.connection) {
90
+ msg += colors.cyan(` (via ${context.connection.type} connection '${context.connection.name}')`);
97
91
  }
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,15 +4,17 @@ 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(context: {
15
- query: string;
16
- } & LogContext): void;
17
- 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(
15
+ context: {
16
+ query: string;
17
+ } & LogContext,
18
+ ): void;
19
+ static create(this: void, options: LoggerOptions): SimpleLogger;
18
20
  }
@@ -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;
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}`);
6
+ /**
7
+ * @inheritDoc
8
+ */
9
+ log(namespace, message, context) {
10
+ if (!this.isEnabled(namespace, context)) {
11
+ return;
17
12
  }
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);
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;
29
24
  }
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,14 +1,15 @@
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 = () => !bool('NO_COLOR') && !bool('MIKRO_ORM_NO_COLOR') && boolIfDefined('FORCE_COLOR') && boolIfDefined('MIKRO_ORM_COLORS');
5
- 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 = () =>
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);
6
7
  /** @internal */
7
8
  export const colors = {
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,
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,
14
15
  };
@@ -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
  }