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

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