@mikro-orm/core 7.0.0-dev.6 → 7.0.0-dev.61
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 +85 -32
- package/EntityManager.js +281 -178
- package/MikroORM.d.ts +8 -8
- package/MikroORM.js +31 -74
- package/README.md +3 -2
- package/cache/FileCacheAdapter.d.ts +2 -1
- package/cache/FileCacheAdapter.js +5 -4
- package/connections/Connection.d.ts +11 -7
- package/connections/Connection.js +16 -13
- package/decorators/Embeddable.d.ts +2 -0
- package/decorators/Embedded.d.ts +5 -11
- package/decorators/Entity.d.ts +20 -3
- package/decorators/Indexed.d.ts +2 -2
- package/decorators/ManyToMany.d.ts +2 -0
- package/decorators/ManyToOne.d.ts +4 -0
- package/decorators/OneToOne.d.ts +4 -0
- package/decorators/Property.d.ts +53 -9
- package/decorators/Transactional.d.ts +3 -1
- package/decorators/Transactional.js +6 -3
- package/decorators/index.d.ts +1 -1
- package/drivers/DatabaseDriver.d.ts +11 -5
- package/drivers/DatabaseDriver.js +13 -4
- package/drivers/IDatabaseDriver.d.ts +29 -5
- package/entity/ArrayCollection.d.ts +6 -4
- package/entity/ArrayCollection.js +27 -12
- package/entity/BaseEntity.d.ts +0 -1
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +3 -4
- package/entity/Collection.js +34 -17
- package/entity/EntityAssigner.d.ts +1 -1
- package/entity/EntityAssigner.js +9 -1
- package/entity/EntityFactory.d.ts +7 -0
- package/entity/EntityFactory.js +63 -40
- package/entity/EntityHelper.js +26 -9
- package/entity/EntityLoader.d.ts +5 -4
- package/entity/EntityLoader.js +69 -36
- package/entity/EntityRepository.d.ts +1 -1
- package/entity/EntityValidator.js +2 -2
- package/entity/Reference.d.ts +9 -7
- package/entity/Reference.js +32 -5
- package/entity/WrappedEntity.d.ts +0 -2
- package/entity/WrappedEntity.js +1 -5
- package/entity/defineEntity.d.ts +555 -0
- package/entity/defineEntity.js +529 -0
- package/entity/index.d.ts +2 -0
- package/entity/index.js +2 -0
- package/entity/utils.d.ts +7 -0
- package/entity/utils.js +15 -3
- package/enums.d.ts +18 -5
- package/enums.js +13 -0
- package/errors.d.ts +6 -1
- package/errors.js +14 -4
- package/events/EventSubscriber.d.ts +3 -1
- package/hydration/ObjectHydrator.d.ts +4 -4
- package/hydration/ObjectHydrator.js +35 -24
- package/index.d.ts +2 -1
- package/index.js +1 -1
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/SimpleLogger.d.ts +1 -1
- package/metadata/EntitySchema.d.ts +8 -4
- package/metadata/EntitySchema.js +41 -23
- package/metadata/MetadataDiscovery.d.ts +5 -7
- package/metadata/MetadataDiscovery.js +151 -159
- package/metadata/MetadataStorage.js +1 -1
- package/metadata/MetadataValidator.js +4 -3
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +39 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +5 -1
- package/naming-strategy/AbstractNamingStrategy.js +7 -1
- package/naming-strategy/NamingStrategy.d.ts +11 -1
- package/package.json +14 -8
- package/platforms/Platform.d.ts +5 -8
- package/platforms/Platform.js +4 -17
- package/serialization/EntitySerializer.d.ts +2 -0
- package/serialization/EntitySerializer.js +29 -11
- package/serialization/EntityTransformer.js +22 -12
- package/serialization/SerializationContext.js +14 -11
- package/types/BigIntType.d.ts +9 -6
- package/types/BigIntType.js +3 -0
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +2 -1
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.d.ts +6 -4
- package/types/DecimalType.js +1 -1
- package/types/DoubleType.js +1 -1
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/Type.d.ts +2 -1
- package/types/Type.js +1 -1
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +0 -3
- package/types/index.d.ts +1 -1
- package/typings.d.ts +95 -52
- package/typings.js +31 -31
- package/unit-of-work/ChangeSetComputer.js +8 -3
- package/unit-of-work/ChangeSetPersister.d.ts +4 -2
- package/unit-of-work/ChangeSetPersister.js +37 -16
- package/unit-of-work/UnitOfWork.d.ts +8 -1
- package/unit-of-work/UnitOfWork.js +110 -53
- package/utils/AbstractSchemaGenerator.js +3 -1
- package/utils/Configuration.d.ts +201 -184
- package/utils/Configuration.js +143 -151
- package/utils/ConfigurationLoader.d.ts +9 -22
- package/utils/ConfigurationLoader.js +53 -76
- package/utils/Cursor.d.ts +3 -3
- package/utils/Cursor.js +3 -0
- package/utils/DataloaderUtils.d.ts +15 -5
- package/utils/DataloaderUtils.js +53 -7
- package/utils/EntityComparator.d.ts +8 -4
- package/utils/EntityComparator.js +105 -58
- package/utils/QueryHelper.d.ts +9 -1
- package/utils/QueryHelper.js +66 -5
- package/utils/RawQueryFragment.d.ts +36 -4
- package/utils/RawQueryFragment.js +34 -13
- package/utils/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +223 -0
- package/utils/Utils.d.ts +16 -31
- package/utils/Utils.js +129 -107
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/upsert-utils.d.ts +7 -2
- package/utils/upsert-utils.js +52 -1
package/types/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { StringType } from './StringType.js';
|
|
|
19
19
|
import { TextType } from './TextType.js';
|
|
20
20
|
import { TimeType } from './TimeType.js';
|
|
21
21
|
import { TinyIntType } from './TinyIntType.js';
|
|
22
|
-
import { IType, TransformContext, Type } from './Type.js';
|
|
22
|
+
import { type IType, type TransformContext, Type } from './Type.js';
|
|
23
23
|
import { Uint8ArrayType } from './Uint8ArrayType.js';
|
|
24
24
|
import { UnknownType } from './UnknownType.js';
|
|
25
25
|
import { UuidType } from './UuidType.js';
|
package/typings.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ import type { RawQueryFragment } from './utils/RawQueryFragment.js';
|
|
|
19
19
|
import type { EntityManager } from './EntityManager.js';
|
|
20
20
|
import type { EmbeddedPrefixMode } from './decorators/Embedded.js';
|
|
21
21
|
import type { EventSubscriber } from './events/EventSubscriber.js';
|
|
22
|
-
import type { FindOneOptions, FindOptions, LoadHint } from './drivers/IDatabaseDriver.js';
|
|
22
|
+
import type { FilterOptions, FindOneOptions, FindOptions, LoadHint } from './drivers/IDatabaseDriver.js';
|
|
23
23
|
export type Constructor<T = unknown> = new (...args: any[]) => T;
|
|
24
24
|
export type Dictionary<T = any> = {
|
|
25
25
|
[k: string]: T;
|
|
@@ -52,18 +52,34 @@ export declare const OptionalProps: unique symbol;
|
|
|
52
52
|
export declare const EagerProps: unique symbol;
|
|
53
53
|
export declare const HiddenProps: unique symbol;
|
|
54
54
|
export declare const Config: unique symbol;
|
|
55
|
-
|
|
56
|
-
declare
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
55
|
+
export type Opt<T = unknown> = T & Opt.Brand;
|
|
56
|
+
export declare namespace Opt {
|
|
57
|
+
const __optional: unique symbol;
|
|
58
|
+
interface Brand {
|
|
59
|
+
[__optional]?: 1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export type RequiredNullable<T = never> = (T & RequiredNullable.Brand) | null;
|
|
63
|
+
export declare namespace RequiredNullable {
|
|
64
|
+
const __requiredNullable: unique symbol;
|
|
65
|
+
interface Brand {
|
|
66
|
+
[__requiredNullable]?: 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export type Hidden<T = unknown> = T & Hidden.Brand;
|
|
70
|
+
export declare namespace Hidden {
|
|
71
|
+
const __hidden: unique symbol;
|
|
72
|
+
interface Brand {
|
|
73
|
+
[__hidden]?: 1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export type DefineConfig<T extends TypeConfig> = T & DefineConfig.Brand;
|
|
77
|
+
export declare namespace DefineConfig {
|
|
78
|
+
const __config: unique symbol;
|
|
79
|
+
interface Brand {
|
|
80
|
+
[__config]?: 1;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
67
83
|
export type CleanTypeConfig<T> = Compute<Pick<T, Extract<keyof T, keyof TypeConfig>>>;
|
|
68
84
|
export interface TypeConfig {
|
|
69
85
|
forceObject?: boolean;
|
|
@@ -75,13 +91,14 @@ type PrimaryPropToType<T, Keys extends (keyof T)[]> = {
|
|
|
75
91
|
type ReadonlyPrimary<T> = T extends any[] ? Readonly<T> : T;
|
|
76
92
|
export type Primary<T> = IsAny<T> extends true ? any : T extends {
|
|
77
93
|
[PrimaryKeyProp]?: infer PK;
|
|
78
|
-
} ?
|
|
94
|
+
} ? PK extends undefined ? Omit<T, typeof PrimaryKeyProp> : PK extends keyof T ? ReadonlyPrimary<UnwrapPrimary<T[PK]>> : PK extends (keyof T)[] ? ReadonlyPrimary<PrimaryPropToType<T, PK>> : PK : T extends {
|
|
79
95
|
_id?: infer PK;
|
|
80
96
|
} ? ReadonlyPrimary<PK> | string : T extends {
|
|
81
|
-
uuid?: infer PK;
|
|
82
|
-
} ? ReadonlyPrimary<PK> : T extends {
|
|
83
97
|
id?: infer PK;
|
|
98
|
+
} ? ReadonlyPrimary<PK> : T extends {
|
|
99
|
+
uuid?: infer PK;
|
|
84
100
|
} ? ReadonlyPrimary<PK> : T;
|
|
101
|
+
/** @internal */
|
|
85
102
|
export type PrimaryProperty<T> = T extends {
|
|
86
103
|
[PrimaryKeyProp]?: infer PK;
|
|
87
104
|
} ? (PK extends keyof T ? PK : (PK extends any[] ? PK[number] : never)) : T extends {
|
|
@@ -89,10 +106,10 @@ export type PrimaryProperty<T> = T extends {
|
|
|
89
106
|
} ? (T extends {
|
|
90
107
|
id?: any;
|
|
91
108
|
} ? 'id' | '_id' : '_id') : T extends {
|
|
92
|
-
uuid?: any;
|
|
93
|
-
} ? 'uuid' : T extends {
|
|
94
109
|
id?: any;
|
|
95
|
-
} ? 'id' :
|
|
110
|
+
} ? 'id' : T extends {
|
|
111
|
+
uuid?: any;
|
|
112
|
+
} ? 'uuid' : never;
|
|
96
113
|
export type IPrimaryKeyValue = number | string | bigint | Date | {
|
|
97
114
|
toHexString(): string;
|
|
98
115
|
};
|
|
@@ -143,7 +160,6 @@ export type FilterQuery<T> = ObjectQuery<T> | NonNullable<ExpandScalar<Primary<T
|
|
|
143
160
|
export type QBFilterQuery<T = any> = ObjectQuery<T> | Dictionary;
|
|
144
161
|
export interface IWrappedEntity<Entity extends object> {
|
|
145
162
|
isInitialized(): boolean;
|
|
146
|
-
isTouched(): boolean;
|
|
147
163
|
isManaged(): boolean;
|
|
148
164
|
populated(populated?: boolean): void;
|
|
149
165
|
populate<Hint extends string = never>(populate: AutoPath<Entity, Hint>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
|
|
@@ -174,10 +190,9 @@ export interface IWrappedEntityInternal<Entity extends object> extends IWrappedE
|
|
|
174
190
|
__factory: EntityFactory;
|
|
175
191
|
__hydrator: IHydrator;
|
|
176
192
|
__initialized: boolean;
|
|
177
|
-
__touched: boolean;
|
|
178
193
|
__originalEntityData?: EntityData<Entity>;
|
|
179
194
|
__loadedProperties: Set<string>;
|
|
180
|
-
__identifier?: EntityIdentifier;
|
|
195
|
+
__identifier?: EntityIdentifier | EntityIdentifier[];
|
|
181
196
|
__managed: boolean;
|
|
182
197
|
__processing: boolean;
|
|
183
198
|
__schema?: string;
|
|
@@ -197,16 +212,12 @@ export type AnyEntity<T = any> = Partial<T>;
|
|
|
197
212
|
export type EntityClass<T> = Function & {
|
|
198
213
|
prototype: T;
|
|
199
214
|
};
|
|
200
|
-
export type EntityClassGroup<T> = {
|
|
201
|
-
entity: EntityClass<T>;
|
|
202
|
-
schema: EntityMetadata<T> | EntitySchema<T>;
|
|
203
|
-
};
|
|
204
215
|
export type EntityName<T> = string | EntityClass<T> | EntitySchema<T, any> | {
|
|
205
216
|
name: string;
|
|
206
217
|
};
|
|
207
218
|
export type GetRepository<Entity extends {
|
|
208
219
|
[k: PropertyKey]: any;
|
|
209
|
-
}, Fallback> = Entity[typeof EntityRepositoryType] extends EntityRepository<
|
|
220
|
+
}, Fallback> = Entity[typeof EntityRepositoryType] extends EntityRepository<any> | undefined ? NonNullable<Entity[typeof EntityRepositoryType]> : Fallback;
|
|
210
221
|
export type EntityDataPropValue<T> = T | Primary<T>;
|
|
211
222
|
type ExpandEntityProp<T, C extends boolean = false> = T extends Record<string, any> ? {
|
|
212
223
|
[K in keyof T as CleanKeys<T, K>]?: EntityDataProp<ExpandProperty<T[K]>, C> | EntityDataPropValue<ExpandProperty<T[K]>> | null;
|
|
@@ -217,14 +228,17 @@ type ExpandRequiredEntityPropObject<T, I = never, C extends boolean = false> = {
|
|
|
217
228
|
} & {
|
|
218
229
|
[K in keyof T as OptionalKeys<T, K, I>]?: RequiredEntityDataProp<ExpandProperty<T[K]>, T, C> | EntityDataPropValue<ExpandProperty<T[K]>> | null | undefined;
|
|
219
230
|
};
|
|
231
|
+
type NonArrayObject = object & {
|
|
232
|
+
[Symbol.iterator]?: never;
|
|
233
|
+
};
|
|
220
234
|
export type EntityDataProp<T, C extends boolean> = T extends Date ? string | Date : T extends Scalar ? T : T extends {
|
|
221
235
|
__runtime?: infer Runtime;
|
|
222
236
|
__raw?: infer Raw;
|
|
223
|
-
} ? (C extends true ? Raw : Runtime) : T extends Reference<infer U> ? EntityDataNested<U, C> : T extends ScalarReference<infer U> ? EntityDataProp<U, C> : T extends Collection<infer U, any> ? U | U[] | EntityDataNested<U, C> | EntityDataNested<U, C>[] : T extends readonly (infer U)[] ? U | U[] | EntityDataNested<U, C> | EntityDataNested<U, C>[] : EntityDataNested<T, C>;
|
|
224
|
-
export type RequiredEntityDataProp<T, O, C extends boolean> = T extends Date ? string | Date : T extends Scalar ? T : T extends {
|
|
237
|
+
} ? (C extends true ? Raw : Runtime) : T extends Reference<infer U> ? EntityDataNested<U, C> : T extends ScalarReference<infer U> ? EntityDataProp<U, C> : T extends Collection<infer U, any> ? U | U[] | EntityDataNested<U, C> | EntityDataNested<U, C>[] : T extends readonly (infer U)[] ? U extends NonArrayObject ? U | U[] | EntityDataNested<U, C> | EntityDataNested<U, C>[] : U[] | EntityDataNested<U, C>[] : EntityDataNested<T, C>;
|
|
238
|
+
export type RequiredEntityDataProp<T, O, C extends boolean> = T extends Date ? string | Date : Exclude<T, null> extends RequiredNullable.Brand ? T | null : T extends Scalar ? T : T extends {
|
|
225
239
|
__runtime?: infer Runtime;
|
|
226
240
|
__raw?: infer Raw;
|
|
227
|
-
} ? (C extends true ? Raw : Runtime) : T extends Reference<infer U> ? RequiredEntityDataNested<U, O, C> : T extends ScalarReference<infer U> ? RequiredEntityDataProp<U, O, C> : T extends Collection<infer U, any> ? U | U[] | RequiredEntityDataNested<U, O, C> | RequiredEntityDataNested<U, O, C>[] : T extends readonly (infer U)[] ? U | U[] | RequiredEntityDataNested<U, O, C> | RequiredEntityDataNested<U, O, C>[] : RequiredEntityDataNested<T, O, C>;
|
|
241
|
+
} ? (C extends true ? Raw : Runtime) : T extends Reference<infer U> ? RequiredEntityDataNested<U, O, C> : T extends ScalarReference<infer U> ? RequiredEntityDataProp<U, O, C> : T extends Collection<infer U, any> ? U | U[] | RequiredEntityDataNested<U, O, C> | RequiredEntityDataNested<U, O, C>[] : T extends readonly (infer U)[] ? U extends NonArrayObject ? U | U[] | RequiredEntityDataNested<U, O, C> | RequiredEntityDataNested<U, O, C>[] : U[] | RequiredEntityDataNested<U, O, C>[] : RequiredEntityDataNested<T, O, C>;
|
|
228
242
|
export type EntityDataNested<T, C extends boolean = false> = T extends undefined ? never : T extends any[] ? Readonly<T> : EntityData<T, C> | ExpandEntityProp<T, C>;
|
|
229
243
|
type EntityDataItem<T, C extends boolean> = C extends false ? T | EntityDataProp<T, C> | null : EntityDataProp<T, C> | null;
|
|
230
244
|
export type RequiredEntityDataNested<T, O, C extends boolean> = T extends any[] ? Readonly<T> : RequiredEntityData<T, O> | ExpandRequiredEntityProp<T, O, C>;
|
|
@@ -236,7 +250,10 @@ type ExplicitlyOptionalProps<T> = (T extends {
|
|
|
236
250
|
type NullableKeys<T, V = null> = {
|
|
237
251
|
[K in keyof T]: V extends T[K] ? K : never;
|
|
238
252
|
}[keyof T];
|
|
239
|
-
type
|
|
253
|
+
type RequiredNullableKeys<T> = {
|
|
254
|
+
[K in keyof T]: Exclude<T[K], null> extends RequiredNullable.Brand ? K : never;
|
|
255
|
+
}[keyof T];
|
|
256
|
+
type ProbablyOptionalProps<T> = PrimaryProperty<T> | ExplicitlyOptionalProps<T> | Exclude<NonNullable<NullableKeys<T, null | undefined>>, RequiredNullableKeys<T>>;
|
|
240
257
|
type IsOptional<T, K extends keyof T, I> = T[K] extends Collection<any, any> ? true : ExtractType<T[K]> extends I ? true : K extends ProbablyOptionalProps<T> ? true : false;
|
|
241
258
|
type RequiredKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? CleanKeys<T, K> : never;
|
|
242
259
|
type OptionalKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? never : CleanKeys<T, K>;
|
|
@@ -283,7 +300,7 @@ type PrimaryOrObject<T, U, C extends TypeConfig> = PreferExplicitConfig<C, Extra
|
|
|
283
300
|
} : Primary<U>;
|
|
284
301
|
export type EntityDTOProp<E, T, C extends TypeConfig = never> = T extends Scalar ? T : T extends {
|
|
285
302
|
__serialized?: infer U;
|
|
286
|
-
} ? U : T extends LoadedReference<infer U> ? EntityDTO<U, C> : T extends Reference<infer U> ? PrimaryOrObject<E, U, C> : T extends ScalarReference<infer U> ? U : T extends LoadedCollection<infer U> ? EntityDTO<U, C>[] : T extends Collection<infer U> ? PrimaryOrObject<E, U, C>[] : T extends readonly (infer U)[] ? (T extends readonly any[] ? T : U[]) : T extends Relation<T> ? EntityDTO<T, C> : T;
|
|
303
|
+
} ? (IsUnknown<U> extends false ? U : T) : T extends LoadedReference<infer U> ? EntityDTO<U, C> : T extends Reference<infer U> ? PrimaryOrObject<E, U, C> : T extends ScalarReference<infer U> ? U : T extends LoadedCollection<infer U> ? EntityDTO<U, C>[] : T extends Collection<infer U> ? PrimaryOrObject<E, U, C>[] : T extends readonly (infer U)[] ? (T extends readonly any[] ? T : U[]) : T extends Relation<T> ? EntityDTO<T, C> : T;
|
|
287
304
|
type DTOProbablyOptionalProps<T> = NonNullable<NullableKeys<T, undefined>>;
|
|
288
305
|
type DTOIsOptional<T, K extends keyof T> = T[K] extends LoadedCollection<any> ? false : K extends PrimaryProperty<T> ? false : K extends DTOProbablyOptionalProps<T> ? true : false;
|
|
289
306
|
type DTORequiredKeys<T, K extends keyof T> = DTOIsOptional<T, K> extends false ? ExcludeHidden<T, K> & CleanKeys<T, K> : never;
|
|
@@ -294,8 +311,14 @@ export type EntityDTO<T, C extends TypeConfig = never> = {
|
|
|
294
311
|
[K in keyof T as DTOOptionalKeys<T, K>]?: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
|
|
295
312
|
};
|
|
296
313
|
type TargetKeys<T> = T extends EntityClass<infer P> ? keyof P : keyof T;
|
|
297
|
-
type
|
|
298
|
-
|
|
314
|
+
type PropertyName<T> = IsUnknown<T> extends false ? TargetKeys<T> : string;
|
|
315
|
+
type TableName = {
|
|
316
|
+
name: string;
|
|
317
|
+
schema?: string;
|
|
318
|
+
toString: () => string;
|
|
319
|
+
};
|
|
320
|
+
export type IndexCallback<T> = (table: TableName, columns: Record<PropertyName<T>, string>, indexName: string) => string | RawQueryFragment;
|
|
321
|
+
export type CheckCallback<T> = (columns: Record<PropertyName<T>, string>) => string;
|
|
299
322
|
export type GeneratedColumnCallback<T> = (columns: Record<keyof T, string>) => string;
|
|
300
323
|
export interface CheckConstraint<T = any> {
|
|
301
324
|
name?: string;
|
|
@@ -332,6 +355,7 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
332
355
|
default?: string | number | boolean | null;
|
|
333
356
|
defaultRaw?: string;
|
|
334
357
|
formula?: (alias: string) => string;
|
|
358
|
+
filters?: FilterOptions;
|
|
335
359
|
prefix?: string | boolean;
|
|
336
360
|
prefixMode?: EmbeddedPrefixMode;
|
|
337
361
|
embedded?: [EntityKey<Owner>, EntityKey<Owner>];
|
|
@@ -348,7 +372,6 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
348
372
|
mapToPk?: boolean;
|
|
349
373
|
persist?: boolean;
|
|
350
374
|
hydrate?: boolean;
|
|
351
|
-
trackChanges?: boolean;
|
|
352
375
|
hidden?: boolean;
|
|
353
376
|
enum?: boolean;
|
|
354
377
|
items?: (number | string)[];
|
|
@@ -359,6 +382,7 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
359
382
|
setter?: boolean;
|
|
360
383
|
getter?: boolean;
|
|
361
384
|
getterName?: keyof Owner;
|
|
385
|
+
accessor?: EntityKey<Owner>;
|
|
362
386
|
cascade: Cascade[];
|
|
363
387
|
orphanRemoval?: boolean;
|
|
364
388
|
onCreate?: (entity: Owner, em: EntityManager) => any;
|
|
@@ -391,6 +415,8 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
391
415
|
optional?: boolean;
|
|
392
416
|
ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
|
|
393
417
|
deferMode?: DeferMode;
|
|
418
|
+
createForeignKeyConstraint: boolean;
|
|
419
|
+
foreignKeyName?: string;
|
|
394
420
|
}
|
|
395
421
|
export declare class EntityMetadata<T = any> {
|
|
396
422
|
private static counter;
|
|
@@ -399,8 +425,9 @@ export declare class EntityMetadata<T = any> {
|
|
|
399
425
|
constructor(meta?: Partial<EntityMetadata>);
|
|
400
426
|
addProperty(prop: Partial<EntityProperty<T>>, sync?: boolean): void;
|
|
401
427
|
removeProperty(name: string, sync?: boolean): void;
|
|
402
|
-
getPrimaryProps(): EntityProperty<T>[];
|
|
428
|
+
getPrimaryProps(flatten?: boolean): EntityProperty<T>[];
|
|
403
429
|
getPrimaryProp(): EntityProperty<T>;
|
|
430
|
+
createColumnMappingObject(): Dictionary<any>;
|
|
404
431
|
get tableName(): string;
|
|
405
432
|
set tableName(name: string);
|
|
406
433
|
sync(initIndexes?: boolean, config?: Configuration): void;
|
|
@@ -419,14 +446,13 @@ export interface EntityMetadata<T = any> {
|
|
|
419
446
|
schema?: string;
|
|
420
447
|
pivotTable?: boolean;
|
|
421
448
|
virtual?: boolean;
|
|
422
|
-
expression?: string | ((em: any, where:
|
|
449
|
+
expression?: string | ((em: any, where: ObjectQuery<T>, options: FindOptions<T, any, any, any>, stream?: boolean) => MaybePromise<RawQueryFragment | object | string>);
|
|
423
450
|
discriminatorColumn?: EntityKey<T> | AnyString;
|
|
424
451
|
discriminatorValue?: number | string;
|
|
425
452
|
discriminatorMap?: Dictionary<string>;
|
|
426
453
|
embeddable: boolean;
|
|
427
|
-
constructorParams
|
|
454
|
+
constructorParams?: (keyof T)[];
|
|
428
455
|
forceConstructor: boolean;
|
|
429
|
-
toJsonParams: string[];
|
|
430
456
|
extends: string;
|
|
431
457
|
collection: string;
|
|
432
458
|
path: string;
|
|
@@ -435,7 +461,7 @@ export interface EntityMetadata<T = any> {
|
|
|
435
461
|
compositePK: boolean;
|
|
436
462
|
versionProperty: EntityKey<T>;
|
|
437
463
|
concurrencyCheckKeys: Set<EntityKey<T>>;
|
|
438
|
-
serializedPrimaryKey
|
|
464
|
+
serializedPrimaryKey?: EntityKey<T>;
|
|
439
465
|
properties: {
|
|
440
466
|
[K in EntityKey<T>]: EntityProperty<T>;
|
|
441
467
|
};
|
|
@@ -452,18 +478,18 @@ export interface EntityMetadata<T = any> {
|
|
|
452
478
|
uniqueProps: EntityProperty<T>[];
|
|
453
479
|
getterProps: EntityProperty<T>[];
|
|
454
480
|
indexes: {
|
|
455
|
-
properties
|
|
481
|
+
properties?: EntityKey<T> | EntityKey<T>[];
|
|
456
482
|
name?: string;
|
|
457
483
|
type?: string;
|
|
458
484
|
options?: Dictionary;
|
|
459
|
-
expression?: string
|
|
485
|
+
expression?: string | IndexCallback<T>;
|
|
460
486
|
}[];
|
|
461
487
|
uniques: {
|
|
462
|
-
properties
|
|
488
|
+
properties?: EntityKey<T> | EntityKey<T>[];
|
|
463
489
|
name?: string;
|
|
464
490
|
options?: Dictionary;
|
|
465
|
-
expression?: string
|
|
466
|
-
deferMode?: DeferMode
|
|
491
|
+
expression?: string | IndexCallback<T>;
|
|
492
|
+
deferMode?: DeferMode | `${DeferMode}`;
|
|
467
493
|
}[];
|
|
468
494
|
checks: CheckConstraint<T>[];
|
|
469
495
|
repositoryClass?: string;
|
|
@@ -482,6 +508,7 @@ export interface EntityMetadata<T = any> {
|
|
|
482
508
|
polymorphs?: EntityMetadata[];
|
|
483
509
|
root: EntityMetadata<T>;
|
|
484
510
|
definedProperties: Dictionary;
|
|
511
|
+
hasTriggers?: boolean;
|
|
485
512
|
/** @internal can be used for computed numeric cache keys */
|
|
486
513
|
readonly _id: number;
|
|
487
514
|
}
|
|
@@ -492,6 +519,7 @@ export interface CreateSchemaOptions {
|
|
|
492
519
|
export interface ClearDatabaseOptions {
|
|
493
520
|
schema?: string;
|
|
494
521
|
truncate?: boolean;
|
|
522
|
+
clearIdentityMap?: boolean;
|
|
495
523
|
}
|
|
496
524
|
export interface EnsureDatabaseOptions extends CreateSchemaOptions, ClearDatabaseOptions {
|
|
497
525
|
clear?: boolean;
|
|
@@ -554,7 +582,9 @@ export interface GenerateOptions {
|
|
|
554
582
|
undefinedDefaults?: boolean;
|
|
555
583
|
bidirectionalRelations?: boolean;
|
|
556
584
|
identifiedReferences?: boolean;
|
|
557
|
-
|
|
585
|
+
entityDefinition?: 'decorators' | 'defineEntity' | 'entitySchema';
|
|
586
|
+
inferEntityType?: boolean;
|
|
587
|
+
enumMode?: 'ts-enum' | 'union-type' | 'dictionary';
|
|
558
588
|
esmImport?: boolean;
|
|
559
589
|
scalarTypeInDecorator?: boolean;
|
|
560
590
|
scalarPropertiesForRelations?: 'always' | 'never' | 'smart';
|
|
@@ -682,12 +712,17 @@ export interface MigrationObject {
|
|
|
682
712
|
name: string;
|
|
683
713
|
class: Constructor<Migration>;
|
|
684
714
|
}
|
|
685
|
-
|
|
715
|
+
type EntityFromInput<T> = T extends readonly EntityName<infer U>[] ? U : T extends EntityName<infer U> ? U : never;
|
|
716
|
+
type FilterDefResolved<T extends object = any> = {
|
|
686
717
|
name: string;
|
|
687
|
-
cond:
|
|
718
|
+
cond: FilterQuery<T> | ((args: Dictionary, type: 'read' | 'update' | 'delete', em: any, options?: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any>, entityName?: EntityName<T>) => MaybePromise<FilterQuery<T>>);
|
|
688
719
|
default?: boolean;
|
|
689
|
-
entity?:
|
|
720
|
+
entity?: EntityName<T> | EntityName<T>[];
|
|
690
721
|
args?: boolean;
|
|
722
|
+
strict?: boolean;
|
|
723
|
+
};
|
|
724
|
+
export type FilterDef<T extends EntityName<any> | readonly EntityName<any>[] = any> = FilterDefResolved<EntityFromInput<T>> & {
|
|
725
|
+
entity?: T;
|
|
691
726
|
};
|
|
692
727
|
export type Populate<T, P extends string = never> = readonly AutoPath<T, P, `${PopulatePath}`>[] | false;
|
|
693
728
|
export type PopulateOptions<T> = {
|
|
@@ -695,6 +730,7 @@ export type PopulateOptions<T> = {
|
|
|
695
730
|
strategy?: LoadStrategy;
|
|
696
731
|
all?: boolean;
|
|
697
732
|
filter?: boolean;
|
|
733
|
+
joinType?: 'inner join' | 'left join';
|
|
698
734
|
children?: PopulateOptions<T[keyof T]>[];
|
|
699
735
|
};
|
|
700
736
|
type Loadable<T extends object> = Collection<T, any> | Reference<T> | Ref<T> | readonly T[];
|
|
@@ -729,7 +765,7 @@ export type MergeSelected<T, U, F extends string> = T extends Loaded<infer TT, i
|
|
|
729
765
|
type MergeFields<F1 extends string, F2 extends string, P1, P2> = P1 | P2 extends '*' ? '*' : F1 | F2;
|
|
730
766
|
type MergeExcludes<F extends string, E extends string> = F extends E ? never : Exclude<E, F>;
|
|
731
767
|
export type MergeLoaded<T, U, P extends string, F extends string, E extends string, R extends boolean = false> = T extends Loaded<U, infer PP, infer FF, infer EE> ? string extends FF ? Loaded<T, P, F, AnyStringToNever<EE> | E> : string extends P ? Loaded<U, never, F | (FF & string), MergeExcludes<F | (FF & string), EE | E>> : Loaded<U, P | AnyStringToNever<PP>, MergeFields<F, AnyStringToNever<FF>, P, PP>, MergeExcludes<MergeFields<F, AnyStringToNever<FF>, P, PP>, (R extends true ? never : EE) | E>> : Loaded<T, P, F>;
|
|
732
|
-
type AddOptional<T> = undefined | null extends T ? null | undefined : null extends T ? null : undefined extends T ? undefined : never;
|
|
768
|
+
export type AddOptional<T> = undefined | null extends T ? null | undefined : null extends T ? null : undefined extends T ? undefined : never;
|
|
733
769
|
type LoadedProp<T, L extends string = never, F extends string = '*', E extends string = never> = LoadedLoadable<T, Loaded<ExtractType<T>, L, F, E>>;
|
|
734
770
|
export type AddEager<T> = ExtractEagerProps<T> & string;
|
|
735
771
|
export type ExpandHint<T, L extends string> = L | AddEager<T>;
|
|
@@ -790,11 +826,11 @@ export interface IHydrator {
|
|
|
790
826
|
* Hydrates the whole entity. This process handles custom type conversions, creating missing Collection instances,
|
|
791
827
|
* mapping FKs to entity instances, as well as merging those entities.
|
|
792
828
|
*/
|
|
793
|
-
hydrate<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, type: 'full' | 'reference', newEntity?: boolean, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
|
|
829
|
+
hydrate<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, type: 'full' | 'reference', newEntity?: boolean, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void;
|
|
794
830
|
/**
|
|
795
831
|
* Hydrates primary keys only
|
|
796
832
|
*/
|
|
797
|
-
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
|
|
833
|
+
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void;
|
|
798
834
|
isRunning(): boolean;
|
|
799
835
|
}
|
|
800
836
|
export interface HydratorConstructor {
|
|
@@ -817,4 +853,11 @@ export type MetadataProcessor = (metadata: EntityMetadata[], platform: Platform)
|
|
|
817
853
|
export type ContextProvider<T> = MaybePromise<MikroORM> | ((type: T) => MaybePromise<MikroORM | EntityManager | EntityRepository<any> | {
|
|
818
854
|
getEntityManager(): EntityManager;
|
|
819
855
|
}>);
|
|
856
|
+
export type MaybeReturnType<T> = T extends (...args: any[]) => infer R ? R : T;
|
|
857
|
+
export interface EntitySchemaWithMeta<TName extends string = string, TTableName extends string = string, TEntity = any, TBase = never, TProperties extends Record<string, any> = Record<string, any>> extends EntitySchema<TEntity, TBase> {
|
|
858
|
+
readonly name: TName;
|
|
859
|
+
readonly properties: TProperties;
|
|
860
|
+
readonly tableName: TTableName;
|
|
861
|
+
}
|
|
862
|
+
export type InferEntity<Schema> = Schema extends EntitySchemaWithMeta<any, any, infer Entity, any, any> ? Entity : Schema extends EntitySchema<infer Entity> ? Entity : Schema extends EntityClass<infer Entity> ? Entity : Schema;
|
|
820
863
|
export {};
|
package/typings.js
CHANGED
|
@@ -45,12 +45,29 @@ export class EntityMetadata {
|
|
|
45
45
|
this.sync();
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
getPrimaryProps() {
|
|
49
|
-
|
|
48
|
+
getPrimaryProps(flatten = false) {
|
|
49
|
+
const pks = this.primaryKeys.map(pk => this.properties[pk]);
|
|
50
|
+
if (flatten) {
|
|
51
|
+
return pks.flatMap(pk => {
|
|
52
|
+
if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(pk.kind)) {
|
|
53
|
+
return pk.targetMeta.getPrimaryProps(true);
|
|
54
|
+
}
|
|
55
|
+
return [pk];
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return pks;
|
|
50
59
|
}
|
|
51
60
|
getPrimaryProp() {
|
|
52
61
|
return this.properties[this.primaryKeys[0]];
|
|
53
62
|
}
|
|
63
|
+
createColumnMappingObject() {
|
|
64
|
+
return Object.values(this.properties).reduce((o, prop) => {
|
|
65
|
+
if (prop.fieldNames) {
|
|
66
|
+
o[prop.name] = prop.fieldNames[0];
|
|
67
|
+
}
|
|
68
|
+
return o;
|
|
69
|
+
}, {});
|
|
70
|
+
}
|
|
54
71
|
get tableName() {
|
|
55
72
|
return this.collection;
|
|
56
73
|
}
|
|
@@ -70,14 +87,15 @@ export class EntityMetadata {
|
|
|
70
87
|
// `prop.userDefined` is either `undefined` or `false`
|
|
71
88
|
const discriminator = this.root.discriminatorColumn === prop.name && prop.userDefined === false;
|
|
72
89
|
// even if we don't have a setter, do not ignore value from database!
|
|
73
|
-
const onlyGetter = prop.getter && !prop.setter;
|
|
90
|
+
const onlyGetter = prop.getter && !prop.setter && prop.persist === false;
|
|
74
91
|
return !prop.inherited && prop.hydrate !== false && !discriminator && !prop.embedded && !onlyGetter;
|
|
75
92
|
});
|
|
76
|
-
this.trackingProps = this.hydrateProps
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
93
|
+
this.trackingProps = this.hydrateProps.filter(prop => {
|
|
94
|
+
return !prop.getter && !prop.setter && [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind);
|
|
95
|
+
});
|
|
96
|
+
this.selfReferencing = this.relations.some(prop => {
|
|
97
|
+
return [this.className, this.root.className].includes(prop.targetMeta?.root.className ?? prop.type);
|
|
98
|
+
});
|
|
81
99
|
this.hasUniqueProps = this.uniques.length + this.uniqueProps.length > 0;
|
|
82
100
|
this.virtual = !!this.expression;
|
|
83
101
|
if (config) {
|
|
@@ -109,8 +127,7 @@ export class EntityMetadata {
|
|
|
109
127
|
this.props.forEach(prop => this.initIndexes(prop));
|
|
110
128
|
}
|
|
111
129
|
this.definedProperties = this.trackingProps.reduce((o, prop) => {
|
|
112
|
-
const
|
|
113
|
-
const isReference = [ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(prop.kind) && (prop.inversedBy || prop.mappedBy) && !prop.mapToPk;
|
|
130
|
+
const isReference = (prop.inversedBy || prop.mappedBy) && !prop.mapToPk;
|
|
114
131
|
if (isReference) {
|
|
115
132
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
116
133
|
const meta = this;
|
|
@@ -123,13 +140,13 @@ export class EntityMetadata {
|
|
|
123
140
|
const hydrator = wrapped.hydrator;
|
|
124
141
|
const entity = Reference.unwrapReference(val ?? wrapped.__data[prop.name]);
|
|
125
142
|
const old = Reference.unwrapReference(wrapped.__data[prop.name]);
|
|
143
|
+
if (old && old !== entity && prop.kind === ReferenceKind.MANY_TO_ONE && prop.inversedBy && old[prop.inversedBy]) {
|
|
144
|
+
old[prop.inversedBy].removeWithoutPropagation(this);
|
|
145
|
+
}
|
|
126
146
|
wrapped.__data[prop.name] = Reference.wrapReference(val, prop);
|
|
127
147
|
// when propagation from inside hydration, we set the FK to the entity data immediately
|
|
128
148
|
if (val && hydrator.isRunning() && wrapped.__originalEntityData && prop.owner) {
|
|
129
|
-
wrapped.__originalEntityData[prop.name] = Utils.getPrimaryKeyValues(val, prop.targetMeta
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
wrapped.__touched = !hydrator.isRunning();
|
|
149
|
+
wrapped.__originalEntityData[prop.name] = Utils.getPrimaryKeyValues(val, prop.targetMeta, true);
|
|
133
150
|
}
|
|
134
151
|
EntityHelper.propagate(meta, entity, this, prop, Reference.unwrapReference(val), old);
|
|
135
152
|
},
|
|
@@ -137,23 +154,6 @@ export class EntityMetadata {
|
|
|
137
154
|
configurable: true,
|
|
138
155
|
};
|
|
139
156
|
}
|
|
140
|
-
if (prop.inherited || prop.primary || isCollection || prop.persist === false || prop.trackChanges === false || isReference || prop.embedded) {
|
|
141
|
-
return o;
|
|
142
|
-
}
|
|
143
|
-
o[prop.name] = {
|
|
144
|
-
get() {
|
|
145
|
-
return this.__helper.__data[prop.name];
|
|
146
|
-
},
|
|
147
|
-
set(val) {
|
|
148
|
-
if (typeof val === 'object' && !!val && '__raw' in val) {
|
|
149
|
-
val.assign();
|
|
150
|
-
}
|
|
151
|
-
this.__helper.__data[prop.name] = val;
|
|
152
|
-
this.__helper.__touched = !this.__helper.hydrator.isRunning();
|
|
153
|
-
},
|
|
154
|
-
enumerable: true,
|
|
155
|
-
configurable: true,
|
|
156
|
-
};
|
|
157
157
|
return o;
|
|
158
158
|
}, { __gettersDefined: { value: true, enumerable: false } });
|
|
159
159
|
}
|
|
@@ -34,8 +34,11 @@ export class ChangeSetComputer {
|
|
|
34
34
|
this.processPropertyInitializers(entity, prop, type, map);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
if (type === ChangeSetType.UPDATE && !wrapped.__initialized
|
|
38
|
-
|
|
37
|
+
if (type === ChangeSetType.UPDATE && !wrapped.__initialized) {
|
|
38
|
+
const data = this.comparator.prepareEntity(entity);
|
|
39
|
+
if (Utils.equals(data, wrapped.__originalEntityData)) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
39
42
|
}
|
|
40
43
|
const changeSet = new ChangeSet(entity, type, this.computePayload(entity), meta);
|
|
41
44
|
changeSet.originalEntity = wrapped.__originalEntityData;
|
|
@@ -141,7 +144,9 @@ export class ChangeSetComputer {
|
|
|
141
144
|
if (!target.isDirty() && changeSet.type !== ChangeSetType.CREATE) {
|
|
142
145
|
return;
|
|
143
146
|
}
|
|
144
|
-
|
|
147
|
+
if (target.isDirty()) {
|
|
148
|
+
this.collectionUpdates.add(target);
|
|
149
|
+
}
|
|
145
150
|
if (prop.owner && !this.platform.usesPivotTable()) {
|
|
146
151
|
changeSet.payload[prop.name] = target.getItems(false).map((item) => item.__helper.__identifier ?? item.__helper.getPrimaryKey());
|
|
147
152
|
}
|
|
@@ -5,6 +5,7 @@ import { type EntityValidator } from '../entity/EntityValidator.js';
|
|
|
5
5
|
import { type ChangeSet } from './ChangeSet.js';
|
|
6
6
|
import { type Configuration } from '../utils/Configuration.js';
|
|
7
7
|
import type { DriverMethodOptions, IDatabaseDriver } from '../drivers/IDatabaseDriver.js';
|
|
8
|
+
import type { EntityManager } from '../EntityManager.js';
|
|
8
9
|
export declare class ChangeSetPersister {
|
|
9
10
|
private readonly driver;
|
|
10
11
|
private readonly metadata;
|
|
@@ -12,10 +13,11 @@ export declare class ChangeSetPersister {
|
|
|
12
13
|
private readonly factory;
|
|
13
14
|
private readonly validator;
|
|
14
15
|
private readonly config;
|
|
16
|
+
private readonly em;
|
|
15
17
|
private readonly platform;
|
|
16
18
|
private readonly comparator;
|
|
17
19
|
private readonly usesReturningStatement;
|
|
18
|
-
constructor(driver: IDatabaseDriver, metadata: MetadataStorage, hydrator: IHydrator, factory: EntityFactory, validator: EntityValidator, config: Configuration);
|
|
20
|
+
constructor(driver: IDatabaseDriver, metadata: MetadataStorage, hydrator: IHydrator, factory: EntityFactory, validator: EntityValidator, config: Configuration, em: EntityManager);
|
|
19
21
|
executeInserts<T extends object>(changeSets: ChangeSet<T>[], options?: DriverMethodOptions, withSchema?: boolean): Promise<void>;
|
|
20
22
|
executeUpdates<T extends object>(changeSets: ChangeSet<T>[], batched: boolean, options?: DriverMethodOptions, withSchema?: boolean): Promise<void>;
|
|
21
23
|
executeDeletes<T extends object>(changeSets: ChangeSet<T>[], options?: DriverMethodOptions, withSchema?: boolean): Promise<void>;
|
|
@@ -23,7 +25,7 @@ export declare class ChangeSetPersister {
|
|
|
23
25
|
private processProperties;
|
|
24
26
|
private persistNewEntity;
|
|
25
27
|
private persistNewEntities;
|
|
26
|
-
private
|
|
28
|
+
private prepareOptions;
|
|
27
29
|
private persistNewEntitiesBatch;
|
|
28
30
|
private persistManagedEntity;
|
|
29
31
|
private persistManagedEntities;
|