@mikro-orm/core 7.0.4-dev.8 → 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.
- package/EntityManager.d.ts +884 -583
- package/EntityManager.js +1922 -1895
- package/MikroORM.d.ts +103 -74
- package/MikroORM.js +178 -179
- package/README.md +1 -1
- package/cache/CacheAdapter.d.ts +36 -36
- package/cache/FileCacheAdapter.d.ts +30 -24
- package/cache/FileCacheAdapter.js +80 -78
- package/cache/GeneratedCacheAdapter.d.ts +18 -20
- package/cache/GeneratedCacheAdapter.js +30 -30
- package/cache/MemoryCacheAdapter.d.ts +18 -20
- package/cache/MemoryCacheAdapter.js +35 -36
- package/cache/NullCacheAdapter.d.ts +16 -16
- package/cache/NullCacheAdapter.js +24 -24
- package/connections/Connection.d.ts +95 -84
- package/connections/Connection.js +165 -168
- package/drivers/DatabaseDriver.d.ts +186 -80
- package/drivers/DatabaseDriver.js +450 -443
- package/drivers/IDatabaseDriver.d.ts +440 -301
- package/entity/BaseEntity.d.ts +120 -83
- package/entity/BaseEntity.js +43 -43
- package/entity/Collection.d.ts +212 -179
- package/entity/Collection.js +727 -721
- package/entity/EntityAssigner.d.ts +88 -77
- package/entity/EntityAssigner.js +231 -230
- package/entity/EntityFactory.d.ts +66 -54
- package/entity/EntityFactory.js +425 -383
- package/entity/EntityHelper.d.ts +34 -22
- package/entity/EntityHelper.js +280 -267
- package/entity/EntityIdentifier.d.ts +4 -4
- package/entity/EntityIdentifier.js +10 -10
- package/entity/EntityLoader.d.ts +98 -72
- package/entity/EntityLoader.js +753 -723
- package/entity/EntityRepository.d.ts +316 -201
- package/entity/EntityRepository.js +213 -213
- package/entity/PolymorphicRef.d.ts +5 -5
- package/entity/PolymorphicRef.js +10 -10
- package/entity/Reference.d.ts +126 -82
- package/entity/Reference.js +278 -274
- package/entity/WrappedEntity.d.ts +115 -72
- package/entity/WrappedEntity.js +168 -166
- package/entity/defineEntity.d.ts +1315 -636
- package/entity/defineEntity.js +527 -518
- package/entity/utils.d.ts +13 -3
- package/entity/utils.js +71 -73
- package/entity/validators.js +43 -43
- package/entity/wrap.js +8 -8
- package/enums.d.ts +258 -253
- package/enums.js +251 -252
- package/errors.d.ts +114 -72
- package/errors.js +350 -253
- package/events/EventManager.d.ts +26 -14
- package/events/EventManager.js +79 -77
- package/events/EventSubscriber.d.ts +29 -29
- package/events/TransactionEventBroadcaster.d.ts +15 -8
- package/events/TransactionEventBroadcaster.js +14 -14
- package/exceptions.d.ts +23 -40
- package/exceptions.js +35 -52
- package/hydration/Hydrator.d.ts +42 -17
- package/hydration/Hydrator.js +43 -43
- package/hydration/ObjectHydrator.d.ts +50 -17
- package/hydration/ObjectHydrator.js +481 -416
- package/index.d.ts +116 -2
- package/index.js +10 -1
- package/logging/DefaultLogger.d.ts +34 -32
- package/logging/DefaultLogger.js +86 -86
- package/logging/Logger.d.ts +41 -41
- package/logging/SimpleLogger.d.ts +13 -11
- package/logging/SimpleLogger.js +22 -22
- package/logging/colors.d.ts +6 -6
- package/logging/colors.js +11 -10
- package/logging/inspect.js +7 -7
- package/metadata/EntitySchema.d.ts +211 -127
- package/metadata/EntitySchema.js +397 -398
- package/metadata/MetadataDiscovery.d.ts +114 -114
- package/metadata/MetadataDiscovery.js +1951 -1863
- package/metadata/MetadataProvider.d.ts +24 -21
- package/metadata/MetadataProvider.js +82 -84
- package/metadata/MetadataStorage.d.ts +38 -32
- package/metadata/MetadataStorage.js +118 -118
- package/metadata/MetadataValidator.d.ts +39 -39
- package/metadata/MetadataValidator.js +381 -338
- package/metadata/discover-entities.d.ts +5 -2
- package/metadata/discover-entities.js +35 -27
- package/metadata/types.d.ts +615 -531
- package/naming-strategy/AbstractNamingStrategy.d.ts +54 -39
- package/naming-strategy/AbstractNamingStrategy.js +90 -85
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
- package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
- package/naming-strategy/MongoNamingStrategy.d.ts +6 -6
- package/naming-strategy/MongoNamingStrategy.js +18 -18
- package/naming-strategy/NamingStrategy.d.ts +109 -99
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
- package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
- package/not-supported.js +7 -4
- package/package.json +1 -1
- package/platforms/ExceptionConverter.d.ts +1 -1
- package/platforms/ExceptionConverter.js +4 -4
- package/platforms/Platform.d.ts +310 -299
- package/platforms/Platform.js +663 -636
- package/serialization/EntitySerializer.d.ts +49 -26
- package/serialization/EntitySerializer.js +224 -218
- package/serialization/EntityTransformer.d.ts +10 -6
- package/serialization/EntityTransformer.js +219 -217
- package/serialization/SerializationContext.d.ts +27 -23
- package/serialization/SerializationContext.js +105 -105
- package/types/ArrayType.d.ts +8 -8
- package/types/ArrayType.js +33 -33
- package/types/BigIntType.d.ts +17 -10
- package/types/BigIntType.js +37 -37
- package/types/BlobType.d.ts +3 -3
- package/types/BlobType.js +13 -13
- package/types/BooleanType.d.ts +4 -4
- package/types/BooleanType.js +12 -12
- package/types/CharacterType.d.ts +2 -2
- package/types/CharacterType.js +6 -6
- package/types/DateTimeType.d.ts +5 -5
- package/types/DateTimeType.js +15 -15
- package/types/DateType.d.ts +5 -5
- package/types/DateType.js +15 -15
- package/types/DecimalType.d.ts +7 -7
- package/types/DecimalType.js +26 -26
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +12 -12
- package/types/EnumArrayType.d.ts +5 -5
- package/types/EnumArrayType.js +24 -24
- package/types/EnumType.d.ts +3 -3
- package/types/EnumType.js +11 -11
- package/types/FloatType.d.ts +3 -3
- package/types/FloatType.js +9 -9
- package/types/IntegerType.d.ts +3 -3
- package/types/IntegerType.js +9 -9
- package/types/IntervalType.d.ts +4 -4
- package/types/IntervalType.js +12 -12
- package/types/JsonType.d.ts +8 -8
- package/types/JsonType.js +32 -32
- package/types/MediumIntType.d.ts +1 -1
- package/types/MediumIntType.js +3 -3
- package/types/SmallIntType.d.ts +3 -3
- package/types/SmallIntType.js +9 -9
- package/types/StringType.d.ts +4 -4
- package/types/StringType.js +12 -12
- package/types/TextType.d.ts +3 -3
- package/types/TextType.js +9 -9
- package/types/TimeType.d.ts +5 -5
- package/types/TimeType.js +17 -17
- package/types/TinyIntType.d.ts +3 -3
- package/types/TinyIntType.js +10 -10
- package/types/Type.d.ts +83 -79
- package/types/Type.js +82 -82
- package/types/Uint8ArrayType.d.ts +4 -4
- package/types/Uint8ArrayType.js +21 -21
- package/types/UnknownType.d.ts +4 -4
- package/types/UnknownType.js +12 -12
- package/types/UuidType.d.ts +5 -5
- package/types/UuidType.js +19 -19
- package/types/index.d.ts +75 -49
- package/types/index.js +52 -26
- package/typings.d.ts +1250 -737
- package/typings.js +244 -231
- package/unit-of-work/ChangeSet.d.ts +26 -26
- package/unit-of-work/ChangeSet.js +56 -56
- package/unit-of-work/ChangeSetComputer.d.ts +12 -12
- package/unit-of-work/ChangeSetComputer.js +178 -170
- package/unit-of-work/ChangeSetPersister.d.ts +63 -44
- package/unit-of-work/ChangeSetPersister.js +442 -421
- package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
- package/unit-of-work/CommitOrderCalculator.js +89 -88
- package/unit-of-work/IdentityMap.d.ts +31 -31
- package/unit-of-work/IdentityMap.js +105 -105
- package/unit-of-work/UnitOfWork.d.ts +181 -141
- package/unit-of-work/UnitOfWork.js +1200 -1183
- package/utils/AbstractMigrator.d.ts +111 -91
- package/utils/AbstractMigrator.js +275 -275
- package/utils/AbstractSchemaGenerator.d.ts +43 -34
- package/utils/AbstractSchemaGenerator.js +121 -122
- package/utils/AsyncContext.d.ts +3 -3
- package/utils/AsyncContext.js +34 -35
- package/utils/Configuration.d.ts +852 -808
- package/utils/Configuration.js +359 -344
- package/utils/Cursor.d.ts +40 -22
- package/utils/Cursor.js +135 -127
- package/utils/DataloaderUtils.d.ts +58 -43
- package/utils/DataloaderUtils.js +203 -198
- package/utils/EntityComparator.d.ts +98 -81
- package/utils/EntityComparator.js +828 -728
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +3 -3
- package/utils/QueryHelper.d.ts +79 -51
- package/utils/QueryHelper.js +372 -361
- package/utils/RawQueryFragment.d.ts +50 -34
- package/utils/RawQueryFragment.js +107 -105
- package/utils/RequestContext.d.ts +32 -32
- package/utils/RequestContext.js +52 -53
- package/utils/TransactionContext.d.ts +16 -16
- package/utils/TransactionContext.js +27 -27
- package/utils/TransactionManager.d.ts +58 -58
- package/utils/TransactionManager.js +199 -197
- package/utils/Utils.d.ts +204 -145
- package/utils/Utils.js +812 -810
- package/utils/clone.js +104 -113
- package/utils/env-vars.js +90 -88
- package/utils/fs-utils.d.ts +15 -15
- package/utils/fs-utils.js +180 -181
- package/utils/upsert-utils.d.ts +20 -5
- 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 {
|
|
6
|
-
|
|
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 {
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
}
|
package/logging/DefaultLogger.js
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
95
|
-
|
|
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
|
}
|
package/logging/Logger.d.ts
CHANGED
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
}
|
package/logging/SimpleLogger.js
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
}
|
package/logging/colors.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** @internal */
|
|
2
2
|
export declare const colors: {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 =
|
|
3
|
-
const boolIfDefined =
|
|
4
|
-
const enabled = () =>
|
|
5
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
};
|
package/logging/inspect.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
let nodeInspect;
|
|
2
2
|
/** @internal */
|
|
3
3
|
export function inspect(value, options) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
}
|