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