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