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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/EntityManager.d.ts +96 -58
  2. package/EntityManager.js +465 -395
  3. package/MikroORM.d.ts +45 -35
  4. package/MikroORM.js +109 -160
  5. package/README.md +3 -2
  6. package/cache/CacheAdapter.js +1 -2
  7. package/cache/FileCacheAdapter.d.ts +2 -2
  8. package/cache/FileCacheAdapter.js +20 -27
  9. package/cache/GeneratedCacheAdapter.d.ts +2 -3
  10. package/cache/GeneratedCacheAdapter.js +1 -7
  11. package/cache/MemoryCacheAdapter.d.ts +1 -1
  12. package/cache/MemoryCacheAdapter.js +1 -5
  13. package/cache/NullCacheAdapter.d.ts +1 -1
  14. package/cache/NullCacheAdapter.js +1 -5
  15. package/cache/index.d.ts +4 -5
  16. package/cache/index.js +4 -21
  17. package/connections/Connection.d.ts +22 -14
  18. package/connections/Connection.js +27 -23
  19. package/connections/index.d.ts +1 -1
  20. package/connections/index.js +1 -17
  21. package/drivers/DatabaseDriver.d.ts +25 -15
  22. package/drivers/DatabaseDriver.js +77 -64
  23. package/drivers/IDatabaseDriver.d.ts +40 -16
  24. package/drivers/IDatabaseDriver.js +1 -4
  25. package/drivers/index.d.ts +2 -2
  26. package/drivers/index.js +2 -18
  27. package/entity/BaseEntity.d.ts +6 -7
  28. package/entity/BaseEntity.js +16 -23
  29. package/entity/Collection.d.ts +98 -34
  30. package/entity/Collection.js +466 -131
  31. package/entity/EntityAssigner.d.ts +3 -3
  32. package/entity/EntityAssigner.js +67 -64
  33. package/entity/EntityFactory.d.ts +10 -3
  34. package/entity/EntityFactory.js +112 -91
  35. package/entity/EntityHelper.d.ts +2 -2
  36. package/entity/EntityHelper.js +66 -53
  37. package/entity/EntityIdentifier.d.ts +1 -1
  38. package/entity/EntityIdentifier.js +1 -5
  39. package/entity/EntityLoader.d.ts +8 -7
  40. package/entity/EntityLoader.js +161 -128
  41. package/entity/EntityRepository.d.ts +8 -8
  42. package/entity/EntityRepository.js +7 -11
  43. package/entity/Reference.d.ts +10 -13
  44. package/entity/Reference.js +64 -46
  45. package/entity/WrappedEntity.d.ts +12 -17
  46. package/entity/WrappedEntity.js +22 -31
  47. package/entity/defineEntity.d.ts +568 -0
  48. package/entity/defineEntity.js +529 -0
  49. package/entity/index.d.ts +14 -13
  50. package/entity/index.js +14 -29
  51. package/entity/utils.d.ts +8 -1
  52. package/entity/utils.js +22 -13
  53. package/entity/validators.d.ts +11 -0
  54. package/entity/validators.js +65 -0
  55. package/entity/wrap.d.ts +1 -1
  56. package/entity/wrap.js +2 -6
  57. package/enums.d.ts +24 -9
  58. package/enums.js +50 -41
  59. package/errors.d.ts +11 -3
  60. package/errors.js +42 -32
  61. package/events/EventManager.d.ts +5 -4
  62. package/events/EventManager.js +26 -22
  63. package/events/EventSubscriber.d.ts +8 -5
  64. package/events/EventSubscriber.js +1 -2
  65. package/events/TransactionEventBroadcaster.d.ts +3 -3
  66. package/events/TransactionEventBroadcaster.js +1 -5
  67. package/events/index.d.ts +3 -3
  68. package/events/index.js +3 -19
  69. package/exceptions.js +18 -39
  70. package/hydration/Hydrator.d.ts +5 -5
  71. package/hydration/Hydrator.js +2 -6
  72. package/hydration/ObjectHydrator.d.ts +7 -7
  73. package/hydration/ObjectHydrator.js +58 -50
  74. package/hydration/index.d.ts +2 -2
  75. package/hydration/index.js +2 -18
  76. package/index.d.ts +21 -21
  77. package/index.js +20 -46
  78. package/logging/DefaultLogger.d.ts +2 -2
  79. package/logging/DefaultLogger.js +10 -13
  80. package/logging/Logger.d.ts +1 -1
  81. package/logging/Logger.js +1 -2
  82. package/logging/SimpleLogger.d.ts +3 -3
  83. package/logging/SimpleLogger.js +2 -6
  84. package/logging/colors.js +1 -5
  85. package/logging/index.d.ts +5 -4
  86. package/logging/index.js +5 -20
  87. package/logging/inspect.d.ts +2 -0
  88. package/logging/inspect.js +16 -0
  89. package/metadata/EntitySchema.d.ts +14 -10
  90. package/metadata/EntitySchema.js +78 -64
  91. package/metadata/MetadataDiscovery.d.ts +11 -14
  92. package/metadata/MetadataDiscovery.js +278 -317
  93. package/metadata/MetadataProvider.d.ts +13 -4
  94. package/metadata/MetadataProvider.js +47 -8
  95. package/metadata/MetadataStorage.d.ts +2 -7
  96. package/metadata/MetadataStorage.js +19 -35
  97. package/metadata/MetadataValidator.d.ts +3 -10
  98. package/metadata/MetadataValidator.js +51 -64
  99. package/metadata/discover-entities.d.ts +5 -0
  100. package/metadata/discover-entities.js +40 -0
  101. package/metadata/index.d.ts +6 -6
  102. package/metadata/index.js +6 -22
  103. package/metadata/types.d.ts +480 -0
  104. package/metadata/types.js +1 -0
  105. package/naming-strategy/AbstractNamingStrategy.d.ts +7 -3
  106. package/naming-strategy/AbstractNamingStrategy.js +11 -9
  107. package/naming-strategy/EntityCaseNamingStrategy.d.ts +1 -1
  108. package/naming-strategy/EntityCaseNamingStrategy.js +2 -6
  109. package/naming-strategy/MongoNamingStrategy.d.ts +1 -1
  110. package/naming-strategy/MongoNamingStrategy.js +2 -6
  111. package/naming-strategy/NamingStrategy.d.ts +12 -2
  112. package/naming-strategy/NamingStrategy.js +1 -2
  113. package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -1
  114. package/naming-strategy/UnderscoreNamingStrategy.js +2 -6
  115. package/naming-strategy/index.d.ts +5 -5
  116. package/naming-strategy/index.js +5 -21
  117. package/not-supported.d.ts +2 -0
  118. package/not-supported.js +4 -0
  119. package/package.json +19 -20
  120. package/platforms/ExceptionConverter.d.ts +2 -2
  121. package/platforms/ExceptionConverter.js +4 -8
  122. package/platforms/Platform.d.ts +15 -22
  123. package/platforms/Platform.js +58 -88
  124. package/platforms/index.d.ts +2 -2
  125. package/platforms/index.js +2 -18
  126. package/serialization/EntitySerializer.d.ts +4 -2
  127. package/serialization/EntitySerializer.js +64 -51
  128. package/serialization/EntityTransformer.d.ts +1 -1
  129. package/serialization/EntityTransformer.js +48 -42
  130. package/serialization/SerializationContext.d.ts +2 -2
  131. package/serialization/SerializationContext.js +24 -25
  132. package/serialization/index.d.ts +3 -3
  133. package/serialization/index.js +3 -19
  134. package/types/ArrayType.d.ts +3 -3
  135. package/types/ArrayType.js +6 -11
  136. package/types/BigIntType.d.ts +12 -9
  137. package/types/BigIntType.js +6 -6
  138. package/types/BlobType.d.ts +3 -4
  139. package/types/BlobType.js +2 -11
  140. package/types/BooleanType.d.ts +5 -4
  141. package/types/BooleanType.js +5 -6
  142. package/types/CharacterType.d.ts +3 -3
  143. package/types/CharacterType.js +2 -6
  144. package/types/DateTimeType.d.ts +3 -3
  145. package/types/DateTimeType.js +2 -6
  146. package/types/DateType.d.ts +3 -3
  147. package/types/DateType.js +2 -6
  148. package/types/DecimalType.d.ts +9 -7
  149. package/types/DecimalType.js +5 -8
  150. package/types/DoubleType.d.ts +3 -3
  151. package/types/DoubleType.js +4 -7
  152. package/types/EnumArrayType.d.ts +4 -4
  153. package/types/EnumArrayType.js +4 -10
  154. package/types/EnumType.d.ts +3 -3
  155. package/types/EnumType.js +2 -6
  156. package/types/FloatType.d.ts +3 -3
  157. package/types/FloatType.js +2 -6
  158. package/types/IntegerType.d.ts +3 -3
  159. package/types/IntegerType.js +2 -6
  160. package/types/IntervalType.d.ts +3 -3
  161. package/types/IntervalType.js +2 -6
  162. package/types/JsonType.d.ts +4 -4
  163. package/types/JsonType.js +9 -8
  164. package/types/MediumIntType.d.ts +3 -3
  165. package/types/MediumIntType.js +2 -6
  166. package/types/SmallIntType.d.ts +3 -3
  167. package/types/SmallIntType.js +2 -6
  168. package/types/StringType.d.ts +3 -3
  169. package/types/StringType.js +2 -6
  170. package/types/TextType.d.ts +3 -3
  171. package/types/TextType.js +2 -6
  172. package/types/TimeType.d.ts +3 -3
  173. package/types/TimeType.js +4 -8
  174. package/types/TinyIntType.d.ts +3 -3
  175. package/types/TinyIntType.js +3 -6
  176. package/types/Type.d.ts +4 -6
  177. package/types/Type.js +6 -10
  178. package/types/Uint8ArrayType.d.ts +3 -4
  179. package/types/Uint8ArrayType.js +3 -12
  180. package/types/UnknownType.d.ts +3 -3
  181. package/types/UnknownType.js +2 -6
  182. package/types/UuidType.d.ts +3 -3
  183. package/types/UuidType.js +2 -6
  184. package/types/index.d.ts +25 -25
  185. package/types/index.js +52 -79
  186. package/typings.d.ts +134 -93
  187. package/typings.js +67 -65
  188. package/unit-of-work/ChangeSet.d.ts +1 -4
  189. package/unit-of-work/ChangeSet.js +13 -17
  190. package/unit-of-work/ChangeSetComputer.d.ts +8 -9
  191. package/unit-of-work/ChangeSetComputer.js +36 -38
  192. package/unit-of-work/ChangeSetPersister.d.ts +11 -9
  193. package/unit-of-work/ChangeSetPersister.js +100 -65
  194. package/unit-of-work/CommitOrderCalculator.d.ts +1 -1
  195. package/unit-of-work/CommitOrderCalculator.js +6 -10
  196. package/unit-of-work/IdentityMap.d.ts +1 -1
  197. package/unit-of-work/IdentityMap.js +1 -5
  198. package/unit-of-work/UnitOfWork.d.ts +16 -8
  199. package/unit-of-work/UnitOfWork.js +266 -209
  200. package/unit-of-work/index.d.ts +6 -6
  201. package/unit-of-work/index.js +6 -22
  202. package/utils/AbstractSchemaGenerator.d.ts +11 -11
  203. package/utils/AbstractSchemaGenerator.js +21 -20
  204. package/utils/Configuration.d.ts +774 -224
  205. package/utils/Configuration.js +166 -216
  206. package/utils/ConfigurationLoader.d.ts +1 -53
  207. package/utils/ConfigurationLoader.js +1 -367
  208. package/utils/Cursor.d.ts +6 -9
  209. package/utils/Cursor.js +25 -25
  210. package/utils/DataloaderUtils.d.ts +18 -8
  211. package/utils/DataloaderUtils.js +63 -21
  212. package/utils/EntityComparator.d.ts +9 -5
  213. package/utils/EntityComparator.js +155 -108
  214. package/utils/NullHighlighter.d.ts +1 -1
  215. package/utils/NullHighlighter.js +1 -5
  216. package/utils/QueryHelper.d.ts +12 -4
  217. package/utils/QueryHelper.js +110 -53
  218. package/utils/RawQueryFragment.d.ts +37 -14
  219. package/utils/RawQueryFragment.js +50 -33
  220. package/utils/RequestContext.d.ts +2 -2
  221. package/utils/RequestContext.js +3 -7
  222. package/utils/TransactionContext.d.ts +1 -1
  223. package/utils/TransactionContext.js +4 -8
  224. package/utils/TransactionManager.d.ts +65 -0
  225. package/utils/TransactionManager.js +223 -0
  226. package/utils/Utils.d.ts +16 -100
  227. package/utils/Utils.js +114 -332
  228. package/utils/clone.js +7 -11
  229. package/utils/env-vars.d.ts +3 -0
  230. package/utils/env-vars.js +87 -0
  231. package/utils/fs-utils.d.ts +12 -0
  232. package/utils/fs-utils.js +97 -0
  233. package/utils/index.d.ts +14 -13
  234. package/utils/index.js +14 -29
  235. package/utils/upsert-utils.d.ts +8 -3
  236. package/utils/upsert-utils.js +57 -10
  237. package/decorators/Check.d.ts +0 -3
  238. package/decorators/Check.js +0 -16
  239. package/decorators/CreateRequestContext.d.ts +0 -3
  240. package/decorators/CreateRequestContext.js +0 -33
  241. package/decorators/Embeddable.d.ts +0 -8
  242. package/decorators/Embeddable.js +0 -14
  243. package/decorators/Embedded.d.ts +0 -18
  244. package/decorators/Embedded.js +0 -20
  245. package/decorators/Entity.d.ts +0 -18
  246. package/decorators/Entity.js +0 -16
  247. package/decorators/Enum.d.ts +0 -9
  248. package/decorators/Enum.js +0 -19
  249. package/decorators/Filter.d.ts +0 -2
  250. package/decorators/Filter.js +0 -11
  251. package/decorators/Formula.d.ts +0 -5
  252. package/decorators/Formula.js +0 -18
  253. package/decorators/Indexed.d.ts +0 -17
  254. package/decorators/Indexed.js +0 -24
  255. package/decorators/ManyToMany.d.ts +0 -40
  256. package/decorators/ManyToMany.js +0 -16
  257. package/decorators/ManyToOne.d.ts +0 -30
  258. package/decorators/ManyToOne.js +0 -16
  259. package/decorators/OneToMany.d.ts +0 -28
  260. package/decorators/OneToMany.js +0 -20
  261. package/decorators/OneToOne.d.ts +0 -24
  262. package/decorators/OneToOne.js +0 -10
  263. package/decorators/PrimaryKey.d.ts +0 -9
  264. package/decorators/PrimaryKey.js +0 -23
  265. package/decorators/Property.d.ts +0 -250
  266. package/decorators/Property.js +0 -34
  267. package/decorators/Transactional.d.ts +0 -13
  268. package/decorators/Transactional.js +0 -31
  269. package/decorators/hooks.d.ts +0 -16
  270. package/decorators/hooks.js +0 -59
  271. package/decorators/index.d.ts +0 -17
  272. package/decorators/index.js +0 -36
  273. package/entity/ArrayCollection.d.ts +0 -116
  274. package/entity/ArrayCollection.js +0 -399
  275. package/entity/EntityValidator.d.ts +0 -19
  276. package/entity/EntityValidator.js +0 -154
  277. package/index.mjs +0 -199
  278. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  279. package/metadata/ReflectMetadataProvider.js +0 -48
  280. package/utils/resolveContextProvider.d.ts +0 -10
  281. package/utils/resolveContextProvider.js +0 -31
@@ -1,11 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GeneratedCacheAdapter = void 0;
4
- class GeneratedCacheAdapter {
5
- options;
1
+ export class GeneratedCacheAdapter {
6
2
  data = new Map();
7
3
  constructor(options) {
8
- this.options = options;
9
4
  this.data = new Map(Object.entries(options.data));
10
5
  }
11
6
  /**
@@ -35,4 +30,3 @@ class GeneratedCacheAdapter {
35
30
  this.data.clear();
36
31
  }
37
32
  }
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,4 @@
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 './MemoryCacheAdapter.js';
4
+ export * from './GeneratedCacheAdapter.js';
package/cache/index.js CHANGED
@@ -1,21 +1,4 @@
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 './MemoryCacheAdapter.js';
4
+ 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;
@@ -17,7 +17,9 @@ export declare abstract class Connection {
17
17
  /**
18
18
  * Establishes connection to database
19
19
  */
20
- abstract connect(): void | Promise<void>;
20
+ abstract connect(options?: {
21
+ skipOnConnect?: boolean;
22
+ }): void | Promise<void>;
21
23
  /**
22
24
  * Are we connected to the database
23
25
  */
@@ -37,26 +39,32 @@ export declare abstract class Connection {
37
39
  */
38
40
  close(force?: boolean): Promise<void>;
39
41
  /**
40
- * Ensure the connection exists, this is used to support lazy connect when using `MikroORM.initSync()`
42
+ * Ensure the connection exists, this is used to support lazy connect when using `new MikroORM()` instead of the async `init` method.
41
43
  */
42
44
  ensureConnection(): Promise<void>;
45
+ /**
46
+ * Load schema dump from file and execute it. Not supported by MongoDB driver.
47
+ */
48
+ loadFile(path: string): Promise<void>;
49
+ protected onConnect(): Promise<void>;
43
50
  transactional<T>(cb: (trx: Transaction) => Promise<T>, options?: {
44
- isolationLevel?: IsolationLevel;
51
+ isolationLevel?: IsolationLevel | `${IsolationLevel}`;
45
52
  readOnly?: boolean;
46
53
  ctx?: Transaction;
47
54
  eventBroadcaster?: TransactionEventBroadcaster;
55
+ loggerContext?: LogContext;
48
56
  }): Promise<T>;
49
57
  begin(options?: {
50
- isolationLevel?: IsolationLevel;
58
+ isolationLevel?: IsolationLevel | `${IsolationLevel}`;
51
59
  readOnly?: boolean;
52
60
  ctx?: Transaction;
53
61
  eventBroadcaster?: TransactionEventBroadcaster;
62
+ loggerContext?: LogContext;
54
63
  }): Promise<Transaction>;
55
- commit(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
56
- rollback(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
64
+ commit(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster, loggerContext?: LogContext): Promise<void>;
65
+ rollback(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster, loggerContext?: LogContext): Promise<void>;
57
66
  abstract execute<T>(query: string, params?: any[], method?: 'all' | 'get' | 'run', ctx?: Transaction): Promise<QueryResult<T> | any | any[]>;
58
67
  getConnectionOptions(): ConnectionConfig;
59
- getClientUrl(): string;
60
68
  setMetadata(metadata: MetadataStorage): void;
61
69
  setPlatform(platform: Platform): void;
62
70
  getPlatform(): Platform;
@@ -1,9 +1,5 @@
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 { Utils } from '../utils/Utils.js';
2
+ export class Connection {
7
3
  config;
8
4
  type;
9
5
  metadata;
@@ -17,7 +13,7 @@ class Connection {
17
13
  this.logger = this.config.getLogger();
18
14
  this.platform = this.config.getPlatform();
19
15
  if (options) {
20
- this.options = utils_1.Utils.copy(options);
16
+ this.options = Utils.copy(options);
21
17
  }
22
18
  else {
23
19
  const props = ['dbName', 'clientUrl', 'host', 'port', 'user', 'password', 'multipleStatements', 'pool', 'schema', 'driverOptions'];
@@ -36,29 +32,47 @@ class Connection {
36
32
  .forEach(k => delete this.options[k]);
37
33
  }
38
34
  /**
39
- * Ensure the connection exists, this is used to support lazy connect when using `MikroORM.initSync()`
35
+ * Ensure the connection exists, this is used to support lazy connect when using `new MikroORM()` instead of the async `init` method.
40
36
  */
41
37
  async ensureConnection() {
42
38
  if (!this.connected) {
43
39
  await this.connect();
44
40
  }
45
41
  }
42
+ /**
43
+ * Load schema dump from file and execute it. Not supported by MongoDB driver.
44
+ */
45
+ async loadFile(path) {
46
+ throw new Error(`Loading SQL files is not supported by current driver`);
47
+ }
48
+ async onConnect() {
49
+ const schemaGenerator = this.config.getExtension('@mikro-orm/schema-generator');
50
+ if (this.type === 'write' && schemaGenerator) {
51
+ if (this.config.get('ensureDatabase')) {
52
+ const options = this.config.get('ensureDatabase');
53
+ await schemaGenerator.ensureDatabase(typeof options === 'boolean' ? {} : { ...options, forceCheck: true });
54
+ }
55
+ if (this.config.get('ensureIndexes')) {
56
+ await schemaGenerator.ensureIndexes();
57
+ }
58
+ }
59
+ }
46
60
  async transactional(cb, options) {
47
61
  throw new Error(`Transactions are not supported by current driver`);
48
62
  }
49
63
  async begin(options) {
50
64
  throw new Error(`Transactions are not supported by current driver`);
51
65
  }
52
- async commit(ctx, eventBroadcaster) {
66
+ async commit(ctx, eventBroadcaster, loggerContext) {
53
67
  throw new Error(`Transactions are not supported by current driver`);
54
68
  }
55
- async rollback(ctx, eventBroadcaster) {
69
+ async rollback(ctx, eventBroadcaster, loggerContext) {
56
70
  throw new Error(`Transactions are not supported by current driver`);
57
71
  }
58
72
  getConnectionOptions() {
59
73
  const ret = {};
60
74
  if (this.options.clientUrl) {
61
- const url = new node_url_1.URL(this.options.clientUrl);
75
+ const url = new URL(this.options.clientUrl);
62
76
  this.options.host = ret.host = this.options.host ?? decodeURIComponent(url.hostname);
63
77
  this.options.port = ret.port = this.options.port ?? +url.port;
64
78
  this.options.user = ret.user = this.options.user ?? decodeURIComponent(url.username);
@@ -70,7 +84,7 @@ class Connection {
70
84
  }
71
85
  }
72
86
  else {
73
- const url = new node_url_1.URL(this.config.getClientUrl());
87
+ const url = new URL(this.config.get('clientUrl'));
74
88
  this.options.host = ret.host = this.options.host ?? this.config.get('host', decodeURIComponent(url.hostname));
75
89
  this.options.port = ret.port = this.options.port ?? this.config.get('port', +url.port);
76
90
  this.options.user = ret.user = this.options.user ?? this.config.get('user', decodeURIComponent(url.username));
@@ -79,15 +93,6 @@ class Connection {
79
93
  }
80
94
  return ret;
81
95
  }
82
- getClientUrl() {
83
- const options = this.getConnectionOptions();
84
- const url = new node_url_1.URL(this.config.getClientUrl(true));
85
- const password = options.password ? ':*****' : '';
86
- const schema = options.schema && options.schema !== this.platform.getDefaultSchemaName()
87
- ? `?schema=${options.schema}`
88
- : '';
89
- return `${url.protocol}//${options.user}${password}@${options.host}:${options.port}${schema}`;
90
- }
91
96
  setMetadata(metadata) {
92
97
  this.metadata = metadata;
93
98
  }
@@ -105,7 +110,7 @@ class Connection {
105
110
  ...context,
106
111
  took: Date.now() - now,
107
112
  results: Array.isArray(res) ? res.length : undefined,
108
- affected: utils_1.Utils.isPlainObject(res) ? res.affectedRows : undefined,
113
+ affected: Utils.isPlainObject(res) ? res.affectedRows : undefined,
109
114
  });
110
115
  return res;
111
116
  }
@@ -126,4 +131,3 @@ class Connection {
126
131
  });
127
132
  }
128
133
  }
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,14 +1,16 @@
1
- import { type CountOptions, type DeleteOptions, type DriverMethodOptions, EntityManagerType, type FindOneOptions, type FindOptions, type IDatabaseDriver, type LockOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type OrderDefinition } from './IDatabaseDriver';
2
- import type { ConnectionType, Dictionary, EntityData, EntityDictionary, EntityMetadata, EntityProperty, FilterQuery, PopulateOptions, Primary } from '../typings';
3
- import type { MetadataStorage } from '../metadata';
4
- import type { Connection, QueryResult, Transaction } from '../connections';
5
- import { type Configuration, type ConnectionOptions, EntityComparator } from '../utils';
6
- import { type QueryOrder } from '../enums';
7
- import type { Platform } from '../platforms';
8
- import type { Collection } from '../entity/Collection';
9
- import { EntityManager } from '../EntityManager';
10
- import { DriverException } from '../exceptions';
11
- import type { Logger } from '../logging/Logger';
1
+ import { type CountOptions, type DeleteOptions, type DriverMethodOptions, EntityManagerType, type FindOneOptions, type FindOptions, type IDatabaseDriver, type LockOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type OrderDefinition, type StreamOptions } from './IDatabaseDriver.js';
2
+ import type { ConnectionType, Constructor, Dictionary, EntityData, EntityDictionary, EntityMetadata, EntityName, EntityProperty, FilterQuery, PopulateOptions, Primary } from '../typings.js';
3
+ import type { MetadataStorage } from '../metadata/MetadataStorage.js';
4
+ import type { Connection, QueryResult, Transaction } from '../connections/Connection.js';
5
+ import { type Configuration, type ConnectionOptions } from '../utils/Configuration.js';
6
+ import { EntityComparator } from '../utils/EntityComparator.js';
7
+ import { type QueryOrder } from '../enums.js';
8
+ import type { Platform } from '../platforms/Platform.js';
9
+ import type { Collection } from '../entity/Collection.js';
10
+ import { EntityManager } from '../EntityManager.js';
11
+ import { DriverException } from '../exceptions.js';
12
+ import type { Logger } from '../logging/Logger.js';
13
+ import { MikroORM } from '../MikroORM.js';
12
14
  export declare abstract class DatabaseDriver<C extends Connection> implements IDatabaseDriver<C> {
13
15
  readonly config: Configuration;
14
16
  protected readonly dependencies: string[];
@@ -28,21 +30,26 @@ export declare abstract class DatabaseDriver<C extends Connection> implements ID
28
30
  nativeUpdateMany<T extends object>(entityName: string, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
29
31
  abstract nativeDelete<T extends object>(entityName: string, where: FilterQuery<T>, options?: DeleteOptions<T>): Promise<QueryResult<T>>;
30
32
  abstract count<T extends object, P extends string = never>(entityName: string, where: FilterQuery<T>, options?: CountOptions<T, P>): Promise<number>;
31
- createEntityManager<D extends IDatabaseDriver = IDatabaseDriver>(useContext?: boolean): D[typeof EntityManagerType];
32
- findVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
33
+ createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
34
+ findVirtual<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
33
35
  countVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: CountOptions<T, any>): Promise<number>;
34
36
  aggregate(entityName: string, pipeline: any[]): Promise<any[]>;
35
37
  loadFromPivotTable<T extends object, O extends object>(prop: EntityProperty, owners: Primary<O>[][], where?: FilterQuery<any>, orderBy?: OrderDefinition<T>, ctx?: Transaction, options?: FindOptions<T, any, any, any>, pivotJoin?: boolean): Promise<Dictionary<T[]>>;
36
38
  syncCollections<T extends object, O extends object>(collections: Iterable<Collection<T, O>>, options?: DriverMethodOptions): Promise<void>;
37
39
  mapResult<T extends object>(result: EntityDictionary<T>, meta?: EntityMetadata<T>, populate?: PopulateOptions<T>[]): EntityData<T> | null;
38
- connect(): Promise<C>;
39
- reconnect(): Promise<C>;
40
+ connect(options?: {
41
+ skipOnConnect?: boolean;
42
+ }): Promise<C>;
43
+ reconnect(options?: {
44
+ skipOnConnect?: boolean;
45
+ }): Promise<C>;
40
46
  getConnection(type?: ConnectionType): C;
41
47
  close(force?: boolean): Promise<void>;
42
48
  getPlatform(): Platform;
43
49
  setMetadata(metadata: MetadataStorage): void;
44
50
  getMetadata(): MetadataStorage;
45
51
  getDependencies(): string[];
52
+ protected isPopulated<T extends object>(meta: EntityMetadata<T>, prop: EntityProperty<T>, hint: PopulateOptions<T>, name?: string): boolean;
46
53
  protected processCursorOptions<T extends object, P extends string>(meta: EntityMetadata<T>, options: FindOptions<T, P, any, any>, orderBy: OrderDefinition<T>): {
47
54
  orderBy: OrderDefinition<T>[];
48
55
  where: FilterQuery<T>;
@@ -54,6 +61,7 @@ export declare abstract class DatabaseDriver<C extends Connection> implements ID
54
61
  protected getPrimaryKeyFields(entityName: string): string[];
55
62
  protected createReplicas(cb: (c: ConnectionOptions) => C): C[];
56
63
  lockPessimistic<T extends object>(entity: T, options: LockOptions): Promise<void>;
64
+ abstract stream<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: StreamOptions<T>): AsyncIterableIterator<T>;
57
65
  /**
58
66
  * @inheritDoc
59
67
  */
@@ -70,4 +78,6 @@ export declare abstract class DatabaseDriver<C extends Connection> implements ID
70
78
  schema?: string;
71
79
  parentSchema?: string;
72
80
  }): string | undefined;
81
+ /** @internal */
82
+ getORMClass(): Constructor<MikroORM>;
73
83
  }