@mikro-orm/core 7.0.0-dev.1 → 7.0.0-dev.100
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 +96 -58
- package/EntityManager.js +465 -395
- package/MikroORM.d.ts +45 -35
- package/MikroORM.js +109 -160
- package/README.md +3 -2
- package/cache/CacheAdapter.js +1 -2
- package/cache/FileCacheAdapter.d.ts +2 -2
- package/cache/FileCacheAdapter.js +20 -27
- package/cache/GeneratedCacheAdapter.d.ts +2 -3
- package/cache/GeneratedCacheAdapter.js +1 -7
- package/cache/MemoryCacheAdapter.d.ts +1 -1
- package/cache/MemoryCacheAdapter.js +1 -5
- package/cache/NullCacheAdapter.d.ts +1 -1
- package/cache/NullCacheAdapter.js +1 -5
- package/cache/index.d.ts +4 -5
- package/cache/index.js +4 -21
- package/connections/Connection.d.ts +22 -14
- package/connections/Connection.js +27 -23
- package/connections/index.d.ts +1 -1
- package/connections/index.js +1 -17
- package/drivers/DatabaseDriver.d.ts +25 -15
- package/drivers/DatabaseDriver.js +77 -64
- package/drivers/IDatabaseDriver.d.ts +40 -16
- package/drivers/IDatabaseDriver.js +1 -4
- package/drivers/index.d.ts +2 -2
- package/drivers/index.js +2 -18
- package/entity/BaseEntity.d.ts +6 -7
- package/entity/BaseEntity.js +16 -23
- package/entity/Collection.d.ts +98 -34
- package/entity/Collection.js +466 -131
- package/entity/EntityAssigner.d.ts +3 -3
- package/entity/EntityAssigner.js +67 -64
- package/entity/EntityFactory.d.ts +10 -3
- package/entity/EntityFactory.js +112 -91
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +66 -53
- package/entity/EntityIdentifier.d.ts +1 -1
- package/entity/EntityIdentifier.js +1 -5
- package/entity/EntityLoader.d.ts +8 -7
- package/entity/EntityLoader.js +161 -128
- package/entity/EntityRepository.d.ts +8 -8
- package/entity/EntityRepository.js +7 -11
- package/entity/Reference.d.ts +10 -13
- package/entity/Reference.js +64 -46
- package/entity/WrappedEntity.d.ts +12 -17
- package/entity/WrappedEntity.js +22 -31
- package/entity/defineEntity.d.ts +568 -0
- package/entity/defineEntity.js +529 -0
- package/entity/index.d.ts +14 -13
- package/entity/index.js +14 -29
- package/entity/utils.d.ts +8 -1
- package/entity/utils.js +22 -13
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +65 -0
- package/entity/wrap.d.ts +1 -1
- package/entity/wrap.js +2 -6
- package/enums.d.ts +24 -9
- package/enums.js +50 -41
- package/errors.d.ts +11 -3
- package/errors.js +42 -32
- package/events/EventManager.d.ts +5 -4
- package/events/EventManager.js +26 -22
- package/events/EventSubscriber.d.ts +8 -5
- package/events/EventSubscriber.js +1 -2
- package/events/TransactionEventBroadcaster.d.ts +3 -3
- package/events/TransactionEventBroadcaster.js +1 -5
- package/events/index.d.ts +3 -3
- package/events/index.js +3 -19
- package/exceptions.js +18 -39
- package/hydration/Hydrator.d.ts +5 -5
- package/hydration/Hydrator.js +2 -6
- package/hydration/ObjectHydrator.d.ts +7 -7
- package/hydration/ObjectHydrator.js +58 -50
- package/hydration/index.d.ts +2 -2
- package/hydration/index.js +2 -18
- package/index.d.ts +21 -21
- package/index.js +20 -46
- package/logging/DefaultLogger.d.ts +2 -2
- package/logging/DefaultLogger.js +10 -13
- package/logging/Logger.d.ts +1 -1
- package/logging/Logger.js +1 -2
- package/logging/SimpleLogger.d.ts +3 -3
- package/logging/SimpleLogger.js +2 -6
- package/logging/colors.js +1 -5
- package/logging/index.d.ts +5 -4
- package/logging/index.js +5 -20
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +16 -0
- package/metadata/EntitySchema.d.ts +14 -10
- package/metadata/EntitySchema.js +78 -64
- package/metadata/MetadataDiscovery.d.ts +11 -14
- package/metadata/MetadataDiscovery.js +278 -317
- package/metadata/MetadataProvider.d.ts +13 -4
- package/metadata/MetadataProvider.js +47 -8
- package/metadata/MetadataStorage.d.ts +2 -7
- package/metadata/MetadataStorage.js +19 -35
- package/metadata/MetadataValidator.d.ts +3 -10
- package/metadata/MetadataValidator.js +51 -64
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +6 -6
- package/metadata/index.js +6 -22
- package/metadata/types.d.ts +480 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +7 -3
- package/naming-strategy/AbstractNamingStrategy.js +11 -9
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +1 -1
- package/naming-strategy/EntityCaseNamingStrategy.js +2 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +1 -1
- package/naming-strategy/MongoNamingStrategy.js +2 -6
- package/naming-strategy/NamingStrategy.d.ts +12 -2
- package/naming-strategy/NamingStrategy.js +1 -2
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -1
- package/naming-strategy/UnderscoreNamingStrategy.js +2 -6
- package/naming-strategy/index.d.ts +5 -5
- package/naming-strategy/index.js +5 -21
- package/not-supported.d.ts +2 -0
- package/not-supported.js +4 -0
- package/package.json +19 -20
- package/platforms/ExceptionConverter.d.ts +2 -2
- package/platforms/ExceptionConverter.js +4 -8
- package/platforms/Platform.d.ts +15 -22
- package/platforms/Platform.js +58 -88
- package/platforms/index.d.ts +2 -2
- package/platforms/index.js +2 -18
- package/serialization/EntitySerializer.d.ts +4 -2
- package/serialization/EntitySerializer.js +64 -51
- package/serialization/EntityTransformer.d.ts +1 -1
- package/serialization/EntityTransformer.js +48 -42
- package/serialization/SerializationContext.d.ts +2 -2
- package/serialization/SerializationContext.js +24 -25
- package/serialization/index.d.ts +3 -3
- package/serialization/index.js +3 -19
- package/types/ArrayType.d.ts +3 -3
- package/types/ArrayType.js +6 -11
- package/types/BigIntType.d.ts +12 -9
- package/types/BigIntType.js +6 -6
- package/types/BlobType.d.ts +3 -4
- package/types/BlobType.js +2 -11
- package/types/BooleanType.d.ts +5 -4
- package/types/BooleanType.js +5 -6
- package/types/CharacterType.d.ts +3 -3
- package/types/CharacterType.js +2 -6
- package/types/DateTimeType.d.ts +3 -3
- package/types/DateTimeType.js +2 -6
- package/types/DateType.d.ts +3 -3
- package/types/DateType.js +2 -6
- package/types/DecimalType.d.ts +9 -7
- package/types/DecimalType.js +5 -8
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +4 -7
- package/types/EnumArrayType.d.ts +4 -4
- package/types/EnumArrayType.js +4 -10
- package/types/EnumType.d.ts +3 -3
- package/types/EnumType.js +2 -6
- package/types/FloatType.d.ts +3 -3
- package/types/FloatType.js +2 -6
- package/types/IntegerType.d.ts +3 -3
- package/types/IntegerType.js +2 -6
- package/types/IntervalType.d.ts +3 -3
- package/types/IntervalType.js +2 -6
- package/types/JsonType.d.ts +4 -4
- package/types/JsonType.js +9 -8
- package/types/MediumIntType.d.ts +3 -3
- package/types/MediumIntType.js +2 -6
- package/types/SmallIntType.d.ts +3 -3
- package/types/SmallIntType.js +2 -6
- package/types/StringType.d.ts +3 -3
- package/types/StringType.js +2 -6
- package/types/TextType.d.ts +3 -3
- package/types/TextType.js +2 -6
- package/types/TimeType.d.ts +3 -3
- package/types/TimeType.js +4 -8
- package/types/TinyIntType.d.ts +3 -3
- package/types/TinyIntType.js +3 -6
- package/types/Type.d.ts +4 -6
- package/types/Type.js +6 -10
- package/types/Uint8ArrayType.d.ts +3 -4
- package/types/Uint8ArrayType.js +3 -12
- package/types/UnknownType.d.ts +3 -3
- package/types/UnknownType.js +2 -6
- package/types/UuidType.d.ts +3 -3
- package/types/UuidType.js +2 -6
- package/types/index.d.ts +25 -25
- package/types/index.js +52 -79
- package/typings.d.ts +134 -93
- package/typings.js +67 -65
- package/unit-of-work/ChangeSet.d.ts +1 -4
- package/unit-of-work/ChangeSet.js +13 -17
- package/unit-of-work/ChangeSetComputer.d.ts +8 -9
- package/unit-of-work/ChangeSetComputer.js +36 -38
- package/unit-of-work/ChangeSetPersister.d.ts +11 -9
- package/unit-of-work/ChangeSetPersister.js +100 -65
- package/unit-of-work/CommitOrderCalculator.d.ts +1 -1
- package/unit-of-work/CommitOrderCalculator.js +6 -10
- package/unit-of-work/IdentityMap.d.ts +1 -1
- package/unit-of-work/IdentityMap.js +1 -5
- package/unit-of-work/UnitOfWork.d.ts +16 -8
- package/unit-of-work/UnitOfWork.js +266 -209
- package/unit-of-work/index.d.ts +6 -6
- package/unit-of-work/index.js +6 -22
- package/utils/AbstractSchemaGenerator.d.ts +11 -11
- package/utils/AbstractSchemaGenerator.js +21 -20
- package/utils/Configuration.d.ts +774 -224
- package/utils/Configuration.js +166 -216
- package/utils/ConfigurationLoader.d.ts +1 -53
- package/utils/ConfigurationLoader.js +1 -367
- package/utils/Cursor.d.ts +6 -9
- package/utils/Cursor.js +25 -25
- package/utils/DataloaderUtils.d.ts +18 -8
- package/utils/DataloaderUtils.js +63 -21
- package/utils/EntityComparator.d.ts +9 -5
- package/utils/EntityComparator.js +155 -108
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +1 -5
- package/utils/QueryHelper.d.ts +12 -4
- package/utils/QueryHelper.js +110 -53
- package/utils/RawQueryFragment.d.ts +37 -14
- package/utils/RawQueryFragment.js +50 -33
- package/utils/RequestContext.d.ts +2 -2
- package/utils/RequestContext.js +3 -7
- package/utils/TransactionContext.d.ts +1 -1
- package/utils/TransactionContext.js +4 -8
- package/utils/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +223 -0
- package/utils/Utils.d.ts +16 -100
- package/utils/Utils.js +114 -332
- package/utils/clone.js +7 -11
- package/utils/env-vars.d.ts +3 -0
- package/utils/env-vars.js +87 -0
- package/utils/fs-utils.d.ts +12 -0
- package/utils/fs-utils.js +97 -0
- package/utils/index.d.ts +14 -13
- package/utils/index.js +14 -29
- package/utils/upsert-utils.d.ts +8 -3
- package/utils/upsert-utils.js +57 -10
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -16
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -33
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -14
- package/decorators/Embedded.d.ts +0 -18
- package/decorators/Embedded.js +0 -20
- package/decorators/Entity.d.ts +0 -18
- package/decorators/Entity.js +0 -16
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -19
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -11
- package/decorators/Formula.d.ts +0 -5
- package/decorators/Formula.js +0 -18
- package/decorators/Indexed.d.ts +0 -17
- package/decorators/Indexed.js +0 -24
- package/decorators/ManyToMany.d.ts +0 -40
- package/decorators/ManyToMany.js +0 -16
- package/decorators/ManyToOne.d.ts +0 -30
- package/decorators/ManyToOne.js +0 -16
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -20
- package/decorators/OneToOne.d.ts +0 -24
- package/decorators/OneToOne.js +0 -10
- package/decorators/PrimaryKey.d.ts +0 -9
- package/decorators/PrimaryKey.js +0 -23
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -34
- package/decorators/Transactional.d.ts +0 -13
- package/decorators/Transactional.js +0 -31
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -59
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -36
- package/entity/ArrayCollection.d.ts +0 -116
- package/entity/ArrayCollection.js +0 -399
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -154
- package/index.mjs +0 -199
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -48
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -31
package/utils/Configuration.js
CHANGED
|
@@ -1,140 +1,132 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
defaultSeeder: 'DatabaseSeeder',
|
|
131
|
-
glob: '!(*.d).{js,ts}',
|
|
132
|
-
emit: 'ts',
|
|
133
|
-
fileName: (className) => className,
|
|
134
|
-
},
|
|
135
|
-
preferReadReplicas: true,
|
|
136
|
-
dynamicImportProvider: /* istanbul ignore next */ (id) => import(id),
|
|
137
|
-
};
|
|
1
|
+
import { NullCacheAdapter } from '../cache/NullCacheAdapter.js';
|
|
2
|
+
import { ObjectHydrator } from '../hydration/ObjectHydrator.js';
|
|
3
|
+
import { NullHighlighter } from '../utils/NullHighlighter.js';
|
|
4
|
+
import { DefaultLogger } from '../logging/DefaultLogger.js';
|
|
5
|
+
import { colors } from '../logging/colors.js';
|
|
6
|
+
import { Utils } from '../utils/Utils.js';
|
|
7
|
+
import { MetadataProvider } from '../metadata/MetadataProvider.js';
|
|
8
|
+
import { NotFoundError } from '../errors.js';
|
|
9
|
+
import { RequestContext } from './RequestContext.js';
|
|
10
|
+
import { DataloaderType, FlushMode, LoadStrategy, PopulateHint } from '../enums.js';
|
|
11
|
+
import { MemoryCacheAdapter } from '../cache/MemoryCacheAdapter.js';
|
|
12
|
+
import { EntityComparator } from './EntityComparator.js';
|
|
13
|
+
const DEFAULTS = {
|
|
14
|
+
pool: {},
|
|
15
|
+
entities: [],
|
|
16
|
+
entitiesTs: [],
|
|
17
|
+
extensions: [],
|
|
18
|
+
subscribers: [],
|
|
19
|
+
filters: {},
|
|
20
|
+
discovery: {
|
|
21
|
+
warnWhenNoEntities: true,
|
|
22
|
+
checkDuplicateTableNames: true,
|
|
23
|
+
checkDuplicateFieldNames: true,
|
|
24
|
+
checkDuplicateEntities: true,
|
|
25
|
+
checkNonPersistentCompositeProps: true,
|
|
26
|
+
inferDefaultValues: true,
|
|
27
|
+
},
|
|
28
|
+
validateRequired: true,
|
|
29
|
+
context: (name) => RequestContext.getEntityManager(name),
|
|
30
|
+
contextName: 'default',
|
|
31
|
+
allowGlobalContext: false,
|
|
32
|
+
// eslint-disable-next-line no-console
|
|
33
|
+
logger: console.log.bind(console),
|
|
34
|
+
colors: true,
|
|
35
|
+
findOneOrFailHandler: (entityName, where) => NotFoundError.findOneFailed(entityName, where),
|
|
36
|
+
findExactlyOneOrFailHandler: (entityName, where) => NotFoundError.findExactlyOneFailed(entityName, where),
|
|
37
|
+
baseDir: process.cwd(),
|
|
38
|
+
hydrator: ObjectHydrator,
|
|
39
|
+
flushMode: FlushMode.AUTO,
|
|
40
|
+
loadStrategy: LoadStrategy.BALANCED,
|
|
41
|
+
dataloader: DataloaderType.NONE,
|
|
42
|
+
populateWhere: PopulateHint.ALL,
|
|
43
|
+
ignoreUndefinedInQuery: false,
|
|
44
|
+
onQuery: (sql) => sql,
|
|
45
|
+
autoJoinOneToOneOwner: true,
|
|
46
|
+
autoJoinRefsForFilters: true,
|
|
47
|
+
filtersOnRelations: true,
|
|
48
|
+
propagationOnPrototype: true,
|
|
49
|
+
populateAfterFlush: true,
|
|
50
|
+
serialization: {
|
|
51
|
+
includePrimaryKeys: true,
|
|
52
|
+
},
|
|
53
|
+
assign: {
|
|
54
|
+
updateNestedEntities: true,
|
|
55
|
+
updateByPrimaryKey: true,
|
|
56
|
+
mergeObjectProperties: false,
|
|
57
|
+
mergeEmbeddedProperties: true,
|
|
58
|
+
ignoreUndefined: false,
|
|
59
|
+
},
|
|
60
|
+
persistOnCreate: true,
|
|
61
|
+
upsertManaged: true,
|
|
62
|
+
forceEntityConstructor: false,
|
|
63
|
+
forceUndefined: false,
|
|
64
|
+
processOnCreateHooksEarly: true,
|
|
65
|
+
ensureDatabase: true,
|
|
66
|
+
ensureIndexes: false,
|
|
67
|
+
batchSize: 300,
|
|
68
|
+
debug: false,
|
|
69
|
+
ignoreDeprecations: false,
|
|
70
|
+
verbose: false,
|
|
71
|
+
driverOptions: {},
|
|
72
|
+
migrations: {
|
|
73
|
+
tableName: 'mikro_orm_migrations',
|
|
74
|
+
glob: '!(*.d).{js,ts,cjs}',
|
|
75
|
+
silent: false,
|
|
76
|
+
transactional: true,
|
|
77
|
+
disableForeignKeys: false,
|
|
78
|
+
allOrNothing: true,
|
|
79
|
+
dropTables: true,
|
|
80
|
+
safe: false,
|
|
81
|
+
snapshot: true,
|
|
82
|
+
emit: 'ts',
|
|
83
|
+
fileName: (timestamp, name) => `Migration${timestamp}${name ? '_' + name : ''}`,
|
|
84
|
+
},
|
|
85
|
+
schemaGenerator: {
|
|
86
|
+
disableForeignKeys: false,
|
|
87
|
+
createForeignKeyConstraints: true,
|
|
88
|
+
ignoreSchema: [],
|
|
89
|
+
skipTables: [],
|
|
90
|
+
skipColumns: {},
|
|
91
|
+
},
|
|
92
|
+
embeddables: {
|
|
93
|
+
prefixMode: 'relative',
|
|
94
|
+
},
|
|
95
|
+
entityGenerator: {
|
|
96
|
+
forceUndefined: true,
|
|
97
|
+
undefinedDefaults: false,
|
|
98
|
+
scalarTypeInDecorator: false,
|
|
99
|
+
bidirectionalRelations: true,
|
|
100
|
+
identifiedReferences: true,
|
|
101
|
+
scalarPropertiesForRelations: 'never',
|
|
102
|
+
entityDefinition: 'defineEntity',
|
|
103
|
+
decorators: 'legacy',
|
|
104
|
+
enumMode: 'dictionary',
|
|
105
|
+
/* v8 ignore next */
|
|
106
|
+
fileName: (className) => className,
|
|
107
|
+
onlyPurePivotTables: false,
|
|
108
|
+
outputPurePivotTables: false,
|
|
109
|
+
readOnlyPivotTables: false,
|
|
110
|
+
useCoreBaseEntity: false,
|
|
111
|
+
},
|
|
112
|
+
metadataCache: {},
|
|
113
|
+
resultCache: {
|
|
114
|
+
adapter: MemoryCacheAdapter,
|
|
115
|
+
expiration: 1000, // 1s
|
|
116
|
+
options: {},
|
|
117
|
+
},
|
|
118
|
+
metadataProvider: MetadataProvider,
|
|
119
|
+
highlighter: new NullHighlighter(),
|
|
120
|
+
seeder: {
|
|
121
|
+
defaultSeeder: 'DatabaseSeeder',
|
|
122
|
+
glob: '!(*.d).{js,ts}',
|
|
123
|
+
emit: 'ts',
|
|
124
|
+
fileName: (className) => className,
|
|
125
|
+
},
|
|
126
|
+
preferReadReplicas: true,
|
|
127
|
+
dynamicImportProvider: /* v8 ignore next */ (id) => import(id),
|
|
128
|
+
};
|
|
129
|
+
export class Configuration {
|
|
138
130
|
options;
|
|
139
131
|
logger;
|
|
140
132
|
driver;
|
|
@@ -143,15 +135,14 @@ class Configuration {
|
|
|
143
135
|
extensions = new Map();
|
|
144
136
|
constructor(options, validate = true) {
|
|
145
137
|
if (options.dynamicImportProvider) {
|
|
146
|
-
|
|
138
|
+
Utils.dynamicImportProvider = options.dynamicImportProvider;
|
|
147
139
|
}
|
|
148
|
-
this.options =
|
|
149
|
-
this.options.baseDir =
|
|
150
|
-
this.options.preferTs ??= options.tsNode;
|
|
140
|
+
this.options = Utils.mergeConfig({}, DEFAULTS, options);
|
|
141
|
+
this.options.baseDir = Utils.absolutePath(this.options.baseDir);
|
|
151
142
|
if (validate) {
|
|
152
143
|
this.validateOptions();
|
|
153
144
|
}
|
|
154
|
-
this.options.loggerFactory ??=
|
|
145
|
+
this.options.loggerFactory ??= DefaultLogger.create;
|
|
155
146
|
this.logger = this.options.loggerFactory({
|
|
156
147
|
debugMode: this.options.debug,
|
|
157
148
|
ignoreDeprecations: this.options.ignoreDeprecations,
|
|
@@ -163,7 +154,6 @@ class Configuration {
|
|
|
163
154
|
this.driver = new this.options.driver(this);
|
|
164
155
|
this.platform = this.driver.getPlatform();
|
|
165
156
|
this.platform.setConfig(this);
|
|
166
|
-
this.detectSourceFolder(options);
|
|
167
157
|
this.init(validate);
|
|
168
158
|
}
|
|
169
159
|
}
|
|
@@ -193,7 +183,7 @@ class Configuration {
|
|
|
193
183
|
* Resets the configuration to its default value
|
|
194
184
|
*/
|
|
195
185
|
reset(key) {
|
|
196
|
-
this.options[key] =
|
|
186
|
+
this.options[key] = DEFAULTS[key];
|
|
197
187
|
}
|
|
198
188
|
/**
|
|
199
189
|
* Gets Logger instance.
|
|
@@ -203,19 +193,10 @@ class Configuration {
|
|
|
203
193
|
}
|
|
204
194
|
getDataloaderType() {
|
|
205
195
|
if (typeof this.options.dataloader === 'boolean') {
|
|
206
|
-
return this.options.dataloader ?
|
|
196
|
+
return this.options.dataloader ? DataloaderType.ALL : DataloaderType.NONE;
|
|
207
197
|
}
|
|
208
198
|
return this.options.dataloader;
|
|
209
199
|
}
|
|
210
|
-
/**
|
|
211
|
-
* Gets current client URL (connection string).
|
|
212
|
-
*/
|
|
213
|
-
getClientUrl(hidePassword = false) {
|
|
214
|
-
if (hidePassword) {
|
|
215
|
-
return this.options.clientUrl.replace(/\/\/([^:]+):(.+)@/, '//$1:*****@');
|
|
216
|
-
}
|
|
217
|
-
return this.options.clientUrl;
|
|
218
|
-
}
|
|
219
200
|
getSchema(skipDefaultSchema = false) {
|
|
220
201
|
if (skipDefaultSchema && this.options.schema === this.platform.getDefaultSchemaName()) {
|
|
221
202
|
return undefined;
|
|
@@ -236,12 +217,12 @@ class Configuration {
|
|
|
236
217
|
return this.cache.get(name);
|
|
237
218
|
}
|
|
238
219
|
const ext = this.extensions.get(name);
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return
|
|
220
|
+
/* v8 ignore next */
|
|
221
|
+
if (!ext) {
|
|
222
|
+
return undefined;
|
|
242
223
|
}
|
|
243
|
-
|
|
244
|
-
return
|
|
224
|
+
this.cache.set(name, ext());
|
|
225
|
+
return this.cache.get(name);
|
|
245
226
|
}
|
|
246
227
|
/**
|
|
247
228
|
* Gets instance of NamingStrategy. (cached)
|
|
@@ -259,7 +240,7 @@ class Configuration {
|
|
|
259
240
|
* Gets instance of Comparator. (cached)
|
|
260
241
|
*/
|
|
261
242
|
getComparator(metadata) {
|
|
262
|
-
return this.getCachedService(
|
|
243
|
+
return this.getCachedService(EntityComparator, metadata, this.platform);
|
|
263
244
|
}
|
|
264
245
|
/**
|
|
265
246
|
* Gets instance of MetadataProvider. (cached)
|
|
@@ -296,8 +277,7 @@ class Configuration {
|
|
|
296
277
|
*/
|
|
297
278
|
getCachedService(cls, ...args) {
|
|
298
279
|
if (!this.cache.has(cls.name)) {
|
|
299
|
-
|
|
300
|
-
this.cache.set(cls.name, new Class(...args));
|
|
280
|
+
this.cache.set(cls.name, new cls(...args));
|
|
301
281
|
}
|
|
302
282
|
return this.cache.get(cls.name);
|
|
303
283
|
}
|
|
@@ -305,26 +285,25 @@ class Configuration {
|
|
|
305
285
|
this.cache.clear();
|
|
306
286
|
}
|
|
307
287
|
init(validate) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
this.options.metadataCache.enabled = this.getMetadataProvider().useCache();
|
|
288
|
+
const useCache = this.getMetadataProvider().useCache();
|
|
289
|
+
const metadataCache = this.options.metadataCache;
|
|
290
|
+
if (!useCache) {
|
|
291
|
+
metadataCache.adapter = NullCacheAdapter;
|
|
313
292
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
if (
|
|
318
|
-
|
|
293
|
+
metadataCache.enabled ??= useCache;
|
|
294
|
+
this.options.clientUrl ??= this.platform.getDefaultClientUrl();
|
|
295
|
+
this.options.implicitTransactions ??= this.platform.usesImplicitTransactions();
|
|
296
|
+
if (metadataCache.enabled && !metadataCache.adapter) {
|
|
297
|
+
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.');
|
|
319
298
|
}
|
|
320
299
|
try {
|
|
321
|
-
const url = new URL(this.
|
|
300
|
+
const url = new URL(this.options.clientUrl);
|
|
322
301
|
if (url.pathname) {
|
|
323
302
|
this.options.dbName = this.get('dbName', decodeURIComponent(url.pathname).substring(1));
|
|
324
303
|
}
|
|
325
304
|
}
|
|
326
305
|
catch {
|
|
327
|
-
const url = this.
|
|
306
|
+
const url = this.options.clientUrl.match(/:\/\/.*\/([^?]+)/);
|
|
328
307
|
if (url) {
|
|
329
308
|
this.options.dbName = this.get('dbName', decodeURIComponent(url[1]));
|
|
330
309
|
}
|
|
@@ -332,59 +311,28 @@ class Configuration {
|
|
|
332
311
|
if (validate && !this.options.dbName && this.options.clientUrl) {
|
|
333
312
|
throw new Error("No database specified, `clientUrl` option provided but it's missing the pathname.");
|
|
334
313
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
338
|
-
if (!this.options.charset) {
|
|
339
|
-
this.options.charset = this.platform.getDefaultCharset();
|
|
340
|
-
}
|
|
314
|
+
this.options.schema ??= this.platform.getDefaultSchemaName();
|
|
315
|
+
this.options.charset ??= this.platform.getDefaultCharset();
|
|
341
316
|
Object.keys(this.options.filters).forEach(key => {
|
|
342
317
|
this.options.filters[key].default ??= true;
|
|
343
318
|
});
|
|
344
|
-
|
|
319
|
+
if (!this.options.filtersOnRelations) {
|
|
320
|
+
this.options.autoJoinRefsForFilters ??= false;
|
|
321
|
+
}
|
|
322
|
+
this.options.subscribers = [...this.options.subscribers].map(subscriber => {
|
|
345
323
|
return subscriber.constructor.name === 'Function' ? new subscriber() : subscriber;
|
|
346
324
|
});
|
|
347
325
|
this.sync();
|
|
348
|
-
if (!
|
|
349
|
-
this.options.highlighter = new
|
|
326
|
+
if (!colors.enabled()) {
|
|
327
|
+
this.options.highlighter = new NullHighlighter();
|
|
350
328
|
}
|
|
351
329
|
}
|
|
352
330
|
sync() {
|
|
353
331
|
process.env.MIKRO_ORM_COLORS = '' + this.options.colors;
|
|
354
|
-
this.options.tsNode = this.options.preferTs;
|
|
355
332
|
this.logger.setDebugMode(this.options.debug);
|
|
356
333
|
}
|
|
357
|
-
/**
|
|
358
|
-
* Checks if `src` folder exists, it so, tries to adjust the migrations and seeders paths automatically to use it.
|
|
359
|
-
* If there is a `dist` or `build` folder, it will be used for the JS variant (`path` option), while the `src` folder will be
|
|
360
|
-
* used for the TS variant (`pathTs` option).
|
|
361
|
-
*
|
|
362
|
-
* If the default folder exists (e.g. `/migrations`), the config will respect that, so this auto-detection should not
|
|
363
|
-
* break existing projects, only help with the new ones.
|
|
364
|
-
*/
|
|
365
|
-
detectSourceFolder(options) {
|
|
366
|
-
if (!(0, fs_extra_1.pathExistsSync)(this.options.baseDir + '/src')) {
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
const migrationsPathExists = (0, fs_extra_1.pathExistsSync)(this.options.baseDir + '/' + this.options.migrations.path);
|
|
370
|
-
const seedersPathExists = (0, fs_extra_1.pathExistsSync)(this.options.baseDir + '/' + this.options.seeder.path);
|
|
371
|
-
const distDir = (0, fs_extra_1.pathExistsSync)(this.options.baseDir + '/dist');
|
|
372
|
-
const buildDir = (0, fs_extra_1.pathExistsSync)(this.options.baseDir + '/build');
|
|
373
|
-
// if neither `dist` nor `build` exist, we use the `src` folder as it might be a JS project without building, but with `src` folder
|
|
374
|
-
const path = distDir ? './dist' : (buildDir ? './build' : './src');
|
|
375
|
-
// only if the user did not provide any values and if the default path does not exist
|
|
376
|
-
if (!options.migrations?.path && !options.migrations?.pathTs && !migrationsPathExists) {
|
|
377
|
-
this.options.migrations.path = `${path}/migrations`;
|
|
378
|
-
this.options.migrations.pathTs = './src/migrations';
|
|
379
|
-
}
|
|
380
|
-
// only if the user did not provide any values and if the default path does not exist
|
|
381
|
-
if (!options.seeder?.path && !options.seeder?.pathTs && !seedersPathExists) {
|
|
382
|
-
this.options.seeder.path = `${path}/seeders`;
|
|
383
|
-
this.options.seeder.pathTs = './src/seeders';
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
334
|
validateOptions() {
|
|
387
|
-
/*
|
|
335
|
+
/* v8 ignore next */
|
|
388
336
|
if ('type' in this.options) {
|
|
389
337
|
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({ ... })`).');
|
|
390
338
|
}
|
|
@@ -397,12 +345,14 @@ class Configuration {
|
|
|
397
345
|
if (this.options.entities.length === 0 && this.options.discovery.warnWhenNoEntities) {
|
|
398
346
|
throw new Error('No entities found, please use `entities` option');
|
|
399
347
|
}
|
|
348
|
+
if (typeof this.options.driverOptions === 'function' && this.options.driverOptions.constructor.name === 'AsyncFunction') {
|
|
349
|
+
throw new Error('`driverOptions` callback cannot be async');
|
|
350
|
+
}
|
|
400
351
|
}
|
|
401
352
|
}
|
|
402
|
-
exports.Configuration = Configuration;
|
|
403
353
|
/**
|
|
404
354
|
* Type helper to make it easier to use `mikro-orm.config.js`.
|
|
405
355
|
*/
|
|
406
|
-
function defineConfig(options) {
|
|
356
|
+
export function defineConfig(options) {
|
|
407
357
|
return options;
|
|
408
358
|
}
|
|
@@ -1,53 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { EntityManagerType, IDatabaseDriver } from '../drivers';
|
|
3
|
-
import type { Dictionary } from '../typings';
|
|
4
|
-
import { Configuration, type Options } from './Configuration';
|
|
5
|
-
/**
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
export declare class ConfigurationLoader {
|
|
9
|
-
/**
|
|
10
|
-
* Gets a named configuration
|
|
11
|
-
*
|
|
12
|
-
* @param contextName Load a config with the given `contextName` value. Used when config file exports array or factory function. Setting it to "default" matches also config objects without `contextName` set.
|
|
13
|
-
* @param paths Array of possible paths for a configuration file. Files will be checked in order, and the first existing one will be used. Defaults to the output of {@link ConfigurationLoader.getConfigPaths}.
|
|
14
|
-
* @param options Additional options to augment the final configuration with.
|
|
15
|
-
*/
|
|
16
|
-
static getConfiguration<D extends IDatabaseDriver = IDatabaseDriver, EM extends D[typeof EntityManagerType] & EntityManager = EntityManager>(contextName: string, paths?: string[], options?: Partial<Options>): Promise<Configuration<D, EM>>;
|
|
17
|
-
/**
|
|
18
|
-
* Gets the default config from the default paths
|
|
19
|
-
*
|
|
20
|
-
* @deprecated Prefer to explicitly set the `contextName` at the first argument. This signature is available for backwards compatibility, and may be removed in v7.
|
|
21
|
-
*/
|
|
22
|
-
static getConfiguration<D extends IDatabaseDriver = IDatabaseDriver, EM extends D[typeof EntityManagerType] & EntityManager = EntityManager>(): Promise<Configuration<D, EM>>;
|
|
23
|
-
/**
|
|
24
|
-
* Gets default configuration out of the default paths, and possibly from `process.argv`
|
|
25
|
-
*
|
|
26
|
-
* @param validate Whether to validate the final configuration.
|
|
27
|
-
* @param options Additional options to augment the final configuration with (just before validation).
|
|
28
|
-
*
|
|
29
|
-
* @deprecated Use the other overloads of this method. This signature will be removed in v7.
|
|
30
|
-
*/
|
|
31
|
-
static getConfiguration<D extends IDatabaseDriver = IDatabaseDriver, EM extends D[typeof EntityManagerType] & EntityManager = EntityManager>(validate: boolean, options?: Partial<Options>): Promise<Configuration<D, EM>>;
|
|
32
|
-
static getConfigFile(paths: string[]): Promise<[string, unknown] | []>;
|
|
33
|
-
static getPackageConfig(basePath?: string): Dictionary;
|
|
34
|
-
static getSettings(): Settings;
|
|
35
|
-
static configPathsFromArg(): string[] | undefined;
|
|
36
|
-
static getConfigPaths(): string[];
|
|
37
|
-
static isESM(): boolean;
|
|
38
|
-
static registerTsNode(configPath?: string): boolean;
|
|
39
|
-
static registerDotenv<D extends IDatabaseDriver>(options?: Options<D> | Configuration<D>): void;
|
|
40
|
-
static loadEnvironmentVars<D extends IDatabaseDriver>(): Partial<Options<D>>;
|
|
41
|
-
static getORMPackages(): Set<string>;
|
|
42
|
-
/** @internal */
|
|
43
|
-
static commonJSCompat(options: Partial<Options>): void;
|
|
44
|
-
static getORMPackageVersion(name: string): string | undefined;
|
|
45
|
-
static checkPackageVersion(): string;
|
|
46
|
-
}
|
|
47
|
-
export interface Settings {
|
|
48
|
-
alwaysAllowTs?: boolean;
|
|
49
|
-
verbose?: boolean;
|
|
50
|
-
useTsNode?: boolean;
|
|
51
|
-
tsConfigPath?: string;
|
|
52
|
-
configPaths?: string[];
|
|
53
|
-
}
|
|
1
|
+
export {};
|