@mikro-orm/core 7.0.2 → 7.0.3-dev.0

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