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