@mikro-orm/core 7.0.2-dev.12 → 7.0.2-dev.14

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 (147) hide show
  1. package/EntityManager.d.ts +4 -0
  2. package/EntityManager.js +4 -0
  3. package/MikroORM.d.ts +2 -0
  4. package/MikroORM.js +2 -0
  5. package/cache/CacheAdapter.d.ts +2 -0
  6. package/cache/GeneratedCacheAdapter.d.ts +1 -0
  7. package/cache/GeneratedCacheAdapter.js +1 -0
  8. package/cache/MemoryCacheAdapter.d.ts +1 -0
  9. package/cache/MemoryCacheAdapter.js +1 -0
  10. package/cache/NullCacheAdapter.d.ts +1 -0
  11. package/cache/NullCacheAdapter.js +1 -0
  12. package/connections/Connection.d.ts +13 -0
  13. package/connections/Connection.js +9 -0
  14. package/drivers/DatabaseDriver.d.ts +12 -0
  15. package/drivers/DatabaseDriver.js +12 -0
  16. package/drivers/IDatabaseDriver.d.ts +44 -0
  17. package/drivers/IDatabaseDriver.js +1 -0
  18. package/entity/BaseEntity.d.ts +11 -0
  19. package/entity/BaseEntity.js +11 -0
  20. package/entity/Collection.d.ts +26 -0
  21. package/entity/Collection.js +15 -0
  22. package/entity/EntityAssigner.d.ts +3 -0
  23. package/entity/EntityAssigner.js +2 -0
  24. package/entity/EntityFactory.d.ts +16 -0
  25. package/entity/EntityFactory.js +6 -0
  26. package/entity/EntityLoader.d.ts +19 -0
  27. package/entity/EntityLoader.js +2 -0
  28. package/entity/EntityRepository.d.ts +2 -0
  29. package/entity/EntityRepository.js +2 -0
  30. package/entity/Reference.d.ts +20 -0
  31. package/entity/Reference.js +16 -0
  32. package/entity/WrappedEntity.d.ts +20 -0
  33. package/entity/WrappedEntity.js +21 -1
  34. package/entity/defineEntity.d.ts +10 -0
  35. package/entity/defineEntity.js +1 -0
  36. package/enums.d.ts +132 -0
  37. package/enums.js +132 -0
  38. package/errors.d.ts +6 -0
  39. package/errors.js +6 -0
  40. package/events/EventManager.d.ts +5 -0
  41. package/events/EventManager.js +5 -0
  42. package/events/EventSubscriber.d.ts +4 -0
  43. package/events/TransactionEventBroadcaster.d.ts +2 -0
  44. package/events/TransactionEventBroadcaster.js +2 -0
  45. package/hydration/Hydrator.d.ts +2 -0
  46. package/hydration/Hydrator.js +2 -0
  47. package/hydration/ObjectHydrator.d.ts +1 -0
  48. package/hydration/ObjectHydrator.js +1 -0
  49. package/logging/DefaultLogger.d.ts +3 -0
  50. package/logging/DefaultLogger.js +3 -0
  51. package/logging/Logger.d.ts +5 -0
  52. package/metadata/EntitySchema.d.ts +22 -0
  53. package/metadata/EntitySchema.js +20 -0
  54. package/metadata/MetadataDiscovery.d.ts +4 -0
  55. package/metadata/MetadataDiscovery.js +4 -0
  56. package/metadata/MetadataProvider.d.ts +8 -0
  57. package/metadata/MetadataProvider.js +8 -0
  58. package/metadata/MetadataStorage.d.ts +14 -0
  59. package/metadata/MetadataStorage.js +13 -0
  60. package/naming-strategy/AbstractNamingStrategy.d.ts +1 -0
  61. package/naming-strategy/AbstractNamingStrategy.js +1 -0
  62. package/naming-strategy/MongoNamingStrategy.d.ts +1 -0
  63. package/naming-strategy/MongoNamingStrategy.js +1 -0
  64. package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -0
  65. package/naming-strategy/UnderscoreNamingStrategy.js +1 -0
  66. package/package.json +1 -1
  67. package/platforms/ExceptionConverter.d.ts +1 -0
  68. package/platforms/ExceptionConverter.js +1 -0
  69. package/platforms/Platform.d.ts +65 -0
  70. package/platforms/Platform.js +65 -0
  71. package/serialization/EntitySerializer.d.ts +2 -0
  72. package/serialization/EntitySerializer.js +2 -0
  73. package/serialization/EntityTransformer.d.ts +2 -0
  74. package/serialization/EntityTransformer.js +2 -0
  75. package/serialization/SerializationContext.d.ts +5 -0
  76. package/serialization/SerializationContext.js +5 -0
  77. package/types/ArrayType.d.ts +1 -0
  78. package/types/ArrayType.js +1 -0
  79. package/types/BlobType.d.ts +1 -0
  80. package/types/BlobType.js +1 -0
  81. package/types/BooleanType.d.ts +1 -0
  82. package/types/BooleanType.js +1 -0
  83. package/types/CharacterType.d.ts +1 -0
  84. package/types/CharacterType.js +1 -0
  85. package/types/DateTimeType.d.ts +1 -0
  86. package/types/DateTimeType.js +1 -0
  87. package/types/DateType.d.ts +1 -0
  88. package/types/DateType.js +1 -0
  89. package/types/EnumArrayType.d.ts +1 -0
  90. package/types/EnumArrayType.js +1 -0
  91. package/types/EnumType.d.ts +1 -0
  92. package/types/EnumType.js +1 -0
  93. package/types/FloatType.d.ts +1 -0
  94. package/types/FloatType.js +1 -0
  95. package/types/IntegerType.d.ts +1 -0
  96. package/types/IntegerType.js +1 -0
  97. package/types/IntervalType.d.ts +1 -0
  98. package/types/IntervalType.js +1 -0
  99. package/types/JsonType.d.ts +1 -0
  100. package/types/JsonType.js +1 -0
  101. package/types/MediumIntType.d.ts +1 -0
  102. package/types/MediumIntType.js +1 -0
  103. package/types/SmallIntType.d.ts +1 -0
  104. package/types/SmallIntType.js +1 -0
  105. package/types/StringType.d.ts +1 -0
  106. package/types/StringType.js +1 -0
  107. package/types/TextType.d.ts +1 -0
  108. package/types/TextType.js +1 -0
  109. package/types/TimeType.d.ts +1 -0
  110. package/types/TimeType.js +1 -0
  111. package/types/TinyIntType.d.ts +1 -0
  112. package/types/TinyIntType.js +1 -0
  113. package/types/Type.d.ts +3 -0
  114. package/types/Type.js +1 -0
  115. package/types/Uint8ArrayType.d.ts +1 -0
  116. package/types/Uint8ArrayType.js +1 -0
  117. package/types/UnknownType.d.ts +1 -0
  118. package/types/UnknownType.js +1 -0
  119. package/types/UuidType.d.ts +1 -0
  120. package/types/UuidType.js +1 -0
  121. package/types/index.d.ts +2 -0
  122. package/types/index.js +2 -0
  123. package/typings.d.ts +177 -0
  124. package/typings.js +11 -0
  125. package/unit-of-work/ChangeSet.d.ts +4 -0
  126. package/unit-of-work/ChangeSet.js +4 -0
  127. package/unit-of-work/ChangeSetComputer.d.ts +2 -0
  128. package/unit-of-work/ChangeSetComputer.js +2 -0
  129. package/unit-of-work/ChangeSetPersister.d.ts +4 -0
  130. package/unit-of-work/ChangeSetPersister.js +4 -0
  131. package/unit-of-work/IdentityMap.d.ts +7 -0
  132. package/unit-of-work/IdentityMap.js +7 -0
  133. package/unit-of-work/UnitOfWork.d.ts +15 -0
  134. package/unit-of-work/UnitOfWork.js +15 -0
  135. package/utils/Configuration.d.ts +8 -0
  136. package/utils/Configuration.js +8 -0
  137. package/utils/EntityComparator.d.ts +2 -0
  138. package/utils/EntityComparator.js +2 -0
  139. package/utils/NullHighlighter.d.ts +1 -0
  140. package/utils/NullHighlighter.js +1 -0
  141. package/utils/RawQueryFragment.d.ts +10 -0
  142. package/utils/RawQueryFragment.js +9 -0
  143. package/utils/RequestContext.d.ts +1 -0
  144. package/utils/TransactionContext.d.ts +1 -0
  145. package/utils/TransactionContext.js +1 -0
  146. package/utils/Utils.d.ts +6 -0
  147. package/utils/Utils.js +7 -1
@@ -28,7 +28,9 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
28
28
  readonly '~entities'?: unknown;
29
29
  /** @internal */
30
30
  readonly _id: number;
31
+ /** Whether this is the global (root) EntityManager instance. */
31
32
  readonly global = false;
33
+ /** The context name of this EntityManager, derived from the ORM configuration. */
32
34
  readonly name: string;
33
35
  protected loggerContext?: Dictionary;
34
36
  /**
@@ -106,6 +108,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
106
108
  getLoggerContext<T extends Dictionary = Dictionary>(options?: {
107
109
  disableContextResolution?: boolean;
108
110
  }): T;
111
+ /** Sets the flush mode for this EntityManager. Pass `undefined` to reset to the global default. */
109
112
  setFlushMode(flushMode?: FlushMode | `${FlushMode}`): void;
110
113
  protected processWhere<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName: EntityName<Entity>, where: FilterQuery<Entity>, options: FindOptions<Entity, Hint, Fields, Excludes> | FindOneOptions<Entity, Hint, Fields, Excludes>, type: 'read' | 'update' | 'delete'): Promise<FilterQuery<Entity>>;
111
114
  protected processUnionWhere<Entity extends object, Hint extends string = never>(entityName: EntityName<Entity>, options: FindOptions<Entity, Hint, any, any> | CountOptions<Entity, Hint> | UpdateOptions<Entity> | DeleteOptions<Entity>, type: 'read' | 'update' | 'delete'): Promise<void>;
@@ -470,6 +473,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
470
473
  * @internal
471
474
  */
472
475
  getContext(validate?: boolean): this;
476
+ /** Gets the EventManager instance used by this EntityManager. */
473
477
  getEventManager(): EventManager;
474
478
  /**
475
479
  * Checks whether this EntityManager is currently operating inside a database transaction.
package/EntityManager.js CHANGED
@@ -31,7 +31,9 @@ export class EntityManager {
31
31
  static #counter = 1;
32
32
  /** @internal */
33
33
  _id = EntityManager.#counter++;
34
+ /** Whether this is the global (root) EntityManager instance. */
34
35
  global = false;
36
+ /** The context name of this EntityManager, derived from the ORM configuration. */
35
37
  name;
36
38
  #loaders = {};
37
39
  #repositoryMap = new Map();
@@ -284,6 +286,7 @@ export class EntityManager {
284
286
  em.loggerContext ??= {};
285
287
  return em.loggerContext;
286
288
  }
289
+ /** Sets the flush mode for this EntityManager. Pass `undefined` to reset to the global default. */
287
290
  setFlushMode(flushMode) {
288
291
  this.getContext(false).#flushMode = flushMode;
289
292
  }
@@ -1586,6 +1589,7 @@ export class EntityManager {
1586
1589
  }
1587
1590
  return em;
1588
1591
  }
1592
+ /** Gets the EventManager instance used by this EntityManager. */
1589
1593
  getEventManager() {
1590
1594
  return this.eventManager;
1591
1595
  }
package/MikroORM.d.ts CHANGED
@@ -40,7 +40,9 @@ export declare class MikroORM<Driver extends IDatabaseDriver = IDatabaseDriver,
40
40
  em: EM & {
41
41
  '~entities'?: Entities;
42
42
  };
43
+ /** The database driver instance used by this ORM. */
43
44
  readonly driver: Driver;
45
+ /** The ORM configuration instance. */
44
46
  readonly config: Configuration<Driver>;
45
47
  /**
46
48
  * Initialize the ORM, load entity metadata, create EntityManager and connect to the database.
package/MikroORM.js CHANGED
@@ -72,7 +72,9 @@ export async function loadOptionalDependencies(options) {
72
72
  export class MikroORM {
73
73
  /** The global EntityManager instance. If you are using `RequestContext` helper, it will automatically pick the request specific context under the hood */
74
74
  em;
75
+ /** The database driver instance used by this ORM. */
75
76
  driver;
77
+ /** The ORM configuration instance. */
76
78
  config;
77
79
  #metadata;
78
80
  #logger;
@@ -1,3 +1,4 @@
1
+ /** Interface for async-capable cache storage used by result cache and metadata cache. */
1
2
  export interface CacheAdapter {
2
3
  /**
3
4
  * Gets the items under `name` key from the cache.
@@ -20,6 +21,7 @@ export interface CacheAdapter {
20
21
  */
21
22
  close?(): void | Promise<void>;
22
23
  }
24
+ /** Synchronous variant of CacheAdapter, used for metadata cache where async access is not needed. */
23
25
  export interface SyncCacheAdapter extends CacheAdapter {
24
26
  /**
25
27
  * Gets the items under `name` key from the cache.
@@ -1,5 +1,6 @@
1
1
  import type { CacheAdapter } from './CacheAdapter.js';
2
2
  import type { Dictionary } from '../typings.js';
3
+ /** Cache adapter backed by pre-generated static data, typically produced by the CLI cache:generate command. */
3
4
  export declare class GeneratedCacheAdapter implements CacheAdapter {
4
5
  #private;
5
6
  constructor(options: {
@@ -1,3 +1,4 @@
1
+ /** Cache adapter backed by pre-generated static data, typically produced by the CLI cache:generate command. */
1
2
  export class GeneratedCacheAdapter {
2
3
  #data;
3
4
  constructor(options) {
@@ -1,4 +1,5 @@
1
1
  import type { CacheAdapter } from './CacheAdapter.js';
2
+ /** In-memory cache adapter with time-based expiration. Used as the default result cache. */
2
3
  export declare class MemoryCacheAdapter implements CacheAdapter {
3
4
  #private;
4
5
  constructor(options: {
@@ -1,3 +1,4 @@
1
+ /** In-memory cache adapter with time-based expiration. Used as the default result cache. */
1
2
  export class MemoryCacheAdapter {
2
3
  #data = new Map();
3
4
  #options;
@@ -1,4 +1,5 @@
1
1
  import type { SyncCacheAdapter } from './CacheAdapter.js';
2
+ /** No-op cache adapter that never stores or returns any data. Used to disable caching. */
2
3
  export declare class NullCacheAdapter implements SyncCacheAdapter {
3
4
  /**
4
5
  * @inheritDoc
@@ -1,3 +1,4 @@
1
+ /** No-op cache adapter that never stores or returns any data. Used to disable caching. */
1
2
  export class NullCacheAdapter {
2
3
  /**
3
4
  * @inheritDoc
@@ -5,6 +5,7 @@ import type { ConnectionType, Dictionary, MaybePromise, Primary } from '../typin
5
5
  import type { Platform } from '../platforms/Platform.js';
6
6
  import type { TransactionEventBroadcaster } from '../events/TransactionEventBroadcaster.js';
7
7
  import type { IsolationLevel } from '../enums.js';
8
+ /** Abstract base class for database connections, providing transaction and query execution support. */
8
9
  export declare abstract class Connection {
9
10
  #private;
10
11
  protected readonly config: Configuration;
@@ -49,6 +50,7 @@ export declare abstract class Connection {
49
50
  */
50
51
  executeDump(dump: string): Promise<void>;
51
52
  protected onConnect(): Promise<void>;
53
+ /** Executes a callback inside a transaction, committing on success and rolling back on failure. */
52
54
  transactional<T>(cb: (trx: Transaction) => Promise<T>, options?: {
53
55
  isolationLevel?: IsolationLevel | `${IsolationLevel}`;
54
56
  readOnly?: boolean;
@@ -56,6 +58,7 @@ export declare abstract class Connection {
56
58
  eventBroadcaster?: TransactionEventBroadcaster;
57
59
  loggerContext?: LogContext;
58
60
  }): Promise<T>;
61
+ /** Begins a new database transaction and returns the transaction context. */
59
62
  begin(options?: {
60
63
  isolationLevel?: IsolationLevel | `${IsolationLevel}`;
61
64
  readOnly?: boolean;
@@ -63,16 +66,24 @@ export declare abstract class Connection {
63
66
  eventBroadcaster?: TransactionEventBroadcaster;
64
67
  loggerContext?: LogContext;
65
68
  }): Promise<Transaction>;
69
+ /** Commits the given transaction. */
66
70
  commit(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster, loggerContext?: LogContext): Promise<void>;
71
+ /** Rolls back the given transaction. */
67
72
  rollback(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster, loggerContext?: LogContext): Promise<void>;
73
+ /** Executes a raw query and returns the result. */
68
74
  abstract execute<T>(query: string, params?: any[], method?: 'all' | 'get' | 'run', ctx?: Transaction): Promise<QueryResult<T> | any | any[]>;
75
+ /** Parses and returns the resolved connection configuration (host, port, user, etc.). */
69
76
  getConnectionOptions(): ConnectionConfig;
77
+ /** Sets the metadata storage on this connection. */
70
78
  setMetadata(metadata: MetadataStorage): void;
79
+ /** Sets the platform abstraction on this connection. */
71
80
  setPlatform(platform: Platform): void;
81
+ /** Returns the platform abstraction for this connection. */
72
82
  getPlatform(): Platform;
73
83
  protected executeQuery<T>(query: string, cb: () => Promise<T>, context?: LogContext): Promise<T>;
74
84
  protected logQuery(query: string, context?: LogContext): void;
75
85
  }
86
+ /** Result of a native database query (insert, update, delete). */
76
87
  export interface QueryResult<T = {
77
88
  id: number;
78
89
  }> {
@@ -82,6 +93,7 @@ export interface QueryResult<T = {
82
93
  rows?: Dictionary[];
83
94
  insertedIds?: Primary<T>[];
84
95
  }
96
+ /** Resolved database connection parameters. */
85
97
  export interface ConnectionConfig {
86
98
  host?: string;
87
99
  port?: number;
@@ -90,4 +102,5 @@ export interface ConnectionConfig {
90
102
  database?: string;
91
103
  schema?: string;
92
104
  }
105
+ /** Opaque transaction context type, wrapping the driver-specific transaction object. */
93
106
  export type Transaction<T = any> = T & {};
@@ -1,4 +1,5 @@
1
1
  import { Utils } from '../utils/Utils.js';
2
+ /** Abstract base class for database connections, providing transaction and query execution support. */
2
3
  export class Connection {
3
4
  config;
4
5
  type;
@@ -75,18 +76,23 @@ export class Connection {
75
76
  }
76
77
  }
77
78
  }
79
+ /** Executes a callback inside a transaction, committing on success and rolling back on failure. */
78
80
  async transactional(cb, options) {
79
81
  throw new Error(`Transactions are not supported by current driver`);
80
82
  }
83
+ /** Begins a new database transaction and returns the transaction context. */
81
84
  async begin(options) {
82
85
  throw new Error(`Transactions are not supported by current driver`);
83
86
  }
87
+ /** Commits the given transaction. */
84
88
  async commit(ctx, eventBroadcaster, loggerContext) {
85
89
  throw new Error(`Transactions are not supported by current driver`);
86
90
  }
91
+ /** Rolls back the given transaction. */
87
92
  async rollback(ctx, eventBroadcaster, loggerContext) {
88
93
  throw new Error(`Transactions are not supported by current driver`);
89
94
  }
95
+ /** Parses and returns the resolved connection configuration (host, port, user, etc.). */
90
96
  getConnectionOptions() {
91
97
  const ret = {};
92
98
  if (this.options.clientUrl) {
@@ -113,12 +119,15 @@ export class Connection {
113
119
  }
114
120
  return ret;
115
121
  }
122
+ /** Sets the metadata storage on this connection. */
116
123
  setMetadata(metadata) {
117
124
  this.metadata = metadata;
118
125
  }
126
+ /** Sets the platform abstraction on this connection. */
119
127
  setPlatform(platform) {
120
128
  this.platform = platform;
121
129
  }
130
+ /** Returns the platform abstraction for this connection. */
122
131
  getPlatform() {
123
132
  return this.platform;
124
133
  }
@@ -10,6 +10,7 @@ import type { Collection } from '../entity/Collection.js';
10
10
  import { EntityManager } from '../EntityManager.js';
11
11
  import { DriverException } from '../exceptions.js';
12
12
  import { MikroORM } from '../MikroORM.js';
13
+ /** Abstract base class for all database drivers, implementing common driver logic. */
13
14
  export declare abstract class DatabaseDriver<C extends Connection> implements IDatabaseDriver<C> {
14
15
  readonly config: Configuration;
15
16
  protected readonly dependencies: string[];
@@ -28,24 +29,34 @@ export declare abstract class DatabaseDriver<C extends Connection> implements ID
28
29
  nativeUpdateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
29
30
  abstract nativeDelete<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options?: DeleteOptions<T>): Promise<QueryResult<T>>;
30
31
  abstract count<T extends object, P extends string = never>(entityName: EntityName<T>, where: FilterQuery<T>, options?: CountOptions<T, P>): Promise<number>;
32
+ /** Creates a new EntityManager instance bound to this driver. */
31
33
  createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
32
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: EntityName<T>, where: FilterQuery<T>, options: CountOptions<T, any>): Promise<number>;
34
36
  aggregate(entityName: EntityName, 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>;
39
+ /** Maps raw database result to entity data, converting column names to property names. */
37
40
  mapResult<T extends object>(result: EntityDictionary<T>, meta?: EntityMetadata<T>, populate?: PopulateOptions<T>[]): EntityData<T> | null;
41
+ /** Opens the primary connection and all read replicas. */
38
42
  connect(options?: {
39
43
  skipOnConnect?: boolean;
40
44
  }): Promise<C>;
45
+ /** Closes all connections and re-establishes them. */
41
46
  reconnect(options?: {
42
47
  skipOnConnect?: boolean;
43
48
  }): Promise<C>;
49
+ /** Returns the write connection or a random read replica. */
44
50
  getConnection(type?: ConnectionType): C;
51
+ /** Closes the primary connection and all read replicas. */
45
52
  close(force?: boolean): Promise<void>;
53
+ /** Returns the database platform abstraction for this driver. */
46
54
  getPlatform(): Platform;
55
+ /** Sets the metadata storage and initializes the comparator for all connections. */
47
56
  setMetadata(metadata: MetadataStorage): void;
57
+ /** Returns the metadata storage used by this driver. */
48
58
  getMetadata(): MetadataStorage;
59
+ /** Returns the names of native database dependencies required by this driver. */
49
60
  getDependencies(): string[];
50
61
  protected isPopulated<T extends object>(meta: EntityMetadata<T>, prop: EntityProperty<T>, hint: PopulateOptions<T>, name?: string): boolean;
51
62
  protected processCursorOptions<T extends object, P extends string>(meta: EntityMetadata<T>, options: FindOptions<T, P, any, any>, orderBy: OrderDefinition<T>): {
@@ -58,6 +69,7 @@ export declare abstract class DatabaseDriver<C extends Connection> implements ID
58
69
  protected inlineEmbeddables<T extends object>(meta: EntityMetadata<T>, data: T, where?: boolean): void;
59
70
  protected getPrimaryKeyFields<T>(meta: EntityMetadata<T>): string[];
60
71
  protected createReplicas(cb: (c: ConnectionOptions) => C): C[];
72
+ /** Acquires a pessimistic lock on the given entity. */
61
73
  lockPessimistic<T extends object>(entity: T, options: LockOptions): Promise<void>;
62
74
  abstract stream<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: StreamOptions<T>): AsyncIterableIterator<T>;
63
75
  /**
@@ -11,6 +11,7 @@ import { helper } from '../entity/wrap.js';
11
11
  import { PolymorphicRef } from '../entity/PolymorphicRef.js';
12
12
  import { JsonType } from '../types/JsonType.js';
13
13
  import { MikroORM } from '../MikroORM.js';
14
+ /** Abstract base class for all database drivers, implementing common driver logic. */
14
15
  export class DatabaseDriver {
15
16
  config;
16
17
  dependencies;
@@ -27,6 +28,7 @@ export class DatabaseDriver {
27
28
  async nativeUpdateMany(entityName, where, data, options) {
28
29
  throw new Error(`Batch updates are not supported by ${this.constructor.name} driver`);
29
30
  }
31
+ /** Creates a new EntityManager instance bound to this driver. */
30
32
  createEntityManager(useContext) {
31
33
  const EntityManagerClass = this.config.get('entityManager', EntityManager);
32
34
  return new EntityManagerClass(this.config, this, this.metadata, useContext);
@@ -62,22 +64,26 @@ export class DatabaseDriver {
62
64
  }
63
65
  }
64
66
  }
67
+ /** Maps raw database result to entity data, converting column names to property names. */
65
68
  mapResult(result, meta, populate = []) {
66
69
  if (!result || !meta) {
67
70
  return result ?? null;
68
71
  }
69
72
  return this.comparator.mapResult(meta, result);
70
73
  }
74
+ /** Opens the primary connection and all read replicas. */
71
75
  async connect(options) {
72
76
  await this.connection.connect(options);
73
77
  await Promise.all(this.replicas.map(replica => replica.connect()));
74
78
  return this.connection;
75
79
  }
80
+ /** Closes all connections and re-establishes them. */
76
81
  async reconnect(options) {
77
82
  await this.close(true);
78
83
  await this.connect(options);
79
84
  return this.connection;
80
85
  }
86
+ /** Returns the write connection or a random read replica. */
81
87
  getConnection(type = 'write') {
82
88
  if (type === 'write' || this.replicas.length === 0) {
83
89
  return this.connection;
@@ -85,13 +91,16 @@ export class DatabaseDriver {
85
91
  const rand = Utils.randomInt(0, this.replicas.length - 1);
86
92
  return this.replicas[rand];
87
93
  }
94
+ /** Closes the primary connection and all read replicas. */
88
95
  async close(force) {
89
96
  await Promise.all(this.replicas.map(replica => replica.close(force)));
90
97
  await this.connection.close(force);
91
98
  }
99
+ /** Returns the database platform abstraction for this driver. */
92
100
  getPlatform() {
93
101
  return this.platform;
94
102
  }
103
+ /** Sets the metadata storage and initializes the comparator for all connections. */
95
104
  setMetadata(metadata) {
96
105
  this.metadata = metadata;
97
106
  this.comparator = new EntityComparator(this.metadata, this.platform);
@@ -102,9 +111,11 @@ export class DatabaseDriver {
102
111
  replica.setPlatform(this.platform);
103
112
  });
104
113
  }
114
+ /** Returns the metadata storage used by this driver. */
105
115
  getMetadata() {
106
116
  return this.metadata;
107
117
  }
118
+ /** Returns the names of native database dependencies required by this driver. */
108
119
  getDependencies() {
109
120
  return this.dependencies;
110
121
  }
@@ -426,6 +437,7 @@ export class DatabaseDriver {
426
437
  }
427
438
  return ret;
428
439
  }
440
+ /** Acquires a pessimistic lock on the given entity. */
429
441
  async lockPessimistic(entity, options) {
430
442
  throw new Error(`Pessimistic locks are not supported by ${this.constructor.name} driver`);
431
443
  }
@@ -10,18 +10,25 @@ import type { Configuration } from '../utils/Configuration.js';
10
10
  import type { MikroORM } from '../MikroORM.js';
11
11
  import type { LoggingOptions, LogContext } from '../logging/Logger.js';
12
12
  import type { Raw } from '../utils/RawQueryFragment.js';
13
+ /** Symbol used to extract the EntityManager type from a driver instance. */
13
14
  export declare const EntityManagerType: unique symbol;
15
+ /** Interface defining the contract for all database drivers. */
14
16
  export interface IDatabaseDriver<C extends Connection = Connection> {
15
17
  [EntityManagerType]: EntityManager<this>;
16
18
  readonly config: Configuration;
19
+ /** Creates a new EntityManager instance for this driver. */
17
20
  createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
21
+ /** Opens a connection to the database. */
18
22
  connect(options?: {
19
23
  skipOnConnect?: boolean;
20
24
  }): Promise<C>;
25
+ /** Closes the database connection. */
21
26
  close(force?: boolean): Promise<void>;
27
+ /** Closes and re-establishes the database connection. */
22
28
  reconnect(options?: {
23
29
  skipOnConnect?: boolean;
24
30
  }): Promise<C>;
31
+ /** Returns the underlying database connection (write or read replica). */
25
32
  getConnection(type?: ConnectionType): C;
26
33
  /**
27
34
  * Finds selection of entities
@@ -31,29 +38,44 @@ export interface IDatabaseDriver<C extends Connection = Connection> {
31
38
  * Finds single entity (table row, document)
32
39
  */
33
40
  findOne<T extends object, P extends string = never, F extends string = '*', E extends string = never>(entityName: EntityName<T>, where: FilterQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>;
41
+ /** Finds entities backed by a virtual (expression-based) definition. */
34
42
  findVirtual<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
43
+ /** Returns an async iterator that streams query results one entity at a time. */
35
44
  stream<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: StreamOptions<T>): AsyncIterableIterator<T>;
45
+ /** Inserts a single row into the database. */
36
46
  nativeInsert<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
47
+ /** Inserts multiple rows into the database in a single batch operation. */
37
48
  nativeInsertMany<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>, transform?: (sql: string) => string): Promise<QueryResult<T>>;
49
+ /** Updates rows matching the given condition. */
38
50
  nativeUpdate<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
51
+ /** Updates multiple rows with different payloads in a single batch operation. */
39
52
  nativeUpdateMany<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
53
+ /** Deletes rows matching the given condition. */
40
54
  nativeDelete<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options?: NativeDeleteOptions<T>): Promise<QueryResult<T>>;
55
+ /** Persists changes to M:N collections (inserts/deletes pivot table rows). */
41
56
  syncCollections<T extends object, O extends object>(collections: Iterable<Collection<T, O>>, options?: DriverMethodOptions): Promise<void>;
57
+ /** Counts entities matching the given condition. */
42
58
  count<T extends object, P extends string = never>(entityName: EntityName<T>, where: FilterQuery<T>, options?: CountOptions<T, P>): Promise<number>;
59
+ /** Executes a MongoDB aggregation pipeline (MongoDB driver only). */
43
60
  aggregate(entityName: EntityName, pipeline: any[]): Promise<any[]>;
61
+ /** Maps raw database result to entity data, converting column names to property names. */
44
62
  mapResult<T extends object>(result: EntityDictionary<T>, meta: EntityMetadata<T>, populate?: PopulateOptions<T>[]): EntityData<T> | null;
45
63
  /**
46
64
  * When driver uses pivot tables for M:N, this method will load identifiers for given collections from them
47
65
  */
48
66
  loadFromPivotTable<T extends object, O extends object>(prop: EntityProperty, owners: Primary<O>[][], where?: FilterQuery<T>, orderBy?: OrderDefinition<T>, ctx?: Transaction, options?: FindOptions<T, any, any, any>, pivotJoin?: boolean): Promise<Dictionary<T[]>>;
67
+ /** Returns the database platform abstraction for this driver. */
49
68
  getPlatform(): Platform;
69
+ /** Sets the metadata storage used by this driver. */
50
70
  setMetadata(metadata: MetadataStorage): void;
71
+ /** Returns the metadata storage used by this driver. */
51
72
  getMetadata(): MetadataStorage;
52
73
  /**
53
74
  * Returns name of the underlying database dependencies (e.g. `mongodb` or `mysql2`)
54
75
  * for SQL drivers it also returns `knex` in the array as connectors are not used directly there
55
76
  */
56
77
  getDependencies(): string[];
78
+ /** Acquires a pessimistic lock on the given entity. */
57
79
  lockPessimistic<T extends object>(entity: T, options: LockOptions): Promise<void>;
58
80
  /**
59
81
  * Converts native db errors to standardized driver exceptions
@@ -71,13 +93,17 @@ export interface IDatabaseDriver<C extends Connection = Connection> {
71
93
  */
72
94
  getORMClass(): Constructor<MikroORM>;
73
95
  }
96
+ /** Represents a field selector for entity queries (property name or wildcard). */
74
97
  export type EntityField<T, P extends string = PopulatePath.ALL> = keyof T | PopulatePath.ALL | AutoPath<T, P, `${PopulatePath.ALL}`>;
98
+ /** Defines the ordering for query results, either a single order map or an array of them. */
75
99
  export type OrderDefinition<T> = (QueryOrderMap<T> & {
76
100
  0?: never;
77
101
  }) | QueryOrderMap<T>[];
102
+ /** Options for `em.findAll()`, extends FindOptions with an optional `where` clause. */
78
103
  export interface FindAllOptions<T, P extends string = never, F extends string = '*', E extends string = never> extends FindOptions<T, P, F, E> {
79
104
  where?: FilterQuery<T>;
80
105
  }
106
+ /** Options for streaming query results via `em.stream()`. */
81
107
  export interface StreamOptions<Entity, Populate extends string = never, Fields extends string = '*', Exclude extends string = never> extends Omit<FindAllOptions<Entity, Populate, Fields, Exclude>, 'cache' | 'before' | 'after' | 'first' | 'last' | 'overfetch' | 'strategy'> {
82
108
  /**
83
109
  * When populating to-many relations, the ORM streams fully merged entities instead of yielding every row.
@@ -90,12 +116,15 @@ export interface StreamOptions<Entity, Populate extends string = never, Fields e
90
116
  */
91
117
  mergeResults?: boolean;
92
118
  }
119
+ /** Configuration for enabling/disabling named filters on a query. */
93
120
  export type FilterOptions = Dictionary<boolean | Dictionary> | string[] | boolean;
121
+ /** Specifies which relations to populate and which fields to select or exclude. */
94
122
  export interface LoadHint<Entity, Hint extends string = never, Fields extends string = PopulatePath.ALL, Excludes extends string = never> {
95
123
  populate?: Populate<Entity, Hint>;
96
124
  fields?: readonly AutoPath<Entity, Fields, `${PopulatePath.ALL}`>[];
97
125
  exclude?: readonly AutoPath<Entity, Excludes>[];
98
126
  }
127
+ /** Options for `em.find()` queries, including population, ordering, pagination, and locking. */
99
128
  export interface FindOptions<Entity, Hint extends string = never, Fields extends string = PopulatePath.ALL, Excludes extends string = never> extends LoadHint<Entity, Hint, Fields, Excludes> {
100
129
  /**
101
130
  * Where condition for populated relations. This will have no effect on the root entity.
@@ -197,17 +226,21 @@ export interface FindOptions<Entity, Hint extends string = never, Fields extends
197
226
  /** @internal used to apply filters to the auto-joined relations */
198
227
  em?: EntityManager;
199
228
  }
229
+ /** Options for cursor-based pagination via `em.findByCursor()`. */
200
230
  export interface FindByCursorOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never, I extends boolean = true> extends Omit<FindAllOptions<T, P, F, E>, 'limit' | 'offset'> {
201
231
  includeCount?: I;
202
232
  }
233
+ /** Options for `em.findOne()`, extends FindOptions with optimistic lock version support. */
203
234
  export interface FindOneOptions<T, P extends string = never, F extends string = '*', E extends string = never> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'lockMode'> {
204
235
  lockMode?: LockMode;
205
236
  lockVersion?: number | Date;
206
237
  }
238
+ /** Options for `em.findOneOrFail()`, adds a custom error handler for missing entities. */
207
239
  export interface FindOneOrFailOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never> extends FindOneOptions<T, P, F, E> {
208
240
  failHandler?: (entityName: string, where: Dictionary | IPrimaryKey | any) => Error;
209
241
  strict?: boolean;
210
242
  }
243
+ /** Options for native insert and update operations. */
211
244
  export interface NativeInsertUpdateOptions<T> {
212
245
  convertCustomTypes?: boolean;
213
246
  ctx?: Transaction;
@@ -223,9 +256,11 @@ export interface NativeInsertUpdateOptions<T> {
223
256
  /** @internal */
224
257
  em?: EntityManager;
225
258
  }
259
+ /** Options for batch native insert and update operations. */
226
260
  export interface NativeInsertUpdateManyOptions<T> extends NativeInsertUpdateOptions<T> {
227
261
  processCollections?: boolean;
228
262
  }
263
+ /** Options for `em.upsert()`, controlling conflict resolution behavior. */
229
264
  export interface UpsertOptions<Entity, Fields extends string = never> extends Omit<NativeInsertUpdateOptions<Entity>, 'upsert'> {
230
265
  onConflictFields?: (keyof Entity)[] | Raw;
231
266
  onConflictAction?: 'ignore' | 'merge';
@@ -234,9 +269,11 @@ export interface UpsertOptions<Entity, Fields extends string = never> extends Om
234
269
  onConflictWhere?: FilterQuery<Entity>;
235
270
  disableIdentityMap?: boolean;
236
271
  }
272
+ /** Options for `em.upsertMany()`, adds batch size control. */
237
273
  export interface UpsertManyOptions<Entity, Fields extends string = never> extends UpsertOptions<Entity, Fields> {
238
274
  batchSize?: number;
239
275
  }
276
+ /** Options for `em.count()` queries. */
240
277
  export interface CountOptions<T extends object, P extends string = never> {
241
278
  filters?: FilterOptions;
242
279
  schema?: string;
@@ -268,6 +305,7 @@ export interface CountOptions<T extends object, P extends string = never> {
268
305
  /** @internal used to apply filters to the auto-joined relations */
269
306
  em?: EntityManager;
270
307
  }
308
+ /** Options for `em.qb().update()` operations. */
271
309
  export interface UpdateOptions<T> {
272
310
  filters?: FilterOptions;
273
311
  schema?: string;
@@ -277,6 +315,7 @@ export interface UpdateOptions<T> {
277
315
  /** sql only */
278
316
  unionWhereStrategy?: 'union-all' | 'union';
279
317
  }
318
+ /** Options for `em.qb().delete()` operations. */
280
319
  export interface DeleteOptions<T> extends DriverMethodOptions {
281
320
  filters?: FilterOptions;
282
321
  /** sql only */
@@ -286,6 +325,7 @@ export interface DeleteOptions<T> extends DriverMethodOptions {
286
325
  /** @internal */
287
326
  em?: EntityManager;
288
327
  }
328
+ /** Options for `em.nativeDelete()` operations. */
289
329
  export interface NativeDeleteOptions<T> extends DriverMethodOptions {
290
330
  filters?: FilterOptions;
291
331
  /** sql only */
@@ -295,17 +335,20 @@ export interface NativeDeleteOptions<T> extends DriverMethodOptions {
295
335
  /** @internal */
296
336
  em?: EntityManager;
297
337
  }
338
+ /** Options for pessimistic and optimistic lock operations. */
298
339
  export interface LockOptions extends DriverMethodOptions {
299
340
  lockMode?: LockMode;
300
341
  lockVersion?: number | Date;
301
342
  lockTableAliases?: string[];
302
343
  logging?: LoggingOptions;
303
344
  }
345
+ /** Base options shared by all driver methods (transaction context, schema, logging). */
304
346
  export interface DriverMethodOptions {
305
347
  ctx?: Transaction;
306
348
  schema?: string;
307
349
  loggerContext?: LogContext;
308
350
  }
351
+ /** MongoDB-style collation options for locale-aware string comparison. */
309
352
  export interface CollationOptions {
310
353
  locale: string;
311
354
  caseLevel?: boolean;
@@ -316,6 +359,7 @@ export interface CollationOptions {
316
359
  maxVariable?: string;
317
360
  backwards?: boolean;
318
361
  }
362
+ /** Options for `em.getReference()`, controlling wrapping and type conversion. */
319
363
  export interface GetReferenceOptions {
320
364
  wrapped?: boolean;
321
365
  convertCustomTypes?: boolean;
@@ -1 +1,2 @@
1
+ /** Symbol used to extract the EntityManager type from a driver instance. */
1
2
  export const EntityManagerType = Symbol('EntityManagerType');
@@ -5,10 +5,15 @@ import type { EntityLoaderOptions } from './EntityLoader.js';
5
5
  import { type SerializeOptions } from '../serialization/EntitySerializer.js';
6
6
  import type { FindOneOptions } from '../drivers/IDatabaseDriver.js';
7
7
  import type { PopulatePath } from '../enums.js';
8
+ /** Base class for entities providing convenience methods like `assign()`, `toObject()`, and `populate()`. */
8
9
  export declare abstract class BaseEntity {
10
+ /** Returns whether the entity has been fully loaded from the database. */
9
11
  isInitialized(): boolean;
12
+ /** Marks the entity as populated or not for serialization purposes. */
10
13
  populated(populated?: boolean): void;
14
+ /** Loads the specified relations on this entity. */
11
15
  populate<Entity extends this = this, Hint extends string = never, Fields extends string = never>(populate: AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity, Fields>): Promise<Loaded<Entity, Hint>>;
16
+ /** Returns a Reference wrapper for this entity. */
12
17
  toReference<Entity extends this = this>(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
13
18
  /**
14
19
  * Converts the entity to a plain object representation.
@@ -72,10 +77,16 @@ export declare abstract class BaseEntity {
72
77
  * @param ignoreFields - Array of field names to omit from the result.
73
78
  */
74
79
  toObject<Entity extends this = this, Ignored extends EntityKey<Entity> = never>(ignoreFields: Ignored[]): Omit<EntityDTO<Entity>, Ignored>;
80
+ /** Converts the entity to a plain object, including all properties regardless of serialization rules. */
75
81
  toPOJO<Entity extends this = this>(): EntityDTO<Entity>;
82
+ /** Serializes the entity with control over which relations and fields to include or exclude. */
76
83
  serialize<Entity extends this = this, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Naked, Hint, Exclude>): SerializeDTO<Naked, Hint, Exclude>;
84
+ /** Assigns the given data to this entity, updating its properties and relations. */
77
85
  assign<Entity extends this, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Convert extends boolean = false, Data extends EntityData<Naked, Convert> | Partial<EntityDTO<Naked>> = EntityData<Naked, Convert> | Partial<EntityDTO<Naked>>>(data: Data & IsSubset<EntityData<Naked>, Data>, options?: AssignOptions<Convert>): MergeSelected<Entity, Naked, keyof Data & string>;
86
+ /** Initializes (refreshes) the entity by reloading it from the database. Returns null if not found. */
78
87
  init<Entity extends this = this, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(options?: FindOneOptions<Entity, Hint, Fields, Excludes>): Promise<Loaded<Entity, Hint, Fields, Excludes> | null>;
88
+ /** Returns the database schema this entity belongs to. */
79
89
  getSchema(): string | undefined;
90
+ /** Sets the database schema for this entity. */
80
91
  setSchema(schema?: string): void;
81
92
  }