@mikro-orm/core 7.0.0-dev.1 → 7.0.0-dev.100
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 +96 -58
- package/EntityManager.js +465 -395
- package/MikroORM.d.ts +45 -35
- package/MikroORM.js +109 -160
- package/README.md +3 -2
- package/cache/CacheAdapter.js +1 -2
- package/cache/FileCacheAdapter.d.ts +2 -2
- package/cache/FileCacheAdapter.js +20 -27
- package/cache/GeneratedCacheAdapter.d.ts +2 -3
- package/cache/GeneratedCacheAdapter.js +1 -7
- package/cache/MemoryCacheAdapter.d.ts +1 -1
- package/cache/MemoryCacheAdapter.js +1 -5
- package/cache/NullCacheAdapter.d.ts +1 -1
- package/cache/NullCacheAdapter.js +1 -5
- package/cache/index.d.ts +4 -5
- package/cache/index.js +4 -21
- package/connections/Connection.d.ts +22 -14
- package/connections/Connection.js +27 -23
- package/connections/index.d.ts +1 -1
- package/connections/index.js +1 -17
- package/drivers/DatabaseDriver.d.ts +25 -15
- package/drivers/DatabaseDriver.js +77 -64
- package/drivers/IDatabaseDriver.d.ts +40 -16
- package/drivers/IDatabaseDriver.js +1 -4
- package/drivers/index.d.ts +2 -2
- package/drivers/index.js +2 -18
- package/entity/BaseEntity.d.ts +6 -7
- package/entity/BaseEntity.js +16 -23
- package/entity/Collection.d.ts +98 -34
- package/entity/Collection.js +466 -131
- package/entity/EntityAssigner.d.ts +3 -3
- package/entity/EntityAssigner.js +67 -64
- package/entity/EntityFactory.d.ts +10 -3
- package/entity/EntityFactory.js +112 -91
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +66 -53
- package/entity/EntityIdentifier.d.ts +1 -1
- package/entity/EntityIdentifier.js +1 -5
- package/entity/EntityLoader.d.ts +8 -7
- package/entity/EntityLoader.js +161 -128
- package/entity/EntityRepository.d.ts +8 -8
- package/entity/EntityRepository.js +7 -11
- package/entity/Reference.d.ts +10 -13
- package/entity/Reference.js +64 -46
- package/entity/WrappedEntity.d.ts +12 -17
- package/entity/WrappedEntity.js +22 -31
- package/entity/defineEntity.d.ts +568 -0
- package/entity/defineEntity.js +529 -0
- package/entity/index.d.ts +14 -13
- package/entity/index.js +14 -29
- package/entity/utils.d.ts +8 -1
- package/entity/utils.js +22 -13
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +65 -0
- package/entity/wrap.d.ts +1 -1
- package/entity/wrap.js +2 -6
- package/enums.d.ts +24 -9
- package/enums.js +50 -41
- package/errors.d.ts +11 -3
- package/errors.js +42 -32
- package/events/EventManager.d.ts +5 -4
- package/events/EventManager.js +26 -22
- package/events/EventSubscriber.d.ts +8 -5
- package/events/EventSubscriber.js +1 -2
- package/events/TransactionEventBroadcaster.d.ts +3 -3
- package/events/TransactionEventBroadcaster.js +1 -5
- package/events/index.d.ts +3 -3
- package/events/index.js +3 -19
- package/exceptions.js +18 -39
- package/hydration/Hydrator.d.ts +5 -5
- package/hydration/Hydrator.js +2 -6
- package/hydration/ObjectHydrator.d.ts +7 -7
- package/hydration/ObjectHydrator.js +58 -50
- package/hydration/index.d.ts +2 -2
- package/hydration/index.js +2 -18
- package/index.d.ts +21 -21
- package/index.js +20 -46
- package/logging/DefaultLogger.d.ts +2 -2
- package/logging/DefaultLogger.js +10 -13
- package/logging/Logger.d.ts +1 -1
- package/logging/Logger.js +1 -2
- package/logging/SimpleLogger.d.ts +3 -3
- package/logging/SimpleLogger.js +2 -6
- package/logging/colors.js +1 -5
- package/logging/index.d.ts +5 -4
- package/logging/index.js +5 -20
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +16 -0
- package/metadata/EntitySchema.d.ts +14 -10
- package/metadata/EntitySchema.js +78 -64
- package/metadata/MetadataDiscovery.d.ts +11 -14
- package/metadata/MetadataDiscovery.js +278 -317
- package/metadata/MetadataProvider.d.ts +13 -4
- package/metadata/MetadataProvider.js +47 -8
- package/metadata/MetadataStorage.d.ts +2 -7
- package/metadata/MetadataStorage.js +19 -35
- package/metadata/MetadataValidator.d.ts +3 -10
- package/metadata/MetadataValidator.js +51 -64
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +6 -6
- package/metadata/index.js +6 -22
- package/metadata/types.d.ts +480 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +7 -3
- package/naming-strategy/AbstractNamingStrategy.js +11 -9
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +1 -1
- package/naming-strategy/EntityCaseNamingStrategy.js +2 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +1 -1
- package/naming-strategy/MongoNamingStrategy.js +2 -6
- package/naming-strategy/NamingStrategy.d.ts +12 -2
- package/naming-strategy/NamingStrategy.js +1 -2
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -1
- package/naming-strategy/UnderscoreNamingStrategy.js +2 -6
- package/naming-strategy/index.d.ts +5 -5
- package/naming-strategy/index.js +5 -21
- package/not-supported.d.ts +2 -0
- package/not-supported.js +4 -0
- package/package.json +19 -20
- package/platforms/ExceptionConverter.d.ts +2 -2
- package/platforms/ExceptionConverter.js +4 -8
- package/platforms/Platform.d.ts +15 -22
- package/platforms/Platform.js +58 -88
- package/platforms/index.d.ts +2 -2
- package/platforms/index.js +2 -18
- package/serialization/EntitySerializer.d.ts +4 -2
- package/serialization/EntitySerializer.js +64 -51
- package/serialization/EntityTransformer.d.ts +1 -1
- package/serialization/EntityTransformer.js +48 -42
- package/serialization/SerializationContext.d.ts +2 -2
- package/serialization/SerializationContext.js +24 -25
- package/serialization/index.d.ts +3 -3
- package/serialization/index.js +3 -19
- package/types/ArrayType.d.ts +3 -3
- package/types/ArrayType.js +6 -11
- package/types/BigIntType.d.ts +12 -9
- package/types/BigIntType.js +6 -6
- package/types/BlobType.d.ts +3 -4
- package/types/BlobType.js +2 -11
- package/types/BooleanType.d.ts +5 -4
- package/types/BooleanType.js +5 -6
- package/types/CharacterType.d.ts +3 -3
- package/types/CharacterType.js +2 -6
- package/types/DateTimeType.d.ts +3 -3
- package/types/DateTimeType.js +2 -6
- package/types/DateType.d.ts +3 -3
- package/types/DateType.js +2 -6
- package/types/DecimalType.d.ts +9 -7
- package/types/DecimalType.js +5 -8
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +4 -7
- package/types/EnumArrayType.d.ts +4 -4
- package/types/EnumArrayType.js +4 -10
- package/types/EnumType.d.ts +3 -3
- package/types/EnumType.js +2 -6
- package/types/FloatType.d.ts +3 -3
- package/types/FloatType.js +2 -6
- package/types/IntegerType.d.ts +3 -3
- package/types/IntegerType.js +2 -6
- package/types/IntervalType.d.ts +3 -3
- package/types/IntervalType.js +2 -6
- package/types/JsonType.d.ts +4 -4
- package/types/JsonType.js +9 -8
- package/types/MediumIntType.d.ts +3 -3
- package/types/MediumIntType.js +2 -6
- package/types/SmallIntType.d.ts +3 -3
- package/types/SmallIntType.js +2 -6
- package/types/StringType.d.ts +3 -3
- package/types/StringType.js +2 -6
- package/types/TextType.d.ts +3 -3
- package/types/TextType.js +2 -6
- package/types/TimeType.d.ts +3 -3
- package/types/TimeType.js +4 -8
- package/types/TinyIntType.d.ts +3 -3
- package/types/TinyIntType.js +3 -6
- package/types/Type.d.ts +4 -6
- package/types/Type.js +6 -10
- package/types/Uint8ArrayType.d.ts +3 -4
- package/types/Uint8ArrayType.js +3 -12
- package/types/UnknownType.d.ts +3 -3
- package/types/UnknownType.js +2 -6
- package/types/UuidType.d.ts +3 -3
- package/types/UuidType.js +2 -6
- package/types/index.d.ts +25 -25
- package/types/index.js +52 -79
- package/typings.d.ts +134 -93
- package/typings.js +67 -65
- package/unit-of-work/ChangeSet.d.ts +1 -4
- package/unit-of-work/ChangeSet.js +13 -17
- package/unit-of-work/ChangeSetComputer.d.ts +8 -9
- package/unit-of-work/ChangeSetComputer.js +36 -38
- package/unit-of-work/ChangeSetPersister.d.ts +11 -9
- package/unit-of-work/ChangeSetPersister.js +100 -65
- package/unit-of-work/CommitOrderCalculator.d.ts +1 -1
- package/unit-of-work/CommitOrderCalculator.js +6 -10
- package/unit-of-work/IdentityMap.d.ts +1 -1
- package/unit-of-work/IdentityMap.js +1 -5
- package/unit-of-work/UnitOfWork.d.ts +16 -8
- package/unit-of-work/UnitOfWork.js +266 -209
- package/unit-of-work/index.d.ts +6 -6
- package/unit-of-work/index.js +6 -22
- package/utils/AbstractSchemaGenerator.d.ts +11 -11
- package/utils/AbstractSchemaGenerator.js +21 -20
- package/utils/Configuration.d.ts +774 -224
- package/utils/Configuration.js +166 -216
- package/utils/ConfigurationLoader.d.ts +1 -53
- package/utils/ConfigurationLoader.js +1 -367
- package/utils/Cursor.d.ts +6 -9
- package/utils/Cursor.js +25 -25
- package/utils/DataloaderUtils.d.ts +18 -8
- package/utils/DataloaderUtils.js +63 -21
- package/utils/EntityComparator.d.ts +9 -5
- package/utils/EntityComparator.js +155 -108
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +1 -5
- package/utils/QueryHelper.d.ts +12 -4
- package/utils/QueryHelper.js +110 -53
- package/utils/RawQueryFragment.d.ts +37 -14
- package/utils/RawQueryFragment.js +50 -33
- package/utils/RequestContext.d.ts +2 -2
- package/utils/RequestContext.js +3 -7
- package/utils/TransactionContext.d.ts +1 -1
- package/utils/TransactionContext.js +4 -8
- package/utils/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +223 -0
- package/utils/Utils.d.ts +16 -100
- package/utils/Utils.js +114 -332
- package/utils/clone.js +7 -11
- package/utils/env-vars.d.ts +3 -0
- package/utils/env-vars.js +87 -0
- package/utils/fs-utils.d.ts +12 -0
- package/utils/fs-utils.js +97 -0
- package/utils/index.d.ts +14 -13
- package/utils/index.js +14 -29
- package/utils/upsert-utils.d.ts +8 -3
- package/utils/upsert-utils.js +57 -10
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -16
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -33
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -14
- package/decorators/Embedded.d.ts +0 -18
- package/decorators/Embedded.js +0 -20
- package/decorators/Entity.d.ts +0 -18
- package/decorators/Entity.js +0 -16
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -19
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -11
- package/decorators/Formula.d.ts +0 -5
- package/decorators/Formula.js +0 -18
- package/decorators/Indexed.d.ts +0 -17
- package/decorators/Indexed.js +0 -24
- package/decorators/ManyToMany.d.ts +0 -40
- package/decorators/ManyToMany.js +0 -16
- package/decorators/ManyToOne.d.ts +0 -30
- package/decorators/ManyToOne.js +0 -16
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -20
- package/decorators/OneToOne.d.ts +0 -24
- package/decorators/OneToOne.js +0 -10
- package/decorators/PrimaryKey.d.ts +0 -9
- package/decorators/PrimaryKey.js +0 -23
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -34
- package/decorators/Transactional.d.ts +0 -13
- package/decorators/Transactional.js +0 -31
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -59
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -36
- package/entity/ArrayCollection.d.ts +0 -116
- package/entity/ArrayCollection.js +0 -399
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -154
- package/index.mjs +0 -199
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -48
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -31
package/EntityManager.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { type
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import type {
|
|
11
|
-
import type
|
|
12
|
-
import {
|
|
13
|
-
import type {
|
|
1
|
+
import { type Configuration } from './utils/Configuration.js';
|
|
2
|
+
import { Cursor } from './utils/Cursor.js';
|
|
3
|
+
import { EntityFactory } from './entity/EntityFactory.js';
|
|
4
|
+
import { type AssignOptions } from './entity/EntityAssigner.js';
|
|
5
|
+
import { type EntityRepository } from './entity/EntityRepository.js';
|
|
6
|
+
import { EntityLoader, type EntityLoaderOptions } from './entity/EntityLoader.js';
|
|
7
|
+
import { Reference } from './entity/Reference.js';
|
|
8
|
+
import { UnitOfWork } from './unit-of-work/UnitOfWork.js';
|
|
9
|
+
import type { CountOptions, DeleteOptions, FilterOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions, GetReferenceOptions, IDatabaseDriver, LockOptions, NativeInsertUpdateOptions, StreamOptions, UpdateOptions, UpsertManyOptions, UpsertOptions } from './drivers/IDatabaseDriver.js';
|
|
10
|
+
import type { AnyString, ArrayElement, AutoPath, ConnectionType, Dictionary, EntityData, EntityDictionary, EntityDTO, EntityMetadata, EntityName, FilterDef, FilterQuery, FromEntityType, GetRepository, IHydrator, IsSubset, Loaded, MergeLoaded, MergeSelected, NoInfer, ObjectQuery, Primary, Ref, RequiredEntityData, UnboxArray } from './typings.js';
|
|
11
|
+
import { FlushMode, LockMode, PopulatePath, type TransactionOptions } from './enums.js';
|
|
12
|
+
import type { MetadataStorage } from './metadata/MetadataStorage.js';
|
|
13
|
+
import type { Transaction } from './connections/Connection.js';
|
|
14
|
+
import { EventManager } from './events/EventManager.js';
|
|
15
|
+
import type { EntityComparator } from './utils/EntityComparator.js';
|
|
14
16
|
/**
|
|
15
17
|
* The EntityManager is the central access point to ORM functionality. It is a facade to all different ORM subsystems
|
|
16
18
|
* such as UnitOfWork, Query Language, and Repository API.
|
|
@@ -22,13 +24,13 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
22
24
|
protected readonly metadata: MetadataStorage;
|
|
23
25
|
protected readonly useContext: boolean;
|
|
24
26
|
protected readonly eventManager: EventManager;
|
|
27
|
+
/** @internal */
|
|
28
|
+
readonly '~entities'?: unknown;
|
|
25
29
|
private static counter;
|
|
26
30
|
readonly _id: number;
|
|
27
31
|
readonly global = false;
|
|
28
32
|
readonly name: string;
|
|
29
|
-
|
|
30
|
-
protected readonly colLoader: DataLoader<[import("./entity").Collection<any, object>, (Omit<import("./entity").InitCollectionOptions<any, any, "*", never>, "dataloader"> | undefined)?], any, [import("./entity").Collection<any, object>, (Omit<import("./entity").InitCollectionOptions<any, any, "*", never>, "dataloader"> | undefined)?]>;
|
|
31
|
-
private readonly validator;
|
|
33
|
+
private readonly loaders;
|
|
32
34
|
private readonly repositoryMap;
|
|
33
35
|
private readonly entityLoader;
|
|
34
36
|
protected readonly comparator: EntityComparator;
|
|
@@ -67,14 +69,28 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
67
69
|
* Shortcut for `em.getRepository()`.
|
|
68
70
|
*/
|
|
69
71
|
repo<Entity extends object, Repository extends EntityRepository<Entity> = EntityRepository<Entity>>(entityName: EntityName<Entity>): GetRepository<Entity, Repository>;
|
|
70
|
-
/**
|
|
71
|
-
* Gets EntityValidator instance
|
|
72
|
-
*/
|
|
73
|
-
getValidator(): EntityValidator;
|
|
74
72
|
/**
|
|
75
73
|
* Finds all entities matching your `where` query. You can pass additional options via the `options` parameter.
|
|
76
74
|
*/
|
|
77
75
|
find<Entity extends object, Hint extends string = never, Fields extends string = PopulatePath.ALL, Excludes extends string = never>(entityName: EntityName<Entity>, where: FilterQuery<NoInfer<Entity>>, options?: FindOptions<Entity, Hint, Fields, Excludes>): Promise<Loaded<Entity, Hint, Fields, Excludes>[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Finds all entities and returns an async iterable (async generator) that yields results one by one.
|
|
78
|
+
* The results are merged and mapped to entity instances, without adding them to the identity map.
|
|
79
|
+
* You can disable merging by passing the options `{ mergeResults: false }`.
|
|
80
|
+
* With `mergeResults` disabled, to-many collections will contain at most one item, and you will get duplicate
|
|
81
|
+
* root entities when there are multiple items in the populated collection.
|
|
82
|
+
* This is useful for processing large datasets without loading everything into memory at once.
|
|
83
|
+
*
|
|
84
|
+
* ```ts
|
|
85
|
+
* const stream = em.stream(Book, { populate: ['author'] });
|
|
86
|
+
*
|
|
87
|
+
* for await (const book of stream) {
|
|
88
|
+
* // book is an instance of Book entity
|
|
89
|
+
* console.log(book.title, book.author.name);
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
stream<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName: EntityName<Entity>, options?: StreamOptions<NoInfer<Entity>, Hint, Fields, Excludes>): AsyncIterableIterator<Loaded<Entity, Hint, Fields, Excludes>>;
|
|
78
94
|
/**
|
|
79
95
|
* Finds all entities of given type, optionally matching the `where` condition provided in the `options` parameter.
|
|
80
96
|
*/
|
|
@@ -83,19 +99,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
83
99
|
/**
|
|
84
100
|
* Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
|
|
85
101
|
*/
|
|
86
|
-
addFilter<
|
|
87
|
-
/**
|
|
88
|
-
* Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
|
|
89
|
-
*/
|
|
90
|
-
addFilter<T1, T2>(name: string, cond: FilterQuery<T1 | T2> | ((args: Dictionary) => MaybePromise<FilterQuery<T1 | T2>>), entityName?: [EntityName<T1>, EntityName<T2>], enabled?: boolean): void;
|
|
91
|
-
/**
|
|
92
|
-
* Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
|
|
93
|
-
*/
|
|
94
|
-
addFilter<T1, T2, T3>(name: string, cond: FilterQuery<T1 | T2 | T3> | ((args: Dictionary) => MaybePromise<FilterQuery<T1 | T2 | T3>>), entityName?: [EntityName<T1>, EntityName<T2>, EntityName<T3>], enabled?: boolean): void;
|
|
95
|
-
/**
|
|
96
|
-
* Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
|
|
97
|
-
*/
|
|
98
|
-
addFilter(name: string, cond: Dictionary | ((args: Dictionary) => MaybePromise<FilterQuery<AnyEntity>>), entityName?: EntityName<AnyEntity> | EntityName<AnyEntity>[], enabled?: boolean): void;
|
|
102
|
+
addFilter<T extends EntityName<any> | readonly EntityName<any>[]>(options: FilterDef<T>): void;
|
|
99
103
|
/**
|
|
100
104
|
* Sets filter parameter values globally inside context defined by this entity manager.
|
|
101
105
|
* If you want to set shared value for all contexts, be sure to use the root entity manager.
|
|
@@ -112,20 +116,25 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
112
116
|
/**
|
|
113
117
|
* Gets logger context for this entity manager.
|
|
114
118
|
*/
|
|
115
|
-
getLoggerContext<T extends Dictionary = Dictionary>(
|
|
116
|
-
|
|
119
|
+
getLoggerContext<T extends Dictionary = Dictionary>(options?: {
|
|
120
|
+
disableContextResolution?: boolean;
|
|
121
|
+
}): T;
|
|
122
|
+
setFlushMode(flushMode?: FlushMode | `${FlushMode}`): void;
|
|
117
123
|
protected processWhere<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName: string, where: FilterQuery<Entity>, options: FindOptions<Entity, Hint, Fields, Excludes> | FindOneOptions<Entity, Hint, Fields, Excludes>, type: 'read' | 'update' | 'delete'): Promise<FilterQuery<Entity>>;
|
|
118
124
|
protected applyDiscriminatorCondition<Entity extends object>(entityName: string, where: FilterQuery<Entity>): FilterQuery<Entity>;
|
|
119
125
|
protected createPopulateWhere<Entity extends object>(cond: ObjectQuery<Entity>, options: FindOptions<Entity, any, any, any> | FindOneOptions<Entity, any, any, any> | CountOptions<Entity, any>): ObjectQuery<Entity>;
|
|
120
|
-
protected getJoinedFilters<Entity extends object>(meta: EntityMetadata<Entity>,
|
|
126
|
+
protected getJoinedFilters<Entity extends object>(meta: EntityMetadata<Entity>, options: FindOptions<Entity, any, any, any> | FindOneOptions<Entity, any, any, any>): Promise<ObjectQuery<Entity> | undefined>;
|
|
121
127
|
/**
|
|
122
128
|
* When filters are active on M:1 or 1:1 relations, we need to ref join them eagerly as they might affect the FK value.
|
|
123
129
|
*/
|
|
124
|
-
protected autoJoinRefsForFilters<T extends object>(meta: EntityMetadata<T>, options: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any
|
|
130
|
+
protected autoJoinRefsForFilters<T extends object>(meta: EntityMetadata<T>, options: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any>, parent?: {
|
|
131
|
+
className: string;
|
|
132
|
+
propName: string;
|
|
133
|
+
}): Promise<void>;
|
|
125
134
|
/**
|
|
126
135
|
* @internal
|
|
127
136
|
*/
|
|
128
|
-
applyFilters<Entity extends object>(entityName: string, where: FilterQuery<Entity> | undefined, options:
|
|
137
|
+
applyFilters<Entity extends object>(entityName: string, where: FilterQuery<Entity> | undefined, options: FilterOptions | undefined, type: 'read' | 'update' | 'delete', findOptions?: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any>): Promise<FilterQuery<Entity> | undefined>;
|
|
129
138
|
/**
|
|
130
139
|
* Calls `em.find()` and `em.count()` with the same arguments (where applicable) and returns the results as tuple
|
|
131
140
|
* where the first element is the array of entities, and the second is the count.
|
|
@@ -166,6 +175,10 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
166
175
|
* });
|
|
167
176
|
* ```
|
|
168
177
|
*
|
|
178
|
+
* The options also support an `includeCount` (true by default) option. If set to false, the `totalCount` is not
|
|
179
|
+
* returned as part of the cursor. This is useful for performance reason, when you don't care about the total number
|
|
180
|
+
* of pages.
|
|
181
|
+
*
|
|
169
182
|
* The `Cursor` object provides the following interface:
|
|
170
183
|
*
|
|
171
184
|
* ```ts
|
|
@@ -175,7 +188,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
175
188
|
* User { ... },
|
|
176
189
|
* User { ... },
|
|
177
190
|
* ],
|
|
178
|
-
* totalCount: 50,
|
|
191
|
+
* totalCount: 50, // not included if `includeCount: false`
|
|
179
192
|
* startCursor: 'WzRd',
|
|
180
193
|
* endCursor: 'WzZd',
|
|
181
194
|
* hasPrevPage: true,
|
|
@@ -183,7 +196,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
183
196
|
* }
|
|
184
197
|
* ```
|
|
185
198
|
*/
|
|
186
|
-
findByCursor<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName: EntityName<Entity>, where: FilterQuery<NoInfer<Entity>>, options: FindByCursorOptions<Entity, Hint, Fields, Excludes>): Promise<Cursor<Entity, Hint, Fields, Excludes>>;
|
|
199
|
+
findByCursor<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never, IncludeCount extends boolean = true>(entityName: EntityName<Entity>, where: FilterQuery<NoInfer<Entity>>, options: FindByCursorOptions<Entity, Hint, Fields, Excludes, IncludeCount>): Promise<Cursor<Entity, Hint, Fields, Excludes, IncludeCount>>;
|
|
187
200
|
/**
|
|
188
201
|
* Refreshes the persistent state of an entity from the database, overriding any local changes that have not yet been
|
|
189
202
|
* persisted. Returns the same entity instance (same object reference), but re-hydrated. If the entity is no longer
|
|
@@ -258,6 +271,29 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
258
271
|
upsertMany<Entity extends object, Fields extends string = any>(entityNameOrEntity: EntityName<Entity> | Entity[], data?: (EntityData<Entity> | NoInfer<Entity>)[], options?: UpsertManyOptions<Entity, Fields>): Promise<Entity[]>;
|
|
259
272
|
/**
|
|
260
273
|
* Runs your callback wrapped inside a database transaction.
|
|
274
|
+
*
|
|
275
|
+
* If a transaction is already active, a new savepoint (nested transaction) will be created by default. This behavior
|
|
276
|
+
* can be controlled via the `propagation` option. Use the provided EntityManager instance for all operations that
|
|
277
|
+
* should be part of the transaction. You can safely use a global EntityManager instance from a DI container, as this
|
|
278
|
+
* method automatically creates an async context for the transaction.
|
|
279
|
+
*
|
|
280
|
+
* **Concurrency note:** When running multiple transactions concurrently (e.g. in parallel requests or jobs), use the
|
|
281
|
+
* `clear: true` option. This ensures the callback runs in a clear fork of the EntityManager, providing full isolation
|
|
282
|
+
* between concurrent transactional handlers. Using `clear: true` is an alternative to forking explicitly and calling
|
|
283
|
+
* the method on the new fork – it already provides the necessary isolation for safe concurrent usage.
|
|
284
|
+
*
|
|
285
|
+
* **Propagation note:** Changes made within a transaction (whether top-level or nested) are always propagated to the
|
|
286
|
+
* parent context, unless the parent context is a global one. If you want to avoid that, fork the EntityManager first
|
|
287
|
+
* and then call this method on the fork.
|
|
288
|
+
*
|
|
289
|
+
* **Example:**
|
|
290
|
+
* ```ts
|
|
291
|
+
* await em.transactional(async (em) => {
|
|
292
|
+
* const author = new Author('Jon');
|
|
293
|
+
* em.persist(author);
|
|
294
|
+
* // flush is called automatically at the end of the callback
|
|
295
|
+
* });
|
|
296
|
+
* ```
|
|
261
297
|
*/
|
|
262
298
|
transactional<T>(cb: (em: this) => T | Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
263
299
|
/**
|
|
@@ -375,11 +411,6 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
375
411
|
* The entity will be entered into the database at or before transaction commit or as a result of the flush operation.
|
|
376
412
|
*/
|
|
377
413
|
persist<Entity extends object>(entity: Entity | Reference<Entity> | Iterable<Entity | Reference<Entity>>): this;
|
|
378
|
-
/**
|
|
379
|
-
* Persists your entity immediately, flushing all not yet persisted changes to the database too.
|
|
380
|
-
* Equivalent to `em.persist(e).flush()`.
|
|
381
|
-
*/
|
|
382
|
-
persistAndFlush(entity: AnyEntity | Reference<AnyEntity> | Iterable<AnyEntity | Reference<AnyEntity>>): Promise<void>;
|
|
383
414
|
/**
|
|
384
415
|
* Marks entity for removal.
|
|
385
416
|
* A removed entity will be removed from the database at or before transaction commit or as a result of the flush operation.
|
|
@@ -387,11 +418,6 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
387
418
|
* To remove entities by condition, use `em.nativeDelete()`.
|
|
388
419
|
*/
|
|
389
420
|
remove<Entity extends object>(entity: Entity | Reference<Entity> | Iterable<Entity | Reference<Entity>>): this;
|
|
390
|
-
/**
|
|
391
|
-
* Removes an entity instance immediately, flushing all not yet persisted changes to the database too.
|
|
392
|
-
* Equivalent to `em.remove(e).flush()`
|
|
393
|
-
*/
|
|
394
|
-
removeAndFlush(entity: AnyEntity | Reference<AnyEntity> | Iterable<AnyEntity | Reference<AnyEntity>>): Promise<void>;
|
|
395
421
|
/**
|
|
396
422
|
* Flushes all changes to objects that have been queued up to now to the database.
|
|
397
423
|
* This effectively synchronizes the in-memory state of managed objects with the database.
|
|
@@ -414,7 +440,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
414
440
|
/**
|
|
415
441
|
* Loads specified relations in batch. This will execute one query for each relation, that will populate it on all the specified entities.
|
|
416
442
|
*/
|
|
417
|
-
populate<Entity extends object, Naked extends FromEntityType<UnboxArray<Entity>> = FromEntityType<UnboxArray<Entity>>, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entities: Entity, populate: AutoPath<Naked, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Naked, Fields, Excludes>): Promise<Entity extends object[] ? MergeLoaded<ArrayElement<Entity>, Naked, Hint, Fields, Excludes>[] : MergeLoaded<Entity, Naked, Hint, Fields, Excludes>>;
|
|
443
|
+
populate<Entity extends object, Naked extends FromEntityType<UnboxArray<Entity>> = FromEntityType<UnboxArray<Entity>>, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entities: Entity, populate: readonly AutoPath<Naked, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Naked, Fields, Excludes>): Promise<Entity extends object[] ? MergeLoaded<ArrayElement<Entity>, Naked, Hint, Fields, Excludes>[] : MergeLoaded<Entity, Naked, Hint, Fields, Excludes>>;
|
|
418
444
|
/**
|
|
419
445
|
* Returns new EntityManager instance with its own identity map
|
|
420
446
|
*/
|
|
@@ -427,6 +453,10 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
427
453
|
* Gets the EntityFactory used by the EntityManager.
|
|
428
454
|
*/
|
|
429
455
|
getEntityFactory(): EntityFactory;
|
|
456
|
+
/**
|
|
457
|
+
* @internal use `em.populate()` as the user facing API, this is exposed only for internal usage
|
|
458
|
+
*/
|
|
459
|
+
getEntityLoader(): EntityLoader;
|
|
430
460
|
/**
|
|
431
461
|
* Gets the Hydrator used by the EntityManager.
|
|
432
462
|
*/
|
|
@@ -474,7 +504,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
474
504
|
* some additional lazy properties, if so, we reload and merge the data from database
|
|
475
505
|
*/
|
|
476
506
|
protected shouldRefresh<T extends object, P extends string = never, F extends string = '*', E extends string = never>(meta: EntityMetadata<T>, entity: T, options: FindOneOptions<T, P, F, E>): boolean;
|
|
477
|
-
protected prepareOptions(options: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any>): void;
|
|
507
|
+
protected prepareOptions(options: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any> | CountOptions<any, any>): void;
|
|
478
508
|
/**
|
|
479
509
|
* @internal
|
|
480
510
|
*/
|
|
@@ -483,15 +513,15 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
483
513
|
* @internal
|
|
484
514
|
*/
|
|
485
515
|
tryCache<T extends object, R>(entityName: string, config: boolean | number | [string, number] | undefined, key: unknown, refresh?: boolean, merge?: boolean): Promise<{
|
|
486
|
-
data?: R;
|
|
516
|
+
data?: R | null;
|
|
487
517
|
key: string;
|
|
488
518
|
} | undefined>;
|
|
489
519
|
/**
|
|
490
520
|
* @internal
|
|
491
521
|
*/
|
|
492
|
-
storeCache(config: boolean | number | [string, number] | undefined, key: {
|
|
522
|
+
storeCache<T>(config: boolean | number | [string, number] | undefined, key: {
|
|
493
523
|
key: string;
|
|
494
|
-
}, data:
|
|
524
|
+
}, data: T | (() => T)): Promise<void>;
|
|
495
525
|
/**
|
|
496
526
|
* Clears result cache for given cache key. If we want to be able to call this method,
|
|
497
527
|
* we need to set the cache key explicitly when storing the cache.
|
|
@@ -515,13 +545,13 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
515
545
|
* if executed inside request context handler.
|
|
516
546
|
*/
|
|
517
547
|
set schema(schema: string | null | undefined);
|
|
548
|
+
/** @internal */
|
|
549
|
+
getDataLoader(type: 'ref' | '1:m' | 'm:n'): Promise<any>;
|
|
518
550
|
/**
|
|
519
551
|
* Returns the ID of this EntityManager. Respects the context, so global EM will give you the contextual ID
|
|
520
552
|
* if executed inside request context handler.
|
|
521
553
|
*/
|
|
522
554
|
get id(): number;
|
|
523
|
-
/** @ignore */
|
|
524
|
-
[inspect.custom](): string;
|
|
525
555
|
}
|
|
526
556
|
export interface CreateOptions<Convert extends boolean> {
|
|
527
557
|
/** creates a managed entity instance instead, bypassing the constructor call */
|
|
@@ -534,11 +564,19 @@ export interface CreateOptions<Convert extends boolean> {
|
|
|
534
564
|
partial?: boolean;
|
|
535
565
|
/** convert raw database values based on mapped types (by default, already converted values are expected) */
|
|
536
566
|
convertCustomTypes?: Convert;
|
|
567
|
+
/**
|
|
568
|
+
* Property `onCreate` hooks are normally executed during `flush` operation.
|
|
569
|
+
* With this option, they will be processed early inside `em.create()` method.
|
|
570
|
+
*/
|
|
571
|
+
processOnCreateHooksEarly?: boolean;
|
|
537
572
|
}
|
|
538
573
|
export interface MergeOptions {
|
|
539
574
|
refresh?: boolean;
|
|
540
575
|
convertCustomTypes?: boolean;
|
|
541
576
|
schema?: string;
|
|
577
|
+
disableContextResolution?: boolean;
|
|
578
|
+
validate?: boolean;
|
|
579
|
+
cascade?: boolean; /** @default true */
|
|
542
580
|
}
|
|
543
581
|
export interface ForkOptions {
|
|
544
582
|
/** do we want a clear identity map? defaults to true */
|
|
@@ -552,7 +590,7 @@ export interface ForkOptions {
|
|
|
552
590
|
/** use this flag to ignore the current async context - this is required if we want to call `em.fork()` inside the `getContext` handler */
|
|
553
591
|
disableContextResolution?: boolean;
|
|
554
592
|
/** set flush mode for this fork, overrides the global option can be overridden locally via FindOptions */
|
|
555
|
-
flushMode?: FlushMode
|
|
593
|
+
flushMode?: FlushMode | `${FlushMode}`;
|
|
556
594
|
/** disable transactions for this fork */
|
|
557
595
|
disableTransactions?: boolean;
|
|
558
596
|
/** should we keep the transaction context of the parent EM? */
|