@mikro-orm/core 7.0.2-dev.8 → 7.0.2

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 (207) hide show
  1. package/EntityManager.d.ts +883 -579
  2. package/EntityManager.js +1897 -1865
  3. package/MikroORM.d.ts +103 -72
  4. package/MikroORM.js +178 -177
  5. package/README.md +128 -294
  6. package/cache/CacheAdapter.d.ts +38 -36
  7. package/cache/FileCacheAdapter.d.ts +30 -24
  8. package/cache/FileCacheAdapter.js +80 -78
  9. package/cache/GeneratedCacheAdapter.d.ts +19 -20
  10. package/cache/GeneratedCacheAdapter.js +31 -30
  11. package/cache/MemoryCacheAdapter.d.ts +19 -20
  12. package/cache/MemoryCacheAdapter.js +36 -36
  13. package/cache/NullCacheAdapter.d.ts +17 -16
  14. package/cache/NullCacheAdapter.js +25 -24
  15. package/connections/Connection.d.ts +99 -75
  16. package/connections/Connection.js +166 -160
  17. package/drivers/DatabaseDriver.d.ts +187 -69
  18. package/drivers/DatabaseDriver.js +451 -432
  19. package/drivers/IDatabaseDriver.d.ts +464 -281
  20. package/drivers/IDatabaseDriver.js +1 -0
  21. package/entity/BaseEntity.d.ts +121 -73
  22. package/entity/BaseEntity.js +44 -33
  23. package/entity/Collection.d.ts +216 -157
  24. package/entity/Collection.js +728 -707
  25. package/entity/EntityAssigner.d.ts +90 -76
  26. package/entity/EntityAssigner.js +232 -229
  27. package/entity/EntityFactory.d.ts +68 -40
  28. package/entity/EntityFactory.js +427 -366
  29. package/entity/EntityHelper.d.ts +34 -22
  30. package/entity/EntityHelper.js +280 -267
  31. package/entity/EntityIdentifier.d.ts +4 -4
  32. package/entity/EntityIdentifier.js +10 -10
  33. package/entity/EntityLoader.d.ts +105 -56
  34. package/entity/EntityLoader.js +754 -722
  35. package/entity/EntityRepository.d.ts +317 -200
  36. package/entity/EntityRepository.js +214 -212
  37. package/entity/PolymorphicRef.d.ts +5 -5
  38. package/entity/PolymorphicRef.js +10 -10
  39. package/entity/Reference.d.ts +130 -66
  40. package/entity/Reference.js +280 -260
  41. package/entity/WrappedEntity.d.ts +116 -53
  42. package/entity/WrappedEntity.js +169 -147
  43. package/entity/defineEntity.d.ts +1290 -614
  44. package/entity/defineEntity.js +521 -511
  45. package/entity/utils.d.ts +13 -3
  46. package/entity/utils.js +71 -73
  47. package/entity/validators.js +43 -43
  48. package/entity/wrap.js +8 -8
  49. package/enums.d.ts +275 -138
  50. package/enums.js +268 -137
  51. package/errors.d.ts +120 -72
  52. package/errors.js +356 -253
  53. package/events/EventManager.d.ts +27 -10
  54. package/events/EventManager.js +80 -73
  55. package/events/EventSubscriber.d.ts +33 -29
  56. package/events/TransactionEventBroadcaster.d.ts +16 -7
  57. package/events/TransactionEventBroadcaster.js +15 -13
  58. package/exceptions.d.ts +23 -40
  59. package/exceptions.js +35 -52
  60. package/hydration/Hydrator.d.ts +43 -16
  61. package/hydration/Hydrator.js +44 -42
  62. package/hydration/ObjectHydrator.d.ts +51 -17
  63. package/hydration/ObjectHydrator.js +480 -416
  64. package/index.d.ts +116 -2
  65. package/index.js +10 -1
  66. package/logging/DefaultLogger.d.ts +35 -30
  67. package/logging/DefaultLogger.js +87 -84
  68. package/logging/Logger.d.ts +45 -40
  69. package/logging/SimpleLogger.d.ts +13 -11
  70. package/logging/SimpleLogger.js +22 -22
  71. package/logging/colors.d.ts +6 -6
  72. package/logging/colors.js +11 -10
  73. package/logging/inspect.js +7 -7
  74. package/metadata/EntitySchema.d.ts +214 -108
  75. package/metadata/EntitySchema.js +398 -379
  76. package/metadata/MetadataDiscovery.d.ts +115 -111
  77. package/metadata/MetadataDiscovery.js +1948 -1857
  78. package/metadata/MetadataProvider.d.ts +25 -14
  79. package/metadata/MetadataProvider.js +83 -77
  80. package/metadata/MetadataStorage.d.ts +39 -19
  81. package/metadata/MetadataStorage.js +119 -106
  82. package/metadata/MetadataValidator.d.ts +39 -39
  83. package/metadata/MetadataValidator.js +381 -338
  84. package/metadata/discover-entities.d.ts +5 -2
  85. package/metadata/discover-entities.js +27 -27
  86. package/metadata/types.d.ts +615 -531
  87. package/naming-strategy/AbstractNamingStrategy.d.ts +55 -39
  88. package/naming-strategy/AbstractNamingStrategy.js +91 -85
  89. package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
  90. package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
  91. package/naming-strategy/MongoNamingStrategy.d.ts +7 -6
  92. package/naming-strategy/MongoNamingStrategy.js +19 -18
  93. package/naming-strategy/NamingStrategy.d.ts +109 -99
  94. package/naming-strategy/UnderscoreNamingStrategy.d.ts +8 -7
  95. package/naming-strategy/UnderscoreNamingStrategy.js +22 -21
  96. package/not-supported.js +7 -4
  97. package/package.json +1 -1
  98. package/platforms/ExceptionConverter.d.ts +2 -1
  99. package/platforms/ExceptionConverter.js +5 -4
  100. package/platforms/Platform.d.ts +310 -236
  101. package/platforms/Platform.js +661 -573
  102. package/serialization/EntitySerializer.d.ts +49 -25
  103. package/serialization/EntitySerializer.js +224 -216
  104. package/serialization/EntityTransformer.d.ts +11 -5
  105. package/serialization/EntityTransformer.js +220 -216
  106. package/serialization/SerializationContext.d.ts +27 -18
  107. package/serialization/SerializationContext.js +105 -100
  108. package/types/ArrayType.d.ts +9 -8
  109. package/types/ArrayType.js +34 -33
  110. package/types/BigIntType.d.ts +17 -10
  111. package/types/BigIntType.js +37 -37
  112. package/types/BlobType.d.ts +4 -3
  113. package/types/BlobType.js +14 -13
  114. package/types/BooleanType.d.ts +5 -4
  115. package/types/BooleanType.js +13 -12
  116. package/types/CharacterType.d.ts +3 -2
  117. package/types/CharacterType.js +7 -6
  118. package/types/DateTimeType.d.ts +6 -5
  119. package/types/DateTimeType.js +16 -15
  120. package/types/DateType.d.ts +6 -5
  121. package/types/DateType.js +16 -15
  122. package/types/DecimalType.d.ts +7 -7
  123. package/types/DecimalType.js +26 -26
  124. package/types/DoubleType.d.ts +3 -3
  125. package/types/DoubleType.js +12 -12
  126. package/types/EnumArrayType.d.ts +6 -5
  127. package/types/EnumArrayType.js +25 -24
  128. package/types/EnumType.d.ts +4 -3
  129. package/types/EnumType.js +12 -11
  130. package/types/FloatType.d.ts +4 -3
  131. package/types/FloatType.js +10 -9
  132. package/types/IntegerType.d.ts +4 -3
  133. package/types/IntegerType.js +10 -9
  134. package/types/IntervalType.d.ts +5 -4
  135. package/types/IntervalType.js +13 -12
  136. package/types/JsonType.d.ts +9 -8
  137. package/types/JsonType.js +33 -32
  138. package/types/MediumIntType.d.ts +2 -1
  139. package/types/MediumIntType.js +4 -3
  140. package/types/SmallIntType.d.ts +4 -3
  141. package/types/SmallIntType.js +10 -9
  142. package/types/StringType.d.ts +5 -4
  143. package/types/StringType.js +13 -12
  144. package/types/TextType.d.ts +4 -3
  145. package/types/TextType.js +10 -9
  146. package/types/TimeType.d.ts +6 -5
  147. package/types/TimeType.js +18 -17
  148. package/types/TinyIntType.d.ts +4 -3
  149. package/types/TinyIntType.js +11 -10
  150. package/types/Type.d.ts +88 -73
  151. package/types/Type.js +85 -74
  152. package/types/Uint8ArrayType.d.ts +5 -4
  153. package/types/Uint8ArrayType.js +22 -21
  154. package/types/UnknownType.d.ts +5 -4
  155. package/types/UnknownType.js +13 -12
  156. package/types/UuidType.d.ts +6 -5
  157. package/types/UuidType.js +20 -19
  158. package/types/index.d.ts +77 -49
  159. package/types/index.js +64 -26
  160. package/typings.d.ts +1388 -729
  161. package/typings.js +255 -231
  162. package/unit-of-work/ChangeSet.d.ts +28 -24
  163. package/unit-of-work/ChangeSet.js +58 -54
  164. package/unit-of-work/ChangeSetComputer.d.ts +13 -11
  165. package/unit-of-work/ChangeSetComputer.js +180 -159
  166. package/unit-of-work/ChangeSetPersister.d.ts +64 -41
  167. package/unit-of-work/ChangeSetPersister.js +443 -418
  168. package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
  169. package/unit-of-work/CommitOrderCalculator.js +89 -88
  170. package/unit-of-work/IdentityMap.d.ts +32 -25
  171. package/unit-of-work/IdentityMap.js +106 -99
  172. package/unit-of-work/UnitOfWork.d.ts +182 -127
  173. package/unit-of-work/UnitOfWork.js +1201 -1169
  174. package/utils/AbstractMigrator.d.ts +111 -91
  175. package/utils/AbstractMigrator.js +275 -275
  176. package/utils/AbstractSchemaGenerator.d.ts +43 -34
  177. package/utils/AbstractSchemaGenerator.js +121 -122
  178. package/utils/AsyncContext.d.ts +3 -3
  179. package/utils/AsyncContext.js +34 -35
  180. package/utils/Configuration.d.ts +853 -801
  181. package/utils/Configuration.js +360 -337
  182. package/utils/Cursor.d.ts +40 -22
  183. package/utils/Cursor.js +135 -127
  184. package/utils/DataloaderUtils.d.ts +58 -43
  185. package/utils/DataloaderUtils.js +203 -198
  186. package/utils/EntityComparator.d.ts +99 -80
  187. package/utils/EntityComparator.js +825 -727
  188. package/utils/NullHighlighter.d.ts +2 -1
  189. package/utils/NullHighlighter.js +4 -3
  190. package/utils/QueryHelper.d.ts +79 -51
  191. package/utils/QueryHelper.js +372 -361
  192. package/utils/RawQueryFragment.d.ts +54 -28
  193. package/utils/RawQueryFragment.js +110 -99
  194. package/utils/RequestContext.d.ts +33 -32
  195. package/utils/RequestContext.js +52 -53
  196. package/utils/TransactionContext.d.ts +17 -16
  197. package/utils/TransactionContext.js +28 -27
  198. package/utils/TransactionManager.d.ts +58 -58
  199. package/utils/TransactionManager.js +199 -197
  200. package/utils/Utils.d.ts +210 -145
  201. package/utils/Utils.js +820 -813
  202. package/utils/clone.js +104 -113
  203. package/utils/env-vars.js +90 -88
  204. package/utils/fs-utils.d.ts +15 -15
  205. package/utils/fs-utils.js +180 -181
  206. package/utils/upsert-utils.d.ts +20 -5
  207. package/utils/upsert-utils.js +114 -116
package/typings.d.ts CHANGED
@@ -1,5 +1,14 @@
1
1
  import type { Transaction } from './connections/Connection.js';
2
- import { type Cascade, type DeferMode, type EmbeddedPrefixMode, type EventType, type LoadStrategy, type PopulatePath, type QueryOrderMap, ReferenceKind } from './enums.js';
2
+ import {
3
+ type Cascade,
4
+ type DeferMode,
5
+ type EmbeddedPrefixMode,
6
+ type EventType,
7
+ type LoadStrategy,
8
+ type PopulatePath,
9
+ type QueryOrderMap,
10
+ ReferenceKind,
11
+ } from './enums.js';
3
12
  import { type AssignOptions } from './entity/EntityAssigner.js';
4
13
  import { type EntityIdentifier } from './entity/EntityIdentifier.js';
5
14
  import { type EntityLoaderOptions } from './entity/EntityLoader.js';
@@ -20,28 +29,63 @@ import type { EntityManager } from './EntityManager.js';
20
29
  import type { EventSubscriber } from './events/EventSubscriber.js';
21
30
  import type { FilterOptions, FindOneOptions, FindOptions, LoadHint } from './drivers/IDatabaseDriver.js';
22
31
  export type { Raw };
32
+ /** Generic constructor type. Matches any class that can be instantiated with `new`. */
23
33
  export type Constructor<T = unknown> = new (...args: any[]) => T;
34
+ /** Simple string-keyed object type. Use instead of `Record<string, T>` for convenience. */
24
35
  export type Dictionary<T = any> = {
25
- [k: string]: T;
36
+ [k: string]: T;
26
37
  };
38
+ /** Record of compiled functions, used internally for hydration and comparison. */
27
39
  export type CompiledFunctions = Record<string, (...args: any[]) => any>;
28
- export type EntityKey<T = unknown, B extends boolean = false> = string & {
40
+ /**
41
+ * Extracts string property keys from an entity, excluding symbols, functions, and internal keys.
42
+ * Pass `B = true` to also exclude scalar properties (useful for getting only relation keys).
43
+ */
44
+ export type EntityKey<T = unknown, B extends boolean = false> = string &
45
+ {
29
46
  [K in keyof T]-?: CleanKeys<T, K, B> extends never ? never : K;
30
- }[keyof T];
47
+ }[keyof T];
48
+ /** Resolves to the value type of entity properties (keyed by `EntityKey<T>`). */
31
49
  export type EntityValue<T> = T[EntityKey<T>];
50
+ /** Resolves to the value type within `EntityData<T>` (the data shape used for create/update). */
32
51
  export type EntityDataValue<T> = EntityData<T>[EntityKey<T>];
52
+ /** Extracts valid keys for `FilterQuery<T>`. */
33
53
  export type FilterKey<T> = keyof FilterQuery<T>;
54
+ /** A function type that accepts a dictionary argument and returns a Promise. */
34
55
  export type AsyncFunction<R = any, T = Dictionary> = (args: T) => Promise<T>;
56
+ /** Identity mapped type that forces TypeScript to eagerly evaluate and flatten `T`. */
35
57
  export type Compute<T> = {
36
- [K in keyof T]: T[K];
58
+ [K in keyof T]: T[K];
37
59
  } & {};
38
- type InternalKeys = 'EntityRepositoryType' | 'PrimaryKeyProp' | 'OptionalProps' | 'EagerProps' | 'HiddenProps' | '__selectedType' | '__loadedType';
39
- 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;
60
+ type InternalKeys =
61
+ | 'EntityRepositoryType'
62
+ | 'PrimaryKeyProp'
63
+ | 'OptionalProps'
64
+ | 'EagerProps'
65
+ | 'HiddenProps'
66
+ | '__selectedType'
67
+ | '__loadedType';
68
+ /** Filters out function, symbol, and internal keys from an entity type. When `B = true`, also excludes scalar keys. */
69
+ export type CleanKeys<T, K extends keyof T, B extends boolean = false> = T[K] & {} extends Function
70
+ ? never
71
+ : K extends symbol | InternalKeys
72
+ ? never
73
+ : B extends true
74
+ ? T[K] & {} extends Scalar
75
+ ? never
76
+ : K
77
+ : K;
78
+ /** Extracts keys of `T` whose values are functions. */
40
79
  export type FunctionKeys<T, K extends keyof T> = T[K] extends Function ? K : never;
80
+ /** Conditional cast: returns `T` if it extends `R`, otherwise returns `R`. */
41
81
  export type Cast<T, R> = T extends R ? T : R;
82
+ /** Evaluates to `true` if `T` is the `unknown` type. */
42
83
  export type IsUnknown<T> = T extends unknown ? (unknown extends T ? true : never) : never;
84
+ /** Evaluates to `true` if `T` is `any`. */
43
85
  export type IsAny<T> = 0 extends 1 & T ? true : false;
86
+ /** Evaluates to `True` if `T` is `never`, otherwise `False`. */
44
87
  export type IsNever<T, True = true, False = false> = [T] extends [never] ? True : False;
88
+ /** Represents a value that may be synchronous or wrapped in a Promise. */
45
89
  export type MaybePromise<T> = T | Promise<T>;
46
90
  /**
47
91
  * Structural type for matching Collection without triggering full interface evaluation.
@@ -54,8 +98,8 @@ export type MaybePromise<T> = T | Promise<T>;
54
98
  * - With inference: `T extends CollectionShape<infer U>`
55
99
  */
56
100
  type CollectionShape<T = any> = {
57
- [k: number]: T;
58
- readonly owner: object;
101
+ [k: number]: T;
102
+ readonly owner: object;
59
103
  };
60
104
  /**
61
105
  * Structural type for matching LoadedCollection (extends CollectionShape with `$` property).
@@ -65,7 +109,7 @@ type CollectionShape<T = any> = {
65
109
  * - With inference: `T extends LoadedCollectionShape<infer U>`
66
110
  */
67
111
  type LoadedCollectionShape<T = any> = CollectionShape<T> & {
68
- $: any;
112
+ $: any;
69
113
  };
70
114
  /**
71
115
  * Structural type for matching Reference without triggering full class evaluation.
@@ -78,7 +122,7 @@ type LoadedCollectionShape<T = any> = CollectionShape<T> & {
78
122
  * - With inference: `T extends ReferenceShape<infer U>`
79
123
  */
80
124
  type ReferenceShape<T = any> = {
81
- unwrap(): T;
125
+ unwrap(): T;
82
126
  };
83
127
  /**
84
128
  * Structural type for matching LoadedReference (Reference with `$` property).
@@ -87,7 +131,7 @@ type ReferenceShape<T = any> = {
87
131
  * We infer T from $ to get the full Loaded type for EntityDTO.
88
132
  */
89
133
  type LoadedReferenceShape<T = any> = ReferenceShape & {
90
- $: T;
134
+ $: T;
91
135
  };
92
136
  /**
93
137
  * Structural type for matching any loadable relation (Collection, Reference, or array).
@@ -95,56 +139,103 @@ type LoadedReferenceShape<T = any> = ReferenceShape & {
95
139
  * TypeScript from evaluating the full Collection/Reference interfaces.
96
140
  */
97
141
  type LoadableShape = CollectionShape | ReferenceShape | readonly any[];
142
+ /** Gets all keys from all members of a union type (distributes over the union). */
98
143
  export type UnionKeys<T> = T extends any ? keyof T : never;
144
+ /** Gets the type of a property from all union members that have it (distributes over the union). */
99
145
  export type UnionPropertyType<T, K extends PropertyKey> = T extends any ? (K extends keyof T ? T[K] : never) : never;
100
146
  type IsUnion<T, U = T> = T extends any ? ([U] extends [T] ? false : true) : false;
101
- export type MergeUnion<T> = [T] extends [object] ? T extends Scalar ? T : IsUnion<T> extends true ? {
102
- [K in UnionKeys<T>]: UnionPropertyType<T, K>;
103
- } : T : T;
147
+ /**
148
+ * Merges all members of a union type into a single object with all their properties.
149
+ * For non-union types, returns `T` directly to avoid expensive key iteration.
150
+ */
151
+ export type MergeUnion<T> = [T] extends [object]
152
+ ? T extends Scalar
153
+ ? T
154
+ : IsUnion<T> extends true
155
+ ? {
156
+ [K in UnionKeys<T>]: UnionPropertyType<T, K>;
157
+ }
158
+ : T
159
+ : T;
160
+ /** Recursively makes all properties of `T` optional, including nested objects and arrays. */
104
161
  export type DeepPartial<T> = T & {
105
- [P in keyof T]?: T[P] extends (infer U)[] ? DeepPartial<U>[] : T[P] extends Readonly<infer U>[] ? Readonly<DeepPartial<U>>[] : DeepPartial<T[P]>;
162
+ [P in keyof T]?: T[P] extends (infer U)[]
163
+ ? DeepPartial<U>[]
164
+ : T[P] extends Readonly<infer U>[]
165
+ ? Readonly<DeepPartial<U>>[]
166
+ : DeepPartial<T[P]>;
106
167
  };
168
+ /** Symbol used to declare a custom repository type on an entity class (e.g., `[EntityRepositoryType]?: BookRepository`). */
107
169
  export declare const EntityRepositoryType: unique symbol;
170
+ /** Symbol used to declare the primary key property name(s) on an entity (e.g., `[PrimaryKeyProp]?: 'id'`). */
108
171
  export declare const PrimaryKeyProp: unique symbol;
172
+ /** Symbol used to declare which properties are optional in `em.create()` (e.g., `[OptionalProps]?: 'createdAt'`). */
109
173
  export declare const OptionalProps: unique symbol;
174
+ /** Symbol used to declare which relation properties should be eagerly loaded (e.g., `[EagerProps]?: 'author'`). */
110
175
  export declare const EagerProps: unique symbol;
176
+ /** Symbol used to declare which properties are hidden from serialization (e.g., `[HiddenProps]?: 'password'`). */
111
177
  export declare const HiddenProps: unique symbol;
178
+ /** Symbol used to declare type-level configuration on an entity (e.g., `[Config]?: DefineConfig<{ forceObject: true }>`). */
112
179
  export declare const Config: unique symbol;
180
+ /** Symbol used to declare the entity name as a string literal type (used by `defineEntity`). */
113
181
  export declare const EntityName: unique symbol;
182
+ /** Extracts the entity name string literal from an entity type that declares `[EntityName]`. */
114
183
  export type InferEntityName<T> = T extends {
115
- [EntityName]?: infer Name;
116
- } ? (Name extends string ? Name : never) : never;
184
+ [EntityName]?: infer Name;
185
+ }
186
+ ? Name extends string
187
+ ? Name
188
+ : never
189
+ : never;
190
+ /**
191
+ * Branded type that marks a property as optional in `em.create()`.
192
+ * Use as a property type wrapper: `createdAt: Opt<Date>` instead of listing in `[OptionalProps]`.
193
+ */
117
194
  export type Opt<T = unknown> = T & Opt.Brand;
118
195
  export declare namespace Opt {
119
- const __optional: unique symbol;
120
- interface Brand {
121
- [__optional]?: 1;
122
- }
196
+ const __optional: unique symbol;
197
+ interface Brand {
198
+ [__optional]?: 1;
199
+ }
123
200
  }
201
+ /**
202
+ * Branded type that marks a nullable property as required in `em.create()`.
203
+ * By default, nullable properties are treated as optional; this forces them to be explicitly provided.
204
+ */
124
205
  export type RequiredNullable<T = never> = (T & RequiredNullable.Brand) | null;
125
206
  export declare namespace RequiredNullable {
126
- const __requiredNullable: unique symbol;
127
- interface Brand {
128
- [__requiredNullable]?: 1;
129
- }
207
+ const __requiredNullable: unique symbol;
208
+ interface Brand {
209
+ [__requiredNullable]?: 1;
210
+ }
130
211
  }
212
+ /**
213
+ * Branded type that marks a property as hidden from serialization.
214
+ * Use as a property type wrapper: `password: Hidden<string>` instead of listing in `[HiddenProps]`.
215
+ */
131
216
  export type Hidden<T = unknown> = T & Hidden.Brand;
132
217
  export declare namespace Hidden {
133
- const __hidden: unique symbol;
134
- interface Brand {
135
- [__hidden]?: 1;
136
- }
218
+ const __hidden: unique symbol;
219
+ interface Brand {
220
+ [__hidden]?: 1;
221
+ }
137
222
  }
223
+ /**
224
+ * Branded type for entity-level configuration (e.g., `[Config]?: DefineConfig<{ forceObject: true }>`).
225
+ * Controls type-level behavior such as forcing object representation for primary keys in DTOs.
226
+ */
138
227
  export type DefineConfig<T extends TypeConfig> = T & DefineConfig.Brand;
139
228
  export declare namespace DefineConfig {
140
- const __config: unique symbol;
141
- interface Brand {
142
- [__config]?: 1;
143
- }
229
+ const __config: unique symbol;
230
+ interface Brand {
231
+ [__config]?: 1;
232
+ }
144
233
  }
234
+ /** Extracts only the `TypeConfig` keys from a branded config type, stripping the brand. */
145
235
  export type CleanTypeConfig<T> = Compute<Pick<T, Extract<keyof T, keyof TypeConfig>>>;
236
+ /** Configuration options that can be set on an entity via the `[Config]` symbol. */
146
237
  export interface TypeConfig {
147
- forceObject?: boolean;
238
+ forceObject?: boolean;
148
239
  }
149
240
  declare const __selectedType: unique symbol;
150
241
  declare const __loadedType: unique symbol;
@@ -155,265 +246,553 @@ declare const __loadHint: unique symbol;
155
246
  * This reflects that loading 'a.b.c' means 'a' and 'a.b' are also loaded.
156
247
  * Special case: '*' returns string to ensure Loaded<T, '*'> is assignable to any Loaded<T, Hint>.
157
248
  */
158
- export type Prefixes<S extends string> = S extends '*' ? string : S extends `${infer H}.${infer T}` ? H | `${H}.${Prefixes<T>}` : S;
249
+ export type Prefixes<S extends string> = S extends '*'
250
+ ? string
251
+ : S extends `${infer H}.${infer T}`
252
+ ? H | `${H}.${Prefixes<T>}`
253
+ : S;
254
+ /** Unwraps a value to its primary key type. Scalars pass through; References are unwrapped first. */
159
255
  export type UnwrapPrimary<T> = T extends Scalar ? T : T extends ReferenceShape<infer U> ? Primary<U> : Primary<T>;
160
256
  type PrimaryPropToType<T, Keys extends (keyof T)[]> = {
161
- [Index in keyof Keys]: UnwrapPrimary<T[Keys[Index]]>;
257
+ [Index in keyof Keys]: UnwrapPrimary<T[Keys[Index]]>;
162
258
  };
163
259
  type ReadonlyPrimary<T> = T extends any[] ? Readonly<T> : T;
164
- export type Primary<T> = IsAny<T> extends true ? any : T extends {
165
- [PrimaryKeyProp]?: infer PK;
166
- } ? 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 {
167
- _id?: infer PK;
168
- } ? ReadonlyPrimary<PK> | string : T extends {
169
- id?: infer PK;
170
- } ? ReadonlyPrimary<PK> : T extends {
171
- uuid?: infer PK;
172
- } ? ReadonlyPrimary<PK> : T;
260
+ /**
261
+ * Resolves the primary key type for an entity. Uses `[PrimaryKeyProp]` if declared,
262
+ * otherwise falls back to `_id`, `id`, or `uuid` properties. For composite keys, returns a tuple.
263
+ */
264
+ export type Primary<T> =
265
+ IsAny<T> extends true
266
+ ? any
267
+ : T extends {
268
+ [PrimaryKeyProp]?: infer PK;
269
+ }
270
+ ? PK extends undefined
271
+ ? Omit<T, typeof PrimaryKeyProp>
272
+ : PK extends keyof T
273
+ ? ReadonlyPrimary<UnwrapPrimary<T[PK]>>
274
+ : PK extends (keyof T)[]
275
+ ? ReadonlyPrimary<PrimaryPropToType<T, PK>>
276
+ : PK
277
+ : T extends {
278
+ _id?: infer PK;
279
+ }
280
+ ? ReadonlyPrimary<PK> | string
281
+ : T extends {
282
+ id?: infer PK;
283
+ }
284
+ ? ReadonlyPrimary<PK>
285
+ : T extends {
286
+ uuid?: infer PK;
287
+ }
288
+ ? ReadonlyPrimary<PK>
289
+ : T;
173
290
  /** @internal */
174
291
  export type PrimaryProperty<T> = T extends {
175
- [PrimaryKeyProp]?: infer PK;
176
- } ? PK extends keyof T ? PK : PK extends any[] ? PK[number] : never : T extends {
177
- _id?: any;
178
- } ? T extends {
179
- id?: any;
180
- } ? 'id' | '_id' : '_id' : T extends {
181
- id?: any;
182
- } ? 'id' : T extends {
183
- uuid?: any;
184
- } ? 'uuid' : never;
185
- export type IPrimaryKeyValue = number | string | bigint | Date | {
186
- toHexString(): string;
187
- };
292
+ [PrimaryKeyProp]?: infer PK;
293
+ }
294
+ ? PK extends keyof T
295
+ ? PK
296
+ : PK extends any[]
297
+ ? PK[number]
298
+ : never
299
+ : T extends {
300
+ _id?: any;
301
+ }
302
+ ? T extends {
303
+ id?: any;
304
+ }
305
+ ? 'id' | '_id'
306
+ : '_id'
307
+ : T extends {
308
+ id?: any;
309
+ }
310
+ ? 'id'
311
+ : T extends {
312
+ uuid?: any;
313
+ }
314
+ ? 'uuid'
315
+ : never;
316
+ /** Union of all allowed primary key value types (number, string, bigint, Date, ObjectId-like). */
317
+ export type IPrimaryKeyValue =
318
+ | number
319
+ | string
320
+ | bigint
321
+ | Date
322
+ | {
323
+ toHexString(): string;
324
+ };
325
+ /** Alias for a primary key value, constrained to `IPrimaryKeyValue`. */
188
326
  export type IPrimaryKey<T extends IPrimaryKeyValue = IPrimaryKeyValue> = T;
189
- export type Scalar = boolean | number | string | bigint | symbol | Date | RegExp | Uint8Array | {
190
- toHexString(): string;
191
- };
327
+ /** Union of types considered "scalar" (non-entity) values. Used to distinguish entity relations from plain values. */
328
+ export type Scalar =
329
+ | boolean
330
+ | number
331
+ | string
332
+ | bigint
333
+ | symbol
334
+ | Date
335
+ | RegExp
336
+ | Uint8Array
337
+ | {
338
+ toHexString(): string;
339
+ };
192
340
  type Primitive = boolean | number | string | bigint | symbol;
193
- export type ExpandScalar<T> = null | (T extends string ? T | RegExp : T extends Date ? Date | string : T extends bigint ? bigint | string | number : T);
341
+ /** Expands a scalar type to include alternative representations accepted in queries (e.g., `Date | string`). */
342
+ export type ExpandScalar<T> =
343
+ | null
344
+ | (T extends string ? T | RegExp : T extends Date ? Date | string : T extends bigint ? bigint | string | number : T);
194
345
  /** Marker interface for query builders that can be used as subqueries */
195
346
  export interface Subquery {
196
- readonly __subquery: true;
347
+ readonly __subquery: true;
197
348
  }
349
+ /** Map of query operators (`$eq`, `$gt`, `$in`, etc.) available for filtering a value of type `T`. */
198
350
  export type OperatorMap<T> = {
199
- $and?: ExpandQuery<T>[];
200
- $or?: ExpandQuery<T>[];
201
- $eq?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
202
- $ne?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
203
- $in?: readonly ExpandScalar<T>[] | readonly Primary<T>[] | Raw | Subquery;
204
- $nin?: readonly ExpandScalar<T>[] | readonly Primary<T>[] | Raw | Subquery;
205
- $not?: ExpandQuery<T>;
206
- $none?: ExpandQuery<T>;
207
- $some?: ExpandQuery<T>;
208
- $every?: ExpandQuery<T>;
209
- $size?: number | {
351
+ $and?: ExpandQuery<T>[];
352
+ $or?: ExpandQuery<T>[];
353
+ $eq?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
354
+ $ne?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
355
+ $in?: readonly ExpandScalar<T>[] | readonly Primary<T>[] | Raw | Subquery;
356
+ $nin?: readonly ExpandScalar<T>[] | readonly Primary<T>[] | Raw | Subquery;
357
+ $not?: ExpandQuery<T>;
358
+ $none?: ExpandQuery<T>;
359
+ $some?: ExpandQuery<T>;
360
+ $every?: ExpandQuery<T>;
361
+ $size?:
362
+ | number
363
+ | {
210
364
  $eq?: number;
211
365
  $ne?: number;
212
366
  $gt?: number;
213
367
  $gte?: number;
214
368
  $lt?: number;
215
369
  $lte?: number;
216
- };
217
- $gt?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
218
- $gte?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
219
- $lt?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
220
- $lte?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
221
- $like?: string;
222
- $re?: string;
223
- $ilike?: string;
224
- $fulltext?: string;
225
- $overlap?: readonly string[] | string | object;
226
- $contains?: readonly string[] | string | object;
227
- $contained?: readonly string[] | string | object;
228
- $exists?: boolean;
229
- $hasKey?: string;
230
- $hasKeys?: readonly string[];
231
- $hasSomeKeys?: readonly string[];
370
+ };
371
+ $gt?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
372
+ $gte?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
373
+ $lt?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
374
+ $lte?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
375
+ $like?: string;
376
+ $re?: string;
377
+ $ilike?: string;
378
+ $fulltext?: string;
379
+ $overlap?: readonly string[] | string | object;
380
+ $contains?: readonly string[] | string | object;
381
+ $contained?: readonly string[] | string | object;
382
+ $exists?: boolean;
383
+ $hasKey?: string;
384
+ $hasKeys?: readonly string[];
385
+ $hasSomeKeys?: readonly string[];
232
386
  };
387
+ /** A single filter value: the raw value, its expanded scalar form, its primary key, or a raw SQL expression. */
233
388
  export type FilterItemValue<T> = T | ExpandScalar<T> | Primary<T> | Raw;
389
+ /** A complete filter value: an operator map, a single value, an array of values, or null. */
234
390
  export type FilterValue<T> = OperatorMap<FilterItemValue<T>> | FilterItemValue<T> | FilterItemValue<T>[] | null;
235
- type FilterObjectProp<T, K extends PropertyKey> = K extends keyof MergeUnion<T> ? MergeUnion<T>[K] : K extends keyof T ? T[K] : never;
236
- type ExpandQueryMerged<T> = [T] extends [object] ? [T] extends [Scalar] ? never : FilterQuery<MergeUnion<T>> : FilterValue<T>;
391
+ type FilterObjectProp<T, K extends PropertyKey> = K extends keyof MergeUnion<T>
392
+ ? MergeUnion<T>[K]
393
+ : K extends keyof T
394
+ ? T[K]
395
+ : never;
396
+ type ExpandQueryMerged<T> = [T] extends [object]
397
+ ? [T] extends [Scalar]
398
+ ? never
399
+ : FilterQuery<MergeUnion<T>>
400
+ : FilterValue<T>;
237
401
  type ElemMatchCondition<T extends Record<string, any>> = {
238
- [K in keyof T]?: T[K] | OperatorMap<T[K]>;
402
+ [K in keyof T]?: T[K] | OperatorMap<T[K]>;
239
403
  } & {
240
- $or?: ElemMatchCondition<T>[];
241
- $and?: ElemMatchCondition<T>[];
242
- $not?: ElemMatchCondition<T>;
404
+ $or?: ElemMatchCondition<T>[];
405
+ $and?: ElemMatchCondition<T>[];
406
+ $not?: ElemMatchCondition<T>;
243
407
  };
244
- type ElemMatchFilter<T> = T extends readonly (infer E)[] ? E extends Record<string, any> ? {
245
- $elemMatch: ElemMatchCondition<E>;
246
- } : never : never;
408
+ type ElemMatchFilter<T> = T extends readonly (infer E)[]
409
+ ? E extends Record<string, any>
410
+ ? {
411
+ $elemMatch: ElemMatchCondition<E>;
412
+ }
413
+ : never
414
+ : never;
415
+ /** Object form of a filter query, mapping entity keys to their filter conditions. */
247
416
  export type FilterObject<T> = {
248
- -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;
417
+ -readonly [K in EntityKey<T>]?:
418
+ | ExpandQuery<ExpandProperty<FilterObjectProp<T, K>>>
419
+ | ExpandQueryMerged<ExpandProperty<FilterObjectProp<T, K>>>
420
+ | FilterValue<ExpandProperty<FilterObjectProp<T, K>>>
421
+ | ElemMatchFilter<FilterObjectProp<T, K>>
422
+ | null;
249
423
  };
424
+ /** Recursively expands a type into its `FilterQuery` form for nested object filtering. */
250
425
  export type ExpandQuery<T> = T extends object ? (T extends Scalar ? never : FilterQuery<T>) : FilterValue<T>;
426
+ /** Partial entity shape with all entity properties optional. */
251
427
  export type EntityProps<T> = {
252
- -readonly [K in EntityKey<T>]?: T[K];
428
+ -readonly [K in EntityKey<T>]?: T[K];
253
429
  };
430
+ /** Object-based query filter combining operator maps with property-level filters. */
254
431
  export type ObjectQuery<T> = OperatorMap<T> & FilterObject<T>;
255
- export type FilterQuery<T> = ObjectQuery<T> | NonNullable<ExpandScalar<Primary<T>>> | NonNullable<EntityProps<T> & OperatorMap<T>> | FilterQuery<T>[];
432
+ /**
433
+ * The main query filter type used in `em.find()`, `em.findOne()`, etc.
434
+ * Accepts an object query, a primary key value, entity props with operators, or an array of filters.
435
+ */
436
+ export type FilterQuery<T> =
437
+ | ObjectQuery<T>
438
+ | NonNullable<ExpandScalar<Primary<T>>>
439
+ | NonNullable<EntityProps<T> & OperatorMap<T>>
440
+ | FilterQuery<T>[];
441
+ /** Public interface for the entity wrapper, accessible via `wrap(entity)`. Provides helper methods for entity state management. */
256
442
  export interface IWrappedEntity<Entity extends object> {
257
- isInitialized(): boolean;
258
- isManaged(): boolean;
259
- populated(populated?: boolean): void;
260
- populate<Hint extends string = never, Fields extends string = never>(populate: readonly AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity, Fields>): Promise<Loaded<Entity, Hint>>;
261
- init<Hint extends string = never, Fields extends string = '*', Exclude extends string = never>(options?: FindOneOptions<Entity, Hint, Fields, Exclude>): Promise<Loaded<Entity, Hint, Fields, Exclude> | null>;
262
- toReference(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
263
- toObject(): EntityDTO<Entity>;
264
- toObject(ignoreFields: never[]): EntityDTO<Entity>;
265
- toObject<Ignored extends EntityKey<Entity>>(ignoreFields: Ignored[]): Omit<EntityDTO<Entity>, Ignored>;
266
- toJSON(...args: any[]): EntityDTO<Entity>;
267
- toPOJO(): EntityDTO<Entity>;
268
- serialize<Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Naked, Hint, Exclude>): SerializeDTO<Naked, Hint, Exclude>;
269
- setSerializationContext<Hint extends string = never, Fields extends string = '*', Exclude extends string = never>(options: LoadHint<Entity, Hint, Fields, Exclude>): void;
270
- assign<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, Convert>, Data>, options?: AssignOptions<Convert>): MergeSelected<Entity, Naked, keyof Data & string>;
271
- getSchema(): string | undefined;
272
- setSchema(schema?: string): void;
443
+ isInitialized(): boolean;
444
+ isManaged(): boolean;
445
+ populated(populated?: boolean): void;
446
+ populate<Hint extends string = never, Fields extends string = never>(
447
+ populate: readonly AutoPath<Entity, Hint, PopulatePath.ALL>[] | false,
448
+ options?: EntityLoaderOptions<Entity, Fields>,
449
+ ): Promise<Loaded<Entity, Hint>>;
450
+ init<Hint extends string = never, Fields extends string = '*', Exclude extends string = never>(
451
+ options?: FindOneOptions<Entity, Hint, Fields, Exclude>,
452
+ ): Promise<Loaded<Entity, Hint, Fields, Exclude> | null>;
453
+ toReference(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
454
+ toObject(): EntityDTO<Entity>;
455
+ toObject(ignoreFields: never[]): EntityDTO<Entity>;
456
+ toObject<Ignored extends EntityKey<Entity>>(ignoreFields: Ignored[]): Omit<EntityDTO<Entity>, Ignored>;
457
+ toJSON(...args: any[]): EntityDTO<Entity>;
458
+ toPOJO(): EntityDTO<Entity>;
459
+ serialize<
460
+ Naked extends FromEntityType<Entity> = FromEntityType<Entity>,
461
+ Hint extends string = never,
462
+ Exclude extends string = never,
463
+ >(
464
+ options?: SerializeOptions<Naked, Hint, Exclude>,
465
+ ): SerializeDTO<Naked, Hint, Exclude>;
466
+ setSerializationContext<Hint extends string = never, Fields extends string = '*', Exclude extends string = never>(
467
+ options: LoadHint<Entity, Hint, Fields, Exclude>,
468
+ ): void;
469
+ assign<
470
+ Naked extends FromEntityType<Entity> = FromEntityType<Entity>,
471
+ Convert extends boolean = false,
472
+ Data extends EntityData<Naked, Convert> | Partial<EntityDTO<Naked>> =
473
+ | EntityData<Naked, Convert>
474
+ | Partial<EntityDTO<Naked>>,
475
+ >(
476
+ data: Data & IsSubset<EntityData<Naked, Convert>, Data>,
477
+ options?: AssignOptions<Convert>,
478
+ ): MergeSelected<Entity, Naked, keyof Data & string>;
479
+ getSchema(): string | undefined;
480
+ setSchema(schema?: string): void;
273
481
  }
482
+ /** @internal Extended wrapper interface with internal state used by the ORM runtime. */
274
483
  export interface IWrappedEntityInternal<Entity extends object> extends IWrappedEntity<Entity> {
275
- hasPrimaryKey(): boolean;
276
- getPrimaryKey(convertCustomTypes?: boolean): Primary<Entity> | null;
277
- getPrimaryKeys(convertCustomTypes?: boolean): Primary<Entity>[] | null;
278
- setPrimaryKey(val: Primary<Entity>): void;
279
- getSerializedPrimaryKey(): string & keyof Entity;
280
- __meta: EntityMetadata<Entity>;
281
- __data: Dictionary;
282
- __em?: EntityManager;
283
- __platform: Platform;
284
- __config: Configuration;
285
- __factory: EntityFactory;
286
- __hydrator: IHydrator;
287
- __initialized: boolean;
288
- __originalEntityData?: EntityData<Entity>;
289
- __loadedProperties: Set<string>;
290
- __identifier?: EntityIdentifier | EntityIdentifier[];
291
- __managed: boolean;
292
- __processing: boolean;
293
- __schema?: string;
294
- __populated: boolean;
295
- __onLoadFired: boolean;
296
- __reference?: Ref<Entity>;
297
- __pk?: Primary<Entity>;
298
- __primaryKeys: Primary<Entity>[];
299
- __serializationContext: {
300
- root?: SerializationContext<Entity>;
301
- populate?: PopulateOptions<Entity>[];
302
- fields?: Set<string>;
303
- exclude?: string[];
304
- };
484
+ hasPrimaryKey(): boolean;
485
+ getPrimaryKey(convertCustomTypes?: boolean): Primary<Entity> | null;
486
+ getPrimaryKeys(convertCustomTypes?: boolean): Primary<Entity>[] | null;
487
+ setPrimaryKey(val: Primary<Entity>): void;
488
+ getSerializedPrimaryKey(): string & keyof Entity;
489
+ __meta: EntityMetadata<Entity>;
490
+ __data: Dictionary;
491
+ __em?: EntityManager;
492
+ __platform: Platform;
493
+ __config: Configuration;
494
+ __factory: EntityFactory;
495
+ __hydrator: IHydrator;
496
+ __initialized: boolean;
497
+ __originalEntityData?: EntityData<Entity>;
498
+ __loadedProperties: Set<string>;
499
+ __identifier?: EntityIdentifier | EntityIdentifier[];
500
+ __managed: boolean;
501
+ __processing: boolean;
502
+ __schema?: string;
503
+ __populated: boolean;
504
+ __onLoadFired: boolean;
505
+ __reference?: Ref<Entity>;
506
+ __pk?: Primary<Entity>;
507
+ __primaryKeys: Primary<Entity>[];
508
+ __serializationContext: {
509
+ root?: SerializationContext<Entity>;
510
+ populate?: PopulateOptions<Entity>[];
511
+ fields?: Set<string>;
512
+ exclude?: string[];
513
+ };
305
514
  }
515
+ /** Loose entity type used in generic contexts. Equivalent to `Partial<T>`. */
306
516
  export type AnyEntity<T = any> = Partial<T>;
517
+ /** A class (function with prototype) whose instances are of type `T`. */
307
518
  export type EntityClass<T = any> = Function & {
308
- prototype: T;
519
+ prototype: T;
309
520
  };
521
+ /** Any valid entity name reference: a class, abstract constructor, or EntitySchema. */
310
522
  export type EntityName<T = any> = EntityClass<T> | EntityCtor<T> | EntitySchema<T, any>;
311
- export type GetRepository<Entity extends {
523
+ /** Resolves the custom repository type for an entity (from `[EntityRepositoryType]`), or falls back to `Fallback`. */
524
+ export type GetRepository<
525
+ Entity extends {
312
526
  [k: PropertyKey]: any;
313
- }, Fallback> = Entity[typeof EntityRepositoryType] extends EntityRepository<any> | undefined ? NonNullable<Entity[typeof EntityRepositoryType]> : Fallback;
314
- type PolymorphicPrimaryInner<T> = T extends object ? Primary<T> extends readonly [infer First, infer Second, ...infer Rest] ? readonly [string, First, Second, ...Rest] | [string, First, Second, ...Rest] : readonly [string, Primary<T>] | [string, Primary<T>] : never;
527
+ },
528
+ Fallback,
529
+ > = Entity[typeof EntityRepositoryType] extends EntityRepository<any> | undefined
530
+ ? NonNullable<Entity[typeof EntityRepositoryType]>
531
+ : Fallback;
532
+ type PolymorphicPrimaryInner<T> = T extends object
533
+ ? Primary<T> extends readonly [infer First, infer Second, ...infer Rest]
534
+ ? readonly [string, First, Second, ...Rest] | [string, First, Second, ...Rest]
535
+ : readonly [string, Primary<T>] | [string, Primary<T>]
536
+ : never;
315
537
  /**
316
538
  * Tuple format for polymorphic FK values: [discriminator, ...pkValues]
317
539
  * Distributes over unions, so `Post | Comment` becomes `['post', number] | ['comment', number]`
318
540
  * For composite keys like [tenantId, orgId], becomes ['discriminator', tenantId, orgId]
319
541
  */
320
542
  export type PolymorphicPrimary<T> = true extends IsUnion<T> ? PolymorphicPrimaryInner<T> : never;
543
+ /** Allowed value types when assigning to an entity data property: the entity itself, its PK, or a polymorphic PK tuple. */
321
544
  export type EntityDataPropValue<T> = T | Primary<T> | PolymorphicPrimary<T>;
322
- type ExpandEntityProp<T, C extends boolean = false> = T extends Record<string, any> ? {
323
- [K in keyof T as CleanKeys<T, K>]?: EntityDataProp<ExpandProperty<T[K]>, C> | EntityDataPropValue<ExpandProperty<T[K]>> | null;
324
- } | EntityDataPropValue<ExpandProperty<T>> : T;
325
- type ExpandRequiredEntityProp<T, I, C extends boolean> = T extends Record<string, any> ? ExpandRequiredEntityPropObject<T, I, C> | EntityDataPropValue<ExpandProperty<T>> : T;
545
+ type ExpandEntityProp<T, C extends boolean = false> =
546
+ T extends Record<string, any>
547
+ ?
548
+ | {
549
+ [K in keyof T as CleanKeys<T, K>]?:
550
+ | EntityDataProp<ExpandProperty<T[K]>, C>
551
+ | EntityDataPropValue<ExpandProperty<T[K]>>
552
+ | null;
553
+ }
554
+ | EntityDataPropValue<ExpandProperty<T>>
555
+ : T;
556
+ type ExpandRequiredEntityProp<T, I, C extends boolean> =
557
+ T extends Record<string, any> ? ExpandRequiredEntityPropObject<T, I, C> | EntityDataPropValue<ExpandProperty<T>> : T;
326
558
  type ExpandRequiredEntityPropObject<T, I = never, C extends boolean = false> = {
327
- [K in keyof T as RequiredKeys<T, K, I>]: RequiredEntityDataProp<ExpandProperty<T[K]>, T, C> | EntityDataPropValue<ExpandProperty<T[K]>>;
559
+ [K in keyof T as RequiredKeys<T, K, I>]:
560
+ | RequiredEntityDataProp<ExpandProperty<T[K]>, T, C>
561
+ | EntityDataPropValue<ExpandProperty<T[K]>>;
328
562
  } & {
329
- [K in keyof T as OptionalKeys<T, K, I>]?: RequiredEntityDataProp<ExpandProperty<T[K]>, T, C> | EntityDataPropValue<ExpandProperty<T[K]>> | null | undefined;
563
+ [K in keyof T as OptionalKeys<T, K, I>]?:
564
+ | RequiredEntityDataProp<ExpandProperty<T[K]>, T, C>
565
+ | EntityDataPropValue<ExpandProperty<T[K]>>
566
+ | null
567
+ | undefined;
330
568
  };
331
569
  type NonArrayObject = object & {
332
- [Symbol.iterator]?: never;
570
+ [Symbol.iterator]?: never;
333
571
  };
334
- 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
- __runtime?: infer Runtime;
336
- __raw?: infer Raw;
337
- } ? 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>;
338
- 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
- __runtime?: infer Runtime;
340
- __raw?: infer Raw;
341
- } ? 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>;
342
- export type EntityDataNested<T, C extends boolean = false> = T extends undefined ? never : T extends any[] ? Readonly<T> : EntityData<T, C> | ExpandEntityProp<T, C>;
572
+ /** Resolves the allowed input type for a single entity property in `EntityData`. Handles scalars, references, collections, and nested entities. */
573
+ export type EntityDataProp<T, C extends boolean> = T extends Date
574
+ ? string | Date
575
+ : T extends Scalar
576
+ ? T
577
+ : T extends ScalarReference<infer U>
578
+ ? EntityDataProp<U, C>
579
+ : T extends {
580
+ __runtime?: infer Runtime;
581
+ __raw?: infer Raw;
582
+ }
583
+ ? C extends true
584
+ ? Raw
585
+ : Runtime
586
+ : T extends ReferenceShape<infer U>
587
+ ? EntityDataNested<U, C>
588
+ : T extends CollectionShape<infer U>
589
+ ? U | U[] | EntityDataNested<U & object, C> | EntityDataNested<U & object, C>[]
590
+ : T extends readonly (infer U)[]
591
+ ? U extends NonArrayObject
592
+ ? U | U[] | EntityDataNested<U, C> | EntityDataNested<U, C>[]
593
+ : U[] | EntityDataNested<U, C>[]
594
+ : EntityDataNested<T, C>;
595
+ /** Like `EntityDataProp` but used in `RequiredEntityData` context with required/optional key distinction. */
596
+ export type RequiredEntityDataProp<T, O, C extends boolean> = T extends Date
597
+ ? string | Date
598
+ : Exclude<T, null> extends RequiredNullable.Brand
599
+ ? T | null
600
+ : T extends Scalar
601
+ ? T
602
+ : T extends ScalarReference<infer U>
603
+ ? RequiredEntityDataProp<U, O, C>
604
+ : T extends {
605
+ __runtime?: infer Runtime;
606
+ __raw?: infer Raw;
607
+ }
608
+ ? C extends true
609
+ ? Raw
610
+ : Runtime
611
+ : T extends ReferenceShape<infer U>
612
+ ? RequiredEntityDataNested<U, O, C>
613
+ : T extends CollectionShape<infer U>
614
+ ? U | U[] | RequiredEntityDataNested<U & object, O, C> | RequiredEntityDataNested<U & object, O, C>[]
615
+ : T extends readonly (infer U)[]
616
+ ? U extends NonArrayObject
617
+ ? U | U[] | RequiredEntityDataNested<U, O, C> | RequiredEntityDataNested<U, O, C>[]
618
+ : U[] | RequiredEntityDataNested<U, O, C>[]
619
+ : RequiredEntityDataNested<T, O, C>;
620
+ /** Nested entity data shape for embedded or related entities within `EntityData`. */
621
+ export type EntityDataNested<T, C extends boolean = false> = T extends undefined
622
+ ? never
623
+ : T extends any[]
624
+ ? Readonly<T>
625
+ : EntityData<T, C> | ExpandEntityProp<T, C>;
343
626
  type UnwrapScalarRef<T> = T extends ScalarReference<infer U> ? U : T;
344
- type EntityDataItem<T, C extends boolean> = C extends false ? UnwrapScalarRef<T> | EntityDataProp<T, C> | Raw | null : EntityDataProp<T, C> | Raw | null;
345
- export type RequiredEntityDataNested<T, O, C extends boolean> = T extends any[] ? Readonly<T> : RequiredEntityData<T, O> | ExpandRequiredEntityProp<T, O, C>;
346
- type ExplicitlyOptionalProps<T> = (T extends {
347
- [OptionalProps]?: infer K;
348
- } ? K : never) | ({
349
- [K in keyof T]: T[K] extends Opt ? K : never;
350
- }[keyof T] & {});
627
+ type EntityDataItem<T, C extends boolean> = C extends false
628
+ ? UnwrapScalarRef<T> | EntityDataProp<T, C> | Raw | null
629
+ : EntityDataProp<T, C> | Raw | null;
630
+ /** Nested entity data shape used within `RequiredEntityData` for embedded or related entities. */
631
+ export type RequiredEntityDataNested<T, O, C extends boolean> = T extends any[]
632
+ ? Readonly<T>
633
+ : RequiredEntityData<T, O> | ExpandRequiredEntityProp<T, O, C>;
634
+ type ExplicitlyOptionalProps<T> =
635
+ | (T extends {
636
+ [OptionalProps]?: infer K;
637
+ }
638
+ ? K
639
+ : never)
640
+ | ({
641
+ [K in keyof T]: T[K] extends Opt ? K : never;
642
+ }[keyof T] & {});
351
643
  type NullableKeys<T, V = null> = {
352
- [K in keyof T]: unknown extends T[K] ? never : V extends T[K] ? K : never;
644
+ [K in keyof T]: unknown extends T[K] ? never : V extends T[K] ? K : never;
353
645
  }[keyof T];
354
646
  type RequiredNullableKeys<T> = {
355
- [K in keyof T]: Exclude<T[K], null> extends RequiredNullable.Brand ? K : never;
647
+ [K in keyof T]: Exclude<T[K], null> extends RequiredNullable.Brand ? K : never;
356
648
  }[keyof T];
357
- type ProbablyOptionalProps<T> = PrimaryProperty<T> | ExplicitlyOptionalProps<T> | Exclude<NonNullable<NullableKeys<T, null | undefined>>, RequiredNullableKeys<T>>;
358
- 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;
649
+ type ProbablyOptionalProps<T> =
650
+ | PrimaryProperty<T>
651
+ | ExplicitlyOptionalProps<T>
652
+ | Exclude<NonNullable<NullableKeys<T, null | undefined>>, RequiredNullableKeys<T>>;
653
+ type IsOptional<T, K extends keyof T, I> = T[K] extends CollectionShape
654
+ ? true
655
+ : ExtractType<T[K]> extends I
656
+ ? true
657
+ : K extends ProbablyOptionalProps<T>
658
+ ? true
659
+ : false;
359
660
  type RequiredKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? CleanKeys<T, K> : never;
360
661
  type OptionalKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? never : CleanKeys<T, K>;
662
+ /** Data shape for creating or updating entities. All properties are optional. Used in `em.create()` and `em.assign()`. */
361
663
  export type EntityData<T, C extends boolean = false> = {
362
- [K in EntityKey<T>]?: EntityDataItem<T[K] & {}, C>;
664
+ [K in EntityKey<T>]?: EntityDataItem<T[K] & {}, C>;
363
665
  };
666
+ /**
667
+ * Data shape for `em.create()` with required/optional distinction based on entity metadata.
668
+ * Properties with defaults, nullable types, `Opt` brand, or `[OptionalProps]` declaration are optional.
669
+ * `I` excludes additional types from being required (used for inverse side of relations).
670
+ */
364
671
  export type RequiredEntityData<T, I = never, C extends boolean = false> = {
365
- [K in keyof T as RequiredKeys<T, K, I>]: T[K] | RequiredEntityDataProp<T[K], T, C> | Primary<T[K]> | PolymorphicPrimary<T[K]> | Raw;
672
+ [K in keyof T as RequiredKeys<T, K, I>]:
673
+ | T[K]
674
+ | RequiredEntityDataProp<T[K], T, C>
675
+ | Primary<T[K]>
676
+ | PolymorphicPrimary<T[K]>
677
+ | Raw;
366
678
  } & {
367
- [K in keyof T as OptionalKeys<T, K, I>]?: T[K] | RequiredEntityDataProp<T[K], T, C> | Primary<T[K]> | PolymorphicPrimary<T[K]> | Raw | null;
679
+ [K in keyof T as OptionalKeys<T, K, I>]?:
680
+ | T[K]
681
+ | RequiredEntityDataProp<T[K], T, C>
682
+ | Primary<T[K]>
683
+ | PolymorphicPrimary<T[K]>
684
+ | Raw
685
+ | null;
368
686
  };
687
+ /** `EntityData<T>` extended with an index signature, allowing arbitrary additional properties. */
369
688
  export type EntityDictionary<T> = EntityData<T> & Record<any, any>;
370
689
  type ExtractEagerProps<T> = T extends {
371
- [EagerProps]?: infer PK;
372
- } ? PK : never;
690
+ [EagerProps]?: infer PK;
691
+ }
692
+ ? PK
693
+ : never;
373
694
  type Relation<T> = {
374
- [P in keyof T as T[P] extends unknown[] | Record<string | number | symbol, unknown> ? P : never]?: T[P];
695
+ [P in keyof T as T[P] extends unknown[] | Record<string | number | symbol, unknown> ? P : never]?: T[P];
375
696
  };
376
697
  /** Identity type that can be used to get around issues with cycles in bidirectional relations. It will disable reflect-metadata inference. */
377
698
  export type Rel<T> = T;
378
699
  /** Alias for `ScalarReference` (see {@apilink Ref}). */
379
700
  export type ScalarRef<T> = ScalarReference<T>;
380
701
  /** Alias for `Reference<T> & { id: number }` (see {@apilink Ref}). */
381
- export type EntityRef<T extends object> = true extends IsUnknown<PrimaryProperty<T>> ? Reference<T> : IsAny<T> extends true ? Reference<T> : {
382
- [K in PrimaryProperty<T> & keyof T]: T[K];
383
- } & Reference<T>;
702
+ export type EntityRef<T extends object> =
703
+ true extends IsUnknown<PrimaryProperty<T>>
704
+ ? Reference<T>
705
+ : IsAny<T> extends true
706
+ ? Reference<T>
707
+ : {
708
+ [K in PrimaryProperty<T> & keyof T]: T[K];
709
+ } & Reference<T>;
384
710
  /**
385
711
  * Ref type represents a `Reference` instance, and adds the primary keys to its prototype automatically, so you can do
386
712
  * `ref.id` instead of `ref.unwrap().id`. It resolves to either `ScalarRef` or `EntityRef`, based on the type argument.
387
713
  */
388
- export type Ref<T> = T extends any ? IsAny<T> extends true ? Reference<T & object> : T extends Scalar ? ScalarReference<T> : EntityRef<T & object> : never;
389
- type ExtractHiddenProps<T> = (T extends {
390
- [HiddenProps]?: infer K;
391
- } ? K : never) | ({
392
- [K in keyof T]: T[K] extends Primitive ? (T[K] extends Hidden ? K : never) : never;
393
- }[keyof T] & {});
714
+ export type Ref<T> = T extends any
715
+ ? IsAny<T> extends true
716
+ ? Reference<T & object>
717
+ : T extends Scalar
718
+ ? ScalarReference<T>
719
+ : EntityRef<T & object>
720
+ : never;
721
+ type ExtractHiddenProps<T> =
722
+ | (T extends {
723
+ [HiddenProps]?: infer K;
724
+ }
725
+ ? K
726
+ : never)
727
+ | ({
728
+ [K in keyof T]: T[K] extends Primitive ? (T[K] extends Hidden ? K : never) : never;
729
+ }[keyof T] & {});
394
730
  type ExcludeHidden<T, K extends keyof T> = K extends ExtractHiddenProps<T> ? never : K;
395
731
  type ExtractConfig<T> = T extends {
396
- [Config]?: infer K;
397
- } ? K & TypeConfig : TypeConfig;
732
+ [Config]?: infer K;
733
+ }
734
+ ? K & TypeConfig
735
+ : TypeConfig;
398
736
  type PreferExplicitConfig<E, I> = IsNever<E, I, E>;
399
- type PrimaryOrObject<T, U, C extends TypeConfig> = PreferExplicitConfig<C, ExtractConfig<T>>['forceObject'] extends true ? {
400
- [K in PrimaryProperty<U> & keyof U]: U[K];
401
- } : Primary<U>;
402
- type DTOWrapper<T, C extends TypeConfig, Flat extends boolean> = Flat extends true ? EntityDTOFlat<T, C> : EntityDTO<T, C>;
403
- 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
- __serialized?: infer U;
405
- } ? 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;
737
+ type PrimaryOrObject<T, U, C extends TypeConfig> = PreferExplicitConfig<C, ExtractConfig<T>>['forceObject'] extends true
738
+ ? {
739
+ [K in PrimaryProperty<U> & keyof U]: U[K];
740
+ }
741
+ : Primary<U>;
742
+ type DTOWrapper<T, C extends TypeConfig, Flat extends boolean> = Flat extends true
743
+ ? EntityDTOFlat<T, C>
744
+ : EntityDTO<T, C>;
745
+ /** Resolves the serialized (DTO) type for a single entity property. Unwraps references, collections, and custom serialized types. */
746
+ export type EntityDTOProp<E, T, C extends TypeConfig = never, Flat extends boolean = false> = T extends Scalar
747
+ ? T
748
+ : T extends ScalarReference<infer U>
749
+ ? U
750
+ : T extends {
751
+ __serialized?: infer U;
752
+ }
753
+ ? IsUnknown<U> extends false
754
+ ? U
755
+ : T
756
+ : T extends LoadedReferenceShape<infer U>
757
+ ? DTOWrapper<U, C, Flat>
758
+ : T extends ReferenceShape<infer U>
759
+ ? PrimaryOrObject<E, U, C>
760
+ : T extends LoadedCollectionShape<infer U>
761
+ ? DTOWrapper<U & object, C, Flat>[]
762
+ : T extends CollectionShape<infer U>
763
+ ? PrimaryOrObject<E, U & object, C>[]
764
+ : T extends readonly (infer U)[]
765
+ ? U extends Scalar
766
+ ? T
767
+ : EntityDTOProp<E, U, C, Flat>[]
768
+ : T extends Relation<T>
769
+ ? DTOWrapper<T, C, Flat>
770
+ : T;
406
771
  type UnwrapLoadedEntity<T> = T extends {
407
- [__loadedType]?: infer U;
408
- } ? NonNullable<U> : T;
772
+ [__loadedType]?: infer U;
773
+ }
774
+ ? NonNullable<U>
775
+ : T;
409
776
  type DTOProbablyOptionalProps<T> = NonNullable<NullableKeys<UnwrapLoadedEntity<T>, undefined>>;
410
- 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
- type DTORequiredKeys<T, K extends keyof T> = DTOIsOptional<T, K> extends false ? ExcludeHidden<T, K> & CleanKeys<T, K> : never;
412
- type DTOOptionalKeys<T, K extends keyof T> = DTOIsOptional<T, K> extends false ? never : ExcludeHidden<T, K> & CleanKeys<T, K>;
777
+ type DTOIsOptional<T, K extends keyof T> = T[K] extends LoadedCollectionShape
778
+ ? false
779
+ : K extends PrimaryProperty<UnwrapLoadedEntity<T>>
780
+ ? false
781
+ : K extends DTOProbablyOptionalProps<T>
782
+ ? true
783
+ : false;
784
+ type DTORequiredKeys<T, K extends keyof T> =
785
+ DTOIsOptional<T, K> extends false ? ExcludeHidden<T, K> & CleanKeys<T, K> : never;
786
+ type DTOOptionalKeys<T, K extends keyof T> =
787
+ DTOIsOptional<T, K> extends false ? never : ExcludeHidden<T, K> & CleanKeys<T, K>;
788
+ /**
789
+ * Plain object (DTO) representation of an entity as returned by `toObject()` / `toPOJO()`.
790
+ * Unwraps references to PKs, collections to arrays, and respects hidden properties.
791
+ */
413
792
  export type EntityDTO<T, C extends TypeConfig = never> = {
414
- [K in keyof T as DTORequiredKeys<T, K>]: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
793
+ [K in keyof T as DTORequiredKeys<T, K>]: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
415
794
  } & {
416
- [K in keyof T as DTOOptionalKeys<T, K>]?: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
795
+ [K in keyof T as DTOOptionalKeys<T, K>]?: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
417
796
  };
418
797
  /**
419
798
  * @internal
@@ -423,7 +802,7 @@ export type EntityDTO<T, C extends TypeConfig = never> = {
423
802
  * function parameter type where generic assignability checks are needed.
424
803
  */
425
804
  export type EntityDTOFlat<T, C extends TypeConfig = never> = {
426
- [K in keyof T as ExcludeHidden<T, K> & CleanKeys<T, K>]: EntityDTOProp<T, T[K], C, true> | AddOptional<T[K]>;
805
+ [K in keyof T as ExcludeHidden<T, K> & CleanKeys<T, K>]: EntityDTOProp<T, T[K], C, true> | AddOptional<T[K]>;
427
806
  };
428
807
  /**
429
808
  * @internal
@@ -432,28 +811,47 @@ export type EntityDTOFlat<T, C extends TypeConfig = never> = {
432
811
  */
433
812
  type SerializeTopHints<H extends string> = H extends `${infer Top}.${string}` ? Top : H;
434
813
  type SerializeSubHints<K extends string, H extends string> = H extends `${K}.${infer Rest}` ? Rest : never;
435
- 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>;
436
- export type SerializeDTO<T, H extends string = never, E extends string = never, C extends TypeConfig = never> = string extends H ? EntityDTOFlat<T, C> : {
437
- [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
- };
814
+ type SerializePropValue<T, K extends keyof T, H extends string, C extends TypeConfig = never> =
815
+ K & string extends SerializeTopHints<H>
816
+ ? NonNullable<T[K]> extends CollectionShape<infer U>
817
+ ? SerializeDTO<U & object, SerializeSubHints<K & string, H>, never, C>[]
818
+ : SerializeDTO<ExpandProperty<T[K]>, SerializeSubHints<K & string, H>, never, C> | Extract<T[K], null | undefined>
819
+ : EntityDTOProp<T, T[K], C>;
820
+ /**
821
+ * Return type of `serialize()`. Combines Loaded + EntityDTO in a single pass for better performance.
822
+ * Respects populate hints (`H`) and exclude hints (`E`).
823
+ */
824
+ export type SerializeDTO<
825
+ T,
826
+ H extends string = never,
827
+ E extends string = never,
828
+ C extends TypeConfig = never,
829
+ > = string extends H
830
+ ? EntityDTOFlat<T, C>
831
+ : {
832
+ [K in keyof T as ExcludeHidden<T, K> & CleanKeys<T, K> & (IsNever<E> extends true ? K : Exclude<K, E>)]:
833
+ | SerializePropValue<T, K, H, C>
834
+ | Extract<T[K], null | undefined>;
835
+ };
439
836
  type TargetKeys<T> = T extends EntityClass<infer P> ? keyof P : keyof T;
440
837
  type PropertyName<T> = IsUnknown<T> extends false ? TargetKeys<T> : string;
838
+ /** Table reference object passed to formula callbacks, including alias and schema information. */
441
839
  export type FormulaTable = {
442
- alias: string;
443
- name: string;
444
- schema?: string;
445
- qualifiedName: string;
446
- toString: () => string;
840
+ alias: string;
841
+ name: string;
842
+ schema?: string;
843
+ qualifiedName: string;
844
+ toString: () => string;
447
845
  };
448
846
  /**
449
847
  * Table reference for schema callbacks (indexes, checks, generated columns).
450
848
  * Unlike FormulaTable, this has no alias since schema generation doesn't use query aliases.
451
849
  */
452
850
  export type SchemaTable = {
453
- name: string;
454
- schema?: string;
455
- qualifiedName: string;
456
- toString: () => string;
851
+ name: string;
852
+ schema?: string;
853
+ qualifiedName: string;
854
+ toString: () => string;
457
855
  };
458
856
  /**
459
857
  * Column mapping for formula callbacks. Maps property names to fully-qualified alias.fieldName.
@@ -466,7 +864,7 @@ export type SchemaTable = {
466
864
  * formula: cols => `${cols}.first_name || ' ' || ${cols}.last_name`
467
865
  */
468
866
  export type FormulaColumns<T> = Record<PropertyName<T>, string> & {
469
- toString(): string;
867
+ toString(): string;
470
868
  };
471
869
  /**
472
870
  * Column mapping for schema callbacks (indexes, checks, generated columns).
@@ -474,544 +872,712 @@ export type FormulaColumns<T> = Record<PropertyName<T>, string> & {
474
872
  * that belong to the current table (not inherited properties from parent tables).
475
873
  */
476
874
  export type SchemaColumns<T> = Record<PropertyName<T>, string>;
477
- export type IndexCallback<T> = (columns: Record<PropertyName<T>, string>, table: SchemaTable, indexName: string) => string | Raw;
875
+ /** Callback for custom index expressions. Receives column mappings, table info, and the index name. */
876
+ export type IndexCallback<T> = (
877
+ columns: Record<PropertyName<T>, string>,
878
+ table: SchemaTable,
879
+ indexName: string,
880
+ ) => string | Raw;
881
+ /** Callback for computed (formula) properties. Receives column mappings and table info, returns a SQL expression. */
478
882
  export type FormulaCallback<T> = (columns: FormulaColumns<T>, table: FormulaTable) => string | Raw;
883
+ /** Callback for CHECK constraint expressions. Receives column mappings and table info. */
479
884
  export type CheckCallback<T> = (columns: Record<PropertyName<T>, string>, table: SchemaTable) => string | Raw;
885
+ /** Callback for generated (computed) column expressions. Receives column mappings and table info. */
480
886
  export type GeneratedColumnCallback<T> = (columns: Record<PropertyName<T>, string>, table: SchemaTable) => string | Raw;
887
+ /** Definition of a CHECK constraint on a table or property. */
481
888
  export interface CheckConstraint<T = any> {
482
- name?: string;
483
- property?: string;
484
- expression: string | Raw | CheckCallback<T>;
889
+ name?: string;
890
+ property?: string;
891
+ expression: string | Raw | CheckCallback<T>;
485
892
  }
893
+ /** Branded string that accepts any string value while preserving autocompletion for known literals. */
486
894
  export type AnyString = string & {};
895
+ /** Describes a single property (column, relation, or embedded) within an entity's metadata. */
487
896
  export interface EntityProperty<Owner = any, Target = any> {
488
- name: EntityKey<Owner>;
489
- entity: () => EntityName<Owner>;
490
- target: EntityClass<Target>;
491
- type: keyof typeof types | AnyString;
492
- runtimeType: 'number' | 'string' | 'boolean' | 'bigint' | 'Buffer' | 'Date' | 'object' | 'any' | AnyString;
493
- targetMeta?: EntityMetadata<Target>;
494
- columnTypes: string[];
495
- generated?: string | Raw | GeneratedColumnCallback<Owner>;
496
- customType?: Type<any>;
497
- customTypes: (Type<any> | undefined)[];
498
- hasConvertToJSValueSQL: boolean;
499
- hasConvertToDatabaseValueSQL: boolean;
500
- autoincrement?: boolean;
501
- returning?: boolean;
502
- primary?: boolean;
503
- serializedPrimaryKey: boolean;
504
- groups?: string[];
505
- lazy?: boolean;
506
- array?: boolean;
507
- length?: number;
508
- precision?: number;
509
- scale?: number;
510
- kind: ReferenceKind;
511
- ref?: boolean;
512
- fieldNames: string[];
513
- fieldNameRaw?: string;
514
- default?: string | number | boolean | null;
515
- defaultRaw?: string;
516
- formula?: FormulaCallback<Owner>;
517
- filters?: FilterOptions;
518
- prefix?: string | boolean;
519
- prefixMode?: EmbeddedPrefixMode;
520
- embedded?: [EntityKey<Owner>, EntityKey<Owner>];
521
- embeddedPath?: string[];
522
- embeddable: EntityClass<Owner>;
523
- embeddedProps: Dictionary<EntityProperty>;
524
- discriminatorColumn?: string;
525
- discriminator?: string;
526
- polymorphic?: boolean;
527
- polymorphTargets?: EntityMetadata[];
528
- discriminatorMap?: Dictionary<EntityClass<Target>>;
529
- discriminatorValue?: string;
530
- object?: boolean;
531
- index?: boolean | string;
532
- unique?: boolean | string;
533
- nullable?: boolean;
534
- inherited?: boolean;
535
- renamedFrom?: string;
536
- stiMerged?: boolean;
537
- stiFieldNames?: string[];
538
- stiFieldNameMap?: Dictionary<string>;
539
- unsigned?: boolean;
540
- mapToPk?: boolean;
541
- persist?: boolean;
542
- hydrate?: boolean;
543
- hidden?: boolean;
544
- enum?: boolean;
545
- items?: (number | string)[];
546
- nativeEnumName?: string;
547
- version?: boolean;
548
- concurrencyCheck?: boolean;
549
- eager?: boolean;
550
- setter?: boolean;
551
- getter?: boolean;
552
- getterName?: keyof Owner;
553
- accessor?: EntityKey<Owner>;
554
- cascade: Cascade[];
555
- orphanRemoval?: boolean;
556
- onCreate?: (entity: Owner, em: EntityManager) => any;
557
- onUpdate?: (entity: Owner, em: EntityManager) => any;
558
- deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
559
- updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
560
- strategy?: LoadStrategy;
561
- owner: boolean;
562
- inversedBy: EntityKey<Target>;
563
- mappedBy: EntityKey<Target>;
564
- where?: FilterQuery<Target>;
565
- orderBy?: QueryOrderMap<Owner> | QueryOrderMap<Owner>[];
566
- customOrder?: string[] | number[] | boolean[];
567
- fixedOrder?: boolean;
568
- fixedOrderColumn?: string;
569
- pivotTable: string;
570
- pivotEntity: EntityClass<Target>;
571
- joinColumns: string[];
572
- ownColumns: string[];
573
- inverseJoinColumns: string[];
574
- referencedColumnNames: string[];
575
- referencedTableName: string;
576
- referencedPKs: EntityKey<Owner>[];
577
- targetKey?: string;
578
- serializer?: (value: any, options?: SerializeOptions<any>) => any;
579
- serializedName?: string;
580
- comment?: string;
581
- /** mysql only */
582
- extra?: string;
583
- userDefined?: boolean;
584
- optional?: boolean;
585
- ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
586
- deferMode?: DeferMode;
587
- createForeignKeyConstraint: boolean;
588
- foreignKeyName?: string;
897
+ name: EntityKey<Owner>;
898
+ entity: () => EntityName<Owner>;
899
+ target: EntityClass<Target>;
900
+ type: keyof typeof types | AnyString;
901
+ runtimeType: 'number' | 'string' | 'boolean' | 'bigint' | 'Buffer' | 'Date' | 'object' | 'any' | AnyString;
902
+ targetMeta?: EntityMetadata<Target>;
903
+ columnTypes: string[];
904
+ generated?: string | Raw | GeneratedColumnCallback<Owner>;
905
+ customType?: Type<any>;
906
+ customTypes: (Type<any> | undefined)[];
907
+ hasConvertToJSValueSQL: boolean;
908
+ hasConvertToDatabaseValueSQL: boolean;
909
+ autoincrement?: boolean;
910
+ returning?: boolean;
911
+ primary?: boolean;
912
+ serializedPrimaryKey: boolean;
913
+ groups?: string[];
914
+ lazy?: boolean;
915
+ array?: boolean;
916
+ length?: number;
917
+ precision?: number;
918
+ scale?: number;
919
+ kind: ReferenceKind;
920
+ ref?: boolean;
921
+ fieldNames: string[];
922
+ fieldNameRaw?: string;
923
+ default?: string | number | boolean | null;
924
+ defaultRaw?: string;
925
+ formula?: FormulaCallback<Owner>;
926
+ filters?: FilterOptions;
927
+ prefix?: string | boolean;
928
+ prefixMode?: EmbeddedPrefixMode;
929
+ embedded?: [EntityKey<Owner>, EntityKey<Owner>];
930
+ embeddedPath?: string[];
931
+ embeddable: EntityClass<Owner>;
932
+ embeddedProps: Dictionary<EntityProperty>;
933
+ discriminatorColumn?: string;
934
+ discriminator?: string;
935
+ polymorphic?: boolean;
936
+ polymorphTargets?: EntityMetadata[];
937
+ discriminatorMap?: Dictionary<EntityClass<Target>>;
938
+ discriminatorValue?: string;
939
+ object?: boolean;
940
+ index?: boolean | string;
941
+ unique?: boolean | string;
942
+ nullable?: boolean;
943
+ inherited?: boolean;
944
+ renamedFrom?: string;
945
+ stiMerged?: boolean;
946
+ stiFieldNames?: string[];
947
+ stiFieldNameMap?: Dictionary<string>;
948
+ unsigned?: boolean;
949
+ mapToPk?: boolean;
950
+ persist?: boolean;
951
+ hydrate?: boolean;
952
+ hidden?: boolean;
953
+ enum?: boolean;
954
+ items?: (number | string)[];
955
+ nativeEnumName?: string;
956
+ version?: boolean;
957
+ concurrencyCheck?: boolean;
958
+ eager?: boolean;
959
+ setter?: boolean;
960
+ getter?: boolean;
961
+ getterName?: keyof Owner;
962
+ accessor?: EntityKey<Owner>;
963
+ cascade: Cascade[];
964
+ orphanRemoval?: boolean;
965
+ onCreate?: (entity: Owner, em: EntityManager) => any;
966
+ onUpdate?: (entity: Owner, em: EntityManager) => any;
967
+ deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
968
+ updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
969
+ strategy?: LoadStrategy;
970
+ owner: boolean;
971
+ inversedBy: EntityKey<Target>;
972
+ mappedBy: EntityKey<Target>;
973
+ where?: FilterQuery<Target>;
974
+ orderBy?: QueryOrderMap<Owner> | QueryOrderMap<Owner>[];
975
+ customOrder?: string[] | number[] | boolean[];
976
+ fixedOrder?: boolean;
977
+ fixedOrderColumn?: string;
978
+ pivotTable: string;
979
+ pivotEntity: EntityClass<Target>;
980
+ joinColumns: string[];
981
+ ownColumns: string[];
982
+ inverseJoinColumns: string[];
983
+ referencedColumnNames: string[];
984
+ referencedTableName: string;
985
+ referencedPKs: EntityKey<Owner>[];
986
+ targetKey?: string;
987
+ serializer?: (value: any, options?: SerializeOptions<any>) => any;
988
+ serializedName?: string;
989
+ comment?: string;
990
+ /** mysql only */
991
+ extra?: string;
992
+ userDefined?: boolean;
993
+ optional?: boolean;
994
+ ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
995
+ deferMode?: DeferMode;
996
+ createForeignKeyConstraint: boolean;
997
+ foreignKeyName?: string;
589
998
  }
999
+ /**
1000
+ * Runtime metadata for an entity, holding its properties, relations, indexes, hooks, and more.
1001
+ * Created during metadata discovery and used throughout the ORM lifecycle.
1002
+ */
590
1003
  export declare class EntityMetadata<Entity = any, Class extends EntityCtor<Entity> = EntityCtor<Entity>> {
591
- private static counter;
592
- readonly _id: number;
593
- readonly propertyOrder: Map<string, number>;
594
- constructor(meta?: Partial<EntityMetadata>);
595
- addProperty(prop: Partial<EntityProperty<Entity>>): void;
596
- removeProperty(name: string, sync?: boolean): void;
597
- getPrimaryProps(flatten?: boolean): EntityProperty<Entity>[];
598
- getPrimaryProp(): EntityProperty<Entity>;
599
- /**
600
- * Creates a mapping from property names to field names.
601
- * @param alias - Optional alias to prefix field names. Can be a string (same for all) or a function (per-property).
602
- * When provided, also adds toString() returning the alias for backwards compatibility with formulas.
603
- * @param toStringAlias - Optional alias to return from toString(). Defaults to `alias` when it's a string.
604
- */
605
- createColumnMappingObject(alias?: string | ((prop: EntityProperty<Entity>) => string), toStringAlias?: string): FormulaColumns<Entity>;
606
- /**
607
- * Creates a column mapping for schema callbacks (indexes, checks, generated columns).
608
- * For TPT entities, only includes properties that belong to the current table (ownProps).
609
- */
610
- createSchemaColumnMappingObject(): SchemaColumns<Entity>;
611
- get tableName(): string;
612
- set tableName(name: string);
613
- get uniqueName(): string;
614
- sync(initIndexes?: boolean, config?: Configuration): void;
615
- private initIndexes;
616
- /** @internal */
617
- clone(): this;
1004
+ private static counter;
1005
+ readonly _id: number;
1006
+ readonly propertyOrder: Map<string, number>;
1007
+ constructor(meta?: Partial<EntityMetadata>);
1008
+ addProperty(prop: Partial<EntityProperty<Entity>>): void;
1009
+ removeProperty(name: string, sync?: boolean): void;
1010
+ getPrimaryProps(flatten?: boolean): EntityProperty<Entity>[];
1011
+ getPrimaryProp(): EntityProperty<Entity>;
1012
+ /**
1013
+ * Creates a mapping from property names to field names.
1014
+ * @param alias - Optional alias to prefix field names. Can be a string (same for all) or a function (per-property).
1015
+ * When provided, also adds toString() returning the alias for backwards compatibility with formulas.
1016
+ * @param toStringAlias - Optional alias to return from toString(). Defaults to `alias` when it's a string.
1017
+ */
1018
+ createColumnMappingObject(
1019
+ alias?: string | ((prop: EntityProperty<Entity>) => string),
1020
+ toStringAlias?: string,
1021
+ ): FormulaColumns<Entity>;
1022
+ /**
1023
+ * Creates a column mapping for schema callbacks (indexes, checks, generated columns).
1024
+ * For TPT entities, only includes properties that belong to the current table (ownProps).
1025
+ */
1026
+ createSchemaColumnMappingObject(): SchemaColumns<Entity>;
1027
+ get tableName(): string;
1028
+ set tableName(name: string);
1029
+ get uniqueName(): string;
1030
+ sync(initIndexes?: boolean, config?: Configuration): void;
1031
+ private initIndexes;
1032
+ /** @internal */
1033
+ clone(): this;
618
1034
  }
1035
+ /** Minimal column metadata with just a name and database type. */
619
1036
  export interface SimpleColumnMeta {
620
- name: string;
621
- type: string;
1037
+ name: string;
1038
+ type: string;
622
1039
  }
1040
+ /** Abstract constructor type that matches both abstract and concrete entity classes. */
623
1041
  export type EntityCtor<T = any> = abstract new (...args: any[]) => T;
624
1042
  export interface EntityMetadata<Entity = any, Class extends EntityCtor<Entity> = EntityCtor<Entity>> {
625
- name?: string;
626
- className: string;
627
- tableName: string;
628
- schema?: string;
629
- pivotTable?: boolean;
630
- virtual?: boolean;
631
- /** True if this entity represents a database view (not a virtual entity). Accepts `{ materialized: true }` as input, normalized to `true` during sync. */
632
- view?: boolean | {
1043
+ name?: string;
1044
+ className: string;
1045
+ tableName: string;
1046
+ schema?: string;
1047
+ pivotTable?: boolean;
1048
+ virtual?: boolean;
1049
+ /** True if this entity represents a database view (not a virtual entity). Accepts `{ materialized: true }` as input, normalized to `true` during sync. */
1050
+ view?:
1051
+ | boolean
1052
+ | {
633
1053
  materialized?: boolean;
634
1054
  withData?: boolean;
635
- };
636
- /** True if this is a materialized view (PostgreSQL only). Requires `view: true`. */
637
- materialized?: boolean;
638
- /** For materialized views, whether data is populated on creation. Defaults to true. */
639
- withData?: boolean;
640
- expression?: string | ((em: any, where: ObjectQuery<Entity>, options: FindOptions<Entity, any, any, any>, stream?: boolean) => MaybePromise<Raw | object | string>);
641
- discriminatorColumn?: EntityKey<Entity> | AnyString;
642
- discriminatorValue?: number | string;
643
- discriminatorMap?: Dictionary<EntityClass>;
644
- embeddable: boolean;
645
- constructorParams?: (keyof Entity)[];
646
- forceConstructor: boolean;
647
- extends?: EntityName<Entity>;
648
- collection: string;
649
- path: string;
650
- primaryKeys: EntityKey<Entity>[];
651
- simplePK: boolean;
652
- compositePK: boolean;
653
- versionProperty: EntityKey<Entity>;
654
- concurrencyCheckKeys: Set<EntityKey<Entity>>;
655
- serializedPrimaryKey?: EntityKey<Entity>;
656
- properties: {
657
- [K in EntityKey<Entity>]: EntityProperty<Entity>;
658
- };
659
- props: EntityProperty<Entity>[];
660
- relations: EntityProperty<Entity>[];
661
- bidirectionalRelations: EntityProperty<Entity>[];
662
- referencingProperties: {
663
- meta: EntityMetadata<Entity>;
664
- prop: EntityProperty<Entity>;
665
- }[];
666
- comparableProps: EntityProperty<Entity>[];
667
- trackingProps: EntityProperty<Entity>[];
668
- hydrateProps: EntityProperty<Entity>[];
669
- validateProps: EntityProperty<Entity>[];
670
- uniqueProps: EntityProperty<Entity>[];
671
- getterProps: EntityProperty<Entity>[];
672
- indexes: {
673
- properties?: EntityKey<Entity> | EntityKey<Entity>[];
674
- name?: string;
675
- type?: string;
676
- options?: Dictionary;
677
- expression?: string | IndexCallback<Entity>;
678
- columns?: IndexColumnOptions[];
679
- include?: EntityKey<Entity> | EntityKey<Entity>[];
680
- fillFactor?: number;
681
- invisible?: boolean;
682
- disabled?: boolean;
683
- clustered?: boolean;
684
- }[];
685
- uniques: {
686
- properties?: EntityKey<Entity> | EntityKey<Entity>[];
687
- name?: string;
688
- options?: Dictionary;
689
- expression?: string | IndexCallback<Entity>;
690
- deferMode?: DeferMode | `${DeferMode}`;
691
- columns?: IndexColumnOptions[];
692
- include?: EntityKey<Entity> | EntityKey<Entity>[];
693
- fillFactor?: number;
694
- disabled?: boolean;
695
- }[];
696
- checks: CheckConstraint<Entity>[];
697
- repositoryClass?: string;
698
- repository: () => EntityClass<EntityRepository<any>>;
699
- hooks: {
700
- [K in EventType]?: (keyof Entity | EventSubscriber<Entity>[EventType])[];
701
- };
702
- prototype: Entity;
703
- class: Class;
704
- abstract: boolean;
705
- filters: Dictionary<FilterDef>;
706
- comment?: string;
707
- selfReferencing?: boolean;
708
- hasUniqueProps?: boolean;
709
- readonly?: boolean;
710
- polymorphs?: EntityMetadata[];
711
- root: EntityMetadata<Entity>;
712
- definedProperties: Dictionary;
713
- /** For polymorphic M:N pivot tables, maps discriminator values to entity classes */
714
- polymorphicDiscriminatorMap?: Dictionary<EntityClass>;
715
- /** Inheritance type: 'sti' (Single Table Inheritance) or 'tpt' (Table-Per-Type). Only set on root entities. */
716
- inheritanceType?: 'sti' | 'tpt';
717
- /** For TPT: direct parent entity metadata (the entity this one extends). */
718
- tptParent?: EntityMetadata;
719
- /** For TPT: direct child entities (entities that extend this one). */
720
- tptChildren?: EntityMetadata[];
721
- /** For TPT: all non-abstract descendants, sorted by depth (deepest first). Precomputed during discovery. */
722
- allTPTDescendants?: EntityMetadata[];
723
- /** For TPT: synthetic property representing the join to the parent table (child PK → parent PK). */
724
- tptParentProp?: EntityProperty;
725
- /** For TPT: inverse of tptParentProp, used for joining from parent to child (parent PK → child PK). */
726
- tptInverseProp?: EntityProperty;
727
- /** For TPT: virtual discriminator property name (computed at query time, not persisted). */
728
- tptDiscriminatorColumn?: string;
729
- /** For TPT: properties defined only in THIS entity (not inherited from parent). */
730
- ownProps?: EntityProperty<Entity>[];
731
- hasTriggers?: boolean;
732
- /**
733
- * Default ordering for this entity. Applied when querying this entity directly
734
- * or when it's populated as a relation. Combined with other orderings based on precedence.
735
- */
736
- orderBy?: QueryOrderMap<Entity> | QueryOrderMap<Entity>[];
737
- /** @internal can be used for computed numeric cache keys */
738
- readonly _id: number;
1055
+ };
1056
+ /** True if this is a materialized view (PostgreSQL only). Requires `view: true`. */
1057
+ materialized?: boolean;
1058
+ /** For materialized views, whether data is populated on creation. Defaults to true. */
1059
+ withData?: boolean;
1060
+ expression?:
1061
+ | string
1062
+ | ((
1063
+ em: any,
1064
+ where: ObjectQuery<Entity>,
1065
+ options: FindOptions<Entity, any, any, any>,
1066
+ stream?: boolean,
1067
+ ) => MaybePromise<Raw | object | string>);
1068
+ discriminatorColumn?: EntityKey<Entity> | AnyString;
1069
+ discriminatorValue?: number | string;
1070
+ discriminatorMap?: Dictionary<EntityClass>;
1071
+ embeddable: boolean;
1072
+ constructorParams?: (keyof Entity)[];
1073
+ forceConstructor: boolean;
1074
+ extends?: EntityName<Entity>;
1075
+ collection: string;
1076
+ path: string;
1077
+ primaryKeys: EntityKey<Entity>[];
1078
+ simplePK: boolean;
1079
+ compositePK: boolean;
1080
+ versionProperty: EntityKey<Entity>;
1081
+ concurrencyCheckKeys: Set<EntityKey<Entity>>;
1082
+ serializedPrimaryKey?: EntityKey<Entity>;
1083
+ properties: {
1084
+ [K in EntityKey<Entity>]: EntityProperty<Entity>;
1085
+ };
1086
+ props: EntityProperty<Entity>[];
1087
+ relations: EntityProperty<Entity>[];
1088
+ bidirectionalRelations: EntityProperty<Entity>[];
1089
+ referencingProperties: {
1090
+ meta: EntityMetadata<Entity>;
1091
+ prop: EntityProperty<Entity>;
1092
+ }[];
1093
+ comparableProps: EntityProperty<Entity>[];
1094
+ trackingProps: EntityProperty<Entity>[];
1095
+ hydrateProps: EntityProperty<Entity>[];
1096
+ validateProps: EntityProperty<Entity>[];
1097
+ uniqueProps: EntityProperty<Entity>[];
1098
+ getterProps: EntityProperty<Entity>[];
1099
+ indexes: {
1100
+ properties?: EntityKey<Entity> | EntityKey<Entity>[];
1101
+ name?: string;
1102
+ type?: string;
1103
+ options?: Dictionary;
1104
+ expression?: string | IndexCallback<Entity>;
1105
+ columns?: IndexColumnOptions[];
1106
+ include?: EntityKey<Entity> | EntityKey<Entity>[];
1107
+ fillFactor?: number;
1108
+ invisible?: boolean;
1109
+ disabled?: boolean;
1110
+ clustered?: boolean;
1111
+ }[];
1112
+ uniques: {
1113
+ properties?: EntityKey<Entity> | EntityKey<Entity>[];
1114
+ name?: string;
1115
+ options?: Dictionary;
1116
+ expression?: string | IndexCallback<Entity>;
1117
+ deferMode?: DeferMode | `${DeferMode}`;
1118
+ columns?: IndexColumnOptions[];
1119
+ include?: EntityKey<Entity> | EntityKey<Entity>[];
1120
+ fillFactor?: number;
1121
+ disabled?: boolean;
1122
+ }[];
1123
+ checks: CheckConstraint<Entity>[];
1124
+ repositoryClass?: string;
1125
+ repository: () => EntityClass<EntityRepository<any>>;
1126
+ hooks: {
1127
+ [K in EventType]?: (keyof Entity | EventSubscriber<Entity>[EventType])[];
1128
+ };
1129
+ prototype: Entity;
1130
+ class: Class;
1131
+ abstract: boolean;
1132
+ filters: Dictionary<FilterDef>;
1133
+ comment?: string;
1134
+ selfReferencing?: boolean;
1135
+ hasUniqueProps?: boolean;
1136
+ readonly?: boolean;
1137
+ polymorphs?: EntityMetadata[];
1138
+ root: EntityMetadata<Entity>;
1139
+ definedProperties: Dictionary;
1140
+ /** For polymorphic M:N pivot tables, maps discriminator values to entity classes */
1141
+ polymorphicDiscriminatorMap?: Dictionary<EntityClass>;
1142
+ /** Inheritance type: 'sti' (Single Table Inheritance) or 'tpt' (Table-Per-Type). Only set on root entities. */
1143
+ inheritanceType?: 'sti' | 'tpt';
1144
+ /** For TPT: direct parent entity metadata (the entity this one extends). */
1145
+ tptParent?: EntityMetadata;
1146
+ /** For TPT: direct child entities (entities that extend this one). */
1147
+ tptChildren?: EntityMetadata[];
1148
+ /** For TPT: all non-abstract descendants, sorted by depth (deepest first). Precomputed during discovery. */
1149
+ allTPTDescendants?: EntityMetadata[];
1150
+ /** For TPT: synthetic property representing the join to the parent table (child PK → parent PK). */
1151
+ tptParentProp?: EntityProperty;
1152
+ /** For TPT: inverse of tptParentProp, used for joining from parent to child (parent PK → child PK). */
1153
+ tptInverseProp?: EntityProperty;
1154
+ /** For TPT: virtual discriminator property name (computed at query time, not persisted). */
1155
+ tptDiscriminatorColumn?: string;
1156
+ /** For TPT: properties defined only in THIS entity (not inherited from parent). */
1157
+ ownProps?: EntityProperty<Entity>[];
1158
+ hasTriggers?: boolean;
1159
+ /**
1160
+ * Default ordering for this entity. Applied when querying this entity directly
1161
+ * or when it's populated as a relation. Combined with other orderings based on precedence.
1162
+ */
1163
+ orderBy?: QueryOrderMap<Entity> | QueryOrderMap<Entity>[];
1164
+ /** @internal can be used for computed numeric cache keys */
1165
+ readonly _id: number;
739
1166
  }
1167
+ /** Options for `ISchemaGenerator.create()`. */
740
1168
  export interface CreateSchemaOptions {
741
- wrap?: boolean;
742
- schema?: string;
1169
+ wrap?: boolean;
1170
+ schema?: string;
743
1171
  }
1172
+ /** Options for `ISchemaGenerator.clear()` to truncate/clear database tables. */
744
1173
  export interface ClearDatabaseOptions {
745
- schema?: string;
746
- truncate?: boolean;
747
- clearIdentityMap?: boolean;
1174
+ schema?: string;
1175
+ truncate?: boolean;
1176
+ clearIdentityMap?: boolean;
748
1177
  }
1178
+ /** Options for `ISchemaGenerator.ensureDatabase()` which creates and optionally clears the database. */
749
1179
  export interface EnsureDatabaseOptions extends CreateSchemaOptions, ClearDatabaseOptions {
750
- clear?: boolean;
751
- create?: boolean;
752
- forceCheck?: boolean;
1180
+ clear?: boolean;
1181
+ create?: boolean;
1182
+ forceCheck?: boolean;
753
1183
  }
1184
+ /** Options for `ISchemaGenerator.drop()`. */
754
1185
  export interface DropSchemaOptions {
755
- wrap?: boolean;
756
- dropMigrationsTable?: boolean;
757
- dropForeignKeys?: boolean;
758
- dropDb?: boolean;
759
- schema?: string;
1186
+ wrap?: boolean;
1187
+ dropMigrationsTable?: boolean;
1188
+ dropForeignKeys?: boolean;
1189
+ dropDb?: boolean;
1190
+ schema?: string;
760
1191
  }
1192
+ /** Options for `ISchemaGenerator.update()` to apply incremental schema changes. */
761
1193
  export interface UpdateSchemaOptions<DatabaseSchema = unknown> {
762
- wrap?: boolean;
763
- safe?: boolean;
764
- dropDb?: boolean;
765
- dropTables?: boolean;
766
- schema?: string;
767
- fromSchema?: DatabaseSchema;
1194
+ wrap?: boolean;
1195
+ safe?: boolean;
1196
+ dropDb?: boolean;
1197
+ dropTables?: boolean;
1198
+ schema?: string;
1199
+ fromSchema?: DatabaseSchema;
768
1200
  }
1201
+ /** Options for `ISchemaGenerator.refresh()` which drops and recreates the schema. */
769
1202
  export interface RefreshDatabaseOptions extends CreateSchemaOptions {
770
- ensureIndexes?: boolean;
771
- dropDb?: boolean;
772
- createSchema?: boolean;
1203
+ ensureIndexes?: boolean;
1204
+ dropDb?: boolean;
1205
+ createSchema?: boolean;
773
1206
  }
1207
+ /** Interface for the schema generator, responsible for creating, updating, and dropping database schemas. */
774
1208
  export interface ISchemaGenerator {
775
- create(options?: CreateSchemaOptions): Promise<void>;
776
- update(options?: UpdateSchemaOptions): Promise<void>;
777
- drop(options?: DropSchemaOptions): Promise<void>;
778
- refresh(options?: RefreshDatabaseOptions): Promise<void>;
779
- clear(options?: ClearDatabaseOptions): Promise<void>;
780
- execute(sql: string, options?: {
781
- wrap?: boolean;
782
- }): Promise<void>;
783
- getCreateSchemaSQL(options?: CreateSchemaOptions): Promise<string>;
784
- getDropSchemaSQL(options?: Omit<DropSchemaOptions, 'dropDb'>): Promise<string>;
785
- getUpdateSchemaSQL(options?: UpdateSchemaOptions): Promise<string>;
786
- getUpdateSchemaMigrationSQL(options?: UpdateSchemaOptions): Promise<{
787
- up: string;
788
- down: string;
789
- }>;
790
- ensureDatabase(options?: EnsureDatabaseOptions): Promise<boolean>;
791
- createDatabase(name?: string): Promise<void>;
792
- dropDatabase(name?: string): Promise<void>;
793
- ensureIndexes(): Promise<void>;
1209
+ create(options?: CreateSchemaOptions): Promise<void>;
1210
+ update(options?: UpdateSchemaOptions): Promise<void>;
1211
+ drop(options?: DropSchemaOptions): Promise<void>;
1212
+ refresh(options?: RefreshDatabaseOptions): Promise<void>;
1213
+ clear(options?: ClearDatabaseOptions): Promise<void>;
1214
+ execute(
1215
+ sql: string,
1216
+ options?: {
1217
+ wrap?: boolean;
1218
+ },
1219
+ ): Promise<void>;
1220
+ getCreateSchemaSQL(options?: CreateSchemaOptions): Promise<string>;
1221
+ getDropSchemaSQL(options?: Omit<DropSchemaOptions, 'dropDb'>): Promise<string>;
1222
+ getUpdateSchemaSQL(options?: UpdateSchemaOptions): Promise<string>;
1223
+ getUpdateSchemaMigrationSQL(options?: UpdateSchemaOptions): Promise<{
1224
+ up: string;
1225
+ down: string;
1226
+ }>;
1227
+ ensureDatabase(options?: EnsureDatabaseOptions): Promise<boolean>;
1228
+ createDatabase(name?: string): Promise<void>;
1229
+ dropDatabase(name?: string): Promise<void>;
1230
+ ensureIndexes(): Promise<void>;
794
1231
  }
795
- export type ImportsResolver = (alias: string, basePath: string, extension: '.js' | '', originFileName: string) => {
796
- path: string;
797
- name: string;
798
- } | undefined;
1232
+ /** Custom resolver for import paths in the entity generator. Returns a path/name pair or undefined to use the default. */
1233
+ export type ImportsResolver = (
1234
+ alias: string,
1235
+ basePath: string,
1236
+ extension: '.js' | '',
1237
+ originFileName: string,
1238
+ ) =>
1239
+ | {
1240
+ path: string;
1241
+ name: string;
1242
+ }
1243
+ | undefined;
1244
+ /** Options for the entity generator (`IEntityGenerator.generate()`). Controls output format, filtering, and style. */
799
1245
  export interface GenerateOptions {
800
- path?: string;
801
- save?: boolean;
802
- schema?: string;
803
- takeTables?: (RegExp | string)[];
804
- skipTables?: (RegExp | string)[];
805
- skipColumns?: Dictionary<(RegExp | string)[]>;
806
- forceUndefined?: boolean;
807
- undefinedDefaults?: boolean;
808
- bidirectionalRelations?: boolean;
809
- identifiedReferences?: boolean;
810
- entityDefinition?: 'decorators' | 'defineEntity' | 'entitySchema';
811
- decorators?: 'es' | 'legacy';
812
- inferEntityType?: boolean;
813
- enumMode?: 'ts-enum' | 'union-type' | 'dictionary';
814
- esmImport?: boolean;
815
- scalarTypeInDecorator?: boolean;
816
- scalarPropertiesForRelations?: 'always' | 'never' | 'smart';
817
- fileName?: (className: string) => string;
818
- onImport?: ImportsResolver;
819
- extraImports?: (basePath: string, originFileName: string) => string[] | undefined;
820
- onlyPurePivotTables?: boolean;
821
- outputPurePivotTables?: boolean;
822
- readOnlyPivotTables?: boolean;
823
- customBaseEntityName?: string;
824
- useCoreBaseEntity?: boolean;
825
- coreImportsPrefix?: string;
826
- onInitialMetadata?: MetadataProcessor;
827
- onProcessedMetadata?: MetadataProcessor;
1246
+ path?: string;
1247
+ save?: boolean;
1248
+ schema?: string;
1249
+ takeTables?: (RegExp | string)[];
1250
+ skipTables?: (RegExp | string)[];
1251
+ skipColumns?: Dictionary<(RegExp | string)[]>;
1252
+ forceUndefined?: boolean;
1253
+ undefinedDefaults?: boolean;
1254
+ bidirectionalRelations?: boolean;
1255
+ identifiedReferences?: boolean;
1256
+ entityDefinition?: 'decorators' | 'defineEntity' | 'entitySchema';
1257
+ decorators?: 'es' | 'legacy';
1258
+ inferEntityType?: boolean;
1259
+ enumMode?: 'ts-enum' | 'union-type' | 'dictionary';
1260
+ esmImport?: boolean;
1261
+ scalarTypeInDecorator?: boolean;
1262
+ scalarPropertiesForRelations?: 'always' | 'never' | 'smart';
1263
+ fileName?: (className: string) => string;
1264
+ onImport?: ImportsResolver;
1265
+ extraImports?: (basePath: string, originFileName: string) => string[] | undefined;
1266
+ onlyPurePivotTables?: boolean;
1267
+ outputPurePivotTables?: boolean;
1268
+ readOnlyPivotTables?: boolean;
1269
+ customBaseEntityName?: string;
1270
+ useCoreBaseEntity?: boolean;
1271
+ coreImportsPrefix?: string;
1272
+ onInitialMetadata?: MetadataProcessor;
1273
+ onProcessedMetadata?: MetadataProcessor;
828
1274
  }
1275
+ /** Interface for the entity generator, which reverse-engineers database schema into entity source files. */
829
1276
  export interface IEntityGenerator {
830
- generate(options?: GenerateOptions): Promise<string[]>;
1277
+ generate(options?: GenerateOptions): Promise<string[]>;
831
1278
  }
1279
+ /** Basic migration descriptor with a name and optional file path. */
832
1280
  export type MigrationInfo = {
833
- name: string;
834
- path?: string;
1281
+ name: string;
1282
+ path?: string;
835
1283
  };
1284
+ /** Options for controlling which migrations to run (range, specific list, or transaction). */
836
1285
  export type MigrateOptions = {
837
- from?: string | number;
838
- to?: string | number;
839
- migrations?: string[];
840
- transaction?: Transaction;
1286
+ from?: string | number;
1287
+ to?: string | number;
1288
+ migrations?: string[];
1289
+ transaction?: Transaction;
841
1290
  };
1291
+ /** Result of creating a new migration file, including the generated code and schema diff. */
842
1292
  export type MigrationResult = {
843
- fileName: string;
844
- code: string;
845
- diff: MigrationDiff;
1293
+ fileName: string;
1294
+ code: string;
1295
+ diff: MigrationDiff;
846
1296
  };
1297
+ /** A row from the migrations tracking table, representing an executed migration. */
847
1298
  export type MigrationRow = {
848
- id: number;
849
- name: string;
850
- executed_at: Date;
1299
+ id: number;
1300
+ name: string;
1301
+ executed_at: Date;
851
1302
  };
852
1303
  /**
853
1304
  * @internal
854
1305
  */
855
1306
  export interface IMigrationRunner {
856
- run(migration: Migration, method: 'up' | 'down'): Promise<void>;
857
- setMasterMigration(trx: Transaction): void;
858
- unsetMasterMigration(): void;
1307
+ run(migration: Migration, method: 'up' | 'down'): Promise<void>;
1308
+ setMasterMigration(trx: Transaction): void;
1309
+ unsetMasterMigration(): void;
859
1310
  }
860
1311
  /**
861
1312
  * @internal
862
1313
  */
863
1314
  export interface IMigratorStorage {
864
- executed(): Promise<string[]>;
865
- logMigration(params: Dictionary): Promise<void>;
866
- unlogMigration(params: Dictionary): Promise<void>;
867
- getExecutedMigrations(): Promise<MigrationRow[]>;
868
- ensureTable?(): Promise<void>;
869
- setMasterMigration(trx: Transaction): void;
870
- unsetMasterMigration(): void;
871
- getMigrationName(name: string): string;
872
- getTableName?(): {
873
- schemaName?: string;
874
- tableName: string;
875
- };
1315
+ executed(): Promise<string[]>;
1316
+ logMigration(params: Dictionary): Promise<void>;
1317
+ unlogMigration(params: Dictionary): Promise<void>;
1318
+ getExecutedMigrations(): Promise<MigrationRow[]>;
1319
+ ensureTable?(): Promise<void>;
1320
+ setMasterMigration(trx: Transaction): void;
1321
+ unsetMasterMigration(): void;
1322
+ getMigrationName(name: string): string;
1323
+ getTableName?(): {
1324
+ schemaName?: string;
1325
+ tableName: string;
1326
+ };
876
1327
  }
1328
+ /** Interface for the migrator, responsible for creating and executing database migrations. */
877
1329
  export interface IMigrator {
878
- /**
879
- * Checks current schema for changes, generates new migration if there are any.
880
- */
881
- create(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<MigrationResult>;
882
- /**
883
- * Checks current schema for changes.
884
- */
885
- checkSchema(): Promise<boolean>;
886
- /**
887
- * Creates initial migration. This generates the schema based on metadata, and checks whether all the tables
888
- * are already present. If yes, it will also automatically log the migration as executed.
889
- * Initial migration can be created only if the schema is already aligned with the metadata, or when no schema
890
- * is present - in such case regular migration would have the same effect.
891
- */
892
- createInitial(path?: string): Promise<MigrationResult>;
893
- /**
894
- * Returns list of already executed migrations.
895
- */
896
- getExecuted(): Promise<MigrationRow[]>;
897
- /**
898
- * Returns list of pending (not yet executed) migrations found in the migration directory.
899
- */
900
- getPending(): Promise<MigrationInfo[]>;
901
- /**
902
- * Executes specified migrations. Without parameter it will migrate up to the latest version.
903
- */
904
- up(options?: string | string[] | MigrateOptions): Promise<MigrationInfo[]>;
905
- /**
906
- * Executes down migrations to the given point. Without parameter it will migrate one version down.
907
- */
908
- down(options?: string | string[] | Omit<MigrateOptions, 'from'>): Promise<MigrationInfo[]>;
909
- /**
910
- * Registers event handler.
911
- */
912
- on(event: MigratorEvent, listener: (event: MigrationInfo) => MaybePromise<void>): IMigrator;
913
- /**
914
- * Removes event handler.
915
- */
916
- off(event: MigratorEvent, listener: (event: MigrationInfo) => MaybePromise<void>): IMigrator;
917
- /**
918
- * @internal
919
- */
920
- getStorage(): IMigratorStorage;
1330
+ /**
1331
+ * Checks current schema for changes, generates new migration if there are any.
1332
+ */
1333
+ create(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<MigrationResult>;
1334
+ /**
1335
+ * Checks current schema for changes.
1336
+ */
1337
+ checkSchema(): Promise<boolean>;
1338
+ /**
1339
+ * Creates initial migration. This generates the schema based on metadata, and checks whether all the tables
1340
+ * are already present. If yes, it will also automatically log the migration as executed.
1341
+ * Initial migration can be created only if the schema is already aligned with the metadata, or when no schema
1342
+ * is present - in such case regular migration would have the same effect.
1343
+ */
1344
+ createInitial(path?: string): Promise<MigrationResult>;
1345
+ /**
1346
+ * Returns list of already executed migrations.
1347
+ */
1348
+ getExecuted(): Promise<MigrationRow[]>;
1349
+ /**
1350
+ * Returns list of pending (not yet executed) migrations found in the migration directory.
1351
+ */
1352
+ getPending(): Promise<MigrationInfo[]>;
1353
+ /**
1354
+ * Executes specified migrations. Without parameter it will migrate up to the latest version.
1355
+ */
1356
+ up(options?: string | string[] | MigrateOptions): Promise<MigrationInfo[]>;
1357
+ /**
1358
+ * Executes down migrations to the given point. Without parameter it will migrate one version down.
1359
+ */
1360
+ down(options?: string | string[] | Omit<MigrateOptions, 'from'>): Promise<MigrationInfo[]>;
1361
+ /**
1362
+ * Registers event handler.
1363
+ */
1364
+ on(event: MigratorEvent, listener: (event: MigrationInfo) => MaybePromise<void>): IMigrator;
1365
+ /**
1366
+ * Removes event handler.
1367
+ */
1368
+ off(event: MigratorEvent, listener: (event: MigrationInfo) => MaybePromise<void>): IMigrator;
1369
+ /**
1370
+ * @internal
1371
+ */
1372
+ getStorage(): IMigratorStorage;
921
1373
  }
1374
+ /** Events emitted by the migrator during migration execution. */
922
1375
  export type MigratorEvent = 'migrating' | 'migrated' | 'reverting' | 'reverted';
1376
+ /** The up and down SQL statements representing a schema diff for a migration. */
923
1377
  export interface MigrationDiff {
924
- up: string[];
925
- down: string[];
1378
+ up: string[];
1379
+ down: string[];
926
1380
  }
1381
+ /** Interface for generating migration file contents from schema diffs. */
927
1382
  export interface IMigrationGenerator {
928
- /**
929
- * Generates the full contents of migration file. Uses `generateMigrationFile` to get the file contents.
930
- */
931
- generate(diff: MigrationDiff, path?: string, name?: string): Promise<[string, string]>;
932
- /**
933
- * Creates single migration statement. By default adds `this.addSql(sql);` to the code.
934
- */
935
- createStatement(sql: string, padLeft: number): string;
936
- /**
937
- * Returns the file contents of given migration.
938
- */
939
- generateMigrationFile(className: string, diff: MigrationDiff): MaybePromise<string>;
1383
+ /**
1384
+ * Generates the full contents of migration file. Uses `generateMigrationFile` to get the file contents.
1385
+ */
1386
+ generate(diff: MigrationDiff, path?: string, name?: string): Promise<[string, string]>;
1387
+ /**
1388
+ * Creates single migration statement. By default adds `this.addSql(sql);` to the code.
1389
+ */
1390
+ createStatement(sql: string, padLeft: number): string;
1391
+ /**
1392
+ * Returns the file contents of given migration.
1393
+ */
1394
+ generateMigrationFile(className: string, diff: MigrationDiff): MaybePromise<string>;
940
1395
  }
1396
+ /** Interface that all migration classes must implement. */
941
1397
  export interface Migration {
942
- up(): Promise<void> | void;
943
- down(): Promise<void> | void;
944
- isTransactional(): boolean;
945
- reset(): void;
946
- setTransactionContext(ctx: Transaction): void;
947
- getQueries?(): any[];
1398
+ up(): Promise<void> | void;
1399
+ down(): Promise<void> | void;
1400
+ isTransactional(): boolean;
1401
+ reset(): void;
1402
+ setTransactionContext(ctx: Transaction): void;
1403
+ getQueries?(): any[];
948
1404
  }
1405
+ /** A named migration class reference, used for inline migration registration. */
949
1406
  export interface MigrationObject {
950
- name: string;
951
- class: Constructor<Migration>;
1407
+ name: string;
1408
+ class: Constructor<Migration>;
952
1409
  }
953
1410
  type EntityFromInput<T> = T extends readonly EntityName<infer U>[] ? U : T extends EntityName<infer U> ? U : never;
954
1411
  type FilterDefResolved<T extends object = any> = {
955
- name: string;
956
- cond: FilterQuery<T> | ((args: Dictionary, type: 'read' | 'update' | 'delete', em: any, options?: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any>, entityName?: string) => MaybePromise<FilterQuery<T>>);
957
- default?: boolean;
958
- entity?: EntityName<T> | EntityName<T>[];
959
- args?: boolean;
960
- strict?: boolean;
1412
+ name: string;
1413
+ cond:
1414
+ | FilterQuery<T>
1415
+ | ((
1416
+ args: Dictionary,
1417
+ type: 'read' | 'update' | 'delete',
1418
+ em: any,
1419
+ options?: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any>,
1420
+ entityName?: string,
1421
+ ) => MaybePromise<FilterQuery<T>>);
1422
+ default?: boolean;
1423
+ entity?: EntityName<T> | EntityName<T>[];
1424
+ args?: boolean;
1425
+ strict?: boolean;
961
1426
  };
1427
+ /** Definition of a query filter that can be registered globally or per-entity via `@Filter()`. */
962
1428
  export type FilterDef<T extends EntityName | readonly EntityName[] = any> = FilterDefResolved<EntityFromInput<T>> & {
963
- entity?: T;
1429
+ entity?: T;
964
1430
  };
1431
+ /** Type for the `populate` option in find methods. An array of relation paths to eagerly load, or `false` to disable. */
965
1432
  export type Populate<T, P extends string = never> = readonly AutoPath<T, P, `${PopulatePath}`>[] | false;
1433
+ /** Parsed populate hint for a single relation, including strategy and nested children. */
966
1434
  export type PopulateOptions<T> = {
967
- field: EntityKey<T>;
968
- strategy?: LoadStrategy;
969
- all?: boolean;
970
- filter?: boolean;
971
- joinType?: 'inner join' | 'left join';
972
- children?: PopulateOptions<T[keyof T]>[];
973
- /** When true, ignores `mapToPk` on the property and returns full entity data instead of just PKs. */
974
- dataOnly?: boolean;
1435
+ field: EntityKey<T>;
1436
+ strategy?: LoadStrategy;
1437
+ all?: boolean;
1438
+ filter?: boolean;
1439
+ joinType?: 'inner join' | 'left join';
1440
+ children?: PopulateOptions<T[keyof T]>[];
1441
+ /** When true, ignores `mapToPk` on the property and returns full entity data instead of just PKs. */
1442
+ dataOnly?: boolean;
975
1443
  };
1444
+ /** Inline options that can be appended to populate hint strings (e.g., strategy, join type). */
976
1445
  export type PopulateHintOptions = {
977
- strategy?: LoadStrategy.JOINED | LoadStrategy.SELECT_IN | 'joined' | 'select-in';
978
- joinType?: 'inner join' | 'left join';
1446
+ strategy?: LoadStrategy.JOINED | LoadStrategy.SELECT_IN | 'joined' | 'select-in';
1447
+ joinType?: 'inner join' | 'left join';
979
1448
  };
980
- type ExtractType<T> = T extends CollectionShape<infer U> ? U : T extends ReferenceShape<infer U> ? U : T extends Ref<infer U> ? U : T extends readonly (infer U)[] ? U : T;
1449
+ type ExtractType<T> =
1450
+ T extends CollectionShape<infer U>
1451
+ ? U
1452
+ : T extends ReferenceShape<infer U>
1453
+ ? U
1454
+ : T extends Ref<infer U>
1455
+ ? U
1456
+ : T extends readonly (infer U)[]
1457
+ ? U
1458
+ : T;
981
1459
  type ExtractStringKeys<T> = {
982
- [K in keyof T]-?: CleanKeys<T, K>;
1460
+ [K in keyof T]-?: CleanKeys<T, K>;
983
1461
  }[keyof T] & {};
984
1462
  /**
985
1463
  * Extracts string keys from an entity type, handling Collection/Reference wrappers.
986
1464
  * Simplified to just check `T extends object` since ExtractType handles the unwrapping.
987
1465
  */
988
1466
  type StringKeys<T, E extends string = never> = T extends object ? ExtractStringKeys<ExtractType<T>> | E : never;
989
- type GetStringKey<T, K extends StringKeys<T, string>, E extends string> = K extends keyof T ? ExtractType<T[K]> : K extends E ? keyof T : never;
1467
+ type GetStringKey<T, K extends StringKeys<T, string>, E extends string> = K extends keyof T
1468
+ ? ExtractType<T[K]>
1469
+ : K extends E
1470
+ ? keyof T
1471
+ : never;
990
1472
  type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
991
- type RelationKeys<T> = T extends object ? {
992
- [K in keyof T]-?: CleanKeys<T, K, true>;
993
- }[keyof T] & {} : never;
994
- 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;
1473
+ type RelationKeys<T> = T extends object
1474
+ ? {
1475
+ [K in keyof T]-?: CleanKeys<T, K, true>;
1476
+ }[keyof T] & {}
1477
+ : never;
1478
+ /**
1479
+ * Autocomplete-friendly type for dot-separated relation paths (e.g., `'author.books'`).
1480
+ * Validates each segment against entity keys and provides IDE suggestions. Depth-limited to prevent infinite recursion.
1481
+ */
1482
+ export type AutoPath<
1483
+ O,
1484
+ P extends string | boolean,
1485
+ E extends string = never,
1486
+ D extends Prev[number] = 9,
1487
+ > = P extends boolean
1488
+ ? P
1489
+ : [D] extends [never]
1490
+ ? never
1491
+ : P extends any
1492
+ ? P extends string
1493
+ ? P extends `${infer A}.${infer B}`
1494
+ ? A extends StringKeys<O, E>
1495
+ ? `${A}.${AutoPath<NonNullable<GetStringKey<O, A, E>>, B, E, Prev[D]>}`
1496
+ : never
1497
+ : P extends StringKeys<O, E>
1498
+ ?
1499
+ | (NonNullable<GetStringKey<O, P & StringKeys<O, E>, E>> extends unknown
1500
+ ? Exclude<P, `${string}.`>
1501
+ : never)
1502
+ | (StringKeys<NonNullable<GetStringKey<O, P & StringKeys<O, E>, E>>, E> extends never
1503
+ ? never
1504
+ : `${P & string}.`)
1505
+ : StringKeys<O, E> | `${RelationKeys<O>}:ref`
1506
+ : never
1507
+ : never;
1508
+ /** Unwraps an array type to its element type; non-arrays pass through unchanged. */
995
1509
  export type UnboxArray<T> = T extends any[] ? ArrayElement<T> : T;
1510
+ /** Extracts the element type from an array type. */
996
1511
  export type ArrayElement<ArrayType extends unknown[]> = ArrayType extends (infer ElementType)[] ? ElementType : never;
997
- 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
- 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;
1512
+ /** Unwraps a property type from its wrapper (Reference, Collection, or array) to the inner entity type. */
1513
+ export type ExpandProperty<T> =
1514
+ T extends ReferenceShape<infer U>
1515
+ ? NonNullable<U>
1516
+ : T extends CollectionShape<infer U>
1517
+ ? NonNullable<U>
1518
+ : T extends (infer U)[]
1519
+ ? NonNullable<U>
1520
+ : NonNullable<T>;
1521
+ type LoadedLoadable<T, E extends object> = T extends CollectionShape
1522
+ ? LoadedCollection<E>
1523
+ : T extends ScalarReference<infer U>
1524
+ ? LoadedScalarReference<U>
1525
+ : T extends ReferenceShape
1526
+ ? T & LoadedReference<E>
1527
+ : T extends Scalar
1528
+ ? T
1529
+ : T extends (infer U)[]
1530
+ ? U extends Scalar
1531
+ ? T
1532
+ : E[]
1533
+ : E;
999
1534
  type IsTrue<T> = IsNever<T> extends true ? false : T extends boolean ? (T extends true ? true : false) : false;
1000
1535
  type StringLiteral<T> = T extends string ? (string extends T ? never : T) : never;
1001
1536
  type Prefix<T, K> = K extends `${infer S}.${string}` ? S : K extends '*' ? keyof T : K;
1002
1537
  type IsPrefixedExclude<T, K extends keyof T, E extends string> = K extends E ? never : K;
1003
- 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
- type Suffix<Key, Hint extends string, All = true | '*'> = Hint extends `${infer Pref}.${infer Suf}` ? Pref extends Key ? Suf : never : Hint extends All ? Hint : never;
1005
- export type IsSubset<T, U> = keyof U extends keyof T ? {} : string extends keyof U ? {} : {
1006
- [K in keyof U as K extends keyof T ? never : CleanKeys<U, K>]: never;
1007
- };
1538
+ /** Checks whether a key `K` is included in the populate/fields hints. Used to filter entity keys in `Loaded`/`Selected`. */
1539
+ export type IsPrefixed<T, K extends keyof T, L extends string, E extends string = never> =
1540
+ IsNever<E> extends false
1541
+ ? IsPrefixedExclude<T, K, E>
1542
+ : K extends symbol
1543
+ ? never
1544
+ : IsTrue<L> extends true
1545
+ ? T[K] & {} extends LoadableShape
1546
+ ? K
1547
+ : never
1548
+ : IsNever<StringLiteral<L>> extends true
1549
+ ? never
1550
+ : '*' extends L
1551
+ ? K
1552
+ : K extends Prefix<T, L>
1553
+ ? K
1554
+ : K extends PrimaryProperty<T>
1555
+ ? K
1556
+ : never;
1557
+ type Suffix<Key, Hint extends string, All = true | '*'> = Hint extends `${infer Pref}.${infer Suf}`
1558
+ ? Pref extends Key
1559
+ ? Suf
1560
+ : never
1561
+ : Hint extends All
1562
+ ? Hint
1563
+ : never;
1564
+ /** Validates that `U` is a subset of `T`. Returns `{}` if valid, or a mapped type with `never` values to cause a type error. */
1565
+ export type IsSubset<T, U> = keyof U extends keyof T
1566
+ ? {}
1567
+ : string extends keyof U
1568
+ ? {}
1569
+ : {
1570
+ [K in keyof U as K extends keyof T ? never : CleanKeys<U, K>]: never;
1571
+ };
1008
1572
  /**
1009
1573
  * Fast check if T is a Loaded type by looking for the marker symbol.
1010
1574
  * This is much cheaper than matching against the full Loaded structure.
1011
1575
  */
1012
1576
  type IsLoadedType<T> = T extends {
1013
- [__loadedType]?: any;
1014
- } ? true : false;
1577
+ [__loadedType]?: any;
1578
+ }
1579
+ ? true
1580
+ : false;
1015
1581
  /**
1016
1582
  * Optimized MergeSelected using intersection instead of extraction.
1017
1583
  * When T is already Loaded, we intersect with a new Loaded type for the selected fields.
@@ -1024,99 +1590,192 @@ export type MergeSelected<T, U, F extends string> = IsLoadedType<T> extends true
1024
1590
  * This avoids the expensive pattern matching needed to extract hints from Loaded types.
1025
1591
  * Used for `em.populate` and `em.refresh`.
1026
1592
  */
1027
- 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>;
1028
- export type AddOptional<T> = undefined | null extends T ? null | undefined : null extends T ? null : undefined extends T ? undefined : never;
1029
- type LoadedProp<T, L extends string = never, F extends string = '*', E extends string = never> = LoadedLoadable<T, Loaded<ExtractType<T>, L, F, E>>;
1593
+ export type MergeLoaded<T, U, P extends string, F extends string, E extends string, R extends boolean = false> =
1594
+ IsLoadedType<T> extends true ? T & Loaded<U, P, F, E> : Loaded<T, P, F, E>;
1595
+ /** Extracts the nullability modifiers (`null`, `undefined`, or both) from a type `T`. */
1596
+ export type AddOptional<T> = undefined | null extends T
1597
+ ? null | undefined
1598
+ : null extends T
1599
+ ? null
1600
+ : undefined extends T
1601
+ ? undefined
1602
+ : never;
1603
+ type LoadedProp<T, L extends string = never, F extends string = '*', E extends string = never> = LoadedLoadable<
1604
+ T,
1605
+ Loaded<ExtractType<T>, L, F, E>
1606
+ >;
1607
+ /** Extracts the eager-loaded property names declared via `[EagerProps]` as a string union. */
1030
1608
  export type AddEager<T> = ExtractEagerProps<T> & string;
1609
+ /** Combines an explicit populate hint `L` with the entity's eagerly loaded properties. */
1031
1610
  export type ExpandHint<T, L extends string> = L | AddEager<T>;
1611
+ /**
1612
+ * Entity type narrowed to only the selected fields (`F`) and populated relations (`L`).
1613
+ * Used as the return type when `fields` option is specified in find methods.
1614
+ */
1032
1615
  export type Selected<T, L extends string = never, F extends string = '*'> = {
1033
- [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]>;
1616
+ [K in keyof T as IsPrefixed<T, K, L | F | AddEager<T>> | FunctionKeys<T, K>]: T[K] extends Function
1617
+ ? T[K]
1618
+ : NonNullable<T[K]> extends Scalar
1619
+ ? T[K]
1620
+ : LoadedProp<NonNullable<T[K]>, Suffix<K, L, true>, Suffix<K, F, true>> | AddOptional<T[K]>;
1034
1621
  } & {
1035
- [__selectedType]?: T;
1036
- };
1037
- type LoadedEntityType<T> = {
1038
- [__loadedType]?: T;
1039
- } | {
1040
- [__selectedType]?: T;
1622
+ [__selectedType]?: T;
1041
1623
  };
1624
+ type LoadedEntityType<T> =
1625
+ | {
1626
+ [__loadedType]?: T;
1627
+ }
1628
+ | {
1629
+ [__selectedType]?: T;
1630
+ };
1631
+ /** Accepts either a plain entity type or a `Loaded`/`Selected` wrapped version. */
1042
1632
  export type EntityType<T> = T | LoadedEntityType<T>;
1633
+ /** Extracts the base entity type from a `Loaded`/`Selected` wrapper, or returns `T` as-is. */
1043
1634
  export type FromEntityType<T> = T extends LoadedEntityType<infer U> ? U : T;
1044
- type LoadedInternal<T, L extends string = never, F extends string = '*', E extends string = never> = [F] extends ['*'] ? IsNever<E> extends true ? T & {
1045
- [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]>;
1046
- } : {
1047
- [K in keyof T as IsPrefixed<T, K, ExpandHint<T, L>, E>]: LoadedProp<NonNullable<T[K]>, Suffix<K, L>, Suffix<K, F>, Suffix<K, E>> | AddOptional<T[K]>;
1048
- } : Selected<T, L, F>;
1635
+ type LoadedInternal<T, L extends string = never, F extends string = '*', E extends string = never> = [F] extends ['*']
1636
+ ? IsNever<E> extends true
1637
+ ? T & {
1638
+ [K in keyof T as IsPrefixed<T, K, ExpandHint<T, L>>]:
1639
+ | LoadedProp<NonNullable<T[K]>, Suffix<K, L>, Suffix<K, F>, Suffix<K, E>>
1640
+ | AddOptional<T[K]>;
1641
+ }
1642
+ : {
1643
+ [K in keyof T as IsPrefixed<T, K, ExpandHint<T, L>, E>]:
1644
+ | LoadedProp<NonNullable<T[K]>, Suffix<K, L>, Suffix<K, F>, Suffix<K, E>>
1645
+ | AddOptional<T[K]>;
1646
+ }
1647
+ : Selected<T, L, F>;
1049
1648
  /**
1050
1649
  * Represents entity with its loaded relations (`populate` hint) and selected properties (`fields` hint).
1051
1650
  * The __loadHint marker uses contravariance to ensure Loaded<A, 'b'> is NOT assignable to Loaded<A, 'b.c'>.
1052
1651
  */
1053
- export type Loaded<T, L extends string = never, F extends string = '*', E extends string = never> = LoadedInternal<T, L, F, E> & {
1054
- [__loadedType]?: T;
1055
- [__loadHint]?: (hint: Prefixes<L>) => void;
1652
+ export type Loaded<T, L extends string = never, F extends string = '*', E extends string = never> = LoadedInternal<
1653
+ T,
1654
+ L,
1655
+ F,
1656
+ E
1657
+ > & {
1658
+ [__loadedType]?: T;
1659
+ [__loadHint]?: (hint: Prefixes<L>) => void;
1056
1660
  };
1661
+ /** A `Reference<T>` that is guaranteed to be loaded, providing synchronous access via `$` and `get()`. */
1057
1662
  export interface LoadedReference<T> extends Reference<NonNullable<T>> {
1058
- $: NonNullable<T>;
1059
- get(): NonNullable<T>;
1663
+ $: NonNullable<T>;
1664
+ get(): NonNullable<T>;
1060
1665
  }
1666
+ /** A `ScalarReference<T>` that is guaranteed to be loaded, providing synchronous access via `$` and `get()`. */
1061
1667
  export interface LoadedScalarReference<T> extends ScalarReference<T> {
1062
- $: T;
1063
- get(): T;
1668
+ $: T;
1669
+ get(): T;
1064
1670
  }
1671
+ /** A `Collection<T>` that is guaranteed to be loaded, providing synchronous access via `$`, `get()`, and `getItems()`. */
1065
1672
  export interface LoadedCollection<T extends object> extends Collection<T> {
1066
- $: Collection<T>;
1067
- get(): Collection<T>;
1068
- getItems(check?: boolean): T[];
1673
+ $: Collection<T>;
1674
+ get(): Collection<T>;
1675
+ getItems(check?: boolean): T[];
1069
1676
  }
1677
+ /** Alias for `Loaded<T, P>`. Represents a newly created entity with all specified relations populated. */
1070
1678
  export type New<T, P extends string = string> = Loaded<T, P>;
1679
+ /** Interface for SQL/code syntax highlighters used in logging output. */
1071
1680
  export interface Highlighter {
1072
- highlight(text: string): string;
1681
+ highlight(text: string): string;
1073
1682
  }
1683
+ /** Interface for the metadata storage, which holds `EntityMetadata` for all discovered entities. */
1074
1684
  export interface IMetadataStorage {
1075
- getAll(): Map<EntityName, EntityMetadata>;
1076
- get<T = any>(entity: EntityName<T>, init?: boolean, validate?: boolean): EntityMetadata<T>;
1077
- find<T = any>(entity: EntityName<T>): EntityMetadata<T> | undefined;
1078
- has<T>(entity: EntityName<T>): boolean;
1079
- set<T>(entity: EntityName<T>, meta: EntityMetadata): EntityMetadata;
1080
- reset<T>(entity: EntityName<T>): void;
1685
+ getAll(): Map<EntityName, EntityMetadata>;
1686
+ get<T = any>(entity: EntityName<T>, init?: boolean, validate?: boolean): EntityMetadata<T>;
1687
+ find<T = any>(entity: EntityName<T>): EntityMetadata<T> | undefined;
1688
+ has<T>(entity: EntityName<T>): boolean;
1689
+ set<T>(entity: EntityName<T>, meta: EntityMetadata): EntityMetadata;
1690
+ reset<T>(entity: EntityName<T>): void;
1081
1691
  }
1692
+ /** Interface for entity hydrators, which populate entity instances from raw database data. */
1082
1693
  export interface IHydrator {
1083
- /**
1084
- * Hydrates the whole entity. This process handles custom type conversions, creating missing Collection instances,
1085
- * mapping FKs to entity instances, as well as merging those entities.
1086
- */
1087
- hydrate<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, type: 'full' | 'reference', newEntity?: boolean, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void;
1088
- /**
1089
- * Hydrates primary keys only
1090
- */
1091
- hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void;
1092
- isRunning(): boolean;
1694
+ /**
1695
+ * Hydrates the whole entity. This process handles custom type conversions, creating missing Collection instances,
1696
+ * mapping FKs to entity instances, as well as merging those entities.
1697
+ */
1698
+ hydrate<T extends object>(
1699
+ entity: T,
1700
+ meta: EntityMetadata<T>,
1701
+ data: EntityData<T>,
1702
+ factory: EntityFactory,
1703
+ type: 'full' | 'reference',
1704
+ newEntity?: boolean,
1705
+ convertCustomTypes?: boolean,
1706
+ schema?: string,
1707
+ parentSchema?: string,
1708
+ normalizeAccessors?: boolean,
1709
+ ): void;
1710
+ /**
1711
+ * Hydrates primary keys only
1712
+ */
1713
+ hydrateReference<T extends object>(
1714
+ entity: T,
1715
+ meta: EntityMetadata<T>,
1716
+ data: EntityData<T>,
1717
+ factory: EntityFactory,
1718
+ convertCustomTypes?: boolean,
1719
+ schema?: string,
1720
+ parentSchema?: string,
1721
+ normalizeAccessors?: boolean,
1722
+ ): void;
1723
+ isRunning(): boolean;
1093
1724
  }
1725
+ /** Constructor signature for hydrator implementations. */
1094
1726
  export interface HydratorConstructor {
1095
- new (metadata: MetadataStorage, platform: Platform, config: Configuration): IHydrator;
1727
+ new (metadata: MetadataStorage, platform: Platform, config: Configuration): IHydrator;
1096
1728
  }
1729
+ /** Interface for the seed manager, which runs database seeders. */
1097
1730
  export interface ISeedManager {
1098
- seed(...classNames: Constructor<Seeder>[]): Promise<void>;
1099
- /** @internal */
1100
- seedString(...classNames: string[]): Promise<void>;
1101
- create(className: string): Promise<string>;
1731
+ seed(...classNames: Constructor<Seeder>[]): Promise<void>;
1732
+ /** @internal */
1733
+ seedString(...classNames: string[]): Promise<void>;
1734
+ create(className: string): Promise<string>;
1102
1735
  }
1736
+ /** Interface that all seeder classes must implement. The `run` method receives an EntityManager. */
1103
1737
  export interface Seeder<T extends Dictionary = Dictionary> {
1104
- run(em: EntityManager, context?: T): void | Promise<void>;
1738
+ run(em: EntityManager, context?: T): void | Promise<void>;
1105
1739
  }
1740
+ /** A named seeder class reference, used for inline seeder registration. */
1106
1741
  export interface SeederObject {
1107
- name: string;
1108
- class: Constructor<Seeder>;
1742
+ name: string;
1743
+ class: Constructor<Seeder>;
1109
1744
  }
1745
+ /** Discriminator for read vs write database connections in read-replica setups. */
1110
1746
  export type ConnectionType = 'read' | 'write';
1747
+ /** Callback for processing entity metadata during discovery or entity generation. */
1111
1748
  export type MetadataProcessor = (metadata: EntityMetadata[], platform: Platform) => MaybePromise<void>;
1749
+ /** Extracts the return type if `T` is a function, otherwise returns `T` as-is. */
1112
1750
  export type MaybeReturnType<T> = T extends (...args: any[]) => infer R ? R : T;
1113
- 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
- readonly name: TName;
1115
- readonly properties: TProperties;
1116
- readonly tableName: TTableName;
1117
- /** @internal Direct entity type access - avoids expensive pattern matching */
1118
- readonly '~entity': TEntity;
1751
+ /**
1752
+ * Extended `EntitySchema` interface that carries additional type-level metadata (entity name, properties, table name).
1753
+ * Returned by `defineEntity()` to provide strong type inference without explicit generics.
1754
+ */
1755
+ export interface EntitySchemaWithMeta<
1756
+ TName extends string = string,
1757
+ TTableName extends string = string,
1758
+ TEntity = any,
1759
+ TBase = never,
1760
+ TProperties extends Record<string, any> = Record<string, any>,
1761
+ TClass extends EntityCtor = EntityCtor<TEntity>,
1762
+ > extends EntitySchema<TEntity, TBase, TClass> {
1763
+ readonly name: TName;
1764
+ readonly properties: TProperties;
1765
+ readonly tableName: TTableName;
1766
+ /** @internal Direct entity type access - avoids expensive pattern matching */
1767
+ readonly '~entity': TEntity;
1119
1768
  }
1769
+ /**
1770
+ * Extracts the entity type from an `EntitySchema`, `EntitySchemaWithMeta`, or entity class.
1771
+ * Uses a fast-path direct property access when available, falling back to generic inference.
1772
+ */
1120
1773
  export type InferEntity<Schema> = Schema extends {
1121
- '~entity': infer E;
1122
- } ? E : Schema extends EntitySchema<infer Entity> ? Entity : Schema extends EntityClass<infer Entity> ? Entity : Schema;
1774
+ '~entity': infer E;
1775
+ }
1776
+ ? E
1777
+ : Schema extends EntitySchema<infer Entity>
1778
+ ? Entity
1779
+ : Schema extends EntityClass<infer Entity>
1780
+ ? Entity
1781
+ : Schema;