@mikro-orm/core 7.0.0-dev.9 → 7.0.0-dev.90

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 (191) hide show
  1. package/EntityManager.d.ts +77 -48
  2. package/EntityManager.js +288 -225
  3. package/MikroORM.d.ts +40 -31
  4. package/MikroORM.js +98 -137
  5. package/README.md +3 -2
  6. package/cache/FileCacheAdapter.d.ts +1 -1
  7. package/cache/FileCacheAdapter.js +6 -5
  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 +11 -7
  13. package/connections/Connection.js +16 -14
  14. package/drivers/DatabaseDriver.d.ts +11 -5
  15. package/drivers/DatabaseDriver.js +23 -11
  16. package/drivers/IDatabaseDriver.d.ts +25 -4
  17. package/entity/BaseEntity.d.ts +0 -1
  18. package/entity/BaseEntity.js +0 -3
  19. package/entity/Collection.d.ts +95 -30
  20. package/entity/Collection.js +432 -93
  21. package/entity/EntityAssigner.d.ts +1 -1
  22. package/entity/EntityAssigner.js +17 -9
  23. package/entity/EntityFactory.d.ts +7 -0
  24. package/entity/EntityFactory.js +63 -41
  25. package/entity/EntityHelper.js +26 -12
  26. package/entity/EntityLoader.d.ts +5 -4
  27. package/entity/EntityLoader.js +63 -38
  28. package/entity/EntityRepository.d.ts +1 -1
  29. package/entity/Reference.d.ts +6 -5
  30. package/entity/Reference.js +34 -9
  31. package/entity/WrappedEntity.d.ts +2 -7
  32. package/entity/WrappedEntity.js +2 -7
  33. package/entity/defineEntity.d.ts +568 -0
  34. package/entity/defineEntity.js +529 -0
  35. package/entity/index.d.ts +3 -2
  36. package/entity/index.js +3 -2
  37. package/entity/utils.d.ts +7 -0
  38. package/entity/utils.js +16 -4
  39. package/entity/validators.d.ts +11 -0
  40. package/entity/validators.js +65 -0
  41. package/enums.d.ts +21 -6
  42. package/enums.js +14 -1
  43. package/errors.d.ts +10 -2
  44. package/errors.js +29 -10
  45. package/events/EventManager.d.ts +2 -1
  46. package/events/EventManager.js +19 -11
  47. package/events/EventSubscriber.d.ts +3 -1
  48. package/hydration/Hydrator.js +1 -2
  49. package/hydration/ObjectHydrator.d.ts +4 -4
  50. package/hydration/ObjectHydrator.js +35 -25
  51. package/index.d.ts +2 -2
  52. package/index.js +1 -2
  53. package/logging/DefaultLogger.d.ts +1 -1
  54. package/logging/DefaultLogger.js +1 -0
  55. package/logging/SimpleLogger.d.ts +1 -1
  56. package/logging/index.d.ts +1 -0
  57. package/logging/index.js +1 -0
  58. package/logging/inspect.d.ts +2 -0
  59. package/logging/inspect.js +16 -0
  60. package/metadata/EntitySchema.d.ts +9 -13
  61. package/metadata/EntitySchema.js +44 -26
  62. package/metadata/MetadataDiscovery.d.ts +6 -9
  63. package/metadata/MetadataDiscovery.js +165 -205
  64. package/metadata/MetadataProvider.d.ts +11 -2
  65. package/metadata/MetadataProvider.js +44 -2
  66. package/metadata/MetadataStorage.d.ts +1 -6
  67. package/metadata/MetadataStorage.js +6 -18
  68. package/metadata/MetadataValidator.d.ts +0 -7
  69. package/metadata/MetadataValidator.js +0 -10
  70. package/metadata/discover-entities.d.ts +5 -0
  71. package/metadata/discover-entities.js +40 -0
  72. package/metadata/index.d.ts +1 -1
  73. package/metadata/index.js +1 -1
  74. package/metadata/types.d.ts +480 -0
  75. package/metadata/types.js +1 -0
  76. package/naming-strategy/AbstractNamingStrategy.d.ts +5 -1
  77. package/naming-strategy/AbstractNamingStrategy.js +8 -2
  78. package/naming-strategy/NamingStrategy.d.ts +11 -1
  79. package/not-supported.d.ts +2 -0
  80. package/not-supported.js +4 -0
  81. package/package.json +18 -10
  82. package/platforms/ExceptionConverter.js +1 -1
  83. package/platforms/Platform.d.ts +6 -13
  84. package/platforms/Platform.js +15 -41
  85. package/serialization/EntitySerializer.d.ts +2 -0
  86. package/serialization/EntitySerializer.js +32 -14
  87. package/serialization/EntityTransformer.js +22 -12
  88. package/serialization/SerializationContext.js +16 -13
  89. package/types/ArrayType.d.ts +1 -1
  90. package/types/ArrayType.js +2 -3
  91. package/types/BigIntType.d.ts +8 -6
  92. package/types/BigIntType.js +1 -1
  93. package/types/BlobType.d.ts +0 -1
  94. package/types/BlobType.js +0 -3
  95. package/types/BooleanType.d.ts +2 -1
  96. package/types/BooleanType.js +3 -0
  97. package/types/DecimalType.d.ts +6 -4
  98. package/types/DecimalType.js +3 -3
  99. package/types/DoubleType.js +2 -2
  100. package/types/EnumArrayType.js +1 -2
  101. package/types/JsonType.d.ts +1 -1
  102. package/types/JsonType.js +7 -2
  103. package/types/TinyIntType.js +1 -1
  104. package/types/Type.d.ts +2 -4
  105. package/types/Type.js +3 -3
  106. package/types/Uint8ArrayType.d.ts +0 -1
  107. package/types/Uint8ArrayType.js +1 -4
  108. package/types/index.d.ts +1 -1
  109. package/typings.d.ts +109 -73
  110. package/typings.js +38 -35
  111. package/unit-of-work/ChangeSet.d.ts +0 -3
  112. package/unit-of-work/ChangeSet.js +2 -2
  113. package/unit-of-work/ChangeSetComputer.d.ts +1 -3
  114. package/unit-of-work/ChangeSetComputer.js +11 -9
  115. package/unit-of-work/ChangeSetPersister.d.ts +5 -4
  116. package/unit-of-work/ChangeSetPersister.js +51 -19
  117. package/unit-of-work/UnitOfWork.d.ts +8 -1
  118. package/unit-of-work/UnitOfWork.js +91 -49
  119. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  120. package/utils/AbstractSchemaGenerator.js +11 -9
  121. package/utils/Configuration.d.ts +757 -206
  122. package/utils/Configuration.js +140 -188
  123. package/utils/ConfigurationLoader.d.ts +1 -54
  124. package/utils/ConfigurationLoader.js +1 -352
  125. package/utils/Cursor.d.ts +0 -3
  126. package/utils/Cursor.js +6 -3
  127. package/utils/DataloaderUtils.d.ts +15 -5
  128. package/utils/DataloaderUtils.js +54 -8
  129. package/utils/EntityComparator.d.ts +8 -4
  130. package/utils/EntityComparator.js +52 -17
  131. package/utils/QueryHelper.d.ts +9 -1
  132. package/utils/QueryHelper.js +70 -9
  133. package/utils/RawQueryFragment.d.ts +36 -13
  134. package/utils/RawQueryFragment.js +36 -16
  135. package/utils/TransactionManager.d.ts +65 -0
  136. package/utils/TransactionManager.js +223 -0
  137. package/utils/Utils.d.ts +8 -97
  138. package/utils/Utils.js +82 -302
  139. package/utils/clone.js +2 -3
  140. package/utils/env-vars.d.ts +3 -0
  141. package/utils/env-vars.js +87 -0
  142. package/utils/fs-utils.d.ts +12 -0
  143. package/utils/fs-utils.js +97 -0
  144. package/utils/index.d.ts +2 -1
  145. package/utils/index.js +2 -1
  146. package/utils/upsert-utils.d.ts +7 -2
  147. package/utils/upsert-utils.js +55 -4
  148. package/decorators/Check.d.ts +0 -3
  149. package/decorators/Check.js +0 -13
  150. package/decorators/CreateRequestContext.d.ts +0 -3
  151. package/decorators/CreateRequestContext.js +0 -32
  152. package/decorators/Embeddable.d.ts +0 -8
  153. package/decorators/Embeddable.js +0 -11
  154. package/decorators/Embedded.d.ts +0 -18
  155. package/decorators/Embedded.js +0 -18
  156. package/decorators/Entity.d.ts +0 -18
  157. package/decorators/Entity.js +0 -12
  158. package/decorators/Enum.d.ts +0 -9
  159. package/decorators/Enum.js +0 -16
  160. package/decorators/Filter.d.ts +0 -2
  161. package/decorators/Filter.js +0 -8
  162. package/decorators/Formula.d.ts +0 -4
  163. package/decorators/Formula.js +0 -15
  164. package/decorators/Indexed.d.ts +0 -19
  165. package/decorators/Indexed.js +0 -20
  166. package/decorators/ManyToMany.d.ts +0 -40
  167. package/decorators/ManyToMany.js +0 -14
  168. package/decorators/ManyToOne.d.ts +0 -30
  169. package/decorators/ManyToOne.js +0 -14
  170. package/decorators/OneToMany.d.ts +0 -28
  171. package/decorators/OneToMany.js +0 -17
  172. package/decorators/OneToOne.d.ts +0 -24
  173. package/decorators/OneToOne.js +0 -7
  174. package/decorators/PrimaryKey.d.ts +0 -8
  175. package/decorators/PrimaryKey.js +0 -20
  176. package/decorators/Property.d.ts +0 -250
  177. package/decorators/Property.js +0 -32
  178. package/decorators/Transactional.d.ts +0 -13
  179. package/decorators/Transactional.js +0 -28
  180. package/decorators/hooks.d.ts +0 -16
  181. package/decorators/hooks.js +0 -47
  182. package/decorators/index.d.ts +0 -17
  183. package/decorators/index.js +0 -17
  184. package/entity/ArrayCollection.d.ts +0 -116
  185. package/entity/ArrayCollection.js +0 -402
  186. package/entity/EntityValidator.d.ts +0 -19
  187. package/entity/EntityValidator.js +0 -150
  188. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  189. package/metadata/ReflectMetadataProvider.js +0 -44
  190. package/utils/resolveContextProvider.d.ts +0 -10
  191. package/utils/resolveContextProvider.js +0 -28
@@ -1,137 +1,132 @@
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
+ 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
+ };
14
129
  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: 'absolute',
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
130
  options;
136
131
  logger;
137
132
  driver;
@@ -140,11 +135,10 @@ export class Configuration {
140
135
  extensions = new Map();
141
136
  constructor(options, validate = true) {
142
137
  if (options.dynamicImportProvider) {
143
- Utils.setDynamicImportProvider(options.dynamicImportProvider);
138
+ Utils.dynamicImportProvider = options.dynamicImportProvider;
144
139
  }
145
- this.options = Utils.mergeConfig({}, Configuration.DEFAULTS, options);
140
+ this.options = Utils.mergeConfig({}, DEFAULTS, options);
146
141
  this.options.baseDir = Utils.absolutePath(this.options.baseDir);
147
- this.options.preferTs ??= options.preferTs;
148
142
  if (validate) {
149
143
  this.validateOptions();
150
144
  }
@@ -160,7 +154,6 @@ export class Configuration {
160
154
  this.driver = new this.options.driver(this);
161
155
  this.platform = this.driver.getPlatform();
162
156
  this.platform.setConfig(this);
163
- this.detectSourceFolder(options);
164
157
  this.init(validate);
165
158
  }
166
159
  }
@@ -190,7 +183,7 @@ export class Configuration {
190
183
  * Resets the configuration to its default value
191
184
  */
192
185
  reset(key) {
193
- this.options[key] = Configuration.DEFAULTS[key];
186
+ this.options[key] = DEFAULTS[key];
194
187
  }
195
188
  /**
196
189
  * Gets Logger instance.
@@ -204,15 +197,6 @@ export class Configuration {
204
197
  }
205
198
  return this.options.dataloader;
206
199
  }
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
200
  getSchema(skipDefaultSchema = false) {
217
201
  if (skipDefaultSchema && this.options.schema === this.platform.getDefaultSchemaName()) {
218
202
  return undefined;
@@ -233,7 +217,7 @@ export class Configuration {
233
217
  return this.cache.get(name);
234
218
  }
235
219
  const ext = this.extensions.get(name);
236
- /* v8 ignore next 3 */
220
+ /* v8 ignore next */
237
221
  if (!ext) {
238
222
  return undefined;
239
223
  }
@@ -293,8 +277,7 @@ export class Configuration {
293
277
  */
294
278
  getCachedService(cls, ...args) {
295
279
  if (!this.cache.has(cls.name)) {
296
- const Class = cls;
297
- this.cache.set(cls.name, new Class(...args));
280
+ this.cache.set(cls.name, new cls(...args));
298
281
  }
299
282
  return this.cache.get(cls.name);
300
283
  }
@@ -302,26 +285,25 @@ export class Configuration {
302
285
  this.cache.clear();
303
286
  }
304
287
  init(validate) {
305
- if (!this.getMetadataProvider().useCache()) {
306
- this.options.metadataCache.adapter = NullCacheAdapter;
288
+ const useCache = this.getMetadataProvider().useCache();
289
+ const metadataCache = this.options.metadataCache;
290
+ if (!useCache) {
291
+ metadataCache.adapter = NullCacheAdapter;
307
292
  }
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();
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.');
316
298
  }
317
299
  try {
318
- const url = new URL(this.getClientUrl());
300
+ const url = new URL(this.options.clientUrl);
319
301
  if (url.pathname) {
320
302
  this.options.dbName = this.get('dbName', decodeURIComponent(url.pathname).substring(1));
321
303
  }
322
304
  }
323
305
  catch {
324
- const url = this.getClientUrl().match(/:\/\/.*\/([^?]+)/);
306
+ const url = this.options.clientUrl.match(/:\/\/.*\/([^?]+)/);
325
307
  if (url) {
326
308
  this.options.dbName = this.get('dbName', decodeURIComponent(url[1]));
327
309
  }
@@ -329,16 +311,15 @@ export class Configuration {
329
311
  if (validate && !this.options.dbName && this.options.clientUrl) {
330
312
  throw new Error("No database specified, `clientUrl` option provided but it's missing the pathname.");
331
313
  }
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
- }
314
+ this.options.schema ??= this.platform.getDefaultSchemaName();
315
+ this.options.charset ??= this.platform.getDefaultCharset();
338
316
  Object.keys(this.options.filters).forEach(key => {
339
317
  this.options.filters[key].default ??= true;
340
318
  });
341
- this.options.subscribers = Utils.unique(this.options.subscribers).map(subscriber => {
319
+ if (!this.options.filtersOnRelations) {
320
+ this.options.autoJoinRefsForFilters ??= false;
321
+ }
322
+ this.options.subscribers = [...this.options.subscribers].map(subscriber => {
342
323
  return subscriber.constructor.name === 'Function' ? new subscriber() : subscriber;
343
324
  });
344
325
  this.sync();
@@ -350,37 +331,8 @@ export class Configuration {
350
331
  process.env.MIKRO_ORM_COLORS = '' + this.options.colors;
351
332
  this.logger.setDebugMode(this.options.debug);
352
333
  }
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
334
  validateOptions() {
383
- /* v8 ignore next 3 */
335
+ /* v8 ignore next */
384
336
  if ('type' in this.options) {
385
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({ ... })`).');
386
338
  }
@@ -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 {};