@mikro-orm/core 7.0.4 → 7.0.5-dev.1
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 +583 -884
- package/EntityManager.js +1895 -1922
- package/MikroORM.d.ts +74 -103
- package/MikroORM.js +179 -178
- package/README.md +1 -1
- package/cache/CacheAdapter.d.ts +36 -36
- package/cache/FileCacheAdapter.d.ts +24 -30
- package/cache/FileCacheAdapter.js +78 -80
- package/cache/GeneratedCacheAdapter.d.ts +20 -18
- package/cache/GeneratedCacheAdapter.js +30 -30
- package/cache/MemoryCacheAdapter.d.ts +20 -18
- package/cache/MemoryCacheAdapter.js +36 -35
- package/cache/NullCacheAdapter.d.ts +16 -16
- package/cache/NullCacheAdapter.js +24 -24
- package/connections/Connection.d.ts +84 -95
- package/connections/Connection.js +168 -165
- package/drivers/DatabaseDriver.d.ts +80 -186
- package/drivers/DatabaseDriver.js +443 -450
- package/drivers/IDatabaseDriver.d.ts +301 -440
- package/entity/BaseEntity.d.ts +83 -120
- package/entity/BaseEntity.js +43 -43
- package/entity/Collection.d.ts +179 -212
- package/entity/Collection.js +721 -727
- package/entity/EntityAssigner.d.ts +77 -88
- package/entity/EntityAssigner.js +230 -231
- package/entity/EntityFactory.d.ts +54 -66
- package/entity/EntityFactory.js +383 -425
- package/entity/EntityHelper.d.ts +22 -34
- package/entity/EntityHelper.js +267 -280
- package/entity/EntityIdentifier.d.ts +4 -4
- package/entity/EntityIdentifier.js +10 -10
- package/entity/EntityLoader.d.ts +72 -98
- package/entity/EntityLoader.js +723 -753
- package/entity/EntityRepository.d.ts +201 -316
- package/entity/EntityRepository.js +213 -213
- package/entity/PolymorphicRef.d.ts +5 -5
- package/entity/PolymorphicRef.js +10 -10
- package/entity/Reference.d.ts +82 -126
- package/entity/Reference.js +274 -278
- package/entity/WrappedEntity.d.ts +72 -115
- package/entity/WrappedEntity.js +166 -168
- package/entity/defineEntity.d.ts +636 -1315
- package/entity/defineEntity.js +518 -527
- package/entity/utils.d.ts +3 -13
- package/entity/utils.js +73 -71
- package/entity/validators.js +43 -43
- package/entity/wrap.js +8 -8
- package/enums.d.ts +253 -258
- package/enums.js +252 -251
- package/errors.d.ts +72 -114
- package/errors.js +253 -350
- package/events/EventManager.d.ts +14 -26
- package/events/EventManager.js +77 -79
- package/events/EventSubscriber.d.ts +29 -29
- package/events/TransactionEventBroadcaster.d.ts +8 -15
- package/events/TransactionEventBroadcaster.js +14 -14
- package/exceptions.d.ts +40 -23
- package/exceptions.js +52 -35
- package/hydration/Hydrator.d.ts +17 -42
- package/hydration/Hydrator.js +43 -43
- package/hydration/ObjectHydrator.d.ts +17 -50
- package/hydration/ObjectHydrator.js +416 -481
- package/index.d.ts +2 -116
- package/index.js +1 -10
- package/logging/DefaultLogger.d.ts +32 -34
- package/logging/DefaultLogger.js +86 -86
- package/logging/Logger.d.ts +41 -41
- package/logging/SimpleLogger.d.ts +11 -13
- package/logging/SimpleLogger.js +22 -22
- package/logging/colors.d.ts +6 -6
- package/logging/colors.js +10 -11
- package/logging/inspect.js +7 -7
- package/metadata/EntitySchema.d.ts +127 -211
- package/metadata/EntitySchema.js +398 -397
- package/metadata/MetadataDiscovery.d.ts +114 -114
- package/metadata/MetadataDiscovery.js +1870 -1951
- package/metadata/MetadataProvider.d.ts +21 -24
- package/metadata/MetadataProvider.js +84 -82
- package/metadata/MetadataStorage.d.ts +32 -38
- package/metadata/MetadataStorage.js +118 -118
- package/metadata/MetadataValidator.d.ts +39 -39
- package/metadata/MetadataValidator.js +338 -381
- package/metadata/discover-entities.d.ts +2 -5
- package/metadata/discover-entities.js +37 -35
- package/metadata/types.d.ts +531 -615
- package/naming-strategy/AbstractNamingStrategy.d.ts +39 -54
- package/naming-strategy/AbstractNamingStrategy.js +85 -90
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
- package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
- package/naming-strategy/MongoNamingStrategy.d.ts +6 -6
- package/naming-strategy/MongoNamingStrategy.js +18 -18
- package/naming-strategy/NamingStrategy.d.ts +99 -109
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
- package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
- package/not-supported.js +4 -7
- package/package.json +1 -1
- package/platforms/ExceptionConverter.d.ts +1 -1
- package/platforms/ExceptionConverter.js +4 -4
- package/platforms/Platform.d.ts +301 -310
- package/platforms/Platform.js +640 -663
- package/serialization/EntitySerializer.d.ts +26 -49
- package/serialization/EntitySerializer.js +218 -224
- package/serialization/EntityTransformer.d.ts +6 -10
- package/serialization/EntityTransformer.js +217 -219
- package/serialization/SerializationContext.d.ts +23 -27
- package/serialization/SerializationContext.js +105 -105
- package/types/ArrayType.d.ts +8 -8
- package/types/ArrayType.js +33 -33
- package/types/BigIntType.d.ts +10 -17
- package/types/BigIntType.js +37 -37
- package/types/BlobType.d.ts +3 -3
- package/types/BlobType.js +13 -13
- package/types/BooleanType.d.ts +4 -4
- package/types/BooleanType.js +12 -12
- package/types/CharacterType.d.ts +2 -2
- package/types/CharacterType.js +6 -6
- package/types/DateTimeType.d.ts +5 -5
- package/types/DateTimeType.js +15 -15
- package/types/DateType.d.ts +5 -5
- package/types/DateType.js +15 -15
- package/types/DecimalType.d.ts +7 -7
- package/types/DecimalType.js +26 -26
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +12 -12
- package/types/EnumArrayType.d.ts +5 -5
- package/types/EnumArrayType.js +24 -24
- package/types/EnumType.d.ts +3 -3
- package/types/EnumType.js +11 -11
- package/types/FloatType.d.ts +3 -3
- package/types/FloatType.js +9 -9
- package/types/IntegerType.d.ts +3 -3
- package/types/IntegerType.js +9 -9
- package/types/IntervalType.d.ts +4 -4
- package/types/IntervalType.js +12 -12
- package/types/JsonType.d.ts +8 -8
- package/types/JsonType.js +32 -32
- package/types/MediumIntType.d.ts +1 -1
- package/types/MediumIntType.js +3 -3
- package/types/SmallIntType.d.ts +3 -3
- package/types/SmallIntType.js +9 -9
- package/types/StringType.d.ts +4 -4
- package/types/StringType.js +12 -12
- package/types/TextType.d.ts +3 -3
- package/types/TextType.js +9 -9
- package/types/TimeType.d.ts +5 -5
- package/types/TimeType.js +17 -17
- package/types/TinyIntType.d.ts +3 -3
- package/types/TinyIntType.js +10 -10
- package/types/Type.d.ts +79 -83
- package/types/Type.js +82 -82
- package/types/Uint8ArrayType.d.ts +4 -4
- package/types/Uint8ArrayType.js +21 -21
- package/types/UnknownType.d.ts +4 -4
- package/types/UnknownType.js +12 -12
- package/types/UuidType.d.ts +5 -5
- package/types/UuidType.js +19 -19
- package/types/index.d.ts +49 -75
- package/types/index.js +26 -52
- package/typings.d.ts +737 -1250
- package/typings.js +231 -244
- package/unit-of-work/ChangeSet.d.ts +26 -26
- package/unit-of-work/ChangeSet.js +56 -56
- package/unit-of-work/ChangeSetComputer.d.ts +12 -12
- package/unit-of-work/ChangeSetComputer.js +170 -178
- package/unit-of-work/ChangeSetPersister.d.ts +44 -63
- package/unit-of-work/ChangeSetPersister.js +421 -442
- package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
- package/unit-of-work/CommitOrderCalculator.js +88 -89
- package/unit-of-work/IdentityMap.d.ts +31 -31
- package/unit-of-work/IdentityMap.js +105 -105
- package/unit-of-work/UnitOfWork.d.ts +141 -181
- package/unit-of-work/UnitOfWork.js +1183 -1200
- package/utils/AbstractMigrator.d.ts +91 -111
- package/utils/AbstractMigrator.js +275 -275
- package/utils/AbstractSchemaGenerator.d.ts +34 -43
- package/utils/AbstractSchemaGenerator.js +122 -121
- package/utils/AsyncContext.d.ts +3 -3
- package/utils/AsyncContext.js +35 -34
- package/utils/Configuration.d.ts +808 -852
- package/utils/Configuration.js +344 -359
- package/utils/Cursor.d.ts +22 -40
- package/utils/Cursor.js +127 -135
- package/utils/DataloaderUtils.d.ts +43 -58
- package/utils/DataloaderUtils.js +198 -203
- package/utils/EntityComparator.d.ts +81 -98
- package/utils/EntityComparator.js +732 -828
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +3 -3
- package/utils/QueryHelper.d.ts +51 -79
- package/utils/QueryHelper.js +361 -372
- package/utils/RawQueryFragment.d.ts +34 -50
- package/utils/RawQueryFragment.js +105 -107
- package/utils/RequestContext.d.ts +32 -32
- package/utils/RequestContext.js +53 -52
- package/utils/TransactionContext.d.ts +16 -16
- package/utils/TransactionContext.js +27 -27
- package/utils/TransactionManager.d.ts +58 -58
- package/utils/TransactionManager.js +197 -199
- package/utils/Utils.d.ts +145 -204
- package/utils/Utils.js +812 -812
- package/utils/clone.js +113 -104
- package/utils/env-vars.js +88 -90
- package/utils/fs-utils.d.ts +15 -15
- package/utils/fs-utils.js +181 -180
- package/utils/upsert-utils.d.ts +5 -20
- package/utils/upsert-utils.js +116 -114
package/typings.d.ts
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import type { Transaction } from './connections/Connection.js';
|
|
2
|
-
import {
|
|
3
|
-
type Cascade,
|
|
4
|
-
type DeferMode,
|
|
5
|
-
type EmbeddedPrefixMode,
|
|
6
|
-
type EventType,
|
|
7
|
-
type LoadStrategy,
|
|
8
|
-
type PopulatePath,
|
|
9
|
-
type QueryOrderMap,
|
|
10
|
-
ReferenceKind,
|
|
11
|
-
} from './enums.js';
|
|
2
|
+
import { type Cascade, type DeferMode, type EmbeddedPrefixMode, type EventType, type LoadStrategy, type PopulatePath, type QueryOrderMap, ReferenceKind } from './enums.js';
|
|
12
3
|
import { type AssignOptions } from './entity/EntityAssigner.js';
|
|
13
4
|
import { type EntityIdentifier } from './entity/EntityIdentifier.js';
|
|
14
5
|
import { type EntityLoaderOptions } from './entity/EntityLoader.js';
|
|
@@ -33,7 +24,7 @@ export type { Raw };
|
|
|
33
24
|
export type Constructor<T = unknown> = new (...args: any[]) => T;
|
|
34
25
|
/** Simple string-keyed object type. Use instead of `Record<string, T>` for convenience. */
|
|
35
26
|
export type Dictionary<T = any> = {
|
|
36
|
-
|
|
27
|
+
[k: string]: T;
|
|
37
28
|
};
|
|
38
29
|
/** Record of compiled functions, used internally for hydration and comparison. */
|
|
39
30
|
export type CompiledFunctions = Record<string, (...args: any[]) => any>;
|
|
@@ -41,10 +32,9 @@ export type CompiledFunctions = Record<string, (...args: any[]) => any>;
|
|
|
41
32
|
* Extracts string property keys from an entity, excluding symbols, functions, and internal keys.
|
|
42
33
|
* Pass `B = true` to also exclude scalar properties (useful for getting only relation keys).
|
|
43
34
|
*/
|
|
44
|
-
export type EntityKey<T = unknown, B extends boolean = false> = string &
|
|
45
|
-
{
|
|
35
|
+
export type EntityKey<T = unknown, B extends boolean = false> = string & {
|
|
46
36
|
[K in keyof T]-?: CleanKeys<T, K, B> extends never ? never : K;
|
|
47
|
-
|
|
37
|
+
}[keyof T];
|
|
48
38
|
/** Resolves to the value type of entity properties (keyed by `EntityKey<T>`). */
|
|
49
39
|
export type EntityValue<T> = T[EntityKey<T>];
|
|
50
40
|
/** Resolves to the value type within `EntityData<T>` (the data shape used for create/update). */
|
|
@@ -55,26 +45,11 @@ export type FilterKey<T> = keyof FilterQuery<T>;
|
|
|
55
45
|
export type AsyncFunction<R = any, T = Dictionary> = (args: T) => Promise<T>;
|
|
56
46
|
/** Identity mapped type that forces TypeScript to eagerly evaluate and flatten `T`. */
|
|
57
47
|
export type Compute<T> = {
|
|
58
|
-
|
|
48
|
+
[K in keyof T]: T[K];
|
|
59
49
|
} & {};
|
|
60
|
-
type InternalKeys =
|
|
61
|
-
| 'EntityRepositoryType'
|
|
62
|
-
| 'PrimaryKeyProp'
|
|
63
|
-
| 'OptionalProps'
|
|
64
|
-
| 'EagerProps'
|
|
65
|
-
| 'HiddenProps'
|
|
66
|
-
| '__selectedType'
|
|
67
|
-
| '__loadedType';
|
|
50
|
+
type InternalKeys = 'EntityRepositoryType' | 'PrimaryKeyProp' | 'OptionalProps' | 'EagerProps' | 'HiddenProps' | '__selectedType' | '__loadedType';
|
|
68
51
|
/** Filters out function, symbol, and internal keys from an entity type. When `B = true`, also excludes scalar keys. */
|
|
69
|
-
export type CleanKeys<T, K extends keyof T, B extends boolean = false> = T[K] & {} extends Function
|
|
70
|
-
? never
|
|
71
|
-
: K extends symbol | InternalKeys
|
|
72
|
-
? never
|
|
73
|
-
: B extends true
|
|
74
|
-
? T[K] & {} extends Scalar
|
|
75
|
-
? never
|
|
76
|
-
: K
|
|
77
|
-
: K;
|
|
52
|
+
export type CleanKeys<T, K extends keyof T, B extends boolean = false> = T[K] & {} extends Function ? never : K extends symbol | InternalKeys ? never : B extends true ? T[K] & {} extends Scalar ? never : K : K;
|
|
78
53
|
/** Extracts keys of `T` whose values are functions. */
|
|
79
54
|
export type FunctionKeys<T, K extends keyof T> = T[K] extends Function ? K : never;
|
|
80
55
|
/** Conditional cast: returns `T` if it extends `R`, otherwise returns `R`. */
|
|
@@ -98,8 +73,8 @@ export type MaybePromise<T> = T | Promise<T>;
|
|
|
98
73
|
* - With inference: `T extends CollectionShape<infer U>`
|
|
99
74
|
*/
|
|
100
75
|
type CollectionShape<T = any> = {
|
|
101
|
-
|
|
102
|
-
|
|
76
|
+
[k: number]: T;
|
|
77
|
+
readonly owner: object;
|
|
103
78
|
};
|
|
104
79
|
/**
|
|
105
80
|
* Structural type for matching LoadedCollection (extends CollectionShape with `$` property).
|
|
@@ -109,7 +84,7 @@ type CollectionShape<T = any> = {
|
|
|
109
84
|
* - With inference: `T extends LoadedCollectionShape<infer U>`
|
|
110
85
|
*/
|
|
111
86
|
type LoadedCollectionShape<T = any> = CollectionShape<T> & {
|
|
112
|
-
|
|
87
|
+
$: any;
|
|
113
88
|
};
|
|
114
89
|
/**
|
|
115
90
|
* Structural type for matching Reference without triggering full class evaluation.
|
|
@@ -122,7 +97,7 @@ type LoadedCollectionShape<T = any> = CollectionShape<T> & {
|
|
|
122
97
|
* - With inference: `T extends ReferenceShape<infer U>`
|
|
123
98
|
*/
|
|
124
99
|
type ReferenceShape<T = any> = {
|
|
125
|
-
|
|
100
|
+
unwrap(): T;
|
|
126
101
|
};
|
|
127
102
|
/**
|
|
128
103
|
* Structural type for matching LoadedReference (Reference with `$` property).
|
|
@@ -131,7 +106,7 @@ type ReferenceShape<T = any> = {
|
|
|
131
106
|
* We infer T from $ to get the full Loaded type for EntityDTO.
|
|
132
107
|
*/
|
|
133
108
|
type LoadedReferenceShape<T = any> = ReferenceShape & {
|
|
134
|
-
|
|
109
|
+
$: T;
|
|
135
110
|
};
|
|
136
111
|
/**
|
|
137
112
|
* Structural type for matching any loadable relation (Collection, Reference, or array).
|
|
@@ -148,22 +123,12 @@ type IsUnion<T, U = T> = T extends any ? ([U] extends [T] ? false : true) : fals
|
|
|
148
123
|
* Merges all members of a union type into a single object with all their properties.
|
|
149
124
|
* For non-union types, returns `T` directly to avoid expensive key iteration.
|
|
150
125
|
*/
|
|
151
|
-
export type MergeUnion<T> = [T] extends [object]
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
: IsUnion<T> extends true
|
|
155
|
-
? {
|
|
156
|
-
[K in UnionKeys<T>]: UnionPropertyType<T, K>;
|
|
157
|
-
}
|
|
158
|
-
: T
|
|
159
|
-
: T;
|
|
126
|
+
export type MergeUnion<T> = [T] extends [object] ? T extends Scalar ? T : IsUnion<T> extends true ? {
|
|
127
|
+
[K in UnionKeys<T>]: UnionPropertyType<T, K>;
|
|
128
|
+
} : T : T;
|
|
160
129
|
/** Recursively makes all properties of `T` optional, including nested objects and arrays. */
|
|
161
130
|
export type DeepPartial<T> = T & {
|
|
162
|
-
|
|
163
|
-
? DeepPartial<U>[]
|
|
164
|
-
: T[P] extends Readonly<infer U>[]
|
|
165
|
-
? Readonly<DeepPartial<U>>[]
|
|
166
|
-
: DeepPartial<T[P]>;
|
|
131
|
+
[P in keyof T]?: T[P] extends (infer U)[] ? DeepPartial<U>[] : T[P] extends Readonly<infer U>[] ? Readonly<DeepPartial<U>>[] : DeepPartial<T[P]>;
|
|
167
132
|
};
|
|
168
133
|
/** Symbol used to declare a custom repository type on an entity class (e.g., `[EntityRepositoryType]?: BookRepository`). */
|
|
169
134
|
export declare const EntityRepositoryType: unique symbol;
|
|
@@ -181,22 +146,18 @@ export declare const Config: unique symbol;
|
|
|
181
146
|
export declare const EntityName: unique symbol;
|
|
182
147
|
/** Extracts the entity name string literal from an entity type that declares `[EntityName]`. */
|
|
183
148
|
export type InferEntityName<T> = T extends {
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
? Name extends string
|
|
187
|
-
? Name
|
|
188
|
-
: never
|
|
189
|
-
: never;
|
|
149
|
+
[EntityName]?: infer Name;
|
|
150
|
+
} ? (Name extends string ? Name : never) : never;
|
|
190
151
|
/**
|
|
191
152
|
* Branded type that marks a property as optional in `em.create()`.
|
|
192
153
|
* Use as a property type wrapper: `createdAt: Opt<Date>` instead of listing in `[OptionalProps]`.
|
|
193
154
|
*/
|
|
194
155
|
export type Opt<T = unknown> = T & Opt.Brand;
|
|
195
156
|
export declare namespace Opt {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
157
|
+
const __optional: unique symbol;
|
|
158
|
+
interface Brand {
|
|
159
|
+
[__optional]?: 1;
|
|
160
|
+
}
|
|
200
161
|
}
|
|
201
162
|
/**
|
|
202
163
|
* Branded type that marks a nullable property as required in `em.create()`.
|
|
@@ -204,10 +165,10 @@ export declare namespace Opt {
|
|
|
204
165
|
*/
|
|
205
166
|
export type RequiredNullable<T = never> = (T & RequiredNullable.Brand) | null;
|
|
206
167
|
export declare namespace RequiredNullable {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
168
|
+
const __requiredNullable: unique symbol;
|
|
169
|
+
interface Brand {
|
|
170
|
+
[__requiredNullable]?: 1;
|
|
171
|
+
}
|
|
211
172
|
}
|
|
212
173
|
/**
|
|
213
174
|
* Branded type that marks a property as hidden from serialization.
|
|
@@ -215,10 +176,10 @@ export declare namespace RequiredNullable {
|
|
|
215
176
|
*/
|
|
216
177
|
export type Hidden<T = unknown> = T & Hidden.Brand;
|
|
217
178
|
export declare namespace Hidden {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
179
|
+
const __hidden: unique symbol;
|
|
180
|
+
interface Brand {
|
|
181
|
+
[__hidden]?: 1;
|
|
182
|
+
}
|
|
222
183
|
}
|
|
223
184
|
/**
|
|
224
185
|
* Branded type for entity-level configuration (e.g., `[Config]?: DefineConfig<{ forceObject: true }>`).
|
|
@@ -226,16 +187,16 @@ export declare namespace Hidden {
|
|
|
226
187
|
*/
|
|
227
188
|
export type DefineConfig<T extends TypeConfig> = T & DefineConfig.Brand;
|
|
228
189
|
export declare namespace DefineConfig {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
190
|
+
const __config: unique symbol;
|
|
191
|
+
interface Brand {
|
|
192
|
+
[__config]?: 1;
|
|
193
|
+
}
|
|
233
194
|
}
|
|
234
195
|
/** Extracts only the `TypeConfig` keys from a branded config type, stripping the brand. */
|
|
235
196
|
export type CleanTypeConfig<T> = Compute<Pick<T, Extract<keyof T, keyof TypeConfig>>>;
|
|
236
197
|
/** Configuration options that can be set on an entity via the `[Config]` symbol. */
|
|
237
198
|
export interface TypeConfig {
|
|
238
|
-
|
|
199
|
+
forceObject?: boolean;
|
|
239
200
|
}
|
|
240
201
|
declare const __selectedType: unique symbol;
|
|
241
202
|
declare const __loadedType: unique symbol;
|
|
@@ -247,186 +208,116 @@ declare const __fieldsHint: unique symbol;
|
|
|
247
208
|
* This reflects that loading 'a.b.c' means 'a' and 'a.b' are also loaded.
|
|
248
209
|
* Special case: '*' returns string to ensure Loaded<T, '*'> is assignable to any Loaded<T, Hint>.
|
|
249
210
|
*/
|
|
250
|
-
export type Prefixes<S extends string> = S extends '*'
|
|
251
|
-
? string
|
|
252
|
-
: S extends `${infer H}.${infer T}`
|
|
253
|
-
? H | `${H}.${Prefixes<T>}`
|
|
254
|
-
: S;
|
|
211
|
+
export type Prefixes<S extends string> = S extends '*' ? string : S extends `${infer H}.${infer T}` ? H | `${H}.${Prefixes<T>}` : S;
|
|
255
212
|
/** Unwraps a value to its primary key type. Scalars pass through; References are unwrapped first. */
|
|
256
213
|
export type UnwrapPrimary<T> = T extends Scalar ? T : T extends ReferenceShape<infer U> ? Primary<U> : Primary<T>;
|
|
257
214
|
type PrimaryPropToType<T, Keys extends (keyof T)[]> = {
|
|
258
|
-
|
|
215
|
+
[Index in keyof Keys]: UnwrapPrimary<T[Keys[Index]]>;
|
|
259
216
|
};
|
|
260
217
|
type ReadonlyPrimary<T> = T extends any[] ? Readonly<T> : T;
|
|
261
218
|
/**
|
|
262
219
|
* Resolves the primary key type for an entity. Uses `[PrimaryKeyProp]` if declared,
|
|
263
220
|
* otherwise falls back to `_id`, `id`, or `uuid` properties. For composite keys, returns a tuple.
|
|
264
221
|
*/
|
|
265
|
-
export type Primary<T> =
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
? ReadonlyPrimary<UnwrapPrimary<T[PK]>>
|
|
275
|
-
: PK extends (keyof T)[]
|
|
276
|
-
? ReadonlyPrimary<PrimaryPropToType<T, PK>>
|
|
277
|
-
: PK
|
|
278
|
-
: T extends {
|
|
279
|
-
_id?: infer PK;
|
|
280
|
-
}
|
|
281
|
-
? ReadonlyPrimary<PK> | string
|
|
282
|
-
: T extends {
|
|
283
|
-
id?: infer PK;
|
|
284
|
-
}
|
|
285
|
-
? ReadonlyPrimary<PK>
|
|
286
|
-
: T extends {
|
|
287
|
-
uuid?: infer PK;
|
|
288
|
-
}
|
|
289
|
-
? ReadonlyPrimary<PK>
|
|
290
|
-
: T;
|
|
222
|
+
export type Primary<T> = IsAny<T> extends true ? any : T extends {
|
|
223
|
+
[PrimaryKeyProp]?: infer PK;
|
|
224
|
+
} ? 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 {
|
|
225
|
+
_id?: infer PK;
|
|
226
|
+
} ? ReadonlyPrimary<PK> | string : T extends {
|
|
227
|
+
id?: infer PK;
|
|
228
|
+
} ? ReadonlyPrimary<PK> : T extends {
|
|
229
|
+
uuid?: infer PK;
|
|
230
|
+
} ? ReadonlyPrimary<PK> : T;
|
|
291
231
|
/** @internal */
|
|
292
232
|
export type PrimaryProperty<T> = T extends {
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
? T extends {
|
|
304
|
-
id?: any;
|
|
305
|
-
}
|
|
306
|
-
? 'id' | '_id'
|
|
307
|
-
: '_id'
|
|
308
|
-
: T extends {
|
|
309
|
-
id?: any;
|
|
310
|
-
}
|
|
311
|
-
? 'id'
|
|
312
|
-
: T extends {
|
|
313
|
-
uuid?: any;
|
|
314
|
-
}
|
|
315
|
-
? 'uuid'
|
|
316
|
-
: never;
|
|
233
|
+
[PrimaryKeyProp]?: infer PK;
|
|
234
|
+
} ? PK extends keyof T ? PK : PK extends any[] ? PK[number] : never : T extends {
|
|
235
|
+
_id?: any;
|
|
236
|
+
} ? T extends {
|
|
237
|
+
id?: any;
|
|
238
|
+
} ? 'id' | '_id' : '_id' : T extends {
|
|
239
|
+
id?: any;
|
|
240
|
+
} ? 'id' : T extends {
|
|
241
|
+
uuid?: any;
|
|
242
|
+
} ? 'uuid' : never;
|
|
317
243
|
/** Union of all allowed primary key value types (number, string, bigint, Date, ObjectId-like). */
|
|
318
|
-
export type IPrimaryKeyValue =
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
| bigint
|
|
322
|
-
| Date
|
|
323
|
-
| {
|
|
324
|
-
toHexString(): string;
|
|
325
|
-
};
|
|
244
|
+
export type IPrimaryKeyValue = number | string | bigint | Date | {
|
|
245
|
+
toHexString(): string;
|
|
246
|
+
};
|
|
326
247
|
/** Alias for a primary key value, constrained to `IPrimaryKeyValue`. */
|
|
327
248
|
export type IPrimaryKey<T extends IPrimaryKeyValue = IPrimaryKeyValue> = T;
|
|
328
249
|
/** Union of types considered "scalar" (non-entity) values. Used to distinguish entity relations from plain values. */
|
|
329
|
-
export type Scalar =
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
| string
|
|
333
|
-
| bigint
|
|
334
|
-
| symbol
|
|
335
|
-
| Date
|
|
336
|
-
| RegExp
|
|
337
|
-
| Uint8Array
|
|
338
|
-
| {
|
|
339
|
-
toHexString(): string;
|
|
340
|
-
};
|
|
250
|
+
export type Scalar = boolean | number | string | bigint | symbol | Date | RegExp | Uint8Array | {
|
|
251
|
+
toHexString(): string;
|
|
252
|
+
};
|
|
341
253
|
type Primitive = boolean | number | string | bigint | symbol;
|
|
342
254
|
/** Expands a scalar type to include alternative representations accepted in queries (e.g., `Date | string`). */
|
|
343
|
-
export type ExpandScalar<T> =
|
|
344
|
-
| null
|
|
345
|
-
| (T extends string ? T | RegExp : T extends Date ? Date | string : T extends bigint ? bigint | string | number : T);
|
|
255
|
+
export type ExpandScalar<T> = null | (T extends string ? T | RegExp : T extends Date ? Date | string : T extends bigint ? bigint | string | number : T);
|
|
346
256
|
/** Marker interface for query builders that can be used as subqueries */
|
|
347
257
|
export interface Subquery {
|
|
348
|
-
|
|
258
|
+
readonly __subquery: true;
|
|
349
259
|
}
|
|
350
260
|
/** Map of query operators (`$eq`, `$gt`, `$in`, etc.) available for filtering a value of type `T`. */
|
|
351
261
|
export type OperatorMap<T> = {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
| number
|
|
364
|
-
| {
|
|
262
|
+
$and?: ExpandQuery<T>[];
|
|
263
|
+
$or?: ExpandQuery<T>[];
|
|
264
|
+
$eq?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
|
|
265
|
+
$ne?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
|
|
266
|
+
$in?: readonly ExpandScalar<T>[] | readonly Primary<T>[] | Raw | Subquery;
|
|
267
|
+
$nin?: readonly ExpandScalar<T>[] | readonly Primary<T>[] | Raw | Subquery;
|
|
268
|
+
$not?: ExpandQuery<T>;
|
|
269
|
+
$none?: ExpandQuery<T>;
|
|
270
|
+
$some?: ExpandQuery<T>;
|
|
271
|
+
$every?: ExpandQuery<T>;
|
|
272
|
+
$size?: number | {
|
|
365
273
|
$eq?: number;
|
|
366
274
|
$ne?: number;
|
|
367
275
|
$gt?: number;
|
|
368
276
|
$gte?: number;
|
|
369
277
|
$lt?: number;
|
|
370
278
|
$lte?: number;
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
279
|
+
};
|
|
280
|
+
$gt?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
|
|
281
|
+
$gte?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
|
|
282
|
+
$lt?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
|
|
283
|
+
$lte?: ExpandScalar<T> | readonly ExpandScalar<T>[] | Subquery;
|
|
284
|
+
$like?: string;
|
|
285
|
+
$re?: string;
|
|
286
|
+
$ilike?: string;
|
|
287
|
+
$fulltext?: string;
|
|
288
|
+
$overlap?: readonly string[] | string | object;
|
|
289
|
+
$contains?: readonly string[] | string | object;
|
|
290
|
+
$contained?: readonly string[] | string | object;
|
|
291
|
+
$exists?: boolean;
|
|
292
|
+
$hasKey?: string;
|
|
293
|
+
$hasKeys?: readonly string[];
|
|
294
|
+
$hasSomeKeys?: readonly string[];
|
|
387
295
|
};
|
|
388
296
|
/** A single filter value: the raw value, its expanded scalar form, its primary key, or a raw SQL expression. */
|
|
389
297
|
export type FilterItemValue<T> = T | ExpandScalar<T> | Primary<T> | Raw;
|
|
390
298
|
/** A complete filter value: an operator map, a single value, an array of values, or null. */
|
|
391
299
|
export type FilterValue<T> = OperatorMap<FilterItemValue<T>> | FilterItemValue<T> | FilterItemValue<T>[] | null;
|
|
392
|
-
type FilterObjectProp<T, K extends PropertyKey> = K extends keyof MergeUnion<T>
|
|
393
|
-
|
|
394
|
-
: K extends keyof T
|
|
395
|
-
? T[K]
|
|
396
|
-
: never;
|
|
397
|
-
type ExpandQueryMerged<T> = [T] extends [object]
|
|
398
|
-
? [T] extends [Scalar]
|
|
399
|
-
? never
|
|
400
|
-
: FilterQuery<MergeUnion<T>>
|
|
401
|
-
: FilterValue<T>;
|
|
300
|
+
type FilterObjectProp<T, K extends PropertyKey> = K extends keyof MergeUnion<T> ? MergeUnion<T>[K] : K extends keyof T ? T[K] : never;
|
|
301
|
+
type ExpandQueryMerged<T> = [T] extends [object] ? [T] extends [Scalar] ? never : FilterQuery<MergeUnion<T>> : FilterValue<T>;
|
|
402
302
|
type ElemMatchCondition<T extends Record<string, any>> = {
|
|
403
|
-
|
|
303
|
+
[K in keyof T]?: T[K] | OperatorMap<T[K]>;
|
|
404
304
|
} & {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
305
|
+
$or?: ElemMatchCondition<T>[];
|
|
306
|
+
$and?: ElemMatchCondition<T>[];
|
|
307
|
+
$not?: ElemMatchCondition<T>;
|
|
408
308
|
};
|
|
409
|
-
type ElemMatchFilter<T> = T extends readonly (infer E)[]
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
$elemMatch: ElemMatchCondition<E>;
|
|
413
|
-
}
|
|
414
|
-
: never
|
|
415
|
-
: never;
|
|
309
|
+
type ElemMatchFilter<T> = T extends readonly (infer E)[] ? E extends Record<string, any> ? {
|
|
310
|
+
$elemMatch: ElemMatchCondition<E>;
|
|
311
|
+
} : never : never;
|
|
416
312
|
/** Object form of a filter query, mapping entity keys to their filter conditions. */
|
|
417
313
|
export type FilterObject<T> = {
|
|
418
|
-
|
|
419
|
-
| ExpandQuery<ExpandProperty<FilterObjectProp<T, K>>>
|
|
420
|
-
| ExpandQueryMerged<ExpandProperty<FilterObjectProp<T, K>>>
|
|
421
|
-
| FilterValue<ExpandProperty<FilterObjectProp<T, K>>>
|
|
422
|
-
| ElemMatchFilter<FilterObjectProp<T, K>>
|
|
423
|
-
| null;
|
|
314
|
+
-readonly [K in EntityKey<T>]?: ExpandQuery<ExpandProperty<FilterObjectProp<T, K>>> | ExpandQueryMerged<ExpandProperty<FilterObjectProp<T, K>>> | FilterValue<ExpandProperty<FilterObjectProp<T, K>>> | ElemMatchFilter<FilterObjectProp<T, K>> | null;
|
|
424
315
|
};
|
|
425
316
|
/** Recursively expands a type into its `FilterQuery` form for nested object filtering. */
|
|
426
317
|
export type ExpandQuery<T> = T extends object ? (T extends Scalar ? never : FilterQuery<T>) : FilterValue<T>;
|
|
427
318
|
/** Partial entity shape with all entity properties optional. */
|
|
428
319
|
export type EntityProps<T> = {
|
|
429
|
-
|
|
320
|
+
-readonly [K in EntityKey<T>]?: T[K];
|
|
430
321
|
};
|
|
431
322
|
/** Object-based query filter combining operator maps with property-level filters. */
|
|
432
323
|
export type ObjectQuery<T> = OperatorMap<T> & FilterObject<T>;
|
|
@@ -434,107 +325,72 @@ export type ObjectQuery<T> = OperatorMap<T> & FilterObject<T>;
|
|
|
434
325
|
* The main query filter type used in `em.find()`, `em.findOne()`, etc.
|
|
435
326
|
* Accepts an object query, a primary key value, entity props with operators, or an array of filters.
|
|
436
327
|
*/
|
|
437
|
-
export type FilterQuery<T> =
|
|
438
|
-
| ObjectQuery<T>
|
|
439
|
-
| NonNullable<ExpandScalar<Primary<T>>>
|
|
440
|
-
| NonNullable<EntityProps<T> & OperatorMap<T>>
|
|
441
|
-
| FilterQuery<T>[];
|
|
328
|
+
export type FilterQuery<T> = ObjectQuery<T> | NonNullable<ExpandScalar<Primary<T>>> | NonNullable<EntityProps<T> & OperatorMap<T>> | FilterQuery<T>[];
|
|
442
329
|
/** Public interface for the entity wrapper, accessible via `wrap(entity)`. Provides helper methods for entity state management. */
|
|
443
330
|
export interface IWrappedEntity<Entity extends object> {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
serialize<
|
|
461
|
-
Naked extends FromEntityType<Entity> = FromEntityType<Entity>,
|
|
462
|
-
Hint extends string = never,
|
|
463
|
-
Exclude extends string = never,
|
|
464
|
-
>(
|
|
465
|
-
options?: SerializeOptions<Naked, Hint, Exclude>,
|
|
466
|
-
): SerializeDTO<Naked, Hint, Exclude>;
|
|
467
|
-
setSerializationContext<Hint extends string = never, Fields extends string = never, Exclude extends string = never>(
|
|
468
|
-
options: LoadHint<Entity, Hint, Fields, Exclude>,
|
|
469
|
-
): void;
|
|
470
|
-
assign<
|
|
471
|
-
Naked extends FromEntityType<Entity> = FromEntityType<Entity>,
|
|
472
|
-
Convert extends boolean = false,
|
|
473
|
-
Data extends EntityData<Naked, Convert> | Partial<EntityDTO<Naked>> =
|
|
474
|
-
| EntityData<Naked, Convert>
|
|
475
|
-
| Partial<EntityDTO<Naked>>,
|
|
476
|
-
>(
|
|
477
|
-
data: Data & IsSubset<EntityData<Naked, Convert>, Data>,
|
|
478
|
-
options?: AssignOptions<Convert>,
|
|
479
|
-
): MergeSelected<Entity, Naked, keyof Data & string>;
|
|
480
|
-
getSchema(): string | undefined;
|
|
481
|
-
setSchema(schema?: string): void;
|
|
331
|
+
isInitialized(): boolean;
|
|
332
|
+
isManaged(): boolean;
|
|
333
|
+
populated(populated?: boolean): void;
|
|
334
|
+
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>>;
|
|
335
|
+
init<Hint extends string = never, Fields extends string = never, Exclude extends string = never>(options?: FindOneOptions<Entity, Hint, Fields, Exclude>): Promise<Loaded<Entity, Hint, Fields, Exclude> | null>;
|
|
336
|
+
toReference(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
|
|
337
|
+
toObject(): EntityDTO<Entity>;
|
|
338
|
+
toObject(ignoreFields: never[]): EntityDTO<Entity>;
|
|
339
|
+
toObject<Ignored extends EntityKey<Entity>>(ignoreFields: Ignored[]): Omit<EntityDTO<Entity>, Ignored>;
|
|
340
|
+
toJSON(...args: any[]): EntityDTO<Entity>;
|
|
341
|
+
toPOJO(): EntityDTO<Entity>;
|
|
342
|
+
serialize<Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Naked, Hint, Exclude>): SerializeDTO<Naked, Hint, Exclude>;
|
|
343
|
+
setSerializationContext<Hint extends string = never, Fields extends string = never, Exclude extends string = never>(options: LoadHint<Entity, Hint, Fields, Exclude>): void;
|
|
344
|
+
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>;
|
|
345
|
+
getSchema(): string | undefined;
|
|
346
|
+
setSchema(schema?: string): void;
|
|
482
347
|
}
|
|
483
348
|
/** @internal Extended wrapper interface with internal state used by the ORM runtime. */
|
|
484
349
|
export interface IWrappedEntityInternal<Entity extends object> extends IWrappedEntity<Entity> {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
350
|
+
hasPrimaryKey(): boolean;
|
|
351
|
+
getPrimaryKey(convertCustomTypes?: boolean): Primary<Entity> | null;
|
|
352
|
+
getPrimaryKeys(convertCustomTypes?: boolean): Primary<Entity>[] | null;
|
|
353
|
+
setPrimaryKey(val: Primary<Entity>): void;
|
|
354
|
+
getSerializedPrimaryKey(): string & keyof Entity;
|
|
355
|
+
__meta: EntityMetadata<Entity>;
|
|
356
|
+
__data: Dictionary;
|
|
357
|
+
__em?: EntityManager;
|
|
358
|
+
__platform: Platform;
|
|
359
|
+
__config: Configuration;
|
|
360
|
+
__factory: EntityFactory;
|
|
361
|
+
__hydrator: IHydrator;
|
|
362
|
+
__initialized: boolean;
|
|
363
|
+
__originalEntityData?: EntityData<Entity>;
|
|
364
|
+
__loadedProperties: Set<string>;
|
|
365
|
+
__identifier?: EntityIdentifier | EntityIdentifier[];
|
|
366
|
+
__managed: boolean;
|
|
367
|
+
__processing: boolean;
|
|
368
|
+
__schema?: string;
|
|
369
|
+
__populated: boolean;
|
|
370
|
+
__onLoadFired: boolean;
|
|
371
|
+
__reference?: Ref<Entity>;
|
|
372
|
+
__pk?: Primary<Entity>;
|
|
373
|
+
__primaryKeys: Primary<Entity>[];
|
|
374
|
+
__serializationContext: {
|
|
375
|
+
root?: SerializationContext<Entity>;
|
|
376
|
+
populate?: PopulateOptions<Entity>[];
|
|
377
|
+
fields?: Set<string>;
|
|
378
|
+
exclude?: string[];
|
|
379
|
+
};
|
|
515
380
|
}
|
|
516
381
|
/** Loose entity type used in generic contexts. Equivalent to `Partial<T>`. */
|
|
517
382
|
export type AnyEntity<T = any> = Partial<T>;
|
|
518
383
|
/** A class (function with prototype) whose instances are of type `T`. */
|
|
519
384
|
export type EntityClass<T = any> = Function & {
|
|
520
|
-
|
|
385
|
+
prototype: T;
|
|
521
386
|
};
|
|
522
387
|
/** Any valid entity name reference: a class, abstract constructor, or EntitySchema. */
|
|
523
388
|
export type EntityName<T = any> = EntityClass<T> | EntityCtor<T> | EntitySchema<T, any>;
|
|
524
389
|
/** Resolves the custom repository type for an entity (from `[EntityRepositoryType]`), or falls back to `Fallback`. */
|
|
525
|
-
export type GetRepository<
|
|
526
|
-
Entity extends {
|
|
390
|
+
export type GetRepository<Entity extends {
|
|
527
391
|
[k: PropertyKey]: any;
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
> = Entity[typeof EntityRepositoryType] extends EntityRepository<any> | undefined
|
|
531
|
-
? NonNullable<Entity[typeof EntityRepositoryType]>
|
|
532
|
-
: Fallback;
|
|
533
|
-
type PolymorphicPrimaryInner<T> = T extends object
|
|
534
|
-
? Primary<T> extends readonly [infer First, infer Second, ...infer Rest]
|
|
535
|
-
? readonly [string, First, Second, ...Rest] | [string, First, Second, ...Rest]
|
|
536
|
-
: readonly [string, Primary<T>] | [string, Primary<T>]
|
|
537
|
-
: never;
|
|
392
|
+
}, Fallback> = Entity[typeof EntityRepositoryType] extends EntityRepository<any> | undefined ? NonNullable<Entity[typeof EntityRepositoryType]> : Fallback;
|
|
393
|
+
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;
|
|
538
394
|
/**
|
|
539
395
|
* Tuple format for polymorphic FK values: [discriminator, ...pkValues]
|
|
540
396
|
* Distributes over unions, so `Post | Comment` becomes `['post', number] | ['comment', number]`
|
|
@@ -543,126 +399,52 @@ type PolymorphicPrimaryInner<T> = T extends object
|
|
|
543
399
|
export type PolymorphicPrimary<T> = true extends IsUnion<T> ? PolymorphicPrimaryInner<T> : never;
|
|
544
400
|
/** Allowed value types when assigning to an entity data property: the entity itself, its PK, or a polymorphic PK tuple. */
|
|
545
401
|
export type EntityDataPropValue<T> = T | Primary<T> | PolymorphicPrimary<T>;
|
|
546
|
-
type ExpandEntityProp<T, C extends boolean = false> =
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
[K in keyof T as CleanKeys<T, K>]?:
|
|
551
|
-
| EntityDataProp<ExpandProperty<T[K]>, C>
|
|
552
|
-
| EntityDataPropValue<ExpandProperty<T[K]>>
|
|
553
|
-
| null;
|
|
554
|
-
}
|
|
555
|
-
| EntityDataPropValue<ExpandProperty<T>>
|
|
556
|
-
: T;
|
|
557
|
-
type ExpandRequiredEntityProp<T, I, C extends boolean> =
|
|
558
|
-
T extends Record<string, any> ? ExpandRequiredEntityPropObject<T, I, C> | EntityDataPropValue<ExpandProperty<T>> : T;
|
|
402
|
+
type ExpandEntityProp<T, C extends boolean = false> = T extends Record<string, any> ? {
|
|
403
|
+
[K in keyof T as CleanKeys<T, K>]?: EntityDataProp<ExpandProperty<T[K]>, C> | EntityDataPropValue<ExpandProperty<T[K]>> | null;
|
|
404
|
+
} | EntityDataPropValue<ExpandProperty<T>> : T;
|
|
405
|
+
type ExpandRequiredEntityProp<T, I, C extends boolean> = T extends Record<string, any> ? ExpandRequiredEntityPropObject<T, I, C> | EntityDataPropValue<ExpandProperty<T>> : T;
|
|
559
406
|
type ExpandRequiredEntityPropObject<T, I = never, C extends boolean = false> = {
|
|
560
|
-
|
|
561
|
-
| RequiredEntityDataProp<ExpandProperty<T[K]>, T, C>
|
|
562
|
-
| EntityDataPropValue<ExpandProperty<T[K]>>;
|
|
407
|
+
[K in keyof T as RequiredKeys<T, K, I>]: RequiredEntityDataProp<ExpandProperty<T[K]>, T, C> | EntityDataPropValue<ExpandProperty<T[K]>>;
|
|
563
408
|
} & {
|
|
564
|
-
|
|
565
|
-
| RequiredEntityDataProp<ExpandProperty<T[K]>, T, C>
|
|
566
|
-
| EntityDataPropValue<ExpandProperty<T[K]>>
|
|
567
|
-
| null
|
|
568
|
-
| undefined;
|
|
409
|
+
[K in keyof T as OptionalKeys<T, K, I>]?: RequiredEntityDataProp<ExpandProperty<T[K]>, T, C> | EntityDataPropValue<ExpandProperty<T[K]>> | null | undefined;
|
|
569
410
|
};
|
|
570
411
|
type NonArrayObject = object & {
|
|
571
|
-
|
|
412
|
+
[Symbol.iterator]?: never;
|
|
572
413
|
};
|
|
573
414
|
/** Resolves the allowed input type for a single entity property in `EntityData`. Handles scalars, references, collections, and nested entities. */
|
|
574
|
-
export type EntityDataProp<T, C extends boolean> = T extends Date
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
: T extends ScalarReference<infer U>
|
|
579
|
-
? EntityDataProp<U, C>
|
|
580
|
-
: T extends {
|
|
581
|
-
__runtime?: infer Runtime;
|
|
582
|
-
__raw?: infer Raw;
|
|
583
|
-
}
|
|
584
|
-
? C extends true
|
|
585
|
-
? Raw
|
|
586
|
-
: Runtime
|
|
587
|
-
: T extends ReferenceShape<infer U>
|
|
588
|
-
? EntityDataNested<U, C>
|
|
589
|
-
: T extends CollectionShape<infer U>
|
|
590
|
-
? U | U[] | EntityDataNested<U & object, C> | EntityDataNested<U & object, C>[]
|
|
591
|
-
: T extends readonly (infer U)[]
|
|
592
|
-
? U extends NonArrayObject
|
|
593
|
-
? U | U[] | EntityDataNested<U, C> | EntityDataNested<U, C>[]
|
|
594
|
-
: U[] | EntityDataNested<U, C>[]
|
|
595
|
-
: EntityDataNested<T, C>;
|
|
415
|
+
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 {
|
|
416
|
+
__runtime?: infer Runtime;
|
|
417
|
+
__raw?: infer Raw;
|
|
418
|
+
} ? 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>;
|
|
596
419
|
/** Like `EntityDataProp` but used in `RequiredEntityData` context with required/optional key distinction. */
|
|
597
|
-
export type RequiredEntityDataProp<T, O, C extends boolean> = T extends Date
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
: T extends Scalar
|
|
602
|
-
? T
|
|
603
|
-
: T extends ScalarReference<infer U>
|
|
604
|
-
? RequiredEntityDataProp<U, O, C>
|
|
605
|
-
: T extends {
|
|
606
|
-
__runtime?: infer Runtime;
|
|
607
|
-
__raw?: infer Raw;
|
|
608
|
-
}
|
|
609
|
-
? C extends true
|
|
610
|
-
? Raw
|
|
611
|
-
: Runtime
|
|
612
|
-
: T extends ReferenceShape<infer U>
|
|
613
|
-
? RequiredEntityDataNested<U, O, C>
|
|
614
|
-
: T extends CollectionShape<infer U>
|
|
615
|
-
? U | U[] | RequiredEntityDataNested<U & object, O, C> | RequiredEntityDataNested<U & object, O, C>[]
|
|
616
|
-
: T extends readonly (infer U)[]
|
|
617
|
-
? U extends NonArrayObject
|
|
618
|
-
? U | U[] | RequiredEntityDataNested<U, O, C> | RequiredEntityDataNested<U, O, C>[]
|
|
619
|
-
: U[] | RequiredEntityDataNested<U, O, C>[]
|
|
620
|
-
: RequiredEntityDataNested<T, O, C>;
|
|
420
|
+
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 {
|
|
421
|
+
__runtime?: infer Runtime;
|
|
422
|
+
__raw?: infer Raw;
|
|
423
|
+
} ? 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>;
|
|
621
424
|
/** Nested entity data shape for embedded or related entities within `EntityData`. */
|
|
622
|
-
export type EntityDataNested<T, C extends boolean = false> = T extends undefined
|
|
623
|
-
? never
|
|
624
|
-
: T extends any[]
|
|
625
|
-
? Readonly<T>
|
|
626
|
-
: EntityData<T, C> | ExpandEntityProp<T, C>;
|
|
425
|
+
export type EntityDataNested<T, C extends boolean = false> = T extends undefined ? never : T extends any[] ? Readonly<T> : EntityData<T, C> | ExpandEntityProp<T, C>;
|
|
627
426
|
type UnwrapScalarRef<T> = T extends ScalarReference<infer U> ? U : T;
|
|
628
|
-
type EntityDataItem<T, C extends boolean> = C extends false
|
|
629
|
-
? UnwrapScalarRef<T> | EntityDataProp<T, C> | Raw | null
|
|
630
|
-
: EntityDataProp<T, C> | Raw | null;
|
|
427
|
+
type EntityDataItem<T, C extends boolean> = C extends false ? UnwrapScalarRef<T> | EntityDataProp<T, C> | Raw | null : EntityDataProp<T, C> | Raw | null;
|
|
631
428
|
/** Nested entity data shape used within `RequiredEntityData` for embedded or related entities. */
|
|
632
|
-
export type RequiredEntityDataNested<T, O, C extends boolean> = T extends any[]
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
}
|
|
639
|
-
? K
|
|
640
|
-
: never)
|
|
641
|
-
| ({
|
|
642
|
-
[K in keyof T]: T[K] extends Opt ? K : never;
|
|
643
|
-
}[keyof T] & {});
|
|
429
|
+
export type RequiredEntityDataNested<T, O, C extends boolean> = T extends any[] ? Readonly<T> : RequiredEntityData<T, O> | ExpandRequiredEntityProp<T, O, C>;
|
|
430
|
+
type ExplicitlyOptionalProps<T> = (T extends {
|
|
431
|
+
[OptionalProps]?: infer K;
|
|
432
|
+
} ? K : never) | ({
|
|
433
|
+
[K in keyof T]: T[K] extends Opt ? K : never;
|
|
434
|
+
}[keyof T] & {});
|
|
644
435
|
type NullableKeys<T, V = null> = {
|
|
645
|
-
|
|
436
|
+
[K in keyof T]: unknown extends T[K] ? never : V extends T[K] ? K : never;
|
|
646
437
|
}[keyof T];
|
|
647
438
|
type RequiredNullableKeys<T> = {
|
|
648
|
-
|
|
439
|
+
[K in keyof T]: Exclude<T[K], null> extends RequiredNullable.Brand ? K : never;
|
|
649
440
|
}[keyof T];
|
|
650
|
-
type ProbablyOptionalProps<T> =
|
|
651
|
-
|
|
652
|
-
| ExplicitlyOptionalProps<T>
|
|
653
|
-
| Exclude<NonNullable<NullableKeys<T, null | undefined>>, RequiredNullableKeys<T>>;
|
|
654
|
-
type IsOptional<T, K extends keyof T, I> = T[K] extends CollectionShape
|
|
655
|
-
? true
|
|
656
|
-
: ExtractType<T[K]> extends I
|
|
657
|
-
? true
|
|
658
|
-
: K extends ProbablyOptionalProps<T>
|
|
659
|
-
? true
|
|
660
|
-
: false;
|
|
441
|
+
type ProbablyOptionalProps<T> = PrimaryProperty<T> | ExplicitlyOptionalProps<T> | Exclude<NonNullable<NullableKeys<T, null | undefined>>, RequiredNullableKeys<T>>;
|
|
442
|
+
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;
|
|
661
443
|
type RequiredKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? CleanKeys<T, K> : never;
|
|
662
444
|
type OptionalKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? never : CleanKeys<T, K>;
|
|
663
445
|
/** Data shape for creating or updating entities. All properties are optional. Used in `em.create()` and `em.assign()`. */
|
|
664
446
|
export type EntityData<T, C extends boolean = false> = {
|
|
665
|
-
|
|
447
|
+
[K in EntityKey<T>]?: EntityDataItem<T[K] & {}, C>;
|
|
666
448
|
};
|
|
667
449
|
/**
|
|
668
450
|
* Data shape for `em.create()` with required/optional distinction based on entity metadata.
|
|
@@ -670,130 +452,64 @@ export type EntityData<T, C extends boolean = false> = {
|
|
|
670
452
|
* `I` excludes additional types from being required (used for inverse side of relations).
|
|
671
453
|
*/
|
|
672
454
|
export type RequiredEntityData<T, I = never, C extends boolean = false> = {
|
|
673
|
-
|
|
674
|
-
| T[K]
|
|
675
|
-
| RequiredEntityDataProp<T[K], T, C>
|
|
676
|
-
| Primary<T[K]>
|
|
677
|
-
| PolymorphicPrimary<T[K]>
|
|
678
|
-
| Raw;
|
|
455
|
+
[K in keyof T as RequiredKeys<T, K, I>]: T[K] | RequiredEntityDataProp<T[K], T, C> | Primary<T[K]> | PolymorphicPrimary<T[K]> | Raw;
|
|
679
456
|
} & {
|
|
680
|
-
|
|
681
|
-
| T[K]
|
|
682
|
-
| RequiredEntityDataProp<T[K], T, C>
|
|
683
|
-
| Primary<T[K]>
|
|
684
|
-
| PolymorphicPrimary<T[K]>
|
|
685
|
-
| Raw
|
|
686
|
-
| null;
|
|
457
|
+
[K in keyof T as OptionalKeys<T, K, I>]?: T[K] | RequiredEntityDataProp<T[K], T, C> | Primary<T[K]> | PolymorphicPrimary<T[K]> | Raw | null;
|
|
687
458
|
};
|
|
688
459
|
/** `EntityData<T>` extended with an index signature, allowing arbitrary additional properties. */
|
|
689
460
|
export type EntityDictionary<T> = EntityData<T> & Record<any, any>;
|
|
690
461
|
type ExtractEagerProps<T> = T extends {
|
|
691
|
-
|
|
692
|
-
}
|
|
693
|
-
? PK
|
|
694
|
-
: never;
|
|
462
|
+
[EagerProps]?: infer PK;
|
|
463
|
+
} ? PK : never;
|
|
695
464
|
type Relation<T> = {
|
|
696
|
-
|
|
465
|
+
[P in keyof T as T[P] extends unknown[] | Record<string | number | symbol, unknown> ? P : never]?: T[P];
|
|
697
466
|
};
|
|
698
467
|
/** Identity type that can be used to get around issues with cycles in bidirectional relations. It will disable reflect-metadata inference. */
|
|
699
468
|
export type Rel<T> = T;
|
|
700
469
|
/** Alias for `ScalarReference` (see {@apilink Ref}). */
|
|
701
470
|
export type ScalarRef<T> = ScalarReference<T>;
|
|
702
471
|
/** Alias for `Reference<T> & { id: number }` (see {@apilink Ref}). */
|
|
703
|
-
export type EntityRef<T extends object> =
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
: IsAny<T> extends true
|
|
707
|
-
? Reference<T>
|
|
708
|
-
: {
|
|
709
|
-
[K in PrimaryProperty<T> & keyof T]: T[K];
|
|
710
|
-
} & Reference<T>;
|
|
472
|
+
export type EntityRef<T extends object> = true extends IsUnknown<PrimaryProperty<T>> ? Reference<T> : IsAny<T> extends true ? Reference<T> : {
|
|
473
|
+
[K in PrimaryProperty<T> & keyof T]: T[K];
|
|
474
|
+
} & Reference<T>;
|
|
711
475
|
/**
|
|
712
476
|
* Ref type represents a `Reference` instance, and adds the primary keys to its prototype automatically, so you can do
|
|
713
477
|
* `ref.id` instead of `ref.unwrap().id`. It resolves to either `ScalarRef` or `EntityRef`, based on the type argument.
|
|
714
478
|
*/
|
|
715
|
-
export type Ref<T> = T extends any
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
: never;
|
|
722
|
-
type ExtractHiddenProps<T> =
|
|
723
|
-
| (T extends {
|
|
724
|
-
[HiddenProps]?: infer K;
|
|
725
|
-
}
|
|
726
|
-
? K
|
|
727
|
-
: never)
|
|
728
|
-
| ({
|
|
729
|
-
[K in keyof T]: T[K] extends Primitive ? (T[K] extends Hidden ? K : never) : never;
|
|
730
|
-
}[keyof T] & {});
|
|
479
|
+
export type Ref<T> = T extends any ? IsAny<T> extends true ? Reference<T & object> : T extends Scalar ? ScalarReference<T> : EntityRef<T & object> : never;
|
|
480
|
+
type ExtractHiddenProps<T> = (T extends {
|
|
481
|
+
[HiddenProps]?: infer K;
|
|
482
|
+
} ? K : never) | ({
|
|
483
|
+
[K in keyof T]: T[K] extends Primitive ? (T[K] extends Hidden ? K : never) : never;
|
|
484
|
+
}[keyof T] & {});
|
|
731
485
|
type ExcludeHidden<T, K extends keyof T> = K extends ExtractHiddenProps<T> ? never : K;
|
|
732
486
|
type ExtractConfig<T> = T extends {
|
|
733
|
-
|
|
734
|
-
}
|
|
735
|
-
? K & TypeConfig
|
|
736
|
-
: TypeConfig;
|
|
487
|
+
[Config]?: infer K;
|
|
488
|
+
} ? K & TypeConfig : TypeConfig;
|
|
737
489
|
type PreferExplicitConfig<E, I> = IsNever<E, I, E>;
|
|
738
|
-
type PrimaryOrObject<T, U, C extends TypeConfig> = PreferExplicitConfig<C, ExtractConfig<T>>['forceObject'] extends true
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
: Primary<U>;
|
|
743
|
-
type DTOWrapper<T, C extends TypeConfig, Flat extends boolean> = Flat extends true
|
|
744
|
-
? EntityDTOFlat<T, C>
|
|
745
|
-
: EntityDTO<T, C>;
|
|
490
|
+
type PrimaryOrObject<T, U, C extends TypeConfig> = PreferExplicitConfig<C, ExtractConfig<T>>['forceObject'] extends true ? {
|
|
491
|
+
[K in PrimaryProperty<U> & keyof U]: U[K];
|
|
492
|
+
} : Primary<U>;
|
|
493
|
+
type DTOWrapper<T, C extends TypeConfig, Flat extends boolean> = Flat extends true ? EntityDTOFlat<T, C> : EntityDTO<T, C>;
|
|
746
494
|
/** Resolves the serialized (DTO) type for a single entity property. Unwraps references, collections, and custom serialized types. */
|
|
747
|
-
export type EntityDTOProp<E, T, C extends TypeConfig = never, Flat extends boolean = false> = T extends Scalar
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
? U
|
|
751
|
-
: T extends {
|
|
752
|
-
__serialized?: infer U;
|
|
753
|
-
}
|
|
754
|
-
? IsUnknown<U> extends false
|
|
755
|
-
? U
|
|
756
|
-
: T
|
|
757
|
-
: T extends LoadedReferenceShape<infer U>
|
|
758
|
-
? DTOWrapper<U, C, Flat>
|
|
759
|
-
: T extends ReferenceShape<infer U>
|
|
760
|
-
? PrimaryOrObject<E, U, C>
|
|
761
|
-
: T extends LoadedCollectionShape<infer U>
|
|
762
|
-
? DTOWrapper<U & object, C, Flat>[]
|
|
763
|
-
: T extends CollectionShape<infer U>
|
|
764
|
-
? PrimaryOrObject<E, U & object, C>[]
|
|
765
|
-
: T extends readonly (infer U)[]
|
|
766
|
-
? U extends Scalar
|
|
767
|
-
? T
|
|
768
|
-
: EntityDTOProp<E, U, C, Flat>[]
|
|
769
|
-
: T extends Relation<T>
|
|
770
|
-
? DTOWrapper<T, C, Flat>
|
|
771
|
-
: T;
|
|
495
|
+
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 {
|
|
496
|
+
__serialized?: infer U;
|
|
497
|
+
} ? 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;
|
|
772
498
|
type UnwrapLoadedEntity<T> = T extends {
|
|
773
|
-
|
|
774
|
-
}
|
|
775
|
-
? NonNullable<U>
|
|
776
|
-
: T;
|
|
499
|
+
[__loadedType]?: infer U;
|
|
500
|
+
} ? NonNullable<U> : T;
|
|
777
501
|
type DTOProbablyOptionalProps<T> = NonNullable<NullableKeys<UnwrapLoadedEntity<T>, undefined>>;
|
|
778
|
-
type DTOIsOptional<T, K extends keyof T> = T[K] extends LoadedCollectionShape
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
? false
|
|
782
|
-
: K extends DTOProbablyOptionalProps<T>
|
|
783
|
-
? true
|
|
784
|
-
: false;
|
|
785
|
-
type DTORequiredKeys<T, K extends keyof T> =
|
|
786
|
-
DTOIsOptional<T, K> extends false ? ExcludeHidden<T, K> & CleanKeys<T, K> : never;
|
|
787
|
-
type DTOOptionalKeys<T, K extends keyof T> =
|
|
788
|
-
DTOIsOptional<T, K> extends false ? never : ExcludeHidden<T, K> & CleanKeys<T, K>;
|
|
502
|
+
type DTOIsOptional<T, K extends keyof T> = T[K] extends LoadedCollectionShape ? false : K extends PrimaryProperty<UnwrapLoadedEntity<T>> ? false : K extends DTOProbablyOptionalProps<T> ? true : false;
|
|
503
|
+
type DTORequiredKeys<T, K extends keyof T> = DTOIsOptional<T, K> extends false ? ExcludeHidden<T, K> & CleanKeys<T, K> : never;
|
|
504
|
+
type DTOOptionalKeys<T, K extends keyof T> = DTOIsOptional<T, K> extends false ? never : ExcludeHidden<T, K> & CleanKeys<T, K>;
|
|
789
505
|
/**
|
|
790
506
|
* Plain object (DTO) representation of an entity as returned by `toObject()` / `toPOJO()`.
|
|
791
507
|
* Unwraps references to PKs, collections to arrays, and respects hidden properties.
|
|
792
508
|
*/
|
|
793
509
|
export type EntityDTO<T, C extends TypeConfig = never> = {
|
|
794
|
-
|
|
510
|
+
[K in keyof T as DTORequiredKeys<T, K>]: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
|
|
795
511
|
} & {
|
|
796
|
-
|
|
512
|
+
[K in keyof T as DTOOptionalKeys<T, K>]?: EntityDTOProp<T, T[K], C> | AddOptional<T[K]>;
|
|
797
513
|
};
|
|
798
514
|
/**
|
|
799
515
|
* @internal
|
|
@@ -803,7 +519,7 @@ export type EntityDTO<T, C extends TypeConfig = never> = {
|
|
|
803
519
|
* function parameter type where generic assignability checks are needed.
|
|
804
520
|
*/
|
|
805
521
|
export type EntityDTOFlat<T, C extends TypeConfig = never> = {
|
|
806
|
-
|
|
522
|
+
[K in keyof T as ExcludeHidden<T, K> & CleanKeys<T, K>]: EntityDTOProp<T, T[K], C, true> | AddOptional<T[K]>;
|
|
807
523
|
};
|
|
808
524
|
/**
|
|
809
525
|
* @internal
|
|
@@ -812,81 +528,38 @@ export type EntityDTOFlat<T, C extends TypeConfig = never> = {
|
|
|
812
528
|
*/
|
|
813
529
|
type SerializeTopHints<H extends string> = H extends `${infer Top}.${string}` ? Top : H;
|
|
814
530
|
type SerializeSubHints<K extends string, H extends string> = H extends `${K}.${infer Rest}` ? Rest : never;
|
|
815
|
-
type SerializeSubFields<K extends string, F extends string> = K extends F
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
: F extends `${K & string}.${infer Rest}`
|
|
820
|
-
? Rest
|
|
821
|
-
: never;
|
|
822
|
-
type SerializeFieldsFilter<T, K extends keyof T, F extends string> = K extends Prefix<T, F> | PrimaryProperty<T>
|
|
823
|
-
? K
|
|
824
|
-
: never;
|
|
825
|
-
type SerializePropValue<T, K extends keyof T, H extends string, C extends TypeConfig = never> =
|
|
826
|
-
K & string extends SerializeTopHints<H>
|
|
827
|
-
? NonNullable<T[K]> extends CollectionShape<infer U>
|
|
828
|
-
? SerializeDTO<U & object, SerializeSubHints<K & string, H>, never, C>[]
|
|
829
|
-
: SerializeDTO<ExpandProperty<T[K]>, SerializeSubHints<K & string, H>, never, C> | Extract<T[K], null | undefined>
|
|
830
|
-
: EntityDTOProp<T, T[K], C>;
|
|
831
|
-
type SerializePropValueWithFields<T, K extends keyof T, H extends string, C extends TypeConfig, F extends string> =
|
|
832
|
-
K & string extends SerializeTopHints<H>
|
|
833
|
-
? NonNullable<T[K]> extends CollectionShape<infer U>
|
|
834
|
-
? SerializeDTO<U & object, SerializeSubHints<K & string, H>, never, C, SerializeSubFields<K & string, F>>[]
|
|
835
|
-
:
|
|
836
|
-
| SerializeDTO<
|
|
837
|
-
ExpandProperty<T[K]>,
|
|
838
|
-
SerializeSubHints<K & string, H>,
|
|
839
|
-
never,
|
|
840
|
-
C,
|
|
841
|
-
SerializeSubFields<K & string, F>
|
|
842
|
-
>
|
|
843
|
-
| Extract<T[K], null | undefined>
|
|
844
|
-
: EntityDTOProp<T, T[K], C>;
|
|
531
|
+
type SerializeSubFields<K extends string, F extends string> = K extends F ? '*' : [F extends `${K & string}.${infer Rest}` ? Rest : never] extends [never] ? '*' : F extends `${K & string}.${infer Rest}` ? Rest : never;
|
|
532
|
+
type SerializeFieldsFilter<T, K extends keyof T, F extends string> = K extends Prefix<T, F> | PrimaryProperty<T> ? K : never;
|
|
533
|
+
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>;
|
|
534
|
+
type SerializePropValueWithFields<T, K extends keyof T, H extends string, C extends TypeConfig, F extends string> = K & string extends SerializeTopHints<H> ? NonNullable<T[K]> extends CollectionShape<infer U> ? SerializeDTO<U & object, SerializeSubHints<K & string, H>, never, C, SerializeSubFields<K & string, F>>[] : SerializeDTO<ExpandProperty<T[K]>, SerializeSubHints<K & string, H>, never, C, SerializeSubFields<K & string, F>> | Extract<T[K], null | undefined> : EntityDTOProp<T, T[K], C>;
|
|
845
535
|
/**
|
|
846
536
|
* Return type of `serialize()`. Combines Loaded + EntityDTO in a single pass for better performance.
|
|
847
537
|
* Respects populate hints (`H`), exclude hints (`E`), and fields hints (`F`).
|
|
848
538
|
*/
|
|
849
|
-
export type SerializeDTO<
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
F extends string = '*',
|
|
855
|
-
> = string extends H
|
|
856
|
-
? EntityDTOFlat<T, C>
|
|
857
|
-
: [F] extends ['*']
|
|
858
|
-
? {
|
|
859
|
-
[K in keyof T as ExcludeHidden<T, K> & CleanKeys<T, K> & (IsNever<E> extends true ? K : Exclude<K, E>)]:
|
|
860
|
-
| SerializePropValue<T, K, H, C>
|
|
861
|
-
| Extract<T[K], null | undefined>;
|
|
862
|
-
}
|
|
863
|
-
: {
|
|
864
|
-
[K in keyof T as ExcludeHidden<T, K> &
|
|
865
|
-
CleanKeys<T, K> &
|
|
866
|
-
(IsNever<E> extends true ? K : Exclude<K, E>) &
|
|
867
|
-
SerializeFieldsFilter<T, K, F>]:
|
|
868
|
-
| SerializePropValueWithFields<T, K, H, C, F>
|
|
869
|
-
| Extract<T[K], null | undefined>;
|
|
870
|
-
};
|
|
539
|
+
export type SerializeDTO<T, H extends string = never, E extends string = never, C extends TypeConfig = never, F extends string = '*'> = string extends H ? EntityDTOFlat<T, C> : [F] extends ['*'] ? {
|
|
540
|
+
[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>;
|
|
541
|
+
} : {
|
|
542
|
+
[K in keyof T as ExcludeHidden<T, K> & CleanKeys<T, K> & (IsNever<E> extends true ? K : Exclude<K, E>) & SerializeFieldsFilter<T, K, F>]: SerializePropValueWithFields<T, K, H, C, F> | Extract<T[K], null | undefined>;
|
|
543
|
+
};
|
|
871
544
|
type TargetKeys<T> = T extends EntityClass<infer P> ? keyof P : keyof T;
|
|
872
545
|
type PropertyName<T> = IsUnknown<T> extends false ? TargetKeys<T> : string;
|
|
873
546
|
/** Table reference object passed to formula callbacks, including alias and schema information. */
|
|
874
547
|
export type FormulaTable = {
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
548
|
+
alias: string;
|
|
549
|
+
name: string;
|
|
550
|
+
schema?: string;
|
|
551
|
+
qualifiedName: string;
|
|
552
|
+
toString: () => string;
|
|
880
553
|
};
|
|
881
554
|
/**
|
|
882
555
|
* Table reference for schema callbacks (indexes, checks, generated columns).
|
|
883
556
|
* Unlike FormulaTable, this has no alias since schema generation doesn't use query aliases.
|
|
884
557
|
*/
|
|
885
558
|
export type SchemaTable = {
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
559
|
+
name: string;
|
|
560
|
+
schema?: string;
|
|
561
|
+
qualifiedName: string;
|
|
562
|
+
toString: () => string;
|
|
890
563
|
};
|
|
891
564
|
/**
|
|
892
565
|
* Column mapping for formula callbacks. Maps property names to fully-qualified alias.fieldName.
|
|
@@ -899,7 +572,7 @@ export type SchemaTable = {
|
|
|
899
572
|
* formula: cols => `${cols}.first_name || ' ' || ${cols}.last_name`
|
|
900
573
|
*/
|
|
901
574
|
export type FormulaColumns<T> = Record<PropertyName<T>, string> & {
|
|
902
|
-
|
|
575
|
+
toString(): string;
|
|
903
576
|
};
|
|
904
577
|
/**
|
|
905
578
|
* Column mapping for schema callbacks (indexes, checks, generated columns).
|
|
@@ -908,11 +581,7 @@ export type FormulaColumns<T> = Record<PropertyName<T>, string> & {
|
|
|
908
581
|
*/
|
|
909
582
|
export type SchemaColumns<T> = Record<PropertyName<T>, string>;
|
|
910
583
|
/** Callback for custom index expressions. Receives column mappings, table info, and the index name. */
|
|
911
|
-
export type IndexCallback<T> = (
|
|
912
|
-
columns: Record<PropertyName<T>, string>,
|
|
913
|
-
table: SchemaTable,
|
|
914
|
-
indexName: string,
|
|
915
|
-
) => string | Raw;
|
|
584
|
+
export type IndexCallback<T> = (columns: Record<PropertyName<T>, string>, table: SchemaTable, indexName: string) => string | Raw;
|
|
916
585
|
/** Callback for computed (formula) properties. Receives column mappings and table info, returns a SQL expression. */
|
|
917
586
|
export type FormulaCallback<T> = (columns: FormulaColumns<T>, table: FormulaTable) => string | Raw;
|
|
918
587
|
/** Callback for CHECK constraint expressions. Receives column mappings and table info. */
|
|
@@ -921,698 +590,580 @@ export type CheckCallback<T> = (columns: Record<PropertyName<T>, string>, table:
|
|
|
921
590
|
export type GeneratedColumnCallback<T> = (columns: Record<PropertyName<T>, string>, table: SchemaTable) => string | Raw;
|
|
922
591
|
/** Definition of a CHECK constraint on a table or property. */
|
|
923
592
|
export interface CheckConstraint<T = any> {
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
593
|
+
name?: string;
|
|
594
|
+
property?: string;
|
|
595
|
+
expression: string | Raw | CheckCallback<T>;
|
|
927
596
|
}
|
|
928
597
|
/** Branded string that accepts any string value while preserving autocompletion for known literals. */
|
|
929
598
|
export type AnyString = string & {};
|
|
930
599
|
/** Describes a single property (column, relation, or embedded) within an entity's metadata. */
|
|
931
600
|
export interface EntityProperty<Owner = any, Target = any> {
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
601
|
+
name: EntityKey<Owner>;
|
|
602
|
+
entity: () => EntityName<Owner>;
|
|
603
|
+
target: EntityClass<Target>;
|
|
604
|
+
type: keyof typeof types | AnyString;
|
|
605
|
+
runtimeType: 'number' | 'string' | 'boolean' | 'bigint' | 'Buffer' | 'Date' | 'object' | 'any' | AnyString;
|
|
606
|
+
targetMeta?: EntityMetadata<Target>;
|
|
607
|
+
columnTypes: string[];
|
|
608
|
+
generated?: string | Raw | GeneratedColumnCallback<Owner>;
|
|
609
|
+
customType?: Type<any>;
|
|
610
|
+
customTypes: (Type<any> | undefined)[];
|
|
611
|
+
hasConvertToJSValueSQL: boolean;
|
|
612
|
+
hasConvertToDatabaseValueSQL: boolean;
|
|
613
|
+
autoincrement?: boolean;
|
|
614
|
+
returning?: boolean;
|
|
615
|
+
primary?: boolean;
|
|
616
|
+
serializedPrimaryKey: boolean;
|
|
617
|
+
groups?: string[];
|
|
618
|
+
lazy?: boolean;
|
|
619
|
+
array?: boolean;
|
|
620
|
+
length?: number;
|
|
621
|
+
precision?: number;
|
|
622
|
+
scale?: number;
|
|
623
|
+
kind: ReferenceKind;
|
|
624
|
+
ref?: boolean;
|
|
625
|
+
fieldNames: string[];
|
|
626
|
+
fieldNameRaw?: string;
|
|
627
|
+
default?: string | number | boolean | null;
|
|
628
|
+
defaultRaw?: string;
|
|
629
|
+
formula?: FormulaCallback<Owner>;
|
|
630
|
+
filters?: FilterOptions;
|
|
631
|
+
prefix?: string | boolean;
|
|
632
|
+
prefixMode?: EmbeddedPrefixMode;
|
|
633
|
+
embedded?: [EntityKey<Owner>, EntityKey<Owner>];
|
|
634
|
+
embeddedPath?: string[];
|
|
635
|
+
embeddable: EntityClass<Owner>;
|
|
636
|
+
embeddedProps: Dictionary<EntityProperty>;
|
|
637
|
+
discriminatorColumn?: string;
|
|
638
|
+
discriminator?: string;
|
|
639
|
+
polymorphic?: boolean;
|
|
640
|
+
polymorphTargets?: EntityMetadata[];
|
|
641
|
+
discriminatorMap?: Dictionary<EntityClass<Target>>;
|
|
642
|
+
discriminatorValue?: string;
|
|
643
|
+
object?: boolean;
|
|
644
|
+
index?: boolean | string;
|
|
645
|
+
unique?: boolean | string;
|
|
646
|
+
nullable?: boolean;
|
|
647
|
+
inherited?: boolean;
|
|
648
|
+
renamedFrom?: string;
|
|
649
|
+
stiMerged?: boolean;
|
|
650
|
+
stiFieldNames?: string[];
|
|
651
|
+
stiFieldNameMap?: Dictionary<string>;
|
|
652
|
+
unsigned?: boolean;
|
|
653
|
+
mapToPk?: boolean;
|
|
654
|
+
persist?: boolean;
|
|
655
|
+
hydrate?: boolean;
|
|
656
|
+
hidden?: boolean;
|
|
657
|
+
enum?: boolean;
|
|
658
|
+
items?: (number | string)[];
|
|
659
|
+
nativeEnumName?: string;
|
|
660
|
+
version?: boolean;
|
|
661
|
+
concurrencyCheck?: boolean;
|
|
662
|
+
eager?: boolean;
|
|
663
|
+
setter?: boolean;
|
|
664
|
+
getter?: boolean;
|
|
665
|
+
getterName?: keyof Owner;
|
|
666
|
+
accessor?: EntityKey<Owner>;
|
|
667
|
+
cascade: Cascade[];
|
|
668
|
+
orphanRemoval?: boolean;
|
|
669
|
+
onCreate?: (entity: Owner, em: EntityManager) => any;
|
|
670
|
+
onUpdate?: (entity: Owner, em: EntityManager) => any;
|
|
671
|
+
deleteRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
|
|
672
|
+
updateRule?: 'cascade' | 'no action' | 'set null' | 'set default' | AnyString;
|
|
673
|
+
strategy?: LoadStrategy;
|
|
674
|
+
owner: boolean;
|
|
675
|
+
inversedBy: EntityKey<Target>;
|
|
676
|
+
mappedBy: EntityKey<Target>;
|
|
677
|
+
where?: FilterQuery<Target>;
|
|
678
|
+
orderBy?: QueryOrderMap<Owner> | QueryOrderMap<Owner>[];
|
|
679
|
+
customOrder?: string[] | number[] | boolean[];
|
|
680
|
+
fixedOrder?: boolean;
|
|
681
|
+
fixedOrderColumn?: string;
|
|
682
|
+
pivotTable: string;
|
|
683
|
+
pivotEntity: EntityClass<Target>;
|
|
684
|
+
joinColumns: string[];
|
|
685
|
+
ownColumns: string[];
|
|
686
|
+
inverseJoinColumns: string[];
|
|
687
|
+
referencedColumnNames: string[];
|
|
688
|
+
referencedTableName: string;
|
|
689
|
+
referencedPKs: EntityKey<Owner>[];
|
|
690
|
+
targetKey?: string;
|
|
691
|
+
serializer?: (value: any, options?: SerializeOptions<any>) => any;
|
|
692
|
+
serializedName?: string;
|
|
693
|
+
comment?: string;
|
|
694
|
+
/** mysql only */
|
|
695
|
+
extra?: string;
|
|
696
|
+
userDefined?: boolean;
|
|
697
|
+
optional?: boolean;
|
|
698
|
+
ignoreSchemaChanges?: ('type' | 'extra' | 'default')[];
|
|
699
|
+
deferMode?: DeferMode;
|
|
700
|
+
createForeignKeyConstraint: boolean;
|
|
701
|
+
foreignKeyName?: string;
|
|
1033
702
|
}
|
|
1034
703
|
/**
|
|
1035
704
|
* Runtime metadata for an entity, holding its properties, relations, indexes, hooks, and more.
|
|
1036
705
|
* Created during metadata discovery and used throughout the ORM lifecycle.
|
|
1037
706
|
*/
|
|
1038
707
|
export declare class EntityMetadata<Entity = any, Class extends EntityCtor<Entity> = EntityCtor<Entity>> {
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
private initIndexes;
|
|
1067
|
-
/** @internal */
|
|
1068
|
-
clone(): this;
|
|
708
|
+
private static counter;
|
|
709
|
+
readonly _id: number;
|
|
710
|
+
readonly propertyOrder: Map<string, number>;
|
|
711
|
+
constructor(meta?: Partial<EntityMetadata>);
|
|
712
|
+
addProperty(prop: Partial<EntityProperty<Entity>>): void;
|
|
713
|
+
removeProperty(name: string, sync?: boolean): void;
|
|
714
|
+
getPrimaryProps(flatten?: boolean): EntityProperty<Entity>[];
|
|
715
|
+
getPrimaryProp(): EntityProperty<Entity>;
|
|
716
|
+
/**
|
|
717
|
+
* Creates a mapping from property names to field names.
|
|
718
|
+
* @param alias - Optional alias to prefix field names. Can be a string (same for all) or a function (per-property).
|
|
719
|
+
* When provided, also adds toString() returning the alias for backwards compatibility with formulas.
|
|
720
|
+
* @param toStringAlias - Optional alias to return from toString(). Defaults to `alias` when it's a string.
|
|
721
|
+
*/
|
|
722
|
+
createColumnMappingObject(alias?: string | ((prop: EntityProperty<Entity>) => string), toStringAlias?: string): FormulaColumns<Entity>;
|
|
723
|
+
/**
|
|
724
|
+
* Creates a column mapping for schema callbacks (indexes, checks, generated columns).
|
|
725
|
+
* For TPT entities, only includes properties that belong to the current table (ownProps).
|
|
726
|
+
*/
|
|
727
|
+
createSchemaColumnMappingObject(): SchemaColumns<Entity>;
|
|
728
|
+
get tableName(): string;
|
|
729
|
+
set tableName(name: string);
|
|
730
|
+
get uniqueName(): string;
|
|
731
|
+
sync(initIndexes?: boolean, config?: Configuration): void;
|
|
732
|
+
private initIndexes;
|
|
733
|
+
/** @internal */
|
|
734
|
+
clone(): this;
|
|
1069
735
|
}
|
|
1070
736
|
/** Minimal column metadata with just a name and database type. */
|
|
1071
737
|
export interface SimpleColumnMeta {
|
|
1072
|
-
|
|
1073
|
-
|
|
738
|
+
name: string;
|
|
739
|
+
type: string;
|
|
1074
740
|
}
|
|
1075
741
|
/** Abstract constructor type that matches both abstract and concrete entity classes. */
|
|
1076
742
|
export type EntityCtor<T = any> = abstract new (...args: any[]) => T;
|
|
1077
743
|
export interface EntityMetadata<Entity = any, Class extends EntityCtor<Entity> = EntityCtor<Entity>> {
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
| boolean
|
|
1087
|
-
| {
|
|
744
|
+
name?: string;
|
|
745
|
+
className: string;
|
|
746
|
+
tableName: string;
|
|
747
|
+
schema?: string;
|
|
748
|
+
pivotTable?: boolean;
|
|
749
|
+
virtual?: boolean;
|
|
750
|
+
/** True if this entity represents a database view (not a virtual entity). Accepts `{ materialized: true }` as input, normalized to `true` during sync. */
|
|
751
|
+
view?: boolean | {
|
|
1088
752
|
materialized?: boolean;
|
|
1089
753
|
withData?: boolean;
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
|
1097
|
-
|
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
/**
|
|
1195
|
-
* Default ordering for this entity. Applied when querying this entity directly
|
|
1196
|
-
* or when it's populated as a relation. Combined with other orderings based on precedence.
|
|
1197
|
-
*/
|
|
1198
|
-
orderBy?: QueryOrderMap<Entity> | QueryOrderMap<Entity>[];
|
|
1199
|
-
/** @internal can be used for computed numeric cache keys */
|
|
1200
|
-
readonly _id: number;
|
|
754
|
+
};
|
|
755
|
+
/** True if this is a materialized view (PostgreSQL only). Requires `view: true`. */
|
|
756
|
+
materialized?: boolean;
|
|
757
|
+
/** For materialized views, whether data is populated on creation. Defaults to true. */
|
|
758
|
+
withData?: boolean;
|
|
759
|
+
expression?: string | ((em: any, where: ObjectQuery<Entity>, options: FindOptions<Entity, any, any, any>, stream?: boolean) => MaybePromise<Raw | object | string>);
|
|
760
|
+
discriminatorColumn?: EntityKey<Entity> | AnyString;
|
|
761
|
+
discriminatorValue?: number | string;
|
|
762
|
+
discriminatorMap?: Dictionary<EntityClass>;
|
|
763
|
+
embeddable: boolean;
|
|
764
|
+
constructorParams?: (keyof Entity)[];
|
|
765
|
+
forceConstructor: boolean;
|
|
766
|
+
extends?: EntityName<Entity>;
|
|
767
|
+
collection: string;
|
|
768
|
+
path: string;
|
|
769
|
+
primaryKeys: EntityKey<Entity>[];
|
|
770
|
+
simplePK: boolean;
|
|
771
|
+
compositePK: boolean;
|
|
772
|
+
versionProperty: EntityKey<Entity>;
|
|
773
|
+
concurrencyCheckKeys: Set<EntityKey<Entity>>;
|
|
774
|
+
serializedPrimaryKey?: EntityKey<Entity>;
|
|
775
|
+
properties: {
|
|
776
|
+
[K in EntityKey<Entity>]: EntityProperty<Entity>;
|
|
777
|
+
};
|
|
778
|
+
props: EntityProperty<Entity>[];
|
|
779
|
+
relations: EntityProperty<Entity>[];
|
|
780
|
+
bidirectionalRelations: EntityProperty<Entity>[];
|
|
781
|
+
referencingProperties: {
|
|
782
|
+
meta: EntityMetadata<Entity>;
|
|
783
|
+
prop: EntityProperty<Entity>;
|
|
784
|
+
}[];
|
|
785
|
+
comparableProps: EntityProperty<Entity>[];
|
|
786
|
+
trackingProps: EntityProperty<Entity>[];
|
|
787
|
+
hydrateProps: EntityProperty<Entity>[];
|
|
788
|
+
validateProps: EntityProperty<Entity>[];
|
|
789
|
+
uniqueProps: EntityProperty<Entity>[];
|
|
790
|
+
getterProps: EntityProperty<Entity>[];
|
|
791
|
+
indexes: {
|
|
792
|
+
properties?: EntityKey<Entity> | EntityKey<Entity>[];
|
|
793
|
+
name?: string;
|
|
794
|
+
type?: string;
|
|
795
|
+
options?: Dictionary;
|
|
796
|
+
expression?: string | IndexCallback<Entity>;
|
|
797
|
+
columns?: IndexColumnOptions[];
|
|
798
|
+
include?: EntityKey<Entity> | EntityKey<Entity>[];
|
|
799
|
+
fillFactor?: number;
|
|
800
|
+
invisible?: boolean;
|
|
801
|
+
disabled?: boolean;
|
|
802
|
+
clustered?: boolean;
|
|
803
|
+
}[];
|
|
804
|
+
uniques: {
|
|
805
|
+
properties?: EntityKey<Entity> | EntityKey<Entity>[];
|
|
806
|
+
name?: string;
|
|
807
|
+
options?: Dictionary;
|
|
808
|
+
expression?: string | IndexCallback<Entity>;
|
|
809
|
+
deferMode?: DeferMode | `${DeferMode}`;
|
|
810
|
+
columns?: IndexColumnOptions[];
|
|
811
|
+
include?: EntityKey<Entity> | EntityKey<Entity>[];
|
|
812
|
+
fillFactor?: number;
|
|
813
|
+
disabled?: boolean;
|
|
814
|
+
}[];
|
|
815
|
+
checks: CheckConstraint<Entity>[];
|
|
816
|
+
repositoryClass?: string;
|
|
817
|
+
repository: () => EntityClass<EntityRepository<any>>;
|
|
818
|
+
hooks: {
|
|
819
|
+
[K in EventType]?: (keyof Entity | EventSubscriber<Entity>[EventType])[];
|
|
820
|
+
};
|
|
821
|
+
prototype: Entity;
|
|
822
|
+
class: Class;
|
|
823
|
+
abstract: boolean;
|
|
824
|
+
filters: Dictionary<FilterDef>;
|
|
825
|
+
comment?: string;
|
|
826
|
+
selfReferencing?: boolean;
|
|
827
|
+
hasUniqueProps?: boolean;
|
|
828
|
+
readonly?: boolean;
|
|
829
|
+
polymorphs?: EntityMetadata[];
|
|
830
|
+
root: EntityMetadata<Entity>;
|
|
831
|
+
definedProperties: Dictionary;
|
|
832
|
+
/** For polymorphic M:N pivot tables, maps discriminator values to entity classes */
|
|
833
|
+
polymorphicDiscriminatorMap?: Dictionary<EntityClass>;
|
|
834
|
+
/** Inheritance type: 'sti' (Single Table Inheritance) or 'tpt' (Table-Per-Type). Only set on root entities. */
|
|
835
|
+
inheritanceType?: 'sti' | 'tpt';
|
|
836
|
+
/** For TPT: direct parent entity metadata (the entity this one extends). */
|
|
837
|
+
tptParent?: EntityMetadata;
|
|
838
|
+
/** For TPT: direct child entities (entities that extend this one). */
|
|
839
|
+
tptChildren?: EntityMetadata[];
|
|
840
|
+
/** For TPT: all non-abstract descendants, sorted by depth (deepest first). Precomputed during discovery. */
|
|
841
|
+
allTPTDescendants?: EntityMetadata[];
|
|
842
|
+
/** For TPT: synthetic property representing the join to the parent table (child PK → parent PK). */
|
|
843
|
+
tptParentProp?: EntityProperty;
|
|
844
|
+
/** For TPT: inverse of tptParentProp, used for joining from parent to child (parent PK → child PK). */
|
|
845
|
+
tptInverseProp?: EntityProperty;
|
|
846
|
+
/** For TPT: virtual discriminator property name (computed at query time, not persisted). */
|
|
847
|
+
tptDiscriminatorColumn?: string;
|
|
848
|
+
/** For TPT: properties defined only in THIS entity (not inherited from parent). */
|
|
849
|
+
ownProps?: EntityProperty<Entity>[];
|
|
850
|
+
hasTriggers?: boolean;
|
|
851
|
+
/**
|
|
852
|
+
* Default ordering for this entity. Applied when querying this entity directly
|
|
853
|
+
* or when it's populated as a relation. Combined with other orderings based on precedence.
|
|
854
|
+
*/
|
|
855
|
+
orderBy?: QueryOrderMap<Entity> | QueryOrderMap<Entity>[];
|
|
856
|
+
/** @internal can be used for computed numeric cache keys */
|
|
857
|
+
readonly _id: number;
|
|
1201
858
|
}
|
|
1202
859
|
/** Options for `ISchemaGenerator.create()`. */
|
|
1203
860
|
export interface CreateSchemaOptions {
|
|
1204
|
-
|
|
1205
|
-
|
|
861
|
+
wrap?: boolean;
|
|
862
|
+
schema?: string;
|
|
1206
863
|
}
|
|
1207
864
|
/** Options for `ISchemaGenerator.clear()` to truncate/clear database tables. */
|
|
1208
865
|
export interface ClearDatabaseOptions {
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
866
|
+
schema?: string;
|
|
867
|
+
truncate?: boolean;
|
|
868
|
+
clearIdentityMap?: boolean;
|
|
1212
869
|
}
|
|
1213
870
|
/** Options for `ISchemaGenerator.ensureDatabase()` which creates and optionally clears the database. */
|
|
1214
871
|
export interface EnsureDatabaseOptions extends CreateSchemaOptions, ClearDatabaseOptions {
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
872
|
+
clear?: boolean;
|
|
873
|
+
create?: boolean;
|
|
874
|
+
forceCheck?: boolean;
|
|
1218
875
|
}
|
|
1219
876
|
/** Options for `ISchemaGenerator.drop()`. */
|
|
1220
877
|
export interface DropSchemaOptions {
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
878
|
+
wrap?: boolean;
|
|
879
|
+
dropMigrationsTable?: boolean;
|
|
880
|
+
dropForeignKeys?: boolean;
|
|
881
|
+
dropDb?: boolean;
|
|
882
|
+
schema?: string;
|
|
1226
883
|
}
|
|
1227
884
|
/** Options for `ISchemaGenerator.update()` to apply incremental schema changes. */
|
|
1228
885
|
export interface UpdateSchemaOptions<DatabaseSchema = unknown> {
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
886
|
+
wrap?: boolean;
|
|
887
|
+
safe?: boolean;
|
|
888
|
+
dropDb?: boolean;
|
|
889
|
+
dropTables?: boolean;
|
|
890
|
+
schema?: string;
|
|
891
|
+
fromSchema?: DatabaseSchema;
|
|
1235
892
|
}
|
|
1236
893
|
/** Options for `ISchemaGenerator.refresh()` which drops and recreates the schema. */
|
|
1237
894
|
export interface RefreshDatabaseOptions extends CreateSchemaOptions {
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
895
|
+
ensureIndexes?: boolean;
|
|
896
|
+
dropDb?: boolean;
|
|
897
|
+
createSchema?: boolean;
|
|
1241
898
|
}
|
|
1242
899
|
/** Interface for the schema generator, responsible for creating, updating, and dropping database schemas. */
|
|
1243
900
|
export interface ISchemaGenerator {
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
createDatabase(name?: string): Promise<void>;
|
|
1264
|
-
dropDatabase(name?: string): Promise<void>;
|
|
1265
|
-
ensureIndexes(): Promise<void>;
|
|
901
|
+
create(options?: CreateSchemaOptions): Promise<void>;
|
|
902
|
+
update(options?: UpdateSchemaOptions): Promise<void>;
|
|
903
|
+
drop(options?: DropSchemaOptions): Promise<void>;
|
|
904
|
+
refresh(options?: RefreshDatabaseOptions): Promise<void>;
|
|
905
|
+
clear(options?: ClearDatabaseOptions): Promise<void>;
|
|
906
|
+
execute(sql: string, options?: {
|
|
907
|
+
wrap?: boolean;
|
|
908
|
+
}): Promise<void>;
|
|
909
|
+
getCreateSchemaSQL(options?: CreateSchemaOptions): Promise<string>;
|
|
910
|
+
getDropSchemaSQL(options?: Omit<DropSchemaOptions, 'dropDb'>): Promise<string>;
|
|
911
|
+
getUpdateSchemaSQL(options?: UpdateSchemaOptions): Promise<string>;
|
|
912
|
+
getUpdateSchemaMigrationSQL(options?: UpdateSchemaOptions): Promise<{
|
|
913
|
+
up: string;
|
|
914
|
+
down: string;
|
|
915
|
+
}>;
|
|
916
|
+
ensureDatabase(options?: EnsureDatabaseOptions): Promise<boolean>;
|
|
917
|
+
createDatabase(name?: string): Promise<void>;
|
|
918
|
+
dropDatabase(name?: string): Promise<void>;
|
|
919
|
+
ensureIndexes(): Promise<void>;
|
|
1266
920
|
}
|
|
1267
921
|
/** Custom resolver for import paths in the entity generator. Returns a path/name pair or undefined to use the default. */
|
|
1268
|
-
export type ImportsResolver = (
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
originFileName: string,
|
|
1273
|
-
) =>
|
|
1274
|
-
| {
|
|
1275
|
-
path: string;
|
|
1276
|
-
name: string;
|
|
1277
|
-
}
|
|
1278
|
-
| undefined;
|
|
922
|
+
export type ImportsResolver = (alias: string, basePath: string, extension: '.js' | '', originFileName: string) => {
|
|
923
|
+
path: string;
|
|
924
|
+
name: string;
|
|
925
|
+
} | undefined;
|
|
1279
926
|
/** Options for the entity generator (`IEntityGenerator.generate()`). Controls output format, filtering, and style. */
|
|
1280
927
|
export interface GenerateOptions {
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
928
|
+
path?: string;
|
|
929
|
+
save?: boolean;
|
|
930
|
+
schema?: string;
|
|
931
|
+
takeTables?: (RegExp | string)[];
|
|
932
|
+
skipTables?: (RegExp | string)[];
|
|
933
|
+
skipColumns?: Dictionary<(RegExp | string)[]>;
|
|
934
|
+
forceUndefined?: boolean;
|
|
935
|
+
undefinedDefaults?: boolean;
|
|
936
|
+
bidirectionalRelations?: boolean;
|
|
937
|
+
identifiedReferences?: boolean;
|
|
938
|
+
entityDefinition?: 'decorators' | 'defineEntity' | 'entitySchema';
|
|
939
|
+
decorators?: 'es' | 'legacy';
|
|
940
|
+
inferEntityType?: boolean;
|
|
941
|
+
enumMode?: 'ts-enum' | 'union-type' | 'dictionary';
|
|
942
|
+
esmImport?: boolean;
|
|
943
|
+
scalarTypeInDecorator?: boolean;
|
|
944
|
+
scalarPropertiesForRelations?: 'always' | 'never' | 'smart';
|
|
945
|
+
fileName?: (className: string) => string;
|
|
946
|
+
onImport?: ImportsResolver;
|
|
947
|
+
extraImports?: (basePath: string, originFileName: string) => string[] | undefined;
|
|
948
|
+
onlyPurePivotTables?: boolean;
|
|
949
|
+
outputPurePivotTables?: boolean;
|
|
950
|
+
readOnlyPivotTables?: boolean;
|
|
951
|
+
customBaseEntityName?: string;
|
|
952
|
+
useCoreBaseEntity?: boolean;
|
|
953
|
+
coreImportsPrefix?: string;
|
|
954
|
+
onInitialMetadata?: MetadataProcessor;
|
|
955
|
+
onProcessedMetadata?: MetadataProcessor;
|
|
1309
956
|
}
|
|
1310
957
|
/** Interface for the entity generator, which reverse-engineers database schema into entity source files. */
|
|
1311
958
|
export interface IEntityGenerator {
|
|
1312
|
-
|
|
959
|
+
generate(options?: GenerateOptions): Promise<string[]>;
|
|
1313
960
|
}
|
|
1314
961
|
/** Basic migration descriptor with a name and optional file path. */
|
|
1315
962
|
export type MigrationInfo = {
|
|
1316
|
-
|
|
1317
|
-
|
|
963
|
+
name: string;
|
|
964
|
+
path?: string;
|
|
1318
965
|
};
|
|
1319
966
|
/** Options for controlling which migrations to run (range, specific list, or transaction). */
|
|
1320
967
|
export type MigrateOptions = {
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
968
|
+
from?: string | number;
|
|
969
|
+
to?: string | number;
|
|
970
|
+
migrations?: string[];
|
|
971
|
+
transaction?: Transaction;
|
|
1325
972
|
};
|
|
1326
973
|
/** Result of creating a new migration file, including the generated code and schema diff. */
|
|
1327
974
|
export type MigrationResult = {
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
975
|
+
fileName: string;
|
|
976
|
+
code: string;
|
|
977
|
+
diff: MigrationDiff;
|
|
1331
978
|
};
|
|
1332
979
|
/** A row from the migrations tracking table, representing an executed migration. */
|
|
1333
980
|
export type MigrationRow = {
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
981
|
+
id: number;
|
|
982
|
+
name: string;
|
|
983
|
+
executed_at: Date;
|
|
1337
984
|
};
|
|
1338
985
|
/**
|
|
1339
986
|
* @internal
|
|
1340
987
|
*/
|
|
1341
988
|
export interface IMigrationRunner {
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
989
|
+
run(migration: Migration, method: 'up' | 'down'): Promise<void>;
|
|
990
|
+
setMasterMigration(trx: Transaction): void;
|
|
991
|
+
unsetMasterMigration(): void;
|
|
1345
992
|
}
|
|
1346
993
|
/**
|
|
1347
994
|
* @internal
|
|
1348
995
|
*/
|
|
1349
996
|
export interface IMigratorStorage {
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
997
|
+
executed(): Promise<string[]>;
|
|
998
|
+
logMigration(params: Dictionary): Promise<void>;
|
|
999
|
+
unlogMigration(params: Dictionary): Promise<void>;
|
|
1000
|
+
getExecutedMigrations(): Promise<MigrationRow[]>;
|
|
1001
|
+
ensureTable?(): Promise<void>;
|
|
1002
|
+
setMasterMigration(trx: Transaction): void;
|
|
1003
|
+
unsetMasterMigration(): void;
|
|
1004
|
+
getMigrationName(name: string): string;
|
|
1005
|
+
getTableName?(): {
|
|
1006
|
+
schemaName?: string;
|
|
1007
|
+
tableName: string;
|
|
1008
|
+
};
|
|
1362
1009
|
}
|
|
1363
1010
|
/** Interface for the migrator, responsible for creating and executing database migrations. */
|
|
1364
1011
|
export interface IMigrator {
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1012
|
+
/**
|
|
1013
|
+
* Checks current schema for changes, generates new migration if there are any.
|
|
1014
|
+
*/
|
|
1015
|
+
create(path?: string, blank?: boolean, initial?: boolean, name?: string): Promise<MigrationResult>;
|
|
1016
|
+
/**
|
|
1017
|
+
* Checks current schema for changes.
|
|
1018
|
+
*/
|
|
1019
|
+
checkSchema(): Promise<boolean>;
|
|
1020
|
+
/**
|
|
1021
|
+
* Creates initial migration. This generates the schema based on metadata, and checks whether all the tables
|
|
1022
|
+
* are already present. If yes, it will also automatically log the migration as executed.
|
|
1023
|
+
* Initial migration can be created only if the schema is already aligned with the metadata, or when no schema
|
|
1024
|
+
* is present - in such case regular migration would have the same effect.
|
|
1025
|
+
*/
|
|
1026
|
+
createInitial(path?: string): Promise<MigrationResult>;
|
|
1027
|
+
/**
|
|
1028
|
+
* Returns list of already executed migrations.
|
|
1029
|
+
*/
|
|
1030
|
+
getExecuted(): Promise<MigrationRow[]>;
|
|
1031
|
+
/**
|
|
1032
|
+
* Returns list of pending (not yet executed) migrations found in the migration directory.
|
|
1033
|
+
*/
|
|
1034
|
+
getPending(): Promise<MigrationInfo[]>;
|
|
1035
|
+
/**
|
|
1036
|
+
* Executes specified migrations. Without parameter it will migrate up to the latest version.
|
|
1037
|
+
*/
|
|
1038
|
+
up(options?: string | string[] | MigrateOptions): Promise<MigrationInfo[]>;
|
|
1039
|
+
/**
|
|
1040
|
+
* Executes down migrations to the given point. Without parameter it will migrate one version down.
|
|
1041
|
+
*/
|
|
1042
|
+
down(options?: string | string[] | Omit<MigrateOptions, 'from'>): Promise<MigrationInfo[]>;
|
|
1043
|
+
/**
|
|
1044
|
+
* Registers event handler.
|
|
1045
|
+
*/
|
|
1046
|
+
on(event: MigratorEvent, listener: (event: MigrationInfo) => MaybePromise<void>): IMigrator;
|
|
1047
|
+
/**
|
|
1048
|
+
* Removes event handler.
|
|
1049
|
+
*/
|
|
1050
|
+
off(event: MigratorEvent, listener: (event: MigrationInfo) => MaybePromise<void>): IMigrator;
|
|
1051
|
+
/**
|
|
1052
|
+
* @internal
|
|
1053
|
+
*/
|
|
1054
|
+
getStorage(): IMigratorStorage;
|
|
1408
1055
|
}
|
|
1409
1056
|
/** Events emitted by the migrator during migration execution. */
|
|
1410
1057
|
export type MigratorEvent = 'migrating' | 'migrated' | 'reverting' | 'reverted';
|
|
1411
1058
|
/** The up and down SQL statements representing a schema diff for a migration. */
|
|
1412
1059
|
export interface MigrationDiff {
|
|
1413
|
-
|
|
1414
|
-
|
|
1060
|
+
up: string[];
|
|
1061
|
+
down: string[];
|
|
1415
1062
|
}
|
|
1416
1063
|
/** Interface for generating migration file contents from schema diffs. */
|
|
1417
1064
|
export interface IMigrationGenerator {
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1065
|
+
/**
|
|
1066
|
+
* Generates the full contents of migration file. Uses `generateMigrationFile` to get the file contents.
|
|
1067
|
+
*/
|
|
1068
|
+
generate(diff: MigrationDiff, path?: string, name?: string): Promise<[string, string]>;
|
|
1069
|
+
/**
|
|
1070
|
+
* Creates single migration statement. By default adds `this.addSql(sql);` to the code.
|
|
1071
|
+
*/
|
|
1072
|
+
createStatement(sql: string, padLeft: number): string;
|
|
1073
|
+
/**
|
|
1074
|
+
* Returns the file contents of given migration.
|
|
1075
|
+
*/
|
|
1076
|
+
generateMigrationFile(className: string, diff: MigrationDiff): MaybePromise<string>;
|
|
1430
1077
|
}
|
|
1431
1078
|
/** Interface that all migration classes must implement. */
|
|
1432
1079
|
export interface Migration {
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1080
|
+
up(): Promise<void> | void;
|
|
1081
|
+
down(): Promise<void> | void;
|
|
1082
|
+
isTransactional(): boolean;
|
|
1083
|
+
reset(): void;
|
|
1084
|
+
setTransactionContext(ctx: Transaction): void;
|
|
1085
|
+
getQueries?(): any[];
|
|
1439
1086
|
}
|
|
1440
1087
|
/** A named migration class reference, used for inline migration registration. */
|
|
1441
1088
|
export interface MigrationObject {
|
|
1442
|
-
|
|
1443
|
-
|
|
1089
|
+
name: string;
|
|
1090
|
+
class: Constructor<Migration>;
|
|
1444
1091
|
}
|
|
1445
1092
|
type EntityFromInput<T> = T extends readonly EntityName<infer U>[] ? U : T extends EntityName<infer U> ? U : never;
|
|
1446
1093
|
type FilterDefResolved<T extends object = any> = {
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
em: any,
|
|
1454
|
-
options?: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any>,
|
|
1455
|
-
entityName?: string,
|
|
1456
|
-
) => MaybePromise<FilterQuery<T>>);
|
|
1457
|
-
default?: boolean;
|
|
1458
|
-
entity?: EntityName<T> | EntityName<T>[];
|
|
1459
|
-
args?: boolean;
|
|
1460
|
-
strict?: boolean;
|
|
1094
|
+
name: string;
|
|
1095
|
+
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>>);
|
|
1096
|
+
default?: boolean;
|
|
1097
|
+
entity?: EntityName<T> | EntityName<T>[];
|
|
1098
|
+
args?: boolean;
|
|
1099
|
+
strict?: boolean;
|
|
1461
1100
|
};
|
|
1462
1101
|
/** Definition of a query filter that can be registered globally or per-entity via `@Filter()`. */
|
|
1463
1102
|
export type FilterDef<T extends EntityName | readonly EntityName[] = any> = FilterDefResolved<EntityFromInput<T>> & {
|
|
1464
|
-
|
|
1103
|
+
entity?: T;
|
|
1465
1104
|
};
|
|
1466
1105
|
/** Type for the `populate` option in find methods. An array of relation paths to eagerly load, or `false` to disable. */
|
|
1467
1106
|
export type Populate<T, P extends string = never> = readonly AutoPath<T, P, `${PopulatePath}`>[] | false;
|
|
1468
1107
|
/** Parsed populate hint for a single relation, including strategy and nested children. */
|
|
1469
1108
|
export type PopulateOptions<T> = {
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1109
|
+
field: EntityKey<T>;
|
|
1110
|
+
strategy?: LoadStrategy;
|
|
1111
|
+
all?: boolean;
|
|
1112
|
+
filter?: boolean;
|
|
1113
|
+
joinType?: 'inner join' | 'left join';
|
|
1114
|
+
children?: PopulateOptions<T[keyof T]>[];
|
|
1115
|
+
/** When true, ignores `mapToPk` on the property and returns full entity data instead of just PKs. */
|
|
1116
|
+
dataOnly?: boolean;
|
|
1478
1117
|
};
|
|
1479
1118
|
/** Inline options that can be appended to populate hint strings (e.g., strategy, join type). */
|
|
1480
1119
|
export type PopulateHintOptions = {
|
|
1481
|
-
|
|
1482
|
-
|
|
1120
|
+
strategy?: LoadStrategy.JOINED | LoadStrategy.SELECT_IN | 'joined' | 'select-in';
|
|
1121
|
+
joinType?: 'inner join' | 'left join';
|
|
1483
1122
|
};
|
|
1484
|
-
type ExtractType<T> =
|
|
1485
|
-
T extends CollectionShape<infer U>
|
|
1486
|
-
? U
|
|
1487
|
-
: T extends ReferenceShape<infer U>
|
|
1488
|
-
? U
|
|
1489
|
-
: T extends Ref<infer U>
|
|
1490
|
-
? U
|
|
1491
|
-
: T extends readonly (infer U)[]
|
|
1492
|
-
? U
|
|
1493
|
-
: T;
|
|
1123
|
+
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;
|
|
1494
1124
|
type ExtractStringKeys<T> = {
|
|
1495
|
-
|
|
1125
|
+
[K in keyof T]-?: CleanKeys<T, K>;
|
|
1496
1126
|
}[keyof T] & {};
|
|
1497
1127
|
/**
|
|
1498
1128
|
* Extracts string keys from an entity type, handling Collection/Reference wrappers.
|
|
1499
1129
|
* Simplified to just check `T extends object` since ExtractType handles the unwrapping.
|
|
1500
1130
|
*/
|
|
1501
1131
|
type StringKeys<T, E extends string = never> = T extends object ? ExtractStringKeys<ExtractType<T>> | E : never;
|
|
1502
|
-
type GetStringKey<T, K extends StringKeys<T, string>, E extends string> = K extends keyof T
|
|
1503
|
-
? ExtractType<T[K]>
|
|
1504
|
-
: K extends E
|
|
1505
|
-
? keyof T
|
|
1506
|
-
: never;
|
|
1132
|
+
type GetStringKey<T, K extends StringKeys<T, string>, E extends string> = K extends keyof T ? ExtractType<T[K]> : K extends E ? keyof T : never;
|
|
1507
1133
|
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
1508
|
-
type RelationKeys<T> = T extends object
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
}[keyof T] & {}
|
|
1512
|
-
: never;
|
|
1134
|
+
type RelationKeys<T> = T extends object ? {
|
|
1135
|
+
[K in keyof T]-?: CleanKeys<T, K, true>;
|
|
1136
|
+
}[keyof T] & {} : never;
|
|
1513
1137
|
/**
|
|
1514
1138
|
* Autocomplete-friendly type for dot-separated relation paths (e.g., `'author.books'`).
|
|
1515
1139
|
* Validates each segment against entity keys and provides IDE suggestions. Depth-limited to prevent infinite recursion.
|
|
1516
1140
|
*/
|
|
1517
|
-
export type AutoPath<
|
|
1518
|
-
O,
|
|
1519
|
-
P extends string | boolean,
|
|
1520
|
-
E extends string = never,
|
|
1521
|
-
D extends Prev[number] = 9,
|
|
1522
|
-
> = P extends boolean
|
|
1523
|
-
? P
|
|
1524
|
-
: [D] extends [never]
|
|
1525
|
-
? never
|
|
1526
|
-
: P extends any
|
|
1527
|
-
? P extends string
|
|
1528
|
-
? P extends `${infer A}.${infer B}`
|
|
1529
|
-
? A extends StringKeys<O, E>
|
|
1530
|
-
? `${A}.${AutoPath<NonNullable<GetStringKey<O, A, E>>, B, E, Prev[D]>}`
|
|
1531
|
-
: never
|
|
1532
|
-
: P extends StringKeys<O, E>
|
|
1533
|
-
?
|
|
1534
|
-
| (NonNullable<GetStringKey<O, P & StringKeys<O, E>, E>> extends unknown
|
|
1535
|
-
? Exclude<P, `${string}.`>
|
|
1536
|
-
: never)
|
|
1537
|
-
| (StringKeys<NonNullable<GetStringKey<O, P & StringKeys<O, E>, E>>, E> extends never
|
|
1538
|
-
? never
|
|
1539
|
-
: `${P & string}.`)
|
|
1540
|
-
: StringKeys<O, E> | `${RelationKeys<O>}:ref`
|
|
1541
|
-
: never
|
|
1542
|
-
: never;
|
|
1141
|
+
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;
|
|
1543
1142
|
/** Unwraps an array type to its element type; non-arrays pass through unchanged. */
|
|
1544
1143
|
export type UnboxArray<T> = T extends any[] ? ArrayElement<T> : T;
|
|
1545
1144
|
/** Extracts the element type from an array type. */
|
|
1546
1145
|
export type ArrayElement<ArrayType extends unknown[]> = ArrayType extends (infer ElementType)[] ? ElementType : never;
|
|
1547
1146
|
/** Unwraps a property type from its wrapper (Reference, Collection, or array) to the inner entity type. */
|
|
1548
|
-
export type ExpandProperty<T> =
|
|
1549
|
-
|
|
1550
|
-
? NonNullable<U>
|
|
1551
|
-
: T extends CollectionShape<infer U>
|
|
1552
|
-
? NonNullable<U>
|
|
1553
|
-
: T extends (infer U)[]
|
|
1554
|
-
? NonNullable<U>
|
|
1555
|
-
: NonNullable<T>;
|
|
1556
|
-
type LoadedLoadable<T, E extends object> = T extends CollectionShape
|
|
1557
|
-
? LoadedCollection<E>
|
|
1558
|
-
: T extends ScalarReference<infer U>
|
|
1559
|
-
? LoadedScalarReference<U>
|
|
1560
|
-
: T extends ReferenceShape
|
|
1561
|
-
? T & LoadedReference<E>
|
|
1562
|
-
: T extends Scalar
|
|
1563
|
-
? T
|
|
1564
|
-
: T extends (infer U)[]
|
|
1565
|
-
? U extends Scalar
|
|
1566
|
-
? T
|
|
1567
|
-
: E[]
|
|
1568
|
-
: E;
|
|
1147
|
+
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>;
|
|
1148
|
+
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;
|
|
1569
1149
|
type IsTrue<T> = IsNever<T> extends true ? false : T extends boolean ? (T extends true ? true : false) : false;
|
|
1570
1150
|
type StringLiteral<T> = T extends string ? (string extends T ? never : T) : never;
|
|
1571
1151
|
type Prefix<T, K> = K extends `${infer S}.${string}` ? S : K extends '*' ? keyof T : K;
|
|
1572
1152
|
type IsPrefixedExclude<T, K extends keyof T, E extends string> = K extends E ? never : K;
|
|
1573
1153
|
/** Checks whether a key `K` is included in the populate/fields hints. Used to filter entity keys in `Loaded`/`Selected`. */
|
|
1574
|
-
export type IsPrefixed<T, K extends keyof T, L extends string, E extends string = never> =
|
|
1575
|
-
|
|
1576
|
-
? IsPrefixedExclude<T, K, E>
|
|
1577
|
-
: K extends symbol
|
|
1578
|
-
? never
|
|
1579
|
-
: IsTrue<L> extends true
|
|
1580
|
-
? T[K] & {} extends LoadableShape
|
|
1581
|
-
? K
|
|
1582
|
-
: never
|
|
1583
|
-
: IsNever<StringLiteral<L>> extends true
|
|
1584
|
-
? never
|
|
1585
|
-
: '*' extends L
|
|
1586
|
-
? K
|
|
1587
|
-
: K extends Prefix<T, L>
|
|
1588
|
-
? K
|
|
1589
|
-
: K extends PrimaryProperty<T>
|
|
1590
|
-
? K
|
|
1591
|
-
: never;
|
|
1592
|
-
type Suffix<Key, Hint extends string, All = true | '*'> = Hint extends `${infer Pref}.${infer Suf}`
|
|
1593
|
-
? Pref extends Key
|
|
1594
|
-
? Suf
|
|
1595
|
-
: never
|
|
1596
|
-
: Hint extends All
|
|
1597
|
-
? Hint
|
|
1598
|
-
: never;
|
|
1154
|
+
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;
|
|
1155
|
+
type Suffix<Key, Hint extends string, All = true | '*'> = Hint extends `${infer Pref}.${infer Suf}` ? Pref extends Key ? Suf : never : Hint extends All ? Hint : never;
|
|
1599
1156
|
/** Validates that `U` is a subset of `T`. Returns `{}` if valid, or a mapped type with `never` values to cause a type error. */
|
|
1600
|
-
export type IsSubset<T, U> = keyof U extends keyof T
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
? {}
|
|
1604
|
-
: {
|
|
1605
|
-
[K in keyof U as K extends keyof T ? never : CleanKeys<U, K>]: never;
|
|
1606
|
-
};
|
|
1157
|
+
export type IsSubset<T, U> = keyof U extends keyof T ? {} : string extends keyof U ? {} : {
|
|
1158
|
+
[K in keyof U as K extends keyof T ? never : CleanKeys<U, K>]: never;
|
|
1159
|
+
};
|
|
1607
1160
|
/**
|
|
1608
1161
|
* Fast check if T is a Loaded type by looking for the marker symbol.
|
|
1609
1162
|
* This is much cheaper than matching against the full Loaded structure.
|
|
1610
1163
|
*/
|
|
1611
1164
|
type IsLoadedType<T> = T extends {
|
|
1612
|
-
|
|
1613
|
-
}
|
|
1614
|
-
? true
|
|
1615
|
-
: false;
|
|
1165
|
+
[__loadedType]?: any;
|
|
1166
|
+
} ? true : false;
|
|
1616
1167
|
/**
|
|
1617
1168
|
* Optimized MergeSelected using intersection instead of extraction.
|
|
1618
1169
|
* When T is already Loaded, we intersect with a new Loaded type for the selected fields.
|
|
@@ -1625,20 +1176,10 @@ export type MergeSelected<T, U, F extends string> = IsLoadedType<T> extends true
|
|
|
1625
1176
|
* This avoids the expensive pattern matching needed to extract hints from Loaded types.
|
|
1626
1177
|
* Used for `em.populate` and `em.refresh`.
|
|
1627
1178
|
*/
|
|
1628
|
-
export type MergeLoaded<T, U, P extends string, F extends string, E extends string, R extends boolean = false> =
|
|
1629
|
-
IsLoadedType<T> extends true ? T & Loaded<U, P, F, E> : Loaded<T, P, F, E>;
|
|
1179
|
+
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>;
|
|
1630
1180
|
/** Extracts the nullability modifiers (`null`, `undefined`, or both) from a type `T`. */
|
|
1631
|
-
export type AddOptional<T> = undefined | null extends T
|
|
1632
|
-
|
|
1633
|
-
: null extends T
|
|
1634
|
-
? null
|
|
1635
|
-
: undefined extends T
|
|
1636
|
-
? undefined
|
|
1637
|
-
: never;
|
|
1638
|
-
type LoadedProp<T, L extends string = never, F extends string = '*', E extends string = never> = LoadedLoadable<
|
|
1639
|
-
T,
|
|
1640
|
-
Loaded<ExtractType<T>, L, F, E>
|
|
1641
|
-
>;
|
|
1181
|
+
export type AddOptional<T> = undefined | null extends T ? null | undefined : null extends T ? null : undefined extends T ? undefined : never;
|
|
1182
|
+
type LoadedProp<T, L extends string = never, F extends string = '*', E extends string = never> = LoadedLoadable<T, Loaded<ExtractType<T>, L, F, E>>;
|
|
1642
1183
|
/** Extracts the eager-loaded property names declared via `[EagerProps]` as a string union. */
|
|
1643
1184
|
export type AddEager<T> = ExtractEagerProps<T> & string;
|
|
1644
1185
|
/** Combines an explicit populate hint `L` with the entity's eagerly loaded properties. */
|
|
@@ -1648,141 +1189,100 @@ export type ExpandHint<T, L extends string> = L | AddEager<T>;
|
|
|
1648
1189
|
* Used as the return type when `fields` option is specified in find methods.
|
|
1649
1190
|
*/
|
|
1650
1191
|
export type Selected<T, L extends string = never, F extends string = '*'> = {
|
|
1651
|
-
|
|
1652
|
-
? T[K]
|
|
1653
|
-
: NonNullable<T[K]> extends Scalar
|
|
1654
|
-
? T[K]
|
|
1655
|
-
: LoadedProp<NonNullable<T[K]>, Suffix<K, L, true>, Suffix<K, F, true>> | AddOptional<T[K]>;
|
|
1192
|
+
[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]>;
|
|
1656
1193
|
} & {
|
|
1657
|
-
|
|
1658
|
-
|
|
1194
|
+
[__selectedType]?: T;
|
|
1195
|
+
[__fieldsHint]?: (hint: F) => void;
|
|
1196
|
+
};
|
|
1197
|
+
type LoadedEntityType<T> = {
|
|
1198
|
+
[__loadedType]?: T;
|
|
1199
|
+
} | {
|
|
1200
|
+
[__selectedType]?: T;
|
|
1659
1201
|
};
|
|
1660
|
-
type LoadedEntityType<T> =
|
|
1661
|
-
| {
|
|
1662
|
-
[__loadedType]?: T;
|
|
1663
|
-
}
|
|
1664
|
-
| {
|
|
1665
|
-
[__selectedType]?: T;
|
|
1666
|
-
};
|
|
1667
1202
|
/** Accepts either a plain entity type or a `Loaded`/`Selected` wrapped version. */
|
|
1668
1203
|
export type EntityType<T> = T | LoadedEntityType<T>;
|
|
1669
1204
|
/** Extracts the base entity type from a `Loaded`/`Selected` wrapper, or returns `T` as-is. */
|
|
1670
1205
|
export type FromEntityType<T> = T extends LoadedEntityType<infer U> ? U : T;
|
|
1671
1206
|
/** Extracts the fields hint (`F`) from a `Loaded`/`Selected` type, or returns `'*'` (all fields) for unwrapped entities. */
|
|
1672
1207
|
export type ExtractFieldsHint<T> = T extends {
|
|
1673
|
-
|
|
1674
|
-
}
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
[K in keyof T as IsPrefixed<T, K, ExpandHint<T, L>>]:
|
|
1681
|
-
| LoadedProp<NonNullable<T[K]>, Suffix<K, L>, Suffix<K, F>, Suffix<K, E>>
|
|
1682
|
-
| AddOptional<T[K]>;
|
|
1683
|
-
}
|
|
1684
|
-
: {
|
|
1685
|
-
[K in keyof T as IsPrefixed<T, K, ExpandHint<T, L>, E>]:
|
|
1686
|
-
| LoadedProp<NonNullable<T[K]>, Suffix<K, L>, Suffix<K, F>, Suffix<K, E>>
|
|
1687
|
-
| AddOptional<T[K]>;
|
|
1688
|
-
}
|
|
1689
|
-
: Selected<T, L, F>;
|
|
1208
|
+
[__fieldsHint]?: (hint: infer F extends string) => void;
|
|
1209
|
+
} ? F : '*';
|
|
1210
|
+
type LoadedInternal<T, L extends string = never, F extends string = '*', E extends string = never> = [F] extends ['*'] ? IsNever<E> extends true ? T & {
|
|
1211
|
+
[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]>;
|
|
1212
|
+
} : {
|
|
1213
|
+
[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]>;
|
|
1214
|
+
} : Selected<T, L, F>;
|
|
1690
1215
|
/**
|
|
1691
1216
|
* Represents entity with its loaded relations (`populate` hint) and selected properties (`fields` hint).
|
|
1692
1217
|
* The __loadHint marker uses contravariance to ensure Loaded<A, 'b'> is NOT assignable to Loaded<A, 'b.c'>.
|
|
1693
1218
|
*/
|
|
1694
|
-
export type Loaded<T, L extends string = never, F extends string = '*', E extends string = never> = LoadedInternal<
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
F,
|
|
1698
|
-
E
|
|
1699
|
-
> & {
|
|
1700
|
-
[__loadedType]?: T;
|
|
1701
|
-
[__loadHint]?: (hint: Prefixes<L>) => void;
|
|
1219
|
+
export type Loaded<T, L extends string = never, F extends string = '*', E extends string = never> = LoadedInternal<T, L, F, E> & {
|
|
1220
|
+
[__loadedType]?: T;
|
|
1221
|
+
[__loadHint]?: (hint: Prefixes<L>) => void;
|
|
1702
1222
|
};
|
|
1703
1223
|
/** A `Reference<T>` that is guaranteed to be loaded, providing synchronous access via `$` and `get()`. */
|
|
1704
1224
|
export interface LoadedReference<T> extends Reference<NonNullable<T>> {
|
|
1705
|
-
|
|
1706
|
-
|
|
1225
|
+
$: NonNullable<T>;
|
|
1226
|
+
get(): NonNullable<T>;
|
|
1707
1227
|
}
|
|
1708
1228
|
/** A `ScalarReference<T>` that is guaranteed to be loaded, providing synchronous access via `$` and `get()`. */
|
|
1709
1229
|
export interface LoadedScalarReference<T> extends ScalarReference<T> {
|
|
1710
|
-
|
|
1711
|
-
|
|
1230
|
+
$: T;
|
|
1231
|
+
get(): T;
|
|
1712
1232
|
}
|
|
1713
1233
|
/** A `Collection<T>` that is guaranteed to be loaded, providing synchronous access via `$`, `get()`, and `getItems()`. */
|
|
1714
1234
|
export interface LoadedCollection<T extends object> extends Collection<T> {
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1235
|
+
$: Collection<T>;
|
|
1236
|
+
get(): Collection<T>;
|
|
1237
|
+
getItems(check?: boolean): T[];
|
|
1718
1238
|
}
|
|
1719
1239
|
/** Alias for `Loaded<T, P>`. Represents a newly created entity with all specified relations populated. */
|
|
1720
1240
|
export type New<T, P extends string = string> = Loaded<T, P>;
|
|
1721
1241
|
/** Interface for SQL/code syntax highlighters used in logging output. */
|
|
1722
1242
|
export interface Highlighter {
|
|
1723
|
-
|
|
1243
|
+
highlight(text: string): string;
|
|
1724
1244
|
}
|
|
1725
1245
|
/** Interface for the metadata storage, which holds `EntityMetadata` for all discovered entities. */
|
|
1726
1246
|
export interface IMetadataStorage {
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1247
|
+
getAll(): Map<EntityName, EntityMetadata>;
|
|
1248
|
+
get<T = any>(entity: EntityName<T>, init?: boolean, validate?: boolean): EntityMetadata<T>;
|
|
1249
|
+
find<T = any>(entity: EntityName<T>): EntityMetadata<T> | undefined;
|
|
1250
|
+
has<T>(entity: EntityName<T>): boolean;
|
|
1251
|
+
set<T>(entity: EntityName<T>, meta: EntityMetadata): EntityMetadata;
|
|
1252
|
+
reset<T>(entity: EntityName<T>): void;
|
|
1733
1253
|
}
|
|
1734
1254
|
/** Interface for entity hydrators, which populate entity instances from raw database data. */
|
|
1735
1255
|
export interface IHydrator {
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
factory: EntityFactory,
|
|
1745
|
-
|
|
1746
|
-
newEntity?: boolean,
|
|
1747
|
-
convertCustomTypes?: boolean,
|
|
1748
|
-
schema?: string,
|
|
1749
|
-
parentSchema?: string,
|
|
1750
|
-
normalizeAccessors?: boolean,
|
|
1751
|
-
): void;
|
|
1752
|
-
/**
|
|
1753
|
-
* Hydrates primary keys only
|
|
1754
|
-
*/
|
|
1755
|
-
hydrateReference<T extends object>(
|
|
1756
|
-
entity: T,
|
|
1757
|
-
meta: EntityMetadata<T>,
|
|
1758
|
-
data: EntityData<T>,
|
|
1759
|
-
factory: EntityFactory,
|
|
1760
|
-
convertCustomTypes?: boolean,
|
|
1761
|
-
schema?: string,
|
|
1762
|
-
parentSchema?: string,
|
|
1763
|
-
normalizeAccessors?: boolean,
|
|
1764
|
-
): void;
|
|
1765
|
-
isRunning(): boolean;
|
|
1256
|
+
/**
|
|
1257
|
+
* Hydrates the whole entity. This process handles custom type conversions, creating missing Collection instances,
|
|
1258
|
+
* mapping FKs to entity instances, as well as merging those entities.
|
|
1259
|
+
*/
|
|
1260
|
+
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;
|
|
1261
|
+
/**
|
|
1262
|
+
* Hydrates primary keys only
|
|
1263
|
+
*/
|
|
1264
|
+
hydrateReference<T extends object>(entity: T, meta: EntityMetadata<T>, data: EntityData<T>, factory: EntityFactory, convertCustomTypes?: boolean, schema?: string, parentSchema?: string, normalizeAccessors?: boolean): void;
|
|
1265
|
+
isRunning(): boolean;
|
|
1766
1266
|
}
|
|
1767
1267
|
/** Constructor signature for hydrator implementations. */
|
|
1768
1268
|
export interface HydratorConstructor {
|
|
1769
|
-
|
|
1269
|
+
new (metadata: MetadataStorage, platform: Platform, config: Configuration): IHydrator;
|
|
1770
1270
|
}
|
|
1771
1271
|
/** Interface for the seed manager, which runs database seeders. */
|
|
1772
1272
|
export interface ISeedManager {
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1273
|
+
seed(...classNames: Constructor<Seeder>[]): Promise<void>;
|
|
1274
|
+
/** @internal */
|
|
1275
|
+
seedString(...classNames: string[]): Promise<void>;
|
|
1276
|
+
create(className: string): Promise<string>;
|
|
1777
1277
|
}
|
|
1778
1278
|
/** Interface that all seeder classes must implement. The `run` method receives an EntityManager. */
|
|
1779
1279
|
export interface Seeder<T extends Dictionary = Dictionary> {
|
|
1780
|
-
|
|
1280
|
+
run(em: EntityManager, context?: T): void | Promise<void>;
|
|
1781
1281
|
}
|
|
1782
1282
|
/** A named seeder class reference, used for inline seeder registration. */
|
|
1783
1283
|
export interface SeederObject {
|
|
1784
|
-
|
|
1785
|
-
|
|
1284
|
+
name: string;
|
|
1285
|
+
class: Constructor<Seeder>;
|
|
1786
1286
|
}
|
|
1787
1287
|
/** Discriminator for read vs write database connections in read-replica setups. */
|
|
1788
1288
|
export type ConnectionType = 'read' | 'write';
|
|
@@ -1794,30 +1294,17 @@ export type MaybeReturnType<T> = T extends (...args: any[]) => infer R ? R : T;
|
|
|
1794
1294
|
* Extended `EntitySchema` interface that carries additional type-level metadata (entity name, properties, table name).
|
|
1795
1295
|
* Returned by `defineEntity()` to provide strong type inference without explicit generics.
|
|
1796
1296
|
*/
|
|
1797
|
-
export interface EntitySchemaWithMeta<
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
TClass extends EntityCtor = EntityCtor<TEntity>,
|
|
1804
|
-
> extends EntitySchema<TEntity, TBase, TClass> {
|
|
1805
|
-
readonly name: TName;
|
|
1806
|
-
readonly properties: TProperties;
|
|
1807
|
-
readonly tableName: TTableName;
|
|
1808
|
-
/** @internal Direct entity type access - avoids expensive pattern matching */
|
|
1809
|
-
readonly '~entity': TEntity;
|
|
1297
|
+
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> {
|
|
1298
|
+
readonly name: TName;
|
|
1299
|
+
readonly properties: TProperties;
|
|
1300
|
+
readonly tableName: TTableName;
|
|
1301
|
+
/** @internal Direct entity type access - avoids expensive pattern matching */
|
|
1302
|
+
readonly '~entity': TEntity;
|
|
1810
1303
|
}
|
|
1811
1304
|
/**
|
|
1812
1305
|
* Extracts the entity type from an `EntitySchema`, `EntitySchemaWithMeta`, or entity class.
|
|
1813
1306
|
* Uses a fast-path direct property access when available, falling back to generic inference.
|
|
1814
1307
|
*/
|
|
1815
1308
|
export type InferEntity<Schema> = Schema extends {
|
|
1816
|
-
|
|
1817
|
-
}
|
|
1818
|
-
? E
|
|
1819
|
-
: Schema extends EntitySchema<infer Entity>
|
|
1820
|
-
? Entity
|
|
1821
|
-
: Schema extends EntityClass<infer Entity>
|
|
1822
|
-
? Entity
|
|
1823
|
-
: Schema;
|
|
1309
|
+
'~entity': infer E;
|
|
1310
|
+
} ? E : Schema extends EntitySchema<infer Entity> ? Entity : Schema extends EntityClass<infer Entity> ? Entity : Schema;
|