@mikro-orm/core 7.0.0-dev.33 → 7.0.0-dev.331
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 +70 -75
- package/EntityManager.js +487 -402
- package/MikroORM.d.ts +45 -38
- package/MikroORM.js +123 -156
- package/README.md +7 -4
- package/cache/FileCacheAdapter.d.ts +2 -7
- package/cache/FileCacheAdapter.js +35 -30
- package/cache/GeneratedCacheAdapter.d.ts +1 -2
- package/cache/GeneratedCacheAdapter.js +6 -8
- package/cache/MemoryCacheAdapter.d.ts +1 -2
- package/cache/MemoryCacheAdapter.js +8 -8
- package/cache/index.d.ts +1 -2
- package/cache/index.js +0 -2
- package/connections/Connection.d.ts +12 -5
- package/connections/Connection.js +37 -15
- package/drivers/DatabaseDriver.d.ts +25 -18
- package/drivers/DatabaseDriver.js +144 -45
- package/drivers/IDatabaseDriver.d.ts +118 -23
- package/entity/BaseEntity.d.ts +63 -4
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +95 -31
- package/entity/Collection.js +487 -139
- package/entity/EntityAssigner.js +37 -25
- package/entity/EntityFactory.d.ts +8 -9
- package/entity/EntityFactory.js +152 -100
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +69 -27
- package/entity/EntityLoader.d.ts +12 -13
- package/entity/EntityLoader.js +286 -125
- package/entity/EntityRepository.d.ts +28 -8
- package/entity/EntityRepository.js +8 -2
- package/entity/PolymorphicRef.d.ts +12 -0
- package/entity/PolymorphicRef.js +18 -0
- package/entity/Reference.d.ts +3 -8
- package/entity/Reference.js +62 -29
- package/entity/WrappedEntity.d.ts +7 -10
- package/entity/WrappedEntity.js +6 -7
- package/entity/defineEntity.d.ts +472 -313
- package/entity/defineEntity.js +134 -290
- package/entity/index.d.ts +2 -2
- package/entity/index.js +2 -2
- package/entity/utils.d.ts +6 -1
- package/entity/utils.js +46 -11
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +66 -0
- package/enums.d.ts +8 -6
- package/enums.js +13 -17
- package/errors.d.ts +26 -16
- package/errors.js +63 -31
- package/events/EventManager.d.ts +3 -5
- package/events/EventManager.js +37 -26
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/exceptions.js +9 -2
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +5 -6
- package/hydration/ObjectHydrator.js +109 -50
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +3 -4
- package/logging/SimpleLogger.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +4 -6
- package/logging/index.d.ts +2 -1
- package/logging/index.js +1 -1
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +11 -0
- package/metadata/EntitySchema.d.ts +47 -23
- package/metadata/EntitySchema.js +103 -34
- package/metadata/MetadataDiscovery.d.ts +65 -18
- package/metadata/MetadataDiscovery.js +940 -424
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +71 -2
- package/metadata/MetadataStorage.d.ts +11 -13
- package/metadata/MetadataStorage.js +79 -48
- package/metadata/MetadataValidator.d.ts +32 -9
- package/metadata/MetadataValidator.js +214 -44
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/metadata/types.d.ts +577 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
- package/naming-strategy/AbstractNamingStrategy.js +26 -5
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +7 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
- package/naming-strategy/MongoNamingStrategy.js +6 -6
- package/naming-strategy/NamingStrategy.d.ts +28 -4
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/not-supported.d.ts +2 -0
- package/not-supported.js +8 -0
- package/package.json +47 -36
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +33 -15
- package/platforms/Platform.js +125 -69
- package/serialization/EntitySerializer.d.ts +6 -3
- package/serialization/EntitySerializer.js +54 -30
- package/serialization/EntityTransformer.js +37 -22
- package/serialization/SerializationContext.d.ts +10 -14
- package/serialization/SerializationContext.js +24 -19
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.js +1 -1
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +1 -0
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.js +2 -2
- package/types/DoubleType.js +1 -1
- package/types/EnumArrayType.js +1 -2
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/TinyIntType.js +1 -1
- package/types/Type.d.ts +2 -4
- package/types/Type.js +3 -3
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +1 -4
- package/types/UuidType.d.ts +2 -0
- package/types/UuidType.js +14 -2
- package/types/index.d.ts +3 -2
- package/typings.d.ts +427 -170
- package/typings.js +100 -45
- package/unit-of-work/ChangeSet.d.ts +4 -6
- package/unit-of-work/ChangeSet.js +8 -9
- package/unit-of-work/ChangeSetComputer.d.ts +2 -12
- package/unit-of-work/ChangeSetComputer.js +61 -38
- package/unit-of-work/ChangeSetPersister.d.ts +10 -17
- package/unit-of-work/ChangeSetPersister.js +136 -73
- package/unit-of-work/CommitOrderCalculator.d.ts +13 -14
- package/unit-of-work/CommitOrderCalculator.js +22 -20
- package/unit-of-work/IdentityMap.d.ts +12 -3
- package/unit-of-work/IdentityMap.js +51 -13
- package/unit-of-work/UnitOfWork.d.ts +39 -23
- package/unit-of-work/UnitOfWork.js +441 -246
- package/utils/AbstractMigrator.d.ts +101 -0
- package/utils/AbstractMigrator.js +303 -0
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +30 -18
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +647 -185
- package/utils/Configuration.js +215 -252
- package/utils/ConfigurationLoader.d.ts +1 -52
- package/utils/ConfigurationLoader.js +1 -330
- package/utils/Cursor.d.ts +3 -6
- package/utils/Cursor.js +32 -17
- package/utils/DataloaderUtils.d.ts +10 -5
- package/utils/DataloaderUtils.js +42 -22
- package/utils/EntityComparator.d.ts +21 -21
- package/utils/EntityComparator.js +224 -118
- package/utils/QueryHelper.d.ts +34 -7
- package/utils/QueryHelper.js +183 -72
- package/utils/RawQueryFragment.d.ts +28 -34
- package/utils/RawQueryFragment.js +37 -72
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.js +11 -8
- package/utils/Utils.d.ts +16 -127
- package/utils/Utils.js +104 -402
- package/utils/clone.js +13 -23
- package/utils/env-vars.d.ts +7 -0
- package/utils/env-vars.js +98 -0
- package/utils/fs-utils.d.ts +20 -0
- package/utils/fs-utils.js +193 -0
- package/utils/index.d.ts +1 -3
- package/utils/index.js +1 -3
- package/utils/upsert-utils.d.ts +9 -4
- package/utils/upsert-utils.js +51 -5
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -13
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -32
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -11
- package/decorators/Embedded.d.ts +0 -12
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -33
- package/decorators/Entity.js +0 -12
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -16
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -8
- package/decorators/Formula.d.ts +0 -4
- package/decorators/Formula.js +0 -15
- package/decorators/Indexed.d.ts +0 -19
- package/decorators/Indexed.js +0 -20
- package/decorators/ManyToMany.d.ts +0 -42
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -34
- package/decorators/ManyToOne.js +0 -14
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -17
- package/decorators/OneToOne.d.ts +0 -28
- package/decorators/OneToOne.js +0 -7
- package/decorators/PrimaryKey.d.ts +0 -8
- package/decorators/PrimaryKey.js +0 -20
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -32
- package/decorators/Transactional.d.ts +0 -14
- package/decorators/Transactional.js +0 -28
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -47
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -17
- package/entity/ArrayCollection.d.ts +0 -118
- package/entity/ArrayCollection.js +0 -407
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -150
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -44
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -28
package/utils/Configuration.js
CHANGED
|
@@ -1,280 +1,271 @@
|
|
|
1
|
-
import { FileCacheAdapter } from '../cache/FileCacheAdapter.js';
|
|
2
1
|
import { NullCacheAdapter } from '../cache/NullCacheAdapter.js';
|
|
3
2
|
import { ObjectHydrator } from '../hydration/ObjectHydrator.js';
|
|
4
3
|
import { NullHighlighter } from '../utils/NullHighlighter.js';
|
|
5
4
|
import { DefaultLogger } from '../logging/DefaultLogger.js';
|
|
6
5
|
import { colors } from '../logging/colors.js';
|
|
7
6
|
import { Utils } from '../utils/Utils.js';
|
|
8
|
-
import {
|
|
7
|
+
import { MetadataProvider } from '../metadata/MetadataProvider.js';
|
|
9
8
|
import { NotFoundError } from '../errors.js';
|
|
10
9
|
import { RequestContext } from './RequestContext.js';
|
|
11
10
|
import { DataloaderType, FlushMode, LoadStrategy, PopulateHint } from '../enums.js';
|
|
12
11
|
import { MemoryCacheAdapter } from '../cache/MemoryCacheAdapter.js';
|
|
13
12
|
import { EntityComparator } from './EntityComparator.js';
|
|
13
|
+
import { setEnv } from './env-vars.js';
|
|
14
|
+
const DEFAULTS = {
|
|
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
|
+
};
|
|
14
130
|
export class Configuration {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
filters: {},
|
|
22
|
-
discovery: {
|
|
23
|
-
warnWhenNoEntities: true,
|
|
24
|
-
requireEntitiesArray: false,
|
|
25
|
-
checkDuplicateTableNames: true,
|
|
26
|
-
checkDuplicateFieldNames: true,
|
|
27
|
-
checkDuplicateEntities: true,
|
|
28
|
-
checkNonPersistentCompositeProps: true,
|
|
29
|
-
alwaysAnalyseProperties: true,
|
|
30
|
-
disableDynamicFileAccess: false,
|
|
31
|
-
inferDefaultValues: true,
|
|
32
|
-
},
|
|
33
|
-
strict: false,
|
|
34
|
-
validate: false,
|
|
35
|
-
validateRequired: true,
|
|
36
|
-
context: (name) => RequestContext.getEntityManager(name),
|
|
37
|
-
contextName: 'default',
|
|
38
|
-
allowGlobalContext: false,
|
|
39
|
-
// eslint-disable-next-line no-console
|
|
40
|
-
logger: console.log.bind(console),
|
|
41
|
-
colors: true,
|
|
42
|
-
findOneOrFailHandler: (entityName, where) => NotFoundError.findOneFailed(entityName, where),
|
|
43
|
-
findExactlyOneOrFailHandler: (entityName, where) => NotFoundError.findExactlyOneFailed(entityName, where),
|
|
44
|
-
baseDir: process.cwd(),
|
|
45
|
-
hydrator: ObjectHydrator,
|
|
46
|
-
flushMode: FlushMode.AUTO,
|
|
47
|
-
loadStrategy: LoadStrategy.BALANCED,
|
|
48
|
-
dataloader: DataloaderType.NONE,
|
|
49
|
-
populateWhere: PopulateHint.ALL,
|
|
50
|
-
connect: true,
|
|
51
|
-
ignoreUndefinedInQuery: false,
|
|
52
|
-
onQuery: sql => sql,
|
|
53
|
-
autoJoinOneToOneOwner: true,
|
|
54
|
-
autoJoinRefsForFilters: true,
|
|
55
|
-
propagationOnPrototype: true,
|
|
56
|
-
populateAfterFlush: true,
|
|
57
|
-
serialization: {
|
|
58
|
-
includePrimaryKeys: true,
|
|
59
|
-
},
|
|
60
|
-
assign: {
|
|
61
|
-
updateNestedEntities: true,
|
|
62
|
-
updateByPrimaryKey: true,
|
|
63
|
-
mergeObjectProperties: false,
|
|
64
|
-
mergeEmbeddedProperties: true,
|
|
65
|
-
ignoreUndefined: false,
|
|
66
|
-
},
|
|
67
|
-
persistOnCreate: true,
|
|
68
|
-
upsertManaged: true,
|
|
69
|
-
forceEntityConstructor: false,
|
|
70
|
-
forceUndefined: false,
|
|
71
|
-
processOnCreateHooksEarly: false,
|
|
72
|
-
ensureDatabase: true,
|
|
73
|
-
ensureIndexes: false,
|
|
74
|
-
batchSize: 300,
|
|
75
|
-
hashAlgorithm: 'md5',
|
|
76
|
-
debug: false,
|
|
77
|
-
ignoreDeprecations: false,
|
|
78
|
-
verbose: false,
|
|
79
|
-
driverOptions: {},
|
|
80
|
-
migrations: {
|
|
81
|
-
tableName: 'mikro_orm_migrations',
|
|
82
|
-
path: './migrations',
|
|
83
|
-
glob: '!(*.d).{js,ts,cjs}',
|
|
84
|
-
silent: false,
|
|
85
|
-
transactional: true,
|
|
86
|
-
disableForeignKeys: false,
|
|
87
|
-
allOrNothing: true,
|
|
88
|
-
dropTables: true,
|
|
89
|
-
safe: false,
|
|
90
|
-
snapshot: true,
|
|
91
|
-
emit: 'ts',
|
|
92
|
-
fileName: (timestamp, name) => `Migration${timestamp}${name ? '_' + name : ''}`,
|
|
93
|
-
},
|
|
94
|
-
schemaGenerator: {
|
|
95
|
-
disableForeignKeys: false,
|
|
96
|
-
createForeignKeyConstraints: true,
|
|
97
|
-
ignoreSchema: [],
|
|
98
|
-
skipTables: [],
|
|
99
|
-
skipColumns: {},
|
|
100
|
-
},
|
|
101
|
-
embeddables: {
|
|
102
|
-
prefixMode: 'relative',
|
|
103
|
-
},
|
|
104
|
-
entityGenerator: {
|
|
105
|
-
forceUndefined: true,
|
|
106
|
-
undefinedDefaults: false,
|
|
107
|
-
bidirectionalRelations: false,
|
|
108
|
-
identifiedReferences: false,
|
|
109
|
-
scalarTypeInDecorator: false,
|
|
110
|
-
scalarPropertiesForRelations: 'never',
|
|
111
|
-
fileName: (className) => className,
|
|
112
|
-
onlyPurePivotTables: false,
|
|
113
|
-
outputPurePivotTables: false,
|
|
114
|
-
readOnlyPivotTables: false,
|
|
115
|
-
useCoreBaseEntity: false,
|
|
116
|
-
},
|
|
117
|
-
metadataCache: {
|
|
118
|
-
pretty: false,
|
|
119
|
-
adapter: FileCacheAdapter,
|
|
120
|
-
options: { cacheDir: process.cwd() + '/temp' },
|
|
121
|
-
},
|
|
122
|
-
resultCache: {
|
|
123
|
-
adapter: MemoryCacheAdapter,
|
|
124
|
-
expiration: 1000, // 1s
|
|
125
|
-
options: {},
|
|
126
|
-
},
|
|
127
|
-
metadataProvider: ReflectMetadataProvider,
|
|
128
|
-
highlighter: new NullHighlighter(),
|
|
129
|
-
seeder: {
|
|
130
|
-
path: './seeders',
|
|
131
|
-
defaultSeeder: 'DatabaseSeeder',
|
|
132
|
-
glob: '!(*.d).{js,ts}',
|
|
133
|
-
emit: 'ts',
|
|
134
|
-
fileName: (className) => className,
|
|
135
|
-
},
|
|
136
|
-
preferReadReplicas: true,
|
|
137
|
-
};
|
|
138
|
-
options;
|
|
139
|
-
logger;
|
|
140
|
-
driver;
|
|
141
|
-
platform;
|
|
142
|
-
cache = new Map();
|
|
143
|
-
extensions = new Map();
|
|
131
|
+
#options;
|
|
132
|
+
#logger;
|
|
133
|
+
#driver;
|
|
134
|
+
#platform;
|
|
135
|
+
#cache = new Map();
|
|
136
|
+
#extensions = new Map();
|
|
144
137
|
constructor(options, validate = true) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
138
|
+
if (options.dynamicImportProvider) {
|
|
139
|
+
globalThis.dynamicImportProvider = options.dynamicImportProvider;
|
|
140
|
+
}
|
|
141
|
+
this.#options = Utils.mergeConfig({}, DEFAULTS, options);
|
|
148
142
|
if (validate) {
|
|
149
143
|
this.validateOptions();
|
|
150
144
|
}
|
|
151
|
-
this
|
|
152
|
-
this
|
|
153
|
-
debugMode: this
|
|
154
|
-
ignoreDeprecations: this
|
|
155
|
-
usesReplicas: (this
|
|
156
|
-
highlighter: this
|
|
157
|
-
writer: this
|
|
145
|
+
this.#options.loggerFactory ??= DefaultLogger.create;
|
|
146
|
+
this.#logger = this.#options.loggerFactory({
|
|
147
|
+
debugMode: this.#options.debug,
|
|
148
|
+
ignoreDeprecations: this.#options.ignoreDeprecations,
|
|
149
|
+
usesReplicas: (this.#options.replicas?.length ?? 0) > 0,
|
|
150
|
+
highlighter: this.#options.highlighter,
|
|
151
|
+
writer: this.#options.logger,
|
|
158
152
|
});
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this.
|
|
162
|
-
|
|
163
|
-
|
|
153
|
+
const cf = this.#options.compiledFunctions;
|
|
154
|
+
if (cf && cf.__version !== Utils.getORMVersion()) {
|
|
155
|
+
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\`.`);
|
|
156
|
+
}
|
|
157
|
+
if (this.#options.driver) {
|
|
158
|
+
this.#driver = new this.#options.driver(this);
|
|
159
|
+
this.#platform = this.#driver.getPlatform();
|
|
160
|
+
this.#platform.setConfig(this);
|
|
164
161
|
this.init(validate);
|
|
165
162
|
}
|
|
166
163
|
}
|
|
167
164
|
getPlatform() {
|
|
168
|
-
return this
|
|
165
|
+
return this.#platform;
|
|
169
166
|
}
|
|
170
167
|
/**
|
|
171
168
|
* Gets specific configuration option. Falls back to specified `defaultValue` if provided.
|
|
172
169
|
*/
|
|
173
170
|
get(key, defaultValue) {
|
|
174
|
-
if (typeof this
|
|
175
|
-
return this
|
|
171
|
+
if (typeof this.#options[key] !== 'undefined') {
|
|
172
|
+
return this.#options[key];
|
|
176
173
|
}
|
|
177
174
|
return defaultValue;
|
|
178
175
|
}
|
|
179
176
|
getAll() {
|
|
180
|
-
return this
|
|
177
|
+
return this.#options;
|
|
181
178
|
}
|
|
182
179
|
/**
|
|
183
180
|
* Overrides specified configuration value.
|
|
184
181
|
*/
|
|
185
182
|
set(key, value) {
|
|
186
|
-
this
|
|
183
|
+
this.#options[key] = value;
|
|
187
184
|
this.sync();
|
|
188
185
|
}
|
|
189
186
|
/**
|
|
190
187
|
* Resets the configuration to its default value
|
|
191
188
|
*/
|
|
192
189
|
reset(key) {
|
|
193
|
-
this
|
|
190
|
+
this.#options[key] = DEFAULTS[key];
|
|
194
191
|
}
|
|
195
192
|
/**
|
|
196
193
|
* Gets Logger instance.
|
|
197
194
|
*/
|
|
198
195
|
getLogger() {
|
|
199
|
-
return this
|
|
196
|
+
return this.#logger;
|
|
200
197
|
}
|
|
201
198
|
getDataloaderType() {
|
|
202
|
-
if (typeof this
|
|
203
|
-
return this
|
|
204
|
-
}
|
|
205
|
-
return this.options.dataloader;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Gets current client URL (connection string).
|
|
209
|
-
*/
|
|
210
|
-
getClientUrl(hidePassword = false) {
|
|
211
|
-
if (hidePassword) {
|
|
212
|
-
return this.options.clientUrl.replace(/\/\/([^:]+):(.+)@/, '//$1:*****@');
|
|
199
|
+
if (typeof this.#options.dataloader === 'boolean') {
|
|
200
|
+
return this.#options.dataloader ? DataloaderType.ALL : DataloaderType.NONE;
|
|
213
201
|
}
|
|
214
|
-
return this
|
|
202
|
+
return this.#options.dataloader;
|
|
215
203
|
}
|
|
216
204
|
getSchema(skipDefaultSchema = false) {
|
|
217
|
-
if (skipDefaultSchema && this
|
|
205
|
+
if (skipDefaultSchema && this.#options.schema === this.#platform.getDefaultSchemaName()) {
|
|
218
206
|
return undefined;
|
|
219
207
|
}
|
|
220
|
-
return this
|
|
208
|
+
return this.#options.schema;
|
|
221
209
|
}
|
|
222
210
|
/**
|
|
223
211
|
* Gets current database driver instance.
|
|
224
212
|
*/
|
|
225
213
|
getDriver() {
|
|
226
|
-
return this
|
|
214
|
+
return this.#driver;
|
|
227
215
|
}
|
|
228
216
|
registerExtension(name, cb) {
|
|
229
|
-
this
|
|
217
|
+
this.#extensions.set(name, cb);
|
|
230
218
|
}
|
|
231
219
|
getExtension(name) {
|
|
232
|
-
if (this
|
|
233
|
-
return this
|
|
220
|
+
if (this.#cache.has(name)) {
|
|
221
|
+
return this.#cache.get(name);
|
|
234
222
|
}
|
|
235
|
-
const ext = this
|
|
236
|
-
/* v8 ignore next
|
|
223
|
+
const ext = this.#extensions.get(name);
|
|
224
|
+
/* v8 ignore next */
|
|
237
225
|
if (!ext) {
|
|
238
226
|
return undefined;
|
|
239
227
|
}
|
|
240
|
-
this
|
|
241
|
-
return this
|
|
228
|
+
this.#cache.set(name, ext());
|
|
229
|
+
return this.#cache.get(name);
|
|
242
230
|
}
|
|
243
231
|
/**
|
|
244
232
|
* Gets instance of NamingStrategy. (cached)
|
|
245
233
|
*/
|
|
246
234
|
getNamingStrategy() {
|
|
247
|
-
return this.getCachedService(this
|
|
235
|
+
return this.getCachedService(this.#options.namingStrategy || this.#platform.getNamingStrategy());
|
|
248
236
|
}
|
|
249
237
|
/**
|
|
250
238
|
* Gets instance of Hydrator. (cached)
|
|
251
239
|
*/
|
|
252
240
|
getHydrator(metadata) {
|
|
253
|
-
return this.getCachedService(this
|
|
241
|
+
return this.getCachedService(this.#options.hydrator, metadata, this.#platform, this);
|
|
254
242
|
}
|
|
255
243
|
/**
|
|
256
244
|
* Gets instance of Comparator. (cached)
|
|
257
245
|
*/
|
|
258
246
|
getComparator(metadata) {
|
|
259
|
-
return this.getCachedService(EntityComparator, metadata, this
|
|
247
|
+
return this.getCachedService(EntityComparator, metadata, this.#platform, this);
|
|
260
248
|
}
|
|
261
249
|
/**
|
|
262
250
|
* Gets instance of MetadataProvider. (cached)
|
|
263
251
|
*/
|
|
264
252
|
getMetadataProvider() {
|
|
265
|
-
return this.getCachedService(this
|
|
253
|
+
return this.getCachedService(this.#options.metadataProvider, this);
|
|
266
254
|
}
|
|
267
255
|
/**
|
|
268
256
|
* Gets instance of metadata CacheAdapter. (cached)
|
|
269
257
|
*/
|
|
270
258
|
getMetadataCacheAdapter() {
|
|
271
|
-
return this.getCachedService(this
|
|
259
|
+
return this.getCachedService(this.#options.metadataCache.adapter, this.#options.metadataCache.options, this.#options.baseDir, this.#options.metadataCache.pretty);
|
|
272
260
|
}
|
|
273
261
|
/**
|
|
274
262
|
* Gets instance of CacheAdapter for result cache. (cached)
|
|
275
263
|
*/
|
|
276
264
|
getResultCacheAdapter() {
|
|
277
|
-
return this.getCachedService(this
|
|
265
|
+
return this.getCachedService(this.#options.resultCache.adapter, {
|
|
266
|
+
expiration: this.#options.resultCache.expiration,
|
|
267
|
+
...this.#options.resultCache.options,
|
|
268
|
+
});
|
|
278
269
|
}
|
|
279
270
|
/**
|
|
280
271
|
* Gets EntityRepository class to be instantiated.
|
|
@@ -283,116 +274,88 @@ export class Configuration {
|
|
|
283
274
|
if (repository) {
|
|
284
275
|
return repository();
|
|
285
276
|
}
|
|
286
|
-
if (this
|
|
287
|
-
return this
|
|
277
|
+
if (this.#options.entityRepository) {
|
|
278
|
+
return this.#options.entityRepository;
|
|
288
279
|
}
|
|
289
|
-
return this
|
|
280
|
+
return this.#platform.getRepositoryClass();
|
|
290
281
|
}
|
|
291
282
|
/**
|
|
292
283
|
* Creates instance of given service and caches it.
|
|
293
284
|
*/
|
|
294
285
|
getCachedService(cls, ...args) {
|
|
295
|
-
if (!this
|
|
296
|
-
|
|
297
|
-
this.cache.set(cls.name, new Class(...args));
|
|
286
|
+
if (!this.#cache.has(cls.name)) {
|
|
287
|
+
this.#cache.set(cls.name, new cls(...args));
|
|
298
288
|
}
|
|
299
|
-
return this
|
|
289
|
+
return this.#cache.get(cls.name);
|
|
300
290
|
}
|
|
301
291
|
resetServiceCache() {
|
|
302
|
-
this
|
|
292
|
+
this.#cache.clear();
|
|
303
293
|
}
|
|
304
294
|
init(validate) {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
this.options.metadataCache.enabled = this.getMetadataProvider().useCache();
|
|
295
|
+
const useCache = this.getMetadataProvider().useCache();
|
|
296
|
+
const metadataCache = this.#options.metadataCache;
|
|
297
|
+
if (!useCache) {
|
|
298
|
+
metadataCache.adapter = NullCacheAdapter;
|
|
310
299
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if (
|
|
315
|
-
|
|
300
|
+
metadataCache.enabled ??= useCache;
|
|
301
|
+
this.#options.clientUrl ??= this.#platform.getDefaultClientUrl();
|
|
302
|
+
this.#options.implicitTransactions ??= this.#platform.usesImplicitTransactions();
|
|
303
|
+
if (validate && metadataCache.enabled && !metadataCache.adapter) {
|
|
304
|
+
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.');
|
|
316
305
|
}
|
|
317
306
|
try {
|
|
318
|
-
const url = new URL(this.
|
|
307
|
+
const url = new URL(this.#options.clientUrl);
|
|
319
308
|
if (url.pathname) {
|
|
320
|
-
this
|
|
309
|
+
this.#options.dbName = this.get('dbName', decodeURIComponent(url.pathname).substring(1));
|
|
321
310
|
}
|
|
322
311
|
}
|
|
323
312
|
catch {
|
|
324
|
-
const url =
|
|
313
|
+
const url = /:\/\/.*\/([^?]+)/.exec(this.#options.clientUrl);
|
|
325
314
|
if (url) {
|
|
326
|
-
this
|
|
315
|
+
this.#options.dbName = this.get('dbName', decodeURIComponent(url[1]));
|
|
327
316
|
}
|
|
328
317
|
}
|
|
329
|
-
if (validate && !this
|
|
318
|
+
if (validate && !this.#options.dbName && this.#options.clientUrl) {
|
|
330
319
|
throw new Error("No database specified, `clientUrl` option provided but it's missing the pathname.");
|
|
331
320
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
this.options.charset = this.platform.getDefaultCharset();
|
|
337
|
-
}
|
|
338
|
-
Object.keys(this.options.filters).forEach(key => {
|
|
339
|
-
this.options.filters[key].default ??= true;
|
|
321
|
+
this.#options.schema ??= this.#platform.getDefaultSchemaName();
|
|
322
|
+
this.#options.charset ??= this.#platform.getDefaultCharset();
|
|
323
|
+
Object.keys(this.#options.filters).forEach(key => {
|
|
324
|
+
this.#options.filters[key].default ??= true;
|
|
340
325
|
});
|
|
341
|
-
|
|
326
|
+
if (!this.#options.filtersOnRelations) {
|
|
327
|
+
this.#options.autoJoinRefsForFilters ??= false;
|
|
328
|
+
}
|
|
329
|
+
this.#options.subscribers = [...this.#options.subscribers].map(subscriber => {
|
|
342
330
|
return subscriber.constructor.name === 'Function' ? new subscriber() : subscriber;
|
|
343
331
|
});
|
|
344
332
|
this.sync();
|
|
345
333
|
if (!colors.enabled()) {
|
|
346
|
-
this
|
|
334
|
+
this.#options.highlighter = new NullHighlighter();
|
|
347
335
|
}
|
|
348
336
|
}
|
|
349
337
|
sync() {
|
|
350
|
-
|
|
351
|
-
this
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* Checks if `src` folder exists, it so, tries to adjust the migrations and seeders paths automatically to use it.
|
|
355
|
-
* If there is a `dist` or `build` folder, it will be used for the JS variant (`path` option), while the `src` folder will be
|
|
356
|
-
* used for the TS variant (`pathTs` option).
|
|
357
|
-
*
|
|
358
|
-
* If the default folder exists (e.g. `/migrations`), the config will respect that, so this auto-detection should not
|
|
359
|
-
* break existing projects, only help with the new ones.
|
|
360
|
-
*/
|
|
361
|
-
detectSourceFolder(options) {
|
|
362
|
-
if (!Utils.pathExistsSync(this.options.baseDir + '/src')) {
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
const migrationsPathExists = Utils.pathExistsSync(this.options.baseDir + '/' + this.options.migrations.path);
|
|
366
|
-
const seedersPathExists = Utils.pathExistsSync(this.options.baseDir + '/' + this.options.seeder.path);
|
|
367
|
-
const distDir = Utils.pathExistsSync(this.options.baseDir + '/dist');
|
|
368
|
-
const buildDir = Utils.pathExistsSync(this.options.baseDir + '/build');
|
|
369
|
-
// if neither `dist` nor `build` exist, we use the `src` folder as it might be a JS project without building, but with `src` folder
|
|
370
|
-
const path = distDir ? './dist' : (buildDir ? './build' : './src');
|
|
371
|
-
// only if the user did not provide any values and if the default path does not exist
|
|
372
|
-
if (!options.migrations?.path && !options.migrations?.pathTs && !migrationsPathExists) {
|
|
373
|
-
this.options.migrations.path = `${path}/migrations`;
|
|
374
|
-
this.options.migrations.pathTs = './src/migrations';
|
|
375
|
-
}
|
|
376
|
-
// only if the user did not provide any values and if the default path does not exist
|
|
377
|
-
if (!options.seeder?.path && !options.seeder?.pathTs && !seedersPathExists) {
|
|
378
|
-
this.options.seeder.path = `${path}/seeders`;
|
|
379
|
-
this.options.seeder.pathTs = './src/seeders';
|
|
380
|
-
}
|
|
338
|
+
setEnv('MIKRO_ORM_COLORS', this.#options.colors);
|
|
339
|
+
this.#logger.setDebugMode(this.#options.debug);
|
|
381
340
|
}
|
|
382
341
|
validateOptions() {
|
|
383
|
-
/* v8 ignore next
|
|
384
|
-
if ('type' in this
|
|
385
|
-
throw new Error(
|
|
342
|
+
/* v8 ignore next */
|
|
343
|
+
if ('type' in this.#options) {
|
|
344
|
+
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({ ... })`).");
|
|
386
345
|
}
|
|
387
|
-
if (!this
|
|
388
|
-
throw new Error(
|
|
346
|
+
if (!this.#options.driver) {
|
|
347
|
+
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({ ... })`).");
|
|
389
348
|
}
|
|
390
|
-
if (!this
|
|
349
|
+
if (!this.#options.dbName && !this.#options.clientUrl) {
|
|
391
350
|
throw new Error('No database specified, please fill in `dbName` or `clientUrl` option');
|
|
392
351
|
}
|
|
393
|
-
if (this
|
|
352
|
+
if (this.#options.entities.length === 0 && this.#options.discovery.warnWhenNoEntities) {
|
|
394
353
|
throw new Error('No entities found, please use `entities` option');
|
|
395
354
|
}
|
|
355
|
+
if (typeof this.#options.driverOptions === 'function' &&
|
|
356
|
+
this.#options.driverOptions.constructor.name === 'AsyncFunction') {
|
|
357
|
+
throw new Error('`driverOptions` callback cannot be async');
|
|
358
|
+
}
|
|
396
359
|
}
|
|
397
360
|
}
|
|
398
361
|
/**
|
|
@@ -1,52 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { EntityManagerType, IDatabaseDriver } from '../drivers/IDatabaseDriver.js';
|
|
3
|
-
import type { Dictionary } from '../typings.js';
|
|
4
|
-
import { Configuration, type Options } from './Configuration.js';
|
|
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 registerTypeScriptSupport(configPath?: string): Promise<boolean>;
|
|
39
|
-
static registerDotenv<D extends IDatabaseDriver>(options?: Options<D>): void;
|
|
40
|
-
static loadEnvironmentVars<D extends IDatabaseDriver>(): Promise<Partial<Options<D>>>;
|
|
41
|
-
static loadEnvironmentVarsSync<D extends IDatabaseDriver>(): Partial<Options<D>>;
|
|
42
|
-
static getORMPackages(): Set<string>;
|
|
43
|
-
static getORMPackageVersion(name: string): string | undefined;
|
|
44
|
-
static checkPackageVersion(): string;
|
|
45
|
-
}
|
|
46
|
-
export interface Settings {
|
|
47
|
-
alwaysAllowTs?: boolean;
|
|
48
|
-
verbose?: boolean;
|
|
49
|
-
preferTs?: boolean;
|
|
50
|
-
tsConfigPath?: string;
|
|
51
|
-
configPaths?: string[];
|
|
52
|
-
}
|
|
1
|
+
export {};
|