@mikro-orm/core 7.0.0-dev.32 → 7.0.0-dev.321

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 (216) hide show
  1. package/EntityManager.d.ts +71 -63
  2. package/EntityManager.js +365 -283
  3. package/MikroORM.d.ts +44 -35
  4. package/MikroORM.js +109 -142
  5. package/README.md +7 -4
  6. package/cache/FileCacheAdapter.d.ts +1 -2
  7. package/cache/FileCacheAdapter.js +19 -14
  8. package/cache/GeneratedCacheAdapter.d.ts +0 -1
  9. package/cache/GeneratedCacheAdapter.js +0 -2
  10. package/cache/index.d.ts +1 -2
  11. package/cache/index.js +0 -2
  12. package/connections/Connection.d.ts +12 -5
  13. package/connections/Connection.js +37 -15
  14. package/drivers/DatabaseDriver.d.ts +25 -18
  15. package/drivers/DatabaseDriver.js +144 -45
  16. package/drivers/IDatabaseDriver.d.ts +118 -23
  17. package/entity/BaseEntity.d.ts +63 -4
  18. package/entity/BaseEntity.js +0 -3
  19. package/entity/Collection.d.ts +101 -29
  20. package/entity/Collection.js +473 -115
  21. package/entity/EntityAssigner.js +37 -25
  22. package/entity/EntityFactory.d.ts +7 -1
  23. package/entity/EntityFactory.js +116 -64
  24. package/entity/EntityHelper.d.ts +2 -2
  25. package/entity/EntityHelper.js +69 -27
  26. package/entity/EntityLoader.d.ts +11 -10
  27. package/entity/EntityLoader.js +264 -102
  28. package/entity/EntityRepository.d.ts +28 -8
  29. package/entity/EntityRepository.js +8 -2
  30. package/entity/PolymorphicRef.d.ts +12 -0
  31. package/entity/PolymorphicRef.js +18 -0
  32. package/entity/Reference.d.ts +2 -6
  33. package/entity/Reference.js +52 -19
  34. package/entity/WrappedEntity.d.ts +3 -8
  35. package/entity/WrappedEntity.js +6 -7
  36. package/entity/defineEntity.d.ts +525 -311
  37. package/entity/defineEntity.js +134 -290
  38. package/entity/index.d.ts +2 -2
  39. package/entity/index.js +2 -2
  40. package/entity/utils.d.ts +6 -1
  41. package/entity/utils.js +46 -11
  42. package/entity/validators.d.ts +11 -0
  43. package/entity/validators.js +66 -0
  44. package/enums.d.ts +8 -6
  45. package/enums.js +13 -17
  46. package/errors.d.ts +20 -10
  47. package/errors.js +63 -31
  48. package/events/EventManager.d.ts +2 -1
  49. package/events/EventManager.js +24 -13
  50. package/events/index.d.ts +1 -1
  51. package/events/index.js +0 -1
  52. package/exceptions.js +9 -2
  53. package/hydration/Hydrator.js +1 -2
  54. package/hydration/ObjectHydrator.d.ts +4 -4
  55. package/hydration/ObjectHydrator.js +105 -46
  56. package/index.d.ts +2 -2
  57. package/index.js +1 -2
  58. package/logging/DefaultLogger.d.ts +1 -1
  59. package/logging/DefaultLogger.js +3 -4
  60. package/logging/SimpleLogger.d.ts +1 -1
  61. package/logging/colors.d.ts +1 -1
  62. package/logging/colors.js +5 -7
  63. package/logging/index.d.ts +2 -1
  64. package/logging/index.js +1 -1
  65. package/logging/inspect.d.ts +2 -0
  66. package/logging/inspect.js +11 -0
  67. package/metadata/EntitySchema.d.ts +47 -23
  68. package/metadata/EntitySchema.js +103 -34
  69. package/metadata/MetadataDiscovery.d.ts +64 -9
  70. package/metadata/MetadataDiscovery.js +867 -354
  71. package/metadata/MetadataProvider.d.ts +11 -2
  72. package/metadata/MetadataProvider.js +71 -2
  73. package/metadata/MetadataStorage.d.ts +13 -11
  74. package/metadata/MetadataStorage.js +72 -41
  75. package/metadata/MetadataValidator.d.ts +32 -9
  76. package/metadata/MetadataValidator.js +214 -44
  77. package/metadata/discover-entities.d.ts +5 -0
  78. package/metadata/discover-entities.js +40 -0
  79. package/metadata/index.d.ts +1 -1
  80. package/metadata/index.js +0 -1
  81. package/metadata/types.d.ts +577 -0
  82. package/metadata/types.js +1 -0
  83. package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
  84. package/naming-strategy/AbstractNamingStrategy.js +26 -5
  85. package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
  86. package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
  87. package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
  88. package/naming-strategy/MongoNamingStrategy.js +6 -6
  89. package/naming-strategy/NamingStrategy.d.ts +28 -4
  90. package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
  91. package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
  92. package/naming-strategy/index.d.ts +1 -1
  93. package/naming-strategy/index.js +0 -1
  94. package/not-supported.d.ts +2 -0
  95. package/not-supported.js +8 -0
  96. package/package.json +47 -36
  97. package/platforms/ExceptionConverter.js +1 -1
  98. package/platforms/Platform.d.ts +33 -15
  99. package/platforms/Platform.js +125 -69
  100. package/serialization/EntitySerializer.d.ts +6 -3
  101. package/serialization/EntitySerializer.js +53 -29
  102. package/serialization/EntityTransformer.js +33 -21
  103. package/serialization/SerializationContext.d.ts +6 -6
  104. package/serialization/SerializationContext.js +4 -4
  105. package/types/ArrayType.d.ts +1 -1
  106. package/types/ArrayType.js +2 -3
  107. package/types/BigIntType.js +1 -1
  108. package/types/BlobType.d.ts +0 -1
  109. package/types/BlobType.js +0 -3
  110. package/types/BooleanType.d.ts +1 -0
  111. package/types/BooleanType.js +3 -0
  112. package/types/DecimalType.js +2 -2
  113. package/types/DoubleType.js +1 -1
  114. package/types/EnumArrayType.js +1 -2
  115. package/types/JsonType.d.ts +1 -1
  116. package/types/JsonType.js +7 -2
  117. package/types/TinyIntType.js +1 -1
  118. package/types/Type.d.ts +2 -4
  119. package/types/Type.js +3 -3
  120. package/types/Uint8ArrayType.d.ts +0 -1
  121. package/types/Uint8ArrayType.js +1 -4
  122. package/types/UuidType.d.ts +2 -0
  123. package/types/UuidType.js +14 -2
  124. package/types/index.d.ts +3 -2
  125. package/typings.d.ts +427 -170
  126. package/typings.js +100 -45
  127. package/unit-of-work/ChangeSet.d.ts +4 -6
  128. package/unit-of-work/ChangeSet.js +8 -9
  129. package/unit-of-work/ChangeSetComputer.d.ts +3 -8
  130. package/unit-of-work/ChangeSetComputer.js +49 -26
  131. package/unit-of-work/ChangeSetPersister.d.ts +13 -12
  132. package/unit-of-work/ChangeSetPersister.js +107 -44
  133. package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
  134. package/unit-of-work/CommitOrderCalculator.js +17 -15
  135. package/unit-of-work/IdentityMap.d.ts +12 -0
  136. package/unit-of-work/IdentityMap.js +39 -1
  137. package/unit-of-work/UnitOfWork.d.ts +34 -4
  138. package/unit-of-work/UnitOfWork.js +294 -107
  139. package/utils/AbstractMigrator.d.ts +101 -0
  140. package/utils/AbstractMigrator.js +303 -0
  141. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  142. package/utils/AbstractSchemaGenerator.js +30 -18
  143. package/utils/AsyncContext.d.ts +6 -0
  144. package/utils/AsyncContext.js +42 -0
  145. package/utils/Configuration.d.ts +796 -211
  146. package/utils/Configuration.js +160 -197
  147. package/utils/ConfigurationLoader.d.ts +1 -52
  148. package/utils/ConfigurationLoader.js +1 -330
  149. package/utils/Cursor.d.ts +0 -3
  150. package/utils/Cursor.js +29 -14
  151. package/utils/DataloaderUtils.d.ts +10 -5
  152. package/utils/DataloaderUtils.js +42 -22
  153. package/utils/EntityComparator.d.ts +16 -9
  154. package/utils/EntityComparator.js +202 -96
  155. package/utils/QueryHelper.d.ts +34 -7
  156. package/utils/QueryHelper.js +183 -72
  157. package/utils/RawQueryFragment.d.ts +28 -34
  158. package/utils/RawQueryFragment.js +37 -72
  159. package/utils/RequestContext.js +2 -2
  160. package/utils/TransactionContext.js +2 -2
  161. package/utils/TransactionManager.js +11 -7
  162. package/utils/Utils.d.ts +16 -127
  163. package/utils/Utils.js +106 -401
  164. package/utils/clone.js +13 -23
  165. package/utils/env-vars.d.ts +7 -0
  166. package/utils/env-vars.js +98 -0
  167. package/utils/fs-utils.d.ts +34 -0
  168. package/utils/fs-utils.js +193 -0
  169. package/utils/index.d.ts +1 -3
  170. package/utils/index.js +1 -3
  171. package/utils/upsert-utils.d.ts +9 -4
  172. package/utils/upsert-utils.js +51 -5
  173. package/decorators/Check.d.ts +0 -3
  174. package/decorators/Check.js +0 -13
  175. package/decorators/CreateRequestContext.d.ts +0 -3
  176. package/decorators/CreateRequestContext.js +0 -32
  177. package/decorators/Embeddable.d.ts +0 -8
  178. package/decorators/Embeddable.js +0 -11
  179. package/decorators/Embedded.d.ts +0 -12
  180. package/decorators/Embedded.js +0 -18
  181. package/decorators/Entity.d.ts +0 -33
  182. package/decorators/Entity.js +0 -12
  183. package/decorators/Enum.d.ts +0 -9
  184. package/decorators/Enum.js +0 -16
  185. package/decorators/Filter.d.ts +0 -2
  186. package/decorators/Filter.js +0 -8
  187. package/decorators/Formula.d.ts +0 -4
  188. package/decorators/Formula.js +0 -15
  189. package/decorators/Indexed.d.ts +0 -19
  190. package/decorators/Indexed.js +0 -20
  191. package/decorators/ManyToMany.d.ts +0 -42
  192. package/decorators/ManyToMany.js +0 -14
  193. package/decorators/ManyToOne.d.ts +0 -34
  194. package/decorators/ManyToOne.js +0 -14
  195. package/decorators/OneToMany.d.ts +0 -28
  196. package/decorators/OneToMany.js +0 -17
  197. package/decorators/OneToOne.d.ts +0 -28
  198. package/decorators/OneToOne.js +0 -7
  199. package/decorators/PrimaryKey.d.ts +0 -8
  200. package/decorators/PrimaryKey.js +0 -20
  201. package/decorators/Property.d.ts +0 -250
  202. package/decorators/Property.js +0 -32
  203. package/decorators/Transactional.d.ts +0 -14
  204. package/decorators/Transactional.js +0 -28
  205. package/decorators/hooks.d.ts +0 -16
  206. package/decorators/hooks.js +0 -47
  207. package/decorators/index.d.ts +0 -17
  208. package/decorators/index.js +0 -17
  209. package/entity/ArrayCollection.d.ts +0 -118
  210. package/entity/ArrayCollection.js +0 -407
  211. package/entity/EntityValidator.d.ts +0 -19
  212. package/entity/EntityValidator.js +0 -150
  213. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  214. package/metadata/ReflectMetadataProvider.js +0 -44
  215. package/utils/resolveContextProvider.d.ts +0 -10
  216. package/utils/resolveContextProvider.js +0 -28
@@ -1,17 +1,25 @@
1
1
  import { types } from '../types/index.js';
2
2
  import { EntitySchema } from '../metadata/EntitySchema.js';
3
+ // Parameter-level sync assertion lives in tests/defineEntity.test.ts to avoid
4
+ // instantiating the full builder class in production builds (~680 instantiations).
3
5
  /** @internal */
4
- export class PropertyOptionsBuilder {
6
+ export class UniversalPropertyOptionsBuilder {
5
7
  '~options';
6
8
  '~type';
7
9
  constructor(options) {
8
10
  this['~options'] = options;
9
11
  }
12
+ assignOptions(options) {
13
+ return new UniversalPropertyOptionsBuilder({ ...this['~options'], ...options });
14
+ }
15
+ $type() {
16
+ return this.assignOptions({});
17
+ }
10
18
  /**
11
19
  * Alias for `fieldName`.
12
20
  */
13
21
  name(name) {
14
- return new PropertyOptionsBuilder({ ...this['~options'], name });
22
+ return this.assignOptions({ name });
15
23
  }
16
24
  /**
17
25
  * Specify database column name for this property.
@@ -19,7 +27,7 @@ export class PropertyOptionsBuilder {
19
27
  * @see https://mikro-orm.io/docs/naming-strategy
20
28
  */
21
29
  fieldName(fieldName) {
22
- return new PropertyOptionsBuilder({ ...this['~options'], fieldName });
30
+ return this.assignOptions({ fieldName });
23
31
  }
24
32
  /**
25
33
  * Specify database column names for this property.
@@ -28,19 +36,19 @@ export class PropertyOptionsBuilder {
28
36
  * @see https://mikro-orm.io/docs/naming-strategy
29
37
  */
30
38
  fieldNames(...fieldNames) {
31
- return new PropertyOptionsBuilder({ ...this['~options'], fieldNames });
39
+ return this.assignOptions({ fieldNames });
32
40
  }
33
41
  /**
34
42
  * 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)
35
43
  */
36
44
  columnType(columnType) {
37
- return new PropertyOptionsBuilder({ ...this['~options'], columnType });
45
+ return this.assignOptions({ columnType });
38
46
  }
39
47
  /**
40
48
  * 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)
41
49
  */
42
50
  columnTypes(...columnTypes) {
43
- return new PropertyOptionsBuilder({ ...this['~options'], columnTypes });
51
+ return this.assignOptions({ columnTypes });
44
52
  }
45
53
  /**
46
54
  * Explicitly specify the runtime type.
@@ -49,72 +57,73 @@ export class PropertyOptionsBuilder {
49
57
  * @see https://mikro-orm.io/docs/custom-types
50
58
  */
51
59
  type(type) {
52
- return new PropertyOptionsBuilder({ ...this['~options'], type });
60
+ return this.assignOptions({ type });
53
61
  }
54
62
  /**
55
63
  * 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`.
56
64
  * 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`.
57
65
  */
58
66
  runtimeType(runtimeType) {
59
- return new PropertyOptionsBuilder({ ...this['~options'], runtimeType });
67
+ return this.assignOptions({ runtimeType });
60
68
  }
61
69
  /**
62
70
  * 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)
63
71
  */
64
72
  length(length) {
65
- return new PropertyOptionsBuilder({ ...this['~options'], length });
73
+ return this.assignOptions({ length });
66
74
  }
67
75
  /**
68
76
  * Set precision of database column to represent the number of significant digits. (SQL only)
69
77
  */
70
78
  precision(precision) {
71
- return new PropertyOptionsBuilder({ ...this['~options'], precision });
79
+ return this.assignOptions({ precision });
72
80
  }
73
81
  /**
74
82
  * Set scale of database column to represents the number of digits after the decimal point. (SQL only)
75
83
  */
76
84
  scale(scale) {
77
- return new PropertyOptionsBuilder({ ...this['~options'], scale });
85
+ return this.assignOptions({ scale });
78
86
  }
79
- /**
80
- * Explicitly specify the auto increment of the primary key.
81
- */
82
87
  autoincrement(autoincrement = true) {
83
- return new PropertyOptionsBuilder({ ...this['~options'], autoincrement });
88
+ return this.assignOptions({ autoincrement });
84
89
  }
85
90
  /**
86
91
  * Add the property to the `returning` statement.
87
92
  */
88
93
  returning(returning = true) {
89
- return new PropertyOptionsBuilder({ ...this['~options'], returning });
94
+ return this.assignOptions({ returning });
90
95
  }
91
96
  /**
92
97
  * Automatically set the property value when entity gets created, executed during flush operation.
93
- * @param entity
94
98
  */
95
99
  onCreate(onCreate) {
96
- return new PropertyOptionsBuilder({ ...this['~options'], onCreate });
100
+ return this.assignOptions({ onCreate });
97
101
  }
98
102
  /**
99
103
  * Automatically update the property value every time entity gets updated, executed during flush operation.
100
- * @param entity
101
104
  */
102
105
  onUpdate(onUpdate) {
103
- return new PropertyOptionsBuilder({ ...this['~options'], onUpdate });
106
+ return this.assignOptions({ onUpdate });
104
107
  }
105
108
  /**
106
109
  * Specify default column value for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
107
110
  * This is a runtime value, assignable to the entity property. (SQL only)
108
111
  */
109
112
  default(defaultValue) {
110
- return new PropertyOptionsBuilder({ ...this['~options'], default: defaultValue });
113
+ return this.assignOptions({ default: defaultValue });
111
114
  }
112
115
  /**
113
116
  * Specify SQL functions for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
114
117
  * Since v4 you should use defaultRaw for SQL functions. e.g. now()
115
118
  */
116
119
  defaultRaw(defaultRaw) {
117
- return new PropertyOptionsBuilder({ ...this['~options'], defaultRaw });
120
+ return this.assignOptions({ defaultRaw });
121
+ }
122
+ /**
123
+ * Allow controlling `filters` option. This will be overridden with `em.fork` or `FindOptions` if provided.
124
+ */
125
+ filters(filters) {
126
+ return this.assignOptions({ filters });
118
127
  }
119
128
  /**
120
129
  * Set to map some SQL snippet for the entity.
@@ -122,81 +131,70 @@ export class PropertyOptionsBuilder {
122
131
  * @see https://mikro-orm.io/docs/defining-entities#formulas Formulas
123
132
  */
124
133
  formula(formula) {
125
- return new PropertyOptionsBuilder({ ...this['~options'], formula });
134
+ return this.assignOptions({ formula });
126
135
  }
127
136
  /**
128
137
  * For generated columns. This will be appended to the column type after the `generated always` clause.
129
138
  */
130
139
  generated(generated) {
131
- return new PropertyOptionsBuilder({ ...this['~options'], generated });
140
+ return this.assignOptions({ generated });
132
141
  }
133
142
  /**
134
143
  * Set column as nullable for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
135
144
  */
136
- nullable(nullable = true) {
137
- return new PropertyOptionsBuilder({ ...this['~options'], nullable });
145
+ nullable() {
146
+ return this.assignOptions({ nullable: true });
138
147
  }
139
148
  /**
140
149
  * Set column as unsigned for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
141
150
  */
142
151
  unsigned(unsigned = true) {
143
- return new PropertyOptionsBuilder({ ...this['~options'], unsigned });
152
+ return this.assignOptions({ unsigned });
144
153
  }
145
- /**
146
- * Set false to define {@link https://mikro-orm.io/docs/serializing#shadow-properties Shadow Property}.
147
- */
148
154
  persist(persist = true) {
149
- return new PropertyOptionsBuilder({ ...this['~options'], persist });
155
+ return this.assignOptions({ persist });
150
156
  }
151
157
  /**
152
158
  * Set false to disable hydration of this property. Useful for persisted getters.
153
159
  */
154
160
  hydrate(hydrate = true) {
155
- return new PropertyOptionsBuilder({ ...this['~options'], hydrate });
161
+ return this.assignOptions({ hydrate });
156
162
  }
157
163
  /**
158
164
  * 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.
159
165
  */
160
- ref(ref = true) {
161
- return new PropertyOptionsBuilder({ ...this['~options'], ref });
162
- }
163
- /**
164
- * Set false to disable change tracking on a property level.
165
- *
166
- * @see https://mikro-orm.io/docs/unit-of-work#change-tracking-and-performance-considerations
167
- */
168
- trackChanges(trackChanges = true) {
169
- return new PropertyOptionsBuilder({ ...this['~options'], trackChanges });
166
+ ref() {
167
+ return this.assignOptions({ ref: true });
170
168
  }
171
169
  /**
172
170
  * Set to true to omit the property when {@link https://mikro-orm.io/docs/serializing Serializing}.
173
171
  */
174
- hidden(hidden = true) {
175
- return new PropertyOptionsBuilder({ ...this['~options'], hidden });
172
+ hidden() {
173
+ return this.assignOptions({ hidden: true });
176
174
  }
177
175
  /**
178
176
  * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via version field. (SQL only)
179
177
  */
180
- version(version = true) {
181
- return new PropertyOptionsBuilder({ ...this['~options'], version });
178
+ version() {
179
+ return this.assignOptions({ version: true });
182
180
  }
183
181
  /**
184
182
  * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via concurrency fields.
185
183
  */
186
184
  concurrencyCheck(concurrencyCheck = true) {
187
- return new PropertyOptionsBuilder({ ...this['~options'], concurrencyCheck });
185
+ return this.assignOptions({ concurrencyCheck });
188
186
  }
189
187
  /**
190
188
  * Explicitly specify index on a property.
191
189
  */
192
190
  index(index = true) {
193
- return new PropertyOptionsBuilder({ ...this['~options'], index });
191
+ return this.assignOptions({ index });
194
192
  }
195
193
  /**
196
194
  * Set column as unique for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
197
195
  */
198
196
  unique(unique = true) {
199
- return new PropertyOptionsBuilder({ ...this['~options'], unique });
197
+ return this.assignOptions({ unique });
200
198
  }
201
199
  /**
202
200
  * Specify column with check constraints. (Postgres driver only)
@@ -204,23 +202,23 @@ export class PropertyOptionsBuilder {
204
202
  * @see https://mikro-orm.io/docs/defining-entities#check-constraints
205
203
  */
206
204
  check(check) {
207
- return new PropertyOptionsBuilder({ ...this['~options'], check });
205
+ return this.assignOptions({ check });
208
206
  }
209
207
  /**
210
208
  * Set to omit the property from the select clause for lazy loading.
211
209
  *
212
210
  * @see https://mikro-orm.io/docs/defining-entities#lazy-scalar-properties
213
211
  */
214
- lazy(lazy = true, ref = true) {
215
- return new PropertyOptionsBuilder({ ...this['~options'], lazy, ref });
212
+ lazy() {
213
+ return this.assignOptions({ lazy: true });
216
214
  }
217
215
  /**
218
216
  * Set true to define entity's unique primary key identifier.
219
217
  *
220
218
  * @see https://mikro-orm.io/docs/decorators#primarykey
221
219
  */
222
- primary(primary = true) {
223
- return new PropertyOptionsBuilder({ ...this['~options'], primary });
220
+ primary() {
221
+ return this.assignOptions({ primary: true });
224
222
  }
225
223
  /**
226
224
  * Set true to define the properties as setter. (virtual)
@@ -234,7 +232,7 @@ export class PropertyOptionsBuilder {
234
232
  * ```
235
233
  */
236
234
  setter(setter = true) {
237
- return new PropertyOptionsBuilder({ ...this['~options'], setter });
235
+ return this.assignOptions({ setter });
238
236
  }
239
237
  /**
240
238
  * Set true to define the properties as getter. (virtual)
@@ -248,7 +246,7 @@ export class PropertyOptionsBuilder {
248
246
  * ```
249
247
  */
250
248
  getter(getter = true) {
251
- return new PropertyOptionsBuilder({ ...this['~options'], getter });
249
+ return this.assignOptions({ getter });
252
250
  }
253
251
  /**
254
252
  * When defining a property over a method (not a getter, a regular function), you can use this option to point
@@ -263,7 +261,7 @@ export class PropertyOptionsBuilder {
263
261
  * ```
264
262
  */
265
263
  getterName(getterName) {
266
- return new PropertyOptionsBuilder({ ...this['~options'], getterName });
264
+ return this.assignOptions({ getterName });
267
265
  }
268
266
  /**
269
267
  * Set to define serialized primary key for MongoDB. (virtual)
@@ -272,7 +270,7 @@ export class PropertyOptionsBuilder {
272
270
  * @see https://mikro-orm.io/docs/decorators#serializedprimarykey
273
271
  */
274
272
  serializedPrimaryKey(serializedPrimaryKey = true) {
275
- return new PropertyOptionsBuilder({ ...this['~options'], serializedPrimaryKey });
273
+ return this.assignOptions({ serializedPrimaryKey });
276
274
  }
277
275
  /**
278
276
  * Set to use serialize property. Allow to specify a callback that will be used when serializing a property.
@@ -280,36 +278,36 @@ export class PropertyOptionsBuilder {
280
278
  * @see https://mikro-orm.io/docs/serializing#property-serializers
281
279
  */
282
280
  serializer(serializer) {
283
- return new PropertyOptionsBuilder({ ...this['~options'], serializer });
281
+ return this.assignOptions({ serializer });
284
282
  }
285
283
  /**
286
284
  * Specify name of key for the serialized value.
287
285
  */
288
286
  serializedName(serializedName) {
289
- return new PropertyOptionsBuilder({ ...this['~options'], serializedName });
287
+ return this.assignOptions({ serializedName });
290
288
  }
291
289
  /**
292
290
  * Specify serialization groups for `serialize()` calls. If a property does not specify any group, it will be included,
293
291
  * otherwise only properties with a matching group are included.
294
292
  */
295
293
  groups(...groups) {
296
- return new PropertyOptionsBuilder({ ...this['~options'], groups });
294
+ return this.assignOptions({ groups });
297
295
  }
298
296
  /**
299
297
  * Specify a custom order based on the values. (SQL only)
300
298
  */
301
299
  customOrder(...customOrder) {
302
- return new PropertyOptionsBuilder({ ...this['~options'], customOrder });
300
+ return this.assignOptions({ customOrder });
303
301
  }
304
302
  /**
305
303
  * Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
306
304
  */
307
305
  comment(comment) {
308
- return new PropertyOptionsBuilder({ ...this['~options'], comment });
306
+ return this.assignOptions({ comment });
309
307
  }
310
308
  /** mysql only */
311
309
  extra(extra) {
312
- return new PropertyOptionsBuilder({ ...this['~options'], extra });
310
+ return this.assignOptions({ extra });
313
311
  }
314
312
  /**
315
313
  * Set to avoid a perpetual diff from the {@link https://mikro-orm.io/docs/schema-generator Schema Generator} when columns are generated.
@@ -317,342 +315,187 @@ export class PropertyOptionsBuilder {
317
315
  * @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
318
316
  */
319
317
  ignoreSchemaChanges(...ignoreSchemaChanges) {
320
- return new PropertyOptionsBuilder({ ...this['~options'], ignoreSchemaChanges });
318
+ return this.assignOptions({ ignoreSchemaChanges });
321
319
  }
322
- $type() {
323
- return new PropertyOptionsBuilder({ ...this['~options'] });
324
- }
325
- }
326
- /** @internal */
327
- export class EnumOptionsBuilder extends PropertyOptionsBuilder {
328
- constructor(options) {
329
- super(options);
330
- this['~options'] = options;
331
- }
332
- array(array = true) {
333
- return new EnumOptionsBuilder({ ...this['~options'], array });
320
+ array() {
321
+ return this.assignOptions({ array: true });
334
322
  }
335
323
  /** for postgres, by default it uses text column with check constraint */
336
324
  nativeEnumName(nativeEnumName) {
337
- return new EnumOptionsBuilder({ ...this['~options'], nativeEnumName });
338
- }
339
- }
340
- /** @internal */
341
- export class EmbeddedOptionsBuilder extends PropertyOptionsBuilder {
342
- constructor(options) {
343
- super(options);
344
- this['~options'] = options;
325
+ return this.assignOptions({ nativeEnumName });
345
326
  }
346
327
  prefix(prefix) {
347
- return new EmbeddedOptionsBuilder({ ...this['~options'], prefix });
328
+ return this.assignOptions({ prefix });
348
329
  }
349
330
  prefixMode(prefixMode) {
350
- return new EmbeddedOptionsBuilder({ ...this['~options'], prefixMode });
331
+ return this.assignOptions({ prefixMode });
351
332
  }
352
333
  object(object = true) {
353
- return new EmbeddedOptionsBuilder({ ...this['~options'], object });
354
- }
355
- array(array = true) {
356
- return new EmbeddedOptionsBuilder({ ...this['~options'], array });
357
- }
358
- }
359
- /** @internal */
360
- export class ReferenceOptionsBuilder extends PropertyOptionsBuilder {
361
- constructor(options) {
362
- super(options);
363
- this['~options'] = options;
334
+ return this.assignOptions({ object });
364
335
  }
365
336
  /** Set what actions on owning entity should be cascaded to the relationship. Defaults to [Cascade.PERSIST, Cascade.MERGE] (see {@doclink cascading}). */
366
337
  cascade(...cascade) {
367
- return new ReferenceOptionsBuilder({ ...this['~options'], cascade });
338
+ return this.assignOptions({ cascade });
368
339
  }
369
340
  /** Always load the relationship. Discouraged for use with to-many relations for performance reasons. */
370
341
  eager(eager = true) {
371
- return new ReferenceOptionsBuilder({ ...this['~options'], eager });
342
+ return this.assignOptions({ eager });
372
343
  }
373
344
  /** Override the default loading strategy for this property. This option has precedence over the global `loadStrategy`, but can be overridden by `FindOptions.strategy`. */
374
345
  strategy(strategy) {
375
- return new ReferenceOptionsBuilder({ ...this['~options'], strategy });
346
+ return this.assignOptions({ strategy });
376
347
  }
377
- /**
378
- * @internal
379
- * re-declare to override type inference
380
- */
381
- /* v8 ignore next 3 */
382
- ref(ref = true) {
383
- return new ReferenceOptionsBuilder({ ...this['~options'], ref });
384
- }
385
- /**
386
- * @internal
387
- * re-declare to override type inference
388
- */
389
- /* v8 ignore next 3 */
390
- primary(primary = true) {
391
- return new ReferenceOptionsBuilder({ ...this['~options'], primary });
348
+ /** 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. */
349
+ owner() {
350
+ return this.assignOptions({ owner: true });
392
351
  }
393
- }
394
- /** @internal */
395
- export class ManyToManyOptionsBuilder extends ReferenceOptionsBuilder {
396
- constructor(options) {
397
- super(options);
398
- this['~options'] = options;
352
+ /** For polymorphic relations. Specifies the property name that stores the entity type discriminator. Defaults to the property name. */
353
+ discriminator(discriminator) {
354
+ return this.assignOptions({ discriminator });
399
355
  }
400
- /** 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. */
401
- owner(owner = true) {
402
- return new ManyToManyOptionsBuilder({ ...this['~options'], owner });
356
+ /** For polymorphic relations. Custom mapping of discriminator values to entity class names. */
357
+ discriminatorMap(discriminatorMap) {
358
+ return this.assignOptions({ discriminatorMap });
403
359
  }
404
360
  /** Point to the inverse side property name. */
405
361
  inversedBy(inversedBy) {
406
- return new ManyToManyOptionsBuilder({ ...this['~options'], inversedBy });
362
+ return this.assignOptions({ inversedBy });
407
363
  }
408
364
  /** Point to the owning side property name. */
409
365
  mappedBy(mappedBy) {
410
- return new ManyToManyOptionsBuilder({ ...this['~options'], mappedBy });
366
+ return this.assignOptions({ mappedBy });
411
367
  }
412
368
  /** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
413
369
  where(...where) {
414
- return new ManyToManyOptionsBuilder({ ...this['~options'], where: where });
370
+ return this.assignOptions({ where });
415
371
  }
416
372
  /** Set default ordering. */
417
373
  orderBy(...orderBy) {
418
- return new ManyToManyOptionsBuilder({ ...this['~options'], orderBy });
374
+ return this.assignOptions({ orderBy });
419
375
  }
420
376
  /** Force stable insertion order of items in the collection (see {@doclink collections | Collections}). */
421
377
  fixedOrder(fixedOrder = true) {
422
- return new ManyToManyOptionsBuilder({ ...this['~options'], fixedOrder });
378
+ return this.assignOptions({ fixedOrder });
423
379
  }
424
380
  /** Override default order column name (`id`) for fixed ordering. */
425
381
  fixedOrderColumn(fixedOrderColumn) {
426
- return new ManyToManyOptionsBuilder({ ...this['~options'], fixedOrderColumn });
382
+ return this.assignOptions({ fixedOrderColumn });
427
383
  }
428
384
  /** Override default name for pivot table (see {@doclink naming-strategy | Naming Strategy}). */
429
385
  pivotTable(pivotTable) {
430
- return new ManyToManyOptionsBuilder({ ...this['~options'], pivotTable });
386
+ return this.assignOptions({ pivotTable });
431
387
  }
432
388
  /** Set pivot entity for this relation (see {@doclink collections#custom-pivot-table-entity | Custom pivot table entity}). */
433
389
  pivotEntity(pivotEntity) {
434
- return new ManyToManyOptionsBuilder({ ...this['~options'], pivotEntity });
390
+ return this.assignOptions({ pivotEntity });
435
391
  }
436
392
  /** 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. */
437
393
  joinColumn(joinColumn) {
438
- return new ManyToManyOptionsBuilder({ ...this['~options'], joinColumn });
394
+ return this.assignOptions({ joinColumn });
439
395
  }
440
396
  /** 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. */
441
397
  joinColumns(...joinColumns) {
442
- return new ManyToManyOptionsBuilder({ ...this['~options'], joinColumns });
398
+ return this.assignOptions({ joinColumns });
443
399
  }
444
400
  /** 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. */
445
401
  inverseJoinColumn(inverseJoinColumn) {
446
- return new ManyToManyOptionsBuilder({ ...this['~options'], inverseJoinColumn });
402
+ return this.assignOptions({ inverseJoinColumn });
447
403
  }
448
404
  /** 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. */
449
405
  inverseJoinColumns(...inverseJoinColumns) {
450
- return new ManyToManyOptionsBuilder({ ...this['~options'], inverseJoinColumns });
406
+ return this.assignOptions({ inverseJoinColumns });
451
407
  }
452
408
  /** 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. */
453
409
  referenceColumnName(referenceColumnName) {
454
- return new ManyToManyOptionsBuilder({ ...this['~options'], referenceColumnName });
410
+ return this.assignOptions({ referenceColumnName });
455
411
  }
456
412
  /** 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. */
457
413
  referencedColumnNames(...referencedColumnNames) {
458
- return new ManyToManyOptionsBuilder({ ...this['~options'], referencedColumnNames });
414
+ return this.assignOptions({ referencedColumnNames });
415
+ }
416
+ /** Specify the property name on the target entity that this FK references instead of the primary key. */
417
+ targetKey(targetKey) {
418
+ return this.assignOptions({ targetKey });
459
419
  }
460
420
  /** What to do when the target entity gets deleted. */
461
421
  deleteRule(deleteRule) {
462
- return new ManyToManyOptionsBuilder({ ...this['~options'], deleteRule });
422
+ return this.assignOptions({ deleteRule });
463
423
  }
464
424
  /** What to do when the reference to the target entity gets updated. */
465
425
  updateRule(updateRule) {
466
- return new ManyToManyOptionsBuilder({ ...this['~options'], updateRule });
467
- }
468
- }
469
- /** @internal */
470
- export class ManyToOneOptionsBuilder extends ReferenceOptionsBuilder {
471
- constructor(options) {
472
- super(options);
473
- this['~options'] = options;
474
- }
475
- /** Point to the inverse side property name. */
476
- inversedBy(inversedBy) {
477
- return new ManyToOneOptionsBuilder({ ...this['~options'], inversedBy });
478
- }
479
- /** Wrap the entity in {@apilink Reference} wrapper. */
480
- ref(ref = true) {
481
- return new ManyToOneOptionsBuilder({ ...this['~options'], ref });
482
- }
483
- /** Use this relation as a primary key. */
484
- primary(primary = true) {
485
- return new ManyToOneOptionsBuilder({ ...this['~options'], primary });
426
+ return this.assignOptions({ updateRule });
486
427
  }
487
428
  /** Map this relation to the primary key value instead of an entity. */
488
- mapToPk(mapToPk = true) {
489
- return new ManyToOneOptionsBuilder({ ...this['~options'], mapToPk });
490
- }
491
- /** 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. */
492
- joinColumn(joinColumn) {
493
- return new ManyToOneOptionsBuilder({ ...this['~options'], joinColumn });
429
+ mapToPk() {
430
+ return this.assignOptions({ mapToPk: true });
494
431
  }
495
- /** 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. */
496
- joinColumns(...joinColumns) {
497
- return new ManyToOneOptionsBuilder({ ...this['~options'], joinColumns });
432
+ /** 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. */
433
+ deferMode(deferMode) {
434
+ return this.assignOptions({ deferMode });
498
435
  }
499
436
  /** 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. */
500
437
  ownColumns(...ownColumns) {
501
- return new ManyToOneOptionsBuilder({ ...this['~options'], ownColumns });
438
+ return this.assignOptions({ ownColumns });
502
439
  }
503
- /** 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. */
504
- referenceColumnName(referenceColumnName) {
505
- return new ManyToOneOptionsBuilder({ ...this['~options'], referenceColumnName });
440
+ /** Enable/disable foreign key constraint creation on this relation */
441
+ createForeignKeyConstraint(createForeignKeyConstraint = true) {
442
+ return this.assignOptions({ createForeignKeyConstraint });
506
443
  }
507
- /** 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. */
508
- referencedColumnNames(...referencedColumnNames) {
509
- return new ManyToOneOptionsBuilder({ ...this['~options'], referencedColumnNames });
510
- }
511
- /** What to do when the target entity gets deleted. */
512
- deleteRule(deleteRule) {
513
- return new ManyToOneOptionsBuilder({ ...this['~options'], deleteRule });
514
- }
515
- /** What to do when the reference to the target entity gets updated. */
516
- updateRule(updateRule) {
517
- return new ManyToOneOptionsBuilder({ ...this['~options'], updateRule });
518
- }
519
- /** 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. */
520
- deferMode(deferMode) {
521
- return new ManyToOneOptionsBuilder({ ...this['~options'], deferMode });
522
- }
523
- }
524
- /** @internal */
525
- export class OneToManyOptionsBuilder extends ReferenceOptionsBuilder {
526
- constructor(options) {
527
- super(options);
528
- this['~options'] = options;
444
+ /** Set a custom foreign key constraint name, overriding NamingStrategy.indexName(). */
445
+ foreignKeyName(foreignKeyName) {
446
+ return this.assignOptions({ foreignKeyName });
529
447
  }
530
448
  /** Remove the entity when it gets disconnected from the relationship (see {@doclink cascading | Cascading}). */
531
449
  orphanRemoval(orphanRemoval = true) {
532
- return new OneToManyOptionsBuilder({ ...this['~options'], orphanRemoval });
533
- }
534
- /** Set default ordering. */
535
- orderBy(orderBy) {
536
- return new OneToManyOptionsBuilder({ ...this['~options'], orderBy });
537
- }
538
- /** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
539
- where(where) {
540
- return new OneToManyOptionsBuilder({ ...this['~options'], where });
541
- }
542
- /** 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. */
543
- joinColumn(joinColumn) {
544
- return new OneToManyOptionsBuilder({ ...this['~options'], joinColumn });
545
- }
546
- /** 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. */
547
- joinColumns(...joinColumns) {
548
- return new OneToManyOptionsBuilder({ ...this['~options'], joinColumns });
549
- }
550
- /** 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. */
551
- inverseJoinColumn(inverseJoinColumn) {
552
- return new OneToManyOptionsBuilder({ ...this['~options'], inverseJoinColumn });
553
- }
554
- /** 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. */
555
- inverseJoinColumns(...inverseJoinColumns) {
556
- return new OneToManyOptionsBuilder({ ...this['~options'], inverseJoinColumns });
557
- }
558
- /** 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. */
559
- referenceColumnName(referenceColumnName) {
560
- return new OneToManyOptionsBuilder({ ...this['~options'], referenceColumnName });
450
+ return this.assignOptions({ orphanRemoval });
561
451
  }
562
- /** 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. */
563
- referencedColumnNames(...referencedColumnNames) {
564
- return new OneToManyOptionsBuilder({ ...this['~options'], referencedColumnNames });
452
+ accessor(accessor = true) {
453
+ return this.assignOptions({ accessor });
565
454
  }
566
455
  }
567
456
  /** @internal */
568
- export class OneToManyOptionsBuilderOnlyMappedBy {
569
- constructor(options) {
570
- this['~options'] = options;
571
- }
457
+ export class OneToManyOptionsBuilderOnlyMappedBy extends UniversalPropertyOptionsBuilder {
572
458
  /** Point to the owning side property name. */
573
459
  mappedBy(mappedBy) {
574
- return new OneToManyOptionsBuilder({ ...this['~options'], mappedBy });
575
- }
576
- }
577
- /** @internal */
578
- export class OneToOneOptionsBuilder extends ReferenceOptionsBuilder {
579
- constructor(options) {
580
- super(options);
581
- this['~options'] = options;
582
- }
583
- /** 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. */
584
- owner(owner = true) {
585
- return new OneToOneOptionsBuilder({ ...this['~options'], owner });
586
- }
587
- /** Point to the inverse side property name. */
588
- inversedBy(inversedBy) {
589
- return new OneToOneOptionsBuilder({ ...this['~options'], inversedBy });
590
- }
591
- /** Wrap the entity in {@apilink Reference} wrapper. */
592
- ref(ref = true) {
593
- return new OneToOneOptionsBuilder({ ...this['~options'], ref });
594
- }
595
- /** Use this relation as a primary key. */
596
- primary(primary = true) {
597
- return new OneToOneOptionsBuilder({ ...this['~options'], primary });
598
- }
599
- /** Map this relation to the primary key value instead of an entity. */
600
- mapToPk(mapToPk = true) {
601
- return new OneToOneOptionsBuilder({ ...this['~options'], mapToPk });
602
- }
603
- /** 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. */
604
- ownColumns(...ownColumns) {
605
- return new OneToOneOptionsBuilder({ ...this['~options'], ownColumns });
606
- }
607
- /** What to do when the target entity gets deleted. */
608
- deleteRule(deleteRule) {
609
- return new OneToOneOptionsBuilder({ ...this['~options'], deleteRule });
610
- }
611
- /** What to do when the reference to the target entity gets updated. */
612
- updateRule(updateRule) {
613
- return new OneToOneOptionsBuilder({ ...this['~options'], updateRule });
614
- }
615
- /** 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. */
616
- deferMode(deferMode) {
617
- return new OneToOneOptionsBuilder({ ...this['~options'], deferMode });
460
+ return new UniversalPropertyOptionsBuilder({ ...this['~options'], mappedBy });
618
461
  }
619
462
  }
620
463
  function createPropertyBuilders(options) {
621
- return Object.fromEntries(Object.entries(options).map(([key, value]) => [key, () => new PropertyOptionsBuilder({ type: value })]));
464
+ return Object.fromEntries(Object.entries(options).map(([key, value]) => [key, () => new UniversalPropertyOptionsBuilder({ type: value })]));
622
465
  }
623
466
  const propertyBuilders = {
624
467
  ...createPropertyBuilders(types),
625
- bigint: (mode) => new PropertyOptionsBuilder({ type: new types.bigint(mode) }),
626
- array: (toJsValue = i => i, toDbValue = i => i) => new PropertyOptionsBuilder({ type: new types.array(toJsValue, toDbValue) }),
627
- decimal: (mode) => new PropertyOptionsBuilder({ type: new types.decimal(mode) }),
628
- json: () => new PropertyOptionsBuilder({ type: types.json }),
629
- formula: (formula) => new PropertyOptionsBuilder({ formula }),
630
- type: (type) => new PropertyOptionsBuilder({ type }),
631
- enum: (items) => new EnumOptionsBuilder({
468
+ bigint: (mode) => new UniversalPropertyOptionsBuilder({ type: new types.bigint(mode) }),
469
+ array: (toJsValue = i => i, toDbValue = i => i) => new UniversalPropertyOptionsBuilder({ type: new types.array(toJsValue, toDbValue) }),
470
+ decimal: (mode) => new UniversalPropertyOptionsBuilder({ type: new types.decimal(mode) }),
471
+ json: () => new UniversalPropertyOptionsBuilder({ type: types.json }),
472
+ formula: (formula) => new UniversalPropertyOptionsBuilder({ formula }),
473
+ datetime: (length) => new UniversalPropertyOptionsBuilder({ type: types.datetime, length }),
474
+ time: (length) => new UniversalPropertyOptionsBuilder({ type: types.time, length }),
475
+ type: (type) => new UniversalPropertyOptionsBuilder({ type }),
476
+ enum: (items) => new UniversalPropertyOptionsBuilder({
632
477
  enum: true,
633
478
  items,
634
479
  }),
635
- embedded: (target) => new EmbeddedOptionsBuilder({
480
+ embedded: (target) => new UniversalPropertyOptionsBuilder({
636
481
  entity: () => target,
637
482
  kind: 'embedded',
638
483
  }),
639
- manyToMany: (target) => new ManyToManyOptionsBuilder({
484
+ manyToMany: (target) => new UniversalPropertyOptionsBuilder({
640
485
  entity: () => target,
641
486
  kind: 'm:n',
642
487
  }),
643
- manyToOne: (target) => new ManyToOneOptionsBuilder({
488
+ manyToOne: (target) => new UniversalPropertyOptionsBuilder({
644
489
  entity: () => target,
645
490
  kind: 'm:1',
646
- ref: true,
647
491
  }),
648
492
  oneToMany: (target) => new OneToManyOptionsBuilderOnlyMappedBy({
649
493
  entity: () => target,
650
494
  kind: '1:m',
651
495
  }),
652
- oneToOne: (target) => new OneToOneOptionsBuilder({
496
+ oneToOne: (target) => new UniversalPropertyOptionsBuilder({
653
497
  entity: () => target,
654
498
  kind: '1:1',
655
- ref: true,
656
499
  }),
657
500
  };
658
501
  function getBuilderOptions(builder) {
@@ -662,8 +505,8 @@ export function defineEntity(meta) {
662
505
  const { properties: propertiesOrGetter, ...options } = meta;
663
506
  const propertyOptions = typeof propertiesOrGetter === 'function' ? propertiesOrGetter(propertyBuilders) : propertiesOrGetter;
664
507
  const properties = {};
508
+ const values = new Map();
665
509
  for (const [key, builder] of Object.entries(propertyOptions)) {
666
- const values = new Map();
667
510
  if (typeof builder === 'function') {
668
511
  Object.defineProperty(properties, key, {
669
512
  get: () => {
@@ -691,3 +534,4 @@ export function defineEntity(meta) {
691
534
  return new EntitySchema({ properties, ...options });
692
535
  }
693
536
  defineEntity.properties = propertyBuilders;
537
+ export { propertyBuilders as p };