@mikro-orm/core 7.0.2-dev.9 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/EntityManager.d.ts +883 -579
  2. package/EntityManager.js +1897 -1865
  3. package/MikroORM.d.ts +103 -72
  4. package/MikroORM.js +178 -177
  5. package/README.md +128 -294
  6. package/cache/CacheAdapter.d.ts +38 -36
  7. package/cache/FileCacheAdapter.d.ts +30 -24
  8. package/cache/FileCacheAdapter.js +80 -78
  9. package/cache/GeneratedCacheAdapter.d.ts +19 -20
  10. package/cache/GeneratedCacheAdapter.js +31 -30
  11. package/cache/MemoryCacheAdapter.d.ts +19 -20
  12. package/cache/MemoryCacheAdapter.js +36 -36
  13. package/cache/NullCacheAdapter.d.ts +17 -16
  14. package/cache/NullCacheAdapter.js +25 -24
  15. package/connections/Connection.d.ts +99 -75
  16. package/connections/Connection.js +166 -160
  17. package/drivers/DatabaseDriver.d.ts +187 -69
  18. package/drivers/DatabaseDriver.js +451 -432
  19. package/drivers/IDatabaseDriver.d.ts +464 -281
  20. package/drivers/IDatabaseDriver.js +1 -0
  21. package/entity/BaseEntity.d.ts +121 -73
  22. package/entity/BaseEntity.js +44 -33
  23. package/entity/Collection.d.ts +216 -157
  24. package/entity/Collection.js +728 -707
  25. package/entity/EntityAssigner.d.ts +90 -76
  26. package/entity/EntityAssigner.js +232 -229
  27. package/entity/EntityFactory.d.ts +68 -40
  28. package/entity/EntityFactory.js +427 -366
  29. package/entity/EntityHelper.d.ts +34 -22
  30. package/entity/EntityHelper.js +280 -267
  31. package/entity/EntityIdentifier.d.ts +4 -4
  32. package/entity/EntityIdentifier.js +10 -10
  33. package/entity/EntityLoader.d.ts +105 -56
  34. package/entity/EntityLoader.js +754 -722
  35. package/entity/EntityRepository.d.ts +317 -200
  36. package/entity/EntityRepository.js +214 -212
  37. package/entity/PolymorphicRef.d.ts +5 -5
  38. package/entity/PolymorphicRef.js +10 -10
  39. package/entity/Reference.d.ts +130 -66
  40. package/entity/Reference.js +280 -260
  41. package/entity/WrappedEntity.d.ts +116 -53
  42. package/entity/WrappedEntity.js +169 -147
  43. package/entity/defineEntity.d.ts +1290 -614
  44. package/entity/defineEntity.js +521 -511
  45. package/entity/utils.d.ts +13 -3
  46. package/entity/utils.js +71 -73
  47. package/entity/validators.js +43 -43
  48. package/entity/wrap.js +8 -8
  49. package/enums.d.ts +275 -138
  50. package/enums.js +268 -137
  51. package/errors.d.ts +120 -72
  52. package/errors.js +356 -253
  53. package/events/EventManager.d.ts +27 -10
  54. package/events/EventManager.js +80 -73
  55. package/events/EventSubscriber.d.ts +33 -29
  56. package/events/TransactionEventBroadcaster.d.ts +16 -7
  57. package/events/TransactionEventBroadcaster.js +15 -13
  58. package/exceptions.d.ts +23 -40
  59. package/exceptions.js +35 -52
  60. package/hydration/Hydrator.d.ts +43 -16
  61. package/hydration/Hydrator.js +44 -42
  62. package/hydration/ObjectHydrator.d.ts +51 -17
  63. package/hydration/ObjectHydrator.js +480 -416
  64. package/index.d.ts +116 -2
  65. package/index.js +10 -1
  66. package/logging/DefaultLogger.d.ts +35 -30
  67. package/logging/DefaultLogger.js +87 -84
  68. package/logging/Logger.d.ts +45 -40
  69. package/logging/SimpleLogger.d.ts +13 -11
  70. package/logging/SimpleLogger.js +22 -22
  71. package/logging/colors.d.ts +6 -6
  72. package/logging/colors.js +11 -10
  73. package/logging/inspect.js +7 -7
  74. package/metadata/EntitySchema.d.ts +214 -108
  75. package/metadata/EntitySchema.js +398 -379
  76. package/metadata/MetadataDiscovery.d.ts +115 -111
  77. package/metadata/MetadataDiscovery.js +1948 -1857
  78. package/metadata/MetadataProvider.d.ts +25 -14
  79. package/metadata/MetadataProvider.js +83 -77
  80. package/metadata/MetadataStorage.d.ts +39 -19
  81. package/metadata/MetadataStorage.js +119 -106
  82. package/metadata/MetadataValidator.d.ts +39 -39
  83. package/metadata/MetadataValidator.js +381 -338
  84. package/metadata/discover-entities.d.ts +5 -2
  85. package/metadata/discover-entities.js +27 -27
  86. package/metadata/types.d.ts +615 -531
  87. package/naming-strategy/AbstractNamingStrategy.d.ts +55 -39
  88. package/naming-strategy/AbstractNamingStrategy.js +91 -85
  89. package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
  90. package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
  91. package/naming-strategy/MongoNamingStrategy.d.ts +7 -6
  92. package/naming-strategy/MongoNamingStrategy.js +19 -18
  93. package/naming-strategy/NamingStrategy.d.ts +109 -99
  94. package/naming-strategy/UnderscoreNamingStrategy.d.ts +8 -7
  95. package/naming-strategy/UnderscoreNamingStrategy.js +22 -21
  96. package/not-supported.js +7 -4
  97. package/package.json +1 -1
  98. package/platforms/ExceptionConverter.d.ts +2 -1
  99. package/platforms/ExceptionConverter.js +5 -4
  100. package/platforms/Platform.d.ts +310 -236
  101. package/platforms/Platform.js +661 -573
  102. package/serialization/EntitySerializer.d.ts +49 -25
  103. package/serialization/EntitySerializer.js +224 -216
  104. package/serialization/EntityTransformer.d.ts +11 -5
  105. package/serialization/EntityTransformer.js +220 -216
  106. package/serialization/SerializationContext.d.ts +27 -18
  107. package/serialization/SerializationContext.js +105 -100
  108. package/types/ArrayType.d.ts +9 -8
  109. package/types/ArrayType.js +34 -33
  110. package/types/BigIntType.d.ts +17 -10
  111. package/types/BigIntType.js +37 -37
  112. package/types/BlobType.d.ts +4 -3
  113. package/types/BlobType.js +14 -13
  114. package/types/BooleanType.d.ts +5 -4
  115. package/types/BooleanType.js +13 -12
  116. package/types/CharacterType.d.ts +3 -2
  117. package/types/CharacterType.js +7 -6
  118. package/types/DateTimeType.d.ts +6 -5
  119. package/types/DateTimeType.js +16 -15
  120. package/types/DateType.d.ts +6 -5
  121. package/types/DateType.js +16 -15
  122. package/types/DecimalType.d.ts +7 -7
  123. package/types/DecimalType.js +26 -26
  124. package/types/DoubleType.d.ts +3 -3
  125. package/types/DoubleType.js +12 -12
  126. package/types/EnumArrayType.d.ts +6 -5
  127. package/types/EnumArrayType.js +25 -24
  128. package/types/EnumType.d.ts +4 -3
  129. package/types/EnumType.js +12 -11
  130. package/types/FloatType.d.ts +4 -3
  131. package/types/FloatType.js +10 -9
  132. package/types/IntegerType.d.ts +4 -3
  133. package/types/IntegerType.js +10 -9
  134. package/types/IntervalType.d.ts +5 -4
  135. package/types/IntervalType.js +13 -12
  136. package/types/JsonType.d.ts +9 -8
  137. package/types/JsonType.js +33 -32
  138. package/types/MediumIntType.d.ts +2 -1
  139. package/types/MediumIntType.js +4 -3
  140. package/types/SmallIntType.d.ts +4 -3
  141. package/types/SmallIntType.js +10 -9
  142. package/types/StringType.d.ts +5 -4
  143. package/types/StringType.js +13 -12
  144. package/types/TextType.d.ts +4 -3
  145. package/types/TextType.js +10 -9
  146. package/types/TimeType.d.ts +6 -5
  147. package/types/TimeType.js +18 -17
  148. package/types/TinyIntType.d.ts +4 -3
  149. package/types/TinyIntType.js +11 -10
  150. package/types/Type.d.ts +88 -73
  151. package/types/Type.js +85 -74
  152. package/types/Uint8ArrayType.d.ts +5 -4
  153. package/types/Uint8ArrayType.js +22 -21
  154. package/types/UnknownType.d.ts +5 -4
  155. package/types/UnknownType.js +13 -12
  156. package/types/UuidType.d.ts +6 -5
  157. package/types/UuidType.js +20 -19
  158. package/types/index.d.ts +77 -49
  159. package/types/index.js +64 -26
  160. package/typings.d.ts +1388 -729
  161. package/typings.js +255 -231
  162. package/unit-of-work/ChangeSet.d.ts +28 -24
  163. package/unit-of-work/ChangeSet.js +58 -54
  164. package/unit-of-work/ChangeSetComputer.d.ts +13 -11
  165. package/unit-of-work/ChangeSetComputer.js +180 -159
  166. package/unit-of-work/ChangeSetPersister.d.ts +64 -41
  167. package/unit-of-work/ChangeSetPersister.js +443 -418
  168. package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
  169. package/unit-of-work/CommitOrderCalculator.js +89 -88
  170. package/unit-of-work/IdentityMap.d.ts +32 -25
  171. package/unit-of-work/IdentityMap.js +106 -99
  172. package/unit-of-work/UnitOfWork.d.ts +182 -127
  173. package/unit-of-work/UnitOfWork.js +1201 -1169
  174. package/utils/AbstractMigrator.d.ts +111 -91
  175. package/utils/AbstractMigrator.js +275 -275
  176. package/utils/AbstractSchemaGenerator.d.ts +43 -34
  177. package/utils/AbstractSchemaGenerator.js +121 -122
  178. package/utils/AsyncContext.d.ts +3 -3
  179. package/utils/AsyncContext.js +34 -35
  180. package/utils/Configuration.d.ts +853 -801
  181. package/utils/Configuration.js +360 -337
  182. package/utils/Cursor.d.ts +40 -22
  183. package/utils/Cursor.js +135 -127
  184. package/utils/DataloaderUtils.d.ts +58 -43
  185. package/utils/DataloaderUtils.js +203 -198
  186. package/utils/EntityComparator.d.ts +99 -80
  187. package/utils/EntityComparator.js +825 -727
  188. package/utils/NullHighlighter.d.ts +2 -1
  189. package/utils/NullHighlighter.js +4 -3
  190. package/utils/QueryHelper.d.ts +79 -51
  191. package/utils/QueryHelper.js +372 -361
  192. package/utils/RawQueryFragment.d.ts +54 -28
  193. package/utils/RawQueryFragment.js +110 -99
  194. package/utils/RequestContext.d.ts +33 -32
  195. package/utils/RequestContext.js +52 -53
  196. package/utils/TransactionContext.d.ts +17 -16
  197. package/utils/TransactionContext.js +28 -27
  198. package/utils/TransactionManager.d.ts +58 -58
  199. package/utils/TransactionManager.js +199 -197
  200. package/utils/Utils.d.ts +210 -145
  201. package/utils/Utils.js +820 -813
  202. package/utils/clone.js +104 -113
  203. package/utils/env-vars.js +90 -88
  204. package/utils/fs-utils.d.ts +15 -15
  205. package/utils/fs-utils.js +180 -181
  206. package/utils/upsert-utils.d.ts +20 -5
  207. package/utils/upsert-utils.js +114 -116
@@ -4,534 +4,544 @@ 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 unsigned for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
150
- */
151
- unsigned(unsigned = true) {
152
- return this.assignOptions({ unsigned });
153
- }
154
- persist(persist = true) {
155
- return this.assignOptions({ persist });
156
- }
157
- /**
158
- * Set false to disable hydration of this property. Useful for persisted getters.
159
- */
160
- hydrate(hydrate = true) {
161
- return this.assignOptions({ hydrate });
162
- }
163
- /**
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.
165
- */
166
- ref() {
167
- return this.assignOptions({ ref: true });
168
- }
169
- /**
170
- * Set to true to omit the property when {@link https://mikro-orm.io/docs/serializing Serializing}.
171
- */
172
- hidden() {
173
- return this.assignOptions({ hidden: true });
174
- }
175
- /**
176
- * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via version field. (SQL only)
177
- */
178
- version() {
179
- return this.assignOptions({ version: true });
180
- }
181
- /**
182
- * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via concurrency fields.
183
- */
184
- concurrencyCheck(concurrencyCheck = true) {
185
- return this.assignOptions({ concurrencyCheck });
186
- }
187
- /**
188
- * Explicitly specify index on a property.
189
- */
190
- index(index = true) {
191
- return this.assignOptions({ index });
192
- }
193
- /**
194
- * Set column as unique for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
195
- */
196
- unique(unique = true) {
197
- return this.assignOptions({ unique });
198
- }
199
- /**
200
- * Specify column with check constraints. (Postgres driver only)
201
- *
202
- * @see https://mikro-orm.io/docs/defining-entities#check-constraints
203
- */
204
- check(check) {
205
- return this.assignOptions({ check });
206
- }
207
- /**
208
- * Set to omit the property from the select clause for lazy loading.
209
- *
210
- * @see https://mikro-orm.io/docs/defining-entities#lazy-scalar-properties
211
- */
212
- lazy() {
213
- return this.assignOptions({ lazy: true });
214
- }
215
- /**
216
- * Set true to define entity's unique primary key identifier.
217
- *
218
- * @see https://mikro-orm.io/docs/decorators#primarykey
219
- */
220
- primary() {
221
- return this.assignOptions({ primary: true });
222
- }
223
- /**
224
- * Set true to define the properties as setter. (virtual)
225
- *
226
- * @example
227
- * ```
228
- * @Property({ setter: true })
229
- * set address(value: string) {
230
- * this._address = value.toLocaleLowerCase();
231
- * }
232
- * ```
233
- */
234
- setter(setter = true) {
235
- return this.assignOptions({ setter });
236
- }
237
- /**
238
- * Set true to define the properties as getter. (virtual)
239
- *
240
- * @example
241
- * ```
242
- * @Property({ getter: true })
243
- * get fullName() {
244
- * return this.firstName + this.lastName;
245
- * }
246
- * ```
247
- */
248
- getter(getter = true) {
249
- return this.assignOptions({ getter });
250
- }
251
- /**
252
- * When defining a property over a method (not a getter, a regular function), you can use this option to point
253
- * to the method name.
254
- *
255
- * @example
256
- * ```
257
- * @Property({ getter: true })
258
- * getFullName() {
259
- * return this.firstName + this.lastName;
260
- * }
261
- * ```
262
- */
263
- getterName(getterName) {
264
- return this.assignOptions({ getterName });
265
- }
266
- /**
267
- * Set to define serialized primary key for MongoDB. (virtual)
268
- * Alias for `@SerializedPrimaryKey()` decorator.
269
- *
270
- * @see https://mikro-orm.io/docs/decorators#serializedprimarykey
271
- */
272
- serializedPrimaryKey(serializedPrimaryKey = true) {
273
- return this.assignOptions({ serializedPrimaryKey });
274
- }
275
- /**
276
- * Set to use serialize property. Allow to specify a callback that will be used when serializing a property.
277
- *
278
- * @see https://mikro-orm.io/docs/serializing#property-serializers
279
- */
280
- serializer(serializer) {
281
- return this.assignOptions({ serializer });
282
- }
283
- /**
284
- * Specify name of key for the serialized value.
285
- */
286
- serializedName(serializedName) {
287
- return this.assignOptions({ serializedName });
288
- }
289
- /**
290
- * Specify serialization groups for `serialize()` calls. If a property does not specify any group, it will be included,
291
- * otherwise only properties with a matching group are included.
292
- */
293
- groups(...groups) {
294
- return this.assignOptions({ groups });
295
- }
296
- /**
297
- * Specify a custom order based on the values. (SQL only)
298
- */
299
- customOrder(...customOrder) {
300
- return this.assignOptions({ customOrder });
301
- }
302
- /**
303
- * Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
304
- */
305
- comment(comment) {
306
- return this.assignOptions({ comment });
307
- }
308
- /** mysql only */
309
- extra(extra) {
310
- return this.assignOptions({ extra });
311
- }
312
- /**
313
- * Set to avoid a perpetual diff from the {@link https://mikro-orm.io/docs/schema-generator Schema Generator} when columns are generated.
314
- *
315
- * @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
316
- */
317
- ignoreSchemaChanges(...ignoreSchemaChanges) {
318
- return this.assignOptions({ ignoreSchemaChanges });
319
- }
320
- array() {
321
- return this.assignOptions({ array: true });
322
- }
323
- /** for postgres, by default it uses text column with check constraint */
324
- nativeEnumName(nativeEnumName) {
325
- return this.assignOptions({ nativeEnumName });
326
- }
327
- prefix(prefix) {
328
- return this.assignOptions({ prefix });
329
- }
330
- prefixMode(prefixMode) {
331
- return this.assignOptions({ prefixMode });
332
- }
333
- object(object = true) {
334
- return this.assignOptions({ object });
335
- }
336
- /** Set what actions on owning entity should be cascaded to the relationship. Defaults to [Cascade.PERSIST, Cascade.MERGE] (see {@doclink cascading}). */
337
- cascade(...cascade) {
338
- return this.assignOptions({ cascade });
339
- }
340
- /** Always load the relationship. Discouraged for use with to-many relations for performance reasons. */
341
- eager(eager = true) {
342
- return this.assignOptions({ eager });
343
- }
344
- /** Override the default loading strategy for this property. This option has precedence over the global `loadStrategy`, but can be overridden by `FindOptions.strategy`. */
345
- strategy(strategy) {
346
- return this.assignOptions({ strategy });
347
- }
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 });
351
- }
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 });
355
- }
356
- /** For polymorphic relations. Custom mapping of discriminator values to entity class names. */
357
- discriminatorMap(discriminatorMap) {
358
- return this.assignOptions({ discriminatorMap });
359
- }
360
- /** Point to the inverse side property name. */
361
- inversedBy(inversedBy) {
362
- return this.assignOptions({ inversedBy });
363
- }
364
- /** Point to the owning side property name. */
365
- mappedBy(mappedBy) {
366
- return this.assignOptions({ mappedBy });
367
- }
368
- /** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
369
- where(...where) {
370
- return this.assignOptions({ where });
371
- }
372
- /** Set default ordering. */
373
- orderBy(...orderBy) {
374
- return this.assignOptions({ orderBy });
375
- }
376
- /** Force stable insertion order of items in the collection (see {@doclink collections | Collections}). */
377
- fixedOrder(fixedOrder = true) {
378
- return this.assignOptions({ fixedOrder });
379
- }
380
- /** Override default order column name (`id`) for fixed ordering. */
381
- fixedOrderColumn(fixedOrderColumn) {
382
- return this.assignOptions({ fixedOrderColumn });
383
- }
384
- /** Override default name for pivot table (see {@doclink naming-strategy | Naming Strategy}). */
385
- pivotTable(pivotTable) {
386
- return this.assignOptions({ pivotTable });
387
- }
388
- /** Set pivot entity for this relation (see {@doclink collections#custom-pivot-table-entity | Custom pivot table entity}). */
389
- pivotEntity(pivotEntity) {
390
- return this.assignOptions({ pivotEntity });
391
- }
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. */
393
- joinColumn(joinColumn) {
394
- return this.assignOptions({ joinColumn });
395
- }
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. */
397
- joinColumns(...joinColumns) {
398
- return this.assignOptions({ joinColumns });
399
- }
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. */
401
- inverseJoinColumn(inverseJoinColumn) {
402
- return this.assignOptions({ inverseJoinColumn });
403
- }
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. */
405
- inverseJoinColumns(...inverseJoinColumns) {
406
- return this.assignOptions({ inverseJoinColumns });
407
- }
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. */
409
- referenceColumnName(referenceColumnName) {
410
- return this.assignOptions({ referenceColumnName });
411
- }
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. */
413
- referencedColumnNames(...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 });
419
- }
420
- /** What to do when the target entity gets deleted. */
421
- deleteRule(deleteRule) {
422
- return this.assignOptions({ deleteRule });
423
- }
424
- /** What to do when the reference to the target entity gets updated. */
425
- updateRule(updateRule) {
426
- return this.assignOptions({ updateRule });
427
- }
428
- /** Map this relation to the primary key value instead of an entity. */
429
- mapToPk() {
430
- return this.assignOptions({ mapToPk: true });
431
- }
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 });
435
- }
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. */
437
- ownColumns(...ownColumns) {
438
- return this.assignOptions({ ownColumns });
439
- }
440
- /** Enable/disable foreign key constraint creation on this relation */
441
- createForeignKeyConstraint(createForeignKeyConstraint = true) {
442
- return this.assignOptions({ createForeignKeyConstraint });
443
- }
444
- /** Set a custom foreign key constraint name, overriding NamingStrategy.indexName(). */
445
- foreignKeyName(foreignKeyName) {
446
- return this.assignOptions({ foreignKeyName });
447
- }
448
- /** Remove the entity when it gets disconnected from the relationship (see {@doclink cascading | Cascading}). */
449
- orphanRemoval(orphanRemoval = true) {
450
- return this.assignOptions({ orphanRemoval });
451
- }
452
- accessor(accessor = true) {
453
- return this.assignOptions({ accessor });
454
- }
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 unsigned for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
150
+ */
151
+ unsigned(unsigned = true) {
152
+ return this.assignOptions({ unsigned });
153
+ }
154
+ persist(persist = true) {
155
+ return this.assignOptions({ persist });
156
+ }
157
+ /**
158
+ * Set false to disable hydration of this property. Useful for persisted getters.
159
+ */
160
+ hydrate(hydrate = true) {
161
+ return this.assignOptions({ hydrate });
162
+ }
163
+ /**
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.
165
+ */
166
+ ref() {
167
+ return this.assignOptions({ ref: true });
168
+ }
169
+ /**
170
+ * Set to true to omit the property when {@link https://mikro-orm.io/docs/serializing Serializing}.
171
+ */
172
+ hidden() {
173
+ return this.assignOptions({ hidden: true });
174
+ }
175
+ /**
176
+ * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via version field. (SQL only)
177
+ */
178
+ version() {
179
+ return this.assignOptions({ version: true });
180
+ }
181
+ /**
182
+ * Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via concurrency fields.
183
+ */
184
+ concurrencyCheck(concurrencyCheck = true) {
185
+ return this.assignOptions({ concurrencyCheck });
186
+ }
187
+ /**
188
+ * Explicitly specify index on a property.
189
+ */
190
+ index(index = true) {
191
+ return this.assignOptions({ index });
192
+ }
193
+ /**
194
+ * Set column as unique for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
195
+ */
196
+ unique(unique = true) {
197
+ return this.assignOptions({ unique });
198
+ }
199
+ /**
200
+ * Specify column with check constraints. (Postgres driver only)
201
+ *
202
+ * @see https://mikro-orm.io/docs/defining-entities#check-constraints
203
+ */
204
+ check(check) {
205
+ return this.assignOptions({ check });
206
+ }
207
+ /**
208
+ * Set to omit the property from the select clause for lazy loading.
209
+ *
210
+ * @see https://mikro-orm.io/docs/defining-entities#lazy-scalar-properties
211
+ */
212
+ lazy() {
213
+ return this.assignOptions({ lazy: true });
214
+ }
215
+ /**
216
+ * Set true to define entity's unique primary key identifier.
217
+ *
218
+ * @see https://mikro-orm.io/docs/decorators#primarykey
219
+ */
220
+ primary() {
221
+ return this.assignOptions({ primary: true });
222
+ }
223
+ /**
224
+ * Set true to define the properties as setter. (virtual)
225
+ *
226
+ * @example
227
+ * ```
228
+ * @Property({ setter: true })
229
+ * set address(value: string) {
230
+ * this._address = value.toLocaleLowerCase();
231
+ * }
232
+ * ```
233
+ */
234
+ setter(setter = true) {
235
+ return this.assignOptions({ setter });
236
+ }
237
+ /**
238
+ * Set true to define the properties as getter. (virtual)
239
+ *
240
+ * @example
241
+ * ```
242
+ * @Property({ getter: true })
243
+ * get fullName() {
244
+ * return this.firstName + this.lastName;
245
+ * }
246
+ * ```
247
+ */
248
+ getter(getter = true) {
249
+ return this.assignOptions({ getter });
250
+ }
251
+ /**
252
+ * When defining a property over a method (not a getter, a regular function), you can use this option to point
253
+ * to the method name.
254
+ *
255
+ * @example
256
+ * ```
257
+ * @Property({ getter: true })
258
+ * getFullName() {
259
+ * return this.firstName + this.lastName;
260
+ * }
261
+ * ```
262
+ */
263
+ getterName(getterName) {
264
+ return this.assignOptions({ getterName });
265
+ }
266
+ /**
267
+ * Set to define serialized primary key for MongoDB. (virtual)
268
+ * Alias for `@SerializedPrimaryKey()` decorator.
269
+ *
270
+ * @see https://mikro-orm.io/docs/decorators#serializedprimarykey
271
+ */
272
+ serializedPrimaryKey(serializedPrimaryKey = true) {
273
+ return this.assignOptions({ serializedPrimaryKey });
274
+ }
275
+ /**
276
+ * Set to use serialize property. Allow to specify a callback that will be used when serializing a property.
277
+ *
278
+ * @see https://mikro-orm.io/docs/serializing#property-serializers
279
+ */
280
+ serializer(serializer) {
281
+ return this.assignOptions({ serializer });
282
+ }
283
+ /**
284
+ * Specify name of key for the serialized value.
285
+ */
286
+ serializedName(serializedName) {
287
+ return this.assignOptions({ serializedName });
288
+ }
289
+ /**
290
+ * Specify serialization groups for `serialize()` calls. If a property does not specify any group, it will be included,
291
+ * otherwise only properties with a matching group are included.
292
+ */
293
+ groups(...groups) {
294
+ return this.assignOptions({ groups });
295
+ }
296
+ /**
297
+ * Specify a custom order based on the values. (SQL only)
298
+ */
299
+ customOrder(...customOrder) {
300
+ return this.assignOptions({ customOrder });
301
+ }
302
+ /**
303
+ * Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
304
+ */
305
+ comment(comment) {
306
+ return this.assignOptions({ comment });
307
+ }
308
+ /** mysql only */
309
+ extra(extra) {
310
+ return this.assignOptions({ extra });
311
+ }
312
+ /**
313
+ * Set to avoid a perpetual diff from the {@link https://mikro-orm.io/docs/schema-generator Schema Generator} when columns are generated.
314
+ *
315
+ * @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
316
+ */
317
+ ignoreSchemaChanges(...ignoreSchemaChanges) {
318
+ return this.assignOptions({ ignoreSchemaChanges });
319
+ }
320
+ array() {
321
+ return this.assignOptions({ array: true });
322
+ }
323
+ /** for postgres, by default it uses text column with check constraint */
324
+ nativeEnumName(nativeEnumName) {
325
+ return this.assignOptions({ nativeEnumName });
326
+ }
327
+ prefix(prefix) {
328
+ return this.assignOptions({ prefix });
329
+ }
330
+ prefixMode(prefixMode) {
331
+ return this.assignOptions({ prefixMode });
332
+ }
333
+ object(object = true) {
334
+ return this.assignOptions({ object });
335
+ }
336
+ /** Set what actions on owning entity should be cascaded to the relationship. Defaults to [Cascade.PERSIST, Cascade.MERGE] (see {@doclink cascading}). */
337
+ cascade(...cascade) {
338
+ return this.assignOptions({ cascade });
339
+ }
340
+ /** Always load the relationship. Discouraged for use with to-many relations for performance reasons. */
341
+ eager(eager = true) {
342
+ return this.assignOptions({ eager });
343
+ }
344
+ /** Override the default loading strategy for this property. This option has precedence over the global `loadStrategy`, but can be overridden by `FindOptions.strategy`. */
345
+ strategy(strategy) {
346
+ return this.assignOptions({ strategy });
347
+ }
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 });
351
+ }
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 });
355
+ }
356
+ /** For polymorphic relations. Custom mapping of discriminator values to entity class names. */
357
+ discriminatorMap(discriminatorMap) {
358
+ return this.assignOptions({ discriminatorMap });
359
+ }
360
+ /** Point to the inverse side property name. */
361
+ inversedBy(inversedBy) {
362
+ return this.assignOptions({ inversedBy });
363
+ }
364
+ /** Point to the owning side property name. */
365
+ mappedBy(mappedBy) {
366
+ return this.assignOptions({ mappedBy });
367
+ }
368
+ /** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
369
+ where(...where) {
370
+ return this.assignOptions({ where });
371
+ }
372
+ /** Set default ordering. */
373
+ orderBy(...orderBy) {
374
+ return this.assignOptions({ orderBy });
375
+ }
376
+ /** Force stable insertion order of items in the collection (see {@doclink collections | Collections}). */
377
+ fixedOrder(fixedOrder = true) {
378
+ return this.assignOptions({ fixedOrder });
379
+ }
380
+ /** Override default order column name (`id`) for fixed ordering. */
381
+ fixedOrderColumn(fixedOrderColumn) {
382
+ return this.assignOptions({ fixedOrderColumn });
383
+ }
384
+ /** Override default name for pivot table (see {@doclink naming-strategy | Naming Strategy}). */
385
+ pivotTable(pivotTable) {
386
+ return this.assignOptions({ pivotTable });
387
+ }
388
+ /** Set pivot entity for this relation (see {@doclink collections#custom-pivot-table-entity | Custom pivot table entity}). */
389
+ pivotEntity(pivotEntity) {
390
+ return this.assignOptions({ pivotEntity });
391
+ }
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. */
393
+ joinColumn(joinColumn) {
394
+ return this.assignOptions({ joinColumn });
395
+ }
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. */
397
+ joinColumns(...joinColumns) {
398
+ return this.assignOptions({ joinColumns });
399
+ }
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. */
401
+ inverseJoinColumn(inverseJoinColumn) {
402
+ return this.assignOptions({ inverseJoinColumn });
403
+ }
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. */
405
+ inverseJoinColumns(...inverseJoinColumns) {
406
+ return this.assignOptions({ inverseJoinColumns });
407
+ }
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. */
409
+ referenceColumnName(referenceColumnName) {
410
+ return this.assignOptions({ referenceColumnName });
411
+ }
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. */
413
+ referencedColumnNames(...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 });
419
+ }
420
+ /** What to do when the target entity gets deleted. */
421
+ deleteRule(deleteRule) {
422
+ return this.assignOptions({ deleteRule });
423
+ }
424
+ /** What to do when the reference to the target entity gets updated. */
425
+ updateRule(updateRule) {
426
+ return this.assignOptions({ updateRule });
427
+ }
428
+ /** Map this relation to the primary key value instead of an entity. */
429
+ mapToPk() {
430
+ return this.assignOptions({ mapToPk: true });
431
+ }
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 });
435
+ }
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. */
437
+ ownColumns(...ownColumns) {
438
+ return this.assignOptions({ ownColumns });
439
+ }
440
+ /** Enable/disable foreign key constraint creation on this relation */
441
+ createForeignKeyConstraint(createForeignKeyConstraint = true) {
442
+ return this.assignOptions({ createForeignKeyConstraint });
443
+ }
444
+ /** Set a custom foreign key constraint name, overriding NamingStrategy.indexName(). */
445
+ foreignKeyName(foreignKeyName) {
446
+ return this.assignOptions({ foreignKeyName });
447
+ }
448
+ /** Remove the entity when it gets disconnected from the relationship (see {@doclink cascading | Cascading}). */
449
+ orphanRemoval(orphanRemoval = true) {
450
+ return this.assignOptions({ orphanRemoval });
451
+ }
452
+ accessor(accessor = true) {
453
+ return this.assignOptions({ accessor });
454
+ }
455
455
  }
456
456
  /** @internal */
457
457
  export class OneToManyOptionsBuilderOnlyMappedBy extends UniversalPropertyOptionsBuilder {
458
- /** Point to the owning side property name. */
459
- mappedBy(mappedBy) {
460
- return new UniversalPropertyOptionsBuilder({ ...this['~options'], mappedBy });
461
- }
458
+ /** Point to the owning side property name. */
459
+ mappedBy(mappedBy) {
460
+ return new UniversalPropertyOptionsBuilder({ ...this['~options'], mappedBy });
461
+ }
462
462
  }
463
463
  function createPropertyBuilders(options) {
464
- return Object.fromEntries(Object.entries(options).map(([key, value]) => [key, () => new UniversalPropertyOptionsBuilder({ type: value })]));
464
+ return Object.fromEntries(
465
+ Object.entries(options).map(([key, value]) => [key, () => new UniversalPropertyOptionsBuilder({ type: value })]),
466
+ );
465
467
  }
466
468
  const propertyBuilders = {
467
- ...createPropertyBuilders(types),
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({
477
- enum: true,
478
- items,
469
+ ...createPropertyBuilders(types),
470
+ bigint: mode => new UniversalPropertyOptionsBuilder({ type: new types.bigint(mode) }),
471
+ array: (toJsValue = i => i, toDbValue = i => i) =>
472
+ new UniversalPropertyOptionsBuilder({ type: new types.array(toJsValue, toDbValue) }),
473
+ decimal: mode => new UniversalPropertyOptionsBuilder({ type: new types.decimal(mode) }),
474
+ json: () => new UniversalPropertyOptionsBuilder({ type: types.json }),
475
+ formula: formula => new UniversalPropertyOptionsBuilder({ formula }),
476
+ datetime: length => new UniversalPropertyOptionsBuilder({ type: types.datetime, length }),
477
+ time: length => new UniversalPropertyOptionsBuilder({ type: types.time, length }),
478
+ type: type => new UniversalPropertyOptionsBuilder({ type }),
479
+ enum: items =>
480
+ new UniversalPropertyOptionsBuilder({
481
+ enum: true,
482
+ items,
479
483
  }),
480
- embedded: (target) => new UniversalPropertyOptionsBuilder({
481
- entity: () => target,
482
- kind: 'embedded',
484
+ embedded: target =>
485
+ new UniversalPropertyOptionsBuilder({
486
+ entity: () => target,
487
+ kind: 'embedded',
483
488
  }),
484
- manyToMany: (target) => new UniversalPropertyOptionsBuilder({
485
- entity: () => target,
486
- kind: 'm:n',
489
+ manyToMany: target =>
490
+ new UniversalPropertyOptionsBuilder({
491
+ entity: () => target,
492
+ kind: 'm:n',
487
493
  }),
488
- manyToOne: (target) => new UniversalPropertyOptionsBuilder({
489
- entity: () => target,
490
- kind: 'm:1',
494
+ manyToOne: target =>
495
+ new UniversalPropertyOptionsBuilder({
496
+ entity: () => target,
497
+ kind: 'm:1',
491
498
  }),
492
- oneToMany: (target) => new OneToManyOptionsBuilderOnlyMappedBy({
493
- entity: () => target,
494
- kind: '1:m',
499
+ oneToMany: target =>
500
+ new OneToManyOptionsBuilderOnlyMappedBy({
501
+ entity: () => target,
502
+ kind: '1:m',
495
503
  }),
496
- oneToOne: (target) => new UniversalPropertyOptionsBuilder({
497
- entity: () => target,
498
- kind: '1:1',
504
+ oneToOne: target =>
505
+ new UniversalPropertyOptionsBuilder({
506
+ entity: () => target,
507
+ kind: '1:1',
499
508
  }),
500
509
  };
501
510
  function getBuilderOptions(builder) {
502
- return '~options' in builder ? builder['~options'] : builder;
511
+ return '~options' in builder ? builder['~options'] : builder;
503
512
  }
504
513
  export function defineEntity(meta) {
505
- const { properties: propertiesOrGetter, ...options } = meta;
506
- const propertyOptions = typeof propertiesOrGetter === 'function' ? propertiesOrGetter(propertyBuilders) : propertiesOrGetter;
507
- const properties = {};
508
- const values = new Map();
509
- for (const [key, builder] of Object.entries(propertyOptions)) {
510
- if (typeof builder === 'function') {
511
- Object.defineProperty(properties, key, {
512
- get: () => {
513
- let value = values.get(key);
514
- if (value === undefined) {
515
- value = getBuilderOptions(builder());
516
- values.set(key, value);
517
- }
518
- return value;
519
- },
520
- set: (value) => {
521
- values.set(key, value);
522
- },
523
- enumerable: true,
524
- });
525
- }
526
- else {
527
- Object.defineProperty(properties, key, {
528
- value: getBuilderOptions(builder),
529
- writable: true,
530
- enumerable: true,
531
- });
532
- }
533
- }
534
- return new EntitySchema({ properties, ...options });
514
+ const { properties: propertiesOrGetter, ...options } = meta;
515
+ const propertyOptions =
516
+ typeof propertiesOrGetter === 'function' ? propertiesOrGetter(propertyBuilders) : propertiesOrGetter;
517
+ const properties = {};
518
+ const values = new Map();
519
+ for (const [key, builder] of Object.entries(propertyOptions)) {
520
+ if (typeof builder === 'function') {
521
+ Object.defineProperty(properties, key, {
522
+ get: () => {
523
+ let value = values.get(key);
524
+ if (value === undefined) {
525
+ value = getBuilderOptions(builder());
526
+ values.set(key, value);
527
+ }
528
+ return value;
529
+ },
530
+ set: value => {
531
+ values.set(key, value);
532
+ },
533
+ enumerable: true,
534
+ });
535
+ } else {
536
+ Object.defineProperty(properties, key, {
537
+ value: getBuilderOptions(builder),
538
+ writable: true,
539
+ enumerable: true,
540
+ });
541
+ }
542
+ }
543
+ return new EntitySchema({ properties, ...options });
535
544
  }
536
545
  defineEntity.properties = propertyBuilders;
546
+ /** Shorthand alias for `defineEntity.properties` - the property builders for use in `defineEntity()`. */
537
547
  export { propertyBuilders as p };