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