@mikro-orm/core 7.0.2-dev.9 → 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.
- package/EntityManager.d.ts +883 -579
- package/EntityManager.js +1897 -1865
- package/MikroORM.d.ts +103 -72
- package/MikroORM.js +178 -177
- package/README.md +128 -294
- package/cache/CacheAdapter.d.ts +38 -36
- package/cache/FileCacheAdapter.d.ts +30 -24
- package/cache/FileCacheAdapter.js +80 -78
- package/cache/GeneratedCacheAdapter.d.ts +19 -20
- package/cache/GeneratedCacheAdapter.js +31 -30
- package/cache/MemoryCacheAdapter.d.ts +19 -20
- package/cache/MemoryCacheAdapter.js +36 -36
- package/cache/NullCacheAdapter.d.ts +17 -16
- package/cache/NullCacheAdapter.js +25 -24
- package/connections/Connection.d.ts +99 -75
- package/connections/Connection.js +166 -160
- package/drivers/DatabaseDriver.d.ts +187 -69
- package/drivers/DatabaseDriver.js +451 -432
- package/drivers/IDatabaseDriver.d.ts +464 -281
- package/drivers/IDatabaseDriver.js +1 -0
- package/entity/BaseEntity.d.ts +121 -73
- package/entity/BaseEntity.js +44 -33
- package/entity/Collection.d.ts +216 -157
- package/entity/Collection.js +728 -707
- package/entity/EntityAssigner.d.ts +90 -76
- package/entity/EntityAssigner.js +232 -229
- package/entity/EntityFactory.d.ts +68 -40
- package/entity/EntityFactory.js +427 -366
- 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 +105 -56
- package/entity/EntityLoader.js +754 -722
- package/entity/EntityRepository.d.ts +317 -200
- package/entity/EntityRepository.js +214 -212
- package/entity/PolymorphicRef.d.ts +5 -5
- package/entity/PolymorphicRef.js +10 -10
- package/entity/Reference.d.ts +130 -66
- package/entity/Reference.js +280 -260
- package/entity/WrappedEntity.d.ts +116 -53
- package/entity/WrappedEntity.js +169 -147
- package/entity/defineEntity.d.ts +1290 -614
- package/entity/defineEntity.js +521 -511
- 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 +275 -138
- package/enums.js +268 -137
- package/errors.d.ts +120 -72
- package/errors.js +356 -253
- package/events/EventManager.d.ts +27 -10
- package/events/EventManager.js +80 -73
- package/events/EventSubscriber.d.ts +33 -29
- package/events/TransactionEventBroadcaster.d.ts +16 -7
- package/events/TransactionEventBroadcaster.js +15 -13
- package/exceptions.d.ts +23 -40
- package/exceptions.js +35 -52
- package/hydration/Hydrator.d.ts +43 -16
- package/hydration/Hydrator.js +44 -42
- package/hydration/ObjectHydrator.d.ts +51 -17
- package/hydration/ObjectHydrator.js +480 -416
- package/index.d.ts +116 -2
- package/index.js +10 -1
- package/logging/DefaultLogger.d.ts +35 -30
- package/logging/DefaultLogger.js +87 -84
- package/logging/Logger.d.ts +45 -40
- 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 +214 -108
- package/metadata/EntitySchema.js +398 -379
- package/metadata/MetadataDiscovery.d.ts +115 -111
- package/metadata/MetadataDiscovery.js +1948 -1857
- package/metadata/MetadataProvider.d.ts +25 -14
- package/metadata/MetadataProvider.js +83 -77
- package/metadata/MetadataStorage.d.ts +39 -19
- package/metadata/MetadataStorage.js +119 -106
- 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 +27 -27
- package/metadata/types.d.ts +615 -531
- package/naming-strategy/AbstractNamingStrategy.d.ts +55 -39
- package/naming-strategy/AbstractNamingStrategy.js +91 -85
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
- package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
- package/naming-strategy/MongoNamingStrategy.d.ts +7 -6
- package/naming-strategy/MongoNamingStrategy.js +19 -18
- package/naming-strategy/NamingStrategy.d.ts +109 -99
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +8 -7
- package/naming-strategy/UnderscoreNamingStrategy.js +22 -21
- package/not-supported.js +7 -4
- package/package.json +1 -1
- package/platforms/ExceptionConverter.d.ts +2 -1
- package/platforms/ExceptionConverter.js +5 -4
- package/platforms/Platform.d.ts +310 -236
- package/platforms/Platform.js +661 -573
- package/serialization/EntitySerializer.d.ts +49 -25
- package/serialization/EntitySerializer.js +224 -216
- package/serialization/EntityTransformer.d.ts +11 -5
- package/serialization/EntityTransformer.js +220 -216
- package/serialization/SerializationContext.d.ts +27 -18
- package/serialization/SerializationContext.js +105 -100
- package/types/ArrayType.d.ts +9 -8
- package/types/ArrayType.js +34 -33
- package/types/BigIntType.d.ts +17 -10
- package/types/BigIntType.js +37 -37
- package/types/BlobType.d.ts +4 -3
- package/types/BlobType.js +14 -13
- package/types/BooleanType.d.ts +5 -4
- package/types/BooleanType.js +13 -12
- package/types/CharacterType.d.ts +3 -2
- package/types/CharacterType.js +7 -6
- package/types/DateTimeType.d.ts +6 -5
- package/types/DateTimeType.js +16 -15
- package/types/DateType.d.ts +6 -5
- package/types/DateType.js +16 -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 +6 -5
- package/types/EnumArrayType.js +25 -24
- package/types/EnumType.d.ts +4 -3
- package/types/EnumType.js +12 -11
- package/types/FloatType.d.ts +4 -3
- package/types/FloatType.js +10 -9
- package/types/IntegerType.d.ts +4 -3
- package/types/IntegerType.js +10 -9
- package/types/IntervalType.d.ts +5 -4
- package/types/IntervalType.js +13 -12
- package/types/JsonType.d.ts +9 -8
- package/types/JsonType.js +33 -32
- package/types/MediumIntType.d.ts +2 -1
- package/types/MediumIntType.js +4 -3
- package/types/SmallIntType.d.ts +4 -3
- package/types/SmallIntType.js +10 -9
- package/types/StringType.d.ts +5 -4
- package/types/StringType.js +13 -12
- package/types/TextType.d.ts +4 -3
- package/types/TextType.js +10 -9
- package/types/TimeType.d.ts +6 -5
- package/types/TimeType.js +18 -17
- package/types/TinyIntType.d.ts +4 -3
- package/types/TinyIntType.js +11 -10
- package/types/Type.d.ts +88 -73
- package/types/Type.js +85 -74
- package/types/Uint8ArrayType.d.ts +5 -4
- package/types/Uint8ArrayType.js +22 -21
- package/types/UnknownType.d.ts +5 -4
- package/types/UnknownType.js +13 -12
- package/types/UuidType.d.ts +6 -5
- package/types/UuidType.js +20 -19
- package/types/index.d.ts +77 -49
- package/types/index.js +64 -26
- package/typings.d.ts +1388 -729
- package/typings.js +255 -231
- package/unit-of-work/ChangeSet.d.ts +28 -24
- package/unit-of-work/ChangeSet.js +58 -54
- package/unit-of-work/ChangeSetComputer.d.ts +13 -11
- package/unit-of-work/ChangeSetComputer.js +180 -159
- package/unit-of-work/ChangeSetPersister.d.ts +64 -41
- package/unit-of-work/ChangeSetPersister.js +443 -418
- package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
- package/unit-of-work/CommitOrderCalculator.js +89 -88
- package/unit-of-work/IdentityMap.d.ts +32 -25
- package/unit-of-work/IdentityMap.js +106 -99
- package/unit-of-work/UnitOfWork.d.ts +182 -127
- package/unit-of-work/UnitOfWork.js +1201 -1169
- 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 +853 -801
- package/utils/Configuration.js +360 -337
- 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 +99 -80
- package/utils/EntityComparator.js +825 -727
- package/utils/NullHighlighter.d.ts +2 -1
- package/utils/NullHighlighter.js +4 -3
- package/utils/QueryHelper.d.ts +79 -51
- package/utils/QueryHelper.js +372 -361
- package/utils/RawQueryFragment.d.ts +54 -28
- package/utils/RawQueryFragment.js +110 -99
- package/utils/RequestContext.d.ts +33 -32
- package/utils/RequestContext.js +52 -53
- package/utils/TransactionContext.d.ts +17 -16
- package/utils/TransactionContext.js +28 -27
- package/utils/TransactionManager.d.ts +58 -58
- package/utils/TransactionManager.js +199 -197
- package/utils/Utils.d.ts +210 -145
- package/utils/Utils.js +820 -813
- 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,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
|
-
|
|
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
|
-
|
|
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
|
}
|
package/logging/DefaultLogger.js
CHANGED
|
@@ -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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
93
|
-
|
|
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
|
}
|
package/logging/Logger.d.ts
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
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
|
}
|