@mikro-orm/core 7.0.0-dev.9 → 7.0.0-dev.90

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 (191) hide show
  1. package/EntityManager.d.ts +77 -48
  2. package/EntityManager.js +288 -225
  3. package/MikroORM.d.ts +40 -31
  4. package/MikroORM.js +98 -137
  5. package/README.md +3 -2
  6. package/cache/FileCacheAdapter.d.ts +1 -1
  7. package/cache/FileCacheAdapter.js +6 -5
  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 +11 -7
  13. package/connections/Connection.js +16 -14
  14. package/drivers/DatabaseDriver.d.ts +11 -5
  15. package/drivers/DatabaseDriver.js +23 -11
  16. package/drivers/IDatabaseDriver.d.ts +25 -4
  17. package/entity/BaseEntity.d.ts +0 -1
  18. package/entity/BaseEntity.js +0 -3
  19. package/entity/Collection.d.ts +95 -30
  20. package/entity/Collection.js +432 -93
  21. package/entity/EntityAssigner.d.ts +1 -1
  22. package/entity/EntityAssigner.js +17 -9
  23. package/entity/EntityFactory.d.ts +7 -0
  24. package/entity/EntityFactory.js +63 -41
  25. package/entity/EntityHelper.js +26 -12
  26. package/entity/EntityLoader.d.ts +5 -4
  27. package/entity/EntityLoader.js +63 -38
  28. package/entity/EntityRepository.d.ts +1 -1
  29. package/entity/Reference.d.ts +6 -5
  30. package/entity/Reference.js +34 -9
  31. package/entity/WrappedEntity.d.ts +2 -7
  32. package/entity/WrappedEntity.js +2 -7
  33. package/entity/defineEntity.d.ts +568 -0
  34. package/entity/defineEntity.js +529 -0
  35. package/entity/index.d.ts +3 -2
  36. package/entity/index.js +3 -2
  37. package/entity/utils.d.ts +7 -0
  38. package/entity/utils.js +16 -4
  39. package/entity/validators.d.ts +11 -0
  40. package/entity/validators.js +65 -0
  41. package/enums.d.ts +21 -6
  42. package/enums.js +14 -1
  43. package/errors.d.ts +10 -2
  44. package/errors.js +29 -10
  45. package/events/EventManager.d.ts +2 -1
  46. package/events/EventManager.js +19 -11
  47. package/events/EventSubscriber.d.ts +3 -1
  48. package/hydration/Hydrator.js +1 -2
  49. package/hydration/ObjectHydrator.d.ts +4 -4
  50. package/hydration/ObjectHydrator.js +35 -25
  51. package/index.d.ts +2 -2
  52. package/index.js +1 -2
  53. package/logging/DefaultLogger.d.ts +1 -1
  54. package/logging/DefaultLogger.js +1 -0
  55. package/logging/SimpleLogger.d.ts +1 -1
  56. package/logging/index.d.ts +1 -0
  57. package/logging/index.js +1 -0
  58. package/logging/inspect.d.ts +2 -0
  59. package/logging/inspect.js +16 -0
  60. package/metadata/EntitySchema.d.ts +9 -13
  61. package/metadata/EntitySchema.js +44 -26
  62. package/metadata/MetadataDiscovery.d.ts +6 -9
  63. package/metadata/MetadataDiscovery.js +165 -205
  64. package/metadata/MetadataProvider.d.ts +11 -2
  65. package/metadata/MetadataProvider.js +44 -2
  66. package/metadata/MetadataStorage.d.ts +1 -6
  67. package/metadata/MetadataStorage.js +6 -18
  68. package/metadata/MetadataValidator.d.ts +0 -7
  69. package/metadata/MetadataValidator.js +0 -10
  70. package/metadata/discover-entities.d.ts +5 -0
  71. package/metadata/discover-entities.js +40 -0
  72. package/metadata/index.d.ts +1 -1
  73. package/metadata/index.js +1 -1
  74. package/metadata/types.d.ts +480 -0
  75. package/metadata/types.js +1 -0
  76. package/naming-strategy/AbstractNamingStrategy.d.ts +5 -1
  77. package/naming-strategy/AbstractNamingStrategy.js +8 -2
  78. package/naming-strategy/NamingStrategy.d.ts +11 -1
  79. package/not-supported.d.ts +2 -0
  80. package/not-supported.js +4 -0
  81. package/package.json +18 -10
  82. package/platforms/ExceptionConverter.js +1 -1
  83. package/platforms/Platform.d.ts +6 -13
  84. package/platforms/Platform.js +15 -41
  85. package/serialization/EntitySerializer.d.ts +2 -0
  86. package/serialization/EntitySerializer.js +32 -14
  87. package/serialization/EntityTransformer.js +22 -12
  88. package/serialization/SerializationContext.js +16 -13
  89. package/types/ArrayType.d.ts +1 -1
  90. package/types/ArrayType.js +2 -3
  91. package/types/BigIntType.d.ts +8 -6
  92. package/types/BigIntType.js +1 -1
  93. package/types/BlobType.d.ts +0 -1
  94. package/types/BlobType.js +0 -3
  95. package/types/BooleanType.d.ts +2 -1
  96. package/types/BooleanType.js +3 -0
  97. package/types/DecimalType.d.ts +6 -4
  98. package/types/DecimalType.js +3 -3
  99. package/types/DoubleType.js +2 -2
  100. package/types/EnumArrayType.js +1 -2
  101. package/types/JsonType.d.ts +1 -1
  102. package/types/JsonType.js +7 -2
  103. package/types/TinyIntType.js +1 -1
  104. package/types/Type.d.ts +2 -4
  105. package/types/Type.js +3 -3
  106. package/types/Uint8ArrayType.d.ts +0 -1
  107. package/types/Uint8ArrayType.js +1 -4
  108. package/types/index.d.ts +1 -1
  109. package/typings.d.ts +109 -73
  110. package/typings.js +38 -35
  111. package/unit-of-work/ChangeSet.d.ts +0 -3
  112. package/unit-of-work/ChangeSet.js +2 -2
  113. package/unit-of-work/ChangeSetComputer.d.ts +1 -3
  114. package/unit-of-work/ChangeSetComputer.js +11 -9
  115. package/unit-of-work/ChangeSetPersister.d.ts +5 -4
  116. package/unit-of-work/ChangeSetPersister.js +51 -19
  117. package/unit-of-work/UnitOfWork.d.ts +8 -1
  118. package/unit-of-work/UnitOfWork.js +91 -49
  119. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  120. package/utils/AbstractSchemaGenerator.js +11 -9
  121. package/utils/Configuration.d.ts +757 -206
  122. package/utils/Configuration.js +140 -188
  123. package/utils/ConfigurationLoader.d.ts +1 -54
  124. package/utils/ConfigurationLoader.js +1 -352
  125. package/utils/Cursor.d.ts +0 -3
  126. package/utils/Cursor.js +6 -3
  127. package/utils/DataloaderUtils.d.ts +15 -5
  128. package/utils/DataloaderUtils.js +54 -8
  129. package/utils/EntityComparator.d.ts +8 -4
  130. package/utils/EntityComparator.js +52 -17
  131. package/utils/QueryHelper.d.ts +9 -1
  132. package/utils/QueryHelper.js +70 -9
  133. package/utils/RawQueryFragment.d.ts +36 -13
  134. package/utils/RawQueryFragment.js +36 -16
  135. package/utils/TransactionManager.d.ts +65 -0
  136. package/utils/TransactionManager.js +223 -0
  137. package/utils/Utils.d.ts +8 -97
  138. package/utils/Utils.js +82 -302
  139. package/utils/clone.js +2 -3
  140. package/utils/env-vars.d.ts +3 -0
  141. package/utils/env-vars.js +87 -0
  142. package/utils/fs-utils.d.ts +12 -0
  143. package/utils/fs-utils.js +97 -0
  144. package/utils/index.d.ts +2 -1
  145. package/utils/index.js +2 -1
  146. package/utils/upsert-utils.d.ts +7 -2
  147. package/utils/upsert-utils.js +55 -4
  148. package/decorators/Check.d.ts +0 -3
  149. package/decorators/Check.js +0 -13
  150. package/decorators/CreateRequestContext.d.ts +0 -3
  151. package/decorators/CreateRequestContext.js +0 -32
  152. package/decorators/Embeddable.d.ts +0 -8
  153. package/decorators/Embeddable.js +0 -11
  154. package/decorators/Embedded.d.ts +0 -18
  155. package/decorators/Embedded.js +0 -18
  156. package/decorators/Entity.d.ts +0 -18
  157. package/decorators/Entity.js +0 -12
  158. package/decorators/Enum.d.ts +0 -9
  159. package/decorators/Enum.js +0 -16
  160. package/decorators/Filter.d.ts +0 -2
  161. package/decorators/Filter.js +0 -8
  162. package/decorators/Formula.d.ts +0 -4
  163. package/decorators/Formula.js +0 -15
  164. package/decorators/Indexed.d.ts +0 -19
  165. package/decorators/Indexed.js +0 -20
  166. package/decorators/ManyToMany.d.ts +0 -40
  167. package/decorators/ManyToMany.js +0 -14
  168. package/decorators/ManyToOne.d.ts +0 -30
  169. package/decorators/ManyToOne.js +0 -14
  170. package/decorators/OneToMany.d.ts +0 -28
  171. package/decorators/OneToMany.js +0 -17
  172. package/decorators/OneToOne.d.ts +0 -24
  173. package/decorators/OneToOne.js +0 -7
  174. package/decorators/PrimaryKey.d.ts +0 -8
  175. package/decorators/PrimaryKey.js +0 -20
  176. package/decorators/Property.d.ts +0 -250
  177. package/decorators/Property.js +0 -32
  178. package/decorators/Transactional.d.ts +0 -13
  179. package/decorators/Transactional.js +0 -28
  180. package/decorators/hooks.d.ts +0 -16
  181. package/decorators/hooks.js +0 -47
  182. package/decorators/index.d.ts +0 -17
  183. package/decorators/index.js +0 -17
  184. package/entity/ArrayCollection.d.ts +0 -116
  185. package/entity/ArrayCollection.js +0 -402
  186. package/entity/EntityValidator.d.ts +0 -19
  187. package/entity/EntityValidator.js +0 -150
  188. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  189. package/metadata/ReflectMetadataProvider.js +0 -44
  190. package/utils/resolveContextProvider.d.ts +0 -10
  191. package/utils/resolveContextProvider.js +0 -28
@@ -5,7 +5,7 @@ export declare class JsonType extends Type<unknown, string | null> {
5
5
  convertToDatabaseValue(value: unknown, platform: Platform, context?: TransformContext): string | null;
6
6
  convertToJSValueSQL(key: string, platform: Platform): string;
7
7
  convertToDatabaseValueSQL(key: string, platform: Platform): string;
8
- convertToJSValue(value: string | unknown, platform: Platform): unknown;
8
+ convertToJSValue(value: string | unknown, platform: Platform, context?: TransformContext): unknown;
9
9
  getColumnType(prop: EntityProperty, platform: Platform): string;
10
10
  ensureComparable<T extends object>(meta: EntityMetadata<T>, prop: EntityProperty<T>): boolean;
11
11
  compareAsType(): string;
package/types/JsonType.js CHANGED
@@ -12,8 +12,13 @@ export class JsonType extends Type {
12
12
  convertToDatabaseValueSQL(key, platform) {
13
13
  return key + platform.castColumn(this.prop);
14
14
  }
15
- convertToJSValue(value, platform) {
16
- return platform.convertJsonToJSValue(value, this.prop);
15
+ convertToJSValue(value, platform, context) {
16
+ const isJsonColumn = ['json', 'jsonb', platform.getJsonDeclarationSQL()].includes(this.prop.columnTypes[0]);
17
+ const isObjectEmbedded = this.prop.embedded && this.prop.object;
18
+ if ((platform.convertsJsonAutomatically() || isObjectEmbedded) && isJsonColumn && !context?.force) {
19
+ return value;
20
+ }
21
+ return platform.convertJsonToJSValue(value, context);
17
22
  }
18
23
  getColumnType(prop, platform) {
19
24
  return platform.getJsonDeclarationSQL();
@@ -6,7 +6,7 @@ export class TinyIntType extends Type {
6
6
  compareAsType() {
7
7
  return 'number';
8
8
  }
9
- /* v8 ignore next 3 */
9
+ /* v8 ignore next */
10
10
  ensureComparable() {
11
11
  return false;
12
12
  }
package/types/Type.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { inspect } from 'node:util';
2
1
  import type { Platform } from '../platforms/Platform.js';
3
2
  import type { Constructor, EntityMetadata, EntityProperty } from '../typings.js';
4
3
  export interface TransformContext {
5
4
  fromQuery?: boolean;
5
+ force?: boolean;
6
6
  key?: string;
7
7
  mode?: 'hydration' | 'query' | 'query-data' | 'discovery' | 'serialization';
8
8
  }
@@ -23,7 +23,7 @@ export declare abstract class Type<JSType = string, DBType = JSType> {
23
23
  /**
24
24
  * Converts a value from its database representation to its JS representation of this type.
25
25
  */
26
- convertToJSValue(value: DBType, platform: Platform): JSType;
26
+ convertToJSValue(value: DBType, platform: Platform, context?: TransformContext): JSType;
27
27
  /**
28
28
  * Converts a value from its JS representation to its database representation of this type.
29
29
  */
@@ -78,6 +78,4 @@ export declare abstract class Type<JSType = string, DBType = JSType> {
78
78
  * Checks whether the argument is instance of `Type`.
79
79
  */
80
80
  static isMappedType(data: any): data is Type<any>;
81
- /** @ignore */
82
- [inspect.custom](depth?: number): string;
83
81
  }
package/types/Type.js CHANGED
@@ -1,4 +1,4 @@
1
- import { inspect } from 'node:util';
1
+ import { inspect } from '../logging/inspect.js';
2
2
  export class Type {
3
3
  static types = new Map();
4
4
  platform;
@@ -13,7 +13,7 @@ export class Type {
13
13
  /**
14
14
  * Converts a value from its database representation to its JS representation of this type.
15
15
  */
16
- convertToJSValue(value, platform) {
16
+ convertToJSValue(value, platform, context) {
17
17
  return value;
18
18
  }
19
19
  /**
@@ -65,7 +65,7 @@ export class Type {
65
65
  return !!data?.__mappedType;
66
66
  }
67
67
  /** @ignore */
68
- [inspect.custom](depth = 2) {
68
+ [Symbol.for('nodejs.util.inspect.custom')](depth = 2) {
69
69
  const object = { ...this };
70
70
  const hidden = ['prop', 'platform', 'meta'];
71
71
  hidden.forEach(k => delete object[k]);
@@ -5,6 +5,5 @@ export declare class Uint8ArrayType extends Type<Uint8Array | null> {
5
5
  convertToDatabaseValue(value: Uint8Array): Buffer;
6
6
  convertToJSValue(value: Buffer): Uint8Array | null;
7
7
  compareAsType(): string;
8
- ensureComparable(): boolean;
9
8
  getColumnType(prop: EntityProperty, platform: Platform): string;
10
9
  }
@@ -7,7 +7,7 @@ export class Uint8ArrayType extends Type {
7
7
  return Buffer.from(value);
8
8
  }
9
9
  convertToJSValue(value) {
10
- /* v8 ignore next 3 */
10
+ /* v8 ignore next */
11
11
  if (!value) {
12
12
  return value;
13
13
  }
@@ -22,9 +22,6 @@ export class Uint8ArrayType extends Type {
22
22
  compareAsType() {
23
23
  return 'Buffer';
24
24
  }
25
- ensureComparable() {
26
- return false;
27
- }
28
25
  getColumnType(prop, platform) {
29
26
  return platform.getBlobDeclarationSQL();
30
27
  }
package/types/index.d.ts CHANGED
@@ -19,7 +19,7 @@ import { StringType } from './StringType.js';
19
19
  import { TextType } from './TextType.js';
20
20
  import { TimeType } from './TimeType.js';
21
21
  import { TinyIntType } from './TinyIntType.js';
22
- import { IType, TransformContext, Type } from './Type.js';
22
+ import { type IType, type TransformContext, Type } from './Type.js';
23
23
  import { Uint8ArrayType } from './Uint8ArrayType.js';
24
24
  import { UnknownType } from './UnknownType.js';
25
25
  import { UuidType } from './UuidType.js';
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';
@@ -17,9 +16,8 @@ import type { Platform } from './platforms/Platform.js';
17
16
  import type { Configuration } from './utils/Configuration.js';
18
17
  import type { RawQueryFragment } 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
  };
@@ -133,7 +148,6 @@ export type FilterValue<T> = OperatorMap<FilterItemValue<T>> | FilterItemValue<T
133
148
  export type FilterObject<T> = {
134
149
  -readonly [K in EntityKey<T>]?: ExpandQuery<ExpandProperty<T[K]>> | FilterValue<ExpandProperty<T[K]>> | null;
135
150
  };
136
- export type ExpandObject<T> = T extends object ? T extends Scalar ? never : FilterObject<T> : never;
137
151
  export type ExpandQuery<T> = T extends object ? T extends Scalar ? never : FilterQuery<T> : FilterValue<T>;
138
152
  export type EntityProps<T> = {
139
153
  -readonly [K in EntityKey<T>]?: T[K];
@@ -143,7 +157,6 @@ export type FilterQuery<T> = ObjectQuery<T> | NonNullable<ExpandScalar<Primary<T
143
157
  export type QBFilterQuery<T = any> = ObjectQuery<T> | Dictionary;
144
158
  export interface IWrappedEntity<Entity extends object> {
145
159
  isInitialized(): boolean;
146
- isTouched(): boolean;
147
160
  isManaged(): boolean;
148
161
  populated(populated?: boolean): void;
149
162
  populate<Hint extends string = never>(populate: AutoPath<Entity, Hint>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
@@ -174,7 +187,6 @@ export interface IWrappedEntityInternal<Entity extends object> extends IWrappedE
174
187
  __factory: EntityFactory;
175
188
  __hydrator: IHydrator;
176
189
  __initialized: boolean;
177
- __touched: boolean;
178
190
  __originalEntityData?: EntityData<Entity>;
179
191
  __loadedProperties: Set<string>;
180
192
  __identifier?: EntityIdentifier | EntityIdentifier[];
@@ -197,10 +209,6 @@ export type AnyEntity<T = any> = Partial<T>;
197
209
  export type EntityClass<T> = Function & {
198
210
  prototype: T;
199
211
  };
200
- export type EntityClassGroup<T> = {
201
- entity: EntityClass<T>;
202
- schema: EntityMetadata<T> | EntitySchema<T>;
203
- };
204
212
  export type EntityName<T> = string | EntityClass<T> | EntitySchema<T, any> | {
205
213
  name: string;
206
214
  };
@@ -217,14 +225,17 @@ type ExpandRequiredEntityPropObject<T, I = never, C extends boolean = false> = {
217
225
  } & {
218
226
  [K in keyof T as OptionalKeys<T, K, I>]?: RequiredEntityDataProp<ExpandProperty<T[K]>, T, C> | EntityDataPropValue<ExpandProperty<T[K]>> | null | undefined;
219
227
  };
228
+ type NonArrayObject = object & {
229
+ [Symbol.iterator]?: never;
230
+ };
220
231
  export type EntityDataProp<T, C extends boolean> = T extends Date ? string | Date : T extends Scalar ? T : T extends {
221
232
  __runtime?: infer Runtime;
222
233
  __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 {
234
+ } ? (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>;
235
+ 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
236
  __runtime?: infer Runtime;
226
237
  __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>;
238
+ } ? (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
239
  export type EntityDataNested<T, C extends boolean = false> = T extends undefined ? never : T extends any[] ? Readonly<T> : EntityData<T, C> | ExpandEntityProp<T, C>;
229
240
  type EntityDataItem<T, C extends boolean> = C extends false ? T | EntityDataProp<T, C> | null : EntityDataProp<T, C> | null;
230
241
  export type RequiredEntityDataNested<T, O, C extends boolean> = T extends any[] ? Readonly<T> : RequiredEntityData<T, O> | ExpandRequiredEntityProp<T, O, C>;
@@ -236,7 +247,10 @@ type ExplicitlyOptionalProps<T> = (T extends {
236
247
  type NullableKeys<T, V = null> = {
237
248
  [K in keyof T]: V extends T[K] ? K : never;
238
249
  }[keyof T];
239
- type ProbablyOptionalProps<T> = PrimaryProperty<T> | ExplicitlyOptionalProps<T> | NonNullable<NullableKeys<T, null | undefined>>;
250
+ type RequiredNullableKeys<T> = {
251
+ [K in keyof T]: Exclude<T[K], null> extends RequiredNullable.Brand ? K : never;
252
+ }[keyof T];
253
+ type ProbablyOptionalProps<T> = PrimaryProperty<T> | ExplicitlyOptionalProps<T> | Exclude<NonNullable<NullableKeys<T, null | undefined>>, RequiredNullableKeys<T>>;
240
254
  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
255
  type RequiredKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? CleanKeys<T, K> : never;
242
256
  type OptionalKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? never : CleanKeys<T, K>;
@@ -294,8 +308,14 @@ export type EntityDTO<T, C extends TypeConfig = never> = {
294
308
  [K in keyof T as DTOOptionalKeys<T, K>]?: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
295
309
  };
296
310
  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;
311
+ type PropertyName<T> = IsUnknown<T> extends false ? TargetKeys<T> : string;
312
+ type TableName = {
313
+ name: string;
314
+ schema?: string;
315
+ toString: () => string;
316
+ };
317
+ export type IndexCallback<T> = (table: TableName, columns: Record<PropertyName<T>, string>, indexName: string) => string | RawQueryFragment;
318
+ export type CheckCallback<T> = (columns: Record<PropertyName<T>, string>) => string;
299
319
  export type GeneratedColumnCallback<T> = (columns: Record<keyof T, string>) => string;
300
320
  export interface CheckConstraint<T = any> {
301
321
  name?: string;
@@ -332,6 +352,7 @@ export interface EntityProperty<Owner = any, Target = any> {
332
352
  default?: string | number | boolean | null;
333
353
  defaultRaw?: string;
334
354
  formula?: (alias: string) => string;
355
+ filters?: FilterOptions;
335
356
  prefix?: string | boolean;
336
357
  prefixMode?: EmbeddedPrefixMode;
337
358
  embedded?: [EntityKey<Owner>, EntityKey<Owner>];
@@ -348,7 +369,6 @@ export interface EntityProperty<Owner = any, Target = any> {
348
369
  mapToPk?: boolean;
349
370
  persist?: boolean;
350
371
  hydrate?: boolean;
351
- trackChanges?: boolean;
352
372
  hidden?: boolean;
353
373
  enum?: boolean;
354
374
  items?: (number | string)[];
@@ -359,6 +379,7 @@ export interface EntityProperty<Owner = any, Target = any> {
359
379
  setter?: boolean;
360
380
  getter?: boolean;
361
381
  getterName?: keyof Owner;
382
+ accessor?: EntityKey<Owner>;
362
383
  cascade: Cascade[];
363
384
  orphanRemoval?: boolean;
364
385
  onCreate?: (entity: Owner, em: EntityManager) => any;
@@ -391,6 +412,8 @@ export interface EntityProperty<Owner = any, Target = any> {
391
412
  optional?: boolean;
392
413
  ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
393
414
  deferMode?: DeferMode;
415
+ createForeignKeyConstraint: boolean;
416
+ foreignKeyName?: string;
394
417
  }
395
418
  export declare class EntityMetadata<T = any> {
396
419
  private static counter;
@@ -399,8 +422,9 @@ export declare class EntityMetadata<T = any> {
399
422
  constructor(meta?: Partial<EntityMetadata>);
400
423
  addProperty(prop: Partial<EntityProperty<T>>, sync?: boolean): void;
401
424
  removeProperty(name: string, sync?: boolean): void;
402
- getPrimaryProps(): EntityProperty<T>[];
425
+ getPrimaryProps(flatten?: boolean): EntityProperty<T>[];
403
426
  getPrimaryProp(): EntityProperty<T>;
427
+ createColumnMappingObject(): Dictionary<any>;
404
428
  get tableName(): string;
405
429
  set tableName(name: string);
406
430
  sync(initIndexes?: boolean, config?: Configuration): void;
@@ -419,14 +443,13 @@ export interface EntityMetadata<T = any> {
419
443
  schema?: string;
420
444
  pivotTable?: boolean;
421
445
  virtual?: boolean;
422
- expression?: string | ((em: any, where: ObjectQuery<T>, options: FindOptions<T, any, any, any>) => MaybePromise<RawQueryFragment | object | string>);
446
+ expression?: string | ((em: any, where: ObjectQuery<T>, options: FindOptions<T, any, any, any>, stream?: boolean) => MaybePromise<RawQueryFragment | object | string>);
423
447
  discriminatorColumn?: EntityKey<T> | AnyString;
424
448
  discriminatorValue?: number | string;
425
449
  discriminatorMap?: Dictionary<string>;
426
450
  embeddable: boolean;
427
- constructorParams: EntityKey<T>[];
451
+ constructorParams?: (keyof T)[];
428
452
  forceConstructor: boolean;
429
- toJsonParams: string[];
430
453
  extends: string;
431
454
  collection: string;
432
455
  path: string;
@@ -435,7 +458,7 @@ export interface EntityMetadata<T = any> {
435
458
  compositePK: boolean;
436
459
  versionProperty: EntityKey<T>;
437
460
  concurrencyCheckKeys: Set<EntityKey<T>>;
438
- serializedPrimaryKey: EntityKey<T>;
461
+ serializedPrimaryKey?: EntityKey<T>;
439
462
  properties: {
440
463
  [K in EntityKey<T>]: EntityProperty<T>;
441
464
  };
@@ -449,21 +472,22 @@ export interface EntityMetadata<T = any> {
449
472
  comparableProps: EntityProperty<T>[];
450
473
  trackingProps: EntityProperty<T>[];
451
474
  hydrateProps: EntityProperty<T>[];
475
+ validateProps: EntityProperty<T>[];
452
476
  uniqueProps: EntityProperty<T>[];
453
477
  getterProps: EntityProperty<T>[];
454
478
  indexes: {
455
- properties: EntityKey<T> | EntityKey<T>[];
479
+ properties?: EntityKey<T> | EntityKey<T>[];
456
480
  name?: string;
457
481
  type?: string;
458
482
  options?: Dictionary;
459
- expression?: string;
483
+ expression?: string | IndexCallback<T>;
460
484
  }[];
461
485
  uniques: {
462
- properties: EntityKey<T> | EntityKey<T>[];
486
+ properties?: EntityKey<T> | EntityKey<T>[];
463
487
  name?: string;
464
488
  options?: Dictionary;
465
- expression?: string;
466
- deferMode?: DeferMode;
489
+ expression?: string | IndexCallback<T>;
490
+ deferMode?: DeferMode | `${DeferMode}`;
467
491
  }[];
468
492
  checks: CheckConstraint<T>[];
469
493
  repositoryClass?: string;
@@ -482,6 +506,7 @@ export interface EntityMetadata<T = any> {
482
506
  polymorphs?: EntityMetadata[];
483
507
  root: EntityMetadata<T>;
484
508
  definedProperties: Dictionary;
509
+ hasTriggers?: boolean;
485
510
  /** @internal can be used for computed numeric cache keys */
486
511
  readonly _id: number;
487
512
  }
@@ -492,6 +517,7 @@ export interface CreateSchemaOptions {
492
517
  export interface ClearDatabaseOptions {
493
518
  schema?: string;
494
519
  truncate?: boolean;
520
+ clearIdentityMap?: boolean;
495
521
  }
496
522
  export interface EnsureDatabaseOptions extends CreateSchemaOptions, ClearDatabaseOptions {
497
523
  clear?: boolean;
@@ -519,25 +545,25 @@ export interface RefreshDatabaseOptions extends CreateSchemaOptions {
519
545
  createSchema?: boolean;
520
546
  }
521
547
  export interface ISchemaGenerator {
522
- createSchema(options?: CreateSchemaOptions): Promise<void>;
523
- ensureDatabase(options?: EnsureDatabaseOptions): Promise<boolean>;
548
+ create(options?: CreateSchemaOptions): Promise<void>;
549
+ update(options?: UpdateSchemaOptions): Promise<void>;
550
+ drop(options?: DropSchemaOptions): Promise<void>;
551
+ refresh(options?: RefreshDatabaseOptions): Promise<void>;
552
+ clear(options?: ClearDatabaseOptions): Promise<void>;
553
+ execute(sql: string, options?: {
554
+ wrap?: boolean;
555
+ }): Promise<void>;
524
556
  getCreateSchemaSQL(options?: CreateSchemaOptions): Promise<string>;
525
- dropSchema(options?: DropSchemaOptions): Promise<void>;
526
557
  getDropSchemaSQL(options?: Omit<DropSchemaOptions, 'dropDb'>): Promise<string>;
527
- updateSchema(options?: UpdateSchemaOptions): Promise<void>;
528
558
  getUpdateSchemaSQL(options?: UpdateSchemaOptions): Promise<string>;
529
559
  getUpdateSchemaMigrationSQL(options?: UpdateSchemaOptions): Promise<{
530
560
  up: string;
531
561
  down: string;
532
562
  }>;
563
+ ensureDatabase(options?: EnsureDatabaseOptions): Promise<boolean>;
533
564
  createDatabase(name?: string): Promise<void>;
534
565
  dropDatabase(name?: string): Promise<void>;
535
- execute(sql: string, options?: {
536
- wrap?: boolean;
537
- }): Promise<void>;
538
566
  ensureIndexes(): Promise<void>;
539
- refreshDatabase(options?: RefreshDatabaseOptions): Promise<void>;
540
- clearDatabase(options?: ClearDatabaseOptions): Promise<void>;
541
567
  }
542
568
  export type ImportsResolver = (alias: string, basePath: string, extension: '.js' | '', originFileName: string) => {
543
569
  path: string;
@@ -554,7 +580,10 @@ export interface GenerateOptions {
554
580
  undefinedDefaults?: boolean;
555
581
  bidirectionalRelations?: boolean;
556
582
  identifiedReferences?: boolean;
557
- entitySchema?: boolean;
583
+ entityDefinition?: 'decorators' | 'defineEntity' | 'entitySchema';
584
+ decorators?: 'es' | 'legacy';
585
+ inferEntityType?: boolean;
586
+ enumMode?: 'ts-enum' | 'union-type' | 'dictionary';
558
587
  esmImport?: boolean;
559
588
  scalarTypeInDecorator?: boolean;
560
589
  scalarPropertiesForRelations?: 'always' | 'never' | 'smart';
@@ -614,26 +643,26 @@ export interface IMigrator {
614
643
  /**
615
644
  * Checks current schema for changes, generates new migration if there are any.
616
645
  */
617
- createMigration(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<MigrationResult>;
646
+ create(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<MigrationResult>;
618
647
  /**
619
648
  * Checks current schema for changes.
620
649
  */
621
- checkMigrationNeeded(): Promise<boolean>;
650
+ checkSchema(): Promise<boolean>;
622
651
  /**
623
652
  * Creates initial migration. This generates the schema based on metadata, and checks whether all the tables
624
653
  * are already present. If yes, it will also automatically log the migration as executed.
625
654
  * Initial migration can be created only if the schema is already aligned with the metadata, or when no schema
626
655
  * is present - in such case regular migration would have the same effect.
627
656
  */
628
- createInitialMigration(path?: string): Promise<MigrationResult>;
657
+ createInitial(path?: string): Promise<MigrationResult>;
629
658
  /**
630
659
  * Returns list of already executed migrations.
631
660
  */
632
- getExecutedMigrations(): Promise<MigrationRow[]>;
661
+ getExecuted(): Promise<MigrationRow[]>;
633
662
  /**
634
663
  * Returns list of pending (not yet executed) migrations found in the migration directory.
635
664
  */
636
- getPendingMigrations(): Promise<UmzugMigration[]>;
665
+ getPending(): Promise<UmzugMigration[]>;
637
666
  /**
638
667
  * Executes specified migrations. Without parameter it will migrate up to the latest version.
639
668
  */
@@ -682,12 +711,17 @@ export interface MigrationObject {
682
711
  name: string;
683
712
  class: Constructor<Migration>;
684
713
  }
685
- export type FilterDef = {
714
+ type EntityFromInput<T> = T extends readonly EntityName<infer U>[] ? U : T extends EntityName<infer U> ? U : never;
715
+ type FilterDefResolved<T extends object = any> = {
686
716
  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>);
717
+ cond: FilterQuery<T> | ((args: Dictionary, type: 'read' | 'update' | 'delete', em: any, options?: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any>, entityName?: EntityName<T>) => MaybePromise<FilterQuery<T>>);
688
718
  default?: boolean;
689
- entity?: string[];
719
+ entity?: EntityName<T> | EntityName<T>[];
690
720
  args?: boolean;
721
+ strict?: boolean;
722
+ };
723
+ export type FilterDef<T extends EntityName<any> | readonly EntityName<any>[] = any> = FilterDefResolved<EntityFromInput<T>> & {
724
+ entity?: T;
691
725
  };
692
726
  export type Populate<T, P extends string = never> = readonly AutoPath<T, P, `${PopulatePath}`>[] | false;
693
727
  export type PopulateOptions<T> = {
@@ -695,6 +729,7 @@ export type PopulateOptions<T> = {
695
729
  strategy?: LoadStrategy;
696
730
  all?: boolean;
697
731
  filter?: boolean;
732
+ joinType?: 'inner join' | 'left join';
698
733
  children?: PopulateOptions<T[keyof T]>[];
699
734
  };
700
735
  type Loadable<T extends object> = Collection<T, any> | Reference<T> | Ref<T> | readonly T[];
@@ -790,11 +825,11 @@ export interface IHydrator {
790
825
  * Hydrates the whole entity. This process handles custom type conversions, creating missing Collection instances,
791
826
  * mapping FKs to entity instances, as well as merging those entities.
792
827
  */
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;
828
+ 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
829
  /**
795
830
  * Hydrates primary keys only
796
831
  */
797
- hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
832
+ hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void;
798
833
  isRunning(): boolean;
799
834
  }
800
835
  export interface HydratorConstructor {
@@ -804,17 +839,18 @@ export interface ISeedManager {
804
839
  seed(...classNames: Constructor<Seeder>[]): Promise<void>;
805
840
  /** @internal */
806
841
  seedString(...classNames: string[]): Promise<void>;
807
- createSeeder(className: string): Promise<string>;
842
+ create(className: string): Promise<string>;
808
843
  }
809
844
  export interface Seeder<T extends Dictionary = Dictionary> {
810
845
  run(em: EntityManager, context?: T): void | Promise<void>;
811
846
  }
812
847
  export type ConnectionType = 'read' | 'write';
813
848
  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
- }>);
849
+ export type MaybeReturnType<T> = T extends (...args: any[]) => infer R ? R : T;
850
+ export interface EntitySchemaWithMeta<TName extends string = string, TTableName extends string = string, TEntity = any, TBase = never, TProperties extends Record<string, any> = Record<string, any>> extends EntitySchema<TEntity, TBase> {
851
+ readonly name: TName;
852
+ readonly properties: TProperties;
853
+ readonly tableName: TTableName;
854
+ }
855
+ 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
856
  export {};