@mikro-orm/core 7.0.0-dev.14 → 7.0.0-dev.141

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/EntityManager.d.ts +87 -57
  2. package/EntityManager.js +334 -294
  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 +38 -17
  17. package/entity/BaseEntity.d.ts +2 -2
  18. package/entity/BaseEntity.js +0 -3
  19. package/entity/Collection.d.ts +95 -30
  20. package/entity/Collection.js +441 -99
  21. package/entity/EntityAssigner.d.ts +1 -1
  22. package/entity/EntityAssigner.js +26 -18
  23. package/entity/EntityFactory.d.ts +7 -0
  24. package/entity/EntityFactory.js +72 -53
  25. package/entity/EntityHelper.d.ts +2 -2
  26. package/entity/EntityHelper.js +35 -15
  27. package/entity/EntityLoader.d.ts +7 -6
  28. package/entity/EntityLoader.js +84 -72
  29. package/entity/EntityRepository.d.ts +1 -1
  30. package/entity/EntityRepository.js +2 -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 +575 -0
  36. package/entity/defineEntity.js +529 -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 +22 -6
  44. package/enums.js +15 -1
  45. package/errors.d.ts +18 -9
  46. package/errors.js +44 -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 +50 -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 +22 -24
  64. package/metadata/EntitySchema.js +73 -51
  65. package/metadata/MetadataDiscovery.d.ts +6 -10
  66. package/metadata/MetadataDiscovery.js +297 -301
  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 +11 -9
  72. package/metadata/MetadataValidator.js +50 -38
  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 +480 -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 +19 -11
  91. package/platforms/ExceptionConverter.js +1 -1
  92. package/platforms/Platform.d.ts +6 -13
  93. package/platforms/Platform.js +17 -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 +157 -112
  120. package/typings.js +55 -42
  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 +14 -12
  125. package/unit-of-work/ChangeSetPersister.d.ts +5 -4
  126. package/unit-of-work/ChangeSetPersister.js +65 -33
  127. package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
  128. package/unit-of-work/CommitOrderCalculator.js +13 -13
  129. package/unit-of-work/UnitOfWork.d.ts +10 -3
  130. package/unit-of-work/UnitOfWork.js +141 -98
  131. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  132. package/utils/AbstractSchemaGenerator.js +18 -16
  133. package/utils/AsyncContext.d.ts +6 -0
  134. package/utils/AsyncContext.js +42 -0
  135. package/utils/Configuration.d.ts +754 -207
  136. package/utils/Configuration.js +146 -190
  137. package/utils/ConfigurationLoader.d.ts +1 -54
  138. package/utils/ConfigurationLoader.js +1 -352
  139. package/utils/Cursor.d.ts +0 -3
  140. package/utils/Cursor.js +27 -11
  141. package/utils/DataloaderUtils.d.ts +15 -5
  142. package/utils/DataloaderUtils.js +65 -17
  143. package/utils/EntityComparator.d.ts +13 -9
  144. package/utils/EntityComparator.js +85 -43
  145. package/utils/QueryHelper.d.ts +14 -6
  146. package/utils/QueryHelper.js +87 -25
  147. package/utils/RawQueryFragment.d.ts +48 -25
  148. package/utils/RawQueryFragment.js +66 -70
  149. package/utils/RequestContext.js +2 -2
  150. package/utils/TransactionContext.js +2 -2
  151. package/utils/TransactionManager.d.ts +65 -0
  152. package/utils/TransactionManager.js +223 -0
  153. package/utils/Utils.d.ts +12 -119
  154. package/utils/Utils.js +97 -373
  155. package/utils/clone.js +8 -23
  156. package/utils/env-vars.d.ts +7 -0
  157. package/utils/env-vars.js +97 -0
  158. package/utils/fs-utils.d.ts +32 -0
  159. package/utils/fs-utils.js +178 -0
  160. package/utils/index.d.ts +2 -1
  161. package/utils/index.js +2 -1
  162. package/utils/upsert-utils.d.ts +9 -4
  163. package/utils/upsert-utils.js +55 -4
  164. package/decorators/Check.d.ts +0 -3
  165. package/decorators/Check.js +0 -13
  166. package/decorators/CreateRequestContext.d.ts +0 -3
  167. package/decorators/CreateRequestContext.js +0 -32
  168. package/decorators/Embeddable.d.ts +0 -8
  169. package/decorators/Embeddable.js +0 -11
  170. package/decorators/Embedded.d.ts +0 -18
  171. package/decorators/Embedded.js +0 -18
  172. package/decorators/Entity.d.ts +0 -18
  173. package/decorators/Entity.js +0 -12
  174. package/decorators/Enum.d.ts +0 -9
  175. package/decorators/Enum.js +0 -16
  176. package/decorators/Filter.d.ts +0 -2
  177. package/decorators/Filter.js +0 -8
  178. package/decorators/Formula.d.ts +0 -4
  179. package/decorators/Formula.js +0 -15
  180. package/decorators/Indexed.d.ts +0 -19
  181. package/decorators/Indexed.js +0 -20
  182. package/decorators/ManyToMany.d.ts +0 -40
  183. package/decorators/ManyToMany.js +0 -14
  184. package/decorators/ManyToOne.d.ts +0 -30
  185. package/decorators/ManyToOne.js +0 -14
  186. package/decorators/OneToMany.d.ts +0 -28
  187. package/decorators/OneToMany.js +0 -17
  188. package/decorators/OneToOne.d.ts +0 -24
  189. package/decorators/OneToOne.js +0 -7
  190. package/decorators/PrimaryKey.d.ts +0 -8
  191. package/decorators/PrimaryKey.js +0 -20
  192. package/decorators/Property.d.ts +0 -250
  193. package/decorators/Property.js +0 -32
  194. package/decorators/Transactional.d.ts +0 -13
  195. package/decorators/Transactional.js +0 -28
  196. package/decorators/hooks.d.ts +0 -16
  197. package/decorators/hooks.js +0 -47
  198. package/decorators/index.d.ts +0 -17
  199. package/decorators/index.js +0 -17
  200. package/entity/ArrayCollection.d.ts +0 -116
  201. package/entity/ArrayCollection.js +0 -402
  202. package/entity/EntityValidator.d.ts +0 -19
  203. package/entity/EntityValidator.js +0 -150
  204. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  205. package/metadata/ReflectMetadataProvider.js +0 -44
  206. package/utils/resolveContextProvider.d.ts +0 -10
  207. 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;
@@ -52,18 +50,34 @@ export declare const OptionalProps: unique symbol;
52
50
  export declare const EagerProps: unique symbol;
53
51
  export declare const HiddenProps: unique symbol;
54
52
  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
- };
53
+ export type Opt<T = unknown> = T & Opt.Brand;
54
+ export declare namespace Opt {
55
+ const __optional: unique symbol;
56
+ interface Brand {
57
+ [__optional]?: 1;
58
+ }
59
+ }
60
+ export type RequiredNullable<T = never> = (T & RequiredNullable.Brand) | null;
61
+ export declare namespace RequiredNullable {
62
+ const __requiredNullable: unique symbol;
63
+ interface Brand {
64
+ [__requiredNullable]?: 1;
65
+ }
66
+ }
67
+ export type Hidden<T = unknown> = T & Hidden.Brand;
68
+ export declare namespace Hidden {
69
+ const __hidden: unique symbol;
70
+ interface Brand {
71
+ [__hidden]?: 1;
72
+ }
73
+ }
74
+ export type DefineConfig<T extends TypeConfig> = T & DefineConfig.Brand;
75
+ export declare namespace DefineConfig {
76
+ const __config: unique symbol;
77
+ interface Brand {
78
+ [__config]?: 1;
79
+ }
80
+ }
67
81
  export type CleanTypeConfig<T> = Compute<Pick<T, Extract<keyof T, keyof TypeConfig>>>;
68
82
  export interface TypeConfig {
69
83
  forceObject?: boolean;
@@ -75,13 +89,14 @@ type PrimaryPropToType<T, Keys extends (keyof T)[]> = {
75
89
  type ReadonlyPrimary<T> = T extends any[] ? Readonly<T> : T;
76
90
  export type Primary<T> = IsAny<T> extends true ? any : T extends {
77
91
  [PrimaryKeyProp]?: infer PK;
78
- } ? (PK extends keyof T ? ReadonlyPrimary<UnwrapPrimary<T[PK]>> : (PK extends (keyof T)[] ? ReadonlyPrimary<PrimaryPropToType<T, PK>> : PK)) : T extends {
92
+ } ? 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
93
  _id?: infer PK;
80
94
  } ? ReadonlyPrimary<PK> | string : T extends {
81
- uuid?: infer PK;
82
- } ? ReadonlyPrimary<PK> : T extends {
83
95
  id?: infer PK;
96
+ } ? ReadonlyPrimary<PK> : T extends {
97
+ uuid?: infer PK;
84
98
  } ? ReadonlyPrimary<PK> : T;
99
+ /** @internal */
85
100
  export type PrimaryProperty<T> = T extends {
86
101
  [PrimaryKeyProp]?: infer PK;
87
102
  } ? (PK extends keyof T ? PK : (PK extends any[] ? PK[number] : never)) : T extends {
@@ -89,10 +104,10 @@ export type PrimaryProperty<T> = T extends {
89
104
  } ? (T extends {
90
105
  id?: any;
91
106
  } ? 'id' | '_id' : '_id') : T extends {
92
- uuid?: any;
93
- } ? 'uuid' : T extends {
94
107
  id?: any;
95
- } ? 'id' : never;
108
+ } ? 'id' : T extends {
109
+ uuid?: any;
110
+ } ? 'uuid' : never;
96
111
  export type IPrimaryKeyValue = number | string | bigint | Date | {
97
112
  toHexString(): string;
98
113
  };
@@ -112,6 +127,14 @@ export type OperatorMap<T> = {
112
127
  $none?: ExpandQuery<T>;
113
128
  $some?: ExpandQuery<T>;
114
129
  $every?: ExpandQuery<T>;
130
+ $size?: number | {
131
+ $eq?: number;
132
+ $ne?: number;
133
+ $gt?: number;
134
+ $gte?: number;
135
+ $lt?: number;
136
+ $lte?: number;
137
+ };
115
138
  $gt?: ExpandScalar<T>;
116
139
  $gte?: ExpandScalar<T>;
117
140
  $lt?: ExpandScalar<T>;
@@ -133,7 +156,6 @@ export type FilterValue<T> = OperatorMap<FilterItemValue<T>> | FilterItemValue<T
133
156
  export type FilterObject<T> = {
134
157
  -readonly [K in EntityKey<T>]?: ExpandQuery<ExpandProperty<T[K]>> | FilterValue<ExpandProperty<T[K]>> | null;
135
158
  };
136
- export type ExpandObject<T> = T extends object ? T extends Scalar ? never : FilterObject<T> : never;
137
159
  export type ExpandQuery<T> = T extends object ? T extends Scalar ? never : FilterQuery<T> : FilterValue<T>;
138
160
  export type EntityProps<T> = {
139
161
  -readonly [K in EntityKey<T>]?: T[K];
@@ -143,10 +165,9 @@ export type FilterQuery<T> = ObjectQuery<T> | NonNullable<ExpandScalar<Primary<T
143
165
  export type QBFilterQuery<T = any> = ObjectQuery<T> | Dictionary;
144
166
  export interface IWrappedEntity<Entity extends object> {
145
167
  isInitialized(): boolean;
146
- isTouched(): boolean;
147
168
  isManaged(): boolean;
148
169
  populated(populated?: boolean): void;
149
- populate<Hint extends string = never>(populate: AutoPath<Entity, Hint>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
170
+ populate<Hint extends string = never>(populate: readonly AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
150
171
  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
172
  toReference(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
152
173
  toObject(): EntityDTO<Entity>;
@@ -174,7 +195,6 @@ export interface IWrappedEntityInternal<Entity extends object> extends IWrappedE
174
195
  __factory: EntityFactory;
175
196
  __hydrator: IHydrator;
176
197
  __initialized: boolean;
177
- __touched: boolean;
178
198
  __originalEntityData?: EntityData<Entity>;
179
199
  __loadedProperties: Set<string>;
180
200
  __identifier?: EntityIdentifier | EntityIdentifier[];
@@ -194,16 +214,10 @@ export interface IWrappedEntityInternal<Entity extends object> extends IWrappedE
194
214
  };
195
215
  }
196
216
  export type AnyEntity<T = any> = Partial<T>;
197
- export type EntityClass<T> = Function & {
217
+ export type EntityClass<T = any> = Function & {
198
218
  prototype: T;
199
219
  };
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
- };
220
+ export type EntityName<T = any> = EntityClass<T> | EntityCtor<T> | EntitySchema<T, any>;
207
221
  export type GetRepository<Entity extends {
208
222
  [k: PropertyKey]: any;
209
223
  }, Fallback> = Entity[typeof EntityRepositoryType] extends EntityRepository<any> | undefined ? NonNullable<Entity[typeof EntityRepositoryType]> : Fallback;
@@ -217,14 +231,17 @@ type ExpandRequiredEntityPropObject<T, I = never, C extends boolean = false> = {
217
231
  } & {
218
232
  [K in keyof T as OptionalKeys<T, K, I>]?: RequiredEntityDataProp<ExpandProperty<T[K]>, T, C> | EntityDataPropValue<ExpandProperty<T[K]>> | null | undefined;
219
233
  };
234
+ type NonArrayObject = object & {
235
+ [Symbol.iterator]?: never;
236
+ };
220
237
  export type EntityDataProp<T, C extends boolean> = T extends Date ? string | Date : T extends Scalar ? T : T extends {
221
238
  __runtime?: infer Runtime;
222
239
  __raw?: infer Raw;
223
- } ? (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 | U[] | EntityDataNested<U, C> | EntityDataNested<U, C>[] : EntityDataNested<T, C>;
224
- export type RequiredEntityDataProp<T, O, C extends boolean> = T extends Date ? string | Date : T extends Scalar ? T : T extends {
240
+ } ? (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>;
241
+ 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 {
225
242
  __runtime?: infer Runtime;
226
243
  __raw?: infer Raw;
227
- } ? (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 | U[] | RequiredEntityDataNested<U, O, C> | RequiredEntityDataNested<U, O, C>[] : RequiredEntityDataNested<T, O, C>;
244
+ } ? (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>;
228
245
  export type EntityDataNested<T, C extends boolean = false> = T extends undefined ? never : T extends any[] ? Readonly<T> : EntityData<T, C> | ExpandEntityProp<T, C>;
229
246
  type EntityDataItem<T, C extends boolean> = C extends false ? T | EntityDataProp<T, C> | null : EntityDataProp<T, C> | null;
230
247
  export type RequiredEntityDataNested<T, O, C extends boolean> = T extends any[] ? Readonly<T> : RequiredEntityData<T, O> | ExpandRequiredEntityProp<T, O, C>;
@@ -236,7 +253,10 @@ type ExplicitlyOptionalProps<T> = (T extends {
236
253
  type NullableKeys<T, V = null> = {
237
254
  [K in keyof T]: V extends T[K] ? K : never;
238
255
  }[keyof T];
239
- type ProbablyOptionalProps<T> = PrimaryProperty<T> | ExplicitlyOptionalProps<T> | NonNullable<NullableKeys<T, null | undefined>>;
256
+ type RequiredNullableKeys<T> = {
257
+ [K in keyof T]: Exclude<T[K], null> extends RequiredNullable.Brand ? K : never;
258
+ }[keyof T];
259
+ type ProbablyOptionalProps<T> = PrimaryProperty<T> | ExplicitlyOptionalProps<T> | Exclude<NonNullable<NullableKeys<T, null | undefined>>, RequiredNullableKeys<T>>;
240
260
  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;
241
261
  type RequiredKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? CleanKeys<T, K> : never;
242
262
  type OptionalKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? never : CleanKeys<T, K>;
@@ -294,8 +314,14 @@ export type EntityDTO<T, C extends TypeConfig = never> = {
294
314
  [K in keyof T as DTOOptionalKeys<T, K>]?: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
295
315
  };
296
316
  type TargetKeys<T> = T extends EntityClass<infer P> ? keyof P : keyof T;
297
- type CheckKey<T> = IsUnknown<T> extends false ? TargetKeys<T> : string;
298
- export type CheckCallback<T> = (columns: Record<CheckKey<T>, string>) => string;
317
+ type PropertyName<T> = IsUnknown<T> extends false ? TargetKeys<T> : string;
318
+ type TableName = {
319
+ name: string;
320
+ schema?: string;
321
+ toString: () => string;
322
+ };
323
+ export type IndexCallback<T> = (table: TableName, columns: Record<PropertyName<T>, string>, indexName: string) => string | Raw;
324
+ export type CheckCallback<T> = (columns: Record<PropertyName<T>, string>) => string;
299
325
  export type GeneratedColumnCallback<T> = (columns: Record<keyof T, string>) => string;
300
326
  export interface CheckConstraint<T = any> {
301
327
  name?: string;
@@ -306,6 +332,7 @@ export type AnyString = string & {};
306
332
  export interface EntityProperty<Owner = any, Target = any> {
307
333
  name: EntityKey<Owner>;
308
334
  entity: () => EntityName<Owner>;
335
+ target: EntityClass<Target>;
309
336
  type: keyof typeof types | AnyString;
310
337
  runtimeType: 'number' | 'string' | 'boolean' | 'bigint' | 'Buffer' | 'Date' | 'object' | 'any' | AnyString;
311
338
  targetMeta?: EntityMetadata<Target>;
@@ -332,6 +359,7 @@ export interface EntityProperty<Owner = any, Target = any> {
332
359
  default?: string | number | boolean | null;
333
360
  defaultRaw?: string;
334
361
  formula?: (alias: string) => string;
362
+ filters?: FilterOptions;
335
363
  prefix?: string | boolean;
336
364
  prefixMode?: EmbeddedPrefixMode;
337
365
  embedded?: [EntityKey<Owner>, EntityKey<Owner>];
@@ -348,7 +376,6 @@ export interface EntityProperty<Owner = any, Target = any> {
348
376
  mapToPk?: boolean;
349
377
  persist?: boolean;
350
378
  hydrate?: boolean;
351
- trackChanges?: boolean;
352
379
  hidden?: boolean;
353
380
  enum?: boolean;
354
381
  items?: (number | string)[];
@@ -359,6 +386,7 @@ export interface EntityProperty<Owner = any, Target = any> {
359
386
  setter?: boolean;
360
387
  getter?: boolean;
361
388
  getterName?: keyof Owner;
389
+ accessor?: EntityKey<Owner>;
362
390
  cascade: Cascade[];
363
391
  orphanRemoval?: boolean;
364
392
  onCreate?: (entity: Owner, em: EntityManager) => any;
@@ -375,7 +403,7 @@ export interface EntityProperty<Owner = any, Target = any> {
375
403
  fixedOrder?: boolean;
376
404
  fixedOrderColumn?: string;
377
405
  pivotTable: string;
378
- pivotEntity: string;
406
+ pivotEntity: EntityClass<Target>;
379
407
  joinColumns: string[];
380
408
  ownColumns: string[];
381
409
  inverseJoinColumns: string[];
@@ -391,18 +419,22 @@ export interface EntityProperty<Owner = any, Target = any> {
391
419
  optional?: boolean;
392
420
  ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
393
421
  deferMode?: DeferMode;
422
+ createForeignKeyConstraint: boolean;
423
+ foreignKeyName?: string;
394
424
  }
395
- export declare class EntityMetadata<T = any> {
425
+ export declare class EntityMetadata<Entity = any, Class extends EntityCtor<Entity> = EntityCtor<Entity>> {
396
426
  private static counter;
397
427
  readonly _id: number;
398
428
  readonly propertyOrder: Map<string, number>;
399
429
  constructor(meta?: Partial<EntityMetadata>);
400
- addProperty(prop: Partial<EntityProperty<T>>, sync?: boolean): void;
430
+ addProperty(prop: Partial<EntityProperty<Entity>>): void;
401
431
  removeProperty(name: string, sync?: boolean): void;
402
- getPrimaryProps(): EntityProperty<T>[];
403
- getPrimaryProp(): EntityProperty<T>;
432
+ getPrimaryProps(flatten?: boolean): EntityProperty<Entity>[];
433
+ getPrimaryProp(): EntityProperty<Entity>;
434
+ createColumnMappingObject(): Dictionary<any>;
404
435
  get tableName(): string;
405
436
  set tableName(name: string);
437
+ get uniqueName(): string;
406
438
  sync(initIndexes?: boolean, config?: Configuration): void;
407
439
  private initIndexes;
408
440
  /** @internal */
@@ -412,67 +444,68 @@ export interface SimpleColumnMeta {
412
444
  name: string;
413
445
  type: string;
414
446
  }
415
- export interface EntityMetadata<T = any> {
447
+ export type EntityCtor<T = any> = abstract new (...args: any[]) => T;
448
+ export interface EntityMetadata<Entity = any, Class extends EntityCtor<Entity> = EntityCtor<Entity>> {
416
449
  name?: string;
417
450
  className: string;
418
451
  tableName: string;
419
452
  schema?: string;
420
453
  pivotTable?: boolean;
421
454
  virtual?: boolean;
422
- expression?: string | ((em: any, where: ObjectQuery<T>, options: FindOptions<T, any, any, any>) => MaybePromise<RawQueryFragment | object | string>);
423
- discriminatorColumn?: EntityKey<T> | AnyString;
455
+ expression?: string | ((em: any, where: ObjectQuery<Entity>, options: FindOptions<Entity, any, any, any>, stream?: boolean) => MaybePromise<Raw | object | string>);
456
+ discriminatorColumn?: EntityKey<Entity> | AnyString;
424
457
  discriminatorValue?: number | string;
425
- discriminatorMap?: Dictionary<string>;
458
+ discriminatorMap?: Dictionary<EntityClass>;
426
459
  embeddable: boolean;
427
- constructorParams: EntityKey<T>[];
460
+ constructorParams?: (keyof Entity)[];
428
461
  forceConstructor: boolean;
429
- toJsonParams: string[];
430
- extends: string;
462
+ extends?: EntityName<Entity>;
431
463
  collection: string;
432
464
  path: string;
433
- primaryKeys: EntityKey<T>[];
465
+ primaryKeys: EntityKey<Entity>[];
434
466
  simplePK: boolean;
435
467
  compositePK: boolean;
436
- versionProperty: EntityKey<T>;
437
- concurrencyCheckKeys: Set<EntityKey<T>>;
438
- serializedPrimaryKey: EntityKey<T>;
468
+ versionProperty: EntityKey<Entity>;
469
+ concurrencyCheckKeys: Set<EntityKey<Entity>>;
470
+ serializedPrimaryKey?: EntityKey<Entity>;
439
471
  properties: {
440
- [K in EntityKey<T>]: EntityProperty<T>;
472
+ [K in EntityKey<Entity>]: EntityProperty<Entity>;
441
473
  };
442
- props: EntityProperty<T>[];
443
- relations: EntityProperty<T>[];
444
- bidirectionalRelations: EntityProperty<T>[];
474
+ props: EntityProperty<Entity>[];
475
+ relations: EntityProperty<Entity>[];
476
+ bidirectionalRelations: EntityProperty<Entity>[];
445
477
  referencingProperties: {
446
- meta: EntityMetadata<T>;
447
- prop: EntityProperty<T>;
478
+ meta: EntityMetadata<Entity>;
479
+ prop: EntityProperty<Entity>;
448
480
  }[];
449
- comparableProps: EntityProperty<T>[];
450
- trackingProps: EntityProperty<T>[];
451
- hydrateProps: EntityProperty<T>[];
452
- uniqueProps: EntityProperty<T>[];
453
- getterProps: EntityProperty<T>[];
481
+ comparableProps: EntityProperty<Entity>[];
482
+ trackingProps: EntityProperty<Entity>[];
483
+ hydrateProps: EntityProperty<Entity>[];
484
+ validateProps: EntityProperty<Entity>[];
485
+ uniqueProps: EntityProperty<Entity>[];
486
+ getterProps: EntityProperty<Entity>[];
454
487
  indexes: {
455
- properties: EntityKey<T> | EntityKey<T>[];
488
+ properties?: EntityKey<Entity> | EntityKey<Entity>[];
456
489
  name?: string;
457
490
  type?: string;
458
491
  options?: Dictionary;
459
- expression?: string;
492
+ expression?: string | IndexCallback<Entity>;
460
493
  }[];
461
494
  uniques: {
462
- properties: EntityKey<T> | EntityKey<T>[];
495
+ properties?: EntityKey<Entity> | EntityKey<Entity>[];
463
496
  name?: string;
464
497
  options?: Dictionary;
465
- expression?: string;
466
- deferMode?: DeferMode;
498
+ expression?: string | IndexCallback<Entity>;
499
+ deferMode?: DeferMode | `${DeferMode}`;
467
500
  }[];
468
- checks: CheckConstraint<T>[];
501
+ checks: CheckConstraint<Entity>[];
469
502
  repositoryClass?: string;
470
503
  repository: () => EntityClass<EntityRepository<any>>;
471
504
  hooks: {
472
- [K in EventType]?: (keyof T | EventSubscriber<T>[EventType])[];
505
+ [K in EventType]?: (keyof Entity | EventSubscriber<Entity>[EventType])[];
473
506
  };
474
- prototype: T;
475
- class: EntityClass<T>;
507
+ prototype: Entity;
508
+ class: Class;
476
509
  abstract: boolean;
477
510
  filters: Dictionary<FilterDef>;
478
511
  comment?: string;
@@ -480,8 +513,9 @@ export interface EntityMetadata<T = any> {
480
513
  hasUniqueProps?: boolean;
481
514
  readonly?: boolean;
482
515
  polymorphs?: EntityMetadata[];
483
- root: EntityMetadata<T>;
516
+ root: EntityMetadata<Entity>;
484
517
  definedProperties: Dictionary;
518
+ hasTriggers?: boolean;
485
519
  /** @internal can be used for computed numeric cache keys */
486
520
  readonly _id: number;
487
521
  }
@@ -492,6 +526,7 @@ export interface CreateSchemaOptions {
492
526
  export interface ClearDatabaseOptions {
493
527
  schema?: string;
494
528
  truncate?: boolean;
529
+ clearIdentityMap?: boolean;
495
530
  }
496
531
  export interface EnsureDatabaseOptions extends CreateSchemaOptions, ClearDatabaseOptions {
497
532
  clear?: boolean;
@@ -519,25 +554,25 @@ export interface RefreshDatabaseOptions extends CreateSchemaOptions {
519
554
  createSchema?: boolean;
520
555
  }
521
556
  export interface ISchemaGenerator {
522
- createSchema(options?: CreateSchemaOptions): Promise<void>;
523
- ensureDatabase(options?: EnsureDatabaseOptions): Promise<boolean>;
557
+ create(options?: CreateSchemaOptions): Promise<void>;
558
+ update(options?: UpdateSchemaOptions): Promise<void>;
559
+ drop(options?: DropSchemaOptions): Promise<void>;
560
+ refresh(options?: RefreshDatabaseOptions): Promise<void>;
561
+ clear(options?: ClearDatabaseOptions): Promise<void>;
562
+ execute(sql: string, options?: {
563
+ wrap?: boolean;
564
+ }): Promise<void>;
524
565
  getCreateSchemaSQL(options?: CreateSchemaOptions): Promise<string>;
525
- dropSchema(options?: DropSchemaOptions): Promise<void>;
526
566
  getDropSchemaSQL(options?: Omit<DropSchemaOptions, 'dropDb'>): Promise<string>;
527
- updateSchema(options?: UpdateSchemaOptions): Promise<void>;
528
567
  getUpdateSchemaSQL(options?: UpdateSchemaOptions): Promise<string>;
529
568
  getUpdateSchemaMigrationSQL(options?: UpdateSchemaOptions): Promise<{
530
569
  up: string;
531
570
  down: string;
532
571
  }>;
572
+ ensureDatabase(options?: EnsureDatabaseOptions): Promise<boolean>;
533
573
  createDatabase(name?: string): Promise<void>;
534
574
  dropDatabase(name?: string): Promise<void>;
535
- execute(sql: string, options?: {
536
- wrap?: boolean;
537
- }): Promise<void>;
538
575
  ensureIndexes(): Promise<void>;
539
- refreshDatabase(options?: RefreshDatabaseOptions): Promise<void>;
540
- clearDatabase(options?: ClearDatabaseOptions): Promise<void>;
541
576
  }
542
577
  export type ImportsResolver = (alias: string, basePath: string, extension: '.js' | '', originFileName: string) => {
543
578
  path: string;
@@ -554,7 +589,10 @@ export interface GenerateOptions {
554
589
  undefinedDefaults?: boolean;
555
590
  bidirectionalRelations?: boolean;
556
591
  identifiedReferences?: boolean;
557
- entitySchema?: boolean;
592
+ entityDefinition?: 'decorators' | 'defineEntity' | 'entitySchema';
593
+ decorators?: 'es' | 'legacy';
594
+ inferEntityType?: boolean;
595
+ enumMode?: 'ts-enum' | 'union-type' | 'dictionary';
558
596
  esmImport?: boolean;
559
597
  scalarTypeInDecorator?: boolean;
560
598
  scalarPropertiesForRelations?: 'always' | 'never' | 'smart';
@@ -614,26 +652,26 @@ export interface IMigrator {
614
652
  /**
615
653
  * Checks current schema for changes, generates new migration if there are any.
616
654
  */
617
- createMigration(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<MigrationResult>;
655
+ create(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<MigrationResult>;
618
656
  /**
619
657
  * Checks current schema for changes.
620
658
  */
621
- checkMigrationNeeded(): Promise<boolean>;
659
+ checkSchema(): Promise<boolean>;
622
660
  /**
623
661
  * Creates initial migration. This generates the schema based on metadata, and checks whether all the tables
624
662
  * are already present. If yes, it will also automatically log the migration as executed.
625
663
  * Initial migration can be created only if the schema is already aligned with the metadata, or when no schema
626
664
  * is present - in such case regular migration would have the same effect.
627
665
  */
628
- createInitialMigration(path?: string): Promise<MigrationResult>;
666
+ createInitial(path?: string): Promise<MigrationResult>;
629
667
  /**
630
668
  * Returns list of already executed migrations.
631
669
  */
632
- getExecutedMigrations(): Promise<MigrationRow[]>;
670
+ getExecuted(): Promise<MigrationRow[]>;
633
671
  /**
634
672
  * Returns list of pending (not yet executed) migrations found in the migration directory.
635
673
  */
636
- getPendingMigrations(): Promise<UmzugMigration[]>;
674
+ getPending(): Promise<UmzugMigration[]>;
637
675
  /**
638
676
  * Executes specified migrations. Without parameter it will migrate up to the latest version.
639
677
  */
@@ -682,12 +720,17 @@ export interface MigrationObject {
682
720
  name: string;
683
721
  class: Constructor<Migration>;
684
722
  }
685
- export type FilterDef = {
723
+ type EntityFromInput<T> = T extends readonly EntityName<infer U>[] ? U : T extends EntityName<infer U> ? U : never;
724
+ type FilterDefResolved<T extends object = any> = {
686
725
  name: string;
687
- 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>);
726
+ 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>>);
688
727
  default?: boolean;
689
- entity?: string[];
728
+ entity?: EntityName<T> | EntityName<T>[];
690
729
  args?: boolean;
730
+ strict?: boolean;
731
+ };
732
+ export type FilterDef<T extends EntityName | readonly EntityName[] = any> = FilterDefResolved<EntityFromInput<T>> & {
733
+ entity?: T;
691
734
  };
692
735
  export type Populate<T, P extends string = never> = readonly AutoPath<T, P, `${PopulatePath}`>[] | false;
693
736
  export type PopulateOptions<T> = {
@@ -695,6 +738,7 @@ export type PopulateOptions<T> = {
695
738
  strategy?: LoadStrategy;
696
739
  all?: boolean;
697
740
  filter?: boolean;
741
+ joinType?: 'inner join' | 'left join';
698
742
  children?: PopulateOptions<T[keyof T]>[];
699
743
  };
700
744
  type Loadable<T extends object> = Collection<T, any> | Reference<T> | Ref<T> | readonly T[];
@@ -778,23 +822,23 @@ export interface Highlighter {
778
822
  highlight(text: string): string;
779
823
  }
780
824
  export interface IMetadataStorage {
781
- getAll(): Dictionary<EntityMetadata>;
782
- get<T = any>(entity: string, init?: boolean, validate?: boolean): EntityMetadata<T>;
783
- find<T = any>(entity: string): EntityMetadata<T> | undefined;
784
- has(entity: string): boolean;
785
- set(entity: string, meta: EntityMetadata): EntityMetadata;
786
- reset(entity: string): void;
825
+ getAll(): Map<EntityName, EntityMetadata>;
826
+ get<T = any>(entity: EntityName<T>, init?: boolean, validate?: boolean): EntityMetadata<T>;
827
+ find<T = any>(entity: EntityName<T>): EntityMetadata<T> | undefined;
828
+ has<T>(entity: EntityName<T>): boolean;
829
+ set<T>(entity: EntityName<T>, meta: EntityMetadata): EntityMetadata;
830
+ reset<T>(entity: EntityName<T>): void;
787
831
  }
788
832
  export interface IHydrator {
789
833
  /**
790
834
  * Hydrates the whole entity. This process handles custom type conversions, creating missing Collection instances,
791
835
  * mapping FKs to entity instances, as well as merging those entities.
792
836
  */
793
- 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;
837
+ 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;
794
838
  /**
795
839
  * Hydrates primary keys only
796
840
  */
797
- hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
841
+ hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void;
798
842
  isRunning(): boolean;
799
843
  }
800
844
  export interface HydratorConstructor {
@@ -804,17 +848,18 @@ export interface ISeedManager {
804
848
  seed(...classNames: Constructor<Seeder>[]): Promise<void>;
805
849
  /** @internal */
806
850
  seedString(...classNames: string[]): Promise<void>;
807
- createSeeder(className: string): Promise<string>;
851
+ create(className: string): Promise<string>;
808
852
  }
809
853
  export interface Seeder<T extends Dictionary = Dictionary> {
810
854
  run(em: EntityManager, context?: T): void | Promise<void>;
811
855
  }
812
856
  export type ConnectionType = 'read' | 'write';
813
857
  export type MetadataProcessor = (metadata: EntityMetadata[], platform: Platform) => MaybePromise<void>;
814
- /**
815
- * The type of context that the user intends to inject.
816
- */
817
- export type ContextProvider<T> = MaybePromise<MikroORM> | ((type: T) => MaybePromise<MikroORM | EntityManager | EntityRepository<any> | {
818
- getEntityManager(): EntityManager;
819
- }>);
858
+ export type MaybeReturnType<T> = T extends (...args: any[]) => infer R ? R : T;
859
+ 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> {
860
+ readonly name: TName;
861
+ readonly properties: TProperties;
862
+ readonly tableName: TTableName;
863
+ }
864
+ export type InferEntity<Schema> = Schema extends EntitySchemaWithMeta<any, any, infer Entity, any, any> ? Entity : Schema extends EntitySchema<infer Entity> ? Entity : Schema extends EntityClass<infer Entity> ? Entity : Schema;
820
865
  export {};