@mikro-orm/core 7.0.0-dev.32 → 7.0.0-dev.321
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 +71 -63
- package/EntityManager.js +365 -283
- package/MikroORM.d.ts +44 -35
- package/MikroORM.js +109 -142
- package/README.md +7 -4
- package/cache/FileCacheAdapter.d.ts +1 -2
- package/cache/FileCacheAdapter.js +19 -14
- package/cache/GeneratedCacheAdapter.d.ts +0 -1
- package/cache/GeneratedCacheAdapter.js +0 -2
- package/cache/index.d.ts +1 -2
- package/cache/index.js +0 -2
- package/connections/Connection.d.ts +12 -5
- package/connections/Connection.js +37 -15
- package/drivers/DatabaseDriver.d.ts +25 -18
- package/drivers/DatabaseDriver.js +144 -45
- package/drivers/IDatabaseDriver.d.ts +118 -23
- package/entity/BaseEntity.d.ts +63 -4
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +101 -29
- package/entity/Collection.js +473 -115
- package/entity/EntityAssigner.js +37 -25
- package/entity/EntityFactory.d.ts +7 -1
- package/entity/EntityFactory.js +116 -64
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +69 -27
- package/entity/EntityLoader.d.ts +11 -10
- package/entity/EntityLoader.js +264 -102
- package/entity/EntityRepository.d.ts +28 -8
- package/entity/EntityRepository.js +8 -2
- package/entity/PolymorphicRef.d.ts +12 -0
- package/entity/PolymorphicRef.js +18 -0
- package/entity/Reference.d.ts +2 -6
- package/entity/Reference.js +52 -19
- package/entity/WrappedEntity.d.ts +3 -8
- package/entity/WrappedEntity.js +6 -7
- package/entity/defineEntity.d.ts +525 -311
- package/entity/defineEntity.js +134 -290
- package/entity/index.d.ts +2 -2
- package/entity/index.js +2 -2
- package/entity/utils.d.ts +6 -1
- package/entity/utils.js +46 -11
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +66 -0
- package/enums.d.ts +8 -6
- package/enums.js +13 -17
- package/errors.d.ts +20 -10
- package/errors.js +63 -31
- package/events/EventManager.d.ts +2 -1
- package/events/EventManager.js +24 -13
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/exceptions.js +9 -2
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +4 -4
- package/hydration/ObjectHydrator.js +105 -46
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +3 -4
- package/logging/SimpleLogger.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +5 -7
- package/logging/index.d.ts +2 -1
- package/logging/index.js +1 -1
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +11 -0
- package/metadata/EntitySchema.d.ts +47 -23
- package/metadata/EntitySchema.js +103 -34
- package/metadata/MetadataDiscovery.d.ts +64 -9
- package/metadata/MetadataDiscovery.js +867 -354
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +71 -2
- package/metadata/MetadataStorage.d.ts +13 -11
- package/metadata/MetadataStorage.js +72 -41
- package/metadata/MetadataValidator.d.ts +32 -9
- package/metadata/MetadataValidator.js +214 -44
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/metadata/types.d.ts +577 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
- package/naming-strategy/AbstractNamingStrategy.js +26 -5
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
- package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
- package/naming-strategy/MongoNamingStrategy.js +6 -6
- package/naming-strategy/NamingStrategy.d.ts +28 -4
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/not-supported.d.ts +2 -0
- package/not-supported.js +8 -0
- package/package.json +47 -36
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +33 -15
- package/platforms/Platform.js +125 -69
- package/serialization/EntitySerializer.d.ts +6 -3
- package/serialization/EntitySerializer.js +53 -29
- package/serialization/EntityTransformer.js +33 -21
- package/serialization/SerializationContext.d.ts +6 -6
- package/serialization/SerializationContext.js +4 -4
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.js +1 -1
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +1 -0
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.js +2 -2
- package/types/DoubleType.js +1 -1
- package/types/EnumArrayType.js +1 -2
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/TinyIntType.js +1 -1
- package/types/Type.d.ts +2 -4
- package/types/Type.js +3 -3
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +1 -4
- package/types/UuidType.d.ts +2 -0
- package/types/UuidType.js +14 -2
- package/types/index.d.ts +3 -2
- package/typings.d.ts +427 -170
- package/typings.js +100 -45
- package/unit-of-work/ChangeSet.d.ts +4 -6
- package/unit-of-work/ChangeSet.js +8 -9
- package/unit-of-work/ChangeSetComputer.d.ts +3 -8
- package/unit-of-work/ChangeSetComputer.js +49 -26
- package/unit-of-work/ChangeSetPersister.d.ts +13 -12
- package/unit-of-work/ChangeSetPersister.js +107 -44
- package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
- package/unit-of-work/CommitOrderCalculator.js +17 -15
- package/unit-of-work/IdentityMap.d.ts +12 -0
- package/unit-of-work/IdentityMap.js +39 -1
- package/unit-of-work/UnitOfWork.d.ts +34 -4
- package/unit-of-work/UnitOfWork.js +294 -107
- package/utils/AbstractMigrator.d.ts +101 -0
- package/utils/AbstractMigrator.js +303 -0
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +30 -18
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +796 -211
- package/utils/Configuration.js +160 -197
- package/utils/ConfigurationLoader.d.ts +1 -52
- package/utils/ConfigurationLoader.js +1 -330
- package/utils/Cursor.d.ts +0 -3
- package/utils/Cursor.js +29 -14
- package/utils/DataloaderUtils.d.ts +10 -5
- package/utils/DataloaderUtils.js +42 -22
- package/utils/EntityComparator.d.ts +16 -9
- package/utils/EntityComparator.js +202 -96
- package/utils/QueryHelper.d.ts +34 -7
- package/utils/QueryHelper.js +183 -72
- package/utils/RawQueryFragment.d.ts +28 -34
- package/utils/RawQueryFragment.js +37 -72
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.js +11 -7
- package/utils/Utils.d.ts +16 -127
- package/utils/Utils.js +106 -401
- package/utils/clone.js +13 -23
- package/utils/env-vars.d.ts +7 -0
- package/utils/env-vars.js +98 -0
- package/utils/fs-utils.d.ts +34 -0
- package/utils/fs-utils.js +193 -0
- package/utils/index.d.ts +1 -3
- package/utils/index.js +1 -3
- package/utils/upsert-utils.d.ts +9 -4
- package/utils/upsert-utils.js +51 -5
- 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 -12
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -33
- 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 -42
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -34
- 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 -28
- 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 -14
- 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 -118
- package/entity/ArrayCollection.js +0 -407
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -150
- 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,23 +7,24 @@ 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';
|
|
14
13
|
import type { EntitySchema } from './metadata/EntitySchema.js';
|
|
14
|
+
import type { IndexColumnOptions } from './metadata/types.js';
|
|
15
15
|
import type { Type, types } from './types/index.js';
|
|
16
16
|
import type { Platform } from './platforms/Platform.js';
|
|
17
17
|
import type { Configuration } from './utils/Configuration.js';
|
|
18
|
-
import type {
|
|
18
|
+
import type { Raw } from './utils/RawQueryFragment.js';
|
|
19
19
|
import type { EntityManager } from './EntityManager.js';
|
|
20
|
-
import type { EmbeddedPrefixMode } from './decorators/Embedded.js';
|
|
21
20
|
import type { EventSubscriber } from './events/EventSubscriber.js';
|
|
22
|
-
import type { FindOneOptions, FindOptions, LoadHint } from './drivers/IDatabaseDriver.js';
|
|
21
|
+
import type { FilterOptions, FindOneOptions, FindOptions, LoadHint } from './drivers/IDatabaseDriver.js';
|
|
22
|
+
export type { Raw };
|
|
23
23
|
export type Constructor<T = unknown> = new (...args: any[]) => T;
|
|
24
24
|
export type Dictionary<T = any> = {
|
|
25
25
|
[k: string]: T;
|
|
26
26
|
};
|
|
27
|
+
export type CompiledFunctions = Record<string, (...args: any[]) => any>;
|
|
27
28
|
export type EntityKey<T = unknown, B extends boolean = false> = string & {
|
|
28
29
|
[K in keyof T]-?: CleanKeys<T, K, B> extends never ? never : K;
|
|
29
30
|
}[keyof T];
|
|
@@ -35,14 +36,71 @@ export type Compute<T> = {
|
|
|
35
36
|
[K in keyof T]: T[K];
|
|
36
37
|
} & {};
|
|
37
38
|
type InternalKeys = 'EntityRepositoryType' | 'PrimaryKeyProp' | 'OptionalProps' | 'EagerProps' | 'HiddenProps' | '__selectedType' | '__loadedType';
|
|
38
|
-
export type CleanKeys<T, K extends keyof T, B extends boolean = false> =
|
|
39
|
+
export type CleanKeys<T, K extends keyof T, B extends boolean = false> = T[K] & {} extends Function ? never : K extends symbol | InternalKeys ? never : B extends true ? T[K] & {} extends Scalar ? never : K : K;
|
|
39
40
|
export type FunctionKeys<T, K extends keyof T> = T[K] extends Function ? K : never;
|
|
40
41
|
export type Cast<T, R> = T extends R ? T : R;
|
|
41
|
-
export type IsUnknown<T> = T extends unknown ? unknown extends T ? true : never : never;
|
|
42
|
-
export type IsAny<T> = 0 extends
|
|
42
|
+
export type IsUnknown<T> = T extends unknown ? (unknown extends T ? true : never) : never;
|
|
43
|
+
export type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
43
44
|
export type IsNever<T, True = true, False = false> = [T] extends [never] ? True : False;
|
|
44
45
|
export type MaybePromise<T> = T | Promise<T>;
|
|
45
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Structural type for matching Collection without triggering full interface evaluation.
|
|
48
|
+
* Using `T extends CollectionShape` instead of `T extends Collection<any, any>` avoids
|
|
49
|
+
* forcing TypeScript to evaluate Collection's 30+ methods, preventing instantiation explosion
|
|
50
|
+
* (~133k → ~2k instantiations).
|
|
51
|
+
*
|
|
52
|
+
* Usage:
|
|
53
|
+
* - Matching only: `T extends CollectionShape`
|
|
54
|
+
* - With inference: `T extends CollectionShape<infer U>`
|
|
55
|
+
*/
|
|
56
|
+
type CollectionShape<T = any> = {
|
|
57
|
+
[k: number]: T;
|
|
58
|
+
readonly owner: object;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Structural type for matching LoadedCollection (extends CollectionShape with `$` property).
|
|
62
|
+
*
|
|
63
|
+
* Usage:
|
|
64
|
+
* - Matching only: `T extends LoadedCollectionShape`
|
|
65
|
+
* - With inference: `T extends LoadedCollectionShape<infer U>`
|
|
66
|
+
*/
|
|
67
|
+
type LoadedCollectionShape<T = any> = CollectionShape<T> & {
|
|
68
|
+
$: any;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Structural type for matching Reference without triggering full class evaluation.
|
|
72
|
+
* Using `T extends ReferenceShape` instead of `T extends Reference<any>` avoids
|
|
73
|
+
* forcing TypeScript to evaluate Reference's methods, preventing instantiation overhead
|
|
74
|
+
* (~800 → ~15 instantiations).
|
|
75
|
+
*
|
|
76
|
+
* Usage:
|
|
77
|
+
* - Matching only: `T extends ReferenceShape`
|
|
78
|
+
* - With inference: `T extends ReferenceShape<infer U>`
|
|
79
|
+
*/
|
|
80
|
+
type ReferenceShape<T = any> = {
|
|
81
|
+
unwrap(): T;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Structural type for matching LoadedReference (Reference with `$` property).
|
|
85
|
+
* Note: We don't parameterize ReferenceShape here because for loaded relations,
|
|
86
|
+
* the Reference unwrap() returns the base type while $ returns the Loaded type.
|
|
87
|
+
* We infer T from $ to get the full Loaded type for EntityDTO.
|
|
88
|
+
*/
|
|
89
|
+
type LoadedReferenceShape<T = any> = ReferenceShape & {
|
|
90
|
+
$: T;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Structural type for matching any loadable relation (Collection, Reference, or array).
|
|
94
|
+
* Using this instead of `Loadable<any>` in conditional type checks prevents
|
|
95
|
+
* TypeScript from evaluating the full Collection/Reference interfaces.
|
|
96
|
+
*/
|
|
97
|
+
type LoadableShape = CollectionShape | ReferenceShape | readonly any[];
|
|
98
|
+
export type UnionKeys<T> = T extends any ? keyof T : never;
|
|
99
|
+
export type UnionPropertyType<T, K extends PropertyKey> = T extends any ? (K extends keyof T ? T[K] : never) : never;
|
|
100
|
+
type IsUnion<T, U = T> = T extends any ? ([U] extends [T] ? false : true) : false;
|
|
101
|
+
export type MergeUnion<T> = [T] extends [object] ? T extends Scalar ? T : IsUnion<T> extends true ? {
|
|
102
|
+
[K in UnionKeys<T>]: UnionPropertyType<T, K>;
|
|
103
|
+
} : T : T;
|
|
46
104
|
export type DeepPartial<T> = T & {
|
|
47
105
|
[P in keyof T]?: T[P] extends (infer U)[] ? DeepPartial<U>[] : T[P] extends Readonly<infer U>[] ? Readonly<DeepPartial<U>>[] : DeepPartial<T[P]>;
|
|
48
106
|
};
|
|
@@ -52,6 +110,10 @@ export declare const OptionalProps: unique symbol;
|
|
|
52
110
|
export declare const EagerProps: unique symbol;
|
|
53
111
|
export declare const HiddenProps: unique symbol;
|
|
54
112
|
export declare const Config: unique symbol;
|
|
113
|
+
export declare const EntityName: unique symbol;
|
|
114
|
+
export type InferEntityName<T> = T extends {
|
|
115
|
+
[EntityName]?: infer Name;
|
|
116
|
+
} ? (Name extends string ? Name : never) : never;
|
|
55
117
|
export type Opt<T = unknown> = T & Opt.Brand;
|
|
56
118
|
export declare namespace Opt {
|
|
57
119
|
const __optional: unique symbol;
|
|
@@ -84,14 +146,24 @@ export type CleanTypeConfig<T> = Compute<Pick<T, Extract<keyof T, keyof TypeConf
|
|
|
84
146
|
export interface TypeConfig {
|
|
85
147
|
forceObject?: boolean;
|
|
86
148
|
}
|
|
87
|
-
|
|
149
|
+
declare const __selectedType: unique symbol;
|
|
150
|
+
declare const __loadedType: unique symbol;
|
|
151
|
+
declare const __loadHint: unique symbol;
|
|
152
|
+
/**
|
|
153
|
+
* Expands a populate hint into all its prefixes.
|
|
154
|
+
* e.g., Prefixes<'a.b.c'> = 'a' | 'a.b' | 'a.b.c'
|
|
155
|
+
* This reflects that loading 'a.b.c' means 'a' and 'a.b' are also loaded.
|
|
156
|
+
* Special case: '*' returns string to ensure Loaded<T, '*'> is assignable to any Loaded<T, Hint>.
|
|
157
|
+
*/
|
|
158
|
+
export type Prefixes<S extends string> = S extends '*' ? string : S extends `${infer H}.${infer T}` ? H | `${H}.${Prefixes<T>}` : S;
|
|
159
|
+
export type UnwrapPrimary<T> = T extends Scalar ? T : T extends ReferenceShape<infer U> ? Primary<U> : Primary<T>;
|
|
88
160
|
type PrimaryPropToType<T, Keys extends (keyof T)[]> = {
|
|
89
161
|
[Index in keyof Keys]: UnwrapPrimary<T[Keys[Index]]>;
|
|
90
162
|
};
|
|
91
163
|
type ReadonlyPrimary<T> = T extends any[] ? Readonly<T> : T;
|
|
92
164
|
export type Primary<T> = IsAny<T> extends true ? any : T extends {
|
|
93
165
|
[PrimaryKeyProp]?: infer PK;
|
|
94
|
-
} ?
|
|
166
|
+
} ? 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 {
|
|
95
167
|
_id?: infer PK;
|
|
96
168
|
} ? ReadonlyPrimary<PK> | string : T extends {
|
|
97
169
|
id?: infer PK;
|
|
@@ -101,11 +173,11 @@ export type Primary<T> = IsAny<T> extends true ? any : T extends {
|
|
|
101
173
|
/** @internal */
|
|
102
174
|
export type PrimaryProperty<T> = T extends {
|
|
103
175
|
[PrimaryKeyProp]?: infer PK;
|
|
104
|
-
} ?
|
|
176
|
+
} ? PK extends keyof T ? PK : PK extends any[] ? PK[number] : never : T extends {
|
|
105
177
|
_id?: any;
|
|
106
|
-
} ?
|
|
178
|
+
} ? T extends {
|
|
107
179
|
id?: any;
|
|
108
|
-
} ? 'id' | '_id' : '_id'
|
|
180
|
+
} ? 'id' | '_id' : '_id' : T extends {
|
|
109
181
|
id?: any;
|
|
110
182
|
} ? 'id' : T extends {
|
|
111
183
|
uuid?: any;
|
|
@@ -117,22 +189,35 @@ export type IPrimaryKey<T extends IPrimaryKeyValue = IPrimaryKeyValue> = T;
|
|
|
117
189
|
export type Scalar = boolean | number | string | bigint | symbol | Date | RegExp | Uint8Array | {
|
|
118
190
|
toHexString(): string;
|
|
119
191
|
};
|
|
192
|
+
type Primitive = boolean | number | string | bigint | symbol;
|
|
120
193
|
export type ExpandScalar<T> = null | (T extends string ? T | RegExp : T extends Date ? Date | string : T extends bigint ? bigint | string | number : T);
|
|
194
|
+
/** Marker interface for query builders that can be used as subqueries */
|
|
195
|
+
export interface Subquery {
|
|
196
|
+
readonly __subquery: true;
|
|
197
|
+
}
|
|
121
198
|
export type OperatorMap<T> = {
|
|
122
199
|
$and?: ExpandQuery<T>[];
|
|
123
200
|
$or?: ExpandQuery<T>[];
|
|
124
|
-
$eq?: ExpandScalar<T> | readonly ExpandScalar<T>[];
|
|
125
|
-
$ne?: ExpandScalar<T
|
|
126
|
-
$in?: readonly ExpandScalar<T>[];
|
|
127
|
-
$nin?: readonly ExpandScalar<T>[];
|
|
201
|
+
$eq?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
|
|
202
|
+
$ne?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
|
|
203
|
+
$in?: readonly ExpandScalar<T>[] | readonly Primary<T>[] | Raw | Subquery;
|
|
204
|
+
$nin?: readonly ExpandScalar<T>[] | readonly Primary<T>[] | Raw | Subquery;
|
|
128
205
|
$not?: ExpandQuery<T>;
|
|
129
206
|
$none?: ExpandQuery<T>;
|
|
130
207
|
$some?: ExpandQuery<T>;
|
|
131
208
|
$every?: ExpandQuery<T>;
|
|
132
|
-
$
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
209
|
+
$size?: number | {
|
|
210
|
+
$eq?: number;
|
|
211
|
+
$ne?: number;
|
|
212
|
+
$gt?: number;
|
|
213
|
+
$gte?: number;
|
|
214
|
+
$lt?: number;
|
|
215
|
+
$lte?: number;
|
|
216
|
+
};
|
|
217
|
+
$gt?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
|
|
218
|
+
$gte?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
|
|
219
|
+
$lt?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
|
|
220
|
+
$lte?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
|
|
136
221
|
$like?: string;
|
|
137
222
|
$re?: string;
|
|
138
223
|
$ilike?: string;
|
|
@@ -145,25 +230,24 @@ export type OperatorMap<T> = {
|
|
|
145
230
|
$hasKeys?: readonly string[];
|
|
146
231
|
$hasSomeKeys?: readonly string[];
|
|
147
232
|
};
|
|
148
|
-
export type FilterItemValue<T> = T | ExpandScalar<T> | Primary<T
|
|
233
|
+
export type FilterItemValue<T> = T | ExpandScalar<T> | Primary<T> | Raw;
|
|
149
234
|
export type FilterValue<T> = OperatorMap<FilterItemValue<T>> | FilterItemValue<T> | FilterItemValue<T>[] | null;
|
|
235
|
+
type FilterObjectProp<T, K extends PropertyKey> = K extends keyof MergeUnion<T> ? MergeUnion<T>[K] : K extends keyof T ? T[K] : never;
|
|
236
|
+
type ExpandQueryMerged<T> = [T] extends [object] ? [T] extends [Scalar] ? never : FilterQuery<MergeUnion<T>> : FilterValue<T>;
|
|
150
237
|
export type FilterObject<T> = {
|
|
151
|
-
-readonly [K in EntityKey<T>]?: ExpandQuery<ExpandProperty<T
|
|
238
|
+
-readonly [K in EntityKey<T>]?: ExpandQuery<ExpandProperty<FilterObjectProp<T, K>>> | ExpandQueryMerged<ExpandProperty<FilterObjectProp<T, K>>> | FilterValue<ExpandProperty<FilterObjectProp<T, K>>> | null;
|
|
152
239
|
};
|
|
153
|
-
export type
|
|
154
|
-
export type ExpandQuery<T> = T extends object ? T extends Scalar ? never : FilterQuery<T> : FilterValue<T>;
|
|
240
|
+
export type ExpandQuery<T> = T extends object ? (T extends Scalar ? never : FilterQuery<T>) : FilterValue<T>;
|
|
155
241
|
export type EntityProps<T> = {
|
|
156
242
|
-readonly [K in EntityKey<T>]?: T[K];
|
|
157
243
|
};
|
|
158
244
|
export type ObjectQuery<T> = OperatorMap<T> & FilterObject<T>;
|
|
159
245
|
export type FilterQuery<T> = ObjectQuery<T> | NonNullable<ExpandScalar<Primary<T>>> | NonNullable<EntityProps<T> & OperatorMap<T>> | FilterQuery<T>[];
|
|
160
|
-
export type QBFilterQuery<T = any> = ObjectQuery<T> | Dictionary;
|
|
161
246
|
export interface IWrappedEntity<Entity extends object> {
|
|
162
247
|
isInitialized(): boolean;
|
|
163
|
-
isTouched(): boolean;
|
|
164
248
|
isManaged(): boolean;
|
|
165
249
|
populated(populated?: boolean): void;
|
|
166
|
-
populate<Hint extends string = never>(populate: AutoPath<Entity, Hint>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
|
|
250
|
+
populate<Hint extends string = never, Fields extends string = never>(populate: readonly AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity, Fields>): Promise<Loaded<Entity, Hint>>;
|
|
167
251
|
init<Hint extends string = never, Fields extends string = '*', Exclude extends string = never>(options?: FindOneOptions<Entity, Hint, Fields, Exclude>): Promise<Loaded<Entity, Hint, Fields, Exclude> | null>;
|
|
168
252
|
toReference(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
|
|
169
253
|
toObject(): EntityDTO<Entity>;
|
|
@@ -171,7 +255,7 @@ export interface IWrappedEntity<Entity extends object> {
|
|
|
171
255
|
toObject<Ignored extends EntityKey<Entity>>(ignoreFields: Ignored[]): Omit<EntityDTO<Entity>, Ignored>;
|
|
172
256
|
toJSON(...args: any[]): EntityDTO<Entity>;
|
|
173
257
|
toPOJO(): EntityDTO<Entity>;
|
|
174
|
-
serialize<Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Naked, Hint, Exclude>):
|
|
258
|
+
serialize<Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Naked, Hint, Exclude>): SerializeDTO<Naked, Hint, Exclude>;
|
|
175
259
|
setSerializationContext<Hint extends string = never, Fields extends string = '*', Exclude extends string = never>(options: LoadHint<Entity, Hint, Fields, Exclude>): void;
|
|
176
260
|
assign<Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Convert extends boolean = false, Data extends EntityData<Naked, Convert> | Partial<EntityDTO<Naked>> = EntityData<Naked, Convert> | Partial<EntityDTO<Naked>>>(data: Data & IsSubset<EntityData<Naked, Convert>, Data>, options?: AssignOptions<Convert>): MergeSelected<Entity, Naked, keyof Data & string>;
|
|
177
261
|
getSchema(): string | undefined;
|
|
@@ -191,7 +275,6 @@ export interface IWrappedEntityInternal<Entity extends object> extends IWrappedE
|
|
|
191
275
|
__factory: EntityFactory;
|
|
192
276
|
__hydrator: IHydrator;
|
|
193
277
|
__initialized: boolean;
|
|
194
|
-
__touched: boolean;
|
|
195
278
|
__originalEntityData?: EntityData<Entity>;
|
|
196
279
|
__loadedProperties: Set<string>;
|
|
197
280
|
__identifier?: EntityIdentifier | EntityIdentifier[];
|
|
@@ -211,20 +294,21 @@ export interface IWrappedEntityInternal<Entity extends object> extends IWrappedE
|
|
|
211
294
|
};
|
|
212
295
|
}
|
|
213
296
|
export type AnyEntity<T = any> = Partial<T>;
|
|
214
|
-
export type EntityClass<T> = Function & {
|
|
297
|
+
export type EntityClass<T = any> = Function & {
|
|
215
298
|
prototype: T;
|
|
216
299
|
};
|
|
217
|
-
export type
|
|
218
|
-
entity: EntityClass<T>;
|
|
219
|
-
schema: EntityMetadata<T> | EntitySchema<T>;
|
|
220
|
-
};
|
|
221
|
-
export type EntityName<T> = string | EntityClass<T> | EntitySchema<T, any> | {
|
|
222
|
-
name: string;
|
|
223
|
-
};
|
|
300
|
+
export type EntityName<T = any> = EntityClass<T> | EntityCtor<T> | EntitySchema<T, any>;
|
|
224
301
|
export type GetRepository<Entity extends {
|
|
225
302
|
[k: PropertyKey]: any;
|
|
226
303
|
}, Fallback> = Entity[typeof EntityRepositoryType] extends EntityRepository<any> | undefined ? NonNullable<Entity[typeof EntityRepositoryType]> : Fallback;
|
|
227
|
-
|
|
304
|
+
type PolymorphicPrimaryInner<T> = T extends object ? Primary<T> extends readonly [infer First, infer Second, ...infer Rest] ? readonly [string, First, Second, ...Rest] | [string, First, Second, ...Rest] : readonly [string, Primary<T>] | [string, Primary<T>] : never;
|
|
305
|
+
/**
|
|
306
|
+
* Tuple format for polymorphic FK values: [discriminator, ...pkValues]
|
|
307
|
+
* Distributes over unions, so `Post | Comment` becomes `['post', number] | ['comment', number]`
|
|
308
|
+
* For composite keys like [tenantId, orgId], becomes ['discriminator', tenantId, orgId]
|
|
309
|
+
*/
|
|
310
|
+
export type PolymorphicPrimary<T> = true extends IsUnion<T> ? PolymorphicPrimaryInner<T> : never;
|
|
311
|
+
export type EntityDataPropValue<T> = T | Primary<T> | PolymorphicPrimary<T>;
|
|
228
312
|
type ExpandEntityProp<T, C extends boolean = false> = T extends Record<string, any> ? {
|
|
229
313
|
[K in keyof T as CleanKeys<T, K>]?: EntityDataProp<ExpandProperty<T[K]>, C> | EntityDataPropValue<ExpandProperty<T[K]>> | null;
|
|
230
314
|
} | EntityDataPropValue<ExpandProperty<T>> : T;
|
|
@@ -237,16 +321,17 @@ type ExpandRequiredEntityPropObject<T, I = never, C extends boolean = false> = {
|
|
|
237
321
|
type NonArrayObject = object & {
|
|
238
322
|
[Symbol.iterator]?: never;
|
|
239
323
|
};
|
|
240
|
-
export type EntityDataProp<T, C extends boolean> = T extends Date ? string | Date : T extends Scalar ? T : T extends {
|
|
324
|
+
export type EntityDataProp<T, C extends boolean> = T extends Date ? string | Date : T extends Scalar ? T : T extends ScalarReference<infer U> ? EntityDataProp<U, C> : T extends {
|
|
241
325
|
__runtime?: infer Runtime;
|
|
242
326
|
__raw?: infer Raw;
|
|
243
|
-
} ?
|
|
244
|
-
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 {
|
|
327
|
+
} ? C extends true ? Raw : Runtime : T extends ReferenceShape<infer U> ? EntityDataNested<U, C> : T extends CollectionShape<infer U> ? U | U[] | EntityDataNested<U & object, C> | EntityDataNested<U & object, C>[] : T extends readonly (infer U)[] ? U extends NonArrayObject ? U | U[] | EntityDataNested<U, C> | EntityDataNested<U, C>[] : U[] | EntityDataNested<U, C>[] : EntityDataNested<T, C>;
|
|
328
|
+
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 ScalarReference<infer U> ? RequiredEntityDataProp<U, O, C> : T extends {
|
|
245
329
|
__runtime?: infer Runtime;
|
|
246
330
|
__raw?: infer Raw;
|
|
247
|
-
} ?
|
|
331
|
+
} ? C extends true ? Raw : Runtime : T extends ReferenceShape<infer U> ? RequiredEntityDataNested<U, O, C> : T extends CollectionShape<infer U> ? U | U[] | RequiredEntityDataNested<U & object, O, C> | RequiredEntityDataNested<U & object, 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>;
|
|
248
332
|
export type EntityDataNested<T, C extends boolean = false> = T extends undefined ? never : T extends any[] ? Readonly<T> : EntityData<T, C> | ExpandEntityProp<T, C>;
|
|
249
|
-
type
|
|
333
|
+
type UnwrapScalarRef<T> = T extends ScalarReference<infer U> ? U : T;
|
|
334
|
+
type EntityDataItem<T, C extends boolean> = C extends false ? UnwrapScalarRef<T> | EntityDataProp<T, C> | Raw | null : EntityDataProp<T, C> | Raw | null;
|
|
250
335
|
export type RequiredEntityDataNested<T, O, C extends boolean> = T extends any[] ? Readonly<T> : RequiredEntityData<T, O> | ExpandRequiredEntityProp<T, O, C>;
|
|
251
336
|
type ExplicitlyOptionalProps<T> = (T extends {
|
|
252
337
|
[OptionalProps]?: infer K;
|
|
@@ -254,22 +339,22 @@ type ExplicitlyOptionalProps<T> = (T extends {
|
|
|
254
339
|
[K in keyof T]: T[K] extends Opt ? K : never;
|
|
255
340
|
}[keyof T] & {});
|
|
256
341
|
type NullableKeys<T, V = null> = {
|
|
257
|
-
[K in keyof T]: V extends T[K] ? K : never;
|
|
342
|
+
[K in keyof T]: unknown extends T[K] ? never : V extends T[K] ? K : never;
|
|
258
343
|
}[keyof T];
|
|
259
344
|
type RequiredNullableKeys<T> = {
|
|
260
345
|
[K in keyof T]: Exclude<T[K], null> extends RequiredNullable.Brand ? K : never;
|
|
261
346
|
}[keyof T];
|
|
262
347
|
type ProbablyOptionalProps<T> = PrimaryProperty<T> | ExplicitlyOptionalProps<T> | Exclude<NonNullable<NullableKeys<T, null | undefined>>, RequiredNullableKeys<T>>;
|
|
263
|
-
type IsOptional<T, K extends keyof T, I> = T[K] extends
|
|
348
|
+
type IsOptional<T, K extends keyof T, I> = T[K] extends CollectionShape ? true : ExtractType<T[K]> extends I ? true : K extends ProbablyOptionalProps<T> ? true : false;
|
|
264
349
|
type RequiredKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? CleanKeys<T, K> : never;
|
|
265
350
|
type OptionalKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? never : CleanKeys<T, K>;
|
|
266
351
|
export type EntityData<T, C extends boolean = false> = {
|
|
267
352
|
[K in EntityKey<T>]?: EntityDataItem<T[K] & {}, C>;
|
|
268
353
|
};
|
|
269
354
|
export type RequiredEntityData<T, I = never, C extends boolean = false> = {
|
|
270
|
-
[K in keyof T as RequiredKeys<T, K, I>]: T[K] | RequiredEntityDataProp<T[K], T, C> | Primary<T[K]
|
|
355
|
+
[K in keyof T as RequiredKeys<T, K, I>]: T[K] | RequiredEntityDataProp<T[K], T, C> | Primary<T[K]> | PolymorphicPrimary<T[K]> | Raw;
|
|
271
356
|
} & {
|
|
272
|
-
[K in keyof T as OptionalKeys<T, K, I>]?: T[K] | RequiredEntityDataProp<T[K], T, C> | Primary<T[K]> | null;
|
|
357
|
+
[K in keyof T as OptionalKeys<T, K, I>]?: T[K] | RequiredEntityDataProp<T[K], T, C> | Primary<T[K]> | PolymorphicPrimary<T[K]> | Raw | null;
|
|
273
358
|
};
|
|
274
359
|
export type EntityDictionary<T> = EntityData<T> & Record<any, any>;
|
|
275
360
|
type ExtractEagerProps<T> = T extends {
|
|
@@ -283,9 +368,9 @@ export type Rel<T> = T;
|
|
|
283
368
|
/** Alias for `ScalarReference` (see {@apilink Ref}). */
|
|
284
369
|
export type ScalarRef<T> = ScalarReference<T>;
|
|
285
370
|
/** Alias for `Reference<T> & { id: number }` (see {@apilink Ref}). */
|
|
286
|
-
export type EntityRef<T extends object> = true extends IsUnknown<PrimaryProperty<T>> ? Reference<T> : IsAny<T> extends true ? Reference<T> :
|
|
371
|
+
export type EntityRef<T extends object> = true extends IsUnknown<PrimaryProperty<T>> ? Reference<T> : IsAny<T> extends true ? Reference<T> : {
|
|
287
372
|
[K in PrimaryProperty<T> & keyof T]: T[K];
|
|
288
|
-
} & Reference<T
|
|
373
|
+
} & Reference<T>;
|
|
289
374
|
/**
|
|
290
375
|
* Ref type represents a `Reference` instance, and adds the primary keys to its prototype automatically, so you can do
|
|
291
376
|
* `ref.id` instead of `ref.unwrap().id`. It resolves to either `ScalarRef` or `EntityRef`, based on the type argument.
|
|
@@ -294,21 +379,25 @@ export type Ref<T> = T extends any ? IsAny<T> extends true ? Reference<T & objec
|
|
|
294
379
|
type ExtractHiddenProps<T> = (T extends {
|
|
295
380
|
[HiddenProps]?: infer K;
|
|
296
381
|
} ? K : never) | ({
|
|
297
|
-
[K in keyof T]: T[K] extends Hidden ? K : never;
|
|
382
|
+
[K in keyof T]: T[K] extends Primitive ? (T[K] extends Hidden ? K : never) : never;
|
|
298
383
|
}[keyof T] & {});
|
|
299
384
|
type ExcludeHidden<T, K extends keyof T> = K extends ExtractHiddenProps<T> ? never : K;
|
|
300
385
|
type ExtractConfig<T> = T extends {
|
|
301
386
|
[Config]?: infer K;
|
|
302
|
-
} ?
|
|
387
|
+
} ? K & TypeConfig : TypeConfig;
|
|
303
388
|
type PreferExplicitConfig<E, I> = IsNever<E, I, E>;
|
|
304
389
|
type PrimaryOrObject<T, U, C extends TypeConfig> = PreferExplicitConfig<C, ExtractConfig<T>>['forceObject'] extends true ? {
|
|
305
390
|
[K in PrimaryProperty<U> & keyof U]: U[K];
|
|
306
391
|
} : Primary<U>;
|
|
307
|
-
|
|
392
|
+
type DTOWrapper<T, C extends TypeConfig, Flat extends boolean> = Flat extends true ? EntityDTOFlat<T, C> : EntityDTO<T, C>;
|
|
393
|
+
export type EntityDTOProp<E, T, C extends TypeConfig = never, Flat extends boolean = false> = T extends Scalar ? T : T extends ScalarReference<infer U> ? U : T extends {
|
|
308
394
|
__serialized?: infer U;
|
|
309
|
-
} ?
|
|
310
|
-
type
|
|
311
|
-
|
|
395
|
+
} ? IsUnknown<U> extends false ? U : T : T extends LoadedReferenceShape<infer U> ? DTOWrapper<U, C, Flat> : T extends ReferenceShape<infer U> ? PrimaryOrObject<E, U, C> : T extends LoadedCollectionShape<infer U> ? DTOWrapper<U & object, C, Flat>[] : T extends CollectionShape<infer U> ? PrimaryOrObject<E, U & object, C>[] : T extends readonly (infer U)[] ? U extends Scalar ? T : EntityDTOProp<E, U, C, Flat>[] : T extends Relation<T> ? DTOWrapper<T, C, Flat> : T;
|
|
396
|
+
type UnwrapLoadedEntity<T> = T extends {
|
|
397
|
+
[__loadedType]?: infer U;
|
|
398
|
+
} ? NonNullable<U> : T;
|
|
399
|
+
type DTOProbablyOptionalProps<T> = NonNullable<NullableKeys<UnwrapLoadedEntity<T>, undefined>>;
|
|
400
|
+
type DTOIsOptional<T, K extends keyof T> = T[K] extends LoadedCollectionShape ? false : K extends PrimaryProperty<UnwrapLoadedEntity<T>> ? false : K extends DTOProbablyOptionalProps<T> ? true : false;
|
|
312
401
|
type DTORequiredKeys<T, K extends keyof T> = DTOIsOptional<T, K> extends false ? ExcludeHidden<T, K> & CleanKeys<T, K> : never;
|
|
313
402
|
type DTOOptionalKeys<T, K extends keyof T> = DTOIsOptional<T, K> extends false ? never : ExcludeHidden<T, K> & CleanKeys<T, K>;
|
|
314
403
|
export type EntityDTO<T, C extends TypeConfig = never> = {
|
|
@@ -316,30 +405,84 @@ export type EntityDTO<T, C extends TypeConfig = never> = {
|
|
|
316
405
|
} & {
|
|
317
406
|
[K in keyof T as DTOOptionalKeys<T, K>]?: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
|
|
318
407
|
};
|
|
408
|
+
/**
|
|
409
|
+
* @internal
|
|
410
|
+
* 1-pass variant of EntityDTO — ~2x cheaper to resolve but all keys are required
|
|
411
|
+
* (optional keys use `| undefined` in value type instead of `?` modifier).
|
|
412
|
+
* Use only for internal type computations (output types), never as a user-facing
|
|
413
|
+
* function parameter type where generic assignability checks are needed.
|
|
414
|
+
*/
|
|
415
|
+
export type EntityDTOFlat<T, C extends TypeConfig = never> = {
|
|
416
|
+
[K in keyof T as ExcludeHidden<T, K> & CleanKeys<T, K>]: EntityDTOProp<T, T[K], C, true> | AddOptional<T[K]>;
|
|
417
|
+
};
|
|
418
|
+
/**
|
|
419
|
+
* @internal
|
|
420
|
+
* Single-pass fused type that combines Loaded + EntityDTO into one mapped type.
|
|
421
|
+
* ~40x faster than `EntityDTO<Loaded<T, H>>` for populated entities.
|
|
422
|
+
*/
|
|
423
|
+
type SerializeTopHints<H extends string> = H extends `${infer Top}.${string}` ? Top : H;
|
|
424
|
+
type SerializeSubHints<K extends string, H extends string> = H extends `${K}.${infer Rest}` ? Rest : never;
|
|
425
|
+
type SerializePropValue<T, K extends keyof T, H extends string, C extends TypeConfig = never> = K & string extends SerializeTopHints<H> ? NonNullable<T[K]> extends CollectionShape<infer U> ? SerializeDTO<U & object, SerializeSubHints<K & string, H>, never, C>[] : SerializeDTO<ExpandProperty<T[K]>, SerializeSubHints<K & string, H>, never, C> | Extract<T[K], null | undefined> : EntityDTOProp<T, T[K], C>;
|
|
426
|
+
export type SerializeDTO<T, H extends string = never, E extends string = never, C extends TypeConfig = never> = string extends H ? EntityDTOFlat<T, C> : {
|
|
427
|
+
[K in keyof T as ExcludeHidden<T, K> & CleanKeys<T, K> & (IsNever<E> extends true ? K : Exclude<K, E>)]: SerializePropValue<T, K, H, C> | Extract<T[K], null | undefined>;
|
|
428
|
+
};
|
|
319
429
|
type TargetKeys<T> = T extends EntityClass<infer P> ? keyof P : keyof T;
|
|
320
430
|
type PropertyName<T> = IsUnknown<T> extends false ? TargetKeys<T> : string;
|
|
321
|
-
type
|
|
431
|
+
export type FormulaTable = {
|
|
432
|
+
alias: string;
|
|
322
433
|
name: string;
|
|
323
434
|
schema?: string;
|
|
435
|
+
qualifiedName: string;
|
|
324
436
|
toString: () => string;
|
|
325
437
|
};
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
438
|
+
/**
|
|
439
|
+
* Table reference for schema callbacks (indexes, checks, generated columns).
|
|
440
|
+
* Unlike FormulaTable, this has no alias since schema generation doesn't use query aliases.
|
|
441
|
+
*/
|
|
442
|
+
export type SchemaTable = {
|
|
443
|
+
name: string;
|
|
444
|
+
schema?: string;
|
|
445
|
+
qualifiedName: string;
|
|
446
|
+
toString: () => string;
|
|
447
|
+
};
|
|
448
|
+
/**
|
|
449
|
+
* Column mapping for formula callbacks. Maps property names to fully-qualified alias.fieldName.
|
|
450
|
+
* Has toString() returning the main alias for backwards compatibility with old formula syntax.
|
|
451
|
+
* @example
|
|
452
|
+
* // New recommended syntax - use cols.propName for fully-qualified references
|
|
453
|
+
* formula: cols => `${cols.firstName} || ' ' || ${cols.lastName}`
|
|
454
|
+
*
|
|
455
|
+
* // Old syntax still works - cols.toString() returns the alias
|
|
456
|
+
* formula: cols => `${cols}.first_name || ' ' || ${cols}.last_name`
|
|
457
|
+
*/
|
|
458
|
+
export type FormulaColumns<T> = Record<PropertyName<T>, string> & {
|
|
459
|
+
toString(): string;
|
|
460
|
+
};
|
|
461
|
+
/**
|
|
462
|
+
* Column mapping for schema callbacks (indexes, checks, generated columns).
|
|
463
|
+
* Maps property names to field names. For TPT entities, only includes properties
|
|
464
|
+
* that belong to the current table (not inherited properties from parent tables).
|
|
465
|
+
*/
|
|
466
|
+
export type SchemaColumns<T> = Record<PropertyName<T>, string>;
|
|
467
|
+
export type IndexCallback<T> = (columns: Record<PropertyName<T>, string>, table: SchemaTable, indexName: string) => string | Raw;
|
|
468
|
+
export type FormulaCallback<T> = (columns: FormulaColumns<T>, table: FormulaTable) => string | Raw;
|
|
469
|
+
export type CheckCallback<T> = (columns: Record<PropertyName<T>, string>, table: SchemaTable) => string | Raw;
|
|
470
|
+
export type GeneratedColumnCallback<T> = (columns: Record<PropertyName<T>, string>, table: SchemaTable) => string | Raw;
|
|
329
471
|
export interface CheckConstraint<T = any> {
|
|
330
472
|
name?: string;
|
|
331
473
|
property?: string;
|
|
332
|
-
expression: string | CheckCallback<T>;
|
|
474
|
+
expression: string | Raw | CheckCallback<T>;
|
|
333
475
|
}
|
|
334
476
|
export type AnyString = string & {};
|
|
335
477
|
export interface EntityProperty<Owner = any, Target = any> {
|
|
336
478
|
name: EntityKey<Owner>;
|
|
337
479
|
entity: () => EntityName<Owner>;
|
|
480
|
+
target: EntityClass<Target>;
|
|
338
481
|
type: keyof typeof types | AnyString;
|
|
339
482
|
runtimeType: 'number' | 'string' | 'boolean' | 'bigint' | 'Buffer' | 'Date' | 'object' | 'any' | AnyString;
|
|
340
483
|
targetMeta?: EntityMetadata<Target>;
|
|
341
484
|
columnTypes: string[];
|
|
342
|
-
generated?: string | GeneratedColumnCallback<Owner>;
|
|
485
|
+
generated?: string | Raw | GeneratedColumnCallback<Owner>;
|
|
343
486
|
customType?: Type<any>;
|
|
344
487
|
customTypes: (Type<any> | undefined)[];
|
|
345
488
|
hasConvertToJSValueSQL: boolean;
|
|
@@ -360,7 +503,8 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
360
503
|
fieldNameRaw?: string;
|
|
361
504
|
default?: string | number | boolean | null;
|
|
362
505
|
defaultRaw?: string;
|
|
363
|
-
formula?:
|
|
506
|
+
formula?: FormulaCallback<Owner>;
|
|
507
|
+
filters?: FilterOptions;
|
|
364
508
|
prefix?: string | boolean;
|
|
365
509
|
prefixMode?: EmbeddedPrefixMode;
|
|
366
510
|
embedded?: [EntityKey<Owner>, EntityKey<Owner>];
|
|
@@ -368,16 +512,23 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
368
512
|
embeddable: EntityClass<Owner>;
|
|
369
513
|
embeddedProps: Dictionary<EntityProperty>;
|
|
370
514
|
discriminatorColumn?: string;
|
|
515
|
+
discriminator?: string;
|
|
516
|
+
polymorphic?: boolean;
|
|
517
|
+
polymorphTargets?: EntityMetadata[];
|
|
518
|
+
discriminatorMap?: Dictionary<EntityClass<Target>>;
|
|
519
|
+
discriminatorValue?: string;
|
|
371
520
|
object?: boolean;
|
|
372
521
|
index?: boolean | string;
|
|
373
522
|
unique?: boolean | string;
|
|
374
523
|
nullable?: boolean;
|
|
375
524
|
inherited?: boolean;
|
|
525
|
+
renamedFrom?: string;
|
|
526
|
+
stiFieldNames?: string[];
|
|
527
|
+
stiFieldNameMap?: Dictionary<string>;
|
|
376
528
|
unsigned?: boolean;
|
|
377
529
|
mapToPk?: boolean;
|
|
378
530
|
persist?: boolean;
|
|
379
531
|
hydrate?: boolean;
|
|
380
|
-
trackChanges?: boolean;
|
|
381
532
|
hidden?: boolean;
|
|
382
533
|
enum?: boolean;
|
|
383
534
|
items?: (number | string)[];
|
|
@@ -388,6 +539,7 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
388
539
|
setter?: boolean;
|
|
389
540
|
getter?: boolean;
|
|
390
541
|
getterName?: keyof Owner;
|
|
542
|
+
accessor?: EntityKey<Owner>;
|
|
391
543
|
cascade: Cascade[];
|
|
392
544
|
orphanRemoval?: boolean;
|
|
393
545
|
onCreate?: (entity: Owner, em: EntityManager) => any;
|
|
@@ -404,13 +556,14 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
404
556
|
fixedOrder?: boolean;
|
|
405
557
|
fixedOrderColumn?: string;
|
|
406
558
|
pivotTable: string;
|
|
407
|
-
pivotEntity:
|
|
559
|
+
pivotEntity: EntityClass<Target>;
|
|
408
560
|
joinColumns: string[];
|
|
409
561
|
ownColumns: string[];
|
|
410
562
|
inverseJoinColumns: string[];
|
|
411
563
|
referencedColumnNames: string[];
|
|
412
564
|
referencedTableName: string;
|
|
413
565
|
referencedPKs: EntityKey<Owner>[];
|
|
566
|
+
targetKey?: string;
|
|
414
567
|
serializer?: (value: any, options?: SerializeOptions<any>) => any;
|
|
415
568
|
serializedName?: string;
|
|
416
569
|
comment?: string;
|
|
@@ -423,18 +576,30 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
423
576
|
createForeignKeyConstraint: boolean;
|
|
424
577
|
foreignKeyName?: string;
|
|
425
578
|
}
|
|
426
|
-
export declare class EntityMetadata<
|
|
579
|
+
export declare class EntityMetadata<Entity = any, Class extends EntityCtor<Entity> = EntityCtor<Entity>> {
|
|
427
580
|
private static counter;
|
|
428
581
|
readonly _id: number;
|
|
429
582
|
readonly propertyOrder: Map<string, number>;
|
|
430
583
|
constructor(meta?: Partial<EntityMetadata>);
|
|
431
|
-
addProperty(prop: Partial<EntityProperty<
|
|
584
|
+
addProperty(prop: Partial<EntityProperty<Entity>>): void;
|
|
432
585
|
removeProperty(name: string, sync?: boolean): void;
|
|
433
|
-
getPrimaryProps(flatten?: boolean): EntityProperty<
|
|
434
|
-
getPrimaryProp(): EntityProperty<
|
|
435
|
-
|
|
586
|
+
getPrimaryProps(flatten?: boolean): EntityProperty<Entity>[];
|
|
587
|
+
getPrimaryProp(): EntityProperty<Entity>;
|
|
588
|
+
/**
|
|
589
|
+
* Creates a mapping from property names to field names.
|
|
590
|
+
* @param alias - Optional alias to prefix field names. Can be a string (same for all) or a function (per-property).
|
|
591
|
+
* When provided, also adds toString() returning the alias for backwards compatibility with formulas.
|
|
592
|
+
* @param toStringAlias - Optional alias to return from toString(). Defaults to `alias` when it's a string.
|
|
593
|
+
*/
|
|
594
|
+
createColumnMappingObject(alias?: string | ((prop: EntityProperty<Entity>) => string), toStringAlias?: string): FormulaColumns<Entity>;
|
|
595
|
+
/**
|
|
596
|
+
* Creates a column mapping for schema callbacks (indexes, checks, generated columns).
|
|
597
|
+
* For TPT entities, only includes properties that belong to the current table (ownProps).
|
|
598
|
+
*/
|
|
599
|
+
createSchemaColumnMappingObject(): SchemaColumns<Entity>;
|
|
436
600
|
get tableName(): string;
|
|
437
601
|
set tableName(name: string);
|
|
602
|
+
get uniqueName(): string;
|
|
438
603
|
sync(initIndexes?: boolean, config?: Configuration): void;
|
|
439
604
|
private initIndexes;
|
|
440
605
|
/** @internal */
|
|
@@ -444,67 +609,87 @@ export interface SimpleColumnMeta {
|
|
|
444
609
|
name: string;
|
|
445
610
|
type: string;
|
|
446
611
|
}
|
|
447
|
-
export
|
|
612
|
+
export type EntityCtor<T = any> = abstract new (...args: any[]) => T;
|
|
613
|
+
export interface EntityMetadata<Entity = any, Class extends EntityCtor<Entity> = EntityCtor<Entity>> {
|
|
448
614
|
name?: string;
|
|
449
615
|
className: string;
|
|
450
616
|
tableName: string;
|
|
451
617
|
schema?: string;
|
|
452
618
|
pivotTable?: boolean;
|
|
453
619
|
virtual?: boolean;
|
|
454
|
-
|
|
455
|
-
|
|
620
|
+
/** True if this entity represents a database view (not a virtual entity). Accepts `{ materialized: true }` as input, normalized to `true` during sync. */
|
|
621
|
+
view?: boolean | {
|
|
622
|
+
materialized?: boolean;
|
|
623
|
+
withData?: boolean;
|
|
624
|
+
};
|
|
625
|
+
/** True if this is a materialized view (PostgreSQL only). Requires `view: true`. */
|
|
626
|
+
materialized?: boolean;
|
|
627
|
+
/** For materialized views, whether data is populated on creation. Defaults to true. */
|
|
628
|
+
withData?: boolean;
|
|
629
|
+
expression?: string | ((em: any, where: ObjectQuery<Entity>, options: FindOptions<Entity, any, any, any>, stream?: boolean) => MaybePromise<Raw | object | string>);
|
|
630
|
+
discriminatorColumn?: EntityKey<Entity> | AnyString;
|
|
456
631
|
discriminatorValue?: number | string;
|
|
457
|
-
discriminatorMap?: Dictionary<
|
|
632
|
+
discriminatorMap?: Dictionary<EntityClass>;
|
|
458
633
|
embeddable: boolean;
|
|
459
|
-
constructorParams
|
|
634
|
+
constructorParams?: (keyof Entity)[];
|
|
460
635
|
forceConstructor: boolean;
|
|
461
|
-
|
|
462
|
-
extends: string;
|
|
636
|
+
extends?: EntityName<Entity>;
|
|
463
637
|
collection: string;
|
|
464
638
|
path: string;
|
|
465
|
-
primaryKeys: EntityKey<
|
|
639
|
+
primaryKeys: EntityKey<Entity>[];
|
|
466
640
|
simplePK: boolean;
|
|
467
641
|
compositePK: boolean;
|
|
468
|
-
versionProperty: EntityKey<
|
|
469
|
-
concurrencyCheckKeys: Set<EntityKey<
|
|
470
|
-
serializedPrimaryKey
|
|
642
|
+
versionProperty: EntityKey<Entity>;
|
|
643
|
+
concurrencyCheckKeys: Set<EntityKey<Entity>>;
|
|
644
|
+
serializedPrimaryKey?: EntityKey<Entity>;
|
|
471
645
|
properties: {
|
|
472
|
-
[K in EntityKey<
|
|
646
|
+
[K in EntityKey<Entity>]: EntityProperty<Entity>;
|
|
473
647
|
};
|
|
474
|
-
props: EntityProperty<
|
|
475
|
-
relations: EntityProperty<
|
|
476
|
-
bidirectionalRelations: EntityProperty<
|
|
648
|
+
props: EntityProperty<Entity>[];
|
|
649
|
+
relations: EntityProperty<Entity>[];
|
|
650
|
+
bidirectionalRelations: EntityProperty<Entity>[];
|
|
477
651
|
referencingProperties: {
|
|
478
|
-
meta: EntityMetadata<
|
|
479
|
-
prop: EntityProperty<
|
|
652
|
+
meta: EntityMetadata<Entity>;
|
|
653
|
+
prop: EntityProperty<Entity>;
|
|
480
654
|
}[];
|
|
481
|
-
comparableProps: EntityProperty<
|
|
482
|
-
trackingProps: EntityProperty<
|
|
483
|
-
hydrateProps: EntityProperty<
|
|
484
|
-
|
|
485
|
-
|
|
655
|
+
comparableProps: EntityProperty<Entity>[];
|
|
656
|
+
trackingProps: EntityProperty<Entity>[];
|
|
657
|
+
hydrateProps: EntityProperty<Entity>[];
|
|
658
|
+
validateProps: EntityProperty<Entity>[];
|
|
659
|
+
uniqueProps: EntityProperty<Entity>[];
|
|
660
|
+
getterProps: EntityProperty<Entity>[];
|
|
486
661
|
indexes: {
|
|
487
|
-
properties?: EntityKey<
|
|
662
|
+
properties?: EntityKey<Entity> | EntityKey<Entity>[];
|
|
488
663
|
name?: string;
|
|
489
664
|
type?: string;
|
|
490
665
|
options?: Dictionary;
|
|
491
|
-
expression?: string | IndexCallback<
|
|
666
|
+
expression?: string | IndexCallback<Entity>;
|
|
667
|
+
columns?: IndexColumnOptions[];
|
|
668
|
+
include?: EntityKey<Entity> | EntityKey<Entity>[];
|
|
669
|
+
fillFactor?: number;
|
|
670
|
+
invisible?: boolean;
|
|
671
|
+
disabled?: boolean;
|
|
672
|
+
clustered?: boolean;
|
|
492
673
|
}[];
|
|
493
674
|
uniques: {
|
|
494
|
-
properties?: EntityKey<
|
|
675
|
+
properties?: EntityKey<Entity> | EntityKey<Entity>[];
|
|
495
676
|
name?: string;
|
|
496
677
|
options?: Dictionary;
|
|
497
|
-
expression?: string | IndexCallback<
|
|
678
|
+
expression?: string | IndexCallback<Entity>;
|
|
498
679
|
deferMode?: DeferMode | `${DeferMode}`;
|
|
680
|
+
columns?: IndexColumnOptions[];
|
|
681
|
+
include?: EntityKey<Entity> | EntityKey<Entity>[];
|
|
682
|
+
fillFactor?: number;
|
|
683
|
+
disabled?: boolean;
|
|
499
684
|
}[];
|
|
500
|
-
checks: CheckConstraint<
|
|
685
|
+
checks: CheckConstraint<Entity>[];
|
|
501
686
|
repositoryClass?: string;
|
|
502
687
|
repository: () => EntityClass<EntityRepository<any>>;
|
|
503
688
|
hooks: {
|
|
504
|
-
[K in EventType]?: (keyof
|
|
689
|
+
[K in EventType]?: (keyof Entity | EventSubscriber<Entity>[EventType])[];
|
|
505
690
|
};
|
|
506
|
-
prototype:
|
|
507
|
-
class:
|
|
691
|
+
prototype: Entity;
|
|
692
|
+
class: Class;
|
|
508
693
|
abstract: boolean;
|
|
509
694
|
filters: Dictionary<FilterDef>;
|
|
510
695
|
comment?: string;
|
|
@@ -512,9 +697,32 @@ export interface EntityMetadata<T = any> {
|
|
|
512
697
|
hasUniqueProps?: boolean;
|
|
513
698
|
readonly?: boolean;
|
|
514
699
|
polymorphs?: EntityMetadata[];
|
|
515
|
-
root: EntityMetadata<
|
|
700
|
+
root: EntityMetadata<Entity>;
|
|
516
701
|
definedProperties: Dictionary;
|
|
702
|
+
/** For polymorphic M:N pivot tables, maps discriminator values to entity classes */
|
|
703
|
+
polymorphicDiscriminatorMap?: Dictionary<EntityClass>;
|
|
704
|
+
/** Inheritance type: 'sti' (Single Table Inheritance) or 'tpt' (Table-Per-Type). Only set on root entities. */
|
|
705
|
+
inheritanceType?: 'sti' | 'tpt';
|
|
706
|
+
/** For TPT: direct parent entity metadata (the entity this one extends). */
|
|
707
|
+
tptParent?: EntityMetadata;
|
|
708
|
+
/** For TPT: direct child entities (entities that extend this one). */
|
|
709
|
+
tptChildren?: EntityMetadata[];
|
|
710
|
+
/** For TPT: all non-abstract descendants, sorted by depth (deepest first). Precomputed during discovery. */
|
|
711
|
+
allTPTDescendants?: EntityMetadata[];
|
|
712
|
+
/** For TPT: synthetic property representing the join to the parent table (child PK → parent PK). */
|
|
713
|
+
tptParentProp?: EntityProperty;
|
|
714
|
+
/** For TPT: inverse of tptParentProp, used for joining from parent to child (parent PK → child PK). */
|
|
715
|
+
tptInverseProp?: EntityProperty;
|
|
716
|
+
/** For TPT: virtual discriminator property name (computed at query time, not persisted). */
|
|
717
|
+
tptDiscriminatorColumn?: string;
|
|
718
|
+
/** For TPT: properties defined only in THIS entity (not inherited from parent). */
|
|
719
|
+
ownProps?: EntityProperty<Entity>[];
|
|
517
720
|
hasTriggers?: boolean;
|
|
721
|
+
/**
|
|
722
|
+
* Default ordering for this entity. Applied when querying this entity directly
|
|
723
|
+
* or when it's populated as a relation. Combined with other orderings based on precedence.
|
|
724
|
+
*/
|
|
725
|
+
orderBy?: QueryOrderMap<Entity> | QueryOrderMap<Entity>[];
|
|
518
726
|
/** @internal can be used for computed numeric cache keys */
|
|
519
727
|
readonly _id: number;
|
|
520
728
|
}
|
|
@@ -525,6 +733,7 @@ export interface CreateSchemaOptions {
|
|
|
525
733
|
export interface ClearDatabaseOptions {
|
|
526
734
|
schema?: string;
|
|
527
735
|
truncate?: boolean;
|
|
736
|
+
clearIdentityMap?: boolean;
|
|
528
737
|
}
|
|
529
738
|
export interface EnsureDatabaseOptions extends CreateSchemaOptions, ClearDatabaseOptions {
|
|
530
739
|
clear?: boolean;
|
|
@@ -552,25 +761,25 @@ export interface RefreshDatabaseOptions extends CreateSchemaOptions {
|
|
|
552
761
|
createSchema?: boolean;
|
|
553
762
|
}
|
|
554
763
|
export interface ISchemaGenerator {
|
|
555
|
-
|
|
556
|
-
|
|
764
|
+
create(options?: CreateSchemaOptions): Promise<void>;
|
|
765
|
+
update(options?: UpdateSchemaOptions): Promise<void>;
|
|
766
|
+
drop(options?: DropSchemaOptions): Promise<void>;
|
|
767
|
+
refresh(options?: RefreshDatabaseOptions): Promise<void>;
|
|
768
|
+
clear(options?: ClearDatabaseOptions): Promise<void>;
|
|
769
|
+
execute(sql: string, options?: {
|
|
770
|
+
wrap?: boolean;
|
|
771
|
+
}): Promise<void>;
|
|
557
772
|
getCreateSchemaSQL(options?: CreateSchemaOptions): Promise<string>;
|
|
558
|
-
dropSchema(options?: DropSchemaOptions): Promise<void>;
|
|
559
773
|
getDropSchemaSQL(options?: Omit<DropSchemaOptions, 'dropDb'>): Promise<string>;
|
|
560
|
-
updateSchema(options?: UpdateSchemaOptions): Promise<void>;
|
|
561
774
|
getUpdateSchemaSQL(options?: UpdateSchemaOptions): Promise<string>;
|
|
562
775
|
getUpdateSchemaMigrationSQL(options?: UpdateSchemaOptions): Promise<{
|
|
563
776
|
up: string;
|
|
564
777
|
down: string;
|
|
565
778
|
}>;
|
|
779
|
+
ensureDatabase(options?: EnsureDatabaseOptions): Promise<boolean>;
|
|
566
780
|
createDatabase(name?: string): Promise<void>;
|
|
567
781
|
dropDatabase(name?: string): Promise<void>;
|
|
568
|
-
execute(sql: string, options?: {
|
|
569
|
-
wrap?: boolean;
|
|
570
|
-
}): Promise<void>;
|
|
571
782
|
ensureIndexes(): Promise<void>;
|
|
572
|
-
refreshDatabase(options?: RefreshDatabaseOptions): Promise<void>;
|
|
573
|
-
clearDatabase(options?: ClearDatabaseOptions): Promise<void>;
|
|
574
783
|
}
|
|
575
784
|
export type ImportsResolver = (alias: string, basePath: string, extension: '.js' | '', originFileName: string) => {
|
|
576
785
|
path: string;
|
|
@@ -587,7 +796,10 @@ export interface GenerateOptions {
|
|
|
587
796
|
undefinedDefaults?: boolean;
|
|
588
797
|
bidirectionalRelations?: boolean;
|
|
589
798
|
identifiedReferences?: boolean;
|
|
590
|
-
|
|
799
|
+
entityDefinition?: 'decorators' | 'defineEntity' | 'entitySchema';
|
|
800
|
+
decorators?: 'es' | 'legacy';
|
|
801
|
+
inferEntityType?: boolean;
|
|
802
|
+
enumMode?: 'ts-enum' | 'union-type' | 'dictionary';
|
|
591
803
|
esmImport?: boolean;
|
|
592
804
|
scalarTypeInDecorator?: boolean;
|
|
593
805
|
scalarPropertiesForRelations?: 'always' | 'never' | 'smart';
|
|
@@ -606,7 +818,7 @@ export interface GenerateOptions {
|
|
|
606
818
|
export interface IEntityGenerator {
|
|
607
819
|
generate(options?: GenerateOptions): Promise<string[]>;
|
|
608
820
|
}
|
|
609
|
-
export type
|
|
821
|
+
export type MigrationInfo = {
|
|
610
822
|
name: string;
|
|
611
823
|
path?: string;
|
|
612
824
|
};
|
|
@@ -626,6 +838,14 @@ export type MigrationRow = {
|
|
|
626
838
|
name: string;
|
|
627
839
|
executed_at: Date;
|
|
628
840
|
};
|
|
841
|
+
/**
|
|
842
|
+
* @internal
|
|
843
|
+
*/
|
|
844
|
+
export interface IMigrationRunner {
|
|
845
|
+
run(migration: Migration, method: 'up' | 'down'): Promise<void>;
|
|
846
|
+
setMasterMigration(trx: Transaction): void;
|
|
847
|
+
unsetMasterMigration(): void;
|
|
848
|
+
}
|
|
629
849
|
/**
|
|
630
850
|
* @internal
|
|
631
851
|
*/
|
|
@@ -647,42 +867,42 @@ export interface IMigrator {
|
|
|
647
867
|
/**
|
|
648
868
|
* Checks current schema for changes, generates new migration if there are any.
|
|
649
869
|
*/
|
|
650
|
-
|
|
870
|
+
create(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<MigrationResult>;
|
|
651
871
|
/**
|
|
652
872
|
* Checks current schema for changes.
|
|
653
873
|
*/
|
|
654
|
-
|
|
874
|
+
checkSchema(): Promise<boolean>;
|
|
655
875
|
/**
|
|
656
876
|
* Creates initial migration. This generates the schema based on metadata, and checks whether all the tables
|
|
657
877
|
* are already present. If yes, it will also automatically log the migration as executed.
|
|
658
878
|
* Initial migration can be created only if the schema is already aligned with the metadata, or when no schema
|
|
659
879
|
* is present - in such case regular migration would have the same effect.
|
|
660
880
|
*/
|
|
661
|
-
|
|
881
|
+
createInitial(path?: string): Promise<MigrationResult>;
|
|
662
882
|
/**
|
|
663
883
|
* Returns list of already executed migrations.
|
|
664
884
|
*/
|
|
665
|
-
|
|
885
|
+
getExecuted(): Promise<MigrationRow[]>;
|
|
666
886
|
/**
|
|
667
887
|
* Returns list of pending (not yet executed) migrations found in the migration directory.
|
|
668
888
|
*/
|
|
669
|
-
|
|
889
|
+
getPending(): Promise<MigrationInfo[]>;
|
|
670
890
|
/**
|
|
671
891
|
* Executes specified migrations. Without parameter it will migrate up to the latest version.
|
|
672
892
|
*/
|
|
673
|
-
up(options?: string | string[] | MigrateOptions): Promise<
|
|
893
|
+
up(options?: string | string[] | MigrateOptions): Promise<MigrationInfo[]>;
|
|
674
894
|
/**
|
|
675
895
|
* Executes down migrations to the given point. Without parameter it will migrate one version down.
|
|
676
896
|
*/
|
|
677
|
-
down(options?: string | string[] | MigrateOptions): Promise<
|
|
897
|
+
down(options?: string | string[] | Omit<MigrateOptions, 'from'>): Promise<MigrationInfo[]>;
|
|
678
898
|
/**
|
|
679
899
|
* Registers event handler.
|
|
680
900
|
*/
|
|
681
|
-
on(event: MigratorEvent, listener: (event:
|
|
901
|
+
on(event: MigratorEvent, listener: (event: MigrationInfo) => MaybePromise<void>): IMigrator;
|
|
682
902
|
/**
|
|
683
903
|
* Removes event handler.
|
|
684
904
|
*/
|
|
685
|
-
off(event: MigratorEvent, listener: (event:
|
|
905
|
+
off(event: MigratorEvent, listener: (event: MigrationInfo) => MaybePromise<void>): IMigrator;
|
|
686
906
|
/**
|
|
687
907
|
* @internal
|
|
688
908
|
*/
|
|
@@ -710,17 +930,26 @@ export interface IMigrationGenerator {
|
|
|
710
930
|
export interface Migration {
|
|
711
931
|
up(): Promise<void> | void;
|
|
712
932
|
down(): Promise<void> | void;
|
|
933
|
+
isTransactional(): boolean;
|
|
934
|
+
reset(): void;
|
|
935
|
+
setTransactionContext(ctx: Transaction): void;
|
|
936
|
+
getQueries?(): any[];
|
|
713
937
|
}
|
|
714
938
|
export interface MigrationObject {
|
|
715
939
|
name: string;
|
|
716
940
|
class: Constructor<Migration>;
|
|
717
941
|
}
|
|
718
|
-
|
|
942
|
+
type EntityFromInput<T> = T extends readonly EntityName<infer U>[] ? U : T extends EntityName<infer U> ? U : never;
|
|
943
|
+
type FilterDefResolved<T extends object = any> = {
|
|
719
944
|
name: string;
|
|
720
|
-
cond:
|
|
945
|
+
cond: FilterQuery<T> | ((args: Dictionary, type: 'read' | 'update' | 'delete', em: any, options?: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any>, entityName?: string) => MaybePromise<FilterQuery<T>>);
|
|
721
946
|
default?: boolean;
|
|
722
|
-
entity?:
|
|
947
|
+
entity?: EntityName<T> | EntityName<T>[];
|
|
723
948
|
args?: boolean;
|
|
949
|
+
strict?: boolean;
|
|
950
|
+
};
|
|
951
|
+
export type FilterDef<T extends EntityName | readonly EntityName[] = any> = FilterDefResolved<EntityFromInput<T>> & {
|
|
952
|
+
entity?: T;
|
|
724
953
|
};
|
|
725
954
|
export type Populate<T, P extends string = never> = readonly AutoPath<T, P, `${PopulatePath}`>[] | false;
|
|
726
955
|
export type PopulateOptions<T> = {
|
|
@@ -730,47 +959,67 @@ export type PopulateOptions<T> = {
|
|
|
730
959
|
filter?: boolean;
|
|
731
960
|
joinType?: 'inner join' | 'left join';
|
|
732
961
|
children?: PopulateOptions<T[keyof T]>[];
|
|
962
|
+
/** When true, ignores `mapToPk` on the property and returns full entity data instead of just PKs. */
|
|
963
|
+
dataOnly?: boolean;
|
|
733
964
|
};
|
|
734
|
-
type
|
|
735
|
-
|
|
965
|
+
export type PopulateHintOptions = {
|
|
966
|
+
strategy?: LoadStrategy.JOINED | LoadStrategy.SELECT_IN | 'joined' | 'select-in';
|
|
967
|
+
joinType?: 'inner join' | 'left join';
|
|
968
|
+
};
|
|
969
|
+
type ExtractType<T> = T extends CollectionShape<infer U> ? U : T extends ReferenceShape<infer U> ? U : T extends Ref<infer U> ? U : T extends readonly (infer U)[] ? U : T;
|
|
736
970
|
type ExtractStringKeys<T> = {
|
|
737
|
-
[K in keyof T]
|
|
971
|
+
[K in keyof T]-?: CleanKeys<T, K>;
|
|
738
972
|
}[keyof T] & {};
|
|
739
|
-
|
|
740
|
-
|
|
973
|
+
/**
|
|
974
|
+
* Extracts string keys from an entity type, handling Collection/Reference wrappers.
|
|
975
|
+
* Simplified to just check `T extends object` since ExtractType handles the unwrapping.
|
|
976
|
+
*/
|
|
977
|
+
type StringKeys<T, E extends string = never> = T extends object ? ExtractStringKeys<ExtractType<T>> | E : never;
|
|
978
|
+
type GetStringKey<T, K extends StringKeys<T, string>, E extends string> = K extends keyof T ? ExtractType<T[K]> : K extends E ? keyof T : never;
|
|
741
979
|
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
742
|
-
type
|
|
743
|
-
[K in keyof T]
|
|
980
|
+
type RelationKeys<T> = T extends object ? {
|
|
981
|
+
[K in keyof T]-?: CleanKeys<T, K, true>;
|
|
744
982
|
}[keyof T] & {} : never;
|
|
745
|
-
export type AutoPath<O, P extends string | boolean, E extends string = never, D extends Prev[number] = 9> = P extends boolean ? P : [D] extends [never] ? never : P extends any ? P extends string ?
|
|
983
|
+
export type AutoPath<O, P extends string | boolean, E extends string = never, D extends Prev[number] = 9> = P extends boolean ? P : [D] extends [never] ? never : P extends any ? P extends string ? P extends `${infer A}.${infer B}` ? A extends StringKeys<O, E> ? `${A}.${AutoPath<NonNullable<GetStringKey<O, A, E>>, B, E, Prev[D]>}` : never : P extends StringKeys<O, E> ? (NonNullable<GetStringKey<O, P & StringKeys<O, E>, E>> extends unknown ? Exclude<P, `${string}.`> : never) | (StringKeys<NonNullable<GetStringKey<O, P & StringKeys<O, E>, E>>, E> extends never ? never : `${P & string}.`) : StringKeys<O, E> | `${RelationKeys<O>}:ref` : never : never;
|
|
746
984
|
export type UnboxArray<T> = T extends any[] ? ArrayElement<T> : T;
|
|
747
985
|
export type ArrayElement<ArrayType extends unknown[]> = ArrayType extends (infer ElementType)[] ? ElementType : never;
|
|
748
|
-
export type ExpandProperty<T> = T extends
|
|
749
|
-
type LoadedLoadable<T, E extends object> = T extends
|
|
750
|
-
type IsTrue<T> = IsNever<T> extends true ? false : T extends boolean ? T extends true ? true : false : false;
|
|
751
|
-
type StringLiteral<T> = T extends string ? string extends T ? never : T : never;
|
|
752
|
-
type Prefix<T, K> = K extends `${infer S}.${string}` ? S :
|
|
986
|
+
export type ExpandProperty<T> = T extends ReferenceShape<infer U> ? NonNullable<U> : T extends CollectionShape<infer U> ? NonNullable<U> : T extends (infer U)[] ? NonNullable<U> : NonNullable<T>;
|
|
987
|
+
type LoadedLoadable<T, E extends object> = T extends CollectionShape ? LoadedCollection<E> : T extends ScalarReference<infer U> ? LoadedScalarReference<U> : T extends ReferenceShape ? T & LoadedReference<E> : T extends Scalar ? T : T extends (infer U)[] ? U extends Scalar ? T : E[] : E;
|
|
988
|
+
type IsTrue<T> = IsNever<T> extends true ? false : T extends boolean ? (T extends true ? true : false) : false;
|
|
989
|
+
type StringLiteral<T> = T extends string ? (string extends T ? never : T) : never;
|
|
990
|
+
type Prefix<T, K> = K extends `${infer S}.${string}` ? S : K extends '*' ? keyof T : K;
|
|
753
991
|
type IsPrefixedExclude<T, K extends keyof T, E extends string> = K extends E ? never : K;
|
|
754
|
-
export type IsPrefixed<T, K extends keyof T, L extends string, E extends string = never> = IsNever<E> extends false ? IsPrefixedExclude<T, K, E> : K extends symbol ? never : IsTrue<L> extends true ?
|
|
755
|
-
type Suffix<Key, Hint extends string, All = true | '*'> = Hint extends `${infer Pref}.${infer Suf}` ?
|
|
756
|
-
export type IsSubset<T, U> = keyof U extends keyof T ? {} :
|
|
992
|
+
export type IsPrefixed<T, K extends keyof T, L extends string, E extends string = never> = IsNever<E> extends false ? IsPrefixedExclude<T, K, E> : K extends symbol ? never : IsTrue<L> extends true ? T[K] & {} extends LoadableShape ? K : never : IsNever<StringLiteral<L>> extends true ? never : '*' extends L ? K : K extends Prefix<T, L> ? K : K extends PrimaryProperty<T> ? K : never;
|
|
993
|
+
type Suffix<Key, Hint extends string, All = true | '*'> = Hint extends `${infer Pref}.${infer Suf}` ? Pref extends Key ? Suf : never : Hint extends All ? Hint : never;
|
|
994
|
+
export type IsSubset<T, U> = keyof U extends keyof T ? {} : string extends keyof U ? {} : {
|
|
757
995
|
[K in keyof U as K extends keyof T ? never : CleanKeys<U, K>]: never;
|
|
758
996
|
};
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
type
|
|
764
|
-
|
|
765
|
-
|
|
997
|
+
/**
|
|
998
|
+
* Fast check if T is a Loaded type by looking for the marker symbol.
|
|
999
|
+
* This is much cheaper than matching against the full Loaded structure.
|
|
1000
|
+
*/
|
|
1001
|
+
type IsLoadedType<T> = T extends {
|
|
1002
|
+
[__loadedType]?: any;
|
|
1003
|
+
} ? true : false;
|
|
1004
|
+
/**
|
|
1005
|
+
* Optimized MergeSelected using intersection instead of extraction.
|
|
1006
|
+
* When T is already Loaded, we intersect with a new Loaded type for the selected fields.
|
|
1007
|
+
* This avoids the expensive pattern matching needed to extract hints from Loaded types.
|
|
1008
|
+
*/
|
|
1009
|
+
export type MergeSelected<T, U, F extends string> = IsLoadedType<T> extends true ? T & Loaded<U, never, F, never> : T;
|
|
1010
|
+
/**
|
|
1011
|
+
* Optimized MergeLoaded using intersection instead of extraction.
|
|
1012
|
+
* When T is already Loaded, we intersect with a new Loaded type for the additional hints.
|
|
1013
|
+
* This avoids the expensive pattern matching needed to extract hints from Loaded types.
|
|
1014
|
+
* Used for `em.populate` and `em.refresh`.
|
|
1015
|
+
*/
|
|
1016
|
+
export type MergeLoaded<T, U, P extends string, F extends string, E extends string, R extends boolean = false> = IsLoadedType<T> extends true ? T & Loaded<U, P, F, E> : Loaded<T, P, F, E>;
|
|
766
1017
|
export type AddOptional<T> = undefined | null extends T ? null | undefined : null extends T ? null : undefined extends T ? undefined : never;
|
|
767
1018
|
type LoadedProp<T, L extends string = never, F extends string = '*', E extends string = never> = LoadedLoadable<T, Loaded<ExtractType<T>, L, F, E>>;
|
|
768
1019
|
export type AddEager<T> = ExtractEagerProps<T> & string;
|
|
769
1020
|
export type ExpandHint<T, L extends string> = L | AddEager<T>;
|
|
770
1021
|
export type Selected<T, L extends string = never, F extends string = '*'> = {
|
|
771
|
-
[K in keyof T as IsPrefixed<T, K, L | F | AddEager<T>>]: LoadedProp<NonNullable<T[K]>, Suffix<K, L, true>, Suffix<K, F, true>> | AddOptional<T[K]>;
|
|
772
|
-
} & {
|
|
773
|
-
[K in keyof T as FunctionKeys<T, K>]: T[K];
|
|
1022
|
+
[K in keyof T as IsPrefixed<T, K, L | F | AddEager<T>> | FunctionKeys<T, K>]: T[K] extends Function ? T[K] : NonNullable<T[K]> extends Scalar ? T[K] : LoadedProp<NonNullable<T[K]>, Suffix<K, L, true>, Suffix<K, F, true>> | AddOptional<T[K]>;
|
|
774
1023
|
} & {
|
|
775
1024
|
[__selectedType]?: T;
|
|
776
1025
|
};
|
|
@@ -781,18 +1030,18 @@ type LoadedEntityType<T> = {
|
|
|
781
1030
|
};
|
|
782
1031
|
export type EntityType<T> = T | LoadedEntityType<T>;
|
|
783
1032
|
export type FromEntityType<T> = T extends LoadedEntityType<infer U> ? U : T;
|
|
784
|
-
type LoadedInternal<T, L extends string = never, F extends string = '*', E extends string = never> = [
|
|
785
|
-
F
|
|
786
|
-
] extends ['*'] ? IsNever<E> extends true ? T & {
|
|
1033
|
+
type LoadedInternal<T, L extends string = never, F extends string = '*', E extends string = never> = [F] extends ['*'] ? IsNever<E> extends true ? T & {
|
|
787
1034
|
[K in keyof T as IsPrefixed<T, K, ExpandHint<T, L>>]: LoadedProp<NonNullable<T[K]>, Suffix<K, L>, Suffix<K, F>, Suffix<K, E>> | AddOptional<T[K]>;
|
|
788
1035
|
} : {
|
|
789
1036
|
[K in keyof T as IsPrefixed<T, K, ExpandHint<T, L>, E>]: LoadedProp<NonNullable<T[K]>, Suffix<K, L>, Suffix<K, F>, Suffix<K, E>> | AddOptional<T[K]>;
|
|
790
1037
|
} : Selected<T, L, F>;
|
|
791
1038
|
/**
|
|
792
1039
|
* Represents entity with its loaded relations (`populate` hint) and selected properties (`fields` hint).
|
|
1040
|
+
* The __loadHint marker uses contravariance to ensure Loaded<A, 'b'> is NOT assignable to Loaded<A, 'b.c'>.
|
|
793
1041
|
*/
|
|
794
1042
|
export type Loaded<T, L extends string = never, F extends string = '*', E extends string = never> = LoadedInternal<T, L, F, E> & {
|
|
795
1043
|
[__loadedType]?: T;
|
|
1044
|
+
[__loadHint]?: (hint: Prefixes<L>) => void;
|
|
796
1045
|
};
|
|
797
1046
|
export interface LoadedReference<T> extends Reference<NonNullable<T>> {
|
|
798
1047
|
$: NonNullable<T>;
|
|
@@ -812,23 +1061,23 @@ export interface Highlighter {
|
|
|
812
1061
|
highlight(text: string): string;
|
|
813
1062
|
}
|
|
814
1063
|
export interface IMetadataStorage {
|
|
815
|
-
getAll():
|
|
816
|
-
get<T = any>(entity:
|
|
817
|
-
find<T = any>(entity:
|
|
818
|
-
has(entity:
|
|
819
|
-
set(entity:
|
|
820
|
-
reset(entity:
|
|
1064
|
+
getAll(): Map<EntityName, EntityMetadata>;
|
|
1065
|
+
get<T = any>(entity: EntityName<T>, init?: boolean, validate?: boolean): EntityMetadata<T>;
|
|
1066
|
+
find<T = any>(entity: EntityName<T>): EntityMetadata<T> | undefined;
|
|
1067
|
+
has<T>(entity: EntityName<T>): boolean;
|
|
1068
|
+
set<T>(entity: EntityName<T>, meta: EntityMetadata): EntityMetadata;
|
|
1069
|
+
reset<T>(entity: EntityName<T>): void;
|
|
821
1070
|
}
|
|
822
1071
|
export interface IHydrator {
|
|
823
1072
|
/**
|
|
824
1073
|
* Hydrates the whole entity. This process handles custom type conversions, creating missing Collection instances,
|
|
825
1074
|
* mapping FKs to entity instances, as well as merging those entities.
|
|
826
1075
|
*/
|
|
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): void;
|
|
1076
|
+
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;
|
|
828
1077
|
/**
|
|
829
1078
|
* Hydrates primary keys only
|
|
830
1079
|
*/
|
|
831
|
-
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string): void;
|
|
1080
|
+
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void;
|
|
832
1081
|
isRunning(): boolean;
|
|
833
1082
|
}
|
|
834
1083
|
export interface HydratorConstructor {
|
|
@@ -838,17 +1087,25 @@ export interface ISeedManager {
|
|
|
838
1087
|
seed(...classNames: Constructor<Seeder>[]): Promise<void>;
|
|
839
1088
|
/** @internal */
|
|
840
1089
|
seedString(...classNames: string[]): Promise<void>;
|
|
841
|
-
|
|
1090
|
+
create(className: string): Promise<string>;
|
|
842
1091
|
}
|
|
843
1092
|
export interface Seeder<T extends Dictionary = Dictionary> {
|
|
844
1093
|
run(em: EntityManager, context?: T): void | Promise<void>;
|
|
845
1094
|
}
|
|
1095
|
+
export interface SeederObject {
|
|
1096
|
+
name: string;
|
|
1097
|
+
class: Constructor<Seeder>;
|
|
1098
|
+
}
|
|
846
1099
|
export type ConnectionType = 'read' | 'write';
|
|
847
1100
|
export type MetadataProcessor = (metadata: EntityMetadata[], platform: Platform) => MaybePromise<void>;
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
1101
|
+
export type MaybeReturnType<T> = T extends (...args: any[]) => infer R ? R : T;
|
|
1102
|
+
export interface EntitySchemaWithMeta<TName extends string = string, TTableName extends string = string, TEntity = any, TBase = never, TProperties extends Record<string, any> = Record<string, any>, TClass extends EntityCtor = EntityCtor<TEntity>> extends EntitySchema<TEntity, TBase, TClass> {
|
|
1103
|
+
readonly name: TName;
|
|
1104
|
+
readonly properties: TProperties;
|
|
1105
|
+
readonly tableName: TTableName;
|
|
1106
|
+
/** @internal Direct entity type access - avoids expensive pattern matching */
|
|
1107
|
+
readonly '~entity': TEntity;
|
|
1108
|
+
}
|
|
1109
|
+
export type InferEntity<Schema> = Schema extends {
|
|
1110
|
+
'~entity': infer E;
|
|
1111
|
+
} ? E : Schema extends EntitySchema<infer Entity> ? Entity : Schema extends EntityClass<infer Entity> ? Entity : Schema;
|