@mikro-orm/core 7.0.4 → 7.0.5-dev.0
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 +583 -884
- package/EntityManager.js +1895 -1922
- package/MikroORM.d.ts +74 -103
- package/MikroORM.js +179 -178
- package/README.md +1 -1
- package/cache/CacheAdapter.d.ts +36 -36
- package/cache/FileCacheAdapter.d.ts +24 -30
- package/cache/FileCacheAdapter.js +78 -80
- package/cache/GeneratedCacheAdapter.d.ts +20 -18
- package/cache/GeneratedCacheAdapter.js +30 -30
- package/cache/MemoryCacheAdapter.d.ts +20 -18
- package/cache/MemoryCacheAdapter.js +36 -35
- package/cache/NullCacheAdapter.d.ts +16 -16
- package/cache/NullCacheAdapter.js +24 -24
- package/connections/Connection.d.ts +84 -95
- package/connections/Connection.js +168 -165
- package/drivers/DatabaseDriver.d.ts +80 -186
- package/drivers/DatabaseDriver.js +443 -450
- package/drivers/IDatabaseDriver.d.ts +301 -440
- package/entity/BaseEntity.d.ts +83 -120
- package/entity/BaseEntity.js +43 -43
- package/entity/Collection.d.ts +179 -212
- package/entity/Collection.js +721 -727
- package/entity/EntityAssigner.d.ts +77 -88
- package/entity/EntityAssigner.js +230 -231
- package/entity/EntityFactory.d.ts +54 -66
- package/entity/EntityFactory.js +383 -425
- package/entity/EntityHelper.d.ts +22 -34
- package/entity/EntityHelper.js +267 -280
- package/entity/EntityIdentifier.d.ts +4 -4
- package/entity/EntityIdentifier.js +10 -10
- package/entity/EntityLoader.d.ts +72 -98
- package/entity/EntityLoader.js +723 -753
- package/entity/EntityRepository.d.ts +201 -316
- package/entity/EntityRepository.js +213 -213
- package/entity/PolymorphicRef.d.ts +5 -5
- package/entity/PolymorphicRef.js +10 -10
- package/entity/Reference.d.ts +82 -126
- package/entity/Reference.js +274 -278
- package/entity/WrappedEntity.d.ts +72 -115
- package/entity/WrappedEntity.js +166 -168
- package/entity/defineEntity.d.ts +636 -1315
- package/entity/defineEntity.js +518 -527
- package/entity/utils.d.ts +3 -13
- package/entity/utils.js +73 -71
- package/entity/validators.js +43 -43
- package/entity/wrap.js +8 -8
- package/enums.d.ts +253 -258
- package/enums.js +252 -251
- package/errors.d.ts +72 -114
- package/errors.js +253 -350
- package/events/EventManager.d.ts +14 -26
- package/events/EventManager.js +77 -79
- package/events/EventSubscriber.d.ts +29 -29
- package/events/TransactionEventBroadcaster.d.ts +8 -15
- package/events/TransactionEventBroadcaster.js +14 -14
- package/exceptions.d.ts +40 -23
- package/exceptions.js +52 -35
- package/hydration/Hydrator.d.ts +17 -42
- package/hydration/Hydrator.js +43 -43
- package/hydration/ObjectHydrator.d.ts +17 -50
- package/hydration/ObjectHydrator.js +416 -481
- package/index.d.ts +2 -116
- package/index.js +1 -10
- package/logging/DefaultLogger.d.ts +32 -34
- package/logging/DefaultLogger.js +86 -86
- package/logging/Logger.d.ts +41 -41
- package/logging/SimpleLogger.d.ts +11 -13
- package/logging/SimpleLogger.js +22 -22
- package/logging/colors.d.ts +6 -6
- package/logging/colors.js +10 -11
- package/logging/inspect.js +7 -7
- package/metadata/EntitySchema.d.ts +127 -211
- package/metadata/EntitySchema.js +398 -397
- package/metadata/MetadataDiscovery.d.ts +114 -114
- package/metadata/MetadataDiscovery.js +1870 -1951
- package/metadata/MetadataProvider.d.ts +21 -24
- package/metadata/MetadataProvider.js +84 -82
- package/metadata/MetadataStorage.d.ts +32 -38
- package/metadata/MetadataStorage.js +118 -118
- package/metadata/MetadataValidator.d.ts +39 -39
- package/metadata/MetadataValidator.js +338 -381
- package/metadata/discover-entities.d.ts +2 -5
- package/metadata/discover-entities.js +37 -35
- package/metadata/types.d.ts +531 -615
- package/naming-strategy/AbstractNamingStrategy.d.ts +39 -54
- package/naming-strategy/AbstractNamingStrategy.js +85 -90
- 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 +99 -109
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
- package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
- package/not-supported.js +4 -7
- package/package.json +1 -1
- package/platforms/ExceptionConverter.d.ts +1 -1
- package/platforms/ExceptionConverter.js +4 -4
- package/platforms/Platform.d.ts +301 -310
- package/platforms/Platform.js +640 -663
- package/serialization/EntitySerializer.d.ts +26 -49
- package/serialization/EntitySerializer.js +218 -224
- package/serialization/EntityTransformer.d.ts +6 -10
- package/serialization/EntityTransformer.js +217 -219
- package/serialization/SerializationContext.d.ts +23 -27
- package/serialization/SerializationContext.js +105 -105
- package/types/ArrayType.d.ts +8 -8
- package/types/ArrayType.js +33 -33
- package/types/BigIntType.d.ts +10 -17
- 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 +79 -83
- 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 +49 -75
- package/types/index.js +26 -52
- package/typings.d.ts +737 -1250
- package/typings.js +231 -244
- 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 +170 -178
- package/unit-of-work/ChangeSetPersister.d.ts +44 -63
- package/unit-of-work/ChangeSetPersister.js +421 -442
- package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
- package/unit-of-work/CommitOrderCalculator.js +88 -89
- package/unit-of-work/IdentityMap.d.ts +31 -31
- package/unit-of-work/IdentityMap.js +105 -105
- package/unit-of-work/UnitOfWork.d.ts +141 -181
- package/unit-of-work/UnitOfWork.js +1183 -1200
- package/utils/AbstractMigrator.d.ts +91 -111
- package/utils/AbstractMigrator.js +275 -275
- package/utils/AbstractSchemaGenerator.d.ts +34 -43
- package/utils/AbstractSchemaGenerator.js +122 -121
- package/utils/AsyncContext.d.ts +3 -3
- package/utils/AsyncContext.js +35 -34
- package/utils/Configuration.d.ts +808 -852
- package/utils/Configuration.js +344 -359
- package/utils/Cursor.d.ts +22 -40
- package/utils/Cursor.js +127 -135
- package/utils/DataloaderUtils.d.ts +43 -58
- package/utils/DataloaderUtils.js +198 -203
- package/utils/EntityComparator.d.ts +81 -98
- package/utils/EntityComparator.js +732 -828
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +3 -3
- package/utils/QueryHelper.d.ts +51 -79
- package/utils/QueryHelper.js +361 -372
- package/utils/RawQueryFragment.d.ts +34 -50
- package/utils/RawQueryFragment.js +105 -107
- package/utils/RequestContext.d.ts +32 -32
- package/utils/RequestContext.js +53 -52
- package/utils/TransactionContext.d.ts +16 -16
- package/utils/TransactionContext.js +27 -27
- package/utils/TransactionManager.d.ts +58 -58
- package/utils/TransactionManager.js +197 -199
- package/utils/Utils.d.ts +145 -204
- package/utils/Utils.js +812 -812
- package/utils/clone.js +113 -104
- package/utils/env-vars.js +88 -90
- package/utils/fs-utils.d.ts +15 -15
- package/utils/fs-utils.js +181 -180
- package/utils/upsert-utils.d.ts +5 -20
- package/utils/upsert-utils.js +116 -114
package/utils/Configuration.js
CHANGED
|
@@ -12,394 +12,379 @@ import { MemoryCacheAdapter } from '../cache/MemoryCacheAdapter.js';
|
|
|
12
12
|
import { EntityComparator } from './EntityComparator.js';
|
|
13
13
|
import { setEnv } from './env-vars.js';
|
|
14
14
|
const DEFAULTS = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
15
|
+
pool: {},
|
|
16
|
+
entities: [],
|
|
17
|
+
entitiesTs: [],
|
|
18
|
+
extensions: [],
|
|
19
|
+
subscribers: [],
|
|
20
|
+
filters: {},
|
|
21
|
+
discovery: {
|
|
22
|
+
warnWhenNoEntities: true,
|
|
23
|
+
checkDuplicateTableNames: true,
|
|
24
|
+
checkDuplicateFieldNames: true,
|
|
25
|
+
checkDuplicateEntities: true,
|
|
26
|
+
checkNonPersistentCompositeProps: true,
|
|
27
|
+
inferDefaultValues: true,
|
|
28
|
+
},
|
|
29
|
+
validateRequired: true,
|
|
30
|
+
context: (name) => RequestContext.getEntityManager(name),
|
|
31
|
+
contextName: 'default',
|
|
32
|
+
allowGlobalContext: false,
|
|
33
|
+
// eslint-disable-next-line no-console
|
|
34
|
+
logger: console.log.bind(console),
|
|
35
|
+
colors: true,
|
|
36
|
+
findOneOrFailHandler: (entityName, where) => NotFoundError.findOneFailed(entityName, where),
|
|
37
|
+
findExactlyOneOrFailHandler: (entityName, where) => NotFoundError.findExactlyOneFailed(entityName, where),
|
|
38
|
+
baseDir: globalThis.process?.cwd?.(),
|
|
39
|
+
hydrator: ObjectHydrator,
|
|
40
|
+
flushMode: FlushMode.AUTO,
|
|
41
|
+
loadStrategy: LoadStrategy.BALANCED,
|
|
42
|
+
dataloader: DataloaderType.NONE,
|
|
43
|
+
populateWhere: PopulateHint.ALL,
|
|
44
|
+
ignoreUndefinedInQuery: false,
|
|
45
|
+
onQuery: (sql) => sql,
|
|
46
|
+
autoJoinOneToOneOwner: true,
|
|
47
|
+
autoJoinRefsForFilters: true,
|
|
48
|
+
filtersOnRelations: true,
|
|
49
|
+
propagationOnPrototype: true,
|
|
50
|
+
populateAfterFlush: true,
|
|
51
|
+
serialization: {
|
|
52
|
+
includePrimaryKeys: true,
|
|
53
|
+
},
|
|
54
|
+
assign: {
|
|
55
|
+
updateNestedEntities: true,
|
|
56
|
+
updateByPrimaryKey: true,
|
|
57
|
+
mergeObjectProperties: false,
|
|
58
|
+
mergeEmbeddedProperties: true,
|
|
59
|
+
ignoreUndefined: false,
|
|
60
|
+
},
|
|
61
|
+
persistOnCreate: true,
|
|
62
|
+
upsertManaged: true,
|
|
63
|
+
forceEntityConstructor: false,
|
|
64
|
+
forceUndefined: false,
|
|
65
|
+
forceUtcTimezone: true,
|
|
66
|
+
processOnCreateHooksEarly: true,
|
|
67
|
+
ensureDatabase: true,
|
|
68
|
+
ensureIndexes: false,
|
|
69
|
+
batchSize: 300,
|
|
70
|
+
debug: false,
|
|
71
|
+
ignoreDeprecations: false,
|
|
72
|
+
verbose: false,
|
|
73
|
+
driverOptions: {},
|
|
74
|
+
migrations: {
|
|
75
|
+
tableName: 'mikro_orm_migrations',
|
|
76
|
+
glob: '!(*.d).{js,ts,cjs}',
|
|
77
|
+
silent: false,
|
|
78
|
+
transactional: true,
|
|
79
|
+
allOrNothing: true,
|
|
80
|
+
dropTables: true,
|
|
81
|
+
safe: false,
|
|
82
|
+
snapshot: true,
|
|
83
|
+
emit: 'ts',
|
|
84
|
+
fileName: (timestamp, name) => `Migration${timestamp}${name ? '_' + name : ''}`,
|
|
85
|
+
},
|
|
86
|
+
schemaGenerator: {
|
|
87
|
+
createForeignKeyConstraints: true,
|
|
88
|
+
ignoreSchema: [],
|
|
89
|
+
skipTables: [],
|
|
90
|
+
skipViews: [],
|
|
91
|
+
skipColumns: {},
|
|
92
|
+
},
|
|
93
|
+
embeddables: {
|
|
94
|
+
prefixMode: 'relative',
|
|
95
|
+
},
|
|
96
|
+
entityGenerator: {
|
|
97
|
+
forceUndefined: true,
|
|
98
|
+
undefinedDefaults: false,
|
|
99
|
+
scalarTypeInDecorator: false,
|
|
100
|
+
bidirectionalRelations: true,
|
|
101
|
+
identifiedReferences: true,
|
|
102
|
+
scalarPropertiesForRelations: 'never',
|
|
103
|
+
entityDefinition: 'defineEntity',
|
|
104
|
+
decorators: 'legacy',
|
|
105
|
+
enumMode: 'dictionary',
|
|
106
|
+
/* v8 ignore next */
|
|
107
|
+
fileName: (className) => className,
|
|
108
|
+
onlyPurePivotTables: false,
|
|
109
|
+
outputPurePivotTables: false,
|
|
110
|
+
readOnlyPivotTables: false,
|
|
111
|
+
useCoreBaseEntity: false,
|
|
112
|
+
},
|
|
113
|
+
metadataCache: {},
|
|
114
|
+
resultCache: {
|
|
115
|
+
adapter: MemoryCacheAdapter,
|
|
116
|
+
expiration: 1000, // 1s
|
|
117
|
+
options: {},
|
|
118
|
+
},
|
|
119
|
+
metadataProvider: MetadataProvider,
|
|
120
|
+
highlighter: new NullHighlighter(),
|
|
121
|
+
seeder: {
|
|
122
|
+
defaultSeeder: 'DatabaseSeeder',
|
|
123
|
+
glob: '!(*.d).{js,ts}',
|
|
124
|
+
emit: 'ts',
|
|
125
|
+
fileName: (className) => className,
|
|
126
|
+
},
|
|
127
|
+
preferReadReplicas: true,
|
|
128
|
+
dynamicImportProvider: /* v8 ignore next */ (id) => import(id),
|
|
129
129
|
};
|
|
130
130
|
/** Holds and validates all ORM configuration options, providing access to drivers, loggers, cache adapters, and other services. */
|
|
131
131
|
export class Configuration {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
132
|
+
#options;
|
|
133
|
+
#logger;
|
|
134
|
+
#slowQueryLogger;
|
|
135
|
+
#driver;
|
|
136
|
+
#platform;
|
|
137
|
+
#cache = new Map();
|
|
138
|
+
#extensions = new Map();
|
|
139
|
+
constructor(options, validate = true) {
|
|
140
|
+
if (options.dynamicImportProvider) {
|
|
141
|
+
globalThis.dynamicImportProvider = options.dynamicImportProvider;
|
|
142
|
+
}
|
|
143
|
+
this.#options = Utils.mergeConfig({}, DEFAULTS, options);
|
|
144
|
+
if (validate) {
|
|
145
|
+
this.validateOptions();
|
|
146
|
+
}
|
|
147
|
+
this.#options.loggerFactory ??= DefaultLogger.create;
|
|
148
|
+
this.#logger = this.#options.loggerFactory({
|
|
149
|
+
debugMode: this.#options.debug,
|
|
150
|
+
ignoreDeprecations: this.#options.ignoreDeprecations,
|
|
151
|
+
usesReplicas: (this.#options.replicas?.length ?? 0) > 0,
|
|
152
|
+
highlighter: this.#options.highlighter,
|
|
153
|
+
writer: this.#options.logger,
|
|
154
|
+
});
|
|
155
|
+
const cf = this.#options.compiledFunctions;
|
|
156
|
+
if (cf && cf.__version !== Utils.getORMVersion()) {
|
|
157
|
+
this.#logger.warn('discovery', `Compiled functions were generated with MikroORM v${cf.__version ?? 'unknown'}, but the current version is v${Utils.getORMVersion()}. Please regenerate with \`npx mikro-orm compile\`.`);
|
|
158
|
+
}
|
|
159
|
+
if (this.#options.driver) {
|
|
160
|
+
this.#driver = new this.#options.driver(this);
|
|
161
|
+
this.#platform = this.#driver.getPlatform();
|
|
162
|
+
this.#platform.setConfig(this);
|
|
163
|
+
this.init(validate);
|
|
164
|
+
}
|
|
142
165
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
166
|
+
/** Returns the database platform instance. */
|
|
167
|
+
getPlatform() {
|
|
168
|
+
return this.#platform;
|
|
146
169
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const cf = this.#options.compiledFunctions;
|
|
156
|
-
if (cf && cf.__version !== Utils.getORMVersion()) {
|
|
157
|
-
this.#logger.warn(
|
|
158
|
-
'discovery',
|
|
159
|
-
`Compiled functions were generated with MikroORM v${cf.__version ?? 'unknown'}, but the current version is v${Utils.getORMVersion()}. Please regenerate with \`npx mikro-orm compile\`.`,
|
|
160
|
-
);
|
|
170
|
+
/**
|
|
171
|
+
* Gets specific configuration option. Falls back to specified `defaultValue` if provided.
|
|
172
|
+
*/
|
|
173
|
+
get(key, defaultValue) {
|
|
174
|
+
if (typeof this.#options[key] !== 'undefined') {
|
|
175
|
+
return this.#options[key];
|
|
176
|
+
}
|
|
177
|
+
return defaultValue;
|
|
161
178
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
this.#platform.setConfig(this);
|
|
166
|
-
this.init(validate);
|
|
179
|
+
/** Returns all configuration options. */
|
|
180
|
+
getAll() {
|
|
181
|
+
return this.#options;
|
|
167
182
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
* Gets specific configuration option. Falls back to specified `defaultValue` if provided.
|
|
175
|
-
*/
|
|
176
|
-
get(key, defaultValue) {
|
|
177
|
-
if (typeof this.#options[key] !== 'undefined') {
|
|
178
|
-
return this.#options[key];
|
|
183
|
+
/**
|
|
184
|
+
* Overrides specified configuration value.
|
|
185
|
+
*/
|
|
186
|
+
set(key, value) {
|
|
187
|
+
this.#options[key] = value;
|
|
188
|
+
this.sync();
|
|
179
189
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Overrides specified configuration value.
|
|
188
|
-
*/
|
|
189
|
-
set(key, value) {
|
|
190
|
-
this.#options[key] = value;
|
|
191
|
-
this.sync();
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Resets the configuration to its default value
|
|
195
|
-
*/
|
|
196
|
-
reset(key) {
|
|
197
|
-
this.#options[key] = DEFAULTS[key];
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Gets Logger instance.
|
|
201
|
-
*/
|
|
202
|
-
getLogger() {
|
|
203
|
-
return this.#logger;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Gets the logger instance for slow queries.
|
|
207
|
-
* Falls back to the main logger if no custom slow query logger factory is configured.
|
|
208
|
-
*/
|
|
209
|
-
getSlowQueryLogger() {
|
|
210
|
-
this.#slowQueryLogger ??=
|
|
211
|
-
this.#options.slowQueryLoggerFactory?.({
|
|
212
|
-
debugMode: this.#options.debug,
|
|
213
|
-
writer: this.#options.logger,
|
|
214
|
-
highlighter: this.#options.highlighter,
|
|
215
|
-
usesReplicas: (this.#options.replicas?.length ?? 0) > 0,
|
|
216
|
-
}) ?? this.#logger;
|
|
217
|
-
return this.#slowQueryLogger;
|
|
218
|
-
}
|
|
219
|
-
/** Returns the configured dataloader type, normalizing boolean values. */
|
|
220
|
-
getDataloaderType() {
|
|
221
|
-
if (typeof this.#options.dataloader === 'boolean') {
|
|
222
|
-
return this.#options.dataloader ? DataloaderType.ALL : DataloaderType.NONE;
|
|
190
|
+
/**
|
|
191
|
+
* Resets the configuration to its default value
|
|
192
|
+
*/
|
|
193
|
+
reset(key) {
|
|
194
|
+
this.#options[key] = DEFAULTS[key];
|
|
223
195
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
return undefined;
|
|
196
|
+
/**
|
|
197
|
+
* Gets Logger instance.
|
|
198
|
+
*/
|
|
199
|
+
getLogger() {
|
|
200
|
+
return this.#logger;
|
|
230
201
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
getExtension(name) {
|
|
245
|
-
if (this.#cache.has(name)) {
|
|
246
|
-
return this.#cache.get(name);
|
|
202
|
+
/**
|
|
203
|
+
* Gets the logger instance for slow queries.
|
|
204
|
+
* Falls back to the main logger if no custom slow query logger factory is configured.
|
|
205
|
+
*/
|
|
206
|
+
getSlowQueryLogger() {
|
|
207
|
+
this.#slowQueryLogger ??=
|
|
208
|
+
this.#options.slowQueryLoggerFactory?.({
|
|
209
|
+
debugMode: this.#options.debug,
|
|
210
|
+
writer: this.#options.logger,
|
|
211
|
+
highlighter: this.#options.highlighter,
|
|
212
|
+
usesReplicas: (this.#options.replicas?.length ?? 0) > 0,
|
|
213
|
+
}) ?? this.#logger;
|
|
214
|
+
return this.#slowQueryLogger;
|
|
247
215
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
216
|
+
/** Returns the configured dataloader type, normalizing boolean values. */
|
|
217
|
+
getDataloaderType() {
|
|
218
|
+
if (typeof this.#options.dataloader === 'boolean') {
|
|
219
|
+
return this.#options.dataloader ? DataloaderType.ALL : DataloaderType.NONE;
|
|
220
|
+
}
|
|
221
|
+
return this.#options.dataloader;
|
|
252
222
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
getNamingStrategy() {
|
|
260
|
-
return this.getCachedService(this.#options.namingStrategy || this.#platform.getNamingStrategy());
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Gets instance of Hydrator. (cached)
|
|
264
|
-
*/
|
|
265
|
-
getHydrator(metadata) {
|
|
266
|
-
return this.getCachedService(this.#options.hydrator, metadata, this.#platform, this);
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Gets instance of Comparator. (cached)
|
|
270
|
-
*/
|
|
271
|
-
getComparator(metadata) {
|
|
272
|
-
return this.getCachedService(EntityComparator, metadata, this.#platform, this);
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Gets instance of MetadataProvider. (cached)
|
|
276
|
-
*/
|
|
277
|
-
getMetadataProvider() {
|
|
278
|
-
return this.getCachedService(this.#options.metadataProvider, this);
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Gets instance of metadata CacheAdapter. (cached)
|
|
282
|
-
*/
|
|
283
|
-
getMetadataCacheAdapter() {
|
|
284
|
-
return this.getCachedService(
|
|
285
|
-
this.#options.metadataCache.adapter,
|
|
286
|
-
this.#options.metadataCache.options,
|
|
287
|
-
this.#options.baseDir,
|
|
288
|
-
this.#options.metadataCache.pretty,
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Gets instance of CacheAdapter for result cache. (cached)
|
|
293
|
-
*/
|
|
294
|
-
getResultCacheAdapter() {
|
|
295
|
-
return this.getCachedService(this.#options.resultCache.adapter, {
|
|
296
|
-
expiration: this.#options.resultCache.expiration,
|
|
297
|
-
...this.#options.resultCache.options,
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Gets EntityRepository class to be instantiated.
|
|
302
|
-
*/
|
|
303
|
-
getRepositoryClass(repository) {
|
|
304
|
-
if (repository) {
|
|
305
|
-
return repository();
|
|
223
|
+
/** Returns the configured schema name, optionally skipping the platform's default schema. */
|
|
224
|
+
getSchema(skipDefaultSchema = false) {
|
|
225
|
+
if (skipDefaultSchema && this.#options.schema === this.#platform.getDefaultSchemaName()) {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
return this.#options.schema;
|
|
306
229
|
}
|
|
307
|
-
|
|
308
|
-
|
|
230
|
+
/**
|
|
231
|
+
* Gets current database driver instance.
|
|
232
|
+
*/
|
|
233
|
+
getDriver() {
|
|
234
|
+
return this.#driver;
|
|
309
235
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
* Creates instance of given service and caches it.
|
|
314
|
-
*/
|
|
315
|
-
getCachedService(cls, ...args) {
|
|
316
|
-
if (!this.#cache.has(cls.name)) {
|
|
317
|
-
this.#cache.set(cls.name, new cls(...args));
|
|
236
|
+
/** Registers a lazily-initialized extension by name. */
|
|
237
|
+
registerExtension(name, cb) {
|
|
238
|
+
this.#extensions.set(name, cb);
|
|
318
239
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
240
|
+
/** Returns a previously registered extension by name, initializing it on first access. */
|
|
241
|
+
getExtension(name) {
|
|
242
|
+
if (this.#cache.has(name)) {
|
|
243
|
+
return this.#cache.get(name);
|
|
244
|
+
}
|
|
245
|
+
const ext = this.#extensions.get(name);
|
|
246
|
+
/* v8 ignore next */
|
|
247
|
+
if (!ext) {
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
this.#cache.set(name, ext());
|
|
251
|
+
return this.#cache.get(name);
|
|
330
252
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
'No metadata cache adapter specified, please fill in `metadataCache.adapter` option or use the async MikroORM.init() method which can autoload it.',
|
|
337
|
-
);
|
|
253
|
+
/**
|
|
254
|
+
* Gets instance of NamingStrategy. (cached)
|
|
255
|
+
*/
|
|
256
|
+
getNamingStrategy() {
|
|
257
|
+
return this.getCachedService(this.#options.namingStrategy || this.#platform.getNamingStrategy());
|
|
338
258
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
} catch {
|
|
345
|
-
const url = /:\/\/.*\/([^?]+)/.exec(this.#options.clientUrl);
|
|
346
|
-
if (url) {
|
|
347
|
-
this.#options.dbName = this.get('dbName', decodeURIComponent(url[1]));
|
|
348
|
-
}
|
|
259
|
+
/**
|
|
260
|
+
* Gets instance of Hydrator. (cached)
|
|
261
|
+
*/
|
|
262
|
+
getHydrator(metadata) {
|
|
263
|
+
return this.getCachedService(this.#options.hydrator, metadata, this.#platform, this);
|
|
349
264
|
}
|
|
350
|
-
|
|
351
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Gets instance of Comparator. (cached)
|
|
267
|
+
*/
|
|
268
|
+
getComparator(metadata) {
|
|
269
|
+
return this.getCachedService(EntityComparator, metadata, this.#platform, this);
|
|
352
270
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (!this.#options.filtersOnRelations) {
|
|
359
|
-
this.#options.autoJoinRefsForFilters ??= false;
|
|
271
|
+
/**
|
|
272
|
+
* Gets instance of MetadataProvider. (cached)
|
|
273
|
+
*/
|
|
274
|
+
getMetadataProvider() {
|
|
275
|
+
return this.getCachedService(this.#options.metadataProvider, this);
|
|
360
276
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
this.#options.highlighter = new NullHighlighter();
|
|
277
|
+
/**
|
|
278
|
+
* Gets instance of metadata CacheAdapter. (cached)
|
|
279
|
+
*/
|
|
280
|
+
getMetadataCacheAdapter() {
|
|
281
|
+
return this.getCachedService(this.#options.metadataCache.adapter, this.#options.metadataCache.options, this.#options.baseDir, this.#options.metadataCache.pretty);
|
|
367
282
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
if ('type' in this.#options) {
|
|
377
|
-
throw new Error(
|
|
378
|
-
"The `type` option has been removed in v6, please fill in the `driver` option instead or use `defineConfig` helper (to define your ORM config) or `MikroORM` class (to call the `init` method) exported from the driver package (e.g. `import { defineConfig } from '@mikro-orm/mysql'; export default defineConfig({ ... })`).",
|
|
379
|
-
);
|
|
283
|
+
/**
|
|
284
|
+
* Gets instance of CacheAdapter for result cache. (cached)
|
|
285
|
+
*/
|
|
286
|
+
getResultCacheAdapter() {
|
|
287
|
+
return this.getCachedService(this.#options.resultCache.adapter, {
|
|
288
|
+
expiration: this.#options.resultCache.expiration,
|
|
289
|
+
...this.#options.resultCache.options,
|
|
290
|
+
});
|
|
380
291
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
292
|
+
/**
|
|
293
|
+
* Gets EntityRepository class to be instantiated.
|
|
294
|
+
*/
|
|
295
|
+
getRepositoryClass(repository) {
|
|
296
|
+
if (repository) {
|
|
297
|
+
return repository();
|
|
298
|
+
}
|
|
299
|
+
if (this.#options.entityRepository) {
|
|
300
|
+
return this.#options.entityRepository;
|
|
301
|
+
}
|
|
302
|
+
return this.#platform.getRepositoryClass();
|
|
385
303
|
}
|
|
386
|
-
|
|
387
|
-
|
|
304
|
+
/**
|
|
305
|
+
* Creates instance of given service and caches it.
|
|
306
|
+
*/
|
|
307
|
+
getCachedService(cls, ...args) {
|
|
308
|
+
if (!this.#cache.has(cls.name)) {
|
|
309
|
+
this.#cache.set(cls.name, new cls(...args));
|
|
310
|
+
}
|
|
311
|
+
return this.#cache.get(cls.name);
|
|
388
312
|
}
|
|
389
|
-
|
|
390
|
-
|
|
313
|
+
/** Clears the cached service instances, forcing re-creation on next access. */
|
|
314
|
+
resetServiceCache() {
|
|
315
|
+
this.#cache.clear();
|
|
391
316
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
317
|
+
init(validate) {
|
|
318
|
+
const useCache = this.getMetadataProvider().useCache();
|
|
319
|
+
const metadataCache = this.#options.metadataCache;
|
|
320
|
+
if (!useCache) {
|
|
321
|
+
metadataCache.adapter = NullCacheAdapter;
|
|
322
|
+
}
|
|
323
|
+
metadataCache.enabled ??= useCache;
|
|
324
|
+
this.#options.clientUrl ??= this.#platform.getDefaultClientUrl();
|
|
325
|
+
this.#options.implicitTransactions ??= this.#platform.usesImplicitTransactions();
|
|
326
|
+
if (validate && metadataCache.enabled && !metadataCache.adapter) {
|
|
327
|
+
throw new Error('No metadata cache adapter specified, please fill in `metadataCache.adapter` option or use the async MikroORM.init() method which can autoload it.');
|
|
328
|
+
}
|
|
329
|
+
try {
|
|
330
|
+
const url = new URL(this.#options.clientUrl);
|
|
331
|
+
if (url.pathname) {
|
|
332
|
+
this.#options.dbName = this.get('dbName', decodeURIComponent(url.pathname).substring(1));
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
const url = /:\/\/.*\/([^?]+)/.exec(this.#options.clientUrl);
|
|
337
|
+
if (url) {
|
|
338
|
+
this.#options.dbName = this.get('dbName', decodeURIComponent(url[1]));
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
if (validate && !this.#options.dbName && this.#options.clientUrl) {
|
|
342
|
+
throw new Error("No database specified, `clientUrl` option provided but it's missing the pathname.");
|
|
343
|
+
}
|
|
344
|
+
this.#options.schema ??= this.#platform.getDefaultSchemaName();
|
|
345
|
+
this.#options.charset ??= this.#platform.getDefaultCharset();
|
|
346
|
+
Object.keys(this.#options.filters).forEach(key => {
|
|
347
|
+
this.#options.filters[key].default ??= true;
|
|
348
|
+
});
|
|
349
|
+
if (!this.#options.filtersOnRelations) {
|
|
350
|
+
this.#options.autoJoinRefsForFilters ??= false;
|
|
351
|
+
}
|
|
352
|
+
this.#options.subscribers = [...this.#options.subscribers].map(subscriber => {
|
|
353
|
+
return subscriber.constructor.name === 'Function' ? new subscriber() : subscriber;
|
|
354
|
+
});
|
|
355
|
+
this.sync();
|
|
356
|
+
if (!colors.enabled()) {
|
|
357
|
+
this.#options.highlighter = new NullHighlighter();
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
sync() {
|
|
361
|
+
setEnv('MIKRO_ORM_COLORS', this.#options.colors);
|
|
362
|
+
this.#logger.setDebugMode(this.#options.debug);
|
|
363
|
+
this.#slowQueryLogger = undefined;
|
|
364
|
+
}
|
|
365
|
+
validateOptions() {
|
|
366
|
+
/* v8 ignore next */
|
|
367
|
+
if ('type' in this.#options) {
|
|
368
|
+
throw new Error("The `type` option has been removed in v6, please fill in the `driver` option instead or use `defineConfig` helper (to define your ORM config) or `MikroORM` class (to call the `init` method) exported from the driver package (e.g. `import { defineConfig } from '@mikro-orm/mysql'; export default defineConfig({ ... })`).");
|
|
369
|
+
}
|
|
370
|
+
if (!this.#options.driver) {
|
|
371
|
+
throw new Error("No driver specified, please fill in the `driver` option or use `defineConfig` helper (to define your ORM config) or `MikroORM` class (to call the `init` method) exported from the driver package (e.g. `import { defineConfig } from '@mikro-orm/mysql'; export defineConfig({ ... })`).");
|
|
372
|
+
}
|
|
373
|
+
if (!this.#options.dbName && !this.#options.clientUrl) {
|
|
374
|
+
throw new Error('No database specified, please fill in `dbName` or `clientUrl` option');
|
|
375
|
+
}
|
|
376
|
+
if (this.#options.entities.length === 0 && this.#options.discovery.warnWhenNoEntities) {
|
|
377
|
+
throw new Error('No entities found, please use `entities` option');
|
|
378
|
+
}
|
|
379
|
+
if (typeof this.#options.driverOptions === 'function' &&
|
|
380
|
+
this.#options.driverOptions.constructor.name === 'AsyncFunction') {
|
|
381
|
+
throw new Error('`driverOptions` callback cannot be async');
|
|
382
|
+
}
|
|
397
383
|
}
|
|
398
|
-
}
|
|
399
384
|
}
|
|
400
385
|
/**
|
|
401
386
|
* Type helper to make it easier to use `mikro-orm.config.js`.
|
|
402
387
|
*/
|
|
403
388
|
export function defineConfig(options) {
|
|
404
|
-
|
|
389
|
+
return options;
|
|
405
390
|
}
|