@mikro-orm/core 7.0.15 → 7.0.16-dev.0

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