@mikro-orm/core 7.0.2-dev.13 → 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
package/typings.d.ts CHANGED
@@ -20,28 +20,47 @@ import type { EntityManager } from './EntityManager.js';
20
20
  import type { EventSubscriber } from './events/EventSubscriber.js';
21
21
  import type { FilterOptions, FindOneOptions, FindOptions, LoadHint } from './drivers/IDatabaseDriver.js';
22
22
  export type { Raw };
23
+ /** Generic constructor type. Matches any class that can be instantiated with `new`. */
23
24
  export type Constructor<T = unknown> = new (...args: any[]) => T;
25
+ /** Simple string-keyed object type. Use instead of `Record<string, T>` for convenience. */
24
26
  export type Dictionary<T = any> = {
25
27
  [k: string]: T;
26
28
  };
29
+ /** Record of compiled functions, used internally for hydration and comparison. */
27
30
  export type CompiledFunctions = Record<string, (...args: any[]) => any>;
31
+ /**
32
+ * Extracts string property keys from an entity, excluding symbols, functions, and internal keys.
33
+ * Pass `B = true` to also exclude scalar properties (useful for getting only relation keys).
34
+ */
28
35
  export type EntityKey<T = unknown, B extends boolean = false> = string & {
29
36
  [K in keyof T]-?: CleanKeys<T, K, B> extends never ? never : K;
30
37
  }[keyof T];
38
+ /** Resolves to the value type of entity properties (keyed by `EntityKey<T>`). */
31
39
  export type EntityValue<T> = T[EntityKey<T>];
40
+ /** Resolves to the value type within `EntityData<T>` (the data shape used for create/update). */
32
41
  export type EntityDataValue<T> = EntityData<T>[EntityKey<T>];
42
+ /** Extracts valid keys for `FilterQuery<T>`. */
33
43
  export type FilterKey<T> = keyof FilterQuery<T>;
44
+ /** A function type that accepts a dictionary argument and returns a Promise. */
34
45
  export type AsyncFunction<R = any, T = Dictionary> = (args: T) => Promise<T>;
46
+ /** Identity mapped type that forces TypeScript to eagerly evaluate and flatten `T`. */
35
47
  export type Compute<T> = {
36
48
  [K in keyof T]: T[K];
37
49
  } & {};
38
50
  type InternalKeys = 'EntityRepositoryType' | 'PrimaryKeyProp' | 'OptionalProps' | 'EagerProps' | 'HiddenProps' | '__selectedType' | '__loadedType';
51
+ /** Filters out function, symbol, and internal keys from an entity type. When `B = true`, also excludes scalar keys. */
39
52
  export type CleanKeys<T, K extends keyof T, B extends boolean = false> = T[K] & {} extends Function ? never : K extends symbol | InternalKeys ? never : B extends true ? T[K] & {} extends Scalar ? never : K : K;
53
+ /** Extracts keys of `T` whose values are functions. */
40
54
  export type FunctionKeys<T, K extends keyof T> = T[K] extends Function ? K : never;
55
+ /** Conditional cast: returns `T` if it extends `R`, otherwise returns `R`. */
41
56
  export type Cast<T, R> = T extends R ? T : R;
57
+ /** Evaluates to `true` if `T` is the `unknown` type. */
42
58
  export type IsUnknown<T> = T extends unknown ? (unknown extends T ? true : never) : never;
59
+ /** Evaluates to `true` if `T` is `any`. */
43
60
  export type IsAny<T> = 0 extends 1 & T ? true : false;
61
+ /** Evaluates to `True` if `T` is `never`, otherwise `False`. */
44
62
  export type IsNever<T, True = true, False = false> = [T] extends [never] ? True : False;
63
+ /** Represents a value that may be synchronous or wrapped in a Promise. */
45
64
  export type MaybePromise<T> = T | Promise<T>;
46
65
  /**
47
66
  * Structural type for matching Collection without triggering full interface evaluation.
@@ -95,25 +114,44 @@ type LoadedReferenceShape<T = any> = ReferenceShape & {
95
114
  * TypeScript from evaluating the full Collection/Reference interfaces.
96
115
  */
97
116
  type LoadableShape = CollectionShape | ReferenceShape | readonly any[];
117
+ /** Gets all keys from all members of a union type (distributes over the union). */
98
118
  export type UnionKeys<T> = T extends any ? keyof T : never;
119
+ /** Gets the type of a property from all union members that have it (distributes over the union). */
99
120
  export type UnionPropertyType<T, K extends PropertyKey> = T extends any ? (K extends keyof T ? T[K] : never) : never;
100
121
  type IsUnion<T, U = T> = T extends any ? ([U] extends [T] ? false : true) : false;
122
+ /**
123
+ * Merges all members of a union type into a single object with all their properties.
124
+ * For non-union types, returns `T` directly to avoid expensive key iteration.
125
+ */
101
126
  export type MergeUnion<T> = [T] extends [object] ? T extends Scalar ? T : IsUnion<T> extends true ? {
102
127
  [K in UnionKeys<T>]: UnionPropertyType<T, K>;
103
128
  } : T : T;
129
+ /** Recursively makes all properties of `T` optional, including nested objects and arrays. */
104
130
  export type DeepPartial<T> = T & {
105
131
  [P in keyof T]?: T[P] extends (infer U)[] ? DeepPartial<U>[] : T[P] extends Readonly<infer U>[] ? Readonly<DeepPartial<U>>[] : DeepPartial<T[P]>;
106
132
  };
133
+ /** Symbol used to declare a custom repository type on an entity class (e.g., `[EntityRepositoryType]?: BookRepository`). */
107
134
  export declare const EntityRepositoryType: unique symbol;
135
+ /** Symbol used to declare the primary key property name(s) on an entity (e.g., `[PrimaryKeyProp]?: 'id'`). */
108
136
  export declare const PrimaryKeyProp: unique symbol;
137
+ /** Symbol used to declare which properties are optional in `em.create()` (e.g., `[OptionalProps]?: 'createdAt'`). */
109
138
  export declare const OptionalProps: unique symbol;
139
+ /** Symbol used to declare which relation properties should be eagerly loaded (e.g., `[EagerProps]?: 'author'`). */
110
140
  export declare const EagerProps: unique symbol;
141
+ /** Symbol used to declare which properties are hidden from serialization (e.g., `[HiddenProps]?: 'password'`). */
111
142
  export declare const HiddenProps: unique symbol;
143
+ /** Symbol used to declare type-level configuration on an entity (e.g., `[Config]?: DefineConfig<{ forceObject: true }>`). */
112
144
  export declare const Config: unique symbol;
145
+ /** Symbol used to declare the entity name as a string literal type (used by `defineEntity`). */
113
146
  export declare const EntityName: unique symbol;
147
+ /** Extracts the entity name string literal from an entity type that declares `[EntityName]`. */
114
148
  export type InferEntityName<T> = T extends {
115
149
  [EntityName]?: infer Name;
116
150
  } ? (Name extends string ? Name : never) : never;
151
+ /**
152
+ * Branded type that marks a property as optional in `em.create()`.
153
+ * Use as a property type wrapper: `createdAt: Opt<Date>` instead of listing in `[OptionalProps]`.
154
+ */
117
155
  export type Opt<T = unknown> = T & Opt.Brand;
118
156
  export declare namespace Opt {
119
157
  const __optional: unique symbol;
@@ -121,6 +159,10 @@ export declare namespace Opt {
121
159
  [__optional]?: 1;
122
160
  }
123
161
  }
162
+ /**
163
+ * Branded type that marks a nullable property as required in `em.create()`.
164
+ * By default, nullable properties are treated as optional; this forces them to be explicitly provided.
165
+ */
124
166
  export type RequiredNullable<T = never> = (T & RequiredNullable.Brand) | null;
125
167
  export declare namespace RequiredNullable {
126
168
  const __requiredNullable: unique symbol;
@@ -128,6 +170,10 @@ export declare namespace RequiredNullable {
128
170
  [__requiredNullable]?: 1;
129
171
  }
130
172
  }
173
+ /**
174
+ * Branded type that marks a property as hidden from serialization.
175
+ * Use as a property type wrapper: `password: Hidden<string>` instead of listing in `[HiddenProps]`.
176
+ */
131
177
  export type Hidden<T = unknown> = T & Hidden.Brand;
132
178
  export declare namespace Hidden {
133
179
  const __hidden: unique symbol;
@@ -135,6 +181,10 @@ export declare namespace Hidden {
135
181
  [__hidden]?: 1;
136
182
  }
137
183
  }
184
+ /**
185
+ * Branded type for entity-level configuration (e.g., `[Config]?: DefineConfig<{ forceObject: true }>`).
186
+ * Controls type-level behavior such as forcing object representation for primary keys in DTOs.
187
+ */
138
188
  export type DefineConfig<T extends TypeConfig> = T & DefineConfig.Brand;
139
189
  export declare namespace DefineConfig {
140
190
  const __config: unique symbol;
@@ -142,7 +192,9 @@ export declare namespace DefineConfig {
142
192
  [__config]?: 1;
143
193
  }
144
194
  }
195
+ /** Extracts only the `TypeConfig` keys from a branded config type, stripping the brand. */
145
196
  export type CleanTypeConfig<T> = Compute<Pick<T, Extract<keyof T, keyof TypeConfig>>>;
197
+ /** Configuration options that can be set on an entity via the `[Config]` symbol. */
146
198
  export interface TypeConfig {
147
199
  forceObject?: boolean;
148
200
  }
@@ -156,11 +208,16 @@ declare const __loadHint: unique symbol;
156
208
  * Special case: '*' returns string to ensure Loaded<T, '*'> is assignable to any Loaded<T, Hint>.
157
209
  */
158
210
  export type Prefixes<S extends string> = S extends '*' ? string : S extends `${infer H}.${infer T}` ? H | `${H}.${Prefixes<T>}` : S;
211
+ /** Unwraps a value to its primary key type. Scalars pass through; References are unwrapped first. */
159
212
  export type UnwrapPrimary<T> = T extends Scalar ? T : T extends ReferenceShape<infer U> ? Primary<U> : Primary<T>;
160
213
  type PrimaryPropToType<T, Keys extends (keyof T)[]> = {
161
214
  [Index in keyof Keys]: UnwrapPrimary<T[Keys[Index]]>;
162
215
  };
163
216
  type ReadonlyPrimary<T> = T extends any[] ? Readonly<T> : T;
217
+ /**
218
+ * Resolves the primary key type for an entity. Uses `[PrimaryKeyProp]` if declared,
219
+ * otherwise falls back to `_id`, `id`, or `uuid` properties. For composite keys, returns a tuple.
220
+ */
164
221
  export type Primary<T> = IsAny<T> extends true ? any : T extends {
165
222
  [PrimaryKeyProp]?: infer PK;
166
223
  } ? PK extends undefined ? Omit<T, typeof PrimaryKeyProp> : PK extends keyof T ? ReadonlyPrimary<UnwrapPrimary<T[PK]>> : PK extends (keyof T)[] ? ReadonlyPrimary<PrimaryPropToType<T, PK>> : PK : T extends {
@@ -182,19 +239,24 @@ export type PrimaryProperty<T> = T extends {
182
239
  } ? 'id' : T extends {
183
240
  uuid?: any;
184
241
  } ? 'uuid' : never;
242
+ /** Union of all allowed primary key value types (number, string, bigint, Date, ObjectId-like). */
185
243
  export type IPrimaryKeyValue = number | string | bigint | Date | {
186
244
  toHexString(): string;
187
245
  };
246
+ /** Alias for a primary key value, constrained to `IPrimaryKeyValue`. */
188
247
  export type IPrimaryKey<T extends IPrimaryKeyValue = IPrimaryKeyValue> = T;
248
+ /** Union of types considered "scalar" (non-entity) values. Used to distinguish entity relations from plain values. */
189
249
  export type Scalar = boolean | number | string | bigint | symbol | Date | RegExp | Uint8Array | {
190
250
  toHexString(): string;
191
251
  };
192
252
  type Primitive = boolean | number | string | bigint | symbol;
253
+ /** Expands a scalar type to include alternative representations accepted in queries (e.g., `Date | string`). */
193
254
  export type ExpandScalar<T> = null | (T extends string ? T | RegExp : T extends Date ? Date | string : T extends bigint ? bigint | string | number : T);
194
255
  /** Marker interface for query builders that can be used as subqueries */
195
256
  export interface Subquery {
196
257
  readonly __subquery: true;
197
258
  }
259
+ /** Map of query operators (`$eq`, `$gt`, `$in`, etc.) available for filtering a value of type `T`. */
198
260
  export type OperatorMap<T> = {
199
261
  $and?: ExpandQuery<T>[];
200
262
  $or?: ExpandQuery<T>[];
@@ -230,7 +292,9 @@ export type OperatorMap<T> = {
230
292
  $hasKeys?: readonly string[];
231
293
  $hasSomeKeys?: readonly string[];
232
294
  };
295
+ /** A single filter value: the raw value, its expanded scalar form, its primary key, or a raw SQL expression. */
233
296
  export type FilterItemValue<T> = T | ExpandScalar<T> | Primary<T> | Raw;
297
+ /** A complete filter value: an operator map, a single value, an array of values, or null. */
234
298
  export type FilterValue<T> = OperatorMap<FilterItemValue<T>> | FilterItemValue<T> | FilterItemValue<T>[] | null;
235
299
  type FilterObjectProp<T, K extends PropertyKey> = K extends keyof MergeUnion<T> ? MergeUnion<T>[K] : K extends keyof T ? T[K] : never;
236
300
  type ExpandQueryMerged<T> = [T] extends [object] ? [T] extends [Scalar] ? never : FilterQuery<MergeUnion<T>> : FilterValue<T>;
@@ -244,15 +308,24 @@ type ElemMatchCondition<T extends Record<string, any>> = {
244
308
  type ElemMatchFilter<T> = T extends readonly (infer E)[] ? E extends Record<string, any> ? {
245
309
  $elemMatch: ElemMatchCondition<E>;
246
310
  } : never : never;
311
+ /** Object form of a filter query, mapping entity keys to their filter conditions. */
247
312
  export type FilterObject<T> = {
248
313
  -readonly [K in EntityKey<T>]?: ExpandQuery<ExpandProperty<FilterObjectProp<T, K>>> | ExpandQueryMerged<ExpandProperty<FilterObjectProp<T, K>>> | FilterValue<ExpandProperty<FilterObjectProp<T, K>>> | ElemMatchFilter<FilterObjectProp<T, K>> | null;
249
314
  };
315
+ /** Recursively expands a type into its `FilterQuery` form for nested object filtering. */
250
316
  export type ExpandQuery<T> = T extends object ? (T extends Scalar ? never : FilterQuery<T>) : FilterValue<T>;
317
+ /** Partial entity shape with all entity properties optional. */
251
318
  export type EntityProps<T> = {
252
319
  -readonly [K in EntityKey<T>]?: T[K];
253
320
  };
321
+ /** Object-based query filter combining operator maps with property-level filters. */
254
322
  export type ObjectQuery<T> = OperatorMap<T> & FilterObject<T>;
323
+ /**
324
+ * The main query filter type used in `em.find()`, `em.findOne()`, etc.
325
+ * Accepts an object query, a primary key value, entity props with operators, or an array of filters.
326
+ */
255
327
  export type FilterQuery<T> = ObjectQuery<T> | NonNullable<ExpandScalar<Primary<T>>> | NonNullable<EntityProps<T> & OperatorMap<T>> | FilterQuery<T>[];
328
+ /** Public interface for the entity wrapper, accessible via `wrap(entity)`. Provides helper methods for entity state management. */
256
329
  export interface IWrappedEntity<Entity extends object> {
257
330
  isInitialized(): boolean;
258
331
  isManaged(): boolean;
@@ -271,6 +344,7 @@ export interface IWrappedEntity<Entity extends object> {
271
344
  getSchema(): string | undefined;
272
345
  setSchema(schema?: string): void;
273
346
  }
347
+ /** @internal Extended wrapper interface with internal state used by the ORM runtime. */
274
348
  export interface IWrappedEntityInternal<Entity extends object> extends IWrappedEntity<Entity> {
275
349
  hasPrimaryKey(): boolean;
276
350
  getPrimaryKey(convertCustomTypes?: boolean): Primary<Entity> | null;
@@ -303,11 +377,15 @@ export interface IWrappedEntityInternal<Entity extends object> extends IWrappedE
303
377
  exclude?: string[];
304
378
  };
305
379
  }
380
+ /** Loose entity type used in generic contexts. Equivalent to `Partial<T>`. */
306
381
  export type AnyEntity<T = any> = Partial<T>;
382
+ /** A class (function with prototype) whose instances are of type `T`. */
307
383
  export type EntityClass<T = any> = Function & {
308
384
  prototype: T;
309
385
  };
386
+ /** Any valid entity name reference: a class, abstract constructor, or EntitySchema. */
310
387
  export type EntityName<T = any> = EntityClass<T> | EntityCtor<T> | EntitySchema<T, any>;
388
+ /** Resolves the custom repository type for an entity (from `[EntityRepositoryType]`), or falls back to `Fallback`. */
311
389
  export type GetRepository<Entity extends {
312
390
  [k: PropertyKey]: any;
313
391
  }, Fallback> = Entity[typeof EntityRepositoryType] extends EntityRepository<any> | undefined ? NonNullable<Entity[typeof EntityRepositoryType]> : Fallback;
@@ -318,6 +396,7 @@ type PolymorphicPrimaryInner<T> = T extends object ? Primary<T> extends readonly
318
396
  * For composite keys like [tenantId, orgId], becomes ['discriminator', tenantId, orgId]
319
397
  */
320
398
  export type PolymorphicPrimary<T> = true extends IsUnion<T> ? PolymorphicPrimaryInner<T> : never;
399
+ /** Allowed value types when assigning to an entity data property: the entity itself, its PK, or a polymorphic PK tuple. */
321
400
  export type EntityDataPropValue<T> = T | Primary<T> | PolymorphicPrimary<T>;
322
401
  type ExpandEntityProp<T, C extends boolean = false> = T extends Record<string, any> ? {
323
402
  [K in keyof T as CleanKeys<T, K>]?: EntityDataProp<ExpandProperty<T[K]>, C> | EntityDataPropValue<ExpandProperty<T[K]>> | null;
@@ -331,17 +410,21 @@ type ExpandRequiredEntityPropObject<T, I = never, C extends boolean = false> = {
331
410
  type NonArrayObject = object & {
332
411
  [Symbol.iterator]?: never;
333
412
  };
413
+ /** Resolves the allowed input type for a single entity property in `EntityData`. Handles scalars, references, collections, and nested entities. */
334
414
  export type EntityDataProp<T, C extends boolean> = T extends Date ? string | Date : T extends Scalar ? T : T extends ScalarReference<infer U> ? EntityDataProp<U, C> : T extends {
335
415
  __runtime?: infer Runtime;
336
416
  __raw?: infer Raw;
337
417
  } ? C extends true ? Raw : Runtime : T extends ReferenceShape<infer U> ? EntityDataNested<U, C> : T extends CollectionShape<infer U> ? U | U[] | EntityDataNested<U & object, C> | EntityDataNested<U & object, C>[] : T extends readonly (infer U)[] ? U extends NonArrayObject ? U | U[] | EntityDataNested<U, C> | EntityDataNested<U, C>[] : U[] | EntityDataNested<U, C>[] : EntityDataNested<T, C>;
418
+ /** Like `EntityDataProp` but used in `RequiredEntityData` context with required/optional key distinction. */
338
419
  export type RequiredEntityDataProp<T, O, C extends boolean> = T extends Date ? string | Date : Exclude<T, null> extends RequiredNullable.Brand ? T | null : T extends Scalar ? T : T extends ScalarReference<infer U> ? RequiredEntityDataProp<U, O, C> : T extends {
339
420
  __runtime?: infer Runtime;
340
421
  __raw?: infer Raw;
341
422
  } ? C extends true ? Raw : Runtime : T extends ReferenceShape<infer U> ? RequiredEntityDataNested<U, O, C> : T extends CollectionShape<infer U> ? U | U[] | RequiredEntityDataNested<U & object, O, C> | RequiredEntityDataNested<U & object, O, C>[] : T extends readonly (infer U)[] ? U extends NonArrayObject ? U | U[] | RequiredEntityDataNested<U, O, C> | RequiredEntityDataNested<U, O, C>[] : U[] | RequiredEntityDataNested<U, O, C>[] : RequiredEntityDataNested<T, O, C>;
423
+ /** Nested entity data shape for embedded or related entities within `EntityData`. */
342
424
  export type EntityDataNested<T, C extends boolean = false> = T extends undefined ? never : T extends any[] ? Readonly<T> : EntityData<T, C> | ExpandEntityProp<T, C>;
343
425
  type UnwrapScalarRef<T> = T extends ScalarReference<infer U> ? U : T;
344
426
  type EntityDataItem<T, C extends boolean> = C extends false ? UnwrapScalarRef<T> | EntityDataProp<T, C> | Raw | null : EntityDataProp<T, C> | Raw | null;
427
+ /** Nested entity data shape used within `RequiredEntityData` for embedded or related entities. */
345
428
  export type RequiredEntityDataNested<T, O, C extends boolean> = T extends any[] ? Readonly<T> : RequiredEntityData<T, O> | ExpandRequiredEntityProp<T, O, C>;
346
429
  type ExplicitlyOptionalProps<T> = (T extends {
347
430
  [OptionalProps]?: infer K;
@@ -358,14 +441,21 @@ type ProbablyOptionalProps<T> = PrimaryProperty<T> | ExplicitlyOptionalProps<T>
358
441
  type IsOptional<T, K extends keyof T, I> = T[K] extends CollectionShape ? true : ExtractType<T[K]> extends I ? true : K extends ProbablyOptionalProps<T> ? true : false;
359
442
  type RequiredKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? CleanKeys<T, K> : never;
360
443
  type OptionalKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? never : CleanKeys<T, K>;
444
+ /** Data shape for creating or updating entities. All properties are optional. Used in `em.create()` and `em.assign()`. */
361
445
  export type EntityData<T, C extends boolean = false> = {
362
446
  [K in EntityKey<T>]?: EntityDataItem<T[K] & {}, C>;
363
447
  };
448
+ /**
449
+ * Data shape for `em.create()` with required/optional distinction based on entity metadata.
450
+ * Properties with defaults, nullable types, `Opt` brand, or `[OptionalProps]` declaration are optional.
451
+ * `I` excludes additional types from being required (used for inverse side of relations).
452
+ */
364
453
  export type RequiredEntityData<T, I = never, C extends boolean = false> = {
365
454
  [K in keyof T as RequiredKeys<T, K, I>]: T[K] | RequiredEntityDataProp<T[K], T, C> | Primary<T[K]> | PolymorphicPrimary<T[K]> | Raw;
366
455
  } & {
367
456
  [K in keyof T as OptionalKeys<T, K, I>]?: T[K] | RequiredEntityDataProp<T[K], T, C> | Primary<T[K]> | PolymorphicPrimary<T[K]> | Raw | null;
368
457
  };
458
+ /** `EntityData<T>` extended with an index signature, allowing arbitrary additional properties. */
369
459
  export type EntityDictionary<T> = EntityData<T> & Record<any, any>;
370
460
  type ExtractEagerProps<T> = T extends {
371
461
  [EagerProps]?: infer PK;
@@ -400,6 +490,7 @@ type PrimaryOrObject<T, U, C extends TypeConfig> = PreferExplicitConfig<C, Extra
400
490
  [K in PrimaryProperty<U> & keyof U]: U[K];
401
491
  } : Primary<U>;
402
492
  type DTOWrapper<T, C extends TypeConfig, Flat extends boolean> = Flat extends true ? EntityDTOFlat<T, C> : EntityDTO<T, C>;
493
+ /** Resolves the serialized (DTO) type for a single entity property. Unwraps references, collections, and custom serialized types. */
403
494
  export type EntityDTOProp<E, T, C extends TypeConfig = never, Flat extends boolean = false> = T extends Scalar ? T : T extends ScalarReference<infer U> ? U : T extends {
404
495
  __serialized?: infer U;
405
496
  } ? IsUnknown<U> extends false ? U : T : T extends LoadedReferenceShape<infer U> ? DTOWrapper<U, C, Flat> : T extends ReferenceShape<infer U> ? PrimaryOrObject<E, U, C> : T extends LoadedCollectionShape<infer U> ? DTOWrapper<U & object, C, Flat>[] : T extends CollectionShape<infer U> ? PrimaryOrObject<E, U & object, C>[] : T extends readonly (infer U)[] ? U extends Scalar ? T : EntityDTOProp<E, U, C, Flat>[] : T extends Relation<T> ? DTOWrapper<T, C, Flat> : T;
@@ -410,6 +501,10 @@ type DTOProbablyOptionalProps<T> = NonNullable<NullableKeys<UnwrapLoadedEntity<T
410
501
  type DTOIsOptional<T, K extends keyof T> = T[K] extends LoadedCollectionShape ? false : K extends PrimaryProperty<UnwrapLoadedEntity<T>> ? false : K extends DTOProbablyOptionalProps<T> ? true : false;
411
502
  type DTORequiredKeys<T, K extends keyof T> = DTOIsOptional<T, K> extends false ? ExcludeHidden<T, K> & CleanKeys<T, K> : never;
412
503
  type DTOOptionalKeys<T, K extends keyof T> = DTOIsOptional<T, K> extends false ? never : ExcludeHidden<T, K> & CleanKeys<T, K>;
504
+ /**
505
+ * Plain object (DTO) representation of an entity as returned by `toObject()` / `toPOJO()`.
506
+ * Unwraps references to PKs, collections to arrays, and respects hidden properties.
507
+ */
413
508
  export type EntityDTO<T, C extends TypeConfig = never> = {
414
509
  [K in keyof T as DTORequiredKeys<T, K>]: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
415
510
  } & {
@@ -433,11 +528,16 @@ export type EntityDTOFlat<T, C extends TypeConfig = never> = {
433
528
  type SerializeTopHints<H extends string> = H extends `${infer Top}.${string}` ? Top : H;
434
529
  type SerializeSubHints<K extends string, H extends string> = H extends `${K}.${infer Rest}` ? Rest : never;
435
530
  type SerializePropValue<T, K extends keyof T, H extends string, C extends TypeConfig = never> = K & string extends SerializeTopHints<H> ? NonNullable<T[K]> extends CollectionShape<infer U> ? SerializeDTO<U & object, SerializeSubHints<K & string, H>, never, C>[] : SerializeDTO<ExpandProperty<T[K]>, SerializeSubHints<K & string, H>, never, C> | Extract<T[K], null | undefined> : EntityDTOProp<T, T[K], C>;
531
+ /**
532
+ * Return type of `serialize()`. Combines Loaded + EntityDTO in a single pass for better performance.
533
+ * Respects populate hints (`H`) and exclude hints (`E`).
534
+ */
436
535
  export type SerializeDTO<T, H extends string = never, E extends string = never, C extends TypeConfig = never> = string extends H ? EntityDTOFlat<T, C> : {
437
536
  [K in keyof T as ExcludeHidden<T, K> & CleanKeys<T, K> & (IsNever<E> extends true ? K : Exclude<K, E>)]: SerializePropValue<T, K, H, C> | Extract<T[K], null | undefined>;
438
537
  };
439
538
  type TargetKeys<T> = T extends EntityClass<infer P> ? keyof P : keyof T;
440
539
  type PropertyName<T> = IsUnknown<T> extends false ? TargetKeys<T> : string;
540
+ /** Table reference object passed to formula callbacks, including alias and schema information. */
441
541
  export type FormulaTable = {
442
542
  alias: string;
443
543
  name: string;
@@ -474,16 +574,23 @@ export type FormulaColumns<T> = Record<PropertyName<T>, string> & {
474
574
  * that belong to the current table (not inherited properties from parent tables).
475
575
  */
476
576
  export type SchemaColumns<T> = Record<PropertyName<T>, string>;
577
+ /** Callback for custom index expressions. Receives column mappings, table info, and the index name. */
477
578
  export type IndexCallback<T> = (columns: Record<PropertyName<T>, string>, table: SchemaTable, indexName: string) => string | Raw;
579
+ /** Callback for computed (formula) properties. Receives column mappings and table info, returns a SQL expression. */
478
580
  export type FormulaCallback<T> = (columns: FormulaColumns<T>, table: FormulaTable) => string | Raw;
581
+ /** Callback for CHECK constraint expressions. Receives column mappings and table info. */
479
582
  export type CheckCallback<T> = (columns: Record<PropertyName<T>, string>, table: SchemaTable) => string | Raw;
583
+ /** Callback for generated (computed) column expressions. Receives column mappings and table info. */
480
584
  export type GeneratedColumnCallback<T> = (columns: Record<PropertyName<T>, string>, table: SchemaTable) => string | Raw;
585
+ /** Definition of a CHECK constraint on a table or property. */
481
586
  export interface CheckConstraint<T = any> {
482
587
  name?: string;
483
588
  property?: string;
484
589
  expression: string | Raw | CheckCallback<T>;
485
590
  }
591
+ /** Branded string that accepts any string value while preserving autocompletion for known literals. */
486
592
  export type AnyString = string & {};
593
+ /** Describes a single property (column, relation, or embedded) within an entity's metadata. */
487
594
  export interface EntityProperty<Owner = any, Target = any> {
488
595
  name: EntityKey<Owner>;
489
596
  entity: () => EntityName<Owner>;
@@ -587,6 +694,10 @@ export interface EntityProperty<Owner = any, Target = any> {
587
694
  createForeignKeyConstraint: boolean;
588
695
  foreignKeyName?: string;
589
696
  }
697
+ /**
698
+ * Runtime metadata for an entity, holding its properties, relations, indexes, hooks, and more.
699
+ * Created during metadata discovery and used throughout the ORM lifecycle.
700
+ */
590
701
  export declare class EntityMetadata<Entity = any, Class extends EntityCtor<Entity> = EntityCtor<Entity>> {
591
702
  private static counter;
592
703
  readonly _id: number;
@@ -616,10 +727,12 @@ export declare class EntityMetadata<Entity = any, Class extends EntityCtor<Entit
616
727
  /** @internal */
617
728
  clone(): this;
618
729
  }
730
+ /** Minimal column metadata with just a name and database type. */
619
731
  export interface SimpleColumnMeta {
620
732
  name: string;
621
733
  type: string;
622
734
  }
735
+ /** Abstract constructor type that matches both abstract and concrete entity classes. */
623
736
  export type EntityCtor<T = any> = abstract new (...args: any[]) => T;
624
737
  export interface EntityMetadata<Entity = any, Class extends EntityCtor<Entity> = EntityCtor<Entity>> {
625
738
  name?: string;
@@ -737,20 +850,24 @@ export interface EntityMetadata<Entity = any, Class extends EntityCtor<Entity> =
737
850
  /** @internal can be used for computed numeric cache keys */
738
851
  readonly _id: number;
739
852
  }
853
+ /** Options for `ISchemaGenerator.create()`. */
740
854
  export interface CreateSchemaOptions {
741
855
  wrap?: boolean;
742
856
  schema?: string;
743
857
  }
858
+ /** Options for `ISchemaGenerator.clear()` to truncate/clear database tables. */
744
859
  export interface ClearDatabaseOptions {
745
860
  schema?: string;
746
861
  truncate?: boolean;
747
862
  clearIdentityMap?: boolean;
748
863
  }
864
+ /** Options for `ISchemaGenerator.ensureDatabase()` which creates and optionally clears the database. */
749
865
  export interface EnsureDatabaseOptions extends CreateSchemaOptions, ClearDatabaseOptions {
750
866
  clear?: boolean;
751
867
  create?: boolean;
752
868
  forceCheck?: boolean;
753
869
  }
870
+ /** Options for `ISchemaGenerator.drop()`. */
754
871
  export interface DropSchemaOptions {
755
872
  wrap?: boolean;
756
873
  dropMigrationsTable?: boolean;
@@ -758,6 +875,7 @@ export interface DropSchemaOptions {
758
875
  dropDb?: boolean;
759
876
  schema?: string;
760
877
  }
878
+ /** Options for `ISchemaGenerator.update()` to apply incremental schema changes. */
761
879
  export interface UpdateSchemaOptions<DatabaseSchema = unknown> {
762
880
  wrap?: boolean;
763
881
  safe?: boolean;
@@ -766,11 +884,13 @@ export interface UpdateSchemaOptions<DatabaseSchema = unknown> {
766
884
  schema?: string;
767
885
  fromSchema?: DatabaseSchema;
768
886
  }
887
+ /** Options for `ISchemaGenerator.refresh()` which drops and recreates the schema. */
769
888
  export interface RefreshDatabaseOptions extends CreateSchemaOptions {
770
889
  ensureIndexes?: boolean;
771
890
  dropDb?: boolean;
772
891
  createSchema?: boolean;
773
892
  }
893
+ /** Interface for the schema generator, responsible for creating, updating, and dropping database schemas. */
774
894
  export interface ISchemaGenerator {
775
895
  create(options?: CreateSchemaOptions): Promise<void>;
776
896
  update(options?: UpdateSchemaOptions): Promise<void>;
@@ -792,10 +912,12 @@ export interface ISchemaGenerator {
792
912
  dropDatabase(name?: string): Promise<void>;
793
913
  ensureIndexes(): Promise<void>;
794
914
  }
915
+ /** Custom resolver for import paths in the entity generator. Returns a path/name pair or undefined to use the default. */
795
916
  export type ImportsResolver = (alias: string, basePath: string, extension: '.js' | '', originFileName: string) => {
796
917
  path: string;
797
918
  name: string;
798
919
  } | undefined;
920
+ /** Options for the entity generator (`IEntityGenerator.generate()`). Controls output format, filtering, and style. */
799
921
  export interface GenerateOptions {
800
922
  path?: string;
801
923
  save?: boolean;
@@ -826,24 +948,29 @@ export interface GenerateOptions {
826
948
  onInitialMetadata?: MetadataProcessor;
827
949
  onProcessedMetadata?: MetadataProcessor;
828
950
  }
951
+ /** Interface for the entity generator, which reverse-engineers database schema into entity source files. */
829
952
  export interface IEntityGenerator {
830
953
  generate(options?: GenerateOptions): Promise<string[]>;
831
954
  }
955
+ /** Basic migration descriptor with a name and optional file path. */
832
956
  export type MigrationInfo = {
833
957
  name: string;
834
958
  path?: string;
835
959
  };
960
+ /** Options for controlling which migrations to run (range, specific list, or transaction). */
836
961
  export type MigrateOptions = {
837
962
  from?: string | number;
838
963
  to?: string | number;
839
964
  migrations?: string[];
840
965
  transaction?: Transaction;
841
966
  };
967
+ /** Result of creating a new migration file, including the generated code and schema diff. */
842
968
  export type MigrationResult = {
843
969
  fileName: string;
844
970
  code: string;
845
971
  diff: MigrationDiff;
846
972
  };
973
+ /** A row from the migrations tracking table, representing an executed migration. */
847
974
  export type MigrationRow = {
848
975
  id: number;
849
976
  name: string;
@@ -874,6 +1001,7 @@ export interface IMigratorStorage {
874
1001
  tableName: string;
875
1002
  };
876
1003
  }
1004
+ /** Interface for the migrator, responsible for creating and executing database migrations. */
877
1005
  export interface IMigrator {
878
1006
  /**
879
1007
  * Checks current schema for changes, generates new migration if there are any.
@@ -919,11 +1047,14 @@ export interface IMigrator {
919
1047
  */
920
1048
  getStorage(): IMigratorStorage;
921
1049
  }
1050
+ /** Events emitted by the migrator during migration execution. */
922
1051
  export type MigratorEvent = 'migrating' | 'migrated' | 'reverting' | 'reverted';
1052
+ /** The up and down SQL statements representing a schema diff for a migration. */
923
1053
  export interface MigrationDiff {
924
1054
  up: string[];
925
1055
  down: string[];
926
1056
  }
1057
+ /** Interface for generating migration file contents from schema diffs. */
927
1058
  export interface IMigrationGenerator {
928
1059
  /**
929
1060
  * Generates the full contents of migration file. Uses `generateMigrationFile` to get the file contents.
@@ -938,6 +1069,7 @@ export interface IMigrationGenerator {
938
1069
  */
939
1070
  generateMigrationFile(className: string, diff: MigrationDiff): MaybePromise<string>;
940
1071
  }
1072
+ /** Interface that all migration classes must implement. */
941
1073
  export interface Migration {
942
1074
  up(): Promise<void> | void;
943
1075
  down(): Promise<void> | void;
@@ -946,6 +1078,7 @@ export interface Migration {
946
1078
  setTransactionContext(ctx: Transaction): void;
947
1079
  getQueries?(): any[];
948
1080
  }
1081
+ /** A named migration class reference, used for inline migration registration. */
949
1082
  export interface MigrationObject {
950
1083
  name: string;
951
1084
  class: Constructor<Migration>;
@@ -959,10 +1092,13 @@ type FilterDefResolved<T extends object = any> = {
959
1092
  args?: boolean;
960
1093
  strict?: boolean;
961
1094
  };
1095
+ /** Definition of a query filter that can be registered globally or per-entity via `@Filter()`. */
962
1096
  export type FilterDef<T extends EntityName | readonly EntityName[] = any> = FilterDefResolved<EntityFromInput<T>> & {
963
1097
  entity?: T;
964
1098
  };
1099
+ /** Type for the `populate` option in find methods. An array of relation paths to eagerly load, or `false` to disable. */
965
1100
  export type Populate<T, P extends string = never> = readonly AutoPath<T, P, `${PopulatePath}`>[] | false;
1101
+ /** Parsed populate hint for a single relation, including strategy and nested children. */
966
1102
  export type PopulateOptions<T> = {
967
1103
  field: EntityKey<T>;
968
1104
  strategy?: LoadStrategy;
@@ -973,6 +1109,7 @@ export type PopulateOptions<T> = {
973
1109
  /** When true, ignores `mapToPk` on the property and returns full entity data instead of just PKs. */
974
1110
  dataOnly?: boolean;
975
1111
  };
1112
+ /** Inline options that can be appended to populate hint strings (e.g., strategy, join type). */
976
1113
  export type PopulateHintOptions = {
977
1114
  strategy?: LoadStrategy.JOINED | LoadStrategy.SELECT_IN | 'joined' | 'select-in';
978
1115
  joinType?: 'inner join' | 'left join';
@@ -991,17 +1128,26 @@ type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
991
1128
  type RelationKeys<T> = T extends object ? {
992
1129
  [K in keyof T]-?: CleanKeys<T, K, true>;
993
1130
  }[keyof T] & {} : never;
1131
+ /**
1132
+ * Autocomplete-friendly type for dot-separated relation paths (e.g., `'author.books'`).
1133
+ * Validates each segment against entity keys and provides IDE suggestions. Depth-limited to prevent infinite recursion.
1134
+ */
994
1135
  export type AutoPath<O, P extends string | boolean, E extends string = never, D extends Prev[number] = 9> = P extends boolean ? P : [D] extends [never] ? never : P extends any ? P extends string ? P extends `${infer A}.${infer B}` ? A extends StringKeys<O, E> ? `${A}.${AutoPath<NonNullable<GetStringKey<O, A, E>>, B, E, Prev[D]>}` : never : P extends StringKeys<O, E> ? (NonNullable<GetStringKey<O, P & StringKeys<O, E>, E>> extends unknown ? Exclude<P, `${string}.`> : never) | (StringKeys<NonNullable<GetStringKey<O, P & StringKeys<O, E>, E>>, E> extends never ? never : `${P & string}.`) : StringKeys<O, E> | `${RelationKeys<O>}:ref` : never : never;
1136
+ /** Unwraps an array type to its element type; non-arrays pass through unchanged. */
995
1137
  export type UnboxArray<T> = T extends any[] ? ArrayElement<T> : T;
1138
+ /** Extracts the element type from an array type. */
996
1139
  export type ArrayElement<ArrayType extends unknown[]> = ArrayType extends (infer ElementType)[] ? ElementType : never;
1140
+ /** Unwraps a property type from its wrapper (Reference, Collection, or array) to the inner entity type. */
997
1141
  export type ExpandProperty<T> = T extends ReferenceShape<infer U> ? NonNullable<U> : T extends CollectionShape<infer U> ? NonNullable<U> : T extends (infer U)[] ? NonNullable<U> : NonNullable<T>;
998
1142
  type LoadedLoadable<T, E extends object> = T extends CollectionShape ? LoadedCollection<E> : T extends ScalarReference<infer U> ? LoadedScalarReference<U> : T extends ReferenceShape ? T & LoadedReference<E> : T extends Scalar ? T : T extends (infer U)[] ? U extends Scalar ? T : E[] : E;
999
1143
  type IsTrue<T> = IsNever<T> extends true ? false : T extends boolean ? (T extends true ? true : false) : false;
1000
1144
  type StringLiteral<T> = T extends string ? (string extends T ? never : T) : never;
1001
1145
  type Prefix<T, K> = K extends `${infer S}.${string}` ? S : K extends '*' ? keyof T : K;
1002
1146
  type IsPrefixedExclude<T, K extends keyof T, E extends string> = K extends E ? never : K;
1147
+ /** Checks whether a key `K` is included in the populate/fields hints. Used to filter entity keys in `Loaded`/`Selected`. */
1003
1148
  export type IsPrefixed<T, K extends keyof T, L extends string, E extends string = never> = IsNever<E> extends false ? IsPrefixedExclude<T, K, E> : K extends symbol ? never : IsTrue<L> extends true ? T[K] & {} extends LoadableShape ? K : never : IsNever<StringLiteral<L>> extends true ? never : '*' extends L ? K : K extends Prefix<T, L> ? K : K extends PrimaryProperty<T> ? K : never;
1004
1149
  type Suffix<Key, Hint extends string, All = true | '*'> = Hint extends `${infer Pref}.${infer Suf}` ? Pref extends Key ? Suf : never : Hint extends All ? Hint : never;
1150
+ /** Validates that `U` is a subset of `T`. Returns `{}` if valid, or a mapped type with `never` values to cause a type error. */
1005
1151
  export type IsSubset<T, U> = keyof U extends keyof T ? {} : string extends keyof U ? {} : {
1006
1152
  [K in keyof U as K extends keyof T ? never : CleanKeys<U, K>]: never;
1007
1153
  };
@@ -1025,10 +1171,17 @@ export type MergeSelected<T, U, F extends string> = IsLoadedType<T> extends true
1025
1171
  * Used for `em.populate` and `em.refresh`.
1026
1172
  */
1027
1173
  export type MergeLoaded<T, U, P extends string, F extends string, E extends string, R extends boolean = false> = IsLoadedType<T> extends true ? T & Loaded<U, P, F, E> : Loaded<T, P, F, E>;
1174
+ /** Extracts the nullability modifiers (`null`, `undefined`, or both) from a type `T`. */
1028
1175
  export type AddOptional<T> = undefined | null extends T ? null | undefined : null extends T ? null : undefined extends T ? undefined : never;
1029
1176
  type LoadedProp<T, L extends string = never, F extends string = '*', E extends string = never> = LoadedLoadable<T, Loaded<ExtractType<T>, L, F, E>>;
1177
+ /** Extracts the eager-loaded property names declared via `[EagerProps]` as a string union. */
1030
1178
  export type AddEager<T> = ExtractEagerProps<T> & string;
1179
+ /** Combines an explicit populate hint `L` with the entity's eagerly loaded properties. */
1031
1180
  export type ExpandHint<T, L extends string> = L | AddEager<T>;
1181
+ /**
1182
+ * Entity type narrowed to only the selected fields (`F`) and populated relations (`L`).
1183
+ * Used as the return type when `fields` option is specified in find methods.
1184
+ */
1032
1185
  export type Selected<T, L extends string = never, F extends string = '*'> = {
1033
1186
  [K in keyof T as IsPrefixed<T, K, L | F | AddEager<T>> | FunctionKeys<T, K>]: T[K] extends Function ? T[K] : NonNullable<T[K]> extends Scalar ? T[K] : LoadedProp<NonNullable<T[K]>, Suffix<K, L, true>, Suffix<K, F, true>> | AddOptional<T[K]>;
1034
1187
  } & {
@@ -1039,7 +1192,9 @@ type LoadedEntityType<T> = {
1039
1192
  } | {
1040
1193
  [__selectedType]?: T;
1041
1194
  };
1195
+ /** Accepts either a plain entity type or a `Loaded`/`Selected` wrapped version. */
1042
1196
  export type EntityType<T> = T | LoadedEntityType<T>;
1197
+ /** Extracts the base entity type from a `Loaded`/`Selected` wrapper, or returns `T` as-is. */
1043
1198
  export type FromEntityType<T> = T extends LoadedEntityType<infer U> ? U : T;
1044
1199
  type LoadedInternal<T, L extends string = never, F extends string = '*', E extends string = never> = [F] extends ['*'] ? IsNever<E> extends true ? T & {
1045
1200
  [K in keyof T as IsPrefixed<T, K, ExpandHint<T, L>>]: LoadedProp<NonNullable<T[K]>, Suffix<K, L>, Suffix<K, F>, Suffix<K, E>> | AddOptional<T[K]>;
@@ -1054,23 +1209,29 @@ export type Loaded<T, L extends string = never, F extends string = '*', E extend
1054
1209
  [__loadedType]?: T;
1055
1210
  [__loadHint]?: (hint: Prefixes<L>) => void;
1056
1211
  };
1212
+ /** A `Reference<T>` that is guaranteed to be loaded, providing synchronous access via `$` and `get()`. */
1057
1213
  export interface LoadedReference<T> extends Reference<NonNullable<T>> {
1058
1214
  $: NonNullable<T>;
1059
1215
  get(): NonNullable<T>;
1060
1216
  }
1217
+ /** A `ScalarReference<T>` that is guaranteed to be loaded, providing synchronous access via `$` and `get()`. */
1061
1218
  export interface LoadedScalarReference<T> extends ScalarReference<T> {
1062
1219
  $: T;
1063
1220
  get(): T;
1064
1221
  }
1222
+ /** A `Collection<T>` that is guaranteed to be loaded, providing synchronous access via `$`, `get()`, and `getItems()`. */
1065
1223
  export interface LoadedCollection<T extends object> extends Collection<T> {
1066
1224
  $: Collection<T>;
1067
1225
  get(): Collection<T>;
1068
1226
  getItems(check?: boolean): T[];
1069
1227
  }
1228
+ /** Alias for `Loaded<T, P>`. Represents a newly created entity with all specified relations populated. */
1070
1229
  export type New<T, P extends string = string> = Loaded<T, P>;
1230
+ /** Interface for SQL/code syntax highlighters used in logging output. */
1071
1231
  export interface Highlighter {
1072
1232
  highlight(text: string): string;
1073
1233
  }
1234
+ /** Interface for the metadata storage, which holds `EntityMetadata` for all discovered entities. */
1074
1235
  export interface IMetadataStorage {
1075
1236
  getAll(): Map<EntityName, EntityMetadata>;
1076
1237
  get<T = any>(entity: EntityName<T>, init?: boolean, validate?: boolean): EntityMetadata<T>;
@@ -1079,6 +1240,7 @@ export interface IMetadataStorage {
1079
1240
  set<T>(entity: EntityName<T>, meta: EntityMetadata): EntityMetadata;
1080
1241
  reset<T>(entity: EntityName<T>): void;
1081
1242
  }
1243
+ /** Interface for entity hydrators, which populate entity instances from raw database data. */
1082
1244
  export interface IHydrator {
1083
1245
  /**
1084
1246
  * Hydrates the whole entity. This process handles custom type conversions, creating missing Collection instances,
@@ -1091,25 +1253,36 @@ export interface IHydrator {
1091
1253
  hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void;
1092
1254
  isRunning(): boolean;
1093
1255
  }
1256
+ /** Constructor signature for hydrator implementations. */
1094
1257
  export interface HydratorConstructor {
1095
1258
  new (metadata: MetadataStorage, platform: Platform, config: Configuration): IHydrator;
1096
1259
  }
1260
+ /** Interface for the seed manager, which runs database seeders. */
1097
1261
  export interface ISeedManager {
1098
1262
  seed(...classNames: Constructor<Seeder>[]): Promise<void>;
1099
1263
  /** @internal */
1100
1264
  seedString(...classNames: string[]): Promise<void>;
1101
1265
  create(className: string): Promise<string>;
1102
1266
  }
1267
+ /** Interface that all seeder classes must implement. The `run` method receives an EntityManager. */
1103
1268
  export interface Seeder<T extends Dictionary = Dictionary> {
1104
1269
  run(em: EntityManager, context?: T): void | Promise<void>;
1105
1270
  }
1271
+ /** A named seeder class reference, used for inline seeder registration. */
1106
1272
  export interface SeederObject {
1107
1273
  name: string;
1108
1274
  class: Constructor<Seeder>;
1109
1275
  }
1276
+ /** Discriminator for read vs write database connections in read-replica setups. */
1110
1277
  export type ConnectionType = 'read' | 'write';
1278
+ /** Callback for processing entity metadata during discovery or entity generation. */
1111
1279
  export type MetadataProcessor = (metadata: EntityMetadata[], platform: Platform) => MaybePromise<void>;
1280
+ /** Extracts the return type if `T` is a function, otherwise returns `T` as-is. */
1112
1281
  export type MaybeReturnType<T> = T extends (...args: any[]) => infer R ? R : T;
1282
+ /**
1283
+ * Extended `EntitySchema` interface that carries additional type-level metadata (entity name, properties, table name).
1284
+ * Returned by `defineEntity()` to provide strong type inference without explicit generics.
1285
+ */
1113
1286
  export interface EntitySchemaWithMeta<TName extends string = string, TTableName extends string = string, TEntity = any, TBase = never, TProperties extends Record<string, any> = Record<string, any>, TClass extends EntityCtor = EntityCtor<TEntity>> extends EntitySchema<TEntity, TBase, TClass> {
1114
1287
  readonly name: TName;
1115
1288
  readonly properties: TProperties;
@@ -1117,6 +1290,10 @@ export interface EntitySchemaWithMeta<TName extends string = string, TTableName
1117
1290
  /** @internal Direct entity type access - avoids expensive pattern matching */
1118
1291
  readonly '~entity': TEntity;
1119
1292
  }
1293
+ /**
1294
+ * Extracts the entity type from an `EntitySchema`, `EntitySchemaWithMeta`, or entity class.
1295
+ * Uses a fast-path direct property access when available, falling back to generic inference.
1296
+ */
1120
1297
  export type InferEntity<Schema> = Schema extends {
1121
1298
  '~entity': infer E;
1122
1299
  } ? E : Schema extends EntitySchema<infer Entity> ? Entity : Schema extends EntityClass<infer Entity> ? Entity : Schema;