@mikro-orm/core 7.0.0-dev.19 → 7.0.0-dev.191

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 (211) hide show
  1. package/EntityManager.d.ts +99 -57
  2. package/EntityManager.js +302 -276
  3. package/MikroORM.d.ts +44 -35
  4. package/MikroORM.js +103 -143
  5. package/README.md +3 -2
  6. package/cache/FileCacheAdapter.d.ts +1 -1
  7. package/cache/FileCacheAdapter.js +8 -7
  8. package/cache/GeneratedCacheAdapter.d.ts +0 -1
  9. package/cache/GeneratedCacheAdapter.js +0 -2
  10. package/cache/index.d.ts +0 -1
  11. package/cache/index.js +0 -1
  12. package/connections/Connection.d.ts +16 -7
  13. package/connections/Connection.js +23 -14
  14. package/drivers/DatabaseDriver.d.ts +25 -16
  15. package/drivers/DatabaseDriver.js +80 -35
  16. package/drivers/IDatabaseDriver.d.ts +44 -17
  17. package/entity/BaseEntity.d.ts +2 -2
  18. package/entity/BaseEntity.js +0 -3
  19. package/entity/Collection.d.ts +94 -29
  20. package/entity/Collection.js +434 -97
  21. package/entity/EntityAssigner.d.ts +1 -1
  22. package/entity/EntityAssigner.js +26 -18
  23. package/entity/EntityFactory.d.ts +13 -1
  24. package/entity/EntityFactory.js +84 -53
  25. package/entity/EntityHelper.d.ts +2 -2
  26. package/entity/EntityHelper.js +35 -15
  27. package/entity/EntityLoader.d.ts +6 -6
  28. package/entity/EntityLoader.js +117 -77
  29. package/entity/EntityRepository.d.ts +24 -4
  30. package/entity/EntityRepository.js +8 -2
  31. package/entity/Reference.d.ts +6 -5
  32. package/entity/Reference.js +34 -9
  33. package/entity/WrappedEntity.d.ts +2 -7
  34. package/entity/WrappedEntity.js +3 -8
  35. package/entity/defineEntity.d.ts +585 -0
  36. package/entity/defineEntity.js +533 -0
  37. package/entity/index.d.ts +3 -2
  38. package/entity/index.js +3 -2
  39. package/entity/utils.d.ts +7 -0
  40. package/entity/utils.js +16 -4
  41. package/entity/validators.d.ts +11 -0
  42. package/entity/validators.js +65 -0
  43. package/enums.d.ts +21 -5
  44. package/enums.js +15 -1
  45. package/errors.d.ts +23 -9
  46. package/errors.js +59 -21
  47. package/events/EventManager.d.ts +2 -1
  48. package/events/EventManager.js +19 -11
  49. package/hydration/Hydrator.js +1 -2
  50. package/hydration/ObjectHydrator.d.ts +4 -4
  51. package/hydration/ObjectHydrator.js +52 -33
  52. package/index.d.ts +2 -2
  53. package/index.js +1 -2
  54. package/logging/DefaultLogger.d.ts +1 -1
  55. package/logging/DefaultLogger.js +1 -0
  56. package/logging/SimpleLogger.d.ts +1 -1
  57. package/logging/colors.d.ts +1 -1
  58. package/logging/colors.js +7 -6
  59. package/logging/index.d.ts +1 -0
  60. package/logging/index.js +1 -0
  61. package/logging/inspect.d.ts +2 -0
  62. package/logging/inspect.js +11 -0
  63. package/metadata/EntitySchema.d.ts +20 -22
  64. package/metadata/EntitySchema.js +59 -34
  65. package/metadata/MetadataDiscovery.d.ts +7 -10
  66. package/metadata/MetadataDiscovery.js +396 -331
  67. package/metadata/MetadataProvider.d.ts +11 -2
  68. package/metadata/MetadataProvider.js +46 -2
  69. package/metadata/MetadataStorage.d.ts +13 -11
  70. package/metadata/MetadataStorage.js +70 -37
  71. package/metadata/MetadataValidator.d.ts +17 -9
  72. package/metadata/MetadataValidator.js +97 -40
  73. package/metadata/discover-entities.d.ts +5 -0
  74. package/metadata/discover-entities.js +40 -0
  75. package/metadata/index.d.ts +1 -1
  76. package/metadata/index.js +1 -1
  77. package/metadata/types.d.ts +502 -0
  78. package/metadata/types.js +1 -0
  79. package/naming-strategy/AbstractNamingStrategy.d.ts +8 -4
  80. package/naming-strategy/AbstractNamingStrategy.js +8 -2
  81. package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
  82. package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
  83. package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
  84. package/naming-strategy/MongoNamingStrategy.js +6 -6
  85. package/naming-strategy/NamingStrategy.d.ts +14 -4
  86. package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
  87. package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
  88. package/not-supported.d.ts +2 -0
  89. package/not-supported.js +4 -0
  90. package/package.json +18 -11
  91. package/platforms/ExceptionConverter.js +1 -1
  92. package/platforms/Platform.d.ts +7 -13
  93. package/platforms/Platform.js +20 -43
  94. package/serialization/EntitySerializer.d.ts +5 -0
  95. package/serialization/EntitySerializer.js +47 -27
  96. package/serialization/EntityTransformer.js +28 -18
  97. package/serialization/SerializationContext.d.ts +6 -6
  98. package/serialization/SerializationContext.js +16 -13
  99. package/types/ArrayType.d.ts +1 -1
  100. package/types/ArrayType.js +2 -3
  101. package/types/BigIntType.d.ts +8 -6
  102. package/types/BigIntType.js +1 -1
  103. package/types/BlobType.d.ts +0 -1
  104. package/types/BlobType.js +0 -3
  105. package/types/BooleanType.d.ts +2 -1
  106. package/types/BooleanType.js +3 -0
  107. package/types/DecimalType.d.ts +6 -4
  108. package/types/DecimalType.js +3 -3
  109. package/types/DoubleType.js +2 -2
  110. package/types/EnumArrayType.js +1 -2
  111. package/types/JsonType.d.ts +1 -1
  112. package/types/JsonType.js +7 -2
  113. package/types/TinyIntType.js +1 -1
  114. package/types/Type.d.ts +2 -4
  115. package/types/Type.js +3 -3
  116. package/types/Uint8ArrayType.d.ts +0 -1
  117. package/types/Uint8ArrayType.js +1 -4
  118. package/types/index.d.ts +1 -1
  119. package/typings.d.ts +241 -129
  120. package/typings.js +59 -44
  121. package/unit-of-work/ChangeSet.d.ts +2 -6
  122. package/unit-of-work/ChangeSet.js +4 -5
  123. package/unit-of-work/ChangeSetComputer.d.ts +1 -3
  124. package/unit-of-work/ChangeSetComputer.js +26 -13
  125. package/unit-of-work/ChangeSetPersister.d.ts +5 -4
  126. package/unit-of-work/ChangeSetPersister.js +70 -34
  127. package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
  128. package/unit-of-work/CommitOrderCalculator.js +13 -13
  129. package/unit-of-work/IdentityMap.d.ts +12 -0
  130. package/unit-of-work/IdentityMap.js +39 -1
  131. package/unit-of-work/UnitOfWork.d.ts +23 -3
  132. package/unit-of-work/UnitOfWork.js +175 -98
  133. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  134. package/utils/AbstractSchemaGenerator.js +18 -16
  135. package/utils/AsyncContext.d.ts +6 -0
  136. package/utils/AsyncContext.js +42 -0
  137. package/utils/Configuration.d.ts +764 -207
  138. package/utils/Configuration.js +146 -190
  139. package/utils/ConfigurationLoader.d.ts +1 -54
  140. package/utils/ConfigurationLoader.js +1 -352
  141. package/utils/Cursor.d.ts +0 -3
  142. package/utils/Cursor.js +27 -11
  143. package/utils/DataloaderUtils.d.ts +15 -5
  144. package/utils/DataloaderUtils.js +64 -30
  145. package/utils/EntityComparator.d.ts +13 -9
  146. package/utils/EntityComparator.js +101 -42
  147. package/utils/QueryHelper.d.ts +14 -6
  148. package/utils/QueryHelper.js +87 -25
  149. package/utils/RawQueryFragment.d.ts +48 -25
  150. package/utils/RawQueryFragment.js +66 -70
  151. package/utils/RequestContext.js +2 -2
  152. package/utils/TransactionContext.js +2 -2
  153. package/utils/TransactionManager.d.ts +65 -0
  154. package/utils/TransactionManager.js +223 -0
  155. package/utils/Utils.d.ts +13 -126
  156. package/utils/Utils.js +100 -391
  157. package/utils/clone.js +8 -23
  158. package/utils/env-vars.d.ts +7 -0
  159. package/utils/env-vars.js +97 -0
  160. package/utils/fs-utils.d.ts +32 -0
  161. package/utils/fs-utils.js +178 -0
  162. package/utils/index.d.ts +2 -1
  163. package/utils/index.js +2 -1
  164. package/utils/upsert-utils.d.ts +9 -4
  165. package/utils/upsert-utils.js +55 -4
  166. package/decorators/Check.d.ts +0 -3
  167. package/decorators/Check.js +0 -13
  168. package/decorators/CreateRequestContext.d.ts +0 -3
  169. package/decorators/CreateRequestContext.js +0 -32
  170. package/decorators/Embeddable.d.ts +0 -8
  171. package/decorators/Embeddable.js +0 -11
  172. package/decorators/Embedded.d.ts +0 -12
  173. package/decorators/Embedded.js +0 -18
  174. package/decorators/Entity.d.ts +0 -18
  175. package/decorators/Entity.js +0 -12
  176. package/decorators/Enum.d.ts +0 -9
  177. package/decorators/Enum.js +0 -16
  178. package/decorators/Filter.d.ts +0 -2
  179. package/decorators/Filter.js +0 -8
  180. package/decorators/Formula.d.ts +0 -4
  181. package/decorators/Formula.js +0 -15
  182. package/decorators/Indexed.d.ts +0 -19
  183. package/decorators/Indexed.js +0 -20
  184. package/decorators/ManyToMany.d.ts +0 -40
  185. package/decorators/ManyToMany.js +0 -14
  186. package/decorators/ManyToOne.d.ts +0 -32
  187. package/decorators/ManyToOne.js +0 -14
  188. package/decorators/OneToMany.d.ts +0 -28
  189. package/decorators/OneToMany.js +0 -17
  190. package/decorators/OneToOne.d.ts +0 -26
  191. package/decorators/OneToOne.js +0 -7
  192. package/decorators/PrimaryKey.d.ts +0 -8
  193. package/decorators/PrimaryKey.js +0 -20
  194. package/decorators/Property.d.ts +0 -250
  195. package/decorators/Property.js +0 -32
  196. package/decorators/Transactional.d.ts +0 -13
  197. package/decorators/Transactional.js +0 -28
  198. package/decorators/hooks.d.ts +0 -16
  199. package/decorators/hooks.js +0 -47
  200. package/decorators/index.d.ts +0 -17
  201. package/decorators/index.js +0 -17
  202. package/entity/ArrayCollection.d.ts +0 -116
  203. package/entity/ArrayCollection.js +0 -402
  204. package/entity/EntityValidator.d.ts +0 -19
  205. package/entity/EntityValidator.js +0 -150
  206. package/exports.d.ts +0 -24
  207. package/exports.js +0 -23
  208. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  209. package/metadata/ReflectMetadataProvider.js +0 -44
  210. package/utils/resolveContextProvider.d.ts +0 -10
  211. package/utils/resolveContextProvider.js +0 -28
package/typings.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Transaction } from './connections/Connection.js';
2
- import { type Cascade, type DeferMode, type EventType, type LoadStrategy, type PopulatePath, type QueryOrderMap, ReferenceKind } from './enums.js';
2
+ import { type Cascade, type DeferMode, type EmbeddedPrefixMode, type EventType, type LoadStrategy, type PopulatePath, type QueryOrderMap, ReferenceKind } from './enums.js';
3
3
  import { type AssignOptions } from './entity/EntityAssigner.js';
4
4
  import { type EntityIdentifier } from './entity/EntityIdentifier.js';
5
5
  import { type EntityLoaderOptions } from './entity/EntityLoader.js';
@@ -7,7 +7,6 @@ import { type Collection } from './entity/Collection.js';
7
7
  import { type EntityFactory } from './entity/EntityFactory.js';
8
8
  import { type EntityRepository } from './entity/EntityRepository.js';
9
9
  import { Reference, type ScalarReference } from './entity/Reference.js';
10
- import type { MikroORM } from './MikroORM.js';
11
10
  import type { SerializationContext } from './serialization/SerializationContext.js';
12
11
  import type { SerializeOptions } from './serialization/EntitySerializer.js';
13
12
  import type { MetadataStorage } from './metadata/MetadataStorage.js';
@@ -15,11 +14,10 @@ import type { EntitySchema } from './metadata/EntitySchema.js';
15
14
  import type { Type, types } from './types/index.js';
16
15
  import type { Platform } from './platforms/Platform.js';
17
16
  import type { Configuration } from './utils/Configuration.js';
18
- import type { RawQueryFragment } from './utils/RawQueryFragment.js';
17
+ import type { Raw } from './utils/RawQueryFragment.js';
19
18
  import type { EntityManager } from './EntityManager.js';
20
- import type { EmbeddedPrefixMode } from './decorators/Embedded.js';
21
19
  import type { EventSubscriber } from './events/EventSubscriber.js';
22
- import type { FindOneOptions, FindOptions, LoadHint } from './drivers/IDatabaseDriver.js';
20
+ import type { FilterOptions, FindOneOptions, FindOptions, LoadHint } from './drivers/IDatabaseDriver.js';
23
21
  export type Constructor<T = unknown> = new (...args: any[]) => T;
24
22
  export type Dictionary<T = any> = {
25
23
  [k: string]: T;
@@ -43,6 +41,35 @@ export type IsAny<T> = 0 extends (1 & T) ? true : false;
43
41
  export type IsNever<T, True = true, False = false> = [T] extends [never] ? True : False;
44
42
  export type MaybePromise<T> = T | Promise<T>;
45
43
  export type NoInfer<T> = [T][T extends any ? 0 : never];
44
+ /**
45
+ * Structural type for matching Collection without triggering full interface evaluation.
46
+ * Using `T extends CollectionShape` instead of `T extends Collection<any, any>` avoids
47
+ * forcing TypeScript to evaluate Collection's 30+ methods, preventing instantiation explosion
48
+ * (~133k → ~2k instantiations).
49
+ *
50
+ * Usage:
51
+ * - Matching only: `T extends CollectionShape`
52
+ * - With inference: `T extends CollectionShape<infer U>`
53
+ */
54
+ type CollectionShape<T = any> = {
55
+ [k: number]: T;
56
+ readonly owner: object;
57
+ };
58
+ /**
59
+ * Structural type for matching LoadedCollection (extends CollectionShape with `$` property).
60
+ *
61
+ * Usage:
62
+ * - Matching only: `T extends LoadedCollectionShape`
63
+ * - With inference: `T extends LoadedCollectionShape<infer U>`
64
+ */
65
+ type LoadedCollectionShape<T = any> = CollectionShape<T> & {
66
+ $: any;
67
+ };
68
+ export type UnionKeys<T> = T extends any ? keyof T : never;
69
+ export type UnionPropertyType<T, K extends PropertyKey> = T extends any ? K extends keyof T ? T[K] : never : never;
70
+ export type MergeUnion<T> = [T] extends [object] ? T extends Scalar ? T : {
71
+ [K in UnionKeys<T>]: UnionPropertyType<T, K>;
72
+ } : T;
46
73
  export type DeepPartial<T> = T & {
47
74
  [P in keyof T]?: T[P] extends (infer U)[] ? DeepPartial<U>[] : T[P] extends Readonly<infer U>[] ? Readonly<DeepPartial<U>>[] : DeepPartial<T[P]>;
48
75
  };
@@ -52,18 +79,34 @@ export declare const OptionalProps: unique symbol;
52
79
  export declare const EagerProps: unique symbol;
53
80
  export declare const HiddenProps: unique symbol;
54
81
  export declare const Config: unique symbol;
55
- declare const __optional: unique symbol;
56
- declare const __hidden: unique symbol;
57
- declare const __config: unique symbol;
58
- export type Opt<T = unknown> = T & {
59
- [__optional]?: 1;
60
- };
61
- export type Hidden<T = unknown> = T & {
62
- [__hidden]?: 1;
63
- };
64
- export type DefineConfig<T extends TypeConfig> = T & {
65
- [__config]?: 1;
66
- };
82
+ export type Opt<T = unknown> = T & Opt.Brand;
83
+ export declare namespace Opt {
84
+ const __optional: unique symbol;
85
+ interface Brand {
86
+ [__optional]?: 1;
87
+ }
88
+ }
89
+ export type RequiredNullable<T = never> = (T & RequiredNullable.Brand) | null;
90
+ export declare namespace RequiredNullable {
91
+ const __requiredNullable: unique symbol;
92
+ interface Brand {
93
+ [__requiredNullable]?: 1;
94
+ }
95
+ }
96
+ export type Hidden<T = unknown> = T & Hidden.Brand;
97
+ export declare namespace Hidden {
98
+ const __hidden: unique symbol;
99
+ interface Brand {
100
+ [__hidden]?: 1;
101
+ }
102
+ }
103
+ export type DefineConfig<T extends TypeConfig> = T & DefineConfig.Brand;
104
+ export declare namespace DefineConfig {
105
+ const __config: unique symbol;
106
+ interface Brand {
107
+ [__config]?: 1;
108
+ }
109
+ }
67
110
  export type CleanTypeConfig<T> = Compute<Pick<T, Extract<keyof T, keyof TypeConfig>>>;
68
111
  export interface TypeConfig {
69
112
  forceObject?: boolean;
@@ -75,13 +118,14 @@ type PrimaryPropToType<T, Keys extends (keyof T)[]> = {
75
118
  type ReadonlyPrimary<T> = T extends any[] ? Readonly<T> : T;
76
119
  export type Primary<T> = IsAny<T> extends true ? any : T extends {
77
120
  [PrimaryKeyProp]?: infer PK;
78
- } ? (PK extends keyof T ? ReadonlyPrimary<UnwrapPrimary<T[PK]>> : (PK extends (keyof T)[] ? ReadonlyPrimary<PrimaryPropToType<T, PK>> : PK)) : T extends {
121
+ } ? 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 {
79
122
  _id?: infer PK;
80
123
  } ? ReadonlyPrimary<PK> | string : T extends {
81
- uuid?: infer PK;
82
- } ? ReadonlyPrimary<PK> : T extends {
83
124
  id?: infer PK;
125
+ } ? ReadonlyPrimary<PK> : T extends {
126
+ uuid?: infer PK;
84
127
  } ? ReadonlyPrimary<PK> : T;
128
+ /** @internal */
85
129
  export type PrimaryProperty<T> = T extends {
86
130
  [PrimaryKeyProp]?: infer PK;
87
131
  } ? (PK extends keyof T ? PK : (PK extends any[] ? PK[number] : never)) : T extends {
@@ -89,10 +133,10 @@ export type PrimaryProperty<T> = T extends {
89
133
  } ? (T extends {
90
134
  id?: any;
91
135
  } ? 'id' | '_id' : '_id') : T extends {
92
- uuid?: any;
93
- } ? 'uuid' : T extends {
94
136
  id?: any;
95
- } ? 'id' : never;
137
+ } ? 'id' : T extends {
138
+ uuid?: any;
139
+ } ? 'uuid' : never;
96
140
  export type IPrimaryKeyValue = number | string | bigint | Date | {
97
141
  toHexString(): string;
98
142
  };
@@ -100,6 +144,7 @@ export type IPrimaryKey<T extends IPrimaryKeyValue = IPrimaryKeyValue> = T;
100
144
  export type Scalar = boolean | number | string | bigint | symbol | Date | RegExp | Uint8Array | {
101
145
  toHexString(): string;
102
146
  };
147
+ type Primitive = boolean | number | string | bigint | symbol;
103
148
  export type ExpandScalar<T> = null | (T extends string ? T | RegExp : T extends Date ? Date | string : T extends bigint ? bigint | string | number : T);
104
149
  export type OperatorMap<T> = {
105
150
  $and?: ExpandQuery<T>[];
@@ -112,6 +157,14 @@ export type OperatorMap<T> = {
112
157
  $none?: ExpandQuery<T>;
113
158
  $some?: ExpandQuery<T>;
114
159
  $every?: ExpandQuery<T>;
160
+ $size?: number | {
161
+ $eq?: number;
162
+ $ne?: number;
163
+ $gt?: number;
164
+ $gte?: number;
165
+ $lt?: number;
166
+ $lte?: number;
167
+ };
115
168
  $gt?: ExpandScalar<T>;
116
169
  $gte?: ExpandScalar<T>;
117
170
  $lt?: ExpandScalar<T>;
@@ -130,10 +183,11 @@ export type OperatorMap<T> = {
130
183
  };
131
184
  export type FilterItemValue<T> = T | ExpandScalar<T> | Primary<T>;
132
185
  export type FilterValue<T> = OperatorMap<FilterItemValue<T>> | FilterItemValue<T> | FilterItemValue<T>[] | null;
186
+ type FilterObjectProp<T, K extends PropertyKey> = K extends keyof MergeUnion<T> ? MergeUnion<T>[K] : K extends keyof T ? T[K] : never;
187
+ type ExpandQueryMerged<T> = [T] extends [object] ? [T] extends [Scalar] ? never : FilterQuery<MergeUnion<T>> : FilterValue<T>;
133
188
  export type FilterObject<T> = {
134
- -readonly [K in EntityKey<T>]?: ExpandQuery<ExpandProperty<T[K]>> | FilterValue<ExpandProperty<T[K]>> | null;
189
+ -readonly [K in EntityKey<T> | EntityKey<MergeUnion<T>>]?: ExpandQuery<ExpandProperty<FilterObjectProp<T, K>>> | ExpandQueryMerged<ExpandProperty<FilterObjectProp<T, K>>> | FilterValue<ExpandProperty<FilterObjectProp<T, K>>> | null;
135
190
  };
136
- export type ExpandObject<T> = T extends object ? T extends Scalar ? never : FilterObject<T> : never;
137
191
  export type ExpandQuery<T> = T extends object ? T extends Scalar ? never : FilterQuery<T> : FilterValue<T>;
138
192
  export type EntityProps<T> = {
139
193
  -readonly [K in EntityKey<T>]?: T[K];
@@ -143,10 +197,9 @@ export type FilterQuery<T> = ObjectQuery<T> | NonNullable<ExpandScalar<Primary<T
143
197
  export type QBFilterQuery<T = any> = ObjectQuery<T> | Dictionary;
144
198
  export interface IWrappedEntity<Entity extends object> {
145
199
  isInitialized(): boolean;
146
- isTouched(): boolean;
147
200
  isManaged(): boolean;
148
201
  populated(populated?: boolean): void;
149
- populate<Hint extends string = never>(populate: AutoPath<Entity, Hint>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
202
+ populate<Hint extends string = never>(populate: readonly AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
150
203
  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>;
151
204
  toReference(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
152
205
  toObject(): EntityDTO<Entity>;
@@ -174,7 +227,6 @@ export interface IWrappedEntityInternal<Entity extends object> extends IWrappedE
174
227
  __factory: EntityFactory;
175
228
  __hydrator: IHydrator;
176
229
  __initialized: boolean;
177
- __touched: boolean;
178
230
  __originalEntityData?: EntityData<Entity>;
179
231
  __loadedProperties: Set<string>;
180
232
  __identifier?: EntityIdentifier | EntityIdentifier[];
@@ -194,16 +246,10 @@ export interface IWrappedEntityInternal<Entity extends object> extends IWrappedE
194
246
  };
195
247
  }
196
248
  export type AnyEntity<T = any> = Partial<T>;
197
- export type EntityClass<T> = Function & {
249
+ export type EntityClass<T = any> = Function & {
198
250
  prototype: T;
199
251
  };
200
- export type EntityClassGroup<T> = {
201
- entity: EntityClass<T>;
202
- schema: EntityMetadata<T> | EntitySchema<T>;
203
- };
204
- export type EntityName<T> = string | EntityClass<T> | EntitySchema<T, any> | {
205
- name: string;
206
- };
252
+ export type EntityName<T = any> = EntityClass<T> | EntityCtor<T> | EntitySchema<T, any>;
207
253
  export type GetRepository<Entity extends {
208
254
  [k: PropertyKey]: any;
209
255
  }, Fallback> = Entity[typeof EntityRepositoryType] extends EntityRepository<any> | undefined ? NonNullable<Entity[typeof EntityRepositoryType]> : Fallback;
@@ -223,11 +269,11 @@ type NonArrayObject = object & {
223
269
  export type EntityDataProp<T, C extends boolean> = T extends Date ? string | Date : T extends Scalar ? T : T extends {
224
270
  __runtime?: infer Runtime;
225
271
  __raw?: infer Raw;
226
- } ? (C extends true ? Raw : Runtime) : T extends Reference<infer U> ? EntityDataNested<U, C> : T extends ScalarReference<infer U> ? EntityDataProp<U, C> : T extends Collection<infer U, any> ? U | U[] | EntityDataNested<U, C> | EntityDataNested<U, C>[] : T extends readonly (infer U)[] ? U extends NonArrayObject ? U | U[] | EntityDataNested<U, C> | EntityDataNested<U, C>[] : U[] | EntityDataNested<U, C>[] : EntityDataNested<T, C>;
227
- export type RequiredEntityDataProp<T, O, C extends boolean> = T extends Date ? string | Date : T extends Scalar ? T : T extends {
272
+ } ? (C extends true ? Raw : Runtime) : T extends Reference<infer U> ? EntityDataNested<U, C> : T extends ScalarReference<infer U> ? EntityDataProp<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>;
273
+ 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 {
228
274
  __runtime?: infer Runtime;
229
275
  __raw?: infer Raw;
230
- } ? (C extends true ? Raw : Runtime) : T extends Reference<infer U> ? RequiredEntityDataNested<U, O, C> : T extends ScalarReference<infer U> ? RequiredEntityDataProp<U, O, C> : T extends Collection<infer U, any> ? U | U[] | RequiredEntityDataNested<U, O, C> | RequiredEntityDataNested<U, 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>;
276
+ } ? (C extends true ? Raw : Runtime) : T extends Reference<infer U> ? RequiredEntityDataNested<U, O, C> : T extends ScalarReference<infer U> ? RequiredEntityDataProp<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>;
231
277
  export type EntityDataNested<T, C extends boolean = false> = T extends undefined ? never : T extends any[] ? Readonly<T> : EntityData<T, C> | ExpandEntityProp<T, C>;
232
278
  type EntityDataItem<T, C extends boolean> = C extends false ? T | EntityDataProp<T, C> | null : EntityDataProp<T, C> | null;
233
279
  export type RequiredEntityDataNested<T, O, C extends boolean> = T extends any[] ? Readonly<T> : RequiredEntityData<T, O> | ExpandRequiredEntityProp<T, O, C>;
@@ -239,8 +285,11 @@ type ExplicitlyOptionalProps<T> = (T extends {
239
285
  type NullableKeys<T, V = null> = {
240
286
  [K in keyof T]: V extends T[K] ? K : never;
241
287
  }[keyof T];
242
- type ProbablyOptionalProps<T> = PrimaryProperty<T> | ExplicitlyOptionalProps<T> | NonNullable<NullableKeys<T, null | undefined>>;
243
- type IsOptional<T, K extends keyof T, I> = T[K] extends Collection<any, any> ? true : ExtractType<T[K]> extends I ? true : K extends ProbablyOptionalProps<T> ? true : false;
288
+ type RequiredNullableKeys<T> = {
289
+ [K in keyof T]: Exclude<T[K], null> extends RequiredNullable.Brand ? K : never;
290
+ }[keyof T];
291
+ type ProbablyOptionalProps<T> = PrimaryProperty<T> | ExplicitlyOptionalProps<T> | Exclude<NonNullable<NullableKeys<T, null | undefined>>, RequiredNullableKeys<T>>;
292
+ 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;
244
293
  type RequiredKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? CleanKeys<T, K> : never;
245
294
  type OptionalKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? never : CleanKeys<T, K>;
246
295
  export type EntityData<T, C extends boolean = false> = {
@@ -274,7 +323,7 @@ export type Ref<T> = T extends any ? IsAny<T> extends true ? Reference<T & objec
274
323
  type ExtractHiddenProps<T> = (T extends {
275
324
  [HiddenProps]?: infer K;
276
325
  } ? K : never) | ({
277
- [K in keyof T]: T[K] extends Hidden ? K : never;
326
+ [K in keyof T]: T[K] extends Primitive ? (T[K] extends Hidden ? K : never) : never;
278
327
  }[keyof T] & {});
279
328
  type ExcludeHidden<T, K extends keyof T> = K extends ExtractHiddenProps<T> ? never : K;
280
329
  type ExtractConfig<T> = T extends {
@@ -286,7 +335,7 @@ type PrimaryOrObject<T, U, C extends TypeConfig> = PreferExplicitConfig<C, Extra
286
335
  } : Primary<U>;
287
336
  export type EntityDTOProp<E, T, C extends TypeConfig = never> = T extends Scalar ? T : T extends {
288
337
  __serialized?: infer U;
289
- } ? (IsUnknown<U> extends false ? U : T) : T extends LoadedReference<infer U> ? EntityDTO<U, C> : T extends Reference<infer U> ? PrimaryOrObject<E, U, C> : T extends ScalarReference<infer U> ? U : T extends LoadedCollection<infer U> ? EntityDTO<U, C>[] : T extends Collection<infer U> ? PrimaryOrObject<E, U, C>[] : T extends readonly (infer U)[] ? (T extends readonly any[] ? T : U[]) : T extends Relation<T> ? EntityDTO<T, C> : T;
338
+ } ? (IsUnknown<U> extends false ? U : T) : T extends LoadedReference<infer U> ? EntityDTO<U, C> : T extends Reference<infer U> ? PrimaryOrObject<E, U, C> : T extends ScalarReference<infer U> ? U : T extends LoadedCollectionShape<infer U> ? EntityDTO<U & object, C>[] : T extends CollectionShape<infer U> ? PrimaryOrObject<E, U & object, C>[] : T extends readonly (infer U)[] ? U extends Scalar ? T : EntityDTOProp<E, U, C>[] : T extends Relation<T> ? EntityDTO<T, C> : T;
290
339
  type DTOProbablyOptionalProps<T> = NonNullable<NullableKeys<T, undefined>>;
291
340
  type DTOIsOptional<T, K extends keyof T> = T[K] extends LoadedCollection<any> ? false : K extends PrimaryProperty<T> ? false : K extends DTOProbablyOptionalProps<T> ? true : false;
292
341
  type DTORequiredKeys<T, K extends keyof T> = DTOIsOptional<T, K> extends false ? ExcludeHidden<T, K> & CleanKeys<T, K> : never;
@@ -297,8 +346,22 @@ export type EntityDTO<T, C extends TypeConfig = never> = {
297
346
  [K in keyof T as DTOOptionalKeys<T, K>]?: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
298
347
  };
299
348
  type TargetKeys<T> = T extends EntityClass<infer P> ? keyof P : keyof T;
300
- type CheckKey<T> = IsUnknown<T> extends false ? TargetKeys<T> : string;
301
- export type CheckCallback<T> = (columns: Record<CheckKey<T>, string>) => string;
349
+ type PropertyName<T> = IsUnknown<T> extends false ? TargetKeys<T> : string;
350
+ type TableName = {
351
+ name: string;
352
+ schema?: string;
353
+ toString: () => string;
354
+ };
355
+ export type FormulaTable = {
356
+ alias: string;
357
+ name: string;
358
+ schema?: string;
359
+ qualifiedName: string;
360
+ toString: () => string;
361
+ };
362
+ export type IndexCallback<T> = (table: TableName, columns: Record<PropertyName<T>, string>, indexName: string) => string | Raw;
363
+ export type FormulaCallback<T> = (table: FormulaTable, columns: Record<PropertyName<T>, string>) => string;
364
+ export type CheckCallback<T> = (columns: Record<PropertyName<T>, string>) => string;
302
365
  export type GeneratedColumnCallback<T> = (columns: Record<keyof T, string>) => string;
303
366
  export interface CheckConstraint<T = any> {
304
367
  name?: string;
@@ -309,6 +372,7 @@ export type AnyString = string & {};
309
372
  export interface EntityProperty<Owner = any, Target = any> {
310
373
  name: EntityKey<Owner>;
311
374
  entity: () => EntityName<Owner>;
375
+ target: EntityClass<Target>;
312
376
  type: keyof typeof types | AnyString;
313
377
  runtimeType: 'number' | 'string' | 'boolean' | 'bigint' | 'Buffer' | 'Date' | 'object' | 'any' | AnyString;
314
378
  targetMeta?: EntityMetadata<Target>;
@@ -334,7 +398,8 @@ export interface EntityProperty<Owner = any, Target = any> {
334
398
  fieldNameRaw?: string;
335
399
  default?: string | number | boolean | null;
336
400
  defaultRaw?: string;
337
- formula?: (alias: string) => string;
401
+ formula?: FormulaCallback<Owner>;
402
+ filters?: FilterOptions;
338
403
  prefix?: string | boolean;
339
404
  prefixMode?: EmbeddedPrefixMode;
340
405
  embedded?: [EntityKey<Owner>, EntityKey<Owner>];
@@ -347,11 +412,13 @@ export interface EntityProperty<Owner = any, Target = any> {
347
412
  unique?: boolean | string;
348
413
  nullable?: boolean;
349
414
  inherited?: boolean;
415
+ renamedFrom?: string;
416
+ stiFieldNames?: string[];
417
+ stiFieldNameMap?: Dictionary<string>;
350
418
  unsigned?: boolean;
351
419
  mapToPk?: boolean;
352
420
  persist?: boolean;
353
421
  hydrate?: boolean;
354
- trackChanges?: boolean;
355
422
  hidden?: boolean;
356
423
  enum?: boolean;
357
424
  items?: (number | string)[];
@@ -362,6 +429,7 @@ export interface EntityProperty<Owner = any, Target = any> {
362
429
  setter?: boolean;
363
430
  getter?: boolean;
364
431
  getterName?: keyof Owner;
432
+ accessor?: EntityKey<Owner>;
365
433
  cascade: Cascade[];
366
434
  orphanRemoval?: boolean;
367
435
  onCreate?: (entity: Owner, em: EntityManager) => any;
@@ -378,13 +446,14 @@ export interface EntityProperty<Owner = any, Target = any> {
378
446
  fixedOrder?: boolean;
379
447
  fixedOrderColumn?: string;
380
448
  pivotTable: string;
381
- pivotEntity: string;
449
+ pivotEntity: EntityClass<Target>;
382
450
  joinColumns: string[];
383
451
  ownColumns: string[];
384
452
  inverseJoinColumns: string[];
385
453
  referencedColumnNames: string[];
386
454
  referencedTableName: string;
387
455
  referencedPKs: EntityKey<Owner>[];
456
+ targetKey?: string;
388
457
  serializer?: (value: any, options?: SerializeOptions<any>) => any;
389
458
  serializedName?: string;
390
459
  comment?: string;
@@ -394,19 +463,22 @@ export interface EntityProperty<Owner = any, Target = any> {
394
463
  optional?: boolean;
395
464
  ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
396
465
  deferMode?: DeferMode;
466
+ createForeignKeyConstraint: boolean;
397
467
  foreignKeyName?: string;
398
468
  }
399
- export declare class EntityMetadata<T = any> {
469
+ export declare class EntityMetadata<Entity = any, Class extends EntityCtor<Entity> = EntityCtor<Entity>> {
400
470
  private static counter;
401
471
  readonly _id: number;
402
472
  readonly propertyOrder: Map<string, number>;
403
473
  constructor(meta?: Partial<EntityMetadata>);
404
- addProperty(prop: Partial<EntityProperty<T>>, sync?: boolean): void;
474
+ addProperty(prop: Partial<EntityProperty<Entity>>): void;
405
475
  removeProperty(name: string, sync?: boolean): void;
406
- getPrimaryProps(): EntityProperty<T>[];
407
- getPrimaryProp(): EntityProperty<T>;
476
+ getPrimaryProps(flatten?: boolean): EntityProperty<Entity>[];
477
+ getPrimaryProp(): EntityProperty<Entity>;
478
+ createColumnMappingObject(): Record<PropertyName<Entity>, string>;
408
479
  get tableName(): string;
409
480
  set tableName(name: string);
481
+ get uniqueName(): string;
410
482
  sync(initIndexes?: boolean, config?: Configuration): void;
411
483
  private initIndexes;
412
484
  /** @internal */
@@ -416,67 +488,74 @@ export interface SimpleColumnMeta {
416
488
  name: string;
417
489
  type: string;
418
490
  }
419
- export interface EntityMetadata<T = any> {
491
+ export type EntityCtor<T = any> = abstract new (...args: any[]) => T;
492
+ export interface EntityMetadata<Entity = any, Class extends EntityCtor<Entity> = EntityCtor<Entity>> {
420
493
  name?: string;
421
494
  className: string;
422
495
  tableName: string;
423
496
  schema?: string;
424
497
  pivotTable?: boolean;
425
498
  virtual?: boolean;
426
- expression?: string | ((em: any, where: ObjectQuery<T>, options: FindOptions<T, any, any, any>) => MaybePromise<RawQueryFragment | object | string>);
427
- discriminatorColumn?: EntityKey<T> | AnyString;
499
+ /** True if this entity represents a database view (not a virtual entity). */
500
+ view?: boolean;
501
+ /** True if this is a materialized view (PostgreSQL only). Requires `view: true`. */
502
+ materialized?: boolean;
503
+ /** For materialized views, whether data is populated on creation. Defaults to true. */
504
+ withData?: boolean;
505
+ expression?: string | ((em: any, where: ObjectQuery<Entity>, options: FindOptions<Entity, any, any, any>, stream?: boolean) => MaybePromise<Raw | object | string>);
506
+ discriminatorColumn?: EntityKey<Entity> | AnyString;
428
507
  discriminatorValue?: number | string;
429
- discriminatorMap?: Dictionary<string>;
508
+ discriminatorMap?: Dictionary<EntityClass>;
430
509
  embeddable: boolean;
431
- constructorParams: EntityKey<T>[];
510
+ constructorParams?: (keyof Entity)[];
432
511
  forceConstructor: boolean;
433
- toJsonParams: string[];
434
- extends: string;
512
+ extends?: EntityName<Entity>;
435
513
  collection: string;
436
514
  path: string;
437
- primaryKeys: EntityKey<T>[];
515
+ primaryKeys: EntityKey<Entity>[];
438
516
  simplePK: boolean;
439
517
  compositePK: boolean;
440
- versionProperty: EntityKey<T>;
441
- concurrencyCheckKeys: Set<EntityKey<T>>;
442
- serializedPrimaryKey: EntityKey<T>;
518
+ versionProperty: EntityKey<Entity>;
519
+ concurrencyCheckKeys: Set<EntityKey<Entity>>;
520
+ serializedPrimaryKey?: EntityKey<Entity>;
443
521
  properties: {
444
- [K in EntityKey<T>]: EntityProperty<T>;
522
+ [K in EntityKey<Entity>]: EntityProperty<Entity>;
445
523
  };
446
- props: EntityProperty<T>[];
447
- relations: EntityProperty<T>[];
448
- bidirectionalRelations: EntityProperty<T>[];
524
+ props: EntityProperty<Entity>[];
525
+ relations: EntityProperty<Entity>[];
526
+ bidirectionalRelations: EntityProperty<Entity>[];
449
527
  referencingProperties: {
450
- meta: EntityMetadata<T>;
451
- prop: EntityProperty<T>;
528
+ meta: EntityMetadata<Entity>;
529
+ prop: EntityProperty<Entity>;
452
530
  }[];
453
- comparableProps: EntityProperty<T>[];
454
- trackingProps: EntityProperty<T>[];
455
- hydrateProps: EntityProperty<T>[];
456
- uniqueProps: EntityProperty<T>[];
457
- getterProps: EntityProperty<T>[];
531
+ comparableProps: EntityProperty<Entity>[];
532
+ trackingProps: EntityProperty<Entity>[];
533
+ hydrateProps: EntityProperty<Entity>[];
534
+ validateProps: EntityProperty<Entity>[];
535
+ uniqueProps: EntityProperty<Entity>[];
536
+ getterProps: EntityProperty<Entity>[];
458
537
  indexes: {
459
- properties: EntityKey<T> | EntityKey<T>[];
538
+ properties?: EntityKey<Entity> | EntityKey<Entity>[];
460
539
  name?: string;
461
540
  type?: string;
462
541
  options?: Dictionary;
463
- expression?: string;
542
+ expression?: string | IndexCallback<Entity>;
464
543
  }[];
465
544
  uniques: {
466
- properties: EntityKey<T> | EntityKey<T>[];
545
+ properties?: EntityKey<Entity> | EntityKey<Entity>[];
467
546
  name?: string;
468
547
  options?: Dictionary;
469
- expression?: string;
470
- deferMode?: DeferMode;
548
+ expression?: string | IndexCallback<Entity>;
549
+ deferMode?: DeferMode | `${DeferMode}`;
471
550
  }[];
472
- checks: CheckConstraint<T>[];
551
+ checks: CheckConstraint<Entity>[];
473
552
  repositoryClass?: string;
474
553
  repository: () => EntityClass<EntityRepository<any>>;
475
554
  hooks: {
476
- [K in EventType]?: (keyof T | EventSubscriber<T>[EventType])[];
555
+ [K in EventType]?: (keyof Entity | EventSubscriber<Entity>[EventType])[];
477
556
  };
478
- prototype: T;
479
- class: EntityClass<T>;
557
+ prototype: Entity;
558
+ class: Class;
480
559
  abstract: boolean;
481
560
  filters: Dictionary<FilterDef>;
482
561
  comment?: string;
@@ -484,8 +563,9 @@ export interface EntityMetadata<T = any> {
484
563
  hasUniqueProps?: boolean;
485
564
  readonly?: boolean;
486
565
  polymorphs?: EntityMetadata[];
487
- root: EntityMetadata<T>;
566
+ root: EntityMetadata<Entity>;
488
567
  definedProperties: Dictionary;
568
+ hasTriggers?: boolean;
489
569
  /** @internal can be used for computed numeric cache keys */
490
570
  readonly _id: number;
491
571
  }
@@ -496,6 +576,7 @@ export interface CreateSchemaOptions {
496
576
  export interface ClearDatabaseOptions {
497
577
  schema?: string;
498
578
  truncate?: boolean;
579
+ clearIdentityMap?: boolean;
499
580
  }
500
581
  export interface EnsureDatabaseOptions extends CreateSchemaOptions, ClearDatabaseOptions {
501
582
  clear?: boolean;
@@ -523,25 +604,25 @@ export interface RefreshDatabaseOptions extends CreateSchemaOptions {
523
604
  createSchema?: boolean;
524
605
  }
525
606
  export interface ISchemaGenerator {
526
- createSchema(options?: CreateSchemaOptions): Promise<void>;
527
- ensureDatabase(options?: EnsureDatabaseOptions): Promise<boolean>;
607
+ create(options?: CreateSchemaOptions): Promise<void>;
608
+ update(options?: UpdateSchemaOptions): Promise<void>;
609
+ drop(options?: DropSchemaOptions): Promise<void>;
610
+ refresh(options?: RefreshDatabaseOptions): Promise<void>;
611
+ clear(options?: ClearDatabaseOptions): Promise<void>;
612
+ execute(sql: string, options?: {
613
+ wrap?: boolean;
614
+ }): Promise<void>;
528
615
  getCreateSchemaSQL(options?: CreateSchemaOptions): Promise<string>;
529
- dropSchema(options?: DropSchemaOptions): Promise<void>;
530
616
  getDropSchemaSQL(options?: Omit<DropSchemaOptions, 'dropDb'>): Promise<string>;
531
- updateSchema(options?: UpdateSchemaOptions): Promise<void>;
532
617
  getUpdateSchemaSQL(options?: UpdateSchemaOptions): Promise<string>;
533
618
  getUpdateSchemaMigrationSQL(options?: UpdateSchemaOptions): Promise<{
534
619
  up: string;
535
620
  down: string;
536
621
  }>;
622
+ ensureDatabase(options?: EnsureDatabaseOptions): Promise<boolean>;
537
623
  createDatabase(name?: string): Promise<void>;
538
624
  dropDatabase(name?: string): Promise<void>;
539
- execute(sql: string, options?: {
540
- wrap?: boolean;
541
- }): Promise<void>;
542
625
  ensureIndexes(): Promise<void>;
543
- refreshDatabase(options?: RefreshDatabaseOptions): Promise<void>;
544
- clearDatabase(options?: ClearDatabaseOptions): Promise<void>;
545
626
  }
546
627
  export type ImportsResolver = (alias: string, basePath: string, extension: '.js' | '', originFileName: string) => {
547
628
  path: string;
@@ -558,7 +639,10 @@ export interface GenerateOptions {
558
639
  undefinedDefaults?: boolean;
559
640
  bidirectionalRelations?: boolean;
560
641
  identifiedReferences?: boolean;
561
- entitySchema?: boolean;
642
+ entityDefinition?: 'decorators' | 'defineEntity' | 'entitySchema';
643
+ decorators?: 'es' | 'legacy';
644
+ inferEntityType?: boolean;
645
+ enumMode?: 'ts-enum' | 'union-type' | 'dictionary';
562
646
  esmImport?: boolean;
563
647
  scalarTypeInDecorator?: boolean;
564
648
  scalarPropertiesForRelations?: 'always' | 'never' | 'smart';
@@ -618,26 +702,26 @@ export interface IMigrator {
618
702
  /**
619
703
  * Checks current schema for changes, generates new migration if there are any.
620
704
  */
621
- createMigration(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<MigrationResult>;
705
+ create(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<MigrationResult>;
622
706
  /**
623
707
  * Checks current schema for changes.
624
708
  */
625
- checkMigrationNeeded(): Promise<boolean>;
709
+ checkSchema(): Promise<boolean>;
626
710
  /**
627
711
  * Creates initial migration. This generates the schema based on metadata, and checks whether all the tables
628
712
  * are already present. If yes, it will also automatically log the migration as executed.
629
713
  * Initial migration can be created only if the schema is already aligned with the metadata, or when no schema
630
714
  * is present - in such case regular migration would have the same effect.
631
715
  */
632
- createInitialMigration(path?: string): Promise<MigrationResult>;
716
+ createInitial(path?: string): Promise<MigrationResult>;
633
717
  /**
634
718
  * Returns list of already executed migrations.
635
719
  */
636
- getExecutedMigrations(): Promise<MigrationRow[]>;
720
+ getExecuted(): Promise<MigrationRow[]>;
637
721
  /**
638
722
  * Returns list of pending (not yet executed) migrations found in the migration directory.
639
723
  */
640
- getPendingMigrations(): Promise<UmzugMigration[]>;
724
+ getPending(): Promise<UmzugMigration[]>;
641
725
  /**
642
726
  * Executes specified migrations. Without parameter it will migrate up to the latest version.
643
727
  */
@@ -686,12 +770,17 @@ export interface MigrationObject {
686
770
  name: string;
687
771
  class: Constructor<Migration>;
688
772
  }
689
- export type FilterDef = {
773
+ type EntityFromInput<T> = T extends readonly EntityName<infer U>[] ? U : T extends EntityName<infer U> ? U : never;
774
+ type FilterDefResolved<T extends object = any> = {
690
775
  name: string;
691
- cond: Dictionary | ((args: Dictionary, type: 'read' | 'update' | 'delete', em: any, options?: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any>, entityName?: EntityName<any>) => Dictionary | Promise<Dictionary>);
776
+ 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>>);
692
777
  default?: boolean;
693
- entity?: string[];
778
+ entity?: EntityName<T> | EntityName<T>[];
694
779
  args?: boolean;
780
+ strict?: boolean;
781
+ };
782
+ export type FilterDef<T extends EntityName | readonly EntityName[] = any> = FilterDefResolved<EntityFromInput<T>> & {
783
+ entity?: T;
695
784
  };
696
785
  export type Populate<T, P extends string = never> = readonly AutoPath<T, P, `${PopulatePath}`>[] | false;
697
786
  export type PopulateOptions<T> = {
@@ -699,40 +788,58 @@ export type PopulateOptions<T> = {
699
788
  strategy?: LoadStrategy;
700
789
  all?: boolean;
701
790
  filter?: boolean;
791
+ joinType?: 'inner join' | 'left join';
702
792
  children?: PopulateOptions<T[keyof T]>[];
793
+ /** When true, ignores `mapToPk` on the property and returns full entity data instead of just PKs. */
794
+ dataOnly?: boolean;
703
795
  };
704
796
  type Loadable<T extends object> = Collection<T, any> | Reference<T> | Ref<T> | readonly T[];
705
- type ExtractType<T> = T extends Loadable<infer U> ? U : T;
797
+ type ExtractType<T> = T extends CollectionShape<infer U> ? U : T extends Reference<infer U> ? U : T extends Ref<infer U> ? U : T extends readonly (infer U)[] ? U : T;
706
798
  type ExtractStringKeys<T> = {
707
- [K in keyof T]: CleanKeys<T, K>;
799
+ [K in keyof T]-?: CleanKeys<T, K>;
708
800
  }[keyof T] & {};
709
- type StringKeys<T, E extends string = never> = T extends Collection<any, any> ? ExtractStringKeys<ExtractType<T>> | E : T extends Reference<any> ? ExtractStringKeys<ExtractType<T>> | E : T extends object ? ExtractStringKeys<ExtractType<T>> | E : never;
801
+ type StringKeys<T, E extends string = never> = T extends CollectionShape ? ExtractStringKeys<ExtractType<T>> | E : T extends Reference<any> ? ExtractStringKeys<ExtractType<T>> | E : T extends object ? ExtractStringKeys<ExtractType<T>> | E : never;
710
802
  type GetStringKey<T, K extends StringKeys<T, string>, E extends string> = K extends keyof T ? ExtractType<T[K]> : (K extends E ? keyof T : never);
711
803
  type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
712
804
  type CollectionKeys<T> = T extends object ? {
713
- [K in keyof T]: T[K] extends Collection<any> ? IsAny<T[K]> extends true ? never : K & string : never;
805
+ [K in keyof T]-?: T[K] extends CollectionShape ? IsAny<T[K]> extends true ? never : K & string : never;
714
806
  }[keyof T] & {} : never;
715
807
  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 & `${string}.` extends never ? P : P & `${string}.`) extends infer Q ? Q extends `${infer A}.${infer B}` ? A extends StringKeys<O, E> ? `${A}.${AutoPath<NonNullable<GetStringKey<O, A, E>>, B, E, Prev[D]>}` : never : Q extends StringKeys<O, E> ? (NonNullable<GetStringKey<O, Q, E>> extends unknown ? Exclude<P, `${string}.`> : never) | (StringKeys<NonNullable<GetStringKey<O, Q, E>>, E> extends never ? never : `${Q & string}.`) : StringKeys<O, E> | `${CollectionKeys<O>}:ref` : never : never : never;
716
808
  export type UnboxArray<T> = T extends any[] ? ArrayElement<T> : T;
717
809
  export type ArrayElement<ArrayType extends unknown[]> = ArrayType extends (infer ElementType)[] ? ElementType : never;
718
- export type ExpandProperty<T> = T extends Reference<infer U> ? NonNullable<U> : T extends Collection<infer U, any> ? NonNullable<U> : T extends (infer U)[] ? NonNullable<U> : NonNullable<T>;
719
- type LoadedLoadable<T, E extends object> = T extends Collection<any, any> ? LoadedCollection<E> : T extends Reference<any> ? T & LoadedReference<E> : T extends ScalarReference<infer U> ? LoadedScalarReference<U> : T extends Scalar | any[] ? T : E;
810
+ export type ExpandProperty<T> = T extends Reference<infer U> ? NonNullable<U> : T extends CollectionShape<infer U> ? NonNullable<U> : T extends (infer U)[] ? NonNullable<U> : NonNullable<T>;
811
+ type LoadedLoadable<T, E extends object> = T extends CollectionShape ? LoadedCollection<E> : T extends Reference<any> ? T & LoadedReference<E> : T extends ScalarReference<infer U> ? LoadedScalarReference<U> : T extends Scalar ? T : T extends (infer U)[] ? U extends Scalar ? T : E[] : E;
720
812
  type IsTrue<T> = IsNever<T> extends true ? false : T extends boolean ? T extends true ? true : false : false;
721
813
  type StringLiteral<T> = T extends string ? string extends T ? never : T : never;
722
814
  type Prefix<T, K> = K extends `${infer S}.${string}` ? S : (K extends '*' ? keyof T : K);
723
815
  type IsPrefixedExclude<T, K extends keyof T, E extends string> = K extends E ? never : K;
724
816
  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 Loadable<any> ? K : never) : IsNever<StringLiteral<L>> extends true ? never : K extends Prefix<T, L> ? K : K extends PrimaryProperty<T> ? K : never;
725
817
  type Suffix<Key, Hint extends string, All = true | '*'> = Hint extends `${infer Pref}.${infer Suf}` ? (Pref extends Key ? Suf : never) : Hint extends All ? Hint : never;
726
- export type IsSubset<T, U> = keyof U extends keyof T ? {} : Dictionary extends U ? {} : {
818
+ export type IsSubset<T, U> = keyof U extends keyof T ? {} : string extends keyof U ? {} : {
727
819
  [K in keyof U as K extends keyof T ? never : CleanKeys<U, K>]: never;
728
820
  };
729
821
  declare const __selectedType: unique symbol;
730
822
  declare const __loadedType: unique symbol;
731
- type AnyStringToNever<T> = string extends T ? never : T;
732
- export type MergeSelected<T, U, F extends string> = T extends Loaded<infer TT, infer P, infer FF, infer E> ? IsNever<Exclude<E, F>> extends true ? Loaded<TT, P, AnyStringToNever<F> | AnyStringToNever<FF>> : Loaded<TT, AnyStringToNever<P>, AnyStringToNever<FF>, AnyStringToNever<Exclude<E, F>>> : T;
733
- type MergeFields<F1 extends string, F2 extends string, P1, P2> = P1 | P2 extends '*' ? '*' : F1 | F2;
734
- type MergeExcludes<F extends string, E extends string> = F extends E ? never : Exclude<E, F>;
735
- export type MergeLoaded<T, U, P extends string, F extends string, E extends string, R extends boolean = false> = T extends Loaded<U, infer PP, infer FF, infer EE> ? string extends FF ? Loaded<T, P, F, AnyStringToNever<EE> | E> : string extends P ? Loaded<U, never, F | (FF & string), MergeExcludes<F | (FF & string), EE | E>> : Loaded<U, P | AnyStringToNever<PP>, MergeFields<F, AnyStringToNever<FF>, P, PP>, MergeExcludes<MergeFields<F, AnyStringToNever<FF>, P, PP>, (R extends true ? never : EE) | E>> : Loaded<T, P, F>;
823
+ /**
824
+ * Fast check if T is a Loaded type by looking for the marker symbol.
825
+ * This is much cheaper than matching against the full Loaded structure.
826
+ */
827
+ type IsLoadedType<T> = T extends {
828
+ [__loadedType]?: any;
829
+ } ? true : false;
830
+ /**
831
+ * Optimized MergeSelected using intersection instead of extraction.
832
+ * When T is already Loaded, we intersect with a new Loaded type for the selected fields.
833
+ * This avoids the expensive pattern matching needed to extract hints from Loaded types.
834
+ */
835
+ export type MergeSelected<T, U, F extends string> = IsLoadedType<T> extends true ? T & Loaded<U, never, F, never> : T;
836
+ /**
837
+ * Optimized MergeLoaded using intersection instead of extraction.
838
+ * When T is already Loaded, we intersect with a new Loaded type for the additional hints.
839
+ * This avoids the expensive pattern matching needed to extract hints from Loaded types.
840
+ * Used for `em.populate` and `em.refresh`.
841
+ */
842
+ 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>;
736
843
  export type AddOptional<T> = undefined | null extends T ? null | undefined : null extends T ? null : undefined extends T ? undefined : never;
737
844
  type LoadedProp<T, L extends string = never, F extends string = '*', E extends string = never> = LoadedLoadable<T, Loaded<ExtractType<T>, L, F, E>>;
738
845
  export type AddEager<T> = ExtractEagerProps<T> & string;
@@ -782,23 +889,23 @@ export interface Highlighter {
782
889
  highlight(text: string): string;
783
890
  }
784
891
  export interface IMetadataStorage {
785
- getAll(): Dictionary<EntityMetadata>;
786
- get<T = any>(entity: string, init?: boolean, validate?: boolean): EntityMetadata<T>;
787
- find<T = any>(entity: string): EntityMetadata<T> | undefined;
788
- has(entity: string): boolean;
789
- set(entity: string, meta: EntityMetadata): EntityMetadata;
790
- reset(entity: string): void;
892
+ getAll(): Map<EntityName, EntityMetadata>;
893
+ get<T = any>(entity: EntityName<T>, init?: boolean, validate?: boolean): EntityMetadata<T>;
894
+ find<T = any>(entity: EntityName<T>): EntityMetadata<T> | undefined;
895
+ has<T>(entity: EntityName<T>): boolean;
896
+ set<T>(entity: EntityName<T>, meta: EntityMetadata): EntityMetadata;
897
+ reset<T>(entity: EntityName<T>): void;
791
898
  }
792
899
  export interface IHydrator {
793
900
  /**
794
901
  * Hydrates the whole entity. This process handles custom type conversions, creating missing Collection instances,
795
902
  * mapping FKs to entity instances, as well as merging those entities.
796
903
  */
797
- 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): void;
904
+ 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;
798
905
  /**
799
906
  * Hydrates primary keys only
800
907
  */
801
- hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
908
+ hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void;
802
909
  isRunning(): boolean;
803
910
  }
804
911
  export interface HydratorConstructor {
@@ -808,17 +915,22 @@ export interface ISeedManager {
808
915
  seed(...classNames: Constructor<Seeder>[]): Promise<void>;
809
916
  /** @internal */
810
917
  seedString(...classNames: string[]): Promise<void>;
811
- createSeeder(className: string): Promise<string>;
918
+ create(className: string): Promise<string>;
812
919
  }
813
920
  export interface Seeder<T extends Dictionary = Dictionary> {
814
921
  run(em: EntityManager, context?: T): void | Promise<void>;
815
922
  }
816
923
  export type ConnectionType = 'read' | 'write';
817
924
  export type MetadataProcessor = (metadata: EntityMetadata[], platform: Platform) => MaybePromise<void>;
818
- /**
819
- * The type of context that the user intends to inject.
820
- */
821
- export type ContextProvider<T> = MaybePromise<MikroORM> | ((type: T) => MaybePromise<MikroORM | EntityManager | EntityRepository<any> | {
822
- getEntityManager(): EntityManager;
823
- }>);
925
+ export type MaybeReturnType<T> = T extends (...args: any[]) => infer R ? R : T;
926
+ 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> {
927
+ readonly name: TName;
928
+ readonly properties: TProperties;
929
+ readonly tableName: TTableName;
930
+ /** @internal Direct entity type access - avoids expensive pattern matching */
931
+ readonly '~entity': TEntity;
932
+ }
933
+ export type InferEntity<Schema> = Schema extends {
934
+ '~entity': infer E;
935
+ } ? E : Schema extends EntitySchema<infer Entity> ? Entity : Schema extends EntityClass<infer Entity> ? Entity : Schema;
824
936
  export {};