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