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