@mikro-orm/core 7.0.0-rc.1 → 7.0.0-rc.3
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/EntityManager.d.ts +3 -2
- package/EntityManager.js +107 -43
- package/MikroORM.js +4 -4
- package/cache/FileCacheAdapter.js +1 -3
- package/connections/Connection.js +16 -3
- package/drivers/DatabaseDriver.js +26 -8
- package/drivers/IDatabaseDriver.d.ts +49 -1
- package/entity/BaseEntity.d.ts +3 -3
- package/entity/Collection.js +43 -17
- package/entity/EntityAssigner.js +23 -11
- package/entity/EntityFactory.js +36 -13
- package/entity/EntityHelper.js +27 -18
- package/entity/EntityLoader.d.ts +6 -6
- package/entity/EntityLoader.js +55 -22
- package/entity/EntityRepository.d.ts +1 -1
- package/entity/Reference.d.ts +1 -1
- package/entity/Reference.js +37 -8
- package/entity/WrappedEntity.d.ts +3 -3
- package/entity/WrappedEntity.js +5 -1
- package/entity/defineEntity.d.ts +202 -58
- package/entity/defineEntity.js +20 -24
- package/entity/utils.js +28 -26
- package/entity/validators.js +2 -1
- package/enums.js +12 -17
- package/errors.js +18 -8
- package/events/EventManager.js +1 -1
- package/exceptions.js +7 -2
- package/hydration/ObjectHydrator.js +27 -13
- package/index.d.ts +2 -2
- package/index.js +1 -1
- package/logging/DefaultLogger.js +3 -5
- package/logging/colors.js +3 -6
- package/metadata/EntitySchema.d.ts +2 -2
- package/metadata/EntitySchema.js +12 -2
- package/metadata/MetadataDiscovery.js +107 -48
- package/metadata/MetadataProvider.js +26 -1
- package/metadata/MetadataStorage.js +2 -4
- package/metadata/MetadataValidator.js +20 -5
- package/metadata/types.d.ts +2 -2
- package/naming-strategy/AbstractNamingStrategy.js +5 -2
- package/not-supported.js +5 -1
- package/package.json +40 -37
- package/platforms/Platform.d.ts +4 -1
- package/platforms/Platform.js +50 -24
- package/serialization/EntitySerializer.d.ts +3 -3
- package/serialization/EntitySerializer.js +7 -3
- package/serialization/EntityTransformer.js +6 -4
- package/serialization/SerializationContext.js +1 -1
- package/typings.d.ts +73 -33
- package/typings.js +11 -9
- package/unit-of-work/ChangeSet.js +4 -4
- package/unit-of-work/ChangeSetComputer.js +8 -6
- package/unit-of-work/ChangeSetPersister.js +15 -10
- package/unit-of-work/CommitOrderCalculator.js +4 -2
- package/unit-of-work/UnitOfWork.d.ts +7 -1
- package/unit-of-work/UnitOfWork.js +51 -22
- package/utils/AbstractMigrator.d.ts +101 -0
- package/utils/AbstractMigrator.js +303 -0
- package/utils/AbstractSchemaGenerator.js +2 -1
- package/utils/AsyncContext.js +1 -1
- package/utils/Configuration.d.ts +3 -1
- package/utils/Configuration.js +8 -4
- package/utils/Cursor.js +4 -2
- package/utils/DataloaderUtils.js +15 -12
- package/utils/EntityComparator.js +51 -43
- package/utils/QueryHelper.js +38 -26
- package/utils/RawQueryFragment.js +3 -2
- package/utils/TransactionManager.js +2 -1
- package/utils/Utils.d.ts +1 -1
- package/utils/Utils.js +36 -30
- package/utils/env-vars.js +6 -5
- package/utils/fs-utils.d.ts +1 -0
- package/utils/fs-utils.js +6 -5
- package/utils/index.d.ts +0 -2
- package/utils/index.js +0 -2
- package/utils/upsert-utils.js +6 -3
package/entity/defineEntity.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EntityManager } from '../EntityManager.js';
|
|
2
2
|
import type { ColumnType, PropertyOptions, ReferenceOptions, EnumOptions, EmbeddedOptions, ManyToOneOptions, OneToManyOptions, OneToOneOptions, ManyToManyOptions } from '../metadata/types.js';
|
|
3
|
-
import type { AnyString, GeneratedColumnCallback, Constructor, CheckCallback, FilterQuery, EntityName, Dictionary, EntityMetadata, PrimaryKeyProp, EntityRepositoryType, Hidden, Opt, Primary, EntityClass, EntitySchemaWithMeta, InferEntity, MaybeReturnType, Ref, IndexCallback, FormulaCallback, EntityCtor, IsNever } from '../typings.js';
|
|
3
|
+
import type { AnyString, GeneratedColumnCallback, Constructor, CheckCallback, FilterQuery, EntityName, Dictionary, EntityMetadata, PrimaryKeyProp, EntityRepositoryType, Hidden, Opt, Primary, EntityClass, EntitySchemaWithMeta, InferEntity, MaybeReturnType, Ref, IndexCallback, FormulaCallback, EntityCtor, IsNever, IWrappedEntity, DefineConfig, Config } from '../typings.js';
|
|
4
4
|
import type { Raw } from '../utils/RawQueryFragment.js';
|
|
5
5
|
import type { ScalarReference } from './Reference.js';
|
|
6
6
|
import type { SerializeOptions } from '../serialization/EntitySerializer.js';
|
|
@@ -16,11 +16,135 @@ type ExcludeKeys = 'entity' | 'items';
|
|
|
16
16
|
type BuilderKeys = Exclude<UniversalPropertyKeys, ExcludeKeys> | BuilderExtraKeys;
|
|
17
17
|
type IncludeKeysForProperty = Exclude<keyof PropertyOptions<any>, ExcludeKeys> | BuilderExtraKeys;
|
|
18
18
|
type IncludeKeysForEnumOptions = Exclude<keyof EnumOptions<any>, ExcludeKeys> | BuilderExtraKeys;
|
|
19
|
-
type IncludeKeysForEmbeddedOptions = Exclude<keyof EmbeddedOptions<any, any>, ExcludeKeys> | BuilderExtraKeys;
|
|
20
|
-
type IncludeKeysForManyToOneOptions = Exclude<keyof ManyToOneOptions<any, any>, ExcludeKeys> | BuilderExtraKeys;
|
|
21
19
|
type IncludeKeysForOneToManyOptions = Exclude<keyof OneToManyOptions<any, any>, ExcludeKeys> | BuilderExtraKeys;
|
|
22
|
-
type
|
|
23
|
-
|
|
20
|
+
type HasKind<Options, K extends string> = Options extends {
|
|
21
|
+
kind: infer X extends string;
|
|
22
|
+
} ? X extends K ? true : false : false;
|
|
23
|
+
/** Lightweight chain result type for property builders - reduces type instantiation cost by avoiding full class resolution. */
|
|
24
|
+
export interface PropertyChain<Value, Options> {
|
|
25
|
+
'~type'?: {
|
|
26
|
+
value: Value;
|
|
27
|
+
};
|
|
28
|
+
'~options': Options;
|
|
29
|
+
$type<T>(): PropertyChain<T, Options>;
|
|
30
|
+
$type<Runtime, Raw, Serialized = Raw>(): PropertyChain<IType<Runtime, Raw, Serialized>, Options>;
|
|
31
|
+
nullable(): PropertyChain<Value, Omit<Options, 'nullable'> & {
|
|
32
|
+
nullable: true;
|
|
33
|
+
}>;
|
|
34
|
+
ref(): PropertyChain<Value, Omit<Options, 'ref'> & {
|
|
35
|
+
ref: true;
|
|
36
|
+
}>;
|
|
37
|
+
primary(): PropertyChain<Value, Omit<Options, 'primary'> & {
|
|
38
|
+
primary: true;
|
|
39
|
+
}>;
|
|
40
|
+
hidden(): PropertyChain<Value, Omit<Options, 'hidden'> & {
|
|
41
|
+
hidden: true;
|
|
42
|
+
}>;
|
|
43
|
+
autoincrement(): PropertyChain<Value, Omit<Options, 'autoincrement'> & {
|
|
44
|
+
autoincrement: true;
|
|
45
|
+
}>;
|
|
46
|
+
autoincrement(autoincrement: false): PropertyChain<Value, Omit<Options, 'autoincrement'> & {
|
|
47
|
+
autoincrement: false;
|
|
48
|
+
}>;
|
|
49
|
+
persist(): PropertyChain<Value, Omit<Options, 'persist'> & {
|
|
50
|
+
persist: true;
|
|
51
|
+
}>;
|
|
52
|
+
persist(persist: false): PropertyChain<Value, Omit<Options, 'persist'> & {
|
|
53
|
+
persist: false;
|
|
54
|
+
}>;
|
|
55
|
+
version(): PropertyChain<Value, Omit<Options, 'version'> & {
|
|
56
|
+
version: true;
|
|
57
|
+
}>;
|
|
58
|
+
lazy(): PropertyChain<Value, Options>;
|
|
59
|
+
name<T extends string>(name: T): PropertyChain<Value, Omit<Options, 'fieldName'> & {
|
|
60
|
+
fieldName: T;
|
|
61
|
+
}>;
|
|
62
|
+
fieldName<T extends string>(fieldName: T): PropertyChain<Value, Omit<Options, 'fieldName'> & {
|
|
63
|
+
fieldName: T;
|
|
64
|
+
}>;
|
|
65
|
+
onCreate(onCreate: (entity: any, em: EntityManager) => Value): PropertyChain<Value, Options & {
|
|
66
|
+
onCreate: (...args: any[]) => any;
|
|
67
|
+
}>;
|
|
68
|
+
default(defaultValue: string | string[] | number | number[] | boolean | null | Date | Raw): PropertyChain<Value, Omit<Options, 'default'> & {
|
|
69
|
+
default: any;
|
|
70
|
+
}>;
|
|
71
|
+
defaultRaw(defaultRaw: string): PropertyChain<Value, Options & {
|
|
72
|
+
defaultRaw: string;
|
|
73
|
+
}>;
|
|
74
|
+
formula(formula: string | FormulaCallback<any>): PropertyChain<Value, Omit<Options, 'formula'> & {
|
|
75
|
+
formula: any;
|
|
76
|
+
}>;
|
|
77
|
+
onUpdate(onUpdate: (entity: any, em: EntityManager) => Value): PropertyChain<Value, Options>;
|
|
78
|
+
fieldNames(...fieldNames: string[]): PropertyChain<Value, Options>;
|
|
79
|
+
type(type: PropertyValueType): PropertyChain<Value, Options>;
|
|
80
|
+
runtimeType(runtimeType: string): PropertyChain<Value, Options>;
|
|
81
|
+
columnType(columnType: ColumnType | AnyString): PropertyChain<Value, Options>;
|
|
82
|
+
columnTypes(...columnTypes: (ColumnType | AnyString)[]): PropertyChain<Value, Options>;
|
|
83
|
+
length(length: number): PropertyChain<Value, Options>;
|
|
84
|
+
precision(precision: number): PropertyChain<Value, Options>;
|
|
85
|
+
scale(scale: number): PropertyChain<Value, Options>;
|
|
86
|
+
returning(returning?: boolean): PropertyChain<Value, Options>;
|
|
87
|
+
unsigned(unsigned?: boolean): PropertyChain<Value, Options>;
|
|
88
|
+
hydrate(hydrate?: boolean): PropertyChain<Value, Options>;
|
|
89
|
+
concurrencyCheck(concurrencyCheck?: boolean): PropertyChain<Value, Options>;
|
|
90
|
+
generated(generated: string | GeneratedColumnCallback<any>): PropertyChain<Value, Options>;
|
|
91
|
+
check(check: string | CheckCallback<any>): PropertyChain<Value, Options>;
|
|
92
|
+
setter(setter?: boolean): PropertyChain<Value, Options>;
|
|
93
|
+
getter(getter?: boolean): PropertyChain<Value, Options>;
|
|
94
|
+
getterName(getterName: string): PropertyChain<Value, Options>;
|
|
95
|
+
serializedPrimaryKey(serializedPrimaryKey?: boolean): PropertyChain<Value, Options>;
|
|
96
|
+
serializer(serializer: (value: Value, options?: SerializeOptions<any>) => any): PropertyChain<Value, Options>;
|
|
97
|
+
serializedName(serializedName: string): PropertyChain<Value, Options>;
|
|
98
|
+
groups(...groups: string[]): PropertyChain<Value, Options>;
|
|
99
|
+
customOrder(...customOrder: string[] | number[] | boolean[]): PropertyChain<Value, Options>;
|
|
100
|
+
extra(extra: string): PropertyChain<Value, Options>;
|
|
101
|
+
ignoreSchemaChanges(...ignoreSchemaChanges: ('type' | 'extra' | 'default')[]): PropertyChain<Value, Options>;
|
|
102
|
+
index(index?: boolean | string): PropertyChain<Value, Options>;
|
|
103
|
+
unique(unique?: boolean | string): PropertyChain<Value, Options>;
|
|
104
|
+
comment(comment: string): PropertyChain<Value, Options>;
|
|
105
|
+
accessor(accessor?: string | boolean): PropertyChain<Value, Options>;
|
|
106
|
+
eager(eager?: boolean): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
107
|
+
cascade(...cascade: Cascade[]): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
108
|
+
strategy(strategy: LoadStrategy | `${LoadStrategy}`): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
109
|
+
filters(filters: FilterOptions): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
110
|
+
mappedBy(mappedBy: (keyof Value & string) | ((e: Value) => any)): HasKind<Options, '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
111
|
+
inversedBy(inversedBy: (keyof Value & string) | ((e: Value) => any)): HasKind<Options, 'm:1' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
112
|
+
owner(): HasKind<Options, '1:1' | 'm:n'> extends true ? PropertyChain<Value, Omit<Options, 'owner'> & {
|
|
113
|
+
owner: true;
|
|
114
|
+
}> : never;
|
|
115
|
+
mapToPk(): HasKind<Options, 'm:1' | '1:1'> extends true ? PropertyChain<Value, Omit<Options, 'mapToPk'> & {
|
|
116
|
+
mapToPk: true;
|
|
117
|
+
}> : never;
|
|
118
|
+
orphanRemoval(orphanRemoval?: boolean): HasKind<Options, '1:m' | '1:1'> extends true ? PropertyChain<Value, Options> : never;
|
|
119
|
+
discriminator(discriminator: string): HasKind<Options, 'm:1' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
120
|
+
discriminatorMap(discriminatorMap: Dictionary<string>): HasKind<Options, 'm:1' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
121
|
+
pivotTable(pivotTable: string): HasKind<Options, 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
122
|
+
pivotEntity(pivotEntity: () => EntityName): HasKind<Options, 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
123
|
+
fixedOrder(fixedOrder?: boolean): HasKind<Options, 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
124
|
+
fixedOrderColumn(fixedOrderColumn: string): HasKind<Options, 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
125
|
+
array(): HasKind<Options, 'embedded' | 'enum'> extends true ? PropertyChain<Value, Omit<Options, 'array'> & {
|
|
126
|
+
array: true;
|
|
127
|
+
}> : never;
|
|
128
|
+
prefix(prefix: string | boolean): HasKind<Options, 'embedded'> extends true ? PropertyChain<Value, Options> : never;
|
|
129
|
+
prefixMode(prefixMode: EmbeddedPrefixMode): HasKind<Options, 'embedded'> extends true ? PropertyChain<Value, Options> : never;
|
|
130
|
+
object(object?: boolean): HasKind<Options, 'embedded'> extends true ? PropertyChain<Value, Options> : never;
|
|
131
|
+
nativeEnumName(nativeEnumName: string): HasKind<Options, 'enum'> extends true ? PropertyChain<Value, Options> : never;
|
|
132
|
+
orderBy(...orderBy: QueryOrderMap<object>[]): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
133
|
+
where(...where: FilterQuery<object>[]): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
134
|
+
joinColumn(joinColumn: string): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
135
|
+
joinColumns(...joinColumns: string[]): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
136
|
+
inverseJoinColumn(inverseJoinColumn: string): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
137
|
+
inverseJoinColumns(...inverseJoinColumns: string[]): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
138
|
+
referenceColumnName(referenceColumnName: string): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
139
|
+
referencedColumnNames(...referencedColumnNames: string[]): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
140
|
+
ownColumns(...ownColumns: string[]): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
141
|
+
targetKey(targetKey: keyof Value & string): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
142
|
+
deleteRule(deleteRule: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
143
|
+
updateRule(updateRule: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
144
|
+
deferMode(deferMode: DeferMode | `${DeferMode}`): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
145
|
+
createForeignKeyConstraint(createForeignKeyConstraint?: boolean): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
146
|
+
foreignKeyName(foreignKeyName: string): HasKind<Options, 'm:1' | '1:m' | '1:1' | 'm:n'> extends true ? PropertyChain<Value, Options> : never;
|
|
147
|
+
}
|
|
24
148
|
/** @internal */
|
|
25
149
|
export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys extends BuilderKeys> implements Record<Exclude<UniversalPropertyKeys, ExcludeKeys>, any> {
|
|
26
150
|
'~options': Options;
|
|
@@ -100,8 +224,11 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
|
|
|
100
224
|
/**
|
|
101
225
|
* Explicitly specify the auto increment of the primary key.
|
|
102
226
|
*/
|
|
103
|
-
autoincrement
|
|
104
|
-
autoincrement:
|
|
227
|
+
autoincrement(): Pick<UniversalPropertyOptionsBuilder<Value, Omit<Options, 'autoincrement'> & {
|
|
228
|
+
autoincrement: true;
|
|
229
|
+
}, IncludeKeys>, IncludeKeys>;
|
|
230
|
+
autoincrement(autoincrement: false): Pick<UniversalPropertyOptionsBuilder<Value, Omit<Options, 'autoincrement'> & {
|
|
231
|
+
autoincrement: false;
|
|
105
232
|
}, IncludeKeys>, IncludeKeys>;
|
|
106
233
|
/**
|
|
107
234
|
* Add the property to the `returning` statement.
|
|
@@ -150,8 +277,8 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
|
|
|
150
277
|
/**
|
|
151
278
|
* Set column as nullable for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
|
|
152
279
|
*/
|
|
153
|
-
nullable
|
|
154
|
-
nullable:
|
|
280
|
+
nullable(): Pick<UniversalPropertyOptionsBuilder<Value, Omit<Options, 'nullable'> & {
|
|
281
|
+
nullable: true;
|
|
155
282
|
}, IncludeKeys>, IncludeKeys>;
|
|
156
283
|
/**
|
|
157
284
|
* Set column as unsigned for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
@@ -160,8 +287,11 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
|
|
|
160
287
|
/**
|
|
161
288
|
* Set false to define {@link https://mikro-orm.io/docs/serializing#shadow-properties Shadow Property}.
|
|
162
289
|
*/
|
|
163
|
-
persist
|
|
164
|
-
persist:
|
|
290
|
+
persist(): Pick<UniversalPropertyOptionsBuilder<Value, Omit<Options, 'persist'> & {
|
|
291
|
+
persist: true;
|
|
292
|
+
}, IncludeKeys>, IncludeKeys>;
|
|
293
|
+
persist(persist: false): Pick<UniversalPropertyOptionsBuilder<Value, Omit<Options, 'persist'> & {
|
|
294
|
+
persist: false;
|
|
165
295
|
}, IncludeKeys>, IncludeKeys>;
|
|
166
296
|
/**
|
|
167
297
|
* Set false to disable hydration of this property. Useful for persisted getters.
|
|
@@ -170,20 +300,20 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
|
|
|
170
300
|
/**
|
|
171
301
|
* Enable `ScalarReference` wrapper for lazy values. Use this in combination with `lazy: true` to have a type-safe accessor object in place of the value.
|
|
172
302
|
*/
|
|
173
|
-
ref
|
|
174
|
-
ref:
|
|
303
|
+
ref(): UniversalPropertyOptionsBuilder<Value, Omit<Options, 'ref'> & {
|
|
304
|
+
ref: true;
|
|
175
305
|
}, IncludeKeys>;
|
|
176
306
|
/**
|
|
177
307
|
* Set to true to omit the property when {@link https://mikro-orm.io/docs/serializing Serializing}.
|
|
178
308
|
*/
|
|
179
|
-
hidden
|
|
180
|
-
hidden:
|
|
309
|
+
hidden(): Pick<UniversalPropertyOptionsBuilder<Value, Omit<Options, 'hidden'> & {
|
|
310
|
+
hidden: true;
|
|
181
311
|
}, IncludeKeys>, IncludeKeys>;
|
|
182
312
|
/**
|
|
183
313
|
* Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via version field. (SQL only)
|
|
184
314
|
*/
|
|
185
|
-
version
|
|
186
|
-
version:
|
|
315
|
+
version(): Pick<UniversalPropertyOptionsBuilder<Value, Omit<Options, 'version'> & {
|
|
316
|
+
version: true;
|
|
187
317
|
}, IncludeKeys>, IncludeKeys>;
|
|
188
318
|
/**
|
|
189
319
|
* Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via concurrency fields.
|
|
@@ -208,16 +338,14 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
|
|
|
208
338
|
*
|
|
209
339
|
* @see https://mikro-orm.io/docs/defining-entities#lazy-scalar-properties
|
|
210
340
|
*/
|
|
211
|
-
lazy
|
|
212
|
-
ref: T;
|
|
213
|
-
}, IncludeKeys>, IncludeKeys>;
|
|
341
|
+
lazy(): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
214
342
|
/**
|
|
215
343
|
* Set true to define entity's unique primary key identifier.
|
|
216
344
|
*
|
|
217
345
|
* @see https://mikro-orm.io/docs/decorators#primarykey
|
|
218
346
|
*/
|
|
219
|
-
primary
|
|
220
|
-
primary:
|
|
347
|
+
primary(): Pick<UniversalPropertyOptionsBuilder<Value, Omit<Options, 'primary'> & {
|
|
348
|
+
primary: true;
|
|
221
349
|
}, IncludeKeys>, IncludeKeys>;
|
|
222
350
|
/**
|
|
223
351
|
* Set true to define the properties as setter. (virtual)
|
|
@@ -281,7 +409,7 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
|
|
|
281
409
|
/**
|
|
282
410
|
* Specify a custom order based on the values. (SQL only)
|
|
283
411
|
*/
|
|
284
|
-
customOrder(...customOrder:
|
|
412
|
+
customOrder(...customOrder: string[] | number[] | boolean[]): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
285
413
|
/**
|
|
286
414
|
* Specify comment of column for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
287
415
|
*/
|
|
@@ -294,8 +422,8 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
|
|
|
294
422
|
* @see https://mikro-orm.io/docs/defining-entities#sql-generated-columns
|
|
295
423
|
*/
|
|
296
424
|
ignoreSchemaChanges(...ignoreSchemaChanges: ('type' | 'extra' | 'default')[]): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
297
|
-
array
|
|
298
|
-
array:
|
|
425
|
+
array(): Pick<UniversalPropertyOptionsBuilder<Value, Omit<Options, 'array'> & {
|
|
426
|
+
array: true;
|
|
299
427
|
}, IncludeKeys>, IncludeKeys>;
|
|
300
428
|
/** for postgres, by default it uses text column with check constraint */
|
|
301
429
|
nativeEnumName(nativeEnumName: string): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
@@ -309,8 +437,8 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
|
|
|
309
437
|
/** Override the default loading strategy for this property. This option has precedence over the global `loadStrategy`, but can be overridden by `FindOptions.strategy`. */
|
|
310
438
|
strategy(strategy: LoadStrategy | `${LoadStrategy}`): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
311
439
|
/** 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
|
|
313
|
-
owner:
|
|
440
|
+
owner(): Pick<UniversalPropertyOptionsBuilder<Value, Omit<Options, 'owner'> & {
|
|
441
|
+
owner: true;
|
|
314
442
|
}, IncludeKeys>, IncludeKeys>;
|
|
315
443
|
/** For polymorphic relations. Specifies the property name that stores the entity type discriminator. Defaults to the property name. */
|
|
316
444
|
discriminator(discriminator: string): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
@@ -351,8 +479,8 @@ export declare class UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys
|
|
|
351
479
|
/** What to do when the reference to the target entity gets updated. */
|
|
352
480
|
updateRule(updateRule: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
353
481
|
/** Map this relation to the primary key value instead of an entity. */
|
|
354
|
-
mapToPk
|
|
355
|
-
mapToPk:
|
|
482
|
+
mapToPk(): Pick<UniversalPropertyOptionsBuilder<Value, Omit<Options, 'mapToPk'> & {
|
|
483
|
+
mapToPk: true;
|
|
356
484
|
}, IncludeKeys>, IncludeKeys>;
|
|
357
485
|
/** 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. */
|
|
358
486
|
deferMode(deferMode: DeferMode | `${DeferMode}`): Pick<UniversalPropertyOptionsBuilder<Value, Options, IncludeKeys>, IncludeKeys>;
|
|
@@ -373,7 +501,7 @@ export declare class OneToManyOptionsBuilderOnlyMappedBy<Value extends object> e
|
|
|
373
501
|
kind: '1:m';
|
|
374
502
|
}, IncludeKeysForOneToManyOptions> {
|
|
375
503
|
/** Point to the owning side property name. */
|
|
376
|
-
mappedBy(mappedBy:
|
|
504
|
+
mappedBy(mappedBy: keyof Value | ((e: Value) => any)): Pick<UniversalPropertyOptionsBuilder<Value, EmptyOptions & {
|
|
377
505
|
kind: '1:m';
|
|
378
506
|
}, IncludeKeysForOneToManyOptions>, IncludeKeysForOneToManyOptions>;
|
|
379
507
|
}
|
|
@@ -390,17 +518,21 @@ declare const propertyBuilders: {
|
|
|
390
518
|
time: (length?: number) => UniversalPropertyOptionsBuilder<any, EmptyOptions, IncludeKeysForProperty>;
|
|
391
519
|
type: <T extends PropertyValueType>(type: T) => UniversalPropertyOptionsBuilder<InferPropertyValueType<T>, EmptyOptions, IncludeKeysForProperty>;
|
|
392
520
|
enum: <const T extends (number | string)[] | (() => Dictionary)>(items?: T) => UniversalPropertyOptionsBuilder<T extends () => Dictionary ? ValueOf<ReturnType<T>> : T extends (infer Value)[] ? Value : T, EmptyOptions, IncludeKeysForEnumOptions>;
|
|
393
|
-
embedded: <Target extends EntityTarget | EntityTarget[]>(target: Target) =>
|
|
394
|
-
|
|
521
|
+
embedded: <Target extends EntityTarget | EntityTarget[]>(target: Target) => PropertyChain<InferEntity<Target extends (infer T)[] ? T : Target>, EmptyOptions & {
|
|
522
|
+
kind: "embedded";
|
|
523
|
+
}>;
|
|
524
|
+
manyToMany: <Target extends EntityTarget>(target: Target) => PropertyChain<InferEntity<Target>, EmptyOptions & {
|
|
395
525
|
kind: "m:n";
|
|
396
|
-
}
|
|
397
|
-
manyToOne: <Target extends EntityTarget | EntityTarget[]>(target: Target) =>
|
|
526
|
+
}>;
|
|
527
|
+
manyToOne: <Target extends EntityTarget | EntityTarget[]>(target: Target) => PropertyChain<InferEntity<Target extends (infer T)[] ? T : Target>, EmptyOptions & {
|
|
398
528
|
kind: "m:1";
|
|
399
|
-
}
|
|
400
|
-
oneToMany: <Target extends EntityTarget>(target: Target) =>
|
|
401
|
-
|
|
529
|
+
}>;
|
|
530
|
+
oneToMany: <Target extends EntityTarget>(target: Target) => PropertyChain<InferEntity<Target>, EmptyOptions & {
|
|
531
|
+
kind: "1:m";
|
|
532
|
+
}>;
|
|
533
|
+
oneToOne: <Target extends EntityTarget | EntityTarget[]>(target: Target) => PropertyChain<InferEntity<Target extends (infer T)[] ? T : Target>, EmptyOptions & {
|
|
402
534
|
kind: "1:1";
|
|
403
|
-
}
|
|
535
|
+
}>;
|
|
404
536
|
date: () => UniversalPropertyOptionsBuilder<string, EmptyOptions, IncludeKeysForProperty>;
|
|
405
537
|
blob: () => UniversalPropertyOptionsBuilder<NonNullable<Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | null>, EmptyOptions, IncludeKeysForProperty>;
|
|
406
538
|
uint8array: () => UniversalPropertyOptionsBuilder<Uint8Array<ArrayBufferLike>, EmptyOptions, IncludeKeysForProperty>;
|
|
@@ -421,7 +553,7 @@ declare const propertyBuilders: {
|
|
|
421
553
|
};
|
|
422
554
|
/** Own keys + base entity keys (when TBase is not `never`). Guards against `keyof never = string | number | symbol`. */
|
|
423
555
|
type AllKeys<TProperties, TBase> = keyof TProperties | (IsNever<TBase> extends true ? never : keyof TBase);
|
|
424
|
-
export interface EntityMetadataWithProperties<TName extends string, TTableName extends string, TProperties extends Record<string, any>, TPK extends (keyof TProperties)[] | undefined = undefined, TBase = never, TRepository = never> extends Omit<Partial<EntityMetadata<InferEntityFromProperties<TProperties, TPK, TBase, TRepository>>>, 'properties' | 'extends' | 'primaryKeys' | 'hooks' | 'discriminatorColumn' | 'versionProperty' | 'concurrencyCheckKeys' | 'serializedPrimaryKey' | 'indexes' | 'uniques' | 'repository' | 'orderBy'> {
|
|
556
|
+
export interface EntityMetadataWithProperties<TName extends string, TTableName extends string, TProperties extends Record<string, any>, TPK extends (keyof TProperties)[] | undefined = undefined, TBase = never, TRepository = never, TForceObject extends boolean = false> extends Omit<Partial<EntityMetadata<InferEntityFromProperties<TProperties, TPK, TBase, TRepository>>>, 'properties' | 'extends' | 'primaryKeys' | 'hooks' | 'discriminatorColumn' | 'versionProperty' | 'concurrencyCheckKeys' | 'serializedPrimaryKey' | 'indexes' | 'uniques' | 'repository' | 'orderBy'> {
|
|
425
557
|
name: TName;
|
|
426
558
|
tableName?: TTableName;
|
|
427
559
|
extends?: {
|
|
@@ -431,6 +563,7 @@ export interface EntityMetadataWithProperties<TName extends string, TTableName e
|
|
|
431
563
|
primaryKeys?: TPK & InferPrimaryKey<TProperties>[];
|
|
432
564
|
hooks?: DefineEntityHooks;
|
|
433
565
|
repository?: () => TRepository;
|
|
566
|
+
forceObject?: TForceObject;
|
|
434
567
|
inheritance?: 'tpt';
|
|
435
568
|
orderBy?: {
|
|
436
569
|
[K in Extract<AllKeys<TProperties, TBase>, string>]?: QueryOrderKeysFlat;
|
|
@@ -456,7 +589,7 @@ export interface EntityMetadataWithProperties<TName extends string, TTableName e
|
|
|
456
589
|
deferMode?: DeferMode | `${DeferMode}`;
|
|
457
590
|
}[];
|
|
458
591
|
}
|
|
459
|
-
export declare function defineEntity<const TName extends string, const TTableName extends string, const TProperties extends Record<string, any>, const TPK extends (keyof TProperties)[] | undefined = undefined, const TBase = never, const TRepository = never>(meta: EntityMetadataWithProperties<TName, TTableName, TProperties, TPK, TBase, TRepository>): EntitySchemaWithMeta<TName, TTableName, InferEntityFromProperties<TProperties, TPK, TBase, TRepository>, TBase, TProperties>;
|
|
592
|
+
export declare function defineEntity<const TName extends string, const TTableName extends string, const TProperties extends Record<string, any>, const TPK extends (keyof TProperties)[] | undefined = undefined, const TBase = never, const TRepository = never, const TForceObject extends boolean = false>(meta: EntityMetadataWithProperties<TName, TTableName, TProperties, TPK, TBase, TRepository, TForceObject>): EntitySchemaWithMeta<TName, TTableName, InferEntityFromProperties<TProperties, TPK, TBase, TRepository, TForceObject>, TBase, TProperties>;
|
|
460
593
|
export declare function defineEntity<const TEntity = any, const TProperties extends Record<string, any> = Record<string, any>, const TClassName extends string = string, const TTableName extends string = string, const TBase = never, const TClass extends EntityCtor = EntityCtor<TEntity>>(meta: Omit<Partial<EntityMetadata<TEntity>>, 'properties' | 'extends' | 'className' | 'tableName' | 'hooks'> & {
|
|
461
594
|
class: TClass;
|
|
462
595
|
className?: TClassName;
|
|
@@ -476,17 +609,21 @@ export declare namespace defineEntity {
|
|
|
476
609
|
time: (length?: number) => UniversalPropertyOptionsBuilder<any, EmptyOptions, IncludeKeysForProperty>;
|
|
477
610
|
type: <T extends PropertyValueType>(type: T) => UniversalPropertyOptionsBuilder<InferPropertyValueType<T>, EmptyOptions, IncludeKeysForProperty>;
|
|
478
611
|
enum: <const T extends (number | string)[] | (() => Dictionary)>(items?: T) => UniversalPropertyOptionsBuilder<T extends () => Dictionary ? ValueOf<ReturnType<T>> : T extends (infer Value)[] ? Value : T, EmptyOptions, IncludeKeysForEnumOptions>;
|
|
479
|
-
embedded: <Target extends EntityTarget | EntityTarget[]>(target: Target) =>
|
|
480
|
-
|
|
612
|
+
embedded: <Target extends EntityTarget | EntityTarget[]>(target: Target) => PropertyChain<InferEntity<Target extends (infer T)[] ? T : Target>, EmptyOptions & {
|
|
613
|
+
kind: "embedded";
|
|
614
|
+
}>;
|
|
615
|
+
manyToMany: <Target extends EntityTarget>(target: Target) => PropertyChain<InferEntity<Target>, EmptyOptions & {
|
|
481
616
|
kind: "m:n";
|
|
482
|
-
}
|
|
483
|
-
manyToOne: <Target extends EntityTarget | EntityTarget[]>(target: Target) =>
|
|
617
|
+
}>;
|
|
618
|
+
manyToOne: <Target extends EntityTarget | EntityTarget[]>(target: Target) => PropertyChain<InferEntity<Target extends (infer T)[] ? T : Target>, EmptyOptions & {
|
|
484
619
|
kind: "m:1";
|
|
485
|
-
}
|
|
486
|
-
oneToMany: <Target extends EntityTarget>(target: Target) =>
|
|
487
|
-
|
|
620
|
+
}>;
|
|
621
|
+
oneToMany: <Target extends EntityTarget>(target: Target) => PropertyChain<InferEntity<Target>, EmptyOptions & {
|
|
622
|
+
kind: "1:m";
|
|
623
|
+
}>;
|
|
624
|
+
oneToOne: <Target extends EntityTarget | EntityTarget[]>(target: Target) => PropertyChain<InferEntity<Target extends (infer T)[] ? T : Target>, EmptyOptions & {
|
|
488
625
|
kind: "1:1";
|
|
489
|
-
}
|
|
626
|
+
}>;
|
|
490
627
|
date: () => UniversalPropertyOptionsBuilder<string, EmptyOptions, IncludeKeysForProperty>;
|
|
491
628
|
blob: () => UniversalPropertyOptionsBuilder<NonNullable<Buffer<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | null>, EmptyOptions, IncludeKeysForProperty>;
|
|
492
629
|
uint8array: () => UniversalPropertyOptionsBuilder<Uint8Array<ArrayBufferLike>, EmptyOptions, IncludeKeysForProperty>;
|
|
@@ -522,23 +659,34 @@ export interface DefineEntityHooks<T = any> {
|
|
|
522
659
|
}
|
|
523
660
|
type PropertyValueType = PropertyOptions<any>['type'];
|
|
524
661
|
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;
|
|
525
|
-
type InferTypeByString<T extends string> = T extends keyof typeof types ? InferJSType<typeof types[T]> : InferColumnType<T>;
|
|
662
|
+
type InferTypeByString<T extends string> = T extends keyof typeof types ? InferJSType<(typeof types)[T]> : InferColumnType<T>;
|
|
526
663
|
type InferJSType<T> = T extends typeof Type<infer TValue, any> ? NonNullable<TValue> : never;
|
|
527
664
|
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;
|
|
528
|
-
|
|
665
|
+
type BaseEntityMethodKeys = 'toObject' | 'toPOJO' | 'serialize' | 'assign' | 'populate' | 'init' | 'toReference';
|
|
666
|
+
export type InferEntityFromProperties<Properties extends Record<string, any>, PK extends (keyof Properties)[] | undefined = undefined, Base = never, Repository = never, ForceObject extends boolean = false> = (IsNever<Base> extends true ? {} : Base extends {
|
|
667
|
+
toObject(...args: any[]): any;
|
|
668
|
+
} ? Pick<IWrappedEntity<{
|
|
529
669
|
-readonly [K in keyof Properties]: InferBuilderValue<MaybeReturnType<Properties[K]>>;
|
|
530
670
|
} & {
|
|
531
671
|
[PrimaryKeyProp]?: InferCombinedPrimaryKey<Properties, PK, Base>;
|
|
532
672
|
} & (IsNever<Repository> extends true ? {} : {
|
|
533
673
|
[EntityRepositoryType]?: Repository extends Constructor<infer R> ? R : Repository;
|
|
534
|
-
}) &
|
|
674
|
+
}) & Omit<Base, typeof PrimaryKeyProp>>, BaseEntityMethodKeys> : {}) & {
|
|
675
|
+
-readonly [K in keyof Properties]: InferBuilderValue<MaybeReturnType<Properties[K]>>;
|
|
676
|
+
} & {
|
|
677
|
+
[PrimaryKeyProp]?: InferCombinedPrimaryKey<Properties, PK, Base>;
|
|
678
|
+
} & (IsNever<Repository> extends true ? {} : {
|
|
679
|
+
[EntityRepositoryType]?: Repository extends Constructor<infer R> ? R : Repository;
|
|
680
|
+
}) & (IsNever<Base> extends true ? {} : Omit<Base, typeof PrimaryKeyProp>) & (ForceObject extends true ? {
|
|
681
|
+
[Config]?: DefineConfig<{
|
|
682
|
+
forceObject: true;
|
|
683
|
+
}>;
|
|
684
|
+
} : {});
|
|
535
685
|
type InferCombinedPrimaryKey<Properties extends Record<string, any>, PK, Base> = PK extends undefined ? CombinePrimaryKeys<InferPrimaryKey<Properties>, ExtractBasePrimaryKey<Base>> : PK;
|
|
536
686
|
type ExtractBasePrimaryKey<Base> = Base extends {
|
|
537
687
|
[PrimaryKeyProp]?: infer BasePK;
|
|
538
688
|
} ? BasePK : never;
|
|
539
|
-
type CombinePrimaryKeys<ChildPK, BasePK> = [
|
|
540
|
-
ChildPK
|
|
541
|
-
] extends [never] ? BasePK : [BasePK] extends [never] ? IsUnion<ChildPK> extends true ? ChildPK[] : ChildPK : ChildPK | BasePK;
|
|
689
|
+
type CombinePrimaryKeys<ChildPK, BasePK> = [ChildPK] extends [never] ? BasePK : [BasePK] extends [never] ? IsUnion<ChildPK> extends true ? ChildPK[] : ChildPK : ChildPK | BasePK;
|
|
542
690
|
export type InferPrimaryKey<Properties extends Record<string, any>> = {
|
|
543
691
|
[K in keyof Properties]: MaybeReturnType<Properties[K]> extends {
|
|
544
692
|
'~options': {
|
|
@@ -563,8 +711,6 @@ type MaybeNullable<Value, Options> = Options extends {
|
|
|
563
711
|
} ? Value | null | undefined : Value;
|
|
564
712
|
type MaybeRelationRef<Value, Options> = Options extends {
|
|
565
713
|
mapToPk: true;
|
|
566
|
-
} ? Value : Options extends {
|
|
567
|
-
ref: false;
|
|
568
714
|
} ? Value : Options extends {
|
|
569
715
|
ref: true;
|
|
570
716
|
kind: '1:1';
|
|
@@ -577,8 +723,6 @@ type MaybeRelationRef<Value, Options> = Options extends {
|
|
|
577
723
|
kind: 'm:n';
|
|
578
724
|
} ? Value extends object ? Collection<Value> : never : Value;
|
|
579
725
|
type MaybeScalarRef<Value, Options> = Options extends {
|
|
580
|
-
ref: false;
|
|
581
|
-
} ? Value : Options extends {
|
|
582
726
|
kind: '1:1' | 'm:1' | '1:m' | 'm:n';
|
|
583
727
|
} ? Value : Options extends {
|
|
584
728
|
ref: true;
|
package/entity/defineEntity.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { types } from '../types/index.js';
|
|
2
2
|
import { EntitySchema } from '../metadata/EntitySchema.js';
|
|
3
|
+
// Parameter-level sync assertion lives in tests/defineEntity.test.ts to avoid
|
|
4
|
+
// instantiating the full builder class in production builds (~680 instantiations).
|
|
3
5
|
/** @internal */
|
|
4
6
|
export class UniversalPropertyOptionsBuilder {
|
|
5
7
|
'~options';
|
|
@@ -82,9 +84,6 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
82
84
|
scale(scale) {
|
|
83
85
|
return this.assignOptions({ scale });
|
|
84
86
|
}
|
|
85
|
-
/**
|
|
86
|
-
* Explicitly specify the auto increment of the primary key.
|
|
87
|
-
*/
|
|
88
87
|
autoincrement(autoincrement = true) {
|
|
89
88
|
return this.assignOptions({ autoincrement });
|
|
90
89
|
}
|
|
@@ -143,8 +142,8 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
143
142
|
/**
|
|
144
143
|
* Set column as nullable for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}.
|
|
145
144
|
*/
|
|
146
|
-
nullable(
|
|
147
|
-
return this.assignOptions({ nullable });
|
|
145
|
+
nullable() {
|
|
146
|
+
return this.assignOptions({ nullable: true });
|
|
148
147
|
}
|
|
149
148
|
/**
|
|
150
149
|
* Set column as unsigned for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only)
|
|
@@ -152,9 +151,6 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
152
151
|
unsigned(unsigned = true) {
|
|
153
152
|
return this.assignOptions({ unsigned });
|
|
154
153
|
}
|
|
155
|
-
/**
|
|
156
|
-
* Set false to define {@link https://mikro-orm.io/docs/serializing#shadow-properties Shadow Property}.
|
|
157
|
-
*/
|
|
158
154
|
persist(persist = true) {
|
|
159
155
|
return this.assignOptions({ persist });
|
|
160
156
|
}
|
|
@@ -167,20 +163,20 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
167
163
|
/**
|
|
168
164
|
* Enable `ScalarReference` wrapper for lazy values. Use this in combination with `lazy: true` to have a type-safe accessor object in place of the value.
|
|
169
165
|
*/
|
|
170
|
-
ref(
|
|
171
|
-
return this.assignOptions({ ref });
|
|
166
|
+
ref() {
|
|
167
|
+
return this.assignOptions({ ref: true });
|
|
172
168
|
}
|
|
173
169
|
/**
|
|
174
170
|
* Set to true to omit the property when {@link https://mikro-orm.io/docs/serializing Serializing}.
|
|
175
171
|
*/
|
|
176
|
-
hidden(
|
|
177
|
-
return this.assignOptions({ hidden });
|
|
172
|
+
hidden() {
|
|
173
|
+
return this.assignOptions({ hidden: true });
|
|
178
174
|
}
|
|
179
175
|
/**
|
|
180
176
|
* Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via version field. (SQL only)
|
|
181
177
|
*/
|
|
182
|
-
version(
|
|
183
|
-
return this.assignOptions({ version });
|
|
178
|
+
version() {
|
|
179
|
+
return this.assignOptions({ version: true });
|
|
184
180
|
}
|
|
185
181
|
/**
|
|
186
182
|
* Set to true to enable {@link https://mikro-orm.io/docs/transactions#optimistic-locking Optimistic Locking} via concurrency fields.
|
|
@@ -213,16 +209,16 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
213
209
|
*
|
|
214
210
|
* @see https://mikro-orm.io/docs/defining-entities#lazy-scalar-properties
|
|
215
211
|
*/
|
|
216
|
-
lazy(
|
|
217
|
-
return this.assignOptions({ lazy
|
|
212
|
+
lazy() {
|
|
213
|
+
return this.assignOptions({ lazy: true });
|
|
218
214
|
}
|
|
219
215
|
/**
|
|
220
216
|
* Set true to define entity's unique primary key identifier.
|
|
221
217
|
*
|
|
222
218
|
* @see https://mikro-orm.io/docs/decorators#primarykey
|
|
223
219
|
*/
|
|
224
|
-
primary(
|
|
225
|
-
return this.assignOptions({ primary });
|
|
220
|
+
primary() {
|
|
221
|
+
return this.assignOptions({ primary: true });
|
|
226
222
|
}
|
|
227
223
|
/**
|
|
228
224
|
* Set true to define the properties as setter. (virtual)
|
|
@@ -321,8 +317,8 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
321
317
|
ignoreSchemaChanges(...ignoreSchemaChanges) {
|
|
322
318
|
return this.assignOptions({ ignoreSchemaChanges });
|
|
323
319
|
}
|
|
324
|
-
array(
|
|
325
|
-
return this.assignOptions({ array });
|
|
320
|
+
array() {
|
|
321
|
+
return this.assignOptions({ array: true });
|
|
326
322
|
}
|
|
327
323
|
/** for postgres, by default it uses text column with check constraint */
|
|
328
324
|
nativeEnumName(nativeEnumName) {
|
|
@@ -350,8 +346,8 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
350
346
|
return this.assignOptions({ strategy });
|
|
351
347
|
}
|
|
352
348
|
/** Set this side as owning. Owning side is where the foreign key is defined. This option is not required if you use `inversedBy` or `mappedBy` to distinguish owning and inverse side. */
|
|
353
|
-
owner(
|
|
354
|
-
return this.assignOptions({ owner });
|
|
349
|
+
owner() {
|
|
350
|
+
return this.assignOptions({ owner: true });
|
|
355
351
|
}
|
|
356
352
|
/** For polymorphic relations. Specifies the property name that stores the entity type discriminator. Defaults to the property name. */
|
|
357
353
|
discriminator(discriminator) {
|
|
@@ -430,8 +426,8 @@ export class UniversalPropertyOptionsBuilder {
|
|
|
430
426
|
return this.assignOptions({ updateRule });
|
|
431
427
|
}
|
|
432
428
|
/** Map this relation to the primary key value instead of an entity. */
|
|
433
|
-
mapToPk(
|
|
434
|
-
return this.assignOptions({ mapToPk });
|
|
429
|
+
mapToPk() {
|
|
430
|
+
return this.assignOptions({ mapToPk: true });
|
|
435
431
|
}
|
|
436
432
|
/** Set the constraint type. Immediate constraints are checked for each statement, while deferred ones are only checked at the end of the transaction. Only for postgres unique constraints. */
|
|
437
433
|
deferMode(deferMode) {
|
package/entity/utils.js
CHANGED
|
@@ -17,15 +17,17 @@ function expandNestedPopulate(parentProp, parts, strategy, all) {
|
|
|
17
17
|
* @internal
|
|
18
18
|
*/
|
|
19
19
|
export function expandDotPaths(meta, populate, normalized = false) {
|
|
20
|
-
const ret = normalized
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
const ret = normalized
|
|
21
|
+
? populate
|
|
22
|
+
: Utils.asArray(populate).map(field => {
|
|
23
|
+
if (typeof field === 'string') {
|
|
24
|
+
return { field };
|
|
25
|
+
}
|
|
26
|
+
/* v8 ignore next */
|
|
27
|
+
return typeof field === 'boolean' || field.field === PopulatePath.ALL
|
|
28
|
+
? { all: !!field, field: meta.primaryKeys[0] }
|
|
29
|
+
: field;
|
|
30
|
+
});
|
|
29
31
|
for (const p of ret) {
|
|
30
32
|
if (!p.field.includes('.')) {
|
|
31
33
|
continue;
|
|
@@ -35,8 +37,8 @@ export function expandDotPaths(meta, populate, normalized = false) {
|
|
|
35
37
|
p.children ??= [];
|
|
36
38
|
const prop = meta.properties[p.field];
|
|
37
39
|
if (parts[0] === PopulatePath.ALL) {
|
|
38
|
-
prop
|
|
39
|
-
.filter(prop => prop.lazy || prop.kind !== ReferenceKind.SCALAR)
|
|
40
|
+
prop
|
|
41
|
+
.targetMeta.props.filter(prop => prop.lazy || prop.kind !== ReferenceKind.SCALAR)
|
|
40
42
|
.forEach(prop => p.children.push({ field: prop.name, strategy: p.strategy }));
|
|
41
43
|
}
|
|
42
44
|
else if (prop.kind === ReferenceKind.EMBEDDED) {
|
|
@@ -67,6 +69,21 @@ export function getLoadingStrategy(strategy, kind) {
|
|
|
67
69
|
}
|
|
68
70
|
return strategy;
|
|
69
71
|
}
|
|
72
|
+
function findPopulateEntry(populate, parts) {
|
|
73
|
+
let current = populate;
|
|
74
|
+
for (let i = 0; i < parts.length; i++) {
|
|
75
|
+
const entry = current.find(p => p.field.split(':')[0] === parts[i]);
|
|
76
|
+
if (!entry) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
if (i === parts.length - 1) {
|
|
80
|
+
return entry;
|
|
81
|
+
}
|
|
82
|
+
current = (entry.children ?? []);
|
|
83
|
+
}
|
|
84
|
+
/* v8 ignore next */
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
70
87
|
/**
|
|
71
88
|
* Applies per-relation overrides from `populateHints` to the normalized populate tree.
|
|
72
89
|
* @internal
|
|
@@ -85,18 +102,3 @@ export function applyPopulateHints(populate, hints) {
|
|
|
85
102
|
}
|
|
86
103
|
}
|
|
87
104
|
}
|
|
88
|
-
function findPopulateEntry(populate, parts) {
|
|
89
|
-
let current = populate;
|
|
90
|
-
for (let i = 0; i < parts.length; i++) {
|
|
91
|
-
const entry = current.find(p => p.field.split(':')[0] === parts[i]);
|
|
92
|
-
if (!entry) {
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
if (i === parts.length - 1) {
|
|
96
|
-
return entry;
|
|
97
|
-
}
|
|
98
|
-
current = (entry.children ?? []);
|
|
99
|
-
}
|
|
100
|
-
/* v8 ignore next */
|
|
101
|
-
return undefined;
|
|
102
|
-
}
|