@mikro-orm/core 7.0.0-dev.7 → 7.0.0-dev.70
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 -42
- package/EntityManager.js +282 -194
- package/MikroORM.d.ts +11 -29
- package/MikroORM.js +33 -127
- 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/drivers/DatabaseDriver.d.ts +11 -5
- package/drivers/DatabaseDriver.js +13 -4
- package/drivers/IDatabaseDriver.d.ts +27 -5
- package/entity/BaseEntity.d.ts +0 -1
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +98 -30
- package/entity/Collection.js +432 -93
- 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 +4 -4
- 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 +549 -0
- package/entity/defineEntity.js +529 -0
- package/entity/index.d.ts +2 -1
- package/entity/index.js +2 -1
- package/entity/utils.d.ts +7 -0
- package/entity/utils.js +15 -3
- package/enums.d.ts +20 -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 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/SimpleLogger.d.ts +1 -1
- package/metadata/EntitySchema.d.ts +9 -13
- package/metadata/EntitySchema.js +44 -26
- package/metadata/MetadataDiscovery.d.ts +6 -7
- package/metadata/MetadataDiscovery.js +161 -162
- package/metadata/MetadataProvider.d.ts +2 -2
- package/metadata/MetadataProvider.js +15 -0
- package/metadata/MetadataStorage.d.ts +0 -4
- package/metadata/MetadataStorage.js +7 -11
- package/metadata/MetadataValidator.d.ts +0 -7
- package/metadata/MetadataValidator.js +4 -13
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +39 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +1 -1
- package/metadata/types.d.ts +480 -0
- package/metadata/types.js +1 -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 +11 -10
- package/platforms/Platform.d.ts +6 -10
- package/platforms/Platform.js +6 -22
- 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/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +1 -2
- package/types/BigIntType.d.ts +8 -6
- 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 +112 -77
- package/typings.js +32 -32
- 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 +111 -54
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +10 -8
- package/utils/Configuration.d.ts +202 -191
- package/utils/Configuration.js +143 -153
- package/utils/ConfigurationLoader.d.ts +3 -44
- package/utils/ConfigurationLoader.js +26 -239
- 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 +107 -60
- package/utils/QueryHelper.d.ts +9 -1
- package/utils/QueryHelper.js +69 -8
- 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 +18 -85
- package/utils/Utils.js +128 -252
- 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/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -13
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -32
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -11
- package/decorators/Embedded.d.ts +0 -18
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -18
- package/decorators/Entity.js +0 -12
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -16
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -8
- package/decorators/Formula.d.ts +0 -4
- package/decorators/Formula.js +0 -15
- package/decorators/Indexed.d.ts +0 -19
- package/decorators/Indexed.js +0 -20
- package/decorators/ManyToMany.d.ts +0 -40
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -30
- package/decorators/ManyToOne.js +0 -14
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -17
- package/decorators/OneToOne.d.ts +0 -24
- package/decorators/OneToOne.js +0 -7
- package/decorators/PrimaryKey.d.ts +0 -8
- package/decorators/PrimaryKey.js +0 -20
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -32
- package/decorators/Transactional.d.ts +0 -13
- package/decorators/Transactional.js +0 -28
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -47
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -17
- package/entity/ArrayCollection.d.ts +0 -116
- package/entity/ArrayCollection.js +0 -402
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -44
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -28
package/typings.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Transaction } from './connections/Connection.js';
|
|
2
|
-
import { type Cascade, type DeferMode, type EventType, type LoadStrategy, type PopulatePath, type QueryOrderMap, ReferenceKind } from './enums.js';
|
|
2
|
+
import { type Cascade, type DeferMode, type EmbeddedPrefixMode, type EventType, type LoadStrategy, type PopulatePath, type QueryOrderMap, ReferenceKind } from './enums.js';
|
|
3
3
|
import { type AssignOptions } from './entity/EntityAssigner.js';
|
|
4
4
|
import { type EntityIdentifier } from './entity/EntityIdentifier.js';
|
|
5
5
|
import { type EntityLoaderOptions } from './entity/EntityLoader.js';
|
|
@@ -7,7 +7,6 @@ import { type Collection } from './entity/Collection.js';
|
|
|
7
7
|
import { type EntityFactory } from './entity/EntityFactory.js';
|
|
8
8
|
import { type EntityRepository } from './entity/EntityRepository.js';
|
|
9
9
|
import { Reference, type ScalarReference } from './entity/Reference.js';
|
|
10
|
-
import type { MikroORM } from './MikroORM.js';
|
|
11
10
|
import type { SerializationContext } from './serialization/SerializationContext.js';
|
|
12
11
|
import type { SerializeOptions } from './serialization/EntitySerializer.js';
|
|
13
12
|
import type { MetadataStorage } from './metadata/MetadataStorage.js';
|
|
@@ -17,9 +16,8 @@ import type { Platform } from './platforms/Platform.js';
|
|
|
17
16
|
import type { Configuration } from './utils/Configuration.js';
|
|
18
17
|
import type { RawQueryFragment } from './utils/RawQueryFragment.js';
|
|
19
18
|
import type { EntityManager } from './EntityManager.js';
|
|
20
|
-
import type { EmbeddedPrefixMode } from './decorators/Embedded.js';
|
|
21
19
|
import type { EventSubscriber } from './events/EventSubscriber.js';
|
|
22
|
-
import type { FindOneOptions, FindOptions, LoadHint } from './drivers/IDatabaseDriver.js';
|
|
20
|
+
import type { FilterOptions, FindOneOptions, FindOptions, LoadHint } from './drivers/IDatabaseDriver.js';
|
|
23
21
|
export type Constructor<T = unknown> = new (...args: any[]) => T;
|
|
24
22
|
export type Dictionary<T = any> = {
|
|
25
23
|
[k: string]: T;
|
|
@@ -52,18 +50,34 @@ export declare const OptionalProps: unique symbol;
|
|
|
52
50
|
export declare const EagerProps: unique symbol;
|
|
53
51
|
export declare const HiddenProps: unique symbol;
|
|
54
52
|
export declare const Config: unique symbol;
|
|
55
|
-
|
|
56
|
-
declare
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
export type Opt<T = unknown> = T & Opt.Brand;
|
|
54
|
+
export declare namespace Opt {
|
|
55
|
+
const __optional: unique symbol;
|
|
56
|
+
interface Brand {
|
|
57
|
+
[__optional]?: 1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export type RequiredNullable<T = never> = (T & RequiredNullable.Brand) | null;
|
|
61
|
+
export declare namespace RequiredNullable {
|
|
62
|
+
const __requiredNullable: unique symbol;
|
|
63
|
+
interface Brand {
|
|
64
|
+
[__requiredNullable]?: 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export type Hidden<T = unknown> = T & Hidden.Brand;
|
|
68
|
+
export declare namespace Hidden {
|
|
69
|
+
const __hidden: unique symbol;
|
|
70
|
+
interface Brand {
|
|
71
|
+
[__hidden]?: 1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export type DefineConfig<T extends TypeConfig> = T & DefineConfig.Brand;
|
|
75
|
+
export declare namespace DefineConfig {
|
|
76
|
+
const __config: unique symbol;
|
|
77
|
+
interface Brand {
|
|
78
|
+
[__config]?: 1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
67
81
|
export type CleanTypeConfig<T> = Compute<Pick<T, Extract<keyof T, keyof TypeConfig>>>;
|
|
68
82
|
export interface TypeConfig {
|
|
69
83
|
forceObject?: boolean;
|
|
@@ -75,13 +89,14 @@ type PrimaryPropToType<T, Keys extends (keyof T)[]> = {
|
|
|
75
89
|
type ReadonlyPrimary<T> = T extends any[] ? Readonly<T> : T;
|
|
76
90
|
export type Primary<T> = IsAny<T> extends true ? any : T extends {
|
|
77
91
|
[PrimaryKeyProp]?: infer PK;
|
|
78
|
-
} ?
|
|
92
|
+
} ? 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
93
|
_id?: infer PK;
|
|
80
94
|
} ? ReadonlyPrimary<PK> | string : T extends {
|
|
81
|
-
uuid?: infer PK;
|
|
82
|
-
} ? ReadonlyPrimary<PK> : T extends {
|
|
83
95
|
id?: infer PK;
|
|
96
|
+
} ? ReadonlyPrimary<PK> : T extends {
|
|
97
|
+
uuid?: infer PK;
|
|
84
98
|
} ? ReadonlyPrimary<PK> : T;
|
|
99
|
+
/** @internal */
|
|
85
100
|
export type PrimaryProperty<T> = T extends {
|
|
86
101
|
[PrimaryKeyProp]?: infer PK;
|
|
87
102
|
} ? (PK extends keyof T ? PK : (PK extends any[] ? PK[number] : never)) : T extends {
|
|
@@ -89,10 +104,10 @@ export type PrimaryProperty<T> = T extends {
|
|
|
89
104
|
} ? (T extends {
|
|
90
105
|
id?: any;
|
|
91
106
|
} ? 'id' | '_id' : '_id') : T extends {
|
|
92
|
-
uuid?: any;
|
|
93
|
-
} ? 'uuid' : T extends {
|
|
94
107
|
id?: any;
|
|
95
|
-
} ? 'id' :
|
|
108
|
+
} ? 'id' : T extends {
|
|
109
|
+
uuid?: any;
|
|
110
|
+
} ? 'uuid' : never;
|
|
96
111
|
export type IPrimaryKeyValue = number | string | bigint | Date | {
|
|
97
112
|
toHexString(): string;
|
|
98
113
|
};
|
|
@@ -133,7 +148,6 @@ export type FilterValue<T> = OperatorMap<FilterItemValue<T>> | FilterItemValue<T
|
|
|
133
148
|
export type FilterObject<T> = {
|
|
134
149
|
-readonly [K in EntityKey<T>]?: ExpandQuery<ExpandProperty<T[K]>> | FilterValue<ExpandProperty<T[K]>> | null;
|
|
135
150
|
};
|
|
136
|
-
export type ExpandObject<T> = T extends object ? T extends Scalar ? never : FilterObject<T> : never;
|
|
137
151
|
export type ExpandQuery<T> = T extends object ? T extends Scalar ? never : FilterQuery<T> : FilterValue<T>;
|
|
138
152
|
export type EntityProps<T> = {
|
|
139
153
|
-readonly [K in EntityKey<T>]?: T[K];
|
|
@@ -143,7 +157,6 @@ export type FilterQuery<T> = ObjectQuery<T> | NonNullable<ExpandScalar<Primary<T
|
|
|
143
157
|
export type QBFilterQuery<T = any> = ObjectQuery<T> | Dictionary;
|
|
144
158
|
export interface IWrappedEntity<Entity extends object> {
|
|
145
159
|
isInitialized(): boolean;
|
|
146
|
-
isTouched(): boolean;
|
|
147
160
|
isManaged(): boolean;
|
|
148
161
|
populated(populated?: boolean): void;
|
|
149
162
|
populate<Hint extends string = never>(populate: AutoPath<Entity, Hint>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
|
|
@@ -174,10 +187,9 @@ export interface IWrappedEntityInternal<Entity extends object> extends IWrappedE
|
|
|
174
187
|
__factory: EntityFactory;
|
|
175
188
|
__hydrator: IHydrator;
|
|
176
189
|
__initialized: boolean;
|
|
177
|
-
__touched: boolean;
|
|
178
190
|
__originalEntityData?: EntityData<Entity>;
|
|
179
191
|
__loadedProperties: Set<string>;
|
|
180
|
-
__identifier?: EntityIdentifier;
|
|
192
|
+
__identifier?: EntityIdentifier | EntityIdentifier[];
|
|
181
193
|
__managed: boolean;
|
|
182
194
|
__processing: boolean;
|
|
183
195
|
__schema?: string;
|
|
@@ -197,16 +209,12 @@ export type AnyEntity<T = any> = Partial<T>;
|
|
|
197
209
|
export type EntityClass<T> = Function & {
|
|
198
210
|
prototype: T;
|
|
199
211
|
};
|
|
200
|
-
export type EntityClassGroup<T> = {
|
|
201
|
-
entity: EntityClass<T>;
|
|
202
|
-
schema: EntityMetadata<T> | EntitySchema<T>;
|
|
203
|
-
};
|
|
204
212
|
export type EntityName<T> = string | EntityClass<T> | EntitySchema<T, any> | {
|
|
205
213
|
name: string;
|
|
206
214
|
};
|
|
207
215
|
export type GetRepository<Entity extends {
|
|
208
216
|
[k: PropertyKey]: any;
|
|
209
|
-
}, Fallback> = Entity[typeof EntityRepositoryType] extends EntityRepository<
|
|
217
|
+
}, Fallback> = Entity[typeof EntityRepositoryType] extends EntityRepository<any> | undefined ? NonNullable<Entity[typeof EntityRepositoryType]> : Fallback;
|
|
210
218
|
export type EntityDataPropValue<T> = T | Primary<T>;
|
|
211
219
|
type ExpandEntityProp<T, C extends boolean = false> = T extends Record<string, any> ? {
|
|
212
220
|
[K in keyof T as CleanKeys<T, K>]?: EntityDataProp<ExpandProperty<T[K]>, C> | EntityDataPropValue<ExpandProperty<T[K]>> | null;
|
|
@@ -217,14 +225,17 @@ type ExpandRequiredEntityPropObject<T, I = never, C extends boolean = false> = {
|
|
|
217
225
|
} & {
|
|
218
226
|
[K in keyof T as OptionalKeys<T, K, I>]?: RequiredEntityDataProp<ExpandProperty<T[K]>, T, C> | EntityDataPropValue<ExpandProperty<T[K]>> | null | undefined;
|
|
219
227
|
};
|
|
228
|
+
type NonArrayObject = object & {
|
|
229
|
+
[Symbol.iterator]?: never;
|
|
230
|
+
};
|
|
220
231
|
export type EntityDataProp<T, C extends boolean> = T extends Date ? string | Date : T extends Scalar ? T : T extends {
|
|
221
232
|
__runtime?: infer Runtime;
|
|
222
233
|
__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 {
|
|
234
|
+
} ? (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>;
|
|
235
|
+
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
236
|
__runtime?: infer Runtime;
|
|
226
237
|
__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>;
|
|
238
|
+
} ? (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
239
|
export type EntityDataNested<T, C extends boolean = false> = T extends undefined ? never : T extends any[] ? Readonly<T> : EntityData<T, C> | ExpandEntityProp<T, C>;
|
|
229
240
|
type EntityDataItem<T, C extends boolean> = C extends false ? T | EntityDataProp<T, C> | null : EntityDataProp<T, C> | null;
|
|
230
241
|
export type RequiredEntityDataNested<T, O, C extends boolean> = T extends any[] ? Readonly<T> : RequiredEntityData<T, O> | ExpandRequiredEntityProp<T, O, C>;
|
|
@@ -236,7 +247,10 @@ type ExplicitlyOptionalProps<T> = (T extends {
|
|
|
236
247
|
type NullableKeys<T, V = null> = {
|
|
237
248
|
[K in keyof T]: V extends T[K] ? K : never;
|
|
238
249
|
}[keyof T];
|
|
239
|
-
type
|
|
250
|
+
type RequiredNullableKeys<T> = {
|
|
251
|
+
[K in keyof T]: Exclude<T[K], null> extends RequiredNullable.Brand ? K : never;
|
|
252
|
+
}[keyof T];
|
|
253
|
+
type ProbablyOptionalProps<T> = PrimaryProperty<T> | ExplicitlyOptionalProps<T> | Exclude<NonNullable<NullableKeys<T, null | undefined>>, RequiredNullableKeys<T>>;
|
|
240
254
|
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
255
|
type RequiredKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? CleanKeys<T, K> : never;
|
|
242
256
|
type OptionalKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? never : CleanKeys<T, K>;
|
|
@@ -283,7 +297,7 @@ type PrimaryOrObject<T, U, C extends TypeConfig> = PreferExplicitConfig<C, Extra
|
|
|
283
297
|
} : Primary<U>;
|
|
284
298
|
export type EntityDTOProp<E, T, C extends TypeConfig = never> = T extends Scalar ? T : T extends {
|
|
285
299
|
__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;
|
|
300
|
+
} ? (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
301
|
type DTOProbablyOptionalProps<T> = NonNullable<NullableKeys<T, undefined>>;
|
|
288
302
|
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
303
|
type DTORequiredKeys<T, K extends keyof T> = DTOIsOptional<T, K> extends false ? ExcludeHidden<T, K> & CleanKeys<T, K> : never;
|
|
@@ -294,8 +308,14 @@ export type EntityDTO<T, C extends TypeConfig = never> = {
|
|
|
294
308
|
[K in keyof T as DTOOptionalKeys<T, K>]?: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
|
|
295
309
|
};
|
|
296
310
|
type TargetKeys<T> = T extends EntityClass<infer P> ? keyof P : keyof T;
|
|
297
|
-
type
|
|
298
|
-
|
|
311
|
+
type PropertyName<T> = IsUnknown<T> extends false ? TargetKeys<T> : string;
|
|
312
|
+
type TableName = {
|
|
313
|
+
name: string;
|
|
314
|
+
schema?: string;
|
|
315
|
+
toString: () => string;
|
|
316
|
+
};
|
|
317
|
+
export type IndexCallback<T> = (table: TableName, columns: Record<PropertyName<T>, string>, indexName: string) => string | RawQueryFragment;
|
|
318
|
+
export type CheckCallback<T> = (columns: Record<PropertyName<T>, string>) => string;
|
|
299
319
|
export type GeneratedColumnCallback<T> = (columns: Record<keyof T, string>) => string;
|
|
300
320
|
export interface CheckConstraint<T = any> {
|
|
301
321
|
name?: string;
|
|
@@ -332,6 +352,7 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
332
352
|
default?: string | number | boolean | null;
|
|
333
353
|
defaultRaw?: string;
|
|
334
354
|
formula?: (alias: string) => string;
|
|
355
|
+
filters?: FilterOptions;
|
|
335
356
|
prefix?: string | boolean;
|
|
336
357
|
prefixMode?: EmbeddedPrefixMode;
|
|
337
358
|
embedded?: [EntityKey<Owner>, EntityKey<Owner>];
|
|
@@ -348,7 +369,6 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
348
369
|
mapToPk?: boolean;
|
|
349
370
|
persist?: boolean;
|
|
350
371
|
hydrate?: boolean;
|
|
351
|
-
trackChanges?: boolean;
|
|
352
372
|
hidden?: boolean;
|
|
353
373
|
enum?: boolean;
|
|
354
374
|
items?: (number | string)[];
|
|
@@ -359,6 +379,7 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
359
379
|
setter?: boolean;
|
|
360
380
|
getter?: boolean;
|
|
361
381
|
getterName?: keyof Owner;
|
|
382
|
+
accessor?: EntityKey<Owner>;
|
|
362
383
|
cascade: Cascade[];
|
|
363
384
|
orphanRemoval?: boolean;
|
|
364
385
|
onCreate?: (entity: Owner, em: EntityManager) => any;
|
|
@@ -391,6 +412,8 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
391
412
|
optional?: boolean;
|
|
392
413
|
ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
|
|
393
414
|
deferMode?: DeferMode;
|
|
415
|
+
createForeignKeyConstraint: boolean;
|
|
416
|
+
foreignKeyName?: string;
|
|
394
417
|
}
|
|
395
418
|
export declare class EntityMetadata<T = any> {
|
|
396
419
|
private static counter;
|
|
@@ -399,8 +422,9 @@ export declare class EntityMetadata<T = any> {
|
|
|
399
422
|
constructor(meta?: Partial<EntityMetadata>);
|
|
400
423
|
addProperty(prop: Partial<EntityProperty<T>>, sync?: boolean): void;
|
|
401
424
|
removeProperty(name: string, sync?: boolean): void;
|
|
402
|
-
getPrimaryProps(): EntityProperty<T>[];
|
|
425
|
+
getPrimaryProps(flatten?: boolean): EntityProperty<T>[];
|
|
403
426
|
getPrimaryProp(): EntityProperty<T>;
|
|
427
|
+
createColumnMappingObject(): Dictionary<any>;
|
|
404
428
|
get tableName(): string;
|
|
405
429
|
set tableName(name: string);
|
|
406
430
|
sync(initIndexes?: boolean, config?: Configuration): void;
|
|
@@ -419,14 +443,13 @@ export interface EntityMetadata<T = any> {
|
|
|
419
443
|
schema?: string;
|
|
420
444
|
pivotTable?: boolean;
|
|
421
445
|
virtual?: boolean;
|
|
422
|
-
expression?: string | ((em: any, where: ObjectQuery<T>, options: FindOptions<T, any, any, any
|
|
446
|
+
expression?: string | ((em: any, where: ObjectQuery<T>, options: FindOptions<T, any, any, any>, stream?: boolean) => MaybePromise<RawQueryFragment | object | string>);
|
|
423
447
|
discriminatorColumn?: EntityKey<T> | AnyString;
|
|
424
448
|
discriminatorValue?: number | string;
|
|
425
449
|
discriminatorMap?: Dictionary<string>;
|
|
426
450
|
embeddable: boolean;
|
|
427
|
-
constructorParams
|
|
451
|
+
constructorParams?: (keyof T)[];
|
|
428
452
|
forceConstructor: boolean;
|
|
429
|
-
toJsonParams: string[];
|
|
430
453
|
extends: string;
|
|
431
454
|
collection: string;
|
|
432
455
|
path: string;
|
|
@@ -435,7 +458,7 @@ export interface EntityMetadata<T = any> {
|
|
|
435
458
|
compositePK: boolean;
|
|
436
459
|
versionProperty: EntityKey<T>;
|
|
437
460
|
concurrencyCheckKeys: Set<EntityKey<T>>;
|
|
438
|
-
serializedPrimaryKey
|
|
461
|
+
serializedPrimaryKey?: EntityKey<T>;
|
|
439
462
|
properties: {
|
|
440
463
|
[K in EntityKey<T>]: EntityProperty<T>;
|
|
441
464
|
};
|
|
@@ -452,18 +475,18 @@ export interface EntityMetadata<T = any> {
|
|
|
452
475
|
uniqueProps: EntityProperty<T>[];
|
|
453
476
|
getterProps: EntityProperty<T>[];
|
|
454
477
|
indexes: {
|
|
455
|
-
properties
|
|
478
|
+
properties?: EntityKey<T> | EntityKey<T>[];
|
|
456
479
|
name?: string;
|
|
457
480
|
type?: string;
|
|
458
481
|
options?: Dictionary;
|
|
459
|
-
expression?: string
|
|
482
|
+
expression?: string | IndexCallback<T>;
|
|
460
483
|
}[];
|
|
461
484
|
uniques: {
|
|
462
|
-
properties
|
|
485
|
+
properties?: EntityKey<T> | EntityKey<T>[];
|
|
463
486
|
name?: string;
|
|
464
487
|
options?: Dictionary;
|
|
465
|
-
expression?: string
|
|
466
|
-
deferMode?: DeferMode
|
|
488
|
+
expression?: string | IndexCallback<T>;
|
|
489
|
+
deferMode?: DeferMode | `${DeferMode}`;
|
|
467
490
|
}[];
|
|
468
491
|
checks: CheckConstraint<T>[];
|
|
469
492
|
repositoryClass?: string;
|
|
@@ -482,6 +505,7 @@ export interface EntityMetadata<T = any> {
|
|
|
482
505
|
polymorphs?: EntityMetadata[];
|
|
483
506
|
root: EntityMetadata<T>;
|
|
484
507
|
definedProperties: Dictionary;
|
|
508
|
+
hasTriggers?: boolean;
|
|
485
509
|
/** @internal can be used for computed numeric cache keys */
|
|
486
510
|
readonly _id: number;
|
|
487
511
|
}
|
|
@@ -492,6 +516,7 @@ export interface CreateSchemaOptions {
|
|
|
492
516
|
export interface ClearDatabaseOptions {
|
|
493
517
|
schema?: string;
|
|
494
518
|
truncate?: boolean;
|
|
519
|
+
clearIdentityMap?: boolean;
|
|
495
520
|
}
|
|
496
521
|
export interface EnsureDatabaseOptions extends CreateSchemaOptions, ClearDatabaseOptions {
|
|
497
522
|
clear?: boolean;
|
|
@@ -519,25 +544,25 @@ export interface RefreshDatabaseOptions extends CreateSchemaOptions {
|
|
|
519
544
|
createSchema?: boolean;
|
|
520
545
|
}
|
|
521
546
|
export interface ISchemaGenerator {
|
|
522
|
-
|
|
523
|
-
|
|
547
|
+
create(options?: CreateSchemaOptions): Promise<void>;
|
|
548
|
+
update(options?: UpdateSchemaOptions): Promise<void>;
|
|
549
|
+
drop(options?: DropSchemaOptions): Promise<void>;
|
|
550
|
+
refresh(options?: RefreshDatabaseOptions): Promise<void>;
|
|
551
|
+
clear(options?: ClearDatabaseOptions): Promise<void>;
|
|
552
|
+
execute(sql: string, options?: {
|
|
553
|
+
wrap?: boolean;
|
|
554
|
+
}): Promise<void>;
|
|
524
555
|
getCreateSchemaSQL(options?: CreateSchemaOptions): Promise<string>;
|
|
525
|
-
dropSchema(options?: DropSchemaOptions): Promise<void>;
|
|
526
556
|
getDropSchemaSQL(options?: Omit<DropSchemaOptions, 'dropDb'>): Promise<string>;
|
|
527
|
-
updateSchema(options?: UpdateSchemaOptions): Promise<void>;
|
|
528
557
|
getUpdateSchemaSQL(options?: UpdateSchemaOptions): Promise<string>;
|
|
529
558
|
getUpdateSchemaMigrationSQL(options?: UpdateSchemaOptions): Promise<{
|
|
530
559
|
up: string;
|
|
531
560
|
down: string;
|
|
532
561
|
}>;
|
|
562
|
+
ensureDatabase(options?: EnsureDatabaseOptions): Promise<boolean>;
|
|
533
563
|
createDatabase(name?: string): Promise<void>;
|
|
534
564
|
dropDatabase(name?: string): Promise<void>;
|
|
535
|
-
execute(sql: string, options?: {
|
|
536
|
-
wrap?: boolean;
|
|
537
|
-
}): Promise<void>;
|
|
538
565
|
ensureIndexes(): Promise<void>;
|
|
539
|
-
refreshDatabase(options?: RefreshDatabaseOptions): Promise<void>;
|
|
540
|
-
clearDatabase(options?: ClearDatabaseOptions): Promise<void>;
|
|
541
566
|
}
|
|
542
567
|
export type ImportsResolver = (alias: string, basePath: string, extension: '.js' | '', originFileName: string) => {
|
|
543
568
|
path: string;
|
|
@@ -554,7 +579,10 @@ export interface GenerateOptions {
|
|
|
554
579
|
undefinedDefaults?: boolean;
|
|
555
580
|
bidirectionalRelations?: boolean;
|
|
556
581
|
identifiedReferences?: boolean;
|
|
557
|
-
|
|
582
|
+
entityDefinition?: 'decorators' | 'defineEntity' | 'entitySchema';
|
|
583
|
+
decorators?: 'es' | 'legacy';
|
|
584
|
+
inferEntityType?: boolean;
|
|
585
|
+
enumMode?: 'ts-enum' | 'union-type' | 'dictionary';
|
|
558
586
|
esmImport?: boolean;
|
|
559
587
|
scalarTypeInDecorator?: boolean;
|
|
560
588
|
scalarPropertiesForRelations?: 'always' | 'never' | 'smart';
|
|
@@ -614,26 +642,26 @@ export interface IMigrator {
|
|
|
614
642
|
/**
|
|
615
643
|
* Checks current schema for changes, generates new migration if there are any.
|
|
616
644
|
*/
|
|
617
|
-
|
|
645
|
+
create(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<MigrationResult>;
|
|
618
646
|
/**
|
|
619
647
|
* Checks current schema for changes.
|
|
620
648
|
*/
|
|
621
|
-
|
|
649
|
+
checkSchema(): Promise<boolean>;
|
|
622
650
|
/**
|
|
623
651
|
* Creates initial migration. This generates the schema based on metadata, and checks whether all the tables
|
|
624
652
|
* are already present. If yes, it will also automatically log the migration as executed.
|
|
625
653
|
* Initial migration can be created only if the schema is already aligned with the metadata, or when no schema
|
|
626
654
|
* is present - in such case regular migration would have the same effect.
|
|
627
655
|
*/
|
|
628
|
-
|
|
656
|
+
createInitial(path?: string): Promise<MigrationResult>;
|
|
629
657
|
/**
|
|
630
658
|
* Returns list of already executed migrations.
|
|
631
659
|
*/
|
|
632
|
-
|
|
660
|
+
getExecuted(): Promise<MigrationRow[]>;
|
|
633
661
|
/**
|
|
634
662
|
* Returns list of pending (not yet executed) migrations found in the migration directory.
|
|
635
663
|
*/
|
|
636
|
-
|
|
664
|
+
getPending(): Promise<UmzugMigration[]>;
|
|
637
665
|
/**
|
|
638
666
|
* Executes specified migrations. Without parameter it will migrate up to the latest version.
|
|
639
667
|
*/
|
|
@@ -682,12 +710,17 @@ export interface MigrationObject {
|
|
|
682
710
|
name: string;
|
|
683
711
|
class: Constructor<Migration>;
|
|
684
712
|
}
|
|
685
|
-
|
|
713
|
+
type EntityFromInput<T> = T extends readonly EntityName<infer U>[] ? U : T extends EntityName<infer U> ? U : never;
|
|
714
|
+
type FilterDefResolved<T extends object = any> = {
|
|
686
715
|
name: string;
|
|
687
|
-
cond:
|
|
716
|
+
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
717
|
default?: boolean;
|
|
689
|
-
entity?:
|
|
718
|
+
entity?: EntityName<T> | EntityName<T>[];
|
|
690
719
|
args?: boolean;
|
|
720
|
+
strict?: boolean;
|
|
721
|
+
};
|
|
722
|
+
export type FilterDef<T extends EntityName<any> | readonly EntityName<any>[] = any> = FilterDefResolved<EntityFromInput<T>> & {
|
|
723
|
+
entity?: T;
|
|
691
724
|
};
|
|
692
725
|
export type Populate<T, P extends string = never> = readonly AutoPath<T, P, `${PopulatePath}`>[] | false;
|
|
693
726
|
export type PopulateOptions<T> = {
|
|
@@ -695,6 +728,7 @@ export type PopulateOptions<T> = {
|
|
|
695
728
|
strategy?: LoadStrategy;
|
|
696
729
|
all?: boolean;
|
|
697
730
|
filter?: boolean;
|
|
731
|
+
joinType?: 'inner join' | 'left join';
|
|
698
732
|
children?: PopulateOptions<T[keyof T]>[];
|
|
699
733
|
};
|
|
700
734
|
type Loadable<T extends object> = Collection<T, any> | Reference<T> | Ref<T> | readonly T[];
|
|
@@ -729,7 +763,7 @@ export type MergeSelected<T, U, F extends string> = T extends Loaded<infer TT, i
|
|
|
729
763
|
type MergeFields<F1 extends string, F2 extends string, P1, P2> = P1 | P2 extends '*' ? '*' : F1 | F2;
|
|
730
764
|
type MergeExcludes<F extends string, E extends string> = F extends E ? never : Exclude<E, F>;
|
|
731
765
|
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;
|
|
766
|
+
export type AddOptional<T> = undefined | null extends T ? null | undefined : null extends T ? null : undefined extends T ? undefined : never;
|
|
733
767
|
type LoadedProp<T, L extends string = never, F extends string = '*', E extends string = never> = LoadedLoadable<T, Loaded<ExtractType<T>, L, F, E>>;
|
|
734
768
|
export type AddEager<T> = ExtractEagerProps<T> & string;
|
|
735
769
|
export type ExpandHint<T, L extends string> = L | AddEager<T>;
|
|
@@ -790,11 +824,11 @@ export interface IHydrator {
|
|
|
790
824
|
* Hydrates the whole entity. This process handles custom type conversions, creating missing Collection instances,
|
|
791
825
|
* mapping FKs to entity instances, as well as merging those entities.
|
|
792
826
|
*/
|
|
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;
|
|
827
|
+
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
828
|
/**
|
|
795
829
|
* Hydrates primary keys only
|
|
796
830
|
*/
|
|
797
|
-
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
|
|
831
|
+
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void;
|
|
798
832
|
isRunning(): boolean;
|
|
799
833
|
}
|
|
800
834
|
export interface HydratorConstructor {
|
|
@@ -804,17 +838,18 @@ export interface ISeedManager {
|
|
|
804
838
|
seed(...classNames: Constructor<Seeder>[]): Promise<void>;
|
|
805
839
|
/** @internal */
|
|
806
840
|
seedString(...classNames: string[]): Promise<void>;
|
|
807
|
-
|
|
841
|
+
create(className: string): Promise<string>;
|
|
808
842
|
}
|
|
809
843
|
export interface Seeder<T extends Dictionary = Dictionary> {
|
|
810
844
|
run(em: EntityManager, context?: T): void | Promise<void>;
|
|
811
845
|
}
|
|
812
846
|
export type ConnectionType = 'read' | 'write';
|
|
813
847
|
export type MetadataProcessor = (metadata: EntityMetadata[], platform: Platform) => MaybePromise<void>;
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
}
|
|
848
|
+
export type MaybeReturnType<T> = T extends (...args: any[]) => infer R ? R : T;
|
|
849
|
+
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> {
|
|
850
|
+
readonly name: TName;
|
|
851
|
+
readonly properties: TProperties;
|
|
852
|
+
readonly tableName: TTableName;
|
|
853
|
+
}
|
|
854
|
+
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
855
|
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,19 +87,20 @@ 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) {
|
|
84
102
|
for (const prop of this.props) {
|
|
85
|
-
if (prop.enum && !prop.nativeEnumName && prop.items?.every(item =>
|
|
103
|
+
if (prop.enum && !prop.nativeEnumName && prop.items?.every(item => typeof item === 'string')) {
|
|
86
104
|
const name = config.getNamingStrategy().indexName(this.tableName, prop.fieldNames, 'check');
|
|
87
105
|
const exists = this.checks.findIndex(check => check.name === name);
|
|
88
106
|
if (exists !== -1) {
|
|
@@ -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;
|