@mikro-orm/core 7.0.0-dev.1 → 7.0.0-dev.3

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 (261) hide show
  1. package/EntityManager.d.ts +18 -13
  2. package/EntityManager.js +203 -203
  3. package/MikroORM.d.ts +7 -6
  4. package/MikroORM.js +33 -45
  5. package/cache/CacheAdapter.js +1 -2
  6. package/cache/FileCacheAdapter.d.ts +1 -1
  7. package/cache/FileCacheAdapter.js +18 -26
  8. package/cache/GeneratedCacheAdapter.d.ts +2 -2
  9. package/cache/GeneratedCacheAdapter.js +1 -5
  10. package/cache/MemoryCacheAdapter.d.ts +1 -1
  11. package/cache/MemoryCacheAdapter.js +1 -5
  12. package/cache/NullCacheAdapter.d.ts +1 -1
  13. package/cache/NullCacheAdapter.js +1 -5
  14. package/cache/index.d.ts +5 -5
  15. package/cache/index.js +5 -21
  16. package/connections/Connection.d.ts +7 -7
  17. package/connections/Connection.js +8 -12
  18. package/connections/index.d.ts +1 -1
  19. package/connections/index.js +1 -17
  20. package/decorators/Check.d.ts +1 -1
  21. package/decorators/Check.js +5 -8
  22. package/decorators/CreateRequestContext.d.ts +1 -1
  23. package/decorators/CreateRequestContext.js +13 -14
  24. package/decorators/Embeddable.d.ts +1 -1
  25. package/decorators/Embeddable.js +3 -6
  26. package/decorators/Embedded.d.ts +1 -1
  27. package/decorators/Embedded.js +10 -12
  28. package/decorators/Entity.d.ts +2 -2
  29. package/decorators/Entity.js +5 -8
  30. package/decorators/Enum.d.ts +2 -2
  31. package/decorators/Enum.js +7 -10
  32. package/decorators/Filter.d.ts +1 -1
  33. package/decorators/Filter.js +3 -6
  34. package/decorators/Formula.d.ts +2 -2
  35. package/decorators/Formula.js +7 -10
  36. package/decorators/Indexed.d.ts +2 -2
  37. package/decorators/Indexed.js +6 -10
  38. package/decorators/ManyToMany.d.ts +3 -3
  39. package/decorators/ManyToMany.js +10 -12
  40. package/decorators/ManyToOne.d.ts +3 -3
  41. package/decorators/ManyToOne.js +10 -12
  42. package/decorators/OneToMany.d.ts +3 -3
  43. package/decorators/OneToMany.js +11 -14
  44. package/decorators/OneToOne.d.ts +4 -4
  45. package/decorators/OneToOne.js +4 -7
  46. package/decorators/PrimaryKey.d.ts +2 -2
  47. package/decorators/PrimaryKey.js +10 -13
  48. package/decorators/Property.d.ts +5 -5
  49. package/decorators/Property.js +10 -12
  50. package/decorators/Transactional.d.ts +2 -2
  51. package/decorators/Transactional.js +7 -10
  52. package/decorators/hooks.js +23 -35
  53. package/decorators/index.d.ts +17 -17
  54. package/decorators/index.js +17 -36
  55. package/drivers/DatabaseDriver.d.ts +13 -12
  56. package/drivers/DatabaseDriver.js +60 -64
  57. package/drivers/IDatabaseDriver.d.ts +12 -12
  58. package/drivers/IDatabaseDriver.js +1 -4
  59. package/drivers/index.d.ts +2 -2
  60. package/drivers/index.js +2 -18
  61. package/entity/ArrayCollection.d.ts +2 -2
  62. package/entity/ArrayCollection.js +29 -33
  63. package/entity/BaseEntity.d.ts +6 -6
  64. package/entity/BaseEntity.js +17 -21
  65. package/entity/Collection.d.ts +6 -6
  66. package/entity/Collection.js +40 -44
  67. package/entity/EntityAssigner.d.ts +2 -2
  68. package/entity/EntityAssigner.js +58 -63
  69. package/entity/EntityFactory.d.ts +3 -3
  70. package/entity/EntityFactory.js +58 -62
  71. package/entity/EntityHelper.d.ts +2 -2
  72. package/entity/EntityHelper.js +41 -45
  73. package/entity/EntityIdentifier.d.ts +1 -1
  74. package/entity/EntityIdentifier.js +1 -5
  75. package/entity/EntityLoader.d.ts +5 -5
  76. package/entity/EntityLoader.js +92 -96
  77. package/entity/EntityRepository.d.ts +7 -7
  78. package/entity/EntityRepository.js +7 -11
  79. package/entity/EntityValidator.d.ts +1 -1
  80. package/entity/EntityValidator.js +25 -29
  81. package/entity/Reference.d.ts +2 -2
  82. package/entity/Reference.js +35 -42
  83. package/entity/WrappedEntity.d.ts +12 -12
  84. package/entity/WrappedEntity.js +23 -27
  85. package/entity/index.d.ts +13 -13
  86. package/entity/index.js +13 -29
  87. package/entity/utils.d.ts +1 -1
  88. package/entity/utils.js +9 -12
  89. package/entity/wrap.d.ts +1 -1
  90. package/entity/wrap.js +2 -6
  91. package/enums.d.ts +3 -3
  92. package/enums.js +37 -41
  93. package/errors.d.ts +1 -1
  94. package/errors.js +15 -24
  95. package/events/EventManager.d.ts +3 -3
  96. package/events/EventManager.js +8 -12
  97. package/events/EventSubscriber.d.ts +5 -4
  98. package/events/EventSubscriber.js +1 -2
  99. package/events/TransactionEventBroadcaster.d.ts +3 -3
  100. package/events/TransactionEventBroadcaster.js +1 -5
  101. package/events/index.d.ts +3 -3
  102. package/events/index.js +3 -19
  103. package/exceptions.js +18 -39
  104. package/hydration/Hydrator.d.ts +5 -5
  105. package/hydration/Hydrator.js +3 -6
  106. package/hydration/ObjectHydrator.d.ts +3 -3
  107. package/hydration/ObjectHydrator.js +25 -28
  108. package/hydration/index.d.ts +2 -2
  109. package/hydration/index.js +2 -18
  110. package/index.d.ts +21 -21
  111. package/index.js +21 -46
  112. package/logging/DefaultLogger.d.ts +1 -1
  113. package/logging/DefaultLogger.js +9 -13
  114. package/logging/Logger.d.ts +1 -1
  115. package/logging/Logger.js +1 -2
  116. package/logging/SimpleLogger.d.ts +2 -2
  117. package/logging/SimpleLogger.js +2 -6
  118. package/logging/colors.js +1 -5
  119. package/logging/index.d.ts +4 -4
  120. package/logging/index.js +4 -20
  121. package/metadata/EntitySchema.d.ts +12 -4
  122. package/metadata/EntitySchema.js +41 -45
  123. package/metadata/MetadataDiscovery.d.ts +7 -7
  124. package/metadata/MetadataDiscovery.js +174 -177
  125. package/metadata/MetadataProvider.d.ts +2 -2
  126. package/metadata/MetadataProvider.js +4 -7
  127. package/metadata/MetadataStorage.d.ts +2 -2
  128. package/metadata/MetadataStorage.js +15 -19
  129. package/metadata/MetadataValidator.d.ts +4 -4
  130. package/metadata/MetadataValidator.js +49 -53
  131. package/metadata/ReflectMetadataProvider.d.ts +2 -2
  132. package/metadata/ReflectMetadataProvider.js +8 -12
  133. package/metadata/index.d.ts +6 -6
  134. package/metadata/index.js +6 -22
  135. package/naming-strategy/AbstractNamingStrategy.d.ts +2 -2
  136. package/naming-strategy/AbstractNamingStrategy.js +4 -8
  137. package/naming-strategy/EntityCaseNamingStrategy.d.ts +1 -1
  138. package/naming-strategy/EntityCaseNamingStrategy.js +2 -6
  139. package/naming-strategy/MongoNamingStrategy.d.ts +1 -1
  140. package/naming-strategy/MongoNamingStrategy.js +2 -6
  141. package/naming-strategy/NamingStrategy.d.ts +1 -1
  142. package/naming-strategy/NamingStrategy.js +1 -2
  143. package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -1
  144. package/naming-strategy/UnderscoreNamingStrategy.js +2 -6
  145. package/naming-strategy/index.d.ts +5 -5
  146. package/naming-strategy/index.js +5 -21
  147. package/package.json +5 -14
  148. package/platforms/ExceptionConverter.d.ts +2 -2
  149. package/platforms/ExceptionConverter.js +4 -8
  150. package/platforms/Platform.d.ts +10 -10
  151. package/platforms/Platform.js +57 -61
  152. package/platforms/index.d.ts +2 -2
  153. package/platforms/index.js +2 -18
  154. package/serialization/EntitySerializer.d.ts +2 -2
  155. package/serialization/EntitySerializer.js +36 -41
  156. package/serialization/EntityTransformer.d.ts +1 -1
  157. package/serialization/EntityTransformer.js +27 -31
  158. package/serialization/SerializationContext.d.ts +2 -2
  159. package/serialization/SerializationContext.js +10 -14
  160. package/serialization/index.d.ts +3 -3
  161. package/serialization/index.js +3 -19
  162. package/types/ArrayType.d.ts +3 -3
  163. package/types/ArrayType.js +7 -11
  164. package/types/BigIntType.d.ts +3 -3
  165. package/types/BigIntType.js +3 -6
  166. package/types/BlobType.d.ts +3 -3
  167. package/types/BlobType.js +2 -8
  168. package/types/BooleanType.d.ts +3 -3
  169. package/types/BooleanType.js +2 -6
  170. package/types/CharacterType.d.ts +3 -3
  171. package/types/CharacterType.js +2 -6
  172. package/types/DateTimeType.d.ts +3 -3
  173. package/types/DateTimeType.js +2 -6
  174. package/types/DateType.d.ts +3 -3
  175. package/types/DateType.js +2 -6
  176. package/types/DecimalType.d.ts +3 -3
  177. package/types/DecimalType.js +4 -7
  178. package/types/DoubleType.d.ts +3 -3
  179. package/types/DoubleType.js +3 -6
  180. package/types/EnumArrayType.d.ts +4 -4
  181. package/types/EnumArrayType.js +5 -10
  182. package/types/EnumType.d.ts +3 -3
  183. package/types/EnumType.js +2 -6
  184. package/types/FloatType.d.ts +3 -3
  185. package/types/FloatType.js +2 -6
  186. package/types/IntegerType.d.ts +3 -3
  187. package/types/IntegerType.js +2 -6
  188. package/types/IntervalType.d.ts +3 -3
  189. package/types/IntervalType.js +2 -6
  190. package/types/JsonType.d.ts +3 -3
  191. package/types/JsonType.js +2 -6
  192. package/types/MediumIntType.d.ts +3 -3
  193. package/types/MediumIntType.js +2 -6
  194. package/types/SmallIntType.d.ts +3 -3
  195. package/types/SmallIntType.js +2 -6
  196. package/types/StringType.d.ts +3 -3
  197. package/types/StringType.js +2 -6
  198. package/types/TextType.d.ts +3 -3
  199. package/types/TextType.js +2 -6
  200. package/types/TimeType.d.ts +3 -3
  201. package/types/TimeType.js +4 -8
  202. package/types/TinyIntType.d.ts +3 -3
  203. package/types/TinyIntType.js +3 -6
  204. package/types/Type.d.ts +2 -2
  205. package/types/Type.js +5 -9
  206. package/types/Uint8ArrayType.d.ts +3 -3
  207. package/types/Uint8ArrayType.js +3 -9
  208. package/types/UnknownType.d.ts +3 -3
  209. package/types/UnknownType.js +2 -6
  210. package/types/UuidType.d.ts +3 -3
  211. package/types/UuidType.js +2 -6
  212. package/types/index.d.ts +25 -25
  213. package/types/index.js +52 -79
  214. package/typings.d.ts +22 -20
  215. package/typings.js +34 -38
  216. package/unit-of-work/ChangeSet.d.ts +1 -1
  217. package/unit-of-work/ChangeSet.js +13 -17
  218. package/unit-of-work/ChangeSetComputer.d.ts +8 -7
  219. package/unit-of-work/ChangeSetComputer.js +26 -30
  220. package/unit-of-work/ChangeSetPersister.d.ts +7 -6
  221. package/unit-of-work/ChangeSetPersister.js +44 -47
  222. package/unit-of-work/CommitOrderCalculator.d.ts +1 -1
  223. package/unit-of-work/CommitOrderCalculator.js +6 -10
  224. package/unit-of-work/IdentityMap.d.ts +1 -1
  225. package/unit-of-work/IdentityMap.js +1 -5
  226. package/unit-of-work/UnitOfWork.d.ts +8 -7
  227. package/unit-of-work/UnitOfWork.js +171 -172
  228. package/unit-of-work/index.d.ts +6 -6
  229. package/unit-of-work/index.js +6 -22
  230. package/utils/AbstractSchemaGenerator.d.ts +6 -6
  231. package/utils/AbstractSchemaGenerator.js +7 -11
  232. package/utils/Configuration.d.ts +26 -27
  233. package/utils/Configuration.js +50 -55
  234. package/utils/ConfigurationLoader.d.ts +9 -8
  235. package/utils/ConfigurationLoader.js +71 -86
  236. package/utils/Cursor.d.ts +3 -3
  237. package/utils/Cursor.js +22 -25
  238. package/utils/DataloaderUtils.d.ts +4 -4
  239. package/utils/DataloaderUtils.js +12 -16
  240. package/utils/EntityComparator.d.ts +2 -2
  241. package/utils/EntityComparator.js +48 -52
  242. package/utils/NullHighlighter.d.ts +1 -1
  243. package/utils/NullHighlighter.js +1 -5
  244. package/utils/QueryHelper.d.ts +3 -3
  245. package/utils/QueryHelper.js +47 -51
  246. package/utils/RawQueryFragment.d.ts +1 -1
  247. package/utils/RawQueryFragment.js +16 -24
  248. package/utils/RequestContext.d.ts +2 -2
  249. package/utils/RequestContext.js +3 -7
  250. package/utils/TransactionContext.d.ts +1 -1
  251. package/utils/TransactionContext.js +4 -8
  252. package/utils/Utils.d.ts +16 -12
  253. package/utils/Utils.js +89 -93
  254. package/utils/clone.js +8 -11
  255. package/utils/index.d.ts +13 -13
  256. package/utils/index.js +13 -29
  257. package/utils/resolveContextProvider.d.ts +3 -3
  258. package/utils/resolveContextProvider.js +9 -12
  259. package/utils/upsert-utils.d.ts +3 -3
  260. package/utils/upsert-utils.js +5 -9
  261. package/index.mjs +0 -199
package/MikroORM.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import type { EntityManagerType, IDatabaseDriver } from './drivers';
2
- import { type EntitySchema, MetadataStorage } from './metadata';
3
- import { Configuration, type Options } from './utils';
4
- import type { EntityManager } from './EntityManager';
5
- import type { Constructor, EntityMetadata, EntityName, IEntityGenerator, IMigrator, ISeedManager } from './typings';
1
+ import type { EntityManagerType, IDatabaseDriver } from './drivers/IDatabaseDriver.js';
2
+ import { type EntitySchema } from './metadata/EntitySchema.js';
3
+ import { MetadataStorage } from './metadata/MetadataStorage.js';
4
+ import { Configuration, type Options } from './utils/Configuration.js';
5
+ import type { EntityManager } from './EntityManager.js';
6
+ import type { Constructor, EntityMetadata, EntityName, IEntityGenerator, IMigrator, ISeedManager } from './typings.js';
6
7
  /**
7
8
  * Helper class for bootstrapping the MikroORM.
8
9
  */
@@ -27,7 +28,7 @@ export declare class MikroORM<Driver extends IDatabaseDriver = IDatabaseDriver,
27
28
  * - no check for mismatched package versions
28
29
  */
29
30
  static initSync<D extends IDatabaseDriver = IDatabaseDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager>(options: Options<D, EM>): MikroORM<D, EM>;
30
- constructor(options: Options<Driver, EM> | Configuration<Driver, EM>);
31
+ constructor(options: Options<Driver, EM>);
31
32
  /**
32
33
  * Connects to the database.
33
34
  */
package/MikroORM.js CHANGED
@@ -1,14 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MikroORM = void 0;
4
- const metadata_1 = require("./metadata");
5
- const utils_1 = require("./utils");
6
- const logging_1 = require("./logging");
7
- const cache_1 = require("./cache");
1
+ import { MetadataDiscovery } from './metadata/MetadataDiscovery.js';
2
+ import { MetadataStorage } from './metadata/MetadataStorage.js';
3
+ import { MetadataValidator } from './metadata/MetadataValidator.js';
4
+ import { ReflectMetadataProvider } from './metadata/ReflectMetadataProvider.js';
5
+ import { Configuration } from './utils/Configuration.js';
6
+ import { ConfigurationLoader } from './utils/ConfigurationLoader.js';
7
+ import { Utils } from './utils/Utils.js';
8
+ import { colors } from './logging/colors.js';
9
+ import { NullCacheAdapter } from './cache/NullCacheAdapter.js';
8
10
  /**
9
11
  * Helper class for bootstrapping the MikroORM.
10
12
  */
11
- class MikroORM {
13
+ export class MikroORM {
12
14
  /** The global EntityManager instance. If you are using `RequestContext` helper, it will automatically pick the request specific context under the hood */
13
15
  em;
14
16
  driver;
@@ -21,28 +23,24 @@ class MikroORM {
21
23
  * If you omit the `options` parameter, your CLI config will be used.
22
24
  */
23
25
  static async init(options) {
24
- // for back-compatibility only, used by @mikro-orm/nestjs v5
25
- if (options instanceof utils_1.Configuration) {
26
- options = options.getAll();
27
- }
28
- utils_1.ConfigurationLoader.registerDotenv(options);
29
- const coreVersion = await utils_1.ConfigurationLoader.checkPackageVersion();
30
- const env = utils_1.ConfigurationLoader.loadEnvironmentVars();
26
+ ConfigurationLoader.registerDotenv(options);
27
+ const coreVersion = ConfigurationLoader.checkPackageVersion();
28
+ const env = await ConfigurationLoader.loadEnvironmentVars();
31
29
  if (!options) {
32
- const configPathFromArg = utils_1.ConfigurationLoader.configPathsFromArg();
33
- const config = (await utils_1.ConfigurationLoader.getConfiguration(process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default', configPathFromArg ?? utils_1.ConfigurationLoader.getConfigPaths()));
30
+ const configPathFromArg = ConfigurationLoader.configPathsFromArg();
31
+ const config = (await ConfigurationLoader.getConfiguration(process.env.MIKRO_ORM_CONTEXT_NAME ?? 'default', configPathFromArg ?? ConfigurationLoader.getConfigPaths()));
34
32
  options = config.getAll();
35
33
  if (configPathFromArg) {
36
34
  config.getLogger().warn('deprecated', 'Path for config file was inferred from the command line arguments. Instead, you should set the MIKRO_ORM_CLI_CONFIG environment variable to specify the path, or if you really must use the command line arguments, import the config manually based on them, and pass it to init.', { label: 'D0001' });
37
35
  }
38
36
  }
39
- options = utils_1.Utils.mergeConfig(options, env);
40
- await utils_1.ConfigurationLoader.commonJSCompat(options);
37
+ options = Utils.mergeConfig(options, env);
38
+ ConfigurationLoader.commonJSCompat(options);
41
39
  if ('DRIVER' in this && !options.driver) {
42
40
  options.driver = this.DRIVER;
43
41
  }
44
42
  const orm = new MikroORM(options);
45
- orm.logger.log('info', `MikroORM version: ${logging_1.colors.green(coreVersion)}`);
43
+ orm.logger.log('info', `MikroORM version: ${colors.green(coreVersion)}`);
46
44
  // we need to allow global context here as we are not in a scope of requests yet
47
45
  const allowGlobalContext = orm.config.get('allowGlobalContext');
48
46
  orm.config.set('allowGlobalContext', true);
@@ -68,13 +66,9 @@ class MikroORM {
68
66
  * - no check for mismatched package versions
69
67
  */
70
68
  static initSync(options) {
71
- // for back-compatibility only, used by @mikro-orm/nestjs v5
72
- if (options instanceof utils_1.Configuration) {
73
- options = options.getAll();
74
- }
75
- utils_1.ConfigurationLoader.registerDotenv(options);
76
- const env = utils_1.ConfigurationLoader.loadEnvironmentVars();
77
- options = utils_1.Utils.merge(options, env);
69
+ ConfigurationLoader.registerDotenv(options);
70
+ const env = ConfigurationLoader.loadEnvironmentVarsSync();
71
+ options = Utils.merge(options, env);
78
72
  if ('DRIVER' in this && !options.driver) {
79
73
  options.driver = this.DRIVER;
80
74
  }
@@ -91,21 +85,16 @@ class MikroORM {
91
85
  return orm;
92
86
  }
93
87
  constructor(options) {
94
- if (options instanceof utils_1.Configuration) {
95
- this.config = options;
96
- }
97
- else {
98
- this.config = new utils_1.Configuration(options);
99
- }
88
+ this.config = new Configuration(options);
100
89
  const discovery = this.config.get('discovery');
101
90
  if (discovery.disableDynamicFileAccess) {
102
- this.config.set('metadataProvider', metadata_1.ReflectMetadataProvider);
103
- this.config.set('metadataCache', { adapter: cache_1.NullCacheAdapter });
91
+ this.config.set('metadataProvider', ReflectMetadataProvider);
92
+ this.config.set('metadataCache', { adapter: NullCacheAdapter });
104
93
  discovery.requireEntitiesArray = true;
105
94
  }
106
95
  this.driver = this.config.getDriver();
107
96
  this.logger = this.config.getLogger();
108
- this.discovery = new metadata_1.MetadataDiscovery(new metadata_1.MetadataStorage(), this.driver.getPlatform(), this.config);
97
+ this.discovery = new MetadataDiscovery(new MetadataStorage(), this.driver.getPlatform(), this.config);
109
98
  }
110
99
  /**
111
100
  * Connects to the database.
@@ -120,7 +109,7 @@ class MikroORM {
120
109
  await this.schema.ensureDatabase(typeof options === 'boolean' ? {} : { ...options, forceCheck: true });
121
110
  }
122
111
  if (await this.isConnected()) {
123
- this.logger.log('info', `MikroORM successfully connected to database ${logging_1.colors.green(db)}`);
112
+ this.logger.log('info', `MikroORM successfully connected to database ${colors.green(db)}`);
124
113
  }
125
114
  else {
126
115
  this.logger.error('info', `MikroORM failed to connect to database ${db}`);
@@ -131,8 +120,8 @@ class MikroORM {
131
120
  * Reconnects, possibly to a different database.
132
121
  */
133
122
  async reconnect(options = {}) {
134
- /* istanbul ignore next */
135
- for (const key of utils_1.Utils.keys(options)) {
123
+ /* v8 ignore next 3 */
124
+ for (const key of Utils.keys(options)) {
136
125
  this.config.set(key, options[key]);
137
126
  }
138
127
  await this.driver.reconnect();
@@ -168,7 +157,7 @@ class MikroORM {
168
157
  */
169
158
  getMetadata(entityName) {
170
159
  if (entityName) {
171
- entityName = utils_1.Utils.className(entityName);
160
+ entityName = Utils.className(entityName);
172
161
  return this.metadata.get(entityName);
173
162
  }
174
163
  return this.metadata;
@@ -192,14 +181,14 @@ class MikroORM {
192
181
  * Allows dynamically discovering new entity by reference, handy for testing schema diffing.
193
182
  */
194
183
  discoverEntity(entities, reset) {
195
- entities = utils_1.Utils.asArray(entities);
196
- for (const className of utils_1.Utils.asArray(reset)) {
184
+ entities = Utils.asArray(entities);
185
+ for (const className of Utils.asArray(reset)) {
197
186
  this.metadata.reset(className);
198
187
  this.discovery.reset(className);
199
188
  }
200
189
  const tmp = this.discovery.discoverReferences(entities);
201
190
  const options = this.config.get('discovery');
202
- new metadata_1.MetadataValidator().validateDiscovered([...Object.values(this.metadata.getAll()), ...tmp], options);
191
+ new MetadataValidator().validateDiscovered([...Object.values(this.metadata.getAll()), ...tmp], options);
203
192
  const metadata = this.discovery.processDiscoveredEntities(tmp);
204
193
  metadata.forEach(meta => {
205
194
  this.metadata.set(meta.className, meta);
@@ -215,7 +204,7 @@ class MikroORM {
215
204
  if (extension) {
216
205
  return extension;
217
206
  }
218
- /* istanbul ignore next */
207
+ /* v8 ignore next 2 */
219
208
  throw new Error(`SchemaGenerator extension not registered.`);
220
209
  }
221
210
  /**
@@ -261,4 +250,3 @@ class MikroORM {
261
250
  return this.getEntityGenerator();
262
251
  }
263
252
  }
264
- exports.MikroORM = MikroORM;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,4 +1,4 @@
1
- import type { SyncCacheAdapter } from './CacheAdapter';
1
+ import type { SyncCacheAdapter } from './CacheAdapter.js';
2
2
  export declare class FileCacheAdapter implements SyncCacheAdapter {
3
3
  private readonly options;
4
4
  private readonly baseDir;
@@ -1,17 +1,11 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.FileCacheAdapter = void 0;
7
- const globby_1 = __importDefault(require("globby"));
8
- const fs_extra_1 = require("fs-extra");
9
- const Utils_1 = require("../utils/Utils");
10
- class FileCacheAdapter {
1
+ import globby from 'globby';
2
+ import { existsSync, readFileSync, writeFileSync, unlinkSync } from 'node:fs';
3
+ import { Utils } from '../utils/Utils.js';
4
+ export class FileCacheAdapter {
11
5
  options;
12
6
  baseDir;
13
7
  pretty;
14
- VERSION = Utils_1.Utils.getORMVersion();
8
+ VERSION = Utils.getORMVersion();
15
9
  cache = {};
16
10
  constructor(options, baseDir, pretty = false) {
17
11
  this.options = options;
@@ -23,10 +17,10 @@ class FileCacheAdapter {
23
17
  */
24
18
  get(name) {
25
19
  const path = this.path(name);
26
- if (!(0, fs_extra_1.pathExistsSync)(path)) {
20
+ if (!existsSync(path)) {
27
21
  return null;
28
22
  }
29
- const payload = (0, fs_extra_1.readJSONSync)(path);
23
+ const payload = Utils.readJSONSync(path);
30
24
  const hash = this.getHash(payload.origin);
31
25
  if (!hash || payload.hash !== hash) {
32
26
  return null;
@@ -43,23 +37,22 @@ class FileCacheAdapter {
43
37
  }
44
38
  const path = this.path(name);
45
39
  const hash = this.getHash(origin);
46
- const opts = this.pretty ? { spaces: 2 } : {};
47
- (0, fs_extra_1.writeJSONSync)(path, { data, origin, hash, version: this.VERSION }, opts);
40
+ writeFileSync(path, JSON.stringify({ data, origin, hash, version: this.VERSION }, null, this.pretty ? 2 : undefined));
48
41
  }
49
42
  /**
50
43
  * @inheritDoc
51
44
  */
52
45
  remove(name) {
53
46
  const path = this.path(name);
54
- (0, fs_extra_1.unlinkSync)(path);
47
+ unlinkSync(path);
55
48
  }
56
49
  /**
57
50
  * @inheritDoc
58
51
  */
59
52
  clear() {
60
53
  const path = this.path('*');
61
- const files = globby_1.default.sync(path);
62
- files.forEach(file => (0, fs_extra_1.unlinkSync)(file));
54
+ const files = globby.sync(path);
55
+ files.forEach(file => unlinkSync(file));
63
56
  this.cache = {};
64
57
  }
65
58
  combine() {
@@ -69,22 +62,21 @@ class FileCacheAdapter {
69
62
  let path = typeof this.options.combined === 'string'
70
63
  ? this.options.combined
71
64
  : './metadata.json';
72
- path = Utils_1.Utils.normalizePath(this.options.cacheDir, path);
65
+ path = Utils.normalizePath(this.options.cacheDir, path);
73
66
  this.options.combined = path; // override in the options, so we can log it from the CLI in `cache:generate` command
74
- (0, fs_extra_1.writeJSONSync)(path, this.cache, { spaces: this.pretty ? 2 : undefined });
67
+ writeFileSync(path, JSON.stringify(this.cache, null, this.pretty ? 2 : undefined));
75
68
  return path;
76
69
  }
77
70
  path(name) {
78
- (0, fs_extra_1.ensureDirSync)(this.options.cacheDir);
71
+ Utils.ensureDir(this.options.cacheDir);
79
72
  return `${this.options.cacheDir}/${name}.json`;
80
73
  }
81
74
  getHash(origin) {
82
- origin = Utils_1.Utils.absolutePath(origin, this.baseDir);
83
- if (!(0, fs_extra_1.pathExistsSync)(origin)) {
75
+ origin = Utils.absolutePath(origin, this.baseDir);
76
+ if (!existsSync(origin)) {
84
77
  return null;
85
78
  }
86
- const contents = (0, fs_extra_1.readFileSync)(origin);
87
- return Utils_1.Utils.hash(contents.toString() + this.VERSION);
79
+ const contents = readFileSync(origin);
80
+ return Utils.hash(contents.toString() + this.VERSION);
88
81
  }
89
82
  }
90
- exports.FileCacheAdapter = FileCacheAdapter;
@@ -1,5 +1,5 @@
1
- import type { CacheAdapter } from './CacheAdapter';
2
- import type { Dictionary } from '../typings';
1
+ import type { CacheAdapter } from './CacheAdapter.js';
2
+ import type { Dictionary } from '../typings.js';
3
3
  export declare class GeneratedCacheAdapter implements CacheAdapter {
4
4
  private readonly options;
5
5
  private readonly data;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GeneratedCacheAdapter = void 0;
4
- class GeneratedCacheAdapter {
1
+ export class GeneratedCacheAdapter {
5
2
  options;
6
3
  data = new Map();
7
4
  constructor(options) {
@@ -35,4 +32,3 @@ class GeneratedCacheAdapter {
35
32
  this.data.clear();
36
33
  }
37
34
  }
38
- exports.GeneratedCacheAdapter = GeneratedCacheAdapter;
@@ -1,4 +1,4 @@
1
- import type { CacheAdapter } from './CacheAdapter';
1
+ import type { CacheAdapter } from './CacheAdapter.js';
2
2
  export declare class MemoryCacheAdapter implements CacheAdapter {
3
3
  private readonly options;
4
4
  private readonly data;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemoryCacheAdapter = void 0;
4
- class MemoryCacheAdapter {
1
+ export class MemoryCacheAdapter {
5
2
  options;
6
3
  data = new Map();
7
4
  constructor(options) {
@@ -41,4 +38,3 @@ class MemoryCacheAdapter {
41
38
  this.data.clear();
42
39
  }
43
40
  }
44
- exports.MemoryCacheAdapter = MemoryCacheAdapter;
@@ -1,4 +1,4 @@
1
- import type { SyncCacheAdapter } from './CacheAdapter';
1
+ import type { SyncCacheAdapter } from './CacheAdapter.js';
2
2
  export declare class NullCacheAdapter implements SyncCacheAdapter {
3
3
  /**
4
4
  * @inheritDoc
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NullCacheAdapter = void 0;
4
- class NullCacheAdapter {
1
+ export class NullCacheAdapter {
5
2
  /**
6
3
  * @inheritDoc
7
4
  */
@@ -27,4 +24,3 @@ class NullCacheAdapter {
27
24
  // ignore
28
25
  }
29
26
  }
30
- exports.NullCacheAdapter = NullCacheAdapter;
package/cache/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from './CacheAdapter';
2
- export * from './NullCacheAdapter';
3
- export * from './FileCacheAdapter';
4
- export * from './MemoryCacheAdapter';
5
- export * from './GeneratedCacheAdapter';
1
+ export * from './CacheAdapter.js';
2
+ export * from './NullCacheAdapter.js';
3
+ export * from './FileCacheAdapter.js';
4
+ export * from './MemoryCacheAdapter.js';
5
+ export * from './GeneratedCacheAdapter.js';
package/cache/index.js CHANGED
@@ -1,21 +1,5 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./CacheAdapter"), exports);
18
- __exportStar(require("./NullCacheAdapter"), exports);
19
- __exportStar(require("./FileCacheAdapter"), exports);
20
- __exportStar(require("./MemoryCacheAdapter"), exports);
21
- __exportStar(require("./GeneratedCacheAdapter"), exports);
1
+ export * from './CacheAdapter.js';
2
+ export * from './NullCacheAdapter.js';
3
+ export * from './FileCacheAdapter.js';
4
+ export * from './MemoryCacheAdapter.js';
5
+ export * from './GeneratedCacheAdapter.js';
@@ -1,10 +1,10 @@
1
- import { type Configuration, type ConnectionOptions } from '../utils';
2
- import type { LogContext, Logger } from '../logging';
3
- import type { MetadataStorage } from '../metadata';
4
- import type { ConnectionType, Dictionary, MaybePromise, Primary } from '../typings';
5
- import type { Platform } from '../platforms/Platform';
6
- import type { TransactionEventBroadcaster } from '../events/TransactionEventBroadcaster';
7
- import type { IsolationLevel } from '../enums';
1
+ import { type Configuration, type ConnectionOptions } from '../utils/Configuration.js';
2
+ import type { LogContext, Logger } from '../logging/Logger.js';
3
+ import type { MetadataStorage } from '../metadata/MetadataStorage.js';
4
+ import type { ConnectionType, Dictionary, MaybePromise, Primary } from '../typings.js';
5
+ import type { Platform } from '../platforms/Platform.js';
6
+ import type { TransactionEventBroadcaster } from '../events/TransactionEventBroadcaster.js';
7
+ import type { IsolationLevel } from '../enums.js';
8
8
  export declare abstract class Connection {
9
9
  protected readonly config: Configuration;
10
10
  protected readonly type: ConnectionType;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Connection = void 0;
4
- const node_url_1 = require("node:url");
5
- const utils_1 = require("../utils");
6
- class Connection {
1
+ import { URL } from 'node:url';
2
+ import { Utils } from '../utils/Utils.js';
3
+ export class Connection {
7
4
  config;
8
5
  type;
9
6
  metadata;
@@ -17,7 +14,7 @@ class Connection {
17
14
  this.logger = this.config.getLogger();
18
15
  this.platform = this.config.getPlatform();
19
16
  if (options) {
20
- this.options = utils_1.Utils.copy(options);
17
+ this.options = Utils.copy(options);
21
18
  }
22
19
  else {
23
20
  const props = ['dbName', 'clientUrl', 'host', 'port', 'user', 'password', 'multipleStatements', 'pool', 'schema', 'driverOptions'];
@@ -58,7 +55,7 @@ class Connection {
58
55
  getConnectionOptions() {
59
56
  const ret = {};
60
57
  if (this.options.clientUrl) {
61
- const url = new node_url_1.URL(this.options.clientUrl);
58
+ const url = new URL(this.options.clientUrl);
62
59
  this.options.host = ret.host = this.options.host ?? decodeURIComponent(url.hostname);
63
60
  this.options.port = ret.port = this.options.port ?? +url.port;
64
61
  this.options.user = ret.user = this.options.user ?? decodeURIComponent(url.username);
@@ -70,7 +67,7 @@ class Connection {
70
67
  }
71
68
  }
72
69
  else {
73
- const url = new node_url_1.URL(this.config.getClientUrl());
70
+ const url = new URL(this.config.getClientUrl());
74
71
  this.options.host = ret.host = this.options.host ?? this.config.get('host', decodeURIComponent(url.hostname));
75
72
  this.options.port = ret.port = this.options.port ?? this.config.get('port', +url.port);
76
73
  this.options.user = ret.user = this.options.user ?? this.config.get('user', decodeURIComponent(url.username));
@@ -81,7 +78,7 @@ class Connection {
81
78
  }
82
79
  getClientUrl() {
83
80
  const options = this.getConnectionOptions();
84
- const url = new node_url_1.URL(this.config.getClientUrl(true));
81
+ const url = new URL(this.config.getClientUrl(true));
85
82
  const password = options.password ? ':*****' : '';
86
83
  const schema = options.schema && options.schema !== this.platform.getDefaultSchemaName()
87
84
  ? `?schema=${options.schema}`
@@ -105,7 +102,7 @@ class Connection {
105
102
  ...context,
106
103
  took: Date.now() - now,
107
104
  results: Array.isArray(res) ? res.length : undefined,
108
- affected: utils_1.Utils.isPlainObject(res) ? res.affectedRows : undefined,
105
+ affected: Utils.isPlainObject(res) ? res.affectedRows : undefined,
109
106
  });
110
107
  return res;
111
108
  }
@@ -126,4 +123,3 @@ class Connection {
126
123
  });
127
124
  }
128
125
  }
129
- exports.Connection = Connection;
@@ -1 +1 @@
1
- export * from './Connection';
1
+ export * from './Connection.js';
@@ -1,17 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Connection"), exports);
1
+ export * from './Connection.js';
@@ -1,3 +1,3 @@
1
- import type { CheckConstraint } from '../typings';
1
+ import type { CheckConstraint } from '../typings.js';
2
2
  export declare function Check<T>(options: CheckOptions<T>): (target: any, propertyName?: string) => any;
3
3
  export type CheckOptions<T = any> = CheckConstraint<T>;
@@ -1,16 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Check = Check;
4
- const metadata_1 = require("../metadata");
5
- const Utils_1 = require("../utils/Utils");
6
- function Check(options) {
1
+ import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
+ import { Utils } from '../utils/Utils.js';
3
+ export function Check(options) {
7
4
  return function (target, propertyName) {
8
- const meta = metadata_1.MetadataStorage.getMetadataFromDecorator((propertyName ? target.constructor : target));
5
+ const meta = MetadataStorage.getMetadataFromDecorator((propertyName ? target.constructor : target));
9
6
  options.property ??= propertyName;
10
7
  meta.checks.push(options);
11
8
  if (!propertyName) {
12
9
  return target;
13
10
  }
14
- return Utils_1.Utils.propertyDecoratorReturnValue();
11
+ return Utils.propertyDecoratorReturnValue();
15
12
  };
16
13
  }
@@ -1,3 +1,3 @@
1
- import type { ContextProvider } from '../typings';
1
+ import type { ContextProvider } from '../typings.js';
2
2
  export declare function CreateRequestContext<T extends object>(context?: ContextProvider<T>, respectExistingContext?: boolean): MethodDecorator;
3
3
  export declare function EnsureRequestContext<T extends object>(context?: ContextProvider<T>): MethodDecorator;
@@ -1,26 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CreateRequestContext = CreateRequestContext;
4
- exports.EnsureRequestContext = EnsureRequestContext;
5
- const RequestContext_1 = require("../utils/RequestContext");
6
- const resolveContextProvider_1 = require("../utils/resolveContextProvider");
7
- const TransactionContext_1 = require("../utils/TransactionContext");
8
- function CreateRequestContext(context, respectExistingContext = false) {
1
+ import { RequestContext } from '../utils/RequestContext.js';
2
+ import { resolveContextProvider } from '../utils/resolveContextProvider.js';
3
+ import { TransactionContext } from '../utils/TransactionContext.js';
4
+ export function CreateRequestContext(context, respectExistingContext = false) {
9
5
  return function (target, propertyKey, descriptor) {
10
6
  const originalMethod = descriptor.value;
7
+ const name = respectExistingContext ? 'EnsureRequestContext' : 'CreateRequestContext';
8
+ if (originalMethod.constructor.name !== 'AsyncFunction') {
9
+ throw new Error(`@${name}() should be use with async functions`);
10
+ }
11
11
  descriptor.value = async function (...args) {
12
- const em = await (0, resolveContextProvider_1.resolveContextProvider)(this, context);
12
+ const em = await resolveContextProvider(this, context);
13
13
  if (!em) {
14
- const name = respectExistingContext ? 'EnsureRequestContext' : 'CreateRequestContext';
15
14
  throw new Error(`@${name}() decorator can only be applied to methods of classes with \`orm: MikroORM\` property, \`em: EntityManager\` property, or with a callback parameter like \`@${name}(() => orm)\` that returns one of those types. The parameter will contain a reference to current \`this\`. Returning an EntityRepository from it is also supported.`);
16
15
  }
17
16
  // reuse existing context if available for given respect `contextName`
18
- if (respectExistingContext && RequestContext_1.RequestContext.getEntityManager(em.name)) {
17
+ if (respectExistingContext && RequestContext.getEntityManager(em.name)) {
19
18
  return originalMethod.apply(this, args);
20
19
  }
21
20
  // Otherwise, the outer tx context would be preferred.
22
- const txContext = TransactionContext_1.TransactionContext.currentTransactionContext();
23
- const provider = txContext ? TransactionContext_1.TransactionContext : RequestContext_1.RequestContext;
21
+ const txContext = TransactionContext.currentTransactionContext();
22
+ const provider = txContext ? TransactionContext : RequestContext;
24
23
  return txContext
25
24
  ? provider.create(em.fork({ useContext: true }), () => originalMethod.apply(this, args))
26
25
  : provider.create(em, () => originalMethod.apply(this, args));
@@ -28,6 +27,6 @@ function CreateRequestContext(context, respectExistingContext = false) {
28
27
  return descriptor;
29
28
  };
30
29
  }
31
- function EnsureRequestContext(context) {
30
+ export function EnsureRequestContext(context) {
32
31
  return CreateRequestContext(context, true);
33
32
  }
@@ -1,4 +1,4 @@
1
- import type { Dictionary } from '../typings';
1
+ import type { Dictionary } from '../typings.js';
2
2
  export declare function Embeddable(options?: EmbeddableOptions): <T>(target: T & Dictionary) => T & Dictionary;
3
3
  export type EmbeddableOptions = {
4
4
  discriminatorColumn?: string;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Embeddable = Embeddable;
4
- const metadata_1 = require("../metadata");
5
- function Embeddable(options = {}) {
1
+ import { MetadataStorage } from '../metadata/MetadataStorage.js';
2
+ export function Embeddable(options = {}) {
6
3
  return function (target) {
7
- const meta = metadata_1.MetadataStorage.getMetadataFromDecorator(target);
4
+ const meta = MetadataStorage.getMetadataFromDecorator(target);
8
5
  meta.class = target;
9
6
  meta.name = target.name;
10
7
  meta.embeddable = true;
@@ -1,4 +1,4 @@
1
- import type { AnyEntity } from '../typings';
1
+ import type { AnyEntity } from '../typings.js';
2
2
  export declare function Embedded<T extends object>(type?: EmbeddedOptions | (() => AnyEntity), options?: EmbeddedOptions): (target: AnyEntity, propertyName: string) => any;
3
3
  /** With `absolute` the prefix is set at the root of the entity (regardless of the nesting level) */
4
4
  export type EmbeddedPrefixMode = 'absolute' | 'relative';