@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
@@ -4,550 +4,541 @@ import { EntitySchema } from '../metadata/EntitySchema.js';
4
4
  // instantiating the full builder class in production builds (~680 instantiations).
5
5
  /** @internal */
6
6
  export class UniversalPropertyOptionsBuilder {
7
- '~options';
8
- '~type';
9
- constructor(options) {
10
- this['~options'] = options;
11
- }
12
- assignOptions(options) {
13
- return new UniversalPropertyOptionsBuilder({ ...this['~options'], ...options });
14
- }
15
- $type() {
16
- return this.assignOptions({});
17
- }
18
- /**
19
- * Alias for `fieldName`.
20
- */
21
- name(name) {
22
- return this.assignOptions({ name });
23
- }
24
- /**
25
- * Specify database column name for this property.
26
- *
27
- * @see https://mikro-orm.io/docs/naming-strategy
28
- */
29
- fieldName(fieldName) {
30
- return this.assignOptions({ fieldName });
31
- }
32
- /**
33
- * Specify database column names for this property.
34
- * Same as `fieldName` but for composite FKs.
35
- *
36
- * @see https://mikro-orm.io/docs/naming-strategy
37
- */
38
- fieldNames(...fieldNames) {
39
- return this.assignOptions({ fieldNames });
40
- }
41
- /**
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)
43
- */
44
- columnType(columnType) {
45
- return this.assignOptions({ columnType });
46
- }
47
- /**
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)
49
- */
50
- columnTypes(...columnTypes) {
51
- return this.assignOptions({ columnTypes });
52
- }
53
- /**
54
- * Explicitly specify the runtime type.
55
- *
56
- * @see https://mikro-orm.io/docs/metadata-providers
57
- * @see https://mikro-orm.io/docs/custom-types
58
- */
59
- type(type) {
60
- return this.assignOptions({ type });
61
- }
62
- /**
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`.
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`.
65
- */
66
- runtimeType(runtimeType) {
67
- return this.assignOptions({ runtimeType });
68
- }
69
- /**
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)
71
- */
72
- length(length) {
73
- return this.assignOptions({ length });
74
- }
75
- /**
76
- * Set precision of database column to represent the number of significant digits. (SQL only)
77
- */
78
- precision(precision) {
79
- return this.assignOptions({ precision });
80
- }
81
- /**
82
- * Set scale of database column to represents the number of digits after the decimal point. (SQL only)
83
- */
84
- scale(scale) {
85
- return this.assignOptions({ scale });
86
- }
87
- autoincrement(autoincrement = true) {
88
- return this.assignOptions({ autoincrement });
89
- }
90
- /**
91
- * Add the property to the `returning` statement.
92
- */
93
- returning(returning = true) {
94
- return this.assignOptions({ returning });
95
- }
96
- /**
97
- * Automatically set the property value when entity gets created, executed during flush operation.
98
- */
99
- onCreate(onCreate) {
100
- return this.assignOptions({ onCreate });
101
- }
102
- /**
103
- * Automatically update the property value every time entity gets updated, executed during flush operation.
104
- */
105
- onUpdate(onUpdate) {
106
- return this.assignOptions({ onUpdate });
107
- }
108
- /**
109
- * Specify default column value for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
110
- * This is a runtime value, assignable to the entity property. (SQL only)
111
- */
112
- default(defaultValue) {
113
- return this.assignOptions({ default: defaultValue });
114
- }
115
- /**
116
- * Specify SQL functions for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
117
- * Since v4 you should use defaultRaw for SQL functions. e.g. now()
118
- */
119
- defaultRaw(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 });
127
- }
128
- /**
129
- * Set to map some SQL snippet for the entity.
130
- *
131
- * @see https://mikro-orm.io/docs/defining-entities#formulas Formulas
132
- */
133
- formula(formula) {
134
- return this.assignOptions({ formula });
135
- }
136
- /**
137
- * For generated columns. This will be appended to the column type after the `generated always` clause.
138
- */
139
- generated(generated) {
140
- return this.assignOptions({ generated });
141
- }
142
- /**
143
- * Set column as nullable for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
144
- */
145
- nullable() {
146
- return this.assignOptions({ nullable: true });
147
- }
148
- /**
149
- * Set column as nullable without adding `| undefined` to the type.
150
- * Use this when the property is always explicitly set (e.g. in constructor) but can be `null`.
151
- */
152
- strictNullable() {
153
- return this.assignOptions({ nullable: true });
154
- }
155
- /**
156
- * Set column as unsigned for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
157
- */
158
- unsigned(unsigned = true) {
159
- return this.assignOptions({ unsigned });
160
- }
161
- persist(persist = true) {
162
- return this.assignOptions({ persist });
163
- }
164
- /**
165
- * Set false to disable hydration of this property. Useful for persisted getters.
166
- */
167
- hydrate(hydrate = true) {
168
- return this.assignOptions({ hydrate });
169
- }
170
- /**
171
- * 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.
172
- */
173
- ref() {
174
- return this.assignOptions({ ref: true });
175
- }
176
- /**
177
- * Set to true to omit the property when {@link https://mikro-orm.io/docs/serializing Serializing}.
178
- */
179
- hidden() {
180
- return this.assignOptions({ hidden: true });
181
- }
182
- /**
183
- * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via version field. (SQL only)
184
- */
185
- version() {
186
- return this.assignOptions({ version: true });
187
- }
188
- /**
189
- * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via concurrency fields.
190
- */
191
- concurrencyCheck(concurrencyCheck = true) {
192
- return this.assignOptions({ concurrencyCheck });
193
- }
194
- /**
195
- * Explicitly specify index on a property.
196
- */
197
- index(index = true) {
198
- return this.assignOptions({ index });
199
- }
200
- /**
201
- * Set column as unique for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
202
- */
203
- unique(unique = true) {
204
- return this.assignOptions({ unique });
205
- }
206
- /**
207
- * Specify column with check constraints. (Postgres driver only)
208
- *
209
- * @see https://mikro-orm.io/docs/defining-entities#check-constraints
210
- */
211
- check(check) {
212
- return this.assignOptions({ check });
213
- }
214
- /**
215
- * Set to omit the property from the select clause for lazy loading.
216
- *
217
- * @see https://mikro-orm.io/docs/defining-entities#lazy-scalar-properties
218
- */
219
- lazy() {
220
- return this.assignOptions({ lazy: true });
221
- }
222
- /**
223
- * Set true to define entity's unique primary key identifier.
224
- *
225
- * @see https://mikro-orm.io/docs/decorators#primarykey
226
- */
227
- primary() {
228
- return this.assignOptions({ primary: true });
229
- }
230
- /**
231
- * Set true to define the properties as setter. (virtual)
232
- *
233
- * @example
234
- * ```
235
- * @Property({ setter: true })
236
- * set address(value: string) {
237
- * this._address = value.toLocaleLowerCase();
238
- * }
239
- * ```
240
- */
241
- setter(setter = true) {
242
- return this.assignOptions({ setter });
243
- }
244
- /**
245
- * Set true to define the properties as getter. (virtual)
246
- *
247
- * @example
248
- * ```
249
- * @Property({ getter: true })
250
- * get fullName() {
251
- * return this.firstName + this.lastName;
252
- * }
253
- * ```
254
- */
255
- getter(getter = true) {
256
- return this.assignOptions({ getter });
257
- }
258
- /**
259
- * When defining a property over a method (not a getter, a regular function), you can use this option to point
260
- * to the method name.
261
- *
262
- * @example
263
- * ```
264
- * @Property({ getter: true })
265
- * getFullName() {
266
- * return this.firstName + this.lastName;
267
- * }
268
- * ```
269
- */
270
- getterName(getterName) {
271
- return this.assignOptions({ getterName });
272
- }
273
- /**
274
- * Set to define serialized primary key for MongoDB. (virtual)
275
- * Alias for `@SerializedPrimaryKey()` decorator.
276
- *
277
- * @see https://mikro-orm.io/docs/decorators#serializedprimarykey
278
- */
279
- serializedPrimaryKey(serializedPrimaryKey = true) {
280
- return this.assignOptions({ serializedPrimaryKey });
281
- }
282
- /**
283
- * Set to use serialize property. Allow to specify a callback that will be used when serializing a property.
284
- *
285
- * @see https://mikro-orm.io/docs/serializing#property-serializers
286
- */
287
- serializer(serializer) {
288
- return this.assignOptions({ serializer });
289
- }
290
- /**
291
- * Specify name of key for the serialized value.
292
- */
293
- serializedName(serializedName) {
294
- return this.assignOptions({ serializedName });
295
- }
296
- /**
297
- * Specify serialization groups for `serialize()` calls. If a property does not specify any group, it will be included,
298
- * otherwise only properties with a matching group are included.
299
- */
300
- groups(...groups) {
301
- return this.assignOptions({ groups });
302
- }
303
- /**
304
- * Specify a custom order based on the values. (SQL only)
305
- */
306
- customOrder(...customOrder) {
307
- return this.assignOptions({ customOrder });
308
- }
309
- /**
310
- * Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
311
- */
312
- comment(comment) {
313
- return this.assignOptions({ comment });
314
- }
315
- /** mysql only */
316
- extra(extra) {
317
- return this.assignOptions({ extra });
318
- }
319
- /**
320
- * Set to avoid a perpetual diff from the {@link https://mikro-orm.io/docs/schema-generator Schema Generator} when columns are generated.
321
- *
322
- * @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
323
- */
324
- ignoreSchemaChanges(...ignoreSchemaChanges) {
325
- return this.assignOptions({ ignoreSchemaChanges });
326
- }
327
- array() {
328
- return this.assignOptions({ array: true });
329
- }
330
- /** for postgres, by default it uses text column with check constraint */
331
- nativeEnumName(nativeEnumName) {
332
- return this.assignOptions({ nativeEnumName });
333
- }
334
- prefix(prefix) {
335
- return this.assignOptions({ prefix });
336
- }
337
- prefixMode(prefixMode) {
338
- return this.assignOptions({ prefixMode });
339
- }
340
- object(object = true) {
341
- return this.assignOptions({ object });
342
- }
343
- /** Set what actions on owning entity should be cascaded to the relationship. Defaults to [Cascade.PERSIST, Cascade.MERGE] (see {@doclink cascading}). */
344
- cascade(...cascade) {
345
- return this.assignOptions({ cascade });
346
- }
347
- /** Always load the relationship. Discouraged for use with to-many relations for performance reasons. */
348
- eager(eager = true) {
349
- return this.assignOptions({ eager });
350
- }
351
- /** Override the default loading strategy for this property. This option has precedence over the global `loadStrategy`, but can be overridden by `FindOptions.strategy`. */
352
- strategy(strategy) {
353
- return this.assignOptions({ strategy });
354
- }
355
- /** 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. */
356
- owner() {
357
- return this.assignOptions({ owner: true });
358
- }
359
- /** For polymorphic relations. Specifies the property name that stores the entity type discriminator. Defaults to the property name. */
360
- discriminator(discriminator) {
361
- return this.assignOptions({ discriminator });
362
- }
363
- /** For polymorphic relations. Custom mapping of discriminator values to entity class names. */
364
- discriminatorMap(discriminatorMap) {
365
- return this.assignOptions({ discriminatorMap });
366
- }
367
- /** Point to the inverse side property name. */
368
- inversedBy(inversedBy) {
369
- return this.assignOptions({ inversedBy });
370
- }
371
- /** Point to the owning side property name. */
372
- mappedBy(mappedBy) {
373
- return this.assignOptions({ mappedBy });
374
- }
375
- /** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
376
- where(...where) {
377
- return this.assignOptions({ where });
378
- }
379
- /** Set default ordering. */
380
- orderBy(...orderBy) {
381
- return this.assignOptions({ orderBy });
382
- }
383
- /** Force stable insertion order of items in the collection (see {@doclink collections | Collections}). */
384
- fixedOrder(fixedOrder = true) {
385
- return this.assignOptions({ fixedOrder });
386
- }
387
- /** Override default order column name (`id`) for fixed ordering. */
388
- fixedOrderColumn(fixedOrderColumn) {
389
- return this.assignOptions({ fixedOrderColumn });
390
- }
391
- /** Override default name for pivot table (see {@doclink naming-strategy | Naming Strategy}). */
392
- pivotTable(pivotTable) {
393
- return this.assignOptions({ pivotTable });
394
- }
395
- /** Set pivot entity for this relation (see {@doclink collections#custom-pivot-table-entity | Custom pivot table entity}). */
396
- pivotEntity(pivotEntity) {
397
- return this.assignOptions({ pivotEntity });
398
- }
399
- /** 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. */
400
- joinColumn(joinColumn) {
401
- return this.assignOptions({ joinColumn });
402
- }
403
- /** 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. */
404
- joinColumns(...joinColumns) {
405
- return this.assignOptions({ joinColumns });
406
- }
407
- /** 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. */
408
- inverseJoinColumn(inverseJoinColumn) {
409
- return this.assignOptions({ inverseJoinColumn });
410
- }
411
- /** 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. */
412
- inverseJoinColumns(...inverseJoinColumns) {
413
- return this.assignOptions({ inverseJoinColumns });
414
- }
415
- /** 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. */
416
- referenceColumnName(referenceColumnName) {
417
- return this.assignOptions({ referenceColumnName });
418
- }
419
- /** 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. */
420
- referencedColumnNames(...referencedColumnNames) {
421
- return this.assignOptions({ referencedColumnNames });
422
- }
423
- /** Specify the property name on the target entity that this FK references instead of the primary key. */
424
- targetKey(targetKey) {
425
- return this.assignOptions({ targetKey });
426
- }
427
- /** What to do when the target entity gets deleted. */
428
- deleteRule(deleteRule) {
429
- return this.assignOptions({ deleteRule });
430
- }
431
- /** What to do when the reference to the target entity gets updated. */
432
- updateRule(updateRule) {
433
- return this.assignOptions({ updateRule });
434
- }
435
- /** Map this relation to the primary key value instead of an entity. */
436
- mapToPk() {
437
- return this.assignOptions({ mapToPk: true });
438
- }
439
- /** 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. */
440
- deferMode(deferMode) {
441
- return this.assignOptions({ deferMode });
442
- }
443
- /** 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. */
444
- ownColumns(...ownColumns) {
445
- return this.assignOptions({ ownColumns });
446
- }
447
- /** Enable/disable foreign key constraint creation on this relation */
448
- createForeignKeyConstraint(createForeignKeyConstraint = true) {
449
- return this.assignOptions({ createForeignKeyConstraint });
450
- }
451
- /** Set a custom foreign key constraint name, overriding NamingStrategy.indexName(). */
452
- foreignKeyName(foreignKeyName) {
453
- return this.assignOptions({ foreignKeyName });
454
- }
455
- /** Remove the entity when it gets disconnected from the relationship (see {@doclink cascading | Cascading}). */
456
- orphanRemoval(orphanRemoval = true) {
457
- return this.assignOptions({ orphanRemoval });
458
- }
459
- accessor(accessor = true) {
460
- return this.assignOptions({ accessor });
461
- }
7
+ '~options';
8
+ '~type';
9
+ constructor(options) {
10
+ this['~options'] = options;
11
+ }
12
+ assignOptions(options) {
13
+ return new UniversalPropertyOptionsBuilder({ ...this['~options'], ...options });
14
+ }
15
+ $type() {
16
+ return this.assignOptions({});
17
+ }
18
+ /**
19
+ * Alias for `fieldName`.
20
+ */
21
+ name(name) {
22
+ return this.assignOptions({ name });
23
+ }
24
+ /**
25
+ * Specify database column name for this property.
26
+ *
27
+ * @see https://mikro-orm.io/docs/naming-strategy
28
+ */
29
+ fieldName(fieldName) {
30
+ return this.assignOptions({ fieldName });
31
+ }
32
+ /**
33
+ * Specify database column names for this property.
34
+ * Same as `fieldName` but for composite FKs.
35
+ *
36
+ * @see https://mikro-orm.io/docs/naming-strategy
37
+ */
38
+ fieldNames(...fieldNames) {
39
+ return this.assignOptions({ fieldNames });
40
+ }
41
+ /**
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)
43
+ */
44
+ columnType(columnType) {
45
+ return this.assignOptions({ columnType });
46
+ }
47
+ /**
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)
49
+ */
50
+ columnTypes(...columnTypes) {
51
+ return this.assignOptions({ columnTypes });
52
+ }
53
+ /**
54
+ * Explicitly specify the runtime type.
55
+ *
56
+ * @see https://mikro-orm.io/docs/metadata-providers
57
+ * @see https://mikro-orm.io/docs/custom-types
58
+ */
59
+ type(type) {
60
+ return this.assignOptions({ type });
61
+ }
62
+ /**
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`.
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`.
65
+ */
66
+ runtimeType(runtimeType) {
67
+ return this.assignOptions({ runtimeType });
68
+ }
69
+ /**
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)
71
+ */
72
+ length(length) {
73
+ return this.assignOptions({ length });
74
+ }
75
+ /**
76
+ * Set precision of database column to represent the number of significant digits. (SQL only)
77
+ */
78
+ precision(precision) {
79
+ return this.assignOptions({ precision });
80
+ }
81
+ /**
82
+ * Set scale of database column to represents the number of digits after the decimal point. (SQL only)
83
+ */
84
+ scale(scale) {
85
+ return this.assignOptions({ scale });
86
+ }
87
+ autoincrement(autoincrement = true) {
88
+ return this.assignOptions({ autoincrement });
89
+ }
90
+ /**
91
+ * Add the property to the `returning` statement.
92
+ */
93
+ returning(returning = true) {
94
+ return this.assignOptions({ returning });
95
+ }
96
+ /**
97
+ * Automatically set the property value when entity gets created, executed during flush operation.
98
+ */
99
+ onCreate(onCreate) {
100
+ return this.assignOptions({ onCreate });
101
+ }
102
+ /**
103
+ * Automatically update the property value every time entity gets updated, executed during flush operation.
104
+ */
105
+ onUpdate(onUpdate) {
106
+ return this.assignOptions({ onUpdate });
107
+ }
108
+ /**
109
+ * Specify default column value for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
110
+ * This is a runtime value, assignable to the entity property. (SQL only)
111
+ */
112
+ default(defaultValue) {
113
+ return this.assignOptions({ default: defaultValue });
114
+ }
115
+ /**
116
+ * Specify SQL functions for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
117
+ * Since v4 you should use defaultRaw for SQL functions. e.g. now()
118
+ */
119
+ defaultRaw(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 });
127
+ }
128
+ /**
129
+ * Set to map some SQL snippet for the entity.
130
+ *
131
+ * @see https://mikro-orm.io/docs/defining-entities#formulas Formulas
132
+ */
133
+ formula(formula) {
134
+ return this.assignOptions({ formula });
135
+ }
136
+ /**
137
+ * For generated columns. This will be appended to the column type after the `generated always` clause.
138
+ */
139
+ generated(generated) {
140
+ return this.assignOptions({ generated });
141
+ }
142
+ /**
143
+ * Set column as nullable for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
144
+ */
145
+ nullable() {
146
+ return this.assignOptions({ nullable: true });
147
+ }
148
+ /**
149
+ * Set column as nullable without adding `| undefined` to the type.
150
+ * Use this when the property is always explicitly set (e.g. in constructor) but can be `null`.
151
+ */
152
+ strictNullable() {
153
+ return this.assignOptions({ nullable: true });
154
+ }
155
+ /**
156
+ * Set column as unsigned for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
157
+ */
158
+ unsigned(unsigned = true) {
159
+ return this.assignOptions({ unsigned });
160
+ }
161
+ persist(persist = true) {
162
+ return this.assignOptions({ persist });
163
+ }
164
+ /**
165
+ * Set false to disable hydration of this property. Useful for persisted getters.
166
+ */
167
+ hydrate(hydrate = true) {
168
+ return this.assignOptions({ hydrate });
169
+ }
170
+ /**
171
+ * 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.
172
+ */
173
+ ref() {
174
+ return this.assignOptions({ ref: true });
175
+ }
176
+ /**
177
+ * Set to true to omit the property when {@link https://mikro-orm.io/docs/serializing Serializing}.
178
+ */
179
+ hidden() {
180
+ return this.assignOptions({ hidden: true });
181
+ }
182
+ /**
183
+ * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via version field. (SQL only)
184
+ */
185
+ version() {
186
+ return this.assignOptions({ version: true });
187
+ }
188
+ /**
189
+ * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via concurrency fields.
190
+ */
191
+ concurrencyCheck(concurrencyCheck = true) {
192
+ return this.assignOptions({ concurrencyCheck });
193
+ }
194
+ /**
195
+ * Explicitly specify index on a property.
196
+ */
197
+ index(index = true) {
198
+ return this.assignOptions({ index });
199
+ }
200
+ /**
201
+ * Set column as unique for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
202
+ */
203
+ unique(unique = true) {
204
+ return this.assignOptions({ unique });
205
+ }
206
+ /**
207
+ * Specify column with check constraints. (Postgres driver only)
208
+ *
209
+ * @see https://mikro-orm.io/docs/defining-entities#check-constraints
210
+ */
211
+ check(check) {
212
+ return this.assignOptions({ check });
213
+ }
214
+ /**
215
+ * Set to omit the property from the select clause for lazy loading.
216
+ *
217
+ * @see https://mikro-orm.io/docs/defining-entities#lazy-scalar-properties
218
+ */
219
+ lazy() {
220
+ return this.assignOptions({ lazy: true });
221
+ }
222
+ /**
223
+ * Set true to define entity's unique primary key identifier.
224
+ *
225
+ * @see https://mikro-orm.io/docs/decorators#primarykey
226
+ */
227
+ primary() {
228
+ return this.assignOptions({ primary: true });
229
+ }
230
+ /**
231
+ * Set true to define the properties as setter. (virtual)
232
+ *
233
+ * @example
234
+ * ```
235
+ * @Property({ setter: true })
236
+ * set address(value: string) {
237
+ * this._address = value.toLocaleLowerCase();
238
+ * }
239
+ * ```
240
+ */
241
+ setter(setter = true) {
242
+ return this.assignOptions({ setter });
243
+ }
244
+ /**
245
+ * Set true to define the properties as getter. (virtual)
246
+ *
247
+ * @example
248
+ * ```
249
+ * @Property({ getter: true })
250
+ * get fullName() {
251
+ * return this.firstName + this.lastName;
252
+ * }
253
+ * ```
254
+ */
255
+ getter(getter = true) {
256
+ return this.assignOptions({ getter });
257
+ }
258
+ /**
259
+ * When defining a property over a method (not a getter, a regular function), you can use this option to point
260
+ * to the method name.
261
+ *
262
+ * @example
263
+ * ```
264
+ * @Property({ getter: true })
265
+ * getFullName() {
266
+ * return this.firstName + this.lastName;
267
+ * }
268
+ * ```
269
+ */
270
+ getterName(getterName) {
271
+ return this.assignOptions({ getterName });
272
+ }
273
+ /**
274
+ * Set to define serialized primary key for MongoDB. (virtual)
275
+ * Alias for `@SerializedPrimaryKey()` decorator.
276
+ *
277
+ * @see https://mikro-orm.io/docs/decorators#serializedprimarykey
278
+ */
279
+ serializedPrimaryKey(serializedPrimaryKey = true) {
280
+ return this.assignOptions({ serializedPrimaryKey });
281
+ }
282
+ /**
283
+ * Set to use serialize property. Allow to specify a callback that will be used when serializing a property.
284
+ *
285
+ * @see https://mikro-orm.io/docs/serializing#property-serializers
286
+ */
287
+ serializer(serializer) {
288
+ return this.assignOptions({ serializer });
289
+ }
290
+ /**
291
+ * Specify name of key for the serialized value.
292
+ */
293
+ serializedName(serializedName) {
294
+ return this.assignOptions({ serializedName });
295
+ }
296
+ /**
297
+ * Specify serialization groups for `serialize()` calls. If a property does not specify any group, it will be included,
298
+ * otherwise only properties with a matching group are included.
299
+ */
300
+ groups(...groups) {
301
+ return this.assignOptions({ groups });
302
+ }
303
+ /**
304
+ * Specify a custom order based on the values. (SQL only)
305
+ */
306
+ customOrder(...customOrder) {
307
+ return this.assignOptions({ customOrder });
308
+ }
309
+ /**
310
+ * Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
311
+ */
312
+ comment(comment) {
313
+ return this.assignOptions({ comment });
314
+ }
315
+ /** mysql only */
316
+ extra(extra) {
317
+ return this.assignOptions({ extra });
318
+ }
319
+ /**
320
+ * Set to avoid a perpetual diff from the {@link https://mikro-orm.io/docs/schema-generator Schema Generator} when columns are generated.
321
+ *
322
+ * @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
323
+ */
324
+ ignoreSchemaChanges(...ignoreSchemaChanges) {
325
+ return this.assignOptions({ ignoreSchemaChanges });
326
+ }
327
+ array() {
328
+ return this.assignOptions({ array: true });
329
+ }
330
+ /** for postgres, by default it uses text column with check constraint */
331
+ nativeEnumName(nativeEnumName) {
332
+ return this.assignOptions({ nativeEnumName });
333
+ }
334
+ prefix(prefix) {
335
+ return this.assignOptions({ prefix });
336
+ }
337
+ prefixMode(prefixMode) {
338
+ return this.assignOptions({ prefixMode });
339
+ }
340
+ object(object = true) {
341
+ return this.assignOptions({ object });
342
+ }
343
+ /** Set what actions on owning entity should be cascaded to the relationship. Defaults to [Cascade.PERSIST, Cascade.MERGE] (see {@doclink cascading}). */
344
+ cascade(...cascade) {
345
+ return this.assignOptions({ cascade });
346
+ }
347
+ /** Always load the relationship. Discouraged for use with to-many relations for performance reasons. */
348
+ eager(eager = true) {
349
+ return this.assignOptions({ eager });
350
+ }
351
+ /** Override the default loading strategy for this property. This option has precedence over the global `loadStrategy`, but can be overridden by `FindOptions.strategy`. */
352
+ strategy(strategy) {
353
+ return this.assignOptions({ strategy });
354
+ }
355
+ /** 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. */
356
+ owner() {
357
+ return this.assignOptions({ owner: true });
358
+ }
359
+ /** For polymorphic relations. Specifies the property name that stores the entity type discriminator. Defaults to the property name. */
360
+ discriminator(discriminator) {
361
+ return this.assignOptions({ discriminator });
362
+ }
363
+ /** For polymorphic relations. Custom mapping of discriminator values to entity class names. */
364
+ discriminatorMap(discriminatorMap) {
365
+ return this.assignOptions({ discriminatorMap });
366
+ }
367
+ /** Point to the inverse side property name. */
368
+ inversedBy(inversedBy) {
369
+ return this.assignOptions({ inversedBy });
370
+ }
371
+ /** Point to the owning side property name. */
372
+ mappedBy(mappedBy) {
373
+ return this.assignOptions({ mappedBy });
374
+ }
375
+ /** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
376
+ where(...where) {
377
+ return this.assignOptions({ where });
378
+ }
379
+ /** Set default ordering. */
380
+ orderBy(...orderBy) {
381
+ return this.assignOptions({ orderBy });
382
+ }
383
+ /** Force stable insertion order of items in the collection (see {@doclink collections | Collections}). */
384
+ fixedOrder(fixedOrder = true) {
385
+ return this.assignOptions({ fixedOrder });
386
+ }
387
+ /** Override default order column name (`id`) for fixed ordering. */
388
+ fixedOrderColumn(fixedOrderColumn) {
389
+ return this.assignOptions({ fixedOrderColumn });
390
+ }
391
+ /** Override default name for pivot table (see {@doclink naming-strategy | Naming Strategy}). */
392
+ pivotTable(pivotTable) {
393
+ return this.assignOptions({ pivotTable });
394
+ }
395
+ /** Set pivot entity for this relation (see {@doclink collections#custom-pivot-table-entity | Custom pivot table entity}). */
396
+ pivotEntity(pivotEntity) {
397
+ return this.assignOptions({ pivotEntity });
398
+ }
399
+ /** 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. */
400
+ joinColumn(joinColumn) {
401
+ return this.assignOptions({ joinColumn });
402
+ }
403
+ /** 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. */
404
+ joinColumns(...joinColumns) {
405
+ return this.assignOptions({ joinColumns });
406
+ }
407
+ /** 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. */
408
+ inverseJoinColumn(inverseJoinColumn) {
409
+ return this.assignOptions({ inverseJoinColumn });
410
+ }
411
+ /** 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. */
412
+ inverseJoinColumns(...inverseJoinColumns) {
413
+ return this.assignOptions({ inverseJoinColumns });
414
+ }
415
+ /** 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. */
416
+ referenceColumnName(referenceColumnName) {
417
+ return this.assignOptions({ referenceColumnName });
418
+ }
419
+ /** 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. */
420
+ referencedColumnNames(...referencedColumnNames) {
421
+ return this.assignOptions({ referencedColumnNames });
422
+ }
423
+ /** Specify the property name on the target entity that this FK references instead of the primary key. */
424
+ targetKey(targetKey) {
425
+ return this.assignOptions({ targetKey });
426
+ }
427
+ /** What to do when the target entity gets deleted. */
428
+ deleteRule(deleteRule) {
429
+ return this.assignOptions({ deleteRule });
430
+ }
431
+ /** What to do when the reference to the target entity gets updated. */
432
+ updateRule(updateRule) {
433
+ return this.assignOptions({ updateRule });
434
+ }
435
+ /** Map this relation to the primary key value instead of an entity. */
436
+ mapToPk() {
437
+ return this.assignOptions({ mapToPk: true });
438
+ }
439
+ /** 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. */
440
+ deferMode(deferMode) {
441
+ return this.assignOptions({ deferMode });
442
+ }
443
+ /** 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. */
444
+ ownColumns(...ownColumns) {
445
+ return this.assignOptions({ ownColumns });
446
+ }
447
+ /** Enable/disable foreign key constraint creation on this relation */
448
+ createForeignKeyConstraint(createForeignKeyConstraint = true) {
449
+ return this.assignOptions({ createForeignKeyConstraint });
450
+ }
451
+ /** Set a custom foreign key constraint name, overriding NamingStrategy.indexName(). */
452
+ foreignKeyName(foreignKeyName) {
453
+ return this.assignOptions({ foreignKeyName });
454
+ }
455
+ /** Remove the entity when it gets disconnected from the relationship (see {@doclink cascading | Cascading}). */
456
+ orphanRemoval(orphanRemoval = true) {
457
+ return this.assignOptions({ orphanRemoval });
458
+ }
459
+ accessor(accessor = true) {
460
+ return this.assignOptions({ accessor });
461
+ }
462
462
  }
463
463
  /** @internal */
464
464
  export class OneToManyOptionsBuilderOnlyMappedBy extends UniversalPropertyOptionsBuilder {
465
- /** Point to the owning side property name. */
466
- mappedBy(mappedBy) {
467
- return new UniversalPropertyOptionsBuilder({ ...this['~options'], mappedBy });
468
- }
465
+ /** Point to the owning side property name. */
466
+ mappedBy(mappedBy) {
467
+ return new UniversalPropertyOptionsBuilder({ ...this['~options'], mappedBy });
468
+ }
469
469
  }
470
470
  function createPropertyBuilders(options) {
471
- return Object.fromEntries(
472
- Object.entries(options).map(([key, value]) => [key, () => new UniversalPropertyOptionsBuilder({ type: value })]),
473
- );
471
+ return Object.fromEntries(Object.entries(options).map(([key, value]) => [key, () => new UniversalPropertyOptionsBuilder({ type: value })]));
474
472
  }
475
473
  const propertyBuilders = {
476
- ...createPropertyBuilders(types),
477
- bigint: mode => new UniversalPropertyOptionsBuilder({ type: new types.bigint(mode) }),
478
- array: (toJsValue = i => i, toDbValue = i => i) =>
479
- new UniversalPropertyOptionsBuilder({ type: new types.array(toJsValue, toDbValue) }),
480
- decimal: mode => new UniversalPropertyOptionsBuilder({ type: new types.decimal(mode) }),
481
- json: () => new UniversalPropertyOptionsBuilder({ type: types.json }),
482
- formula: formula => new UniversalPropertyOptionsBuilder({ formula }),
483
- datetime: length => new UniversalPropertyOptionsBuilder({ type: types.datetime, length }),
484
- time: length => new UniversalPropertyOptionsBuilder({ type: types.time, length }),
485
- type: type => new UniversalPropertyOptionsBuilder({ type }),
486
- enum: items =>
487
- new UniversalPropertyOptionsBuilder({
488
- enum: true,
489
- items,
474
+ ...createPropertyBuilders(types),
475
+ bigint: (mode) => new UniversalPropertyOptionsBuilder({ type: new types.bigint(mode) }),
476
+ array: (toJsValue = i => i, toDbValue = i => i) => new UniversalPropertyOptionsBuilder({ type: new types.array(toJsValue, toDbValue) }),
477
+ decimal: (mode) => new UniversalPropertyOptionsBuilder({ type: new types.decimal(mode) }),
478
+ json: () => new UniversalPropertyOptionsBuilder({ type: types.json }),
479
+ formula: (formula) => new UniversalPropertyOptionsBuilder({ formula }),
480
+ datetime: (length) => new UniversalPropertyOptionsBuilder({ type: types.datetime, length }),
481
+ time: (length) => new UniversalPropertyOptionsBuilder({ type: types.time, length }),
482
+ type: (type) => new UniversalPropertyOptionsBuilder({ type }),
483
+ enum: (items) => new UniversalPropertyOptionsBuilder({
484
+ enum: true,
485
+ items,
490
486
  }),
491
- embedded: target =>
492
- new UniversalPropertyOptionsBuilder({
493
- entity: () => target,
494
- kind: 'embedded',
487
+ embedded: (target) => new UniversalPropertyOptionsBuilder({
488
+ entity: () => target,
489
+ kind: 'embedded',
495
490
  }),
496
- manyToMany: target =>
497
- new UniversalPropertyOptionsBuilder({
498
- entity: () => target,
499
- kind: 'm:n',
491
+ manyToMany: (target) => new UniversalPropertyOptionsBuilder({
492
+ entity: () => target,
493
+ kind: 'm:n',
500
494
  }),
501
- manyToOne: target =>
502
- new UniversalPropertyOptionsBuilder({
503
- entity: () => target,
504
- kind: 'm:1',
495
+ manyToOne: (target) => new UniversalPropertyOptionsBuilder({
496
+ entity: () => target,
497
+ kind: 'm:1',
505
498
  }),
506
- oneToMany: target =>
507
- new OneToManyOptionsBuilderOnlyMappedBy({
508
- entity: () => target,
509
- kind: '1:m',
499
+ oneToMany: (target) => new OneToManyOptionsBuilderOnlyMappedBy({
500
+ entity: () => target,
501
+ kind: '1:m',
510
502
  }),
511
- oneToOne: target =>
512
- new UniversalPropertyOptionsBuilder({
513
- entity: () => target,
514
- kind: '1:1',
503
+ oneToOne: (target) => new UniversalPropertyOptionsBuilder({
504
+ entity: () => target,
505
+ kind: '1:1',
515
506
  }),
516
507
  };
517
508
  function getBuilderOptions(builder) {
518
- return '~options' in builder ? builder['~options'] : builder;
509
+ return '~options' in builder ? builder['~options'] : builder;
519
510
  }
520
511
  export function defineEntity(meta) {
521
- const { properties: propertiesOrGetter, ...options } = meta;
522
- const propertyOptions =
523
- typeof propertiesOrGetter === 'function' ? propertiesOrGetter(propertyBuilders) : propertiesOrGetter;
524
- const properties = {};
525
- const values = new Map();
526
- for (const [key, builder] of Object.entries(propertyOptions)) {
527
- if (typeof builder === 'function') {
528
- Object.defineProperty(properties, key, {
529
- get: () => {
530
- let value = values.get(key);
531
- if (value === undefined) {
532
- value = getBuilderOptions(builder());
533
- values.set(key, value);
534
- }
535
- return value;
536
- },
537
- set: value => {
538
- values.set(key, value);
539
- },
540
- enumerable: true,
541
- });
542
- } else {
543
- Object.defineProperty(properties, key, {
544
- value: getBuilderOptions(builder),
545
- writable: true,
546
- enumerable: true,
547
- });
548
- }
549
- }
550
- return new EntitySchema({ properties, ...options });
512
+ const { properties: propertiesOrGetter, ...options } = meta;
513
+ const propertyOptions = typeof propertiesOrGetter === 'function' ? propertiesOrGetter(propertyBuilders) : propertiesOrGetter;
514
+ const properties = {};
515
+ const values = new Map();
516
+ for (const [key, builder] of Object.entries(propertyOptions)) {
517
+ if (typeof builder === 'function') {
518
+ Object.defineProperty(properties, key, {
519
+ get: () => {
520
+ let value = values.get(key);
521
+ if (value === undefined) {
522
+ value = getBuilderOptions(builder());
523
+ values.set(key, value);
524
+ }
525
+ return value;
526
+ },
527
+ set: (value) => {
528
+ values.set(key, value);
529
+ },
530
+ enumerable: true,
531
+ });
532
+ }
533
+ else {
534
+ Object.defineProperty(properties, key, {
535
+ value: getBuilderOptions(builder),
536
+ writable: true,
537
+ enumerable: true,
538
+ });
539
+ }
540
+ }
541
+ return new EntitySchema({ properties, ...options });
551
542
  }
552
543
  defineEntity.properties = propertyBuilders;
553
544
  /** Shorthand alias for `defineEntity.properties` - the property builders for use in `defineEntity()`. */