@mikro-orm/core 7.0.2-dev.8 → 7.0.2

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 (207) hide show
  1. package/EntityManager.d.ts +883 -579
  2. package/EntityManager.js +1897 -1865
  3. package/MikroORM.d.ts +103 -72
  4. package/MikroORM.js +178 -177
  5. package/README.md +128 -294
  6. package/cache/CacheAdapter.d.ts +38 -36
  7. package/cache/FileCacheAdapter.d.ts +30 -24
  8. package/cache/FileCacheAdapter.js +80 -78
  9. package/cache/GeneratedCacheAdapter.d.ts +19 -20
  10. package/cache/GeneratedCacheAdapter.js +31 -30
  11. package/cache/MemoryCacheAdapter.d.ts +19 -20
  12. package/cache/MemoryCacheAdapter.js +36 -36
  13. package/cache/NullCacheAdapter.d.ts +17 -16
  14. package/cache/NullCacheAdapter.js +25 -24
  15. package/connections/Connection.d.ts +99 -75
  16. package/connections/Connection.js +166 -160
  17. package/drivers/DatabaseDriver.d.ts +187 -69
  18. package/drivers/DatabaseDriver.js +451 -432
  19. package/drivers/IDatabaseDriver.d.ts +464 -281
  20. package/drivers/IDatabaseDriver.js +1 -0
  21. package/entity/BaseEntity.d.ts +121 -73
  22. package/entity/BaseEntity.js +44 -33
  23. package/entity/Collection.d.ts +216 -157
  24. package/entity/Collection.js +728 -707
  25. package/entity/EntityAssigner.d.ts +90 -76
  26. package/entity/EntityAssigner.js +232 -229
  27. package/entity/EntityFactory.d.ts +68 -40
  28. package/entity/EntityFactory.js +427 -366
  29. package/entity/EntityHelper.d.ts +34 -22
  30. package/entity/EntityHelper.js +280 -267
  31. package/entity/EntityIdentifier.d.ts +4 -4
  32. package/entity/EntityIdentifier.js +10 -10
  33. package/entity/EntityLoader.d.ts +105 -56
  34. package/entity/EntityLoader.js +754 -722
  35. package/entity/EntityRepository.d.ts +317 -200
  36. package/entity/EntityRepository.js +214 -212
  37. package/entity/PolymorphicRef.d.ts +5 -5
  38. package/entity/PolymorphicRef.js +10 -10
  39. package/entity/Reference.d.ts +130 -66
  40. package/entity/Reference.js +280 -260
  41. package/entity/WrappedEntity.d.ts +116 -53
  42. package/entity/WrappedEntity.js +169 -147
  43. package/entity/defineEntity.d.ts +1290 -614
  44. package/entity/defineEntity.js +521 -511
  45. package/entity/utils.d.ts +13 -3
  46. package/entity/utils.js +71 -73
  47. package/entity/validators.js +43 -43
  48. package/entity/wrap.js +8 -8
  49. package/enums.d.ts +275 -138
  50. package/enums.js +268 -137
  51. package/errors.d.ts +120 -72
  52. package/errors.js +356 -253
  53. package/events/EventManager.d.ts +27 -10
  54. package/events/EventManager.js +80 -73
  55. package/events/EventSubscriber.d.ts +33 -29
  56. package/events/TransactionEventBroadcaster.d.ts +16 -7
  57. package/events/TransactionEventBroadcaster.js +15 -13
  58. package/exceptions.d.ts +23 -40
  59. package/exceptions.js +35 -52
  60. package/hydration/Hydrator.d.ts +43 -16
  61. package/hydration/Hydrator.js +44 -42
  62. package/hydration/ObjectHydrator.d.ts +51 -17
  63. package/hydration/ObjectHydrator.js +480 -416
  64. package/index.d.ts +116 -2
  65. package/index.js +10 -1
  66. package/logging/DefaultLogger.d.ts +35 -30
  67. package/logging/DefaultLogger.js +87 -84
  68. package/logging/Logger.d.ts +45 -40
  69. package/logging/SimpleLogger.d.ts +13 -11
  70. package/logging/SimpleLogger.js +22 -22
  71. package/logging/colors.d.ts +6 -6
  72. package/logging/colors.js +11 -10
  73. package/logging/inspect.js +7 -7
  74. package/metadata/EntitySchema.d.ts +214 -108
  75. package/metadata/EntitySchema.js +398 -379
  76. package/metadata/MetadataDiscovery.d.ts +115 -111
  77. package/metadata/MetadataDiscovery.js +1948 -1857
  78. package/metadata/MetadataProvider.d.ts +25 -14
  79. package/metadata/MetadataProvider.js +83 -77
  80. package/metadata/MetadataStorage.d.ts +39 -19
  81. package/metadata/MetadataStorage.js +119 -106
  82. package/metadata/MetadataValidator.d.ts +39 -39
  83. package/metadata/MetadataValidator.js +381 -338
  84. package/metadata/discover-entities.d.ts +5 -2
  85. package/metadata/discover-entities.js +27 -27
  86. package/metadata/types.d.ts +615 -531
  87. package/naming-strategy/AbstractNamingStrategy.d.ts +55 -39
  88. package/naming-strategy/AbstractNamingStrategy.js +91 -85
  89. package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
  90. package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
  91. package/naming-strategy/MongoNamingStrategy.d.ts +7 -6
  92. package/naming-strategy/MongoNamingStrategy.js +19 -18
  93. package/naming-strategy/NamingStrategy.d.ts +109 -99
  94. package/naming-strategy/UnderscoreNamingStrategy.d.ts +8 -7
  95. package/naming-strategy/UnderscoreNamingStrategy.js +22 -21
  96. package/not-supported.js +7 -4
  97. package/package.json +1 -1
  98. package/platforms/ExceptionConverter.d.ts +2 -1
  99. package/platforms/ExceptionConverter.js +5 -4
  100. package/platforms/Platform.d.ts +310 -236
  101. package/platforms/Platform.js +661 -573
  102. package/serialization/EntitySerializer.d.ts +49 -25
  103. package/serialization/EntitySerializer.js +224 -216
  104. package/serialization/EntityTransformer.d.ts +11 -5
  105. package/serialization/EntityTransformer.js +220 -216
  106. package/serialization/SerializationContext.d.ts +27 -18
  107. package/serialization/SerializationContext.js +105 -100
  108. package/types/ArrayType.d.ts +9 -8
  109. package/types/ArrayType.js +34 -33
  110. package/types/BigIntType.d.ts +17 -10
  111. package/types/BigIntType.js +37 -37
  112. package/types/BlobType.d.ts +4 -3
  113. package/types/BlobType.js +14 -13
  114. package/types/BooleanType.d.ts +5 -4
  115. package/types/BooleanType.js +13 -12
  116. package/types/CharacterType.d.ts +3 -2
  117. package/types/CharacterType.js +7 -6
  118. package/types/DateTimeType.d.ts +6 -5
  119. package/types/DateTimeType.js +16 -15
  120. package/types/DateType.d.ts +6 -5
  121. package/types/DateType.js +16 -15
  122. package/types/DecimalType.d.ts +7 -7
  123. package/types/DecimalType.js +26 -26
  124. package/types/DoubleType.d.ts +3 -3
  125. package/types/DoubleType.js +12 -12
  126. package/types/EnumArrayType.d.ts +6 -5
  127. package/types/EnumArrayType.js +25 -24
  128. package/types/EnumType.d.ts +4 -3
  129. package/types/EnumType.js +12 -11
  130. package/types/FloatType.d.ts +4 -3
  131. package/types/FloatType.js +10 -9
  132. package/types/IntegerType.d.ts +4 -3
  133. package/types/IntegerType.js +10 -9
  134. package/types/IntervalType.d.ts +5 -4
  135. package/types/IntervalType.js +13 -12
  136. package/types/JsonType.d.ts +9 -8
  137. package/types/JsonType.js +33 -32
  138. package/types/MediumIntType.d.ts +2 -1
  139. package/types/MediumIntType.js +4 -3
  140. package/types/SmallIntType.d.ts +4 -3
  141. package/types/SmallIntType.js +10 -9
  142. package/types/StringType.d.ts +5 -4
  143. package/types/StringType.js +13 -12
  144. package/types/TextType.d.ts +4 -3
  145. package/types/TextType.js +10 -9
  146. package/types/TimeType.d.ts +6 -5
  147. package/types/TimeType.js +18 -17
  148. package/types/TinyIntType.d.ts +4 -3
  149. package/types/TinyIntType.js +11 -10
  150. package/types/Type.d.ts +88 -73
  151. package/types/Type.js +85 -74
  152. package/types/Uint8ArrayType.d.ts +5 -4
  153. package/types/Uint8ArrayType.js +22 -21
  154. package/types/UnknownType.d.ts +5 -4
  155. package/types/UnknownType.js +13 -12
  156. package/types/UuidType.d.ts +6 -5
  157. package/types/UuidType.js +20 -19
  158. package/types/index.d.ts +77 -49
  159. package/types/index.js +64 -26
  160. package/typings.d.ts +1388 -729
  161. package/typings.js +255 -231
  162. package/unit-of-work/ChangeSet.d.ts +28 -24
  163. package/unit-of-work/ChangeSet.js +58 -54
  164. package/unit-of-work/ChangeSetComputer.d.ts +13 -11
  165. package/unit-of-work/ChangeSetComputer.js +180 -159
  166. package/unit-of-work/ChangeSetPersister.d.ts +64 -41
  167. package/unit-of-work/ChangeSetPersister.js +443 -418
  168. package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
  169. package/unit-of-work/CommitOrderCalculator.js +89 -88
  170. package/unit-of-work/IdentityMap.d.ts +32 -25
  171. package/unit-of-work/IdentityMap.js +106 -99
  172. package/unit-of-work/UnitOfWork.d.ts +182 -127
  173. package/unit-of-work/UnitOfWork.js +1201 -1169
  174. package/utils/AbstractMigrator.d.ts +111 -91
  175. package/utils/AbstractMigrator.js +275 -275
  176. package/utils/AbstractSchemaGenerator.d.ts +43 -34
  177. package/utils/AbstractSchemaGenerator.js +121 -122
  178. package/utils/AsyncContext.d.ts +3 -3
  179. package/utils/AsyncContext.js +34 -35
  180. package/utils/Configuration.d.ts +853 -801
  181. package/utils/Configuration.js +360 -337
  182. package/utils/Cursor.d.ts +40 -22
  183. package/utils/Cursor.js +135 -127
  184. package/utils/DataloaderUtils.d.ts +58 -43
  185. package/utils/DataloaderUtils.js +203 -198
  186. package/utils/EntityComparator.d.ts +99 -80
  187. package/utils/EntityComparator.js +825 -727
  188. package/utils/NullHighlighter.d.ts +2 -1
  189. package/utils/NullHighlighter.js +4 -3
  190. package/utils/QueryHelper.d.ts +79 -51
  191. package/utils/QueryHelper.js +372 -361
  192. package/utils/RawQueryFragment.d.ts +54 -28
  193. package/utils/RawQueryFragment.js +110 -99
  194. package/utils/RequestContext.d.ts +33 -32
  195. package/utils/RequestContext.js +52 -53
  196. package/utils/TransactionContext.d.ts +17 -16
  197. package/utils/TransactionContext.js +28 -27
  198. package/utils/TransactionManager.d.ts +58 -58
  199. package/utils/TransactionManager.js +199 -197
  200. package/utils/Utils.d.ts +210 -145
  201. package/utils/Utils.js +820 -813
  202. package/utils/clone.js +104 -113
  203. package/utils/env-vars.js +90 -88
  204. package/utils/fs-utils.d.ts +15 -15
  205. package/utils/fs-utils.js +180 -181
  206. package/utils/upsert-utils.d.ts +20 -5
  207. 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,33 +1,38 @@
1
1
  import type { Logger, LoggerNamespace, LogContext, LoggerOptions } from './Logger.js';
2
+ /** Default logger implementation with colored output, query formatting, and namespace-based filtering. */
2
3
  export declare class DefaultLogger implements Logger {
3
- private readonly options;
4
- debugMode: boolean | LoggerNamespace[];
5
- readonly writer: (message: string) => void;
6
- private readonly usesReplicas?;
7
- private readonly highlighter?;
8
- constructor(options: LoggerOptions);
9
- /**
10
- * @inheritDoc
11
- */
12
- log(namespace: LoggerNamespace, message: string, context?: LogContext): void;
13
- /**
14
- * @inheritDoc
15
- */
16
- error(namespace: LoggerNamespace, message: string, context?: LogContext): void;
17
- /**
18
- * @inheritDoc
19
- */
20
- warn(namespace: LoggerNamespace, message: string, context?: LogContext): void;
21
- /**
22
- * @inheritDoc
23
- */
24
- setDebugMode(debugMode: boolean | LoggerNamespace[]): void;
25
- isEnabled(namespace: LoggerNamespace, context?: LogContext): boolean;
26
- /**
27
- * @inheritDoc
28
- */
29
- logQuery(context: {
30
- query: string;
31
- } & LogContext): void;
32
- 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;
33
38
  }
@@ -1,95 +1,98 @@
1
1
  import { colors } from './colors.js';
2
+ /** Default logger implementation with colored output, query formatting, and namespace-based filtering. */
2
3
  export class DefaultLogger {
3
- options;
4
- debugMode;
5
- writer;
6
- usesReplicas;
7
- highlighter;
8
- constructor(options) {
9
- this.options = options;
10
- this.debugMode = this.options.debugMode ?? false;
11
- this.writer = this.options.writer;
12
- this.usesReplicas = this.options.usesReplicas;
13
- 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;
14
22
  }
15
- /**
16
- * @inheritDoc
17
- */
18
- log(namespace, message, context) {
19
- if (!this.isEnabled(namespace, context)) {
20
- return;
21
- }
22
- // clean up the whitespace
23
- message = message.replace(/\n/g, '').replace(/ +/g, ' ').trim();
24
- // use red for error levels
25
- if (context?.level === 'error') {
26
- message = colors.red(message);
27
- }
28
- // use yellow for warning levels
29
- if (context?.level === 'warning') {
30
- message = colors.yellow(message);
31
- }
32
- const label = context?.label ? colors.cyan(`(${context.label}) `) : '';
33
- 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);
34
28
  }
35
- /**
36
- * @inheritDoc
37
- */
38
- error(namespace, message, context) {
39
- this.log(namespace, message, { ...context, level: 'error' });
29
+ // use yellow for warning levels
30
+ if (context?.level === 'warning') {
31
+ message = colors.yellow(message);
40
32
  }
41
- /**
42
- * @inheritDoc
43
- */
44
- warn(namespace, message, context) {
45
- 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;
46
58
  }
47
- /**
48
- * @inheritDoc
49
- */
50
- setDebugMode(debugMode) {
51
- 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;
52
66
  }
53
- isEnabled(namespace, context) {
54
- if (context?.enabled !== undefined) {
55
- return context.enabled;
56
- }
57
- const debugMode = context?.debugMode ?? this.debugMode;
58
- if (namespace === 'deprecated') {
59
- const { ignoreDeprecations = false } = this.options;
60
- return Array.isArray(ignoreDeprecations)
61
- ? /* v8 ignore next */
62
- !ignoreDeprecations.includes(context?.label ?? '')
63
- : !ignoreDeprecations;
64
- }
65
- 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;
66
76
  }
67
- /**
68
- * @inheritDoc
69
- */
70
- logQuery(context) {
71
- const namespace = context.namespace ?? 'query';
72
- if (!this.isEnabled(namespace, context)) {
73
- return;
74
- }
75
- /* v8 ignore next */
76
- let msg = this.highlighter?.highlight(context.query) ?? context.query;
77
- if (context.took != null) {
78
- const meta = [`took ${context.took} ms`];
79
- if (context.results != null) {
80
- meta.push(`${context.results} result${context.results === 0 || context.results > 1 ? 's' : ''}`);
81
- }
82
- if (context.affected != null) {
83
- meta.push(`${context.affected} row${context.affected === 0 || context.affected > 1 ? 's' : ''} affected`);
84
- }
85
- msg += colors.grey(` [${meta.join(', ')}]`);
86
- }
87
- if (this.usesReplicas && context.connection) {
88
- msg += colors.cyan(` (via ${context.connection.type} connection '${context.connection.name}')`);
89
- }
90
- 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(', ')}]`);
91
88
  }
92
- static create(options) {
93
- return new DefaultLogger(options);
89
+ if (this.usesReplicas && context.connection) {
90
+ msg += colors.cyan(` (via ${context.connection.type} connection '${context.connection.name}')`);
94
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
+ }
95
98
  }
@@ -1,50 +1,55 @@
1
1
  import type { AnyString, Dictionary, Highlighter } from '../typings.js';
2
+ /** Interface for ORM logging, supporting namespaced log levels and query logging. */
2
3
  export interface Logger {
3
- /**
4
- * Logs a message inside given namespace.
5
- */
6
- log(namespace: LoggerNamespace | AnyString, message: string, context?: LogContext): void;
7
- /**
8
- * Logs error message inside given namespace.
9
- */
10
- error(namespace: LoggerNamespace | AnyString, message: string, context?: LogContext): void;
11
- /**
12
- * Logs warning message inside given namespace.
13
- */
14
- warn(namespace: LoggerNamespace | AnyString, message: string, context?: LogContext): void;
15
- /**
16
- * Logs a message inside given namespace.
17
- */
18
- logQuery(context: LogContext): void;
19
- /**
20
- * Sets active namespaces. Pass `true` to enable all logging.
21
- */
22
- setDebugMode(debugMode: boolean | LoggerNamespace[]): void;
23
- 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;
24
26
  }
27
+ /** Available logging namespaces that can be individually enabled or disabled. */
25
28
  export type LoggerNamespace = 'query' | 'query-params' | 'schema' | 'discovery' | 'info' | 'deprecated' | 'slow-query';
29
+ /** Contextual metadata passed alongside log messages, including query details and timing. */
26
30
  export interface LogContext extends Dictionary {
27
- query?: string;
28
- label?: string;
29
- namespace?: LoggerNamespace;
30
- params?: readonly unknown[];
31
- took?: number;
32
- results?: number;
33
- affected?: number;
34
- level?: 'info' | 'warning' | 'error';
35
- enabled?: boolean;
36
- debugMode?: LoggerNamespace[];
37
- connection?: {
38
- type?: string;
39
- name?: string;
40
- };
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
+ };
41
45
  }
46
+ /** Options for constructing a Logger instance. */
42
47
  export interface LoggerOptions {
43
- writer: (message: string) => void;
44
- debugMode?: boolean | LoggerNamespace[];
45
- ignoreDeprecations?: boolean | string[];
46
- highlighter?: Highlighter;
47
- usesReplicas?: boolean;
48
+ writer: (message: string) => void;
49
+ debugMode?: boolean | LoggerNamespace[];
50
+ ignoreDeprecations?: boolean | string[];
51
+ highlighter?: Highlighter;
52
+ usesReplicas?: boolean;
48
53
  }
49
54
  /**
50
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
  }