@mikro-orm/core 7.0.0-dev.21 → 7.0.0-dev.211

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.
Files changed (211) hide show
  1. package/EntityManager.d.ts +99 -57
  2. package/EntityManager.js +302 -276
  3. package/MikroORM.d.ts +44 -35
  4. package/MikroORM.js +103 -143
  5. package/README.md +3 -2
  6. package/cache/FileCacheAdapter.d.ts +1 -1
  7. package/cache/FileCacheAdapter.js +8 -7
  8. package/cache/GeneratedCacheAdapter.d.ts +0 -1
  9. package/cache/GeneratedCacheAdapter.js +0 -2
  10. package/cache/index.d.ts +0 -1
  11. package/cache/index.js +0 -1
  12. package/connections/Connection.d.ts +16 -7
  13. package/connections/Connection.js +23 -14
  14. package/drivers/DatabaseDriver.d.ts +25 -16
  15. package/drivers/DatabaseDriver.js +80 -35
  16. package/drivers/IDatabaseDriver.d.ts +44 -17
  17. package/entity/BaseEntity.d.ts +2 -2
  18. package/entity/BaseEntity.js +0 -3
  19. package/entity/Collection.d.ts +94 -29
  20. package/entity/Collection.js +434 -97
  21. package/entity/EntityAssigner.d.ts +1 -1
  22. package/entity/EntityAssigner.js +26 -18
  23. package/entity/EntityFactory.d.ts +13 -1
  24. package/entity/EntityFactory.js +84 -53
  25. package/entity/EntityHelper.d.ts +2 -2
  26. package/entity/EntityHelper.js +40 -15
  27. package/entity/EntityLoader.d.ts +6 -6
  28. package/entity/EntityLoader.js +119 -82
  29. package/entity/EntityRepository.d.ts +24 -4
  30. package/entity/EntityRepository.js +8 -2
  31. package/entity/Reference.d.ts +6 -5
  32. package/entity/Reference.js +34 -9
  33. package/entity/WrappedEntity.d.ts +2 -7
  34. package/entity/WrappedEntity.js +3 -8
  35. package/entity/defineEntity.d.ts +594 -0
  36. package/entity/defineEntity.js +533 -0
  37. package/entity/index.d.ts +3 -2
  38. package/entity/index.js +3 -2
  39. package/entity/utils.d.ts +7 -0
  40. package/entity/utils.js +16 -4
  41. package/entity/validators.d.ts +11 -0
  42. package/entity/validators.js +65 -0
  43. package/enums.d.ts +21 -5
  44. package/enums.js +15 -1
  45. package/errors.d.ts +23 -9
  46. package/errors.js +59 -21
  47. package/events/EventManager.d.ts +2 -1
  48. package/events/EventManager.js +19 -11
  49. package/hydration/Hydrator.js +1 -2
  50. package/hydration/ObjectHydrator.d.ts +4 -4
  51. package/hydration/ObjectHydrator.js +52 -33
  52. package/index.d.ts +2 -2
  53. package/index.js +1 -2
  54. package/logging/DefaultLogger.d.ts +1 -1
  55. package/logging/DefaultLogger.js +1 -0
  56. package/logging/SimpleLogger.d.ts +1 -1
  57. package/logging/colors.d.ts +1 -1
  58. package/logging/colors.js +7 -6
  59. package/logging/index.d.ts +1 -0
  60. package/logging/index.js +1 -0
  61. package/logging/inspect.d.ts +2 -0
  62. package/logging/inspect.js +11 -0
  63. package/metadata/EntitySchema.d.ts +40 -23
  64. package/metadata/EntitySchema.js +81 -34
  65. package/metadata/MetadataDiscovery.d.ts +7 -10
  66. package/metadata/MetadataDiscovery.js +391 -331
  67. package/metadata/MetadataProvider.d.ts +11 -2
  68. package/metadata/MetadataProvider.js +46 -2
  69. package/metadata/MetadataStorage.d.ts +13 -11
  70. package/metadata/MetadataStorage.js +70 -37
  71. package/metadata/MetadataValidator.d.ts +17 -9
  72. package/metadata/MetadataValidator.js +97 -40
  73. package/metadata/discover-entities.d.ts +5 -0
  74. package/metadata/discover-entities.js +40 -0
  75. package/metadata/index.d.ts +1 -1
  76. package/metadata/index.js +1 -1
  77. package/metadata/types.d.ts +502 -0
  78. package/metadata/types.js +1 -0
  79. package/naming-strategy/AbstractNamingStrategy.d.ts +12 -4
  80. package/naming-strategy/AbstractNamingStrategy.js +14 -2
  81. package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
  82. package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
  83. package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
  84. package/naming-strategy/MongoNamingStrategy.js +6 -6
  85. package/naming-strategy/NamingStrategy.d.ts +24 -4
  86. package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
  87. package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
  88. package/not-supported.d.ts +2 -0
  89. package/not-supported.js +4 -0
  90. package/package.json +18 -11
  91. package/platforms/ExceptionConverter.js +1 -1
  92. package/platforms/Platform.d.ts +7 -13
  93. package/platforms/Platform.js +20 -43
  94. package/serialization/EntitySerializer.d.ts +5 -0
  95. package/serialization/EntitySerializer.js +47 -27
  96. package/serialization/EntityTransformer.js +28 -18
  97. package/serialization/SerializationContext.d.ts +6 -6
  98. package/serialization/SerializationContext.js +16 -13
  99. package/types/ArrayType.d.ts +1 -1
  100. package/types/ArrayType.js +2 -3
  101. package/types/BigIntType.d.ts +8 -6
  102. package/types/BigIntType.js +1 -1
  103. package/types/BlobType.d.ts +0 -1
  104. package/types/BlobType.js +0 -3
  105. package/types/BooleanType.d.ts +2 -1
  106. package/types/BooleanType.js +3 -0
  107. package/types/DecimalType.d.ts +6 -4
  108. package/types/DecimalType.js +3 -3
  109. package/types/DoubleType.js +2 -2
  110. package/types/EnumArrayType.js +1 -2
  111. package/types/JsonType.d.ts +1 -1
  112. package/types/JsonType.js +7 -2
  113. package/types/TinyIntType.js +1 -1
  114. package/types/Type.d.ts +2 -4
  115. package/types/Type.js +3 -3
  116. package/types/Uint8ArrayType.d.ts +0 -1
  117. package/types/Uint8ArrayType.js +1 -4
  118. package/types/index.d.ts +1 -1
  119. package/typings.d.ts +290 -137
  120. package/typings.js +59 -44
  121. package/unit-of-work/ChangeSet.d.ts +2 -6
  122. package/unit-of-work/ChangeSet.js +4 -5
  123. package/unit-of-work/ChangeSetComputer.d.ts +1 -3
  124. package/unit-of-work/ChangeSetComputer.js +26 -13
  125. package/unit-of-work/ChangeSetPersister.d.ts +5 -4
  126. package/unit-of-work/ChangeSetPersister.js +70 -34
  127. package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
  128. package/unit-of-work/CommitOrderCalculator.js +13 -13
  129. package/unit-of-work/IdentityMap.d.ts +12 -0
  130. package/unit-of-work/IdentityMap.js +39 -1
  131. package/unit-of-work/UnitOfWork.d.ts +23 -3
  132. package/unit-of-work/UnitOfWork.js +175 -98
  133. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  134. package/utils/AbstractSchemaGenerator.js +18 -16
  135. package/utils/AsyncContext.d.ts +6 -0
  136. package/utils/AsyncContext.js +42 -0
  137. package/utils/Configuration.d.ts +785 -207
  138. package/utils/Configuration.js +147 -190
  139. package/utils/ConfigurationLoader.d.ts +1 -54
  140. package/utils/ConfigurationLoader.js +1 -352
  141. package/utils/Cursor.d.ts +0 -3
  142. package/utils/Cursor.js +27 -11
  143. package/utils/DataloaderUtils.d.ts +15 -5
  144. package/utils/DataloaderUtils.js +64 -30
  145. package/utils/EntityComparator.d.ts +13 -9
  146. package/utils/EntityComparator.js +101 -42
  147. package/utils/QueryHelper.d.ts +14 -6
  148. package/utils/QueryHelper.js +87 -25
  149. package/utils/RawQueryFragment.d.ts +48 -25
  150. package/utils/RawQueryFragment.js +66 -70
  151. package/utils/RequestContext.js +2 -2
  152. package/utils/TransactionContext.js +2 -2
  153. package/utils/TransactionManager.d.ts +65 -0
  154. package/utils/TransactionManager.js +223 -0
  155. package/utils/Utils.d.ts +13 -126
  156. package/utils/Utils.js +100 -391
  157. package/utils/clone.js +8 -23
  158. package/utils/env-vars.d.ts +7 -0
  159. package/utils/env-vars.js +97 -0
  160. package/utils/fs-utils.d.ts +32 -0
  161. package/utils/fs-utils.js +178 -0
  162. package/utils/index.d.ts +2 -1
  163. package/utils/index.js +2 -1
  164. package/utils/upsert-utils.d.ts +9 -4
  165. package/utils/upsert-utils.js +55 -4
  166. package/decorators/Check.d.ts +0 -3
  167. package/decorators/Check.js +0 -13
  168. package/decorators/CreateRequestContext.d.ts +0 -3
  169. package/decorators/CreateRequestContext.js +0 -32
  170. package/decorators/Embeddable.d.ts +0 -8
  171. package/decorators/Embeddable.js +0 -11
  172. package/decorators/Embedded.d.ts +0 -12
  173. package/decorators/Embedded.js +0 -18
  174. package/decorators/Entity.d.ts +0 -18
  175. package/decorators/Entity.js +0 -12
  176. package/decorators/Enum.d.ts +0 -9
  177. package/decorators/Enum.js +0 -16
  178. package/decorators/Filter.d.ts +0 -2
  179. package/decorators/Filter.js +0 -8
  180. package/decorators/Formula.d.ts +0 -4
  181. package/decorators/Formula.js +0 -15
  182. package/decorators/Indexed.d.ts +0 -19
  183. package/decorators/Indexed.js +0 -20
  184. package/decorators/ManyToMany.d.ts +0 -40
  185. package/decorators/ManyToMany.js +0 -14
  186. package/decorators/ManyToOne.d.ts +0 -32
  187. package/decorators/ManyToOne.js +0 -14
  188. package/decorators/OneToMany.d.ts +0 -28
  189. package/decorators/OneToMany.js +0 -17
  190. package/decorators/OneToOne.d.ts +0 -26
  191. package/decorators/OneToOne.js +0 -7
  192. package/decorators/PrimaryKey.d.ts +0 -8
  193. package/decorators/PrimaryKey.js +0 -20
  194. package/decorators/Property.d.ts +0 -250
  195. package/decorators/Property.js +0 -32
  196. package/decorators/Transactional.d.ts +0 -13
  197. package/decorators/Transactional.js +0 -28
  198. package/decorators/hooks.d.ts +0 -16
  199. package/decorators/hooks.js +0 -47
  200. package/decorators/index.d.ts +0 -17
  201. package/decorators/index.js +0 -17
  202. package/entity/ArrayCollection.d.ts +0 -116
  203. package/entity/ArrayCollection.js +0 -402
  204. package/entity/EntityValidator.d.ts +0 -19
  205. package/entity/EntityValidator.js +0 -150
  206. package/exports.d.ts +0 -24
  207. package/exports.js +0 -23
  208. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  209. package/metadata/ReflectMetadataProvider.js +0 -44
  210. package/utils/resolveContextProvider.d.ts +0 -10
  211. package/utils/resolveContextProvider.js +0 -28
@@ -1,137 +1,135 @@
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 { ReflectMetadataProvider } from '../metadata/ReflectMetadataProvider.js';
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
+ disableForeignKeys: false,
80
+ allOrNothing: true,
81
+ dropTables: true,
82
+ safe: false,
83
+ snapshot: true,
84
+ emit: 'ts',
85
+ fileName: (timestamp, name) => `Migration${timestamp}${name ? '_' + name : ''}`,
86
+ },
87
+ schemaGenerator: {
88
+ disableForeignKeys: false,
89
+ createForeignKeyConstraints: true,
90
+ ignoreSchema: [],
91
+ skipTables: [],
92
+ skipViews: [],
93
+ skipColumns: {},
94
+ },
95
+ embeddables: {
96
+ prefixMode: 'relative',
97
+ },
98
+ entityGenerator: {
99
+ forceUndefined: true,
100
+ undefinedDefaults: false,
101
+ scalarTypeInDecorator: false,
102
+ bidirectionalRelations: true,
103
+ identifiedReferences: true,
104
+ scalarPropertiesForRelations: 'never',
105
+ entityDefinition: 'defineEntity',
106
+ decorators: 'legacy',
107
+ enumMode: 'dictionary',
108
+ /* v8 ignore next */
109
+ fileName: (className) => className,
110
+ onlyPurePivotTables: false,
111
+ outputPurePivotTables: false,
112
+ readOnlyPivotTables: false,
113
+ useCoreBaseEntity: false,
114
+ },
115
+ metadataCache: {},
116
+ resultCache: {
117
+ adapter: MemoryCacheAdapter,
118
+ expiration: 1000, // 1s
119
+ options: {},
120
+ },
121
+ metadataProvider: MetadataProvider,
122
+ highlighter: new NullHighlighter(),
123
+ seeder: {
124
+ defaultSeeder: 'DatabaseSeeder',
125
+ glob: '!(*.d).{js,ts}',
126
+ emit: 'ts',
127
+ fileName: (className) => className,
128
+ },
129
+ preferReadReplicas: true,
130
+ dynamicImportProvider: /* v8 ignore next */ (id) => import(id),
131
+ };
14
132
  export class Configuration {
15
- static DEFAULTS = {
16
- pool: {},
17
- entities: [],
18
- entitiesTs: [],
19
- extensions: [],
20
- subscribers: [],
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.JOINED,
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
- ensureDatabase: true,
72
- ensureIndexes: false,
73
- batchSize: 300,
74
- debug: false,
75
- ignoreDeprecations: false,
76
- verbose: false,
77
- driverOptions: {},
78
- migrations: {
79
- tableName: 'mikro_orm_migrations',
80
- path: './migrations',
81
- glob: '!(*.d).{js,ts,cjs}',
82
- silent: false,
83
- transactional: true,
84
- disableForeignKeys: false,
85
- allOrNothing: true,
86
- dropTables: true,
87
- safe: false,
88
- snapshot: true,
89
- emit: 'ts',
90
- fileName: (timestamp, name) => `Migration${timestamp}${name ? '_' + name : ''}`,
91
- },
92
- schemaGenerator: {
93
- disableForeignKeys: false,
94
- createForeignKeyConstraints: true,
95
- ignoreSchema: [],
96
- },
97
- embeddables: {
98
- prefixMode: 'relative',
99
- },
100
- entityGenerator: {
101
- forceUndefined: true,
102
- undefinedDefaults: false,
103
- bidirectionalRelations: false,
104
- identifiedReferences: false,
105
- scalarTypeInDecorator: false,
106
- scalarPropertiesForRelations: 'never',
107
- fileName: (className) => className,
108
- onlyPurePivotTables: false,
109
- outputPurePivotTables: false,
110
- readOnlyPivotTables: false,
111
- useCoreBaseEntity: false,
112
- },
113
- metadataCache: {
114
- pretty: false,
115
- adapter: FileCacheAdapter,
116
- options: { cacheDir: process.cwd() + '/temp' },
117
- },
118
- resultCache: {
119
- adapter: MemoryCacheAdapter,
120
- expiration: 1000, // 1s
121
- options: {},
122
- },
123
- metadataProvider: ReflectMetadataProvider,
124
- highlighter: new NullHighlighter(),
125
- seeder: {
126
- path: './seeders',
127
- defaultSeeder: 'DatabaseSeeder',
128
- glob: '!(*.d).{js,ts}',
129
- emit: 'ts',
130
- fileName: (className) => className,
131
- },
132
- preferReadReplicas: true,
133
- dynamicImportProvider: /* v8 ignore next */ (id) => import(id),
134
- };
135
133
  options;
136
134
  logger;
137
135
  driver;
@@ -140,11 +138,9 @@ export class Configuration {
140
138
  extensions = new Map();
141
139
  constructor(options, validate = true) {
142
140
  if (options.dynamicImportProvider) {
143
- Utils.setDynamicImportProvider(options.dynamicImportProvider);
141
+ globalThis.dynamicImportProvider = options.dynamicImportProvider;
144
142
  }
145
- this.options = Utils.mergeConfig({}, Configuration.DEFAULTS, options);
146
- this.options.baseDir = Utils.absolutePath(this.options.baseDir);
147
- this.options.preferTs ??= options.preferTs;
143
+ this.options = Utils.mergeConfig({}, DEFAULTS, options);
148
144
  if (validate) {
149
145
  this.validateOptions();
150
146
  }
@@ -160,7 +156,6 @@ export class Configuration {
160
156
  this.driver = new this.options.driver(this);
161
157
  this.platform = this.driver.getPlatform();
162
158
  this.platform.setConfig(this);
163
- this.detectSourceFolder(options);
164
159
  this.init(validate);
165
160
  }
166
161
  }
@@ -190,7 +185,7 @@ export class Configuration {
190
185
  * Resets the configuration to its default value
191
186
  */
192
187
  reset(key) {
193
- this.options[key] = Configuration.DEFAULTS[key];
188
+ this.options[key] = DEFAULTS[key];
194
189
  }
195
190
  /**
196
191
  * Gets Logger instance.
@@ -204,15 +199,6 @@ export class Configuration {
204
199
  }
205
200
  return this.options.dataloader;
206
201
  }
207
- /**
208
- * Gets current client URL (connection string).
209
- */
210
- getClientUrl(hidePassword = false) {
211
- if (hidePassword) {
212
- return this.options.clientUrl.replace(/\/\/([^:]+):(.+)@/, '//$1:*****@');
213
- }
214
- return this.options.clientUrl;
215
- }
216
202
  getSchema(skipDefaultSchema = false) {
217
203
  if (skipDefaultSchema && this.options.schema === this.platform.getDefaultSchemaName()) {
218
204
  return undefined;
@@ -233,7 +219,7 @@ export class Configuration {
233
219
  return this.cache.get(name);
234
220
  }
235
221
  const ext = this.extensions.get(name);
236
- /* v8 ignore next 3 */
222
+ /* v8 ignore next */
237
223
  if (!ext) {
238
224
  return undefined;
239
225
  }
@@ -293,8 +279,7 @@ export class Configuration {
293
279
  */
294
280
  getCachedService(cls, ...args) {
295
281
  if (!this.cache.has(cls.name)) {
296
- const Class = cls;
297
- this.cache.set(cls.name, new Class(...args));
282
+ this.cache.set(cls.name, new cls(...args));
298
283
  }
299
284
  return this.cache.get(cls.name);
300
285
  }
@@ -302,26 +287,25 @@ export class Configuration {
302
287
  this.cache.clear();
303
288
  }
304
289
  init(validate) {
305
- if (!this.getMetadataProvider().useCache()) {
306
- this.options.metadataCache.adapter = NullCacheAdapter;
290
+ const useCache = this.getMetadataProvider().useCache();
291
+ const metadataCache = this.options.metadataCache;
292
+ if (!useCache) {
293
+ metadataCache.adapter = NullCacheAdapter;
307
294
  }
308
- if (!('enabled' in this.options.metadataCache)) {
309
- this.options.metadataCache.enabled = this.getMetadataProvider().useCache();
310
- }
311
- if (!this.options.clientUrl) {
312
- this.options.clientUrl = this.platform.getDefaultClientUrl();
313
- }
314
- if (!('implicitTransactions' in this.options)) {
315
- this.options.implicitTransactions = this.platform.usesImplicitTransactions();
295
+ metadataCache.enabled ??= useCache;
296
+ this.options.clientUrl ??= this.platform.getDefaultClientUrl();
297
+ this.options.implicitTransactions ??= this.platform.usesImplicitTransactions();
298
+ if (validate && metadataCache.enabled && !metadataCache.adapter) {
299
+ 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
300
  }
317
301
  try {
318
- const url = new URL(this.getClientUrl());
302
+ const url = new URL(this.options.clientUrl);
319
303
  if (url.pathname) {
320
304
  this.options.dbName = this.get('dbName', decodeURIComponent(url.pathname).substring(1));
321
305
  }
322
306
  }
323
307
  catch {
324
- const url = this.getClientUrl().match(/:\/\/.*\/([^?]+)/);
308
+ const url = this.options.clientUrl.match(/:\/\/.*\/([^?]+)/);
325
309
  if (url) {
326
310
  this.options.dbName = this.get('dbName', decodeURIComponent(url[1]));
327
311
  }
@@ -329,16 +313,15 @@ export class Configuration {
329
313
  if (validate && !this.options.dbName && this.options.clientUrl) {
330
314
  throw new Error("No database specified, `clientUrl` option provided but it's missing the pathname.");
331
315
  }
332
- if (!this.options.schema) {
333
- this.options.schema = this.platform.getDefaultSchemaName();
334
- }
335
- if (!this.options.charset) {
336
- this.options.charset = this.platform.getDefaultCharset();
337
- }
316
+ this.options.schema ??= this.platform.getDefaultSchemaName();
317
+ this.options.charset ??= this.platform.getDefaultCharset();
338
318
  Object.keys(this.options.filters).forEach(key => {
339
319
  this.options.filters[key].default ??= true;
340
320
  });
341
- this.options.subscribers = Utils.unique(this.options.subscribers).map(subscriber => {
321
+ if (!this.options.filtersOnRelations) {
322
+ this.options.autoJoinRefsForFilters ??= false;
323
+ }
324
+ this.options.subscribers = [...this.options.subscribers].map(subscriber => {
342
325
  return subscriber.constructor.name === 'Function' ? new subscriber() : subscriber;
343
326
  });
344
327
  this.sync();
@@ -347,40 +330,11 @@ export class Configuration {
347
330
  }
348
331
  }
349
332
  sync() {
350
- process.env.MIKRO_ORM_COLORS = '' + this.options.colors;
333
+ setEnv('MIKRO_ORM_COLORS', this.options.colors);
351
334
  this.logger.setDebugMode(this.options.debug);
352
335
  }
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
- }
381
- }
382
336
  validateOptions() {
383
- /* v8 ignore next 3 */
337
+ /* v8 ignore next */
384
338
  if ('type' in this.options) {
385
339
  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
340
  }
@@ -393,6 +347,9 @@ export class Configuration {
393
347
  if (this.options.entities.length === 0 && this.options.discovery.warnWhenNoEntities) {
394
348
  throw new Error('No entities found, please use `entities` option');
395
349
  }
350
+ if (typeof this.options.driverOptions === 'function' && this.options.driverOptions.constructor.name === 'AsyncFunction') {
351
+ throw new Error('`driverOptions` callback cannot be async');
352
+ }
396
353
  }
397
354
  }
398
355
  /**
@@ -1,54 +1 @@
1
- import type { EntityManager } from '../EntityManager.js';
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
- /** @internal */
44
- static commonJSCompat(options: Partial<Options>): void;
45
- static getORMPackageVersion(name: string): string | undefined;
46
- static checkPackageVersion(): string;
47
- }
48
- export interface Settings {
49
- alwaysAllowTs?: boolean;
50
- verbose?: boolean;
51
- preferTs?: boolean;
52
- tsConfigPath?: string;
53
- configPaths?: string[];
54
- }
1
+ export {};