@mikro-orm/core 7.0.4 → 7.0.5-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/EntityManager.d.ts +583 -884
  2. package/EntityManager.js +1895 -1922
  3. package/MikroORM.d.ts +74 -103
  4. package/MikroORM.js +179 -178
  5. package/README.md +1 -1
  6. package/cache/CacheAdapter.d.ts +36 -36
  7. package/cache/FileCacheAdapter.d.ts +24 -30
  8. package/cache/FileCacheAdapter.js +78 -80
  9. package/cache/GeneratedCacheAdapter.d.ts +20 -18
  10. package/cache/GeneratedCacheAdapter.js +30 -30
  11. package/cache/MemoryCacheAdapter.d.ts +20 -18
  12. package/cache/MemoryCacheAdapter.js +36 -35
  13. package/cache/NullCacheAdapter.d.ts +16 -16
  14. package/cache/NullCacheAdapter.js +24 -24
  15. package/connections/Connection.d.ts +84 -95
  16. package/connections/Connection.js +168 -165
  17. package/drivers/DatabaseDriver.d.ts +80 -186
  18. package/drivers/DatabaseDriver.js +443 -450
  19. package/drivers/IDatabaseDriver.d.ts +301 -440
  20. package/entity/BaseEntity.d.ts +83 -120
  21. package/entity/BaseEntity.js +43 -43
  22. package/entity/Collection.d.ts +179 -212
  23. package/entity/Collection.js +721 -727
  24. package/entity/EntityAssigner.d.ts +77 -88
  25. package/entity/EntityAssigner.js +230 -231
  26. package/entity/EntityFactory.d.ts +54 -66
  27. package/entity/EntityFactory.js +383 -425
  28. package/entity/EntityHelper.d.ts +22 -34
  29. package/entity/EntityHelper.js +267 -280
  30. package/entity/EntityIdentifier.d.ts +4 -4
  31. package/entity/EntityIdentifier.js +10 -10
  32. package/entity/EntityLoader.d.ts +72 -98
  33. package/entity/EntityLoader.js +723 -753
  34. package/entity/EntityRepository.d.ts +201 -316
  35. package/entity/EntityRepository.js +213 -213
  36. package/entity/PolymorphicRef.d.ts +5 -5
  37. package/entity/PolymorphicRef.js +10 -10
  38. package/entity/Reference.d.ts +82 -126
  39. package/entity/Reference.js +274 -278
  40. package/entity/WrappedEntity.d.ts +72 -115
  41. package/entity/WrappedEntity.js +166 -168
  42. package/entity/defineEntity.d.ts +636 -1315
  43. package/entity/defineEntity.js +518 -527
  44. package/entity/utils.d.ts +3 -13
  45. package/entity/utils.js +73 -71
  46. package/entity/validators.js +43 -43
  47. package/entity/wrap.js +8 -8
  48. package/enums.d.ts +253 -258
  49. package/enums.js +252 -251
  50. package/errors.d.ts +72 -114
  51. package/errors.js +253 -350
  52. package/events/EventManager.d.ts +14 -26
  53. package/events/EventManager.js +77 -79
  54. package/events/EventSubscriber.d.ts +29 -29
  55. package/events/TransactionEventBroadcaster.d.ts +8 -15
  56. package/events/TransactionEventBroadcaster.js +14 -14
  57. package/exceptions.d.ts +40 -23
  58. package/exceptions.js +52 -35
  59. package/hydration/Hydrator.d.ts +17 -42
  60. package/hydration/Hydrator.js +43 -43
  61. package/hydration/ObjectHydrator.d.ts +17 -50
  62. package/hydration/ObjectHydrator.js +416 -481
  63. package/index.d.ts +2 -116
  64. package/index.js +1 -10
  65. package/logging/DefaultLogger.d.ts +32 -34
  66. package/logging/DefaultLogger.js +86 -86
  67. package/logging/Logger.d.ts +41 -41
  68. package/logging/SimpleLogger.d.ts +11 -13
  69. package/logging/SimpleLogger.js +22 -22
  70. package/logging/colors.d.ts +6 -6
  71. package/logging/colors.js +10 -11
  72. package/logging/inspect.js +7 -7
  73. package/metadata/EntitySchema.d.ts +127 -211
  74. package/metadata/EntitySchema.js +398 -397
  75. package/metadata/MetadataDiscovery.d.ts +114 -114
  76. package/metadata/MetadataDiscovery.js +1870 -1951
  77. package/metadata/MetadataProvider.d.ts +21 -24
  78. package/metadata/MetadataProvider.js +84 -82
  79. package/metadata/MetadataStorage.d.ts +32 -38
  80. package/metadata/MetadataStorage.js +118 -118
  81. package/metadata/MetadataValidator.d.ts +39 -39
  82. package/metadata/MetadataValidator.js +338 -381
  83. package/metadata/discover-entities.d.ts +2 -5
  84. package/metadata/discover-entities.js +37 -35
  85. package/metadata/types.d.ts +531 -615
  86. package/naming-strategy/AbstractNamingStrategy.d.ts +39 -54
  87. package/naming-strategy/AbstractNamingStrategy.js +85 -90
  88. package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
  89. package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
  90. package/naming-strategy/MongoNamingStrategy.d.ts +6 -6
  91. package/naming-strategy/MongoNamingStrategy.js +18 -18
  92. package/naming-strategy/NamingStrategy.d.ts +99 -109
  93. package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
  94. package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
  95. package/not-supported.js +4 -7
  96. package/package.json +1 -1
  97. package/platforms/ExceptionConverter.d.ts +1 -1
  98. package/platforms/ExceptionConverter.js +4 -4
  99. package/platforms/Platform.d.ts +301 -310
  100. package/platforms/Platform.js +640 -663
  101. package/serialization/EntitySerializer.d.ts +26 -49
  102. package/serialization/EntitySerializer.js +218 -224
  103. package/serialization/EntityTransformer.d.ts +6 -10
  104. package/serialization/EntityTransformer.js +217 -219
  105. package/serialization/SerializationContext.d.ts +23 -27
  106. package/serialization/SerializationContext.js +105 -105
  107. package/types/ArrayType.d.ts +8 -8
  108. package/types/ArrayType.js +33 -33
  109. package/types/BigIntType.d.ts +10 -17
  110. package/types/BigIntType.js +37 -37
  111. package/types/BlobType.d.ts +3 -3
  112. package/types/BlobType.js +13 -13
  113. package/types/BooleanType.d.ts +4 -4
  114. package/types/BooleanType.js +12 -12
  115. package/types/CharacterType.d.ts +2 -2
  116. package/types/CharacterType.js +6 -6
  117. package/types/DateTimeType.d.ts +5 -5
  118. package/types/DateTimeType.js +15 -15
  119. package/types/DateType.d.ts +5 -5
  120. package/types/DateType.js +15 -15
  121. package/types/DecimalType.d.ts +7 -7
  122. package/types/DecimalType.js +26 -26
  123. package/types/DoubleType.d.ts +3 -3
  124. package/types/DoubleType.js +12 -12
  125. package/types/EnumArrayType.d.ts +5 -5
  126. package/types/EnumArrayType.js +24 -24
  127. package/types/EnumType.d.ts +3 -3
  128. package/types/EnumType.js +11 -11
  129. package/types/FloatType.d.ts +3 -3
  130. package/types/FloatType.js +9 -9
  131. package/types/IntegerType.d.ts +3 -3
  132. package/types/IntegerType.js +9 -9
  133. package/types/IntervalType.d.ts +4 -4
  134. package/types/IntervalType.js +12 -12
  135. package/types/JsonType.d.ts +8 -8
  136. package/types/JsonType.js +32 -32
  137. package/types/MediumIntType.d.ts +1 -1
  138. package/types/MediumIntType.js +3 -3
  139. package/types/SmallIntType.d.ts +3 -3
  140. package/types/SmallIntType.js +9 -9
  141. package/types/StringType.d.ts +4 -4
  142. package/types/StringType.js +12 -12
  143. package/types/TextType.d.ts +3 -3
  144. package/types/TextType.js +9 -9
  145. package/types/TimeType.d.ts +5 -5
  146. package/types/TimeType.js +17 -17
  147. package/types/TinyIntType.d.ts +3 -3
  148. package/types/TinyIntType.js +10 -10
  149. package/types/Type.d.ts +79 -83
  150. package/types/Type.js +82 -82
  151. package/types/Uint8ArrayType.d.ts +4 -4
  152. package/types/Uint8ArrayType.js +21 -21
  153. package/types/UnknownType.d.ts +4 -4
  154. package/types/UnknownType.js +12 -12
  155. package/types/UuidType.d.ts +5 -5
  156. package/types/UuidType.js +19 -19
  157. package/types/index.d.ts +49 -75
  158. package/types/index.js +26 -52
  159. package/typings.d.ts +737 -1250
  160. package/typings.js +231 -244
  161. package/unit-of-work/ChangeSet.d.ts +26 -26
  162. package/unit-of-work/ChangeSet.js +56 -56
  163. package/unit-of-work/ChangeSetComputer.d.ts +12 -12
  164. package/unit-of-work/ChangeSetComputer.js +170 -178
  165. package/unit-of-work/ChangeSetPersister.d.ts +44 -63
  166. package/unit-of-work/ChangeSetPersister.js +421 -442
  167. package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
  168. package/unit-of-work/CommitOrderCalculator.js +88 -89
  169. package/unit-of-work/IdentityMap.d.ts +31 -31
  170. package/unit-of-work/IdentityMap.js +105 -105
  171. package/unit-of-work/UnitOfWork.d.ts +141 -181
  172. package/unit-of-work/UnitOfWork.js +1183 -1200
  173. package/utils/AbstractMigrator.d.ts +91 -111
  174. package/utils/AbstractMigrator.js +275 -275
  175. package/utils/AbstractSchemaGenerator.d.ts +34 -43
  176. package/utils/AbstractSchemaGenerator.js +122 -121
  177. package/utils/AsyncContext.d.ts +3 -3
  178. package/utils/AsyncContext.js +35 -34
  179. package/utils/Configuration.d.ts +808 -852
  180. package/utils/Configuration.js +344 -359
  181. package/utils/Cursor.d.ts +22 -40
  182. package/utils/Cursor.js +127 -135
  183. package/utils/DataloaderUtils.d.ts +43 -58
  184. package/utils/DataloaderUtils.js +198 -203
  185. package/utils/EntityComparator.d.ts +81 -98
  186. package/utils/EntityComparator.js +732 -828
  187. package/utils/NullHighlighter.d.ts +1 -1
  188. package/utils/NullHighlighter.js +3 -3
  189. package/utils/QueryHelper.d.ts +51 -79
  190. package/utils/QueryHelper.js +361 -372
  191. package/utils/RawQueryFragment.d.ts +34 -50
  192. package/utils/RawQueryFragment.js +105 -107
  193. package/utils/RequestContext.d.ts +32 -32
  194. package/utils/RequestContext.js +53 -52
  195. package/utils/TransactionContext.d.ts +16 -16
  196. package/utils/TransactionContext.js +27 -27
  197. package/utils/TransactionManager.d.ts +58 -58
  198. package/utils/TransactionManager.js +197 -199
  199. package/utils/Utils.d.ts +145 -204
  200. package/utils/Utils.js +812 -812
  201. package/utils/clone.js +113 -104
  202. package/utils/env-vars.js +88 -90
  203. package/utils/fs-utils.d.ts +15 -15
  204. package/utils/fs-utils.js +181 -180
  205. package/utils/upsert-utils.d.ts +5 -20
  206. package/utils/upsert-utils.js +116 -114
@@ -1,661 +1,577 @@
1
- import type {
2
- AnyEntity,
3
- Constructor,
4
- EntityName,
5
- AnyString,
6
- CheckCallback,
7
- GeneratedColumnCallback,
8
- FormulaCallback,
9
- FilterQuery,
10
- Dictionary,
11
- AutoPath,
12
- EntityClass,
13
- IndexCallback,
14
- ObjectQuery,
15
- Raw,
16
- } from '../typings.js';
1
+ import type { AnyEntity, Constructor, EntityName, AnyString, CheckCallback, GeneratedColumnCallback, FormulaCallback, FilterQuery, Dictionary, AutoPath, EntityClass, IndexCallback, ObjectQuery, Raw } from '../typings.js';
17
2
  import type { Cascade, LoadStrategy, DeferMode, QueryOrderMap, EmbeddedPrefixMode } from '../enums.js';
18
3
  import type { Type, types } from '../types/index.js';
19
4
  import type { EntityManager } from '../EntityManager.js';
20
5
  import type { FilterOptions, FindOptions } from '../drivers/IDatabaseDriver.js';
21
6
  import type { SerializeOptions } from '../serialization/EntitySerializer.js';
22
7
  export type EntityOptions<T, E = T extends EntityClass<infer P> ? P : T> = {
23
- /** Override default collection/table name. Alias for `collection`. */
24
- tableName?: string;
25
- /** Sets the schema name. */
26
- schema?: string;
27
- /** Override default collection/table name. Alias for `tableName`. */
28
- collection?: string;
29
- /**
30
- * Set default ordering for this entity. This ordering is applied when:
31
- * - Querying the entity directly via `em.find()`, `em.findAll()`, etc.
32
- * - Populating the entity as a relation
33
- *
34
- * All orderings are combined together. Precedence (highest to lowest):
35
- * 1. Runtime `FindOptions.orderBy`
36
- * 2. Relation-level `@OneToMany({ orderBy })` / `@ManyToMany({ orderBy })`
37
- * 3. Entity-level `@Entity({ orderBy })`
38
- */
39
- orderBy?: QueryOrderMap<E> | QueryOrderMap<E>[];
40
- /** For {@doclink inheritance-mapping#single-table-inheritance | Single Table Inheritance}. */
41
- discriminatorColumn?: (T extends EntityClass<infer P> ? keyof P : string) | AnyString;
42
- /** For {@doclink inheritance-mapping#single-table-inheritance | Single Table Inheritance}. */
43
- discriminatorMap?: Dictionary<string>;
44
- /** For {@doclink inheritance-mapping#single-table-inheritance | Single Table Inheritance}. */
45
- discriminatorValue?: number | string;
46
- /** Set inheritance strategy: 'tpt' for {@doclink inheritance-mapping#table-per-type-inheritance-tpt | Table-Per-Type} inheritance. When set on the root entity, each entity in the hierarchy gets its own table with a FK from child PK to parent PK. */
47
- inheritance?: 'tpt';
48
- /** Enforce use of constructor when creating managed entity instances. */
49
- forceConstructor?: boolean;
50
- /** Specify constructor parameters to be used in `em.create` or when `forceConstructor` is enabled. Those should be names of declared entity properties in the same order as your constructor uses them. The ORM tries to infer those automatically, use this option in case the inference fails. */
51
- constructorParams?: (T extends EntityClass<infer P> ? keyof P : string)[];
52
- /** Specify comment to table. (SQL only) */
53
- comment?: string;
54
- /** Marks entity as abstract, such entities are inlined during discovery. */
55
- abstract?: boolean;
56
- /** Disables change tracking - such entities are ignored during flush. */
57
- readonly?: boolean;
58
- /** Marks entity as {@doclink virtual-entities | virtual}. This is set automatically when you use `expression` option (unless `view` is set). */
59
- virtual?: boolean;
60
- /**
61
- * Marks entity as a database view. Unlike virtual entities which evaluate expressions at query time,
62
- * view entities create actual database views. The `expression` option must be provided when `view` is true.
63
- * View entities are read-only by default.
64
- *
65
- * Use `view: true` for regular views, or `view: { materialized: true }` for materialized views (PostgreSQL only).
66
- * Materialized views store the query results and must be refreshed to update data.
67
- * Use `view: { materialized: true, withData: false }` to create an unpopulated materialized view.
68
- */
69
- view?:
70
- | boolean
71
- | {
8
+ /** Override default collection/table name. Alias for `collection`. */
9
+ tableName?: string;
10
+ /** Sets the schema name. */
11
+ schema?: string;
12
+ /** Override default collection/table name. Alias for `tableName`. */
13
+ collection?: string;
14
+ /**
15
+ * Set default ordering for this entity. This ordering is applied when:
16
+ * - Querying the entity directly via `em.find()`, `em.findAll()`, etc.
17
+ * - Populating the entity as a relation
18
+ *
19
+ * All orderings are combined together. Precedence (highest to lowest):
20
+ * 1. Runtime `FindOptions.orderBy`
21
+ * 2. Relation-level `@OneToMany({ orderBy })` / `@ManyToMany({ orderBy })`
22
+ * 3. Entity-level `@Entity({ orderBy })`
23
+ */
24
+ orderBy?: QueryOrderMap<E> | QueryOrderMap<E>[];
25
+ /** For {@doclink inheritance-mapping#single-table-inheritance | Single Table Inheritance}. */
26
+ discriminatorColumn?: (T extends EntityClass<infer P> ? keyof P : string) | AnyString;
27
+ /** For {@doclink inheritance-mapping#single-table-inheritance | Single Table Inheritance}. */
28
+ discriminatorMap?: Dictionary<string>;
29
+ /** For {@doclink inheritance-mapping#single-table-inheritance | Single Table Inheritance}. */
30
+ discriminatorValue?: number | string;
31
+ /** Set inheritance strategy: 'tpt' for {@doclink inheritance-mapping#table-per-type-inheritance-tpt | Table-Per-Type} inheritance. When set on the root entity, each entity in the hierarchy gets its own table with a FK from child PK to parent PK. */
32
+ inheritance?: 'tpt';
33
+ /** Enforce use of constructor when creating managed entity instances. */
34
+ forceConstructor?: boolean;
35
+ /** Specify constructor parameters to be used in `em.create` or when `forceConstructor` is enabled. Those should be names of declared entity properties in the same order as your constructor uses them. The ORM tries to infer those automatically, use this option in case the inference fails. */
36
+ constructorParams?: (T extends EntityClass<infer P> ? keyof P : string)[];
37
+ /** Specify comment to table. (SQL only) */
38
+ comment?: string;
39
+ /** Marks entity as abstract, such entities are inlined during discovery. */
40
+ abstract?: boolean;
41
+ /** Disables change tracking - such entities are ignored during flush. */
42
+ readonly?: boolean;
43
+ /** Marks entity as {@doclink virtual-entities | virtual}. This is set automatically when you use `expression` option (unless `view` is set). */
44
+ virtual?: boolean;
45
+ /**
46
+ * Marks entity as a database view. Unlike virtual entities which evaluate expressions at query time,
47
+ * view entities create actual database views. The `expression` option must be provided when `view` is true.
48
+ * View entities are read-only by default.
49
+ *
50
+ * Use `view: true` for regular views, or `view: { materialized: true }` for materialized views (PostgreSQL only).
51
+ * Materialized views store the query results and must be refreshed to update data.
52
+ * Use `view: { materialized: true, withData: false }` to create an unpopulated materialized view.
53
+ */
54
+ view?: boolean | {
72
55
  materialized?: boolean;
73
56
  withData?: boolean;
74
- };
75
- /** Used to make ORM aware of externally defined triggers. This is needed for MS SQL Server multi inserts, ignored in other dialects. */
76
- hasTriggers?: boolean;
77
- /** SQL query that maps to a {@doclink virtual-entities | virtual entity}, or for view entities, the view definition. */
78
- expression?:
79
- | string
80
- | ((em: any, where: ObjectQuery<E>, options: FindOptions<E, any, any, any>, stream?: boolean) => object);
81
- /** Set {@doclink repositories#custom-repository | custom repository class}. */
82
- repository?: () => Constructor;
57
+ };
58
+ /** Used to make ORM aware of externally defined triggers. This is needed for MS SQL Server multi inserts, ignored in other dialects. */
59
+ hasTriggers?: boolean;
60
+ /** SQL query that maps to a {@doclink virtual-entities | virtual entity}, or for view entities, the view definition. */
61
+ expression?: string | ((em: any, where: ObjectQuery<E>, options: FindOptions<E, any, any, any>, stream?: boolean) => object);
62
+ /** Set {@doclink repositories#custom-repository | custom repository class}. */
63
+ repository?: () => Constructor;
83
64
  };
84
65
  export interface PropertyOptions<Owner> {
85
- /**
86
- * Alias for `fieldName`.
87
- */
88
- name?: string;
89
- /**
90
- * Specify database column name for this property.
91
- *
92
- * @see https://mikro-orm.io/docs/naming-strategy
93
- */
94
- fieldName?: string;
95
- /**
96
- * Specify database column names for this property.
97
- * Same as `fieldName` but for composite FKs.
98
- *
99
- * @see https://mikro-orm.io/docs/naming-strategy
100
- */
101
- fieldNames?: string[];
102
- /**
103
- * Specify an exact database column type for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. This option is only for simple properties represented by a single column. (SQL only)
104
- */
105
- columnType?: ColumnType | AnyString;
106
- /**
107
- * Specify an exact database column type for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. This option is suitable for composite keys, where one property is represented by multiple columns. (SQL only)
108
- */
109
- columnTypes?: (ColumnType | AnyString)[];
110
- /**
111
- * Explicitly specify the runtime type.
112
- *
113
- * @see https://mikro-orm.io/docs/metadata-providers
114
- * @see https://mikro-orm.io/docs/custom-types
115
- */
116
- type?:
117
- | keyof typeof types
118
- | 'ObjectId'
119
- | Date
120
- | Constructor<AnyEntity>
121
- | Constructor<Type<any>>
122
- | Type<any>
123
- | (() => unknown)
124
- | ColumnType
125
- | AnyString;
126
- /**
127
- * Runtime type of the property. This is the JS type that your property is mapped to, e.g. `string` or `number`, and is normally inferred automatically via `reflect-metadata`.
128
- * In some cases, the inference won't work, and you might need to specify the `runtimeType` explicitly - the most common one is when you use a union type with null like `foo: number | null`.
129
- */
130
- runtimeType?: string;
131
- /**
132
- * Set length of database column, used for datetime/timestamp/varchar column types for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
133
- */
134
- length?: number;
135
- /**
136
- * Set precision of database column to represent the number of significant digits. (SQL only)
137
- */
138
- precision?: number;
139
- /**
140
- * Set scale of database column to represents the number of digits after the decimal point. (SQL only)
141
- */
142
- scale?: number;
143
- /**
144
- * Explicitly specify the auto increment of the primary key.
145
- */
146
- autoincrement?: boolean;
147
- /**
148
- * Add the property to the `returning` statement.
149
- */
150
- returning?: boolean;
151
- /**
152
- * Automatically set the property value when entity gets created, executed during flush operation.
153
- * @param entity
154
- */
155
- onCreate?: (entity: Owner, em: EntityManager) => any;
156
- /**
157
- * Automatically update the property value every time entity gets updated, executed during flush operation.
158
- * @param entity
159
- */
160
- onUpdate?: (entity: Owner, em: EntityManager) => any;
161
- /**
162
- * Specify default column value for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
163
- * This is a runtime value, assignable to the entity property. (SQL only)
164
- */
165
- default?: string | string[] | number | number[] | boolean | null | Date | Raw;
166
- /**
167
- * Specify SQL functions for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
168
- * Since v4 you should use defaultRaw for SQL functions. e.g. now()
169
- */
170
- defaultRaw?: string | Raw;
171
- /**
172
- * Set to map some SQL snippet for the entity.
173
- *
174
- * @see https://mikro-orm.io/docs/defining-entities#formulas Formulas
175
- */
176
- formula?: string | FormulaCallback<Owner>;
177
- /**
178
- * For generated columns. This will be appended to the column type after the `generated always` clause.
179
- */
180
- generated?: string | Raw | GeneratedColumnCallback<Owner>;
181
- /**
182
- * Set column as nullable for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
183
- */
184
- nullable?: boolean;
185
- /**
186
- * Set column as unsigned for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
187
- */
188
- unsigned?: boolean;
189
- /**
190
- * Set false to define {@link https://mikro-orm.io/docs/serializing#shadow-properties Shadow Property}.
191
- */
192
- persist?: boolean;
193
- /**
194
- * Set false to disable hydration of this property. Useful for persisted getters.
195
- */
196
- hydrate?: boolean;
197
- /**
198
- * Enable `ScalarReference` wrapper for lazy values. Use this in combination with `lazy: true` to have a type-safe accessor object in place of the value.
199
- */
200
- ref?: boolean;
201
- /**
202
- * Set to true to omit the property when {@link https://mikro-orm.io/docs/serializing Serializing}.
203
- */
204
- hidden?: boolean;
205
- /**
206
- * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via version field. (SQL only)
207
- */
208
- version?: boolean;
209
- /**
210
- * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via concurrency fields.
211
- */
212
- concurrencyCheck?: boolean;
213
- /**
214
- * Explicitly specify index on a property.
215
- */
216
- index?: boolean | string;
217
- /**
218
- * Set column as unique for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
219
- */
220
- unique?: boolean | string;
221
- /**
222
- * Specify column with check constraints. (Postgres driver only)
223
- *
224
- * @see https://mikro-orm.io/docs/defining-entities#check-constraints
225
- */
226
- check?: string | CheckCallback<Owner>;
227
- /**
228
- * Set to omit the property from the select clause for lazy loading.
229
- *
230
- * @see https://mikro-orm.io/docs/defining-entities#lazy-scalar-properties
231
- */
232
- lazy?: boolean;
233
- /**
234
- * Set true to define entity's unique primary key identifier.
235
- * Alias for `@PrimaryKey()` decorator
236
- *
237
- * @see https://mikro-orm.io/docs/decorators#primarykey
238
- */
239
- primary?: boolean;
240
- /**
241
- * Set true to define the properties as setter. (virtual)
242
- *
243
- * @example
244
- * ```ts
245
- * @Property({ setter: true })
246
- * set address(value: string) {
247
- * this._address = value.toLocaleLowerCase();
248
- * }
249
- * ```
250
- */
251
- setter?: boolean;
252
- /**
253
- * Set true to define the properties as getter. (virtual)
254
- *
255
- * @example
256
- * ```ts
257
- * @Property({ getter: true })
258
- * get fullName() {
259
- * return this.firstName + this.lastName;
260
- * }
261
- * ```
262
- */
263
- getter?: boolean;
264
- /**
265
- * When defining a property over a method (not a getter, a regular function), you can use this option to point
266
- * to the method name.
267
- *
268
- * @example
269
- * ```ts
270
- * @Property({ getter: true })
271
- * getFullName() {
272
- * return this.firstName + this.lastName;
273
- * }
274
- * ```
275
- */
276
- getterName?: keyof Owner;
277
- /**
278
- * When using a private property backed by a public get/set pair, use the `accessor` option to point to the other side.
279
- *
280
- * > The `fieldName` will be inferred based on the accessor name unless specified explicitly.
281
- *
282
- * If the `accessor` option points to something, the ORM will use the backing property directly.
283
- *
284
- * @example
285
- * ```ts
286
- * @Entity()
287
- * export class User {
288
- * // the ORM will use the backing field directly
289
- * @Property({ accessor: 'email' })
290
- * private _email: string;
291
- *
292
- * get email() {
293
- * return this._email;
294
- * }
295
- *
296
- * set email() {
297
- * return this._email;
298
- * }
299
- * }
300
- *```
301
- *
302
- * If you want to the ORM to use your accessor internally too, use `accessor: true` on the get/set property instead.
303
- * This is handy if you want to use a native private property for the backing field.
304
- *
305
- * @example
306
- * ```ts
307
- * @Entity({ forceConstructor: true })
308
- * export class User {
309
- * #email: string;
310
- *
311
- * // the ORM will use the accessor internally
312
- * @Property({ accessor: true })
313
- * get email() {
314
- * return this.#email;
315
- * }
316
- *
317
- * set email() {
318
- * return this.#email;
319
- * }
320
- * }
321
- * ```
322
- */
323
- accessor?: keyof Owner | AnyString | boolean;
324
- /**
325
- * Set to define serialized primary key for MongoDB. (virtual)
326
- * Alias for `@SerializedPrimaryKey()` decorator.
327
- *
328
- * @see https://mikro-orm.io/docs/decorators#serializedprimarykey
329
- */
330
- serializedPrimaryKey?: boolean;
331
- /**
332
- * Set to use serialize property. Allow to specify a callback that will be used when serializing a property.
333
- *
334
- * @see https://mikro-orm.io/docs/serializing#property-serializers
335
- */
336
- serializer?: (value: any, options?: SerializeOptions<any>) => any;
337
- /**
338
- * Specify name of key for the serialized value.
339
- */
340
- serializedName?: string;
341
- /**
342
- * Specify serialization groups for `serialize()` calls. If a property does not specify any group, it will be included,
343
- * otherwise only properties with a matching group are included.
344
- */
345
- groups?: string[];
346
- /**
347
- * Specify a custom order based on the values. (SQL only)
348
- */
349
- customOrder?: string[] | number[] | boolean[];
350
- /**
351
- * Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
352
- */
353
- comment?: string;
354
- /** mysql only */
355
- extra?: string;
356
- /**
357
- * Set to avoid a perpetual diff from the {@link https://mikro-orm.io/docs/schema-generator Schema Generator} when columns are generated.
358
- *
359
- * @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
360
- */
361
- ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
66
+ /**
67
+ * Alias for `fieldName`.
68
+ */
69
+ name?: string;
70
+ /**
71
+ * Specify database column name for this property.
72
+ *
73
+ * @see https://mikro-orm.io/docs/naming-strategy
74
+ */
75
+ fieldName?: string;
76
+ /**
77
+ * Specify database column names for this property.
78
+ * Same as `fieldName` but for composite FKs.
79
+ *
80
+ * @see https://mikro-orm.io/docs/naming-strategy
81
+ */
82
+ fieldNames?: string[];
83
+ /**
84
+ * Specify an exact database column type for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. This option is only for simple properties represented by a single column. (SQL only)
85
+ */
86
+ columnType?: ColumnType | AnyString;
87
+ /**
88
+ * Specify an exact database column type for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. This option is suitable for composite keys, where one property is represented by multiple columns. (SQL only)
89
+ */
90
+ columnTypes?: (ColumnType | AnyString)[];
91
+ /**
92
+ * Explicitly specify the runtime type.
93
+ *
94
+ * @see https://mikro-orm.io/docs/metadata-providers
95
+ * @see https://mikro-orm.io/docs/custom-types
96
+ */
97
+ type?: keyof typeof types | 'ObjectId' | Date | Constructor<AnyEntity> | Constructor<Type<any>> | Type<any> | (() => unknown) | ColumnType | AnyString;
98
+ /**
99
+ * Runtime type of the property. This is the JS type that your property is mapped to, e.g. `string` or `number`, and is normally inferred automatically via `reflect-metadata`.
100
+ * In some cases, the inference won't work, and you might need to specify the `runtimeType` explicitly - the most common one is when you use a union type with null like `foo: number | null`.
101
+ */
102
+ runtimeType?: string;
103
+ /**
104
+ * Set length of database column, used for datetime/timestamp/varchar column types for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
105
+ */
106
+ length?: number;
107
+ /**
108
+ * Set precision of database column to represent the number of significant digits. (SQL only)
109
+ */
110
+ precision?: number;
111
+ /**
112
+ * Set scale of database column to represents the number of digits after the decimal point. (SQL only)
113
+ */
114
+ scale?: number;
115
+ /**
116
+ * Explicitly specify the auto increment of the primary key.
117
+ */
118
+ autoincrement?: boolean;
119
+ /**
120
+ * Add the property to the `returning` statement.
121
+ */
122
+ returning?: boolean;
123
+ /**
124
+ * Automatically set the property value when entity gets created, executed during flush operation.
125
+ * @param entity
126
+ */
127
+ onCreate?: (entity: Owner, em: EntityManager) => any;
128
+ /**
129
+ * Automatically update the property value every time entity gets updated, executed during flush operation.
130
+ * @param entity
131
+ */
132
+ onUpdate?: (entity: Owner, em: EntityManager) => any;
133
+ /**
134
+ * Specify default column value for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
135
+ * This is a runtime value, assignable to the entity property. (SQL only)
136
+ */
137
+ default?: string | string[] | number | number[] | boolean | null | Date | Raw;
138
+ /**
139
+ * Specify SQL functions for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
140
+ * Since v4 you should use defaultRaw for SQL functions. e.g. now()
141
+ */
142
+ defaultRaw?: string | Raw;
143
+ /**
144
+ * Set to map some SQL snippet for the entity.
145
+ *
146
+ * @see https://mikro-orm.io/docs/defining-entities#formulas Formulas
147
+ */
148
+ formula?: string | FormulaCallback<Owner>;
149
+ /**
150
+ * For generated columns. This will be appended to the column type after the `generated always` clause.
151
+ */
152
+ generated?: string | Raw | GeneratedColumnCallback<Owner>;
153
+ /**
154
+ * Set column as nullable for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
155
+ */
156
+ nullable?: boolean;
157
+ /**
158
+ * Set column as unsigned for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
159
+ */
160
+ unsigned?: boolean;
161
+ /**
162
+ * Set false to define {@link https://mikro-orm.io/docs/serializing#shadow-properties Shadow Property}.
163
+ */
164
+ persist?: boolean;
165
+ /**
166
+ * Set false to disable hydration of this property. Useful for persisted getters.
167
+ */
168
+ hydrate?: boolean;
169
+ /**
170
+ * Enable `ScalarReference` wrapper for lazy values. Use this in combination with `lazy: true` to have a type-safe accessor object in place of the value.
171
+ */
172
+ ref?: boolean;
173
+ /**
174
+ * Set to true to omit the property when {@link https://mikro-orm.io/docs/serializing Serializing}.
175
+ */
176
+ hidden?: boolean;
177
+ /**
178
+ * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via version field. (SQL only)
179
+ */
180
+ version?: boolean;
181
+ /**
182
+ * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via concurrency fields.
183
+ */
184
+ concurrencyCheck?: boolean;
185
+ /**
186
+ * Explicitly specify index on a property.
187
+ */
188
+ index?: boolean | string;
189
+ /**
190
+ * Set column as unique for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
191
+ */
192
+ unique?: boolean | string;
193
+ /**
194
+ * Specify column with check constraints. (Postgres driver only)
195
+ *
196
+ * @see https://mikro-orm.io/docs/defining-entities#check-constraints
197
+ */
198
+ check?: string | CheckCallback<Owner>;
199
+ /**
200
+ * Set to omit the property from the select clause for lazy loading.
201
+ *
202
+ * @see https://mikro-orm.io/docs/defining-entities#lazy-scalar-properties
203
+ */
204
+ lazy?: boolean;
205
+ /**
206
+ * Set true to define entity's unique primary key identifier.
207
+ * Alias for `@PrimaryKey()` decorator
208
+ *
209
+ * @see https://mikro-orm.io/docs/decorators#primarykey
210
+ */
211
+ primary?: boolean;
212
+ /**
213
+ * Set true to define the properties as setter. (virtual)
214
+ *
215
+ * @example
216
+ * ```ts
217
+ * @Property({ setter: true })
218
+ * set address(value: string) {
219
+ * this._address = value.toLocaleLowerCase();
220
+ * }
221
+ * ```
222
+ */
223
+ setter?: boolean;
224
+ /**
225
+ * Set true to define the properties as getter. (virtual)
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * @Property({ getter: true })
230
+ * get fullName() {
231
+ * return this.firstName + this.lastName;
232
+ * }
233
+ * ```
234
+ */
235
+ getter?: boolean;
236
+ /**
237
+ * When defining a property over a method (not a getter, a regular function), you can use this option to point
238
+ * to the method name.
239
+ *
240
+ * @example
241
+ * ```ts
242
+ * @Property({ getter: true })
243
+ * getFullName() {
244
+ * return this.firstName + this.lastName;
245
+ * }
246
+ * ```
247
+ */
248
+ getterName?: keyof Owner;
249
+ /**
250
+ * When using a private property backed by a public get/set pair, use the `accessor` option to point to the other side.
251
+ *
252
+ * > The `fieldName` will be inferred based on the accessor name unless specified explicitly.
253
+ *
254
+ * If the `accessor` option points to something, the ORM will use the backing property directly.
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * @Entity()
259
+ * export class User {
260
+ * // the ORM will use the backing field directly
261
+ * @Property({ accessor: 'email' })
262
+ * private _email: string;
263
+ *
264
+ * get email() {
265
+ * return this._email;
266
+ * }
267
+ *
268
+ * set email() {
269
+ * return this._email;
270
+ * }
271
+ * }
272
+ *```
273
+ *
274
+ * If you want to the ORM to use your accessor internally too, use `accessor: true` on the get/set property instead.
275
+ * This is handy if you want to use a native private property for the backing field.
276
+ *
277
+ * @example
278
+ * ```ts
279
+ * @Entity({ forceConstructor: true })
280
+ * export class User {
281
+ * #email: string;
282
+ *
283
+ * // the ORM will use the accessor internally
284
+ * @Property({ accessor: true })
285
+ * get email() {
286
+ * return this.#email;
287
+ * }
288
+ *
289
+ * set email() {
290
+ * return this.#email;
291
+ * }
292
+ * }
293
+ * ```
294
+ */
295
+ accessor?: keyof Owner | AnyString | boolean;
296
+ /**
297
+ * Set to define serialized primary key for MongoDB. (virtual)
298
+ * Alias for `@SerializedPrimaryKey()` decorator.
299
+ *
300
+ * @see https://mikro-orm.io/docs/decorators#serializedprimarykey
301
+ */
302
+ serializedPrimaryKey?: boolean;
303
+ /**
304
+ * Set to use serialize property. Allow to specify a callback that will be used when serializing a property.
305
+ *
306
+ * @see https://mikro-orm.io/docs/serializing#property-serializers
307
+ */
308
+ serializer?: (value: any, options?: SerializeOptions<any>) => any;
309
+ /**
310
+ * Specify name of key for the serialized value.
311
+ */
312
+ serializedName?: string;
313
+ /**
314
+ * Specify serialization groups for `serialize()` calls. If a property does not specify any group, it will be included,
315
+ * otherwise only properties with a matching group are included.
316
+ */
317
+ groups?: string[];
318
+ /**
319
+ * Specify a custom order based on the values. (SQL only)
320
+ */
321
+ customOrder?: string[] | number[] | boolean[];
322
+ /**
323
+ * Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
324
+ */
325
+ comment?: string;
326
+ /** mysql only */
327
+ extra?: string;
328
+ /**
329
+ * Set to avoid a perpetual diff from the {@link https://mikro-orm.io/docs/schema-generator Schema Generator} when columns are generated.
330
+ *
331
+ * @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
332
+ */
333
+ ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
362
334
  }
363
335
  export interface ReferenceOptions<Owner, Target> extends PropertyOptions<Owner> {
364
- /** Set target entity type. For polymorphic relations, pass an array of entity types. */
365
- entity?: () => EntityName<Target> | EntityName<Target>[];
366
- /** Set what actions on owning entity should be cascaded to the relationship. Defaults to [Cascade.PERSIST, Cascade.MERGE] (see {@doclink cascading}). */
367
- cascade?: Cascade[];
368
- /** Always load the relationship. Discouraged for use with to-many relations for performance reasons. */
369
- eager?: boolean;
370
- /** Override the default loading strategy for this property. This option has precedence over the global `loadStrategy`, but can be overridden by `FindOptions.strategy`. */
371
- strategy?: LoadStrategy | `${LoadStrategy}`;
372
- /** Control filter parameters for the relation. This will serve as a default value when processing filters on this relation. It's value can be overridden via `em.fork()` or `FindOptions`. */
373
- filters?: FilterOptions;
336
+ /** Set target entity type. For polymorphic relations, pass an array of entity types. */
337
+ entity?: () => EntityName<Target> | EntityName<Target>[];
338
+ /** Set what actions on owning entity should be cascaded to the relationship. Defaults to [Cascade.PERSIST, Cascade.MERGE] (see {@doclink cascading}). */
339
+ cascade?: Cascade[];
340
+ /** Always load the relationship. Discouraged for use with to-many relations for performance reasons. */
341
+ eager?: boolean;
342
+ /** Override the default loading strategy for this property. This option has precedence over the global `loadStrategy`, but can be overridden by `FindOptions.strategy`. */
343
+ strategy?: LoadStrategy | `${LoadStrategy}`;
344
+ /** Control filter parameters for the relation. This will serve as a default value when processing filters on this relation. It's value can be overridden via `em.fork()` or `FindOptions`. */
345
+ filters?: FilterOptions;
374
346
  }
375
347
  /**
376
348
  * Inspired by https://github.com/typeorm/typeorm/blob/941b584ba135617e55d6685caef671172ec1dc03/src/driver/types/ColumnTypes.ts
377
349
  * @ignore
378
350
  */
379
- export type ColumnType =
380
- | 'int'
381
- | 'int4'
382
- | 'integer'
383
- | 'bigint'
384
- | 'int8'
385
- | 'int2'
386
- | 'tinyint'
387
- | 'smallint'
388
- | 'mediumint'
389
- | 'double'
390
- | 'double precision'
391
- | 'real'
392
- | 'float8'
393
- | 'decimal'
394
- | 'numeric'
395
- | 'float'
396
- | 'float4'
397
- | 'datetime'
398
- | 'time'
399
- | 'time with time zone'
400
- | 'timestamp'
401
- | 'timestamp with time zone'
402
- | 'timetz'
403
- | 'timestamptz'
404
- | 'date'
405
- | 'interval'
406
- | 'character varying'
407
- | 'varchar'
408
- | 'char'
409
- | 'character'
410
- | 'uuid'
411
- | 'text'
412
- | 'tinytext'
413
- | 'mediumtext'
414
- | 'longtext'
415
- | 'boolean'
416
- | 'bool'
417
- | 'bit'
418
- | 'enum'
419
- | 'blob'
420
- | 'tinyblob'
421
- | 'mediumblob'
422
- | 'longblob'
423
- | 'bytea'
424
- | 'point'
425
- | 'line'
426
- | 'lseg'
427
- | 'box'
428
- | 'circle'
429
- | 'path'
430
- | 'polygon'
431
- | 'geometry'
432
- | 'tsvector'
433
- | 'tsquery'
434
- | 'json'
435
- | 'jsonb';
351
+ export type ColumnType = 'int' | 'int4' | 'integer' | 'bigint' | 'int8' | 'int2' | 'tinyint' | 'smallint' | 'mediumint' | 'double' | 'double precision' | 'real' | 'float8' | 'decimal' | 'numeric' | 'float' | 'float4' | 'datetime' | 'time' | 'time with time zone' | 'timestamp' | 'timestamp with time zone' | 'timetz' | 'timestamptz' | 'date' | 'interval' | 'character varying' | 'varchar' | 'char' | 'character' | 'uuid' | 'text' | 'tinytext' | 'mediumtext' | 'longtext' | 'boolean' | 'bool' | 'bit' | 'enum' | 'blob' | 'tinyblob' | 'mediumblob' | 'longblob' | 'bytea' | 'point' | 'line' | 'lseg' | 'box' | 'circle' | 'path' | 'polygon' | 'geometry' | 'tsvector' | 'tsquery' | 'json' | 'jsonb';
436
352
  interface PolymorphicOptions {
437
- /**
438
- * For polymorphic relations. Specifies the property name that stores the entity type discriminator.
439
- * Defaults to the property name. Only used when `entity` returns an array of types.
440
- * For M:N relations, this is the column name in the pivot table.
441
- */
442
- discriminator?: string;
443
- /**
444
- * For polymorphic relations. Custom mapping of discriminator values to entity class names.
445
- * If not provided, table names are used as discriminator values.
446
- */
447
- discriminatorMap?: Dictionary<string>;
353
+ /**
354
+ * For polymorphic relations. Specifies the property name that stores the entity type discriminator.
355
+ * Defaults to the property name. Only used when `entity` returns an array of types.
356
+ * For M:N relations, this is the column name in the pivot table.
357
+ */
358
+ discriminator?: string;
359
+ /**
360
+ * For polymorphic relations. Custom mapping of discriminator values to entity class names.
361
+ * If not provided, table names are used as discriminator values.
362
+ */
363
+ discriminatorMap?: Dictionary<string>;
448
364
  }
449
365
  export interface ManyToOneOptions<Owner, Target> extends ReferenceOptions<Owner, Target>, PolymorphicOptions {
450
- /** Point to the inverse side property name. */
451
- inversedBy?: (string & keyof Target) | ((e: Target) => any);
452
- /** Wrap the entity in {@apilink Reference} wrapper. */
453
- ref?: boolean;
454
- /** Use this relation as a primary key. */
455
- primary?: boolean;
456
- /** Map this relation to the primary key value instead of an entity. */
457
- mapToPk?: boolean;
458
- /** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
459
- joinColumn?: string;
460
- /** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
461
- joinColumns?: string[];
462
- /** When a part of a composite column is shared in other properties, use this option to specify what columns are considered as owned by this property. This is useful when your composite property is nullable, but parts of it are not. */
463
- ownColumns?: string[];
464
- /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
465
- referenceColumnName?: string;
466
- /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
467
- referencedColumnNames?: string[];
468
- /** Specify the property name on the target entity that this FK references instead of the primary key. */
469
- targetKey?: string & keyof Target;
470
- /** What to do when the target entity gets deleted. */
471
- deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
472
- /** What to do when the reference to the target entity gets updated. */
473
- updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
474
- /** Set the constraint type. Immediate constraints are checked for each statement, while deferred ones are only checked at the end of the transaction. Only for postgres unique constraints. */
475
- deferMode?: DeferMode | `${DeferMode}`;
476
- /** Enable/disable foreign key constraint creation on this relation */
477
- createForeignKeyConstraint?: boolean;
478
- /** Set a custom foreign key constraint name, overriding NamingStrategy.indexName(). */
479
- foreignKeyName?: string;
366
+ /** Point to the inverse side property name. */
367
+ inversedBy?: (string & keyof Target) | ((e: Target) => any);
368
+ /** Wrap the entity in {@apilink Reference} wrapper. */
369
+ ref?: boolean;
370
+ /** Use this relation as a primary key. */
371
+ primary?: boolean;
372
+ /** Map this relation to the primary key value instead of an entity. */
373
+ mapToPk?: boolean;
374
+ /** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
375
+ joinColumn?: string;
376
+ /** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
377
+ joinColumns?: string[];
378
+ /** When a part of a composite column is shared in other properties, use this option to specify what columns are considered as owned by this property. This is useful when your composite property is nullable, but parts of it are not. */
379
+ ownColumns?: string[];
380
+ /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
381
+ referenceColumnName?: string;
382
+ /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
383
+ referencedColumnNames?: string[];
384
+ /** Specify the property name on the target entity that this FK references instead of the primary key. */
385
+ targetKey?: string & keyof Target;
386
+ /** What to do when the target entity gets deleted. */
387
+ deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
388
+ /** What to do when the reference to the target entity gets updated. */
389
+ updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
390
+ /** Set the constraint type. Immediate constraints are checked for each statement, while deferred ones are only checked at the end of the transaction. Only for postgres unique constraints. */
391
+ deferMode?: DeferMode | `${DeferMode}`;
392
+ /** Enable/disable foreign key constraint creation on this relation */
393
+ createForeignKeyConstraint?: boolean;
394
+ /** Set a custom foreign key constraint name, overriding NamingStrategy.indexName(). */
395
+ foreignKeyName?: string;
480
396
  }
481
397
  export interface OneToManyOptions<Owner, Target> extends ReferenceOptions<Owner, Target> {
482
- /** Remove the entity when it gets disconnected from the relationship (see {@doclink cascading | Cascading}). */
483
- orphanRemoval?: boolean;
484
- /** Set default ordering. */
485
- orderBy?: QueryOrderMap<Target> | QueryOrderMap<Target>[];
486
- /** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
487
- where?: FilterQuery<Target>;
488
- /** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
489
- joinColumn?: string;
490
- /** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
491
- joinColumns?: string[];
492
- /** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
493
- inverseJoinColumn?: string;
494
- /** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
495
- inverseJoinColumns?: string[];
496
- /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
497
- referenceColumnName?: string;
498
- /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
499
- referencedColumnNames?: string[];
500
- /** Point to the owning side property name. */
501
- mappedBy: (string & keyof Target) | ((e: Target) => any);
398
+ /** Remove the entity when it gets disconnected from the relationship (see {@doclink cascading | Cascading}). */
399
+ orphanRemoval?: boolean;
400
+ /** Set default ordering. */
401
+ orderBy?: QueryOrderMap<Target> | QueryOrderMap<Target>[];
402
+ /** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
403
+ where?: FilterQuery<Target>;
404
+ /** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
405
+ joinColumn?: string;
406
+ /** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
407
+ joinColumns?: string[];
408
+ /** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
409
+ inverseJoinColumn?: string;
410
+ /** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
411
+ inverseJoinColumns?: string[];
412
+ /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
413
+ referenceColumnName?: string;
414
+ /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
415
+ referencedColumnNames?: string[];
416
+ /** Point to the owning side property name. */
417
+ mappedBy: (string & keyof Target) | ((e: Target) => any);
502
418
  }
503
- export interface OneToOneOptions<Owner, Target>
504
- extends Partial<Omit<OneToManyOptions<Owner, Target>, 'orderBy'>>, PolymorphicOptions {
505
- /** Set this side as owning. Owning side is where the foreign key is defined. This option is not required if you use `inversedBy` or `mappedBy` to distinguish owning and inverse side. */
506
- owner?: boolean;
507
- /** Point to the inverse side property name. */
508
- inversedBy?: (string & keyof Target) | ((e: Target) => any);
509
- /** Wrap the entity in {@apilink Reference} wrapper. */
510
- ref?: boolean;
511
- /** Use this relation as a primary key. */
512
- primary?: boolean;
513
- /** Map this relation to the primary key value instead of an entity. */
514
- mapToPk?: boolean;
515
- /** When a part of a composite column is shared in other properties, use this option to specify what columns are considered as owned by this property. This is useful when your composite property is nullable, but parts of it are not. */
516
- ownColumns?: string[];
517
- /** Specify the property name on the target entity that this FK references instead of the primary key. */
518
- targetKey?: string & keyof Target;
519
- /** What to do when the target entity gets deleted. */
520
- deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
521
- /** What to do when the reference to the target entity gets updated. */
522
- updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
523
- /** Set the constraint type. Immediate constraints are checked for each statement, while deferred ones are only checked at the end of the transaction. Only for postgres unique constraints. */
524
- deferMode?: DeferMode | `${DeferMode}`;
525
- /** Set a custom foreign key constraint name, overriding NamingStrategy.indexName(). */
526
- foreignKeyName?: string;
527
- /** Enable/disable foreign key constraint creation on this relation */
528
- createForeignKeyConstraint?: boolean;
419
+ export interface OneToOneOptions<Owner, Target> extends Partial<Omit<OneToManyOptions<Owner, Target>, 'orderBy'>>, PolymorphicOptions {
420
+ /** Set this side as owning. Owning side is where the foreign key is defined. This option is not required if you use `inversedBy` or `mappedBy` to distinguish owning and inverse side. */
421
+ owner?: boolean;
422
+ /** Point to the inverse side property name. */
423
+ inversedBy?: (string & keyof Target) | ((e: Target) => any);
424
+ /** Wrap the entity in {@apilink Reference} wrapper. */
425
+ ref?: boolean;
426
+ /** Use this relation as a primary key. */
427
+ primary?: boolean;
428
+ /** Map this relation to the primary key value instead of an entity. */
429
+ mapToPk?: boolean;
430
+ /** When a part of a composite column is shared in other properties, use this option to specify what columns are considered as owned by this property. This is useful when your composite property is nullable, but parts of it are not. */
431
+ ownColumns?: string[];
432
+ /** Specify the property name on the target entity that this FK references instead of the primary key. */
433
+ targetKey?: string & keyof Target;
434
+ /** What to do when the target entity gets deleted. */
435
+ deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
436
+ /** What to do when the reference to the target entity gets updated. */
437
+ updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
438
+ /** Set the constraint type. Immediate constraints are checked for each statement, while deferred ones are only checked at the end of the transaction. Only for postgres unique constraints. */
439
+ deferMode?: DeferMode | `${DeferMode}`;
440
+ /** Set a custom foreign key constraint name, overriding NamingStrategy.indexName(). */
441
+ foreignKeyName?: string;
442
+ /** Enable/disable foreign key constraint creation on this relation */
443
+ createForeignKeyConstraint?: boolean;
529
444
  }
530
445
  export interface ManyToManyOptions<Owner, Target> extends ReferenceOptions<Owner, Target>, PolymorphicOptions {
531
- /** Set this side as owning. Owning side is where the foreign key is defined. This option is not required if you use `inversedBy` or `mappedBy` to distinguish owning and inverse side. */
532
- owner?: boolean;
533
- /** Point to the inverse side property name. */
534
- inversedBy?: (string & keyof Target) | ((e: Target) => any);
535
- /** Point to the owning side property name. */
536
- mappedBy?: (string & keyof Target) | ((e: Target) => any);
537
- /** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
538
- where?: FilterQuery<Target>;
539
- /** Set default ordering. */
540
- orderBy?: QueryOrderMap<Target> | QueryOrderMap<Target>[];
541
- /** Force stable insertion order of items in the collection (see {@doclink collections | Collections}). */
542
- fixedOrder?: boolean;
543
- /** Override default order column name (`id`) for fixed ordering. */
544
- fixedOrderColumn?: string;
545
- /** Override default name for pivot table (see {@doclink naming-strategy | Naming Strategy}). */
546
- pivotTable?: string;
547
- /** Set pivot entity for this relation (see {@doclink collections#custom-pivot-table-entity | Custom pivot table entity}). */
548
- pivotEntity?: () => EntityName;
549
- /** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
550
- joinColumn?: string;
551
- /** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
552
- joinColumns?: string[];
553
- /** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
554
- inverseJoinColumn?: string;
555
- /** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
556
- inverseJoinColumns?: string[];
557
- /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
558
- referenceColumnName?: string;
559
- /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
560
- referencedColumnNames?: string[];
561
- /** What to do when the target entity gets deleted. */
562
- deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
563
- /** What to do when the reference to the target entity gets updated. */
564
- updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
565
- /** Enable/disable foreign key constraint creation on this relation */
566
- createForeignKeyConstraint?: boolean;
446
+ /** Set this side as owning. Owning side is where the foreign key is defined. This option is not required if you use `inversedBy` or `mappedBy` to distinguish owning and inverse side. */
447
+ owner?: boolean;
448
+ /** Point to the inverse side property name. */
449
+ inversedBy?: (string & keyof Target) | ((e: Target) => any);
450
+ /** Point to the owning side property name. */
451
+ mappedBy?: (string & keyof Target) | ((e: Target) => any);
452
+ /** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
453
+ where?: FilterQuery<Target>;
454
+ /** Set default ordering. */
455
+ orderBy?: QueryOrderMap<Target> | QueryOrderMap<Target>[];
456
+ /** Force stable insertion order of items in the collection (see {@doclink collections | Collections}). */
457
+ fixedOrder?: boolean;
458
+ /** Override default order column name (`id`) for fixed ordering. */
459
+ fixedOrderColumn?: string;
460
+ /** Override default name for pivot table (see {@doclink naming-strategy | Naming Strategy}). */
461
+ pivotTable?: string;
462
+ /** Set pivot entity for this relation (see {@doclink collections#custom-pivot-table-entity | Custom pivot table entity}). */
463
+ pivotEntity?: () => EntityName;
464
+ /** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
465
+ joinColumn?: string;
466
+ /** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
467
+ joinColumns?: string[];
468
+ /** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
469
+ inverseJoinColumn?: string;
470
+ /** Override the default database column name on the inverse side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
471
+ inverseJoinColumns?: string[];
472
+ /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
473
+ referenceColumnName?: string;
474
+ /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
475
+ referencedColumnNames?: string[];
476
+ /** What to do when the target entity gets deleted. */
477
+ deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
478
+ /** What to do when the reference to the target entity gets updated. */
479
+ updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
480
+ /** Enable/disable foreign key constraint creation on this relation */
481
+ createForeignKeyConstraint?: boolean;
567
482
  }
568
483
  export interface EmbeddedOptions<Owner, Target> extends PropertyOptions<Owner> {
569
- entity?: () => EntityName<Target> | EntityName[];
570
- prefix?: string | boolean;
571
- prefixMode?: EmbeddedPrefixMode;
572
- object?: boolean;
573
- array?: boolean;
484
+ entity?: () => EntityName<Target> | EntityName[];
485
+ prefix?: string | boolean;
486
+ prefixMode?: EmbeddedPrefixMode;
487
+ object?: boolean;
488
+ array?: boolean;
574
489
  }
575
490
  export interface EmbeddableOptions<Owner> {
576
- /** Specify constructor parameters to be used in `em.create` or when `forceConstructor` is enabled. Those should be names of declared entity properties in the same order as your constructor uses them. The ORM tries to infer those automatically, use this option in case the inference fails. */
577
- constructorParams?: (Owner extends EntityClass<infer P> ? keyof P : string)[];
578
- /** For polymorphic embeddables. Specify the property name that stores the discriminator value. Alias for `discriminatorColumn`. */
579
- discriminator?: (Owner extends EntityClass<infer P> ? keyof P : string) | AnyString;
580
- /** For polymorphic embeddables. @deprecated Use `discriminator` instead. */
581
- discriminatorColumn?: (Owner extends EntityClass<infer P> ? keyof P : string) | AnyString;
582
- discriminatorMap?: Dictionary<string>;
583
- discriminatorValue?: number | string;
584
- abstract?: boolean;
491
+ /** Specify constructor parameters to be used in `em.create` or when `forceConstructor` is enabled. Those should be names of declared entity properties in the same order as your constructor uses them. The ORM tries to infer those automatically, use this option in case the inference fails. */
492
+ constructorParams?: (Owner extends EntityClass<infer P> ? keyof P : string)[];
493
+ /** For polymorphic embeddables. Specify the property name that stores the discriminator value. Alias for `discriminatorColumn`. */
494
+ discriminator?: (Owner extends EntityClass<infer P> ? keyof P : string) | AnyString;
495
+ /** For polymorphic embeddables. @deprecated Use `discriminator` instead. */
496
+ discriminatorColumn?: (Owner extends EntityClass<infer P> ? keyof P : string) | AnyString;
497
+ discriminatorMap?: Dictionary<string>;
498
+ discriminatorValue?: number | string;
499
+ abstract?: boolean;
585
500
  }
586
501
  export interface EnumOptions<T> extends PropertyOptions<T> {
587
- items?: readonly (number | string)[] | (() => Dictionary);
588
- array?: boolean;
589
- /** for postgres, by default it uses text column with check constraint */
590
- nativeEnumName?: string;
502
+ items?: readonly (number | string)[] | (() => Dictionary);
503
+ array?: boolean;
504
+ /** for postgres, by default it uses text column with check constraint */
505
+ nativeEnumName?: string;
506
+ }
507
+ export interface PrimaryKeyOptions<T> extends PropertyOptions<T> {
591
508
  }
592
- export interface PrimaryKeyOptions<T> extends PropertyOptions<T> {}
593
509
  export interface SerializedPrimaryKeyOptions<T> extends PropertyOptions<T> {
594
- type?: any;
510
+ type?: any;
595
511
  }
596
512
  type MaybeArray<T> = T | T[];
597
513
  type Properties<T, H extends string> = MaybeArray<AutoPath<T, H>>;
598
514
  /** Options for column within an index, supporting advanced index features like prefix length and collation. */
599
515
  export interface IndexColumnOptions {
600
- /** Column name or property path. */
601
- name: string;
602
- /** Sort order for the column (default: ASC). */
603
- sort?: 'ASC' | 'DESC' | 'asc' | 'desc';
604
- /** NULLS ordering for the column (PostgreSQL). */
605
- nulls?: 'FIRST' | 'LAST' | 'first' | 'last';
606
- /** Prefix length for the column (MySQL, MariaDB). */
607
- length?: number;
608
- /** Collation for the column (PostgreSQL, SQLite, or MySQL/MariaDB via expression). */
609
- collation?: string;
516
+ /** Column name or property path. */
517
+ name: string;
518
+ /** Sort order for the column (default: ASC). */
519
+ sort?: 'ASC' | 'DESC' | 'asc' | 'desc';
520
+ /** NULLS ordering for the column (PostgreSQL). */
521
+ nulls?: 'FIRST' | 'LAST' | 'first' | 'last';
522
+ /** Prefix length for the column (MySQL, MariaDB). */
523
+ length?: number;
524
+ /** Collation for the column (PostgreSQL, SQLite, or MySQL/MariaDB via expression). */
525
+ collation?: string;
610
526
  }
611
527
  interface BaseOptions<T, H extends string> {
612
- name?: string;
613
- properties?: T extends EntityClass<infer P> ? Properties<P, H> : Properties<T, H>;
614
- options?: Dictionary;
615
- expression?: string | (T extends EntityClass<infer P> ? IndexCallback<P> : IndexCallback<T>);
616
- /**
617
- * Advanced column options for the index.
618
- * When specified, allows fine-grained control over each column in the index including
619
- * sort order, nulls ordering, prefix length, and collation.
620
- * If both `columns` and `properties` are specified, `columns` takes precedence for index creation.
621
- */
622
- columns?: IndexColumnOptions[];
623
- /**
624
- * Columns to include in the index but not as part of the key (PostgreSQL, MSSQL).
625
- * These columns are stored in the leaf level of the index but not used for searching.
626
- */
627
- include?: T extends EntityClass<infer P> ? Properties<P, H> : Properties<T, H>;
628
- /** Fill factor for the index as a percentage 0-100 (PostgreSQL, MSSQL). */
629
- fillFactor?: number;
528
+ name?: string;
529
+ properties?: T extends EntityClass<infer P> ? Properties<P, H> : Properties<T, H>;
530
+ options?: Dictionary;
531
+ expression?: string | (T extends EntityClass<infer P> ? IndexCallback<P> : IndexCallback<T>);
532
+ /**
533
+ * Advanced column options for the index.
534
+ * When specified, allows fine-grained control over each column in the index including
535
+ * sort order, nulls ordering, prefix length, and collation.
536
+ * If both `columns` and `properties` are specified, `columns` takes precedence for index creation.
537
+ */
538
+ columns?: IndexColumnOptions[];
539
+ /**
540
+ * Columns to include in the index but not as part of the key (PostgreSQL, MSSQL).
541
+ * These columns are stored in the leaf level of the index but not used for searching.
542
+ */
543
+ include?: T extends EntityClass<infer P> ? Properties<P, H> : Properties<T, H>;
544
+ /** Fill factor for the index as a percentage 0-100 (PostgreSQL, MSSQL). */
545
+ fillFactor?: number;
630
546
  }
631
547
  export interface UniqueOptions<T, H extends string = string> extends BaseOptions<T, H> {
632
- deferMode?: DeferMode | `${DeferMode}`;
633
- /**
634
- * Whether the index is disabled (MSSQL only).
635
- * A disabled index is not used for query planning and is not maintained on writes.
636
- * It can be re-enabled later using `ALTER INDEX ... REBUILD`.
637
- */
638
- disabled?: boolean;
548
+ deferMode?: DeferMode | `${DeferMode}`;
549
+ /**
550
+ * Whether the index is disabled (MSSQL only).
551
+ * A disabled index is not used for query planning and is not maintained on writes.
552
+ * It can be re-enabled later using `ALTER INDEX ... REBUILD`.
553
+ */
554
+ disabled?: boolean;
639
555
  }
640
556
  export interface IndexOptions<T, H extends string = string> extends BaseOptions<T, H> {
641
- type?: string;
642
- /**
643
- * Whether the index is invisible/hidden from the query optimizer (MySQL 8+, MariaDB 10.6+, MongoDB).
644
- * An invisible index is still maintained on writes but not used for query planning.
645
- * Useful for testing the impact of removing an index before actually dropping it.
646
- */
647
- invisible?: boolean;
648
- /**
649
- * Whether the index is disabled (MSSQL only).
650
- * A disabled index is not used for query planning and is not maintained on writes.
651
- * It can be re-enabled later using `ALTER INDEX ... REBUILD`.
652
- */
653
- disabled?: boolean;
654
- /**
655
- * Whether the index should be clustered (MariaDB, MSSQL).
656
- * A clustered index determines the physical order of data in the table.
657
- * Only one clustered index can exist per table.
658
- */
659
- clustered?: boolean;
557
+ type?: string;
558
+ /**
559
+ * Whether the index is invisible/hidden from the query optimizer (MySQL 8+, MariaDB 10.6+, MongoDB).
560
+ * An invisible index is still maintained on writes but not used for query planning.
561
+ * Useful for testing the impact of removing an index before actually dropping it.
562
+ */
563
+ invisible?: boolean;
564
+ /**
565
+ * Whether the index is disabled (MSSQL only).
566
+ * A disabled index is not used for query planning and is not maintained on writes.
567
+ * It can be re-enabled later using `ALTER INDEX ... REBUILD`.
568
+ */
569
+ disabled?: boolean;
570
+ /**
571
+ * Whether the index should be clustered (MariaDB, MSSQL).
572
+ * A clustered index determines the physical order of data in the table.
573
+ * Only one clustered index can exist per table.
574
+ */
575
+ clustered?: boolean;
660
576
  }
661
577
  export {};