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