@mikro-orm/core 6.4.17-dev.24 → 6.4.17-dev.26
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.
- package/entity/defineEntity.d.ts +528 -0
- package/entity/defineEntity.js +684 -0
- package/entity/index.d.ts +1 -0
- package/entity/index.js +1 -0
- package/hydration/ObjectHydrator.js +1 -1
- package/index.mjs +1 -0
- package/package.json +2 -2
- package/typings.js +1 -1
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
import type { EntityManager } from '../EntityManager';
|
|
2
|
+
import type { ColumnType, PropertyOptions, ReferenceOptions } from '../decorators/Property';
|
|
3
|
+
import type { EnumOptions } from '../decorators/Enum';
|
|
4
|
+
import type { EmbeddedOptions, EmbeddedPrefixMode } from '../decorators/Embedded';
|
|
5
|
+
import type { ManyToOneOptions } from '../decorators/ManyToOne';
|
|
6
|
+
import type { OneToManyOptions } from '../decorators/OneToMany';
|
|
7
|
+
import type { OneToOneOptions } from '../decorators/OneToOne';
|
|
8
|
+
import type { ManyToManyOptions } from '../decorators/ManyToMany';
|
|
9
|
+
import type { AnyString, GeneratedColumnCallback, Constructor, Opt, Hidden, CheckCallback, FilterQuery, EntityName, Dictionary, EntityMetadata } from '../typings';
|
|
10
|
+
import type { Reference, ScalarReference } from './Reference';
|
|
11
|
+
import type { SerializeOptions } from '../serialization/EntitySerializer';
|
|
12
|
+
import type { Cascade, DeferMode, LoadStrategy, QueryOrderMap } from '../enums';
|
|
13
|
+
import type { Collection } from './Collection';
|
|
14
|
+
import type { IType, Type } from '../types/Type';
|
|
15
|
+
import { types } from '../types';
|
|
16
|
+
import { EntitySchema } from '../metadata/EntitySchema';
|
|
17
|
+
declare class PropertyOptionsBuilder<Value> {
|
|
18
|
+
'~options': PropertyOptions<any>;
|
|
19
|
+
'~type'?: {
|
|
20
|
+
value: Value;
|
|
21
|
+
};
|
|
22
|
+
constructor(options: PropertyOptionsBuilder<Value>['~options']);
|
|
23
|
+
/**
|
|
24
|
+
* Alias for `fieldName`.
|
|
25
|
+
*/
|
|
26
|
+
name(name: string): PropertyOptionsBuilder<Value>;
|
|
27
|
+
/**
|
|
28
|
+
* Specify database column name for this property.
|
|
29
|
+
*
|
|
30
|
+
* @see https://mikro-orm.io/docs/naming-strategy
|
|
31
|
+
*/
|
|
32
|
+
fieldName(fieldName: string): PropertyOptionsBuilder<Value>;
|
|
33
|
+
/**
|
|
34
|
+
* Specify database column names for this property.
|
|
35
|
+
* Same as `fieldName` but for composite FKs.
|
|
36
|
+
*
|
|
37
|
+
* @see https://mikro-orm.io/docs/naming-strategy
|
|
38
|
+
*/
|
|
39
|
+
fieldNames(...fieldNames: string[]): PropertyOptionsBuilder<Value>;
|
|
40
|
+
/**
|
|
41
|
+
* 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)
|
|
42
|
+
*/
|
|
43
|
+
columnType(columnType: ColumnType | AnyString): PropertyOptionsBuilder<Value>;
|
|
44
|
+
/**
|
|
45
|
+
* 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)
|
|
46
|
+
*/
|
|
47
|
+
columnTypes(...columnTypes: (ColumnType | AnyString)[]): PropertyOptionsBuilder<Value>;
|
|
48
|
+
/**
|
|
49
|
+
* Explicitly specify the runtime type.
|
|
50
|
+
*
|
|
51
|
+
* @see https://mikro-orm.io/docs/metadata-providers
|
|
52
|
+
* @see https://mikro-orm.io/docs/custom-types
|
|
53
|
+
*/
|
|
54
|
+
type<TType extends PropertyValueType>(type: TType): PropertyOptionsBuilder<InferPropertyValueType<TType>>;
|
|
55
|
+
/**
|
|
56
|
+
* 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`.
|
|
57
|
+
* 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`.
|
|
58
|
+
*/
|
|
59
|
+
runtimeType(runtimeType: string): PropertyOptionsBuilder<Value>;
|
|
60
|
+
/**
|
|
61
|
+
* 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)
|
|
62
|
+
*/
|
|
63
|
+
length(length: number): PropertyOptionsBuilder<Value>;
|
|
64
|
+
/**
|
|
65
|
+
* Set precision of database column to represent the number of significant digits. (SQL only)
|
|
66
|
+
*/
|
|
67
|
+
precision(precision: number): PropertyOptionsBuilder<Value>;
|
|
68
|
+
/**
|
|
69
|
+
* Set scale of database column to represents the number of digits after the decimal point. (SQL only)
|
|
70
|
+
*/
|
|
71
|
+
scale(scale: number): PropertyOptionsBuilder<Value>;
|
|
72
|
+
/**
|
|
73
|
+
* Explicitly specify the auto increment of the primary key.
|
|
74
|
+
*/
|
|
75
|
+
autoincrement(autoincrement?: boolean): PropertyOptionsBuilder<Value>;
|
|
76
|
+
/**
|
|
77
|
+
* Add the property to the `returning` statement.
|
|
78
|
+
*/
|
|
79
|
+
returning(returning?: boolean): PropertyOptionsBuilder<Value>;
|
|
80
|
+
/**
|
|
81
|
+
* Automatically set the property value when entity gets created, executed during flush operation.
|
|
82
|
+
* @param entity
|
|
83
|
+
*/
|
|
84
|
+
onCreate(onCreate: (entity: any, em: EntityManager) => Value): PropertyOptionsBuilder<Opt<Value>>;
|
|
85
|
+
/**
|
|
86
|
+
* Automatically update the property value every time entity gets updated, executed during flush operation.
|
|
87
|
+
* @param entity
|
|
88
|
+
*/
|
|
89
|
+
onUpdate(onUpdate: (entity: any, em: EntityManager) => Value): PropertyOptionsBuilder<Value>;
|
|
90
|
+
/**
|
|
91
|
+
* Specify default column value for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
|
|
92
|
+
* This is a runtime value, assignable to the entity property. (SQL only)
|
|
93
|
+
*/
|
|
94
|
+
default(defaultValue: string | string[] | number | number[] | boolean | null): PropertyOptionsBuilder<Opt<Value>>;
|
|
95
|
+
/**
|
|
96
|
+
* Specify SQL functions for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
97
|
+
* Since v4 you should use defaultRaw for SQL functions. e.g. now()
|
|
98
|
+
*/
|
|
99
|
+
defaultRaw(defaultRaw: string): PropertyOptionsBuilder<Value>;
|
|
100
|
+
/**
|
|
101
|
+
* Set to map some SQL snippet for the entity.
|
|
102
|
+
*
|
|
103
|
+
* @see https://mikro-orm.io/docs/defining-entities#formulas Formulas
|
|
104
|
+
*/
|
|
105
|
+
formula(formula: string | ((alias: string) => string)): PropertyOptionsBuilder<Value>;
|
|
106
|
+
/**
|
|
107
|
+
* For generated columns. This will be appended to the column type after the `generated always` clause.
|
|
108
|
+
*/
|
|
109
|
+
generated(generated: string | GeneratedColumnCallback<any>): PropertyOptionsBuilder<Value>;
|
|
110
|
+
/**
|
|
111
|
+
* Set column as nullable for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
|
|
112
|
+
*/
|
|
113
|
+
nullable<T extends boolean = true>(nullable?: T): PropertyOptionsBuilder<T extends true ? Value extends ScalarReference<infer InnerValue> ? ScalarReference<InnerValue | null> : Value | null | undefined : NonNullable<Value>>;
|
|
114
|
+
/**
|
|
115
|
+
* Set column as unsigned for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
116
|
+
*/
|
|
117
|
+
unsigned(unsigned?: boolean): PropertyOptionsBuilder<Value>;
|
|
118
|
+
/**
|
|
119
|
+
* Set false to define {@link https://mikro-orm.io/docs/serializing#shadow-properties Shadow Property}.
|
|
120
|
+
*/
|
|
121
|
+
persist(persist?: boolean): PropertyOptionsBuilder<Value>;
|
|
122
|
+
/**
|
|
123
|
+
* Set false to disable hydration of this property. Useful for persisted getters.
|
|
124
|
+
*/
|
|
125
|
+
hydrate(hydrate?: boolean): PropertyOptionsBuilder<Value>;
|
|
126
|
+
/**
|
|
127
|
+
* 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.
|
|
128
|
+
*/
|
|
129
|
+
ref<T extends boolean = true>(ref?: T): PropertyOptionsBuilder<T extends true ? ScalarReference<Value> : UnwrapRef<Value>>;
|
|
130
|
+
/**
|
|
131
|
+
* Set false to disable change tracking on a property level.
|
|
132
|
+
*
|
|
133
|
+
* @see https://mikro-orm.io/docs/unit-of-work#change-tracking-and-performance-considerations
|
|
134
|
+
*/
|
|
135
|
+
trackChanges(trackChanges?: boolean): PropertyOptionsBuilder<Value>;
|
|
136
|
+
/**
|
|
137
|
+
* Set to true to omit the property when {@link https://mikro-orm.io/docs/serializing Serializing}.
|
|
138
|
+
*/
|
|
139
|
+
hidden<T extends boolean = true>(hidden?: T): PropertyOptionsBuilder<T extends true ? Hidden<Value> : Value>;
|
|
140
|
+
/**
|
|
141
|
+
* Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via version field. (SQL only)
|
|
142
|
+
*/
|
|
143
|
+
version(version?: boolean): PropertyOptionsBuilder<Value>;
|
|
144
|
+
/**
|
|
145
|
+
* Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via concurrency fields.
|
|
146
|
+
*/
|
|
147
|
+
concurrencyCheck(concurrencyCheck?: boolean): PropertyOptionsBuilder<Value>;
|
|
148
|
+
/**
|
|
149
|
+
* Explicitly specify index on a property.
|
|
150
|
+
*/
|
|
151
|
+
index(index?: boolean | string): PropertyOptionsBuilder<Value>;
|
|
152
|
+
/**
|
|
153
|
+
* Set column as unique for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
154
|
+
*/
|
|
155
|
+
unique(unique?: boolean | string): PropertyOptionsBuilder<Value>;
|
|
156
|
+
/**
|
|
157
|
+
* Specify column with check constraints. (Postgres driver only)
|
|
158
|
+
*
|
|
159
|
+
* @see https://mikro-orm.io/docs/defining-entities#check-constraints
|
|
160
|
+
*/
|
|
161
|
+
check(check: string | CheckCallback<any>): PropertyOptionsBuilder<Value>;
|
|
162
|
+
/**
|
|
163
|
+
* Set to omit the property from the select clause for lazy loading.
|
|
164
|
+
*
|
|
165
|
+
* @see https://mikro-orm.io/docs/defining-entities#lazy-scalar-properties
|
|
166
|
+
*/
|
|
167
|
+
lazy<T extends boolean = true>(lazy?: boolean, ref?: T): PropertyOptionsBuilder<T extends true ? ScalarReference<Value> : UnwrapRef<Value>>;
|
|
168
|
+
/**
|
|
169
|
+
* Set true to define entity's unique primary key identifier.
|
|
170
|
+
*
|
|
171
|
+
* @see https://mikro-orm.io/docs/decorators#primarykey
|
|
172
|
+
*/
|
|
173
|
+
primary(primary?: boolean): PropertyOptionsBuilder<Value>;
|
|
174
|
+
/**
|
|
175
|
+
* Set true to define the properties as setter. (virtual)
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```
|
|
179
|
+
* @Property({ setter: true })
|
|
180
|
+
* set address(value: string) {
|
|
181
|
+
* this._address = value.toLocaleLowerCase();
|
|
182
|
+
* }
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
setter(setter?: boolean): PropertyOptionsBuilder<Value>;
|
|
186
|
+
/**
|
|
187
|
+
* Set true to define the properties as getter. (virtual)
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```
|
|
191
|
+
* @Property({ getter: true })
|
|
192
|
+
* get fullName() {
|
|
193
|
+
* return this.firstName + this.lastName;
|
|
194
|
+
* }
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
getter(getter?: boolean): PropertyOptionsBuilder<Value>;
|
|
198
|
+
/**
|
|
199
|
+
* When defining a property over a method (not a getter, a regular function), you can use this option to point
|
|
200
|
+
* to the method name.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```
|
|
204
|
+
* @Property({ getter: true })
|
|
205
|
+
* getFullName() {
|
|
206
|
+
* return this.firstName + this.lastName;
|
|
207
|
+
* }
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
getterName(getterName: string): PropertyOptionsBuilder<Value>;
|
|
211
|
+
/**
|
|
212
|
+
* Set to define serialized primary key for MongoDB. (virtual)
|
|
213
|
+
* Alias for `@SerializedPrimaryKey()` decorator.
|
|
214
|
+
*
|
|
215
|
+
* @see https://mikro-orm.io/docs/decorators#serializedprimarykey
|
|
216
|
+
*/
|
|
217
|
+
serializedPrimaryKey(serializedPrimaryKey?: boolean): PropertyOptionsBuilder<Value>;
|
|
218
|
+
/**
|
|
219
|
+
* Set to use serialize property. Allow to specify a callback that will be used when serializing a property.
|
|
220
|
+
*
|
|
221
|
+
* @see https://mikro-orm.io/docs/serializing#property-serializers
|
|
222
|
+
*/
|
|
223
|
+
serializer(serializer: (value: Value, options?: SerializeOptions<any>) => any): PropertyOptionsBuilder<Value>;
|
|
224
|
+
/**
|
|
225
|
+
* Specify name of key for the serialized value.
|
|
226
|
+
*/
|
|
227
|
+
serializedName(serializedName: string): PropertyOptionsBuilder<Value>;
|
|
228
|
+
/**
|
|
229
|
+
* Specify serialization groups for `serialize()` calls. If a property does not specify any group, it will be included,
|
|
230
|
+
* otherwise only properties with a matching group are included.
|
|
231
|
+
*/
|
|
232
|
+
groups(...groups: string[]): PropertyOptionsBuilder<Value>;
|
|
233
|
+
/**
|
|
234
|
+
* Specify a custom order based on the values. (SQL only)
|
|
235
|
+
*/
|
|
236
|
+
customOrder(...customOrder: (string[] | number[] | boolean[])): PropertyOptionsBuilder<Value>;
|
|
237
|
+
/**
|
|
238
|
+
* Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
239
|
+
*/
|
|
240
|
+
comment(comment: string): PropertyOptionsBuilder<Value>;
|
|
241
|
+
/** mysql only */
|
|
242
|
+
extra(extra: string): PropertyOptionsBuilder<Value>;
|
|
243
|
+
/**
|
|
244
|
+
* Set to avoid a perpetual diff from the {@link https://mikro-orm.io/docs/schema-generator Schema Generator} when columns are generated.
|
|
245
|
+
*
|
|
246
|
+
* @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
|
|
247
|
+
*/
|
|
248
|
+
ignoreSchemaChanges(...ignoreSchemaChanges: ('type' | 'extra' | 'default')[]): PropertyOptionsBuilder<Value>;
|
|
249
|
+
/**
|
|
250
|
+
* Set the TypeScript type of the property.
|
|
251
|
+
*/
|
|
252
|
+
$type<T>(): PropertyOptionsBuilder<T>;
|
|
253
|
+
/**
|
|
254
|
+
* Set the TypeScript type for custom types that map to objects.
|
|
255
|
+
* This method provides type safety for custom types by specifying the runtime type,
|
|
256
|
+
* raw database value type, and optional serialized type.
|
|
257
|
+
*
|
|
258
|
+
* @template Runtime - The runtime type that the property will have in JavaScript
|
|
259
|
+
* @template Raw - The raw value type as stored in the database
|
|
260
|
+
* @template Serialized - The type when serialized (defaults to Raw)
|
|
261
|
+
* @returns PropertyOptionsBuilder with IType wrapper for type safety
|
|
262
|
+
*/
|
|
263
|
+
$type<Runtime, Raw, Serialized = Raw>(): PropertyOptionsBuilder<IType<Runtime, Raw, Serialized>>;
|
|
264
|
+
}
|
|
265
|
+
declare class EnumOptionsBuilder<Value> extends PropertyOptionsBuilder<Value> {
|
|
266
|
+
'~options': {
|
|
267
|
+
enum: true;
|
|
268
|
+
} & EnumOptions<any>;
|
|
269
|
+
constructor(options: EnumOptionsBuilder<Value>['~options']);
|
|
270
|
+
array<T extends boolean = true>(array?: T): EnumOptionsBuilder<T extends true ? Value[] : UnwrapArray<Value>>;
|
|
271
|
+
/** for postgres, by default it uses text column with check constraint */
|
|
272
|
+
nativeEnumName(nativeEnumName: string): EnumOptionsBuilder<Value>;
|
|
273
|
+
}
|
|
274
|
+
declare class EmbeddedOptionsBuilder<Value> extends PropertyOptionsBuilder<Value> {
|
|
275
|
+
'~options': ({
|
|
276
|
+
kind: 'embedded';
|
|
277
|
+
entity: () => EntitySchema<any, any> | EntitySchema<any, any>[];
|
|
278
|
+
} & EmbeddedOptions<any, any> & PropertyOptions<any>);
|
|
279
|
+
constructor(options: EmbeddedOptionsBuilder<Value>['~options']);
|
|
280
|
+
prefix(prefix: string): EmbeddedOptionsBuilder<Value>;
|
|
281
|
+
prefixMode(prefixMode: EmbeddedPrefixMode): EmbeddedOptionsBuilder<Value>;
|
|
282
|
+
object(object?: boolean): EmbeddedOptionsBuilder<Value>;
|
|
283
|
+
array<T extends boolean = true>(array?: T): EmbeddedOptionsBuilder<T extends true ? Value[] : UnwrapArray<Value>>;
|
|
284
|
+
}
|
|
285
|
+
declare class ReferenceOptionsBuilder<Value extends object> extends PropertyOptionsBuilder<Value> {
|
|
286
|
+
'~options': ReferenceOptions<any, any>;
|
|
287
|
+
constructor(options: ReferenceOptionsBuilder<Value>['~options']);
|
|
288
|
+
/** Set what actions on owning entity should be cascaded to the relationship. Defaults to [Cascade.PERSIST, Cascade.MERGE] (see {@doclink cascading}). */
|
|
289
|
+
cascade(...cascade: Cascade[]): ReferenceOptionsBuilder<Value>;
|
|
290
|
+
/** Always load the relationship. Discouraged for use with to-many relations for performance reasons. */
|
|
291
|
+
eager(eager?: boolean): ReferenceOptionsBuilder<Value>;
|
|
292
|
+
/** Override the default loading strategy for this property. This option has precedence over the global `loadStrategy`, but can be overridden by `FindOptions.strategy`. */
|
|
293
|
+
strategy(strategy: LoadStrategy | `${LoadStrategy}`): ReferenceOptionsBuilder<Value>;
|
|
294
|
+
/**
|
|
295
|
+
* @internal
|
|
296
|
+
* re-declare to override type inference
|
|
297
|
+
*/
|
|
298
|
+
ref(ref?: boolean): ReferenceOptionsBuilder<any>;
|
|
299
|
+
/**
|
|
300
|
+
* @internal
|
|
301
|
+
* re-declare to override type inference
|
|
302
|
+
*/
|
|
303
|
+
primary(primary?: boolean): ReferenceOptionsBuilder<any>;
|
|
304
|
+
}
|
|
305
|
+
declare class ManyToManyOptionsBuilder<TargetValue extends object> extends ReferenceOptionsBuilder<TargetValue> {
|
|
306
|
+
'~options': ({
|
|
307
|
+
kind: 'm:n';
|
|
308
|
+
entity: () => EntitySchema<any, any>;
|
|
309
|
+
} & ManyToManyOptions<any, UnwrapCollection<TargetValue>>);
|
|
310
|
+
constructor(options: ManyToManyOptionsBuilder<TargetValue>['~options']);
|
|
311
|
+
/** 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. */
|
|
312
|
+
owner(owner?: boolean): ManyToManyOptionsBuilder<TargetValue>;
|
|
313
|
+
/** Point to the inverse side property name. */
|
|
314
|
+
inversedBy(inversedBy: (string & keyof UnwrapCollection<TargetValue>) | ((e: UnwrapCollection<TargetValue>) => any)): ManyToManyOptionsBuilder<TargetValue>;
|
|
315
|
+
/** Point to the owning side property name. */
|
|
316
|
+
mappedBy(mappedBy: string | ((e: any) => any)): ManyToManyOptionsBuilder<TargetValue>;
|
|
317
|
+
/** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
|
|
318
|
+
where(...where: FilterQuery<object>[]): ManyToManyOptionsBuilder<TargetValue>;
|
|
319
|
+
/** Set default ordering. */
|
|
320
|
+
orderBy(...orderBy: QueryOrderMap<object>[]): ManyToManyOptionsBuilder<TargetValue>;
|
|
321
|
+
/** Force stable insertion order of items in the collection (see {@doclink collections | Collections}). */
|
|
322
|
+
fixedOrder(fixedOrder?: boolean): ManyToManyOptionsBuilder<TargetValue>;
|
|
323
|
+
/** Override default order column name (`id`) for fixed ordering. */
|
|
324
|
+
fixedOrderColumn(fixedOrderColumn: string): ManyToManyOptionsBuilder<TargetValue>;
|
|
325
|
+
/** Override default name for pivot table (see {@doclink naming-strategy | Naming Strategy}). */
|
|
326
|
+
pivotTable(pivotTable: string): ManyToManyOptionsBuilder<TargetValue>;
|
|
327
|
+
/** Set pivot entity for this relation (see {@doclink collections#custom-pivot-table-entity | Custom pivot table entity}). */
|
|
328
|
+
pivotEntity(pivotEntity: string | (() => EntityName<any>)): ManyToManyOptionsBuilder<TargetValue>;
|
|
329
|
+
/** 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. */
|
|
330
|
+
joinColumn(joinColumn: string): ManyToManyOptionsBuilder<TargetValue>;
|
|
331
|
+
/** 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. */
|
|
332
|
+
joinColumns(...joinColumns: string[]): ManyToManyOptionsBuilder<TargetValue>;
|
|
333
|
+
/** 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. */
|
|
334
|
+
inverseJoinColumn(inverseJoinColumn: string): ManyToManyOptionsBuilder<TargetValue>;
|
|
335
|
+
/** 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. */
|
|
336
|
+
inverseJoinColumns(...inverseJoinColumns: string[]): ManyToManyOptionsBuilder<TargetValue>;
|
|
337
|
+
/** 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. */
|
|
338
|
+
referenceColumnName(referenceColumnName: string): ManyToManyOptionsBuilder<TargetValue>;
|
|
339
|
+
/** 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. */
|
|
340
|
+
referencedColumnNames(...referencedColumnNames: string[]): ManyToManyOptionsBuilder<TargetValue>;
|
|
341
|
+
/** What to do when the target entity gets deleted. */
|
|
342
|
+
deleteRule(deleteRule: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString): ManyToManyOptionsBuilder<TargetValue>;
|
|
343
|
+
/** What to do when the reference to the target entity gets updated. */
|
|
344
|
+
updateRule(updateRule: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString): ManyToManyOptionsBuilder<TargetValue>;
|
|
345
|
+
}
|
|
346
|
+
declare class ManyToOneOptionsBuilder<TargetValue extends object> extends ReferenceOptionsBuilder<TargetValue> {
|
|
347
|
+
'~options': ({
|
|
348
|
+
kind: 'm:1';
|
|
349
|
+
entity: () => EntitySchema<any, any>;
|
|
350
|
+
} & ManyToOneOptions<any, UnwrapRef<TargetValue>>);
|
|
351
|
+
constructor(options: ManyToOneOptionsBuilder<TargetValue>['~options']);
|
|
352
|
+
/** Point to the inverse side property name. */
|
|
353
|
+
inversedBy(inversedBy: (string & keyof UnwrapRef<TargetValue>) | ((e: UnwrapRef<TargetValue>) => any)): ManyToOneOptionsBuilder<TargetValue>;
|
|
354
|
+
/** Wrap the entity in {@apilink Reference} wrapper. */
|
|
355
|
+
ref<T extends boolean = true>(ref?: T): ManyToOneOptionsBuilder<T extends true ? Reference<TargetValue> : UnwrapRef<TargetValue>>;
|
|
356
|
+
/** Use this relation as a primary key. */
|
|
357
|
+
primary(primary?: boolean): ManyToOneOptionsBuilder<TargetValue>;
|
|
358
|
+
/** Map this relation to the primary key value instead of an entity. */
|
|
359
|
+
mapToPk(mapToPk?: boolean): ManyToOneOptionsBuilder<TargetValue>;
|
|
360
|
+
/** 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. */
|
|
361
|
+
joinColumn(joinColumn: string): ManyToOneOptionsBuilder<TargetValue>;
|
|
362
|
+
/** 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. */
|
|
363
|
+
joinColumns(...joinColumns: string[]): ManyToOneOptionsBuilder<TargetValue>;
|
|
364
|
+
/** 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. */
|
|
365
|
+
ownColumns(...ownColumns: string[]): ManyToOneOptionsBuilder<TargetValue>;
|
|
366
|
+
/** 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. */
|
|
367
|
+
referenceColumnName(referenceColumnName: string): ManyToOneOptionsBuilder<TargetValue>;
|
|
368
|
+
/** 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. */
|
|
369
|
+
referencedColumnNames(...referencedColumnNames: string[]): ManyToOneOptionsBuilder<TargetValue>;
|
|
370
|
+
/** What to do when the target entity gets deleted. */
|
|
371
|
+
deleteRule(deleteRule: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString): ManyToOneOptionsBuilder<TargetValue>;
|
|
372
|
+
/** What to do when the reference to the target entity gets updated. */
|
|
373
|
+
updateRule(updateRule: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString): ManyToOneOptionsBuilder<TargetValue>;
|
|
374
|
+
/** 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. */
|
|
375
|
+
deferMode(deferMode: DeferMode | `${DeferMode}`): ManyToOneOptionsBuilder<TargetValue>;
|
|
376
|
+
}
|
|
377
|
+
declare class OneToManyOptionsBuilder<TargetValue extends object> extends ReferenceOptionsBuilder<TargetValue> {
|
|
378
|
+
'~options': ({
|
|
379
|
+
kind: '1:m';
|
|
380
|
+
entity: () => EntitySchema<TargetValue>;
|
|
381
|
+
} & OneToManyOptions<any, UnwrapCollection<TargetValue>>);
|
|
382
|
+
constructor(options: OneToManyOptionsBuilder<TargetValue>['~options']);
|
|
383
|
+
/** Remove the entity when it gets disconnected from the relationship (see {@doclink cascading | Cascading}). */
|
|
384
|
+
orphanRemoval(orphanRemoval?: boolean): OneToManyOptionsBuilder<TargetValue>;
|
|
385
|
+
/** Set default ordering. */
|
|
386
|
+
orderBy(orderBy: QueryOrderMap<UnwrapCollection<TargetValue>> | QueryOrderMap<UnwrapCollection<TargetValue>>[]): OneToManyOptionsBuilder<TargetValue>;
|
|
387
|
+
/** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
|
|
388
|
+
where(where: FilterQuery<UnwrapCollection<TargetValue>>): OneToManyOptionsBuilder<TargetValue>;
|
|
389
|
+
/** 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. */
|
|
390
|
+
joinColumn(joinColumn: string): OneToManyOptionsBuilder<TargetValue>;
|
|
391
|
+
/** 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. */
|
|
392
|
+
joinColumns(...joinColumns: string[]): OneToManyOptionsBuilder<TargetValue>;
|
|
393
|
+
/** 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. */
|
|
394
|
+
inverseJoinColumn(inverseJoinColumn: string): OneToManyOptionsBuilder<TargetValue>;
|
|
395
|
+
/** 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. */
|
|
396
|
+
inverseJoinColumns(...inverseJoinColumns: string[]): OneToManyOptionsBuilder<TargetValue>;
|
|
397
|
+
/** 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. */
|
|
398
|
+
referenceColumnName(referenceColumnName: string): OneToManyOptionsBuilder<TargetValue>;
|
|
399
|
+
/** 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. */
|
|
400
|
+
referencedColumnNames(...referencedColumnNames: string[]): OneToManyOptionsBuilder<TargetValue>;
|
|
401
|
+
}
|
|
402
|
+
declare class OneToManyOptionsBuilderOnlyMappedBy<TargetValue extends object> {
|
|
403
|
+
'~options': ({
|
|
404
|
+
kind: '1:m';
|
|
405
|
+
entity: () => EntitySchema<TargetValue>;
|
|
406
|
+
} & Omit<OneToManyOptions<any, UnwrapCollection<TargetValue>>, 'mappedBy'>);
|
|
407
|
+
constructor(options: OneToManyOptionsBuilderOnlyMappedBy<TargetValue>['~options']);
|
|
408
|
+
/** Point to the owning side property name. */
|
|
409
|
+
mappedBy(mappedBy: (AnyString & keyof UnwrapCollection<TargetValue>) | ((e: UnwrapCollection<TargetValue>) => any)): OneToManyOptionsBuilder<TargetValue>;
|
|
410
|
+
}
|
|
411
|
+
declare class OneToOneOptionsBuilder<TargetValue extends object> extends ReferenceOptionsBuilder<TargetValue> {
|
|
412
|
+
'~options': ({
|
|
413
|
+
kind: '1:1';
|
|
414
|
+
entity: () => EntitySchema<any, any>;
|
|
415
|
+
} & OneToOneOptions<any, UnwrapRef<TargetValue>>);
|
|
416
|
+
constructor(options: OneToOneOptionsBuilder<TargetValue>['~options']);
|
|
417
|
+
/** 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. */
|
|
418
|
+
owner(owner?: boolean): OneToOneOptionsBuilder<TargetValue>;
|
|
419
|
+
/** Point to the inverse side property name. */
|
|
420
|
+
inversedBy(inversedBy: (string & keyof UnwrapRef<TargetValue>) | ((e: UnwrapRef<TargetValue>) => any)): OneToOneOptionsBuilder<TargetValue>;
|
|
421
|
+
/** Wrap the entity in {@apilink Reference} wrapper. */
|
|
422
|
+
ref<T extends boolean = true>(ref?: T): OneToOneOptionsBuilder<T extends true ? Reference<TargetValue> : UnwrapRef<TargetValue>>;
|
|
423
|
+
/** Use this relation as a primary key. */
|
|
424
|
+
primary(primary?: boolean): OneToOneOptionsBuilder<TargetValue>;
|
|
425
|
+
/** Map this relation to the primary key value instead of an entity. */
|
|
426
|
+
mapToPk(mapToPk?: boolean): OneToOneOptionsBuilder<TargetValue>;
|
|
427
|
+
/** 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. */
|
|
428
|
+
ownColumns(...ownColumns: string[]): OneToOneOptionsBuilder<TargetValue>;
|
|
429
|
+
/** What to do when the target entity gets deleted. */
|
|
430
|
+
deleteRule(deleteRule: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString): OneToOneOptionsBuilder<TargetValue>;
|
|
431
|
+
/** What to do when the reference to the target entity gets updated. */
|
|
432
|
+
updateRule(updateRule: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString): OneToOneOptionsBuilder<TargetValue>;
|
|
433
|
+
/** 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. */
|
|
434
|
+
deferMode(deferMode: DeferMode | `${DeferMode}`): OneToOneOptionsBuilder<TargetValue>;
|
|
435
|
+
}
|
|
436
|
+
declare const propertyBuilders: {
|
|
437
|
+
json: <T>() => PropertyOptionsBuilder<T>;
|
|
438
|
+
formula: <T>(formula: string | ((alias: string) => string)) => PropertyOptionsBuilder<T>;
|
|
439
|
+
type: <T extends PropertyValueType>(type: T) => PropertyOptionsBuilder<InferPropertyValueType<T>>;
|
|
440
|
+
enum: <const T extends (number | string)[] | (() => Dictionary)>(items?: T) => EnumOptionsBuilder<T extends () => Dictionary ? ValueOf<ReturnType<T>> : T extends (infer Value)[] ? Value : T>;
|
|
441
|
+
embedded: <Target extends EntitySchema<any, any> | EntitySchema<any, any>[]>(target: Target) => EmbeddedOptionsBuilder<InferEntity<Target extends (infer T)[] ? T : Target>>;
|
|
442
|
+
manyToMany: <Target extends EntitySchema<any, any>>(target: Target) => ManyToManyOptionsBuilder<Collection<InferEntity<Target>, object>>;
|
|
443
|
+
manyToOne: <Target extends EntitySchema<any, any>>(target: Target) => ManyToOneOptionsBuilder<Reference<InferEntity<Target>>>;
|
|
444
|
+
oneToMany: <Target extends EntitySchema<any, any>>(target: Target) => OneToManyOptionsBuilderOnlyMappedBy<Collection<InferEntity<Target>, object>>;
|
|
445
|
+
oneToOne: <Target extends EntitySchema<any, any>>(target: Target) => OneToOneOptionsBuilder<Reference<InferEntity<Target>>>;
|
|
446
|
+
date: () => PropertyOptionsBuilder<string>;
|
|
447
|
+
time: () => PropertyOptionsBuilder<any>;
|
|
448
|
+
datetime: () => PropertyOptionsBuilder<Date>;
|
|
449
|
+
bigint: () => PropertyOptionsBuilder<NonNullable<string | number | bigint | null | undefined>>;
|
|
450
|
+
blob: () => PropertyOptionsBuilder<NonNullable<Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike> | null>>;
|
|
451
|
+
uint8array: () => PropertyOptionsBuilder<Uint8Array<ArrayBufferLike>>;
|
|
452
|
+
array: () => PropertyOptionsBuilder<unknown[]>;
|
|
453
|
+
enumArray: () => PropertyOptionsBuilder<(string | number)[]>;
|
|
454
|
+
integer: () => PropertyOptionsBuilder<number>;
|
|
455
|
+
smallint: () => PropertyOptionsBuilder<number>;
|
|
456
|
+
tinyint: () => PropertyOptionsBuilder<number>;
|
|
457
|
+
mediumint: () => PropertyOptionsBuilder<number>;
|
|
458
|
+
float: () => PropertyOptionsBuilder<number>;
|
|
459
|
+
double: () => PropertyOptionsBuilder<NonNullable<string | number>>;
|
|
460
|
+
boolean: () => PropertyOptionsBuilder<number>;
|
|
461
|
+
decimal: () => PropertyOptionsBuilder<NonNullable<string | number>>;
|
|
462
|
+
character: () => PropertyOptionsBuilder<string>;
|
|
463
|
+
string: () => PropertyOptionsBuilder<string>;
|
|
464
|
+
uuid: () => PropertyOptionsBuilder<string>;
|
|
465
|
+
text: () => PropertyOptionsBuilder<string>;
|
|
466
|
+
interval: () => PropertyOptionsBuilder<string>;
|
|
467
|
+
unknown: () => PropertyOptionsBuilder<{}>;
|
|
468
|
+
};
|
|
469
|
+
export declare function defineEntity<Properties extends Record<string, any>>(meta: Omit<Partial<EntityMetadata<InferEntityFromProperties<Properties>>>, 'properties' | 'extends'> & {
|
|
470
|
+
name: string;
|
|
471
|
+
properties: Properties | ((properties: typeof propertyBuilders) => Properties);
|
|
472
|
+
}): EntitySchema<InferEntityFromProperties<Properties>, never>;
|
|
473
|
+
export declare namespace defineEntity {
|
|
474
|
+
var properties: {
|
|
475
|
+
json: <T>() => PropertyOptionsBuilder<T>;
|
|
476
|
+
formula: <T>(formula: string | ((alias: string) => string)) => PropertyOptionsBuilder<T>;
|
|
477
|
+
type: <T extends PropertyValueType>(type: T) => PropertyOptionsBuilder<InferPropertyValueType<T>>;
|
|
478
|
+
enum: <const T extends (number | string)[] | (() => Dictionary)>(items?: T) => EnumOptionsBuilder<T extends () => Dictionary ? ValueOf<ReturnType<T>> : T extends (infer Value)[] ? Value : T>;
|
|
479
|
+
embedded: <Target extends EntitySchema<any, any> | EntitySchema<any, any>[]>(target: Target) => EmbeddedOptionsBuilder<InferEntity<Target extends (infer T)[] ? T : Target>>;
|
|
480
|
+
manyToMany: <Target extends EntitySchema<any, any>>(target: Target) => ManyToManyOptionsBuilder<Collection<InferEntity<Target>, object>>;
|
|
481
|
+
manyToOne: <Target extends EntitySchema<any, any>>(target: Target) => ManyToOneOptionsBuilder<Reference<InferEntity<Target>>>;
|
|
482
|
+
oneToMany: <Target extends EntitySchema<any, any>>(target: Target) => OneToManyOptionsBuilderOnlyMappedBy<Collection<InferEntity<Target>, object>>;
|
|
483
|
+
oneToOne: <Target extends EntitySchema<any, any>>(target: Target) => OneToOneOptionsBuilder<Reference<InferEntity<Target>>>;
|
|
484
|
+
date: () => PropertyOptionsBuilder<string>;
|
|
485
|
+
time: () => PropertyOptionsBuilder<any>;
|
|
486
|
+
datetime: () => PropertyOptionsBuilder<Date>;
|
|
487
|
+
bigint: () => PropertyOptionsBuilder<NonNullable<string | number | bigint | null | undefined>>;
|
|
488
|
+
blob: () => PropertyOptionsBuilder<NonNullable<Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike> | null>>;
|
|
489
|
+
uint8array: () => PropertyOptionsBuilder<Uint8Array<ArrayBufferLike>>;
|
|
490
|
+
array: () => PropertyOptionsBuilder<unknown[]>;
|
|
491
|
+
enumArray: () => PropertyOptionsBuilder<(string | number)[]>;
|
|
492
|
+
integer: () => PropertyOptionsBuilder<number>;
|
|
493
|
+
smallint: () => PropertyOptionsBuilder<number>;
|
|
494
|
+
tinyint: () => PropertyOptionsBuilder<number>;
|
|
495
|
+
mediumint: () => PropertyOptionsBuilder<number>;
|
|
496
|
+
float: () => PropertyOptionsBuilder<number>;
|
|
497
|
+
double: () => PropertyOptionsBuilder<NonNullable<string | number>>;
|
|
498
|
+
boolean: () => PropertyOptionsBuilder<number>;
|
|
499
|
+
decimal: () => PropertyOptionsBuilder<NonNullable<string | number>>;
|
|
500
|
+
character: () => PropertyOptionsBuilder<string>;
|
|
501
|
+
string: () => PropertyOptionsBuilder<string>;
|
|
502
|
+
uuid: () => PropertyOptionsBuilder<string>;
|
|
503
|
+
text: () => PropertyOptionsBuilder<string>;
|
|
504
|
+
interval: () => PropertyOptionsBuilder<string>;
|
|
505
|
+
unknown: () => PropertyOptionsBuilder<{}>;
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
type PropertyValueType = PropertyOptions<any>['type'];
|
|
509
|
+
type InferPropertyValueType<T extends PropertyValueType> = T extends string ? InferTypeByString<T> : T extends NumberConstructor ? number : T extends StringConstructor ? string : T extends BooleanConstructor ? boolean : T extends DateConstructor ? Date : T extends ArrayConstructor ? string[] : T extends Constructor<infer TType> ? TType extends Type<infer TValue, any> ? NonNullable<TValue> : TType : T extends Type<infer TValue, any> ? NonNullable<TValue> : any;
|
|
510
|
+
type InferTypeByString<T extends string> = T extends keyof typeof types ? InferJSType<typeof types[T]> : InferColumnType<T>;
|
|
511
|
+
type InferJSType<T> = T extends typeof Type<infer TValue, any> ? NonNullable<TValue> : never;
|
|
512
|
+
type InferColumnType<T extends string> = T extends 'int' | 'int4' | 'integer' | 'bigint' | 'int8' | 'int2' | 'tinyint' | 'smallint' | 'mediumint' ? number : T extends 'double' | 'double precision' | 'real' | 'float8' | 'decimal' | 'numeric' | 'float' | 'float4' ? number : T extends 'datetime' | 'time' | 'time with time zone' | 'timestamp' | 'timestamp with time zone' | 'timetz' | 'timestamptz' | 'date' | 'interval' ? Date : T extends 'ObjectId' | 'objectId' | 'character varying' | 'varchar' | 'char' | 'character' | 'uuid' | 'text' | 'tinytext' | 'mediumtext' | 'longtext' | 'enum' ? string : T extends 'boolean' | 'bool' | 'bit' ? boolean : T extends 'blob' | 'tinyblob' | 'mediumblob' | 'longblob' | 'bytea' ? Buffer : T extends 'point' | 'line' | 'lseg' | 'box' | 'circle' | 'path' | 'polygon' | 'geometry' ? number[] : T extends 'tsvector' | 'tsquery' ? string[] : T extends 'json' | 'jsonb' ? any : any;
|
|
513
|
+
type InferEntityFromProperties<Properties extends Record<string, any>> = {
|
|
514
|
+
-readonly [K in keyof Properties]: Properties[K] extends (() => any) ? InferBuilderValue<ReturnType<Properties[K]>> : InferBuilderValue<Properties[K]>;
|
|
515
|
+
};
|
|
516
|
+
type InferBuilderValue<Builder> = Builder extends {
|
|
517
|
+
'~type'?: {
|
|
518
|
+
value: infer T;
|
|
519
|
+
};
|
|
520
|
+
} ? T : never;
|
|
521
|
+
type UnwrapRef<T> = T extends ScalarReference<any> ? UnwrapScalarReference<T> : T extends Reference<any> ? UnwrapReference<T> : T;
|
|
522
|
+
type UnwrapScalarReference<T extends ScalarReference<any>> = T extends ScalarReference<infer Value> ? Value : T;
|
|
523
|
+
type UnwrapReference<T extends Reference<any>> = T extends Reference<infer Value> ? Value : T;
|
|
524
|
+
type UnwrapCollection<T> = T extends Collection<infer Value> ? Value : T;
|
|
525
|
+
type UnwrapArray<T> = T extends (infer Value)[] ? Value : T;
|
|
526
|
+
type ValueOf<T extends Dictionary> = T[keyof T];
|
|
527
|
+
export type InferEntity<Schema> = Schema extends EntitySchema<infer Entity, any> ? Entity : never;
|
|
528
|
+
export {};
|
|
@@ -0,0 +1,684 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineEntity = defineEntity;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
const EntitySchema_1 = require("../metadata/EntitySchema");
|
|
6
|
+
class PropertyOptionsBuilder {
|
|
7
|
+
'~options';
|
|
8
|
+
'~type';
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this['~options'] = options;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Alias for `fieldName`.
|
|
14
|
+
*/
|
|
15
|
+
name(name) {
|
|
16
|
+
return new PropertyOptionsBuilder({ ...this['~options'], name });
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Specify database column name for this property.
|
|
20
|
+
*
|
|
21
|
+
* @see https://mikro-orm.io/docs/naming-strategy
|
|
22
|
+
*/
|
|
23
|
+
fieldName(fieldName) {
|
|
24
|
+
return new PropertyOptionsBuilder({ ...this['~options'], fieldName });
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Specify database column names for this property.
|
|
28
|
+
* Same as `fieldName` but for composite FKs.
|
|
29
|
+
*
|
|
30
|
+
* @see https://mikro-orm.io/docs/naming-strategy
|
|
31
|
+
*/
|
|
32
|
+
fieldNames(...fieldNames) {
|
|
33
|
+
return new PropertyOptionsBuilder({ ...this['~options'], fieldNames });
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 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)
|
|
37
|
+
*/
|
|
38
|
+
columnType(columnType) {
|
|
39
|
+
return new PropertyOptionsBuilder({ ...this['~options'], columnType });
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 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)
|
|
43
|
+
*/
|
|
44
|
+
columnTypes(...columnTypes) {
|
|
45
|
+
return new PropertyOptionsBuilder({ ...this['~options'], columnTypes });
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Explicitly specify the runtime type.
|
|
49
|
+
*
|
|
50
|
+
* @see https://mikro-orm.io/docs/metadata-providers
|
|
51
|
+
* @see https://mikro-orm.io/docs/custom-types
|
|
52
|
+
*/
|
|
53
|
+
type(type) {
|
|
54
|
+
return new PropertyOptionsBuilder({ ...this['~options'], type });
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 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`.
|
|
58
|
+
* 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`.
|
|
59
|
+
*/
|
|
60
|
+
runtimeType(runtimeType) {
|
|
61
|
+
return new PropertyOptionsBuilder({ ...this['~options'], runtimeType });
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 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)
|
|
65
|
+
*/
|
|
66
|
+
length(length) {
|
|
67
|
+
return new PropertyOptionsBuilder({ ...this['~options'], length });
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Set precision of database column to represent the number of significant digits. (SQL only)
|
|
71
|
+
*/
|
|
72
|
+
precision(precision) {
|
|
73
|
+
return new PropertyOptionsBuilder({ ...this['~options'], precision });
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Set scale of database column to represents the number of digits after the decimal point. (SQL only)
|
|
77
|
+
*/
|
|
78
|
+
scale(scale) {
|
|
79
|
+
return new PropertyOptionsBuilder({ ...this['~options'], scale });
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Explicitly specify the auto increment of the primary key.
|
|
83
|
+
*/
|
|
84
|
+
autoincrement(autoincrement = true) {
|
|
85
|
+
return new PropertyOptionsBuilder({ ...this['~options'], autoincrement });
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Add the property to the `returning` statement.
|
|
89
|
+
*/
|
|
90
|
+
returning(returning = true) {
|
|
91
|
+
return new PropertyOptionsBuilder({ ...this['~options'], returning });
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Automatically set the property value when entity gets created, executed during flush operation.
|
|
95
|
+
* @param entity
|
|
96
|
+
*/
|
|
97
|
+
onCreate(onCreate) {
|
|
98
|
+
return new PropertyOptionsBuilder({ ...this['~options'], onCreate });
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Automatically update the property value every time entity gets updated, executed during flush operation.
|
|
102
|
+
* @param entity
|
|
103
|
+
*/
|
|
104
|
+
onUpdate(onUpdate) {
|
|
105
|
+
return new PropertyOptionsBuilder({ ...this['~options'], onUpdate });
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Specify default column value for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
|
|
109
|
+
* This is a runtime value, assignable to the entity property. (SQL only)
|
|
110
|
+
*/
|
|
111
|
+
default(defaultValue) {
|
|
112
|
+
return new PropertyOptionsBuilder({ ...this['~options'], default: defaultValue });
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Specify SQL functions for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
116
|
+
* Since v4 you should use defaultRaw for SQL functions. e.g. now()
|
|
117
|
+
*/
|
|
118
|
+
defaultRaw(defaultRaw) {
|
|
119
|
+
return new PropertyOptionsBuilder({ ...this['~options'], defaultRaw });
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Set to map some SQL snippet for the entity.
|
|
123
|
+
*
|
|
124
|
+
* @see https://mikro-orm.io/docs/defining-entities#formulas Formulas
|
|
125
|
+
*/
|
|
126
|
+
formula(formula) {
|
|
127
|
+
return new PropertyOptionsBuilder({ ...this['~options'], formula });
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* For generated columns. This will be appended to the column type after the `generated always` clause.
|
|
131
|
+
*/
|
|
132
|
+
generated(generated) {
|
|
133
|
+
return new PropertyOptionsBuilder({ ...this['~options'], generated });
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Set column as nullable for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
|
|
137
|
+
*/
|
|
138
|
+
nullable(nullable = true) {
|
|
139
|
+
return new PropertyOptionsBuilder({ ...this['~options'], nullable });
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Set column as unsigned for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
143
|
+
*/
|
|
144
|
+
unsigned(unsigned = true) {
|
|
145
|
+
return new PropertyOptionsBuilder({ ...this['~options'], unsigned });
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Set false to define {@link https://mikro-orm.io/docs/serializing#shadow-properties Shadow Property}.
|
|
149
|
+
*/
|
|
150
|
+
persist(persist = true) {
|
|
151
|
+
return new PropertyOptionsBuilder({ ...this['~options'], persist });
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Set false to disable hydration of this property. Useful for persisted getters.
|
|
155
|
+
*/
|
|
156
|
+
hydrate(hydrate = true) {
|
|
157
|
+
return new PropertyOptionsBuilder({ ...this['~options'], hydrate });
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 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.
|
|
161
|
+
*/
|
|
162
|
+
ref(ref = true) {
|
|
163
|
+
return new PropertyOptionsBuilder({ ...this['~options'], ref });
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Set false to disable change tracking on a property level.
|
|
167
|
+
*
|
|
168
|
+
* @see https://mikro-orm.io/docs/unit-of-work#change-tracking-and-performance-considerations
|
|
169
|
+
*/
|
|
170
|
+
trackChanges(trackChanges = true) {
|
|
171
|
+
return new PropertyOptionsBuilder({ ...this['~options'], trackChanges });
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Set to true to omit the property when {@link https://mikro-orm.io/docs/serializing Serializing}.
|
|
175
|
+
*/
|
|
176
|
+
hidden(hidden = true) {
|
|
177
|
+
return new PropertyOptionsBuilder({ ...this['~options'], hidden });
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via version field. (SQL only)
|
|
181
|
+
*/
|
|
182
|
+
version(version = true) {
|
|
183
|
+
return new PropertyOptionsBuilder({ ...this['~options'], version });
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via concurrency fields.
|
|
187
|
+
*/
|
|
188
|
+
concurrencyCheck(concurrencyCheck = true) {
|
|
189
|
+
return new PropertyOptionsBuilder({ ...this['~options'], concurrencyCheck });
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Explicitly specify index on a property.
|
|
193
|
+
*/
|
|
194
|
+
index(index = true) {
|
|
195
|
+
return new PropertyOptionsBuilder({ ...this['~options'], index });
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Set column as unique for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
199
|
+
*/
|
|
200
|
+
unique(unique = true) {
|
|
201
|
+
return new PropertyOptionsBuilder({ ...this['~options'], unique });
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Specify column with check constraints. (Postgres driver only)
|
|
205
|
+
*
|
|
206
|
+
* @see https://mikro-orm.io/docs/defining-entities#check-constraints
|
|
207
|
+
*/
|
|
208
|
+
check(check) {
|
|
209
|
+
return new PropertyOptionsBuilder({ ...this['~options'], check });
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Set to omit the property from the select clause for lazy loading.
|
|
213
|
+
*
|
|
214
|
+
* @see https://mikro-orm.io/docs/defining-entities#lazy-scalar-properties
|
|
215
|
+
*/
|
|
216
|
+
lazy(lazy = true, ref = true) {
|
|
217
|
+
return new PropertyOptionsBuilder({ ...this['~options'], lazy, ref });
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Set true to define entity's unique primary key identifier.
|
|
221
|
+
*
|
|
222
|
+
* @see https://mikro-orm.io/docs/decorators#primarykey
|
|
223
|
+
*/
|
|
224
|
+
primary(primary = true) {
|
|
225
|
+
return new PropertyOptionsBuilder({ ...this['~options'], primary });
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Set true to define the properties as setter. (virtual)
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```
|
|
232
|
+
* @Property({ setter: true })
|
|
233
|
+
* set address(value: string) {
|
|
234
|
+
* this._address = value.toLocaleLowerCase();
|
|
235
|
+
* }
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
setter(setter = true) {
|
|
239
|
+
return new PropertyOptionsBuilder({ ...this['~options'], setter });
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Set true to define the properties as getter. (virtual)
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```
|
|
246
|
+
* @Property({ getter: true })
|
|
247
|
+
* get fullName() {
|
|
248
|
+
* return this.firstName + this.lastName;
|
|
249
|
+
* }
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
getter(getter = true) {
|
|
253
|
+
return new PropertyOptionsBuilder({ ...this['~options'], getter });
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* When defining a property over a method (not a getter, a regular function), you can use this option to point
|
|
257
|
+
* to the method name.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```
|
|
261
|
+
* @Property({ getter: true })
|
|
262
|
+
* getFullName() {
|
|
263
|
+
* return this.firstName + this.lastName;
|
|
264
|
+
* }
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
getterName(getterName) {
|
|
268
|
+
return new PropertyOptionsBuilder({ ...this['~options'], getterName });
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Set to define serialized primary key for MongoDB. (virtual)
|
|
272
|
+
* Alias for `@SerializedPrimaryKey()` decorator.
|
|
273
|
+
*
|
|
274
|
+
* @see https://mikro-orm.io/docs/decorators#serializedprimarykey
|
|
275
|
+
*/
|
|
276
|
+
serializedPrimaryKey(serializedPrimaryKey = true) {
|
|
277
|
+
return new PropertyOptionsBuilder({ ...this['~options'], serializedPrimaryKey });
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Set to use serialize property. Allow to specify a callback that will be used when serializing a property.
|
|
281
|
+
*
|
|
282
|
+
* @see https://mikro-orm.io/docs/serializing#property-serializers
|
|
283
|
+
*/
|
|
284
|
+
serializer(serializer) {
|
|
285
|
+
return new PropertyOptionsBuilder({ ...this['~options'], serializer });
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Specify name of key for the serialized value.
|
|
289
|
+
*/
|
|
290
|
+
serializedName(serializedName) {
|
|
291
|
+
return new PropertyOptionsBuilder({ ...this['~options'], serializedName });
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Specify serialization groups for `serialize()` calls. If a property does not specify any group, it will be included,
|
|
295
|
+
* otherwise only properties with a matching group are included.
|
|
296
|
+
*/
|
|
297
|
+
groups(...groups) {
|
|
298
|
+
return new PropertyOptionsBuilder({ ...this['~options'], groups });
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Specify a custom order based on the values. (SQL only)
|
|
302
|
+
*/
|
|
303
|
+
customOrder(...customOrder) {
|
|
304
|
+
return new PropertyOptionsBuilder({ ...this['~options'], customOrder });
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
308
|
+
*/
|
|
309
|
+
comment(comment) {
|
|
310
|
+
return new PropertyOptionsBuilder({ ...this['~options'], comment });
|
|
311
|
+
}
|
|
312
|
+
/** mysql only */
|
|
313
|
+
extra(extra) {
|
|
314
|
+
return new PropertyOptionsBuilder({ ...this['~options'], extra });
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Set to avoid a perpetual diff from the {@link https://mikro-orm.io/docs/schema-generator Schema Generator} when columns are generated.
|
|
318
|
+
*
|
|
319
|
+
* @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
|
|
320
|
+
*/
|
|
321
|
+
ignoreSchemaChanges(...ignoreSchemaChanges) {
|
|
322
|
+
return new PropertyOptionsBuilder({ ...this['~options'], ignoreSchemaChanges });
|
|
323
|
+
}
|
|
324
|
+
$type() {
|
|
325
|
+
return new PropertyOptionsBuilder({ ...this['~options'] });
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
class EnumOptionsBuilder extends PropertyOptionsBuilder {
|
|
329
|
+
constructor(options) {
|
|
330
|
+
super(options);
|
|
331
|
+
this['~options'] = options;
|
|
332
|
+
}
|
|
333
|
+
array(array = true) {
|
|
334
|
+
return new EnumOptionsBuilder({ ...this['~options'], array });
|
|
335
|
+
}
|
|
336
|
+
/** for postgres, by default it uses text column with check constraint */
|
|
337
|
+
nativeEnumName(nativeEnumName) {
|
|
338
|
+
return new EnumOptionsBuilder({ ...this['~options'], nativeEnumName });
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
class EmbeddedOptionsBuilder extends PropertyOptionsBuilder {
|
|
342
|
+
constructor(options) {
|
|
343
|
+
super(options);
|
|
344
|
+
this['~options'] = options;
|
|
345
|
+
}
|
|
346
|
+
prefix(prefix) {
|
|
347
|
+
return new EmbeddedOptionsBuilder({ ...this['~options'], prefix });
|
|
348
|
+
}
|
|
349
|
+
prefixMode(prefixMode) {
|
|
350
|
+
return new EmbeddedOptionsBuilder({ ...this['~options'], prefixMode });
|
|
351
|
+
}
|
|
352
|
+
object(object = true) {
|
|
353
|
+
return new EmbeddedOptionsBuilder({ ...this['~options'], object });
|
|
354
|
+
}
|
|
355
|
+
array(array = true) {
|
|
356
|
+
return new EmbeddedOptionsBuilder({ ...this['~options'], array });
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
class ReferenceOptionsBuilder extends PropertyOptionsBuilder {
|
|
360
|
+
constructor(options) {
|
|
361
|
+
super(options);
|
|
362
|
+
this['~options'] = options;
|
|
363
|
+
}
|
|
364
|
+
/** Set what actions on owning entity should be cascaded to the relationship. Defaults to [Cascade.PERSIST, Cascade.MERGE] (see {@doclink cascading}). */
|
|
365
|
+
cascade(...cascade) {
|
|
366
|
+
return new ReferenceOptionsBuilder({ ...this['~options'], cascade });
|
|
367
|
+
}
|
|
368
|
+
/** Always load the relationship. Discouraged for use with to-many relations for performance reasons. */
|
|
369
|
+
eager(eager = true) {
|
|
370
|
+
return new ReferenceOptionsBuilder({ ...this['~options'], eager });
|
|
371
|
+
}
|
|
372
|
+
/** Override the default loading strategy for this property. This option has precedence over the global `loadStrategy`, but can be overridden by `FindOptions.strategy`. */
|
|
373
|
+
strategy(strategy) {
|
|
374
|
+
return new ReferenceOptionsBuilder({ ...this['~options'], strategy });
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* @internal
|
|
378
|
+
* re-declare to override type inference
|
|
379
|
+
*/
|
|
380
|
+
/* istanbul ignore next */
|
|
381
|
+
ref(ref = true) {
|
|
382
|
+
return new ReferenceOptionsBuilder({ ...this['~options'], ref });
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* @internal
|
|
386
|
+
* re-declare to override type inference
|
|
387
|
+
*/
|
|
388
|
+
/* istanbul ignore next */
|
|
389
|
+
primary(primary = true) {
|
|
390
|
+
return new ReferenceOptionsBuilder({ ...this['~options'], primary });
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
class ManyToManyOptionsBuilder extends ReferenceOptionsBuilder {
|
|
394
|
+
constructor(options) {
|
|
395
|
+
super(options);
|
|
396
|
+
this['~options'] = options;
|
|
397
|
+
}
|
|
398
|
+
/** 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. */
|
|
399
|
+
owner(owner = true) {
|
|
400
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], owner });
|
|
401
|
+
}
|
|
402
|
+
/** Point to the inverse side property name. */
|
|
403
|
+
inversedBy(inversedBy) {
|
|
404
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], inversedBy });
|
|
405
|
+
}
|
|
406
|
+
/** Point to the owning side property name. */
|
|
407
|
+
mappedBy(mappedBy) {
|
|
408
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], mappedBy });
|
|
409
|
+
}
|
|
410
|
+
/** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
|
|
411
|
+
where(...where) {
|
|
412
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], where: where });
|
|
413
|
+
}
|
|
414
|
+
/** Set default ordering. */
|
|
415
|
+
orderBy(...orderBy) {
|
|
416
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], orderBy });
|
|
417
|
+
}
|
|
418
|
+
/** Force stable insertion order of items in the collection (see {@doclink collections | Collections}). */
|
|
419
|
+
fixedOrder(fixedOrder = true) {
|
|
420
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], fixedOrder });
|
|
421
|
+
}
|
|
422
|
+
/** Override default order column name (`id`) for fixed ordering. */
|
|
423
|
+
fixedOrderColumn(fixedOrderColumn) {
|
|
424
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], fixedOrderColumn });
|
|
425
|
+
}
|
|
426
|
+
/** Override default name for pivot table (see {@doclink naming-strategy | Naming Strategy}). */
|
|
427
|
+
pivotTable(pivotTable) {
|
|
428
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], pivotTable });
|
|
429
|
+
}
|
|
430
|
+
/** Set pivot entity for this relation (see {@doclink collections#custom-pivot-table-entity | Custom pivot table entity}). */
|
|
431
|
+
pivotEntity(pivotEntity) {
|
|
432
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], pivotEntity });
|
|
433
|
+
}
|
|
434
|
+
/** 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. */
|
|
435
|
+
joinColumn(joinColumn) {
|
|
436
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], joinColumn });
|
|
437
|
+
}
|
|
438
|
+
/** 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. */
|
|
439
|
+
joinColumns(...joinColumns) {
|
|
440
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], joinColumns });
|
|
441
|
+
}
|
|
442
|
+
/** 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. */
|
|
443
|
+
inverseJoinColumn(inverseJoinColumn) {
|
|
444
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], inverseJoinColumn });
|
|
445
|
+
}
|
|
446
|
+
/** 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. */
|
|
447
|
+
inverseJoinColumns(...inverseJoinColumns) {
|
|
448
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], inverseJoinColumns });
|
|
449
|
+
}
|
|
450
|
+
/** 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. */
|
|
451
|
+
referenceColumnName(referenceColumnName) {
|
|
452
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], referenceColumnName });
|
|
453
|
+
}
|
|
454
|
+
/** 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. */
|
|
455
|
+
referencedColumnNames(...referencedColumnNames) {
|
|
456
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], referencedColumnNames });
|
|
457
|
+
}
|
|
458
|
+
/** What to do when the target entity gets deleted. */
|
|
459
|
+
deleteRule(deleteRule) {
|
|
460
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], deleteRule });
|
|
461
|
+
}
|
|
462
|
+
/** What to do when the reference to the target entity gets updated. */
|
|
463
|
+
updateRule(updateRule) {
|
|
464
|
+
return new ManyToManyOptionsBuilder({ ...this['~options'], updateRule });
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
class ManyToOneOptionsBuilder extends ReferenceOptionsBuilder {
|
|
468
|
+
constructor(options) {
|
|
469
|
+
super(options);
|
|
470
|
+
this['~options'] = options;
|
|
471
|
+
}
|
|
472
|
+
/** Point to the inverse side property name. */
|
|
473
|
+
inversedBy(inversedBy) {
|
|
474
|
+
return new ManyToOneOptionsBuilder({ ...this['~options'], inversedBy });
|
|
475
|
+
}
|
|
476
|
+
/** Wrap the entity in {@apilink Reference} wrapper. */
|
|
477
|
+
ref(ref = true) {
|
|
478
|
+
return new ManyToOneOptionsBuilder({ ...this['~options'], ref });
|
|
479
|
+
}
|
|
480
|
+
/** Use this relation as a primary key. */
|
|
481
|
+
primary(primary = true) {
|
|
482
|
+
return new ManyToOneOptionsBuilder({ ...this['~options'], primary });
|
|
483
|
+
}
|
|
484
|
+
/** Map this relation to the primary key value instead of an entity. */
|
|
485
|
+
mapToPk(mapToPk = true) {
|
|
486
|
+
return new ManyToOneOptionsBuilder({ ...this['~options'], mapToPk });
|
|
487
|
+
}
|
|
488
|
+
/** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
|
|
489
|
+
joinColumn(joinColumn) {
|
|
490
|
+
return new ManyToOneOptionsBuilder({ ...this['~options'], joinColumn });
|
|
491
|
+
}
|
|
492
|
+
/** 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. */
|
|
493
|
+
joinColumns(...joinColumns) {
|
|
494
|
+
return new ManyToOneOptionsBuilder({ ...this['~options'], joinColumns });
|
|
495
|
+
}
|
|
496
|
+
/** 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. */
|
|
497
|
+
ownColumns(...ownColumns) {
|
|
498
|
+
return new ManyToOneOptionsBuilder({ ...this['~options'], ownColumns });
|
|
499
|
+
}
|
|
500
|
+
/** 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. */
|
|
501
|
+
referenceColumnName(referenceColumnName) {
|
|
502
|
+
return new ManyToOneOptionsBuilder({ ...this['~options'], referenceColumnName });
|
|
503
|
+
}
|
|
504
|
+
/** 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. */
|
|
505
|
+
referencedColumnNames(...referencedColumnNames) {
|
|
506
|
+
return new ManyToOneOptionsBuilder({ ...this['~options'], referencedColumnNames });
|
|
507
|
+
}
|
|
508
|
+
/** What to do when the target entity gets deleted. */
|
|
509
|
+
deleteRule(deleteRule) {
|
|
510
|
+
return new ManyToOneOptionsBuilder({ ...this['~options'], deleteRule });
|
|
511
|
+
}
|
|
512
|
+
/** What to do when the reference to the target entity gets updated. */
|
|
513
|
+
updateRule(updateRule) {
|
|
514
|
+
return new ManyToOneOptionsBuilder({ ...this['~options'], updateRule });
|
|
515
|
+
}
|
|
516
|
+
/** 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. */
|
|
517
|
+
deferMode(deferMode) {
|
|
518
|
+
return new ManyToOneOptionsBuilder({ ...this['~options'], deferMode });
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
class OneToManyOptionsBuilder extends ReferenceOptionsBuilder {
|
|
522
|
+
constructor(options) {
|
|
523
|
+
super(options);
|
|
524
|
+
this['~options'] = options;
|
|
525
|
+
}
|
|
526
|
+
/** Remove the entity when it gets disconnected from the relationship (see {@doclink cascading | Cascading}). */
|
|
527
|
+
orphanRemoval(orphanRemoval = true) {
|
|
528
|
+
return new OneToManyOptionsBuilder({ ...this['~options'], orphanRemoval });
|
|
529
|
+
}
|
|
530
|
+
/** Set default ordering. */
|
|
531
|
+
orderBy(orderBy) {
|
|
532
|
+
return new OneToManyOptionsBuilder({ ...this['~options'], orderBy });
|
|
533
|
+
}
|
|
534
|
+
/** Condition for {@doclink collections#declarative-partial-loading | Declarative partial loading}. */
|
|
535
|
+
where(where) {
|
|
536
|
+
return new OneToManyOptionsBuilder({ ...this['~options'], where });
|
|
537
|
+
}
|
|
538
|
+
/** 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. */
|
|
539
|
+
joinColumn(joinColumn) {
|
|
540
|
+
return new OneToManyOptionsBuilder({ ...this['~options'], joinColumn });
|
|
541
|
+
}
|
|
542
|
+
/** 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. */
|
|
543
|
+
joinColumns(...joinColumns) {
|
|
544
|
+
return new OneToManyOptionsBuilder({ ...this['~options'], joinColumns });
|
|
545
|
+
}
|
|
546
|
+
/** 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. */
|
|
547
|
+
inverseJoinColumn(inverseJoinColumn) {
|
|
548
|
+
return new OneToManyOptionsBuilder({ ...this['~options'], inverseJoinColumn });
|
|
549
|
+
}
|
|
550
|
+
/** 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. */
|
|
551
|
+
inverseJoinColumns(...inverseJoinColumns) {
|
|
552
|
+
return new OneToManyOptionsBuilder({ ...this['~options'], inverseJoinColumns });
|
|
553
|
+
}
|
|
554
|
+
/** 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. */
|
|
555
|
+
referenceColumnName(referenceColumnName) {
|
|
556
|
+
return new OneToManyOptionsBuilder({ ...this['~options'], referenceColumnName });
|
|
557
|
+
}
|
|
558
|
+
/** 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. */
|
|
559
|
+
referencedColumnNames(...referencedColumnNames) {
|
|
560
|
+
return new OneToManyOptionsBuilder({ ...this['~options'], referencedColumnNames });
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
class OneToManyOptionsBuilderOnlyMappedBy {
|
|
564
|
+
constructor(options) {
|
|
565
|
+
this['~options'] = options;
|
|
566
|
+
}
|
|
567
|
+
/** Point to the owning side property name. */
|
|
568
|
+
mappedBy(mappedBy) {
|
|
569
|
+
return new OneToManyOptionsBuilder({ ...this['~options'], mappedBy });
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
class OneToOneOptionsBuilder extends ReferenceOptionsBuilder {
|
|
573
|
+
constructor(options) {
|
|
574
|
+
super(options);
|
|
575
|
+
this['~options'] = options;
|
|
576
|
+
}
|
|
577
|
+
/** 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. */
|
|
578
|
+
owner(owner = true) {
|
|
579
|
+
return new OneToOneOptionsBuilder({ ...this['~options'], owner });
|
|
580
|
+
}
|
|
581
|
+
/** Point to the inverse side property name. */
|
|
582
|
+
inversedBy(inversedBy) {
|
|
583
|
+
return new OneToOneOptionsBuilder({ ...this['~options'], inversedBy });
|
|
584
|
+
}
|
|
585
|
+
/** Wrap the entity in {@apilink Reference} wrapper. */
|
|
586
|
+
ref(ref = true) {
|
|
587
|
+
return new OneToOneOptionsBuilder({ ...this['~options'], ref });
|
|
588
|
+
}
|
|
589
|
+
/** Use this relation as a primary key. */
|
|
590
|
+
primary(primary = true) {
|
|
591
|
+
return new OneToOneOptionsBuilder({ ...this['~options'], primary });
|
|
592
|
+
}
|
|
593
|
+
/** Map this relation to the primary key value instead of an entity. */
|
|
594
|
+
mapToPk(mapToPk = true) {
|
|
595
|
+
return new OneToOneOptionsBuilder({ ...this['~options'], mapToPk });
|
|
596
|
+
}
|
|
597
|
+
/** 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. */
|
|
598
|
+
ownColumns(...ownColumns) {
|
|
599
|
+
return new OneToOneOptionsBuilder({ ...this['~options'], ownColumns });
|
|
600
|
+
}
|
|
601
|
+
/** What to do when the target entity gets deleted. */
|
|
602
|
+
deleteRule(deleteRule) {
|
|
603
|
+
return new OneToOneOptionsBuilder({ ...this['~options'], deleteRule });
|
|
604
|
+
}
|
|
605
|
+
/** What to do when the reference to the target entity gets updated. */
|
|
606
|
+
updateRule(updateRule) {
|
|
607
|
+
return new OneToOneOptionsBuilder({ ...this['~options'], updateRule });
|
|
608
|
+
}
|
|
609
|
+
/** 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. */
|
|
610
|
+
deferMode(deferMode) {
|
|
611
|
+
return new OneToOneOptionsBuilder({ ...this['~options'], deferMode });
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
function createPropertyBuilders(options) {
|
|
615
|
+
return Object.fromEntries(Object.entries(options).map(([key, value]) => [key, () => new PropertyOptionsBuilder({ type: value })]));
|
|
616
|
+
}
|
|
617
|
+
const propertyBuilders = {
|
|
618
|
+
...createPropertyBuilders(types_1.types),
|
|
619
|
+
json: () => new PropertyOptionsBuilder({ type: types_1.types.json }),
|
|
620
|
+
formula: (formula) => new PropertyOptionsBuilder({ formula }),
|
|
621
|
+
type: (type) => new PropertyOptionsBuilder({ type }),
|
|
622
|
+
enum: (items) => new EnumOptionsBuilder({
|
|
623
|
+
enum: true,
|
|
624
|
+
items,
|
|
625
|
+
}),
|
|
626
|
+
embedded: (target) => new EmbeddedOptionsBuilder({
|
|
627
|
+
entity: () => target,
|
|
628
|
+
kind: 'embedded',
|
|
629
|
+
}),
|
|
630
|
+
manyToMany: (target) => new ManyToManyOptionsBuilder({
|
|
631
|
+
entity: () => target,
|
|
632
|
+
kind: 'm:n',
|
|
633
|
+
}),
|
|
634
|
+
manyToOne: (target) => new ManyToOneOptionsBuilder({
|
|
635
|
+
entity: () => target,
|
|
636
|
+
kind: 'm:1',
|
|
637
|
+
ref: true,
|
|
638
|
+
}),
|
|
639
|
+
oneToMany: (target) => new OneToManyOptionsBuilderOnlyMappedBy({
|
|
640
|
+
entity: () => target,
|
|
641
|
+
kind: '1:m',
|
|
642
|
+
}),
|
|
643
|
+
oneToOne: (target) => new OneToOneOptionsBuilder({
|
|
644
|
+
entity: () => target,
|
|
645
|
+
kind: '1:1',
|
|
646
|
+
ref: true,
|
|
647
|
+
}),
|
|
648
|
+
};
|
|
649
|
+
function getBuilderOptions(builder) {
|
|
650
|
+
return '~options' in builder ? builder['~options'] : builder;
|
|
651
|
+
}
|
|
652
|
+
function defineEntity(meta) {
|
|
653
|
+
const { properties: propertiesOrGetter, ...options } = meta;
|
|
654
|
+
const propertyOptions = typeof propertiesOrGetter === 'function' ? propertiesOrGetter(propertyBuilders) : propertiesOrGetter;
|
|
655
|
+
const properties = {};
|
|
656
|
+
for (const [key, builder] of Object.entries(propertyOptions)) {
|
|
657
|
+
const values = new Map();
|
|
658
|
+
if (typeof builder === 'function') {
|
|
659
|
+
Object.defineProperty(properties, key, {
|
|
660
|
+
get: () => {
|
|
661
|
+
let value = values.get(key);
|
|
662
|
+
if (value === undefined) {
|
|
663
|
+
value = getBuilderOptions(builder());
|
|
664
|
+
values.set(key, value);
|
|
665
|
+
}
|
|
666
|
+
return value;
|
|
667
|
+
},
|
|
668
|
+
set: (value) => {
|
|
669
|
+
values.set(key, value);
|
|
670
|
+
},
|
|
671
|
+
enumerable: true,
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
else {
|
|
675
|
+
Object.defineProperty(properties, key, {
|
|
676
|
+
value: getBuilderOptions(builder),
|
|
677
|
+
writable: true,
|
|
678
|
+
enumerable: true,
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
return new EntitySchema_1.EntitySchema({ properties, ...options });
|
|
683
|
+
}
|
|
684
|
+
defineEntity.properties = propertyBuilders;
|
package/entity/index.d.ts
CHANGED
package/entity/index.js
CHANGED
|
@@ -65,7 +65,7 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
65
65
|
const ret = [];
|
|
66
66
|
const idx = this.tmpIndex++;
|
|
67
67
|
const nullVal = this.config.get('forceUndefined') ? 'undefined' : 'null';
|
|
68
|
-
if (prop.getter && !prop.setter) {
|
|
68
|
+
if (prop.getter && !prop.setter && prop.persist === false) {
|
|
69
69
|
return [];
|
|
70
70
|
}
|
|
71
71
|
if (prop.ref) {
|
package/index.mjs
CHANGED
|
@@ -182,6 +182,7 @@ export const compareBuffers = mod.compareBuffers;
|
|
|
182
182
|
export const compareObjects = mod.compareObjects;
|
|
183
183
|
export const createSqlFunction = mod.createSqlFunction;
|
|
184
184
|
export const defineConfig = mod.defineConfig;
|
|
185
|
+
export const defineEntity = mod.defineEntity;
|
|
185
186
|
export const equals = mod.equals;
|
|
186
187
|
export const getOnConflictFields = mod.getOnConflictFields;
|
|
187
188
|
export const getOnConflictReturningFields = mod.getOnConflictReturningFields;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.4.17-dev.
|
|
3
|
+
"version": "6.4.17-dev.26",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"esprima": "4.0.1",
|
|
65
65
|
"fs-extra": "11.3.0",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.4.17-dev.
|
|
67
|
+
"mikro-orm": "6.4.17-dev.26",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/typings.js
CHANGED
|
@@ -72,7 +72,7 @@ class EntityMetadata {
|
|
|
72
72
|
// `prop.userDefined` is either `undefined` or `false`
|
|
73
73
|
const discriminator = this.root.discriminatorColumn === prop.name && prop.userDefined === false;
|
|
74
74
|
// even if we don't have a setter, do not ignore value from database!
|
|
75
|
-
const onlyGetter = prop.getter && !prop.setter;
|
|
75
|
+
const onlyGetter = prop.getter && !prop.setter && prop.persist === false;
|
|
76
76
|
return !prop.inherited && prop.hydrate !== false && !discriminator && !prop.embedded && !onlyGetter;
|
|
77
77
|
});
|
|
78
78
|
this.trackingProps = this.hydrateProps
|