@mikro-orm/core 7.0.0-dev.33 → 7.0.0-dev.331
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 +70 -75
- package/EntityManager.js +487 -402
- package/MikroORM.d.ts +45 -38
- package/MikroORM.js +123 -156
- package/README.md +7 -4
- package/cache/FileCacheAdapter.d.ts +2 -7
- package/cache/FileCacheAdapter.js +35 -30
- package/cache/GeneratedCacheAdapter.d.ts +1 -2
- package/cache/GeneratedCacheAdapter.js +6 -8
- package/cache/MemoryCacheAdapter.d.ts +1 -2
- package/cache/MemoryCacheAdapter.js +8 -8
- package/cache/index.d.ts +1 -2
- package/cache/index.js +0 -2
- package/connections/Connection.d.ts +12 -5
- package/connections/Connection.js +37 -15
- package/drivers/DatabaseDriver.d.ts +25 -18
- package/drivers/DatabaseDriver.js +144 -45
- package/drivers/IDatabaseDriver.d.ts +118 -23
- package/entity/BaseEntity.d.ts +63 -4
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +95 -31
- package/entity/Collection.js +487 -139
- package/entity/EntityAssigner.js +37 -25
- package/entity/EntityFactory.d.ts +8 -9
- package/entity/EntityFactory.js +152 -100
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +69 -27
- package/entity/EntityLoader.d.ts +12 -13
- package/entity/EntityLoader.js +286 -125
- package/entity/EntityRepository.d.ts +28 -8
- package/entity/EntityRepository.js +8 -2
- package/entity/PolymorphicRef.d.ts +12 -0
- package/entity/PolymorphicRef.js +18 -0
- package/entity/Reference.d.ts +3 -8
- package/entity/Reference.js +62 -29
- package/entity/WrappedEntity.d.ts +7 -10
- package/entity/WrappedEntity.js +6 -7
- package/entity/defineEntity.d.ts +472 -313
- package/entity/defineEntity.js +134 -290
- package/entity/index.d.ts +2 -2
- package/entity/index.js +2 -2
- package/entity/utils.d.ts +6 -1
- package/entity/utils.js +46 -11
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +66 -0
- package/enums.d.ts +8 -6
- package/enums.js +13 -17
- package/errors.d.ts +26 -16
- package/errors.js +63 -31
- package/events/EventManager.d.ts +3 -5
- package/events/EventManager.js +37 -26
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/exceptions.js +9 -2
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +5 -6
- package/hydration/ObjectHydrator.js +109 -50
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +3 -4
- package/logging/SimpleLogger.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +4 -6
- package/logging/index.d.ts +2 -1
- package/logging/index.js +1 -1
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +11 -0
- package/metadata/EntitySchema.d.ts +47 -23
- package/metadata/EntitySchema.js +103 -34
- package/metadata/MetadataDiscovery.d.ts +65 -18
- package/metadata/MetadataDiscovery.js +940 -424
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +71 -2
- package/metadata/MetadataStorage.d.ts +11 -13
- package/metadata/MetadataStorage.js +79 -48
- package/metadata/MetadataValidator.d.ts +32 -9
- package/metadata/MetadataValidator.js +214 -44
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/metadata/types.d.ts +577 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
- package/naming-strategy/AbstractNamingStrategy.js +26 -5
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +7 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
- package/naming-strategy/MongoNamingStrategy.js +6 -6
- package/naming-strategy/NamingStrategy.d.ts +28 -4
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/not-supported.d.ts +2 -0
- package/not-supported.js +8 -0
- package/package.json +47 -36
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +33 -15
- package/platforms/Platform.js +125 -69
- package/serialization/EntitySerializer.d.ts +6 -3
- package/serialization/EntitySerializer.js +54 -30
- package/serialization/EntityTransformer.js +37 -22
- package/serialization/SerializationContext.d.ts +10 -14
- package/serialization/SerializationContext.js +24 -19
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.js +1 -1
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +1 -0
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.js +2 -2
- package/types/DoubleType.js +1 -1
- package/types/EnumArrayType.js +1 -2
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/TinyIntType.js +1 -1
- package/types/Type.d.ts +2 -4
- package/types/Type.js +3 -3
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +1 -4
- package/types/UuidType.d.ts +2 -0
- package/types/UuidType.js +14 -2
- package/types/index.d.ts +3 -2
- package/typings.d.ts +427 -170
- package/typings.js +100 -45
- package/unit-of-work/ChangeSet.d.ts +4 -6
- package/unit-of-work/ChangeSet.js +8 -9
- package/unit-of-work/ChangeSetComputer.d.ts +2 -12
- package/unit-of-work/ChangeSetComputer.js +61 -38
- package/unit-of-work/ChangeSetPersister.d.ts +10 -17
- package/unit-of-work/ChangeSetPersister.js +136 -73
- package/unit-of-work/CommitOrderCalculator.d.ts +13 -14
- package/unit-of-work/CommitOrderCalculator.js +22 -20
- package/unit-of-work/IdentityMap.d.ts +12 -3
- package/unit-of-work/IdentityMap.js +51 -13
- package/unit-of-work/UnitOfWork.d.ts +39 -23
- package/unit-of-work/UnitOfWork.js +441 -246
- package/utils/AbstractMigrator.d.ts +101 -0
- package/utils/AbstractMigrator.js +303 -0
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +30 -18
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +647 -185
- package/utils/Configuration.js +215 -252
- package/utils/ConfigurationLoader.d.ts +1 -52
- package/utils/ConfigurationLoader.js +1 -330
- package/utils/Cursor.d.ts +3 -6
- package/utils/Cursor.js +32 -17
- package/utils/DataloaderUtils.d.ts +10 -5
- package/utils/DataloaderUtils.js +42 -22
- package/utils/EntityComparator.d.ts +21 -21
- package/utils/EntityComparator.js +224 -118
- package/utils/QueryHelper.d.ts +34 -7
- package/utils/QueryHelper.js +183 -72
- package/utils/RawQueryFragment.d.ts +28 -34
- package/utils/RawQueryFragment.js +37 -72
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.js +11 -8
- package/utils/Utils.d.ts +16 -127
- package/utils/Utils.js +104 -402
- package/utils/clone.js +13 -23
- package/utils/env-vars.d.ts +7 -0
- package/utils/env-vars.js +98 -0
- package/utils/fs-utils.d.ts +20 -0
- package/utils/fs-utils.js +193 -0
- package/utils/index.d.ts +1 -3
- package/utils/index.js +1 -3
- package/utils/upsert-utils.d.ts +9 -4
- package/utils/upsert-utils.js +51 -5
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -13
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -32
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -11
- package/decorators/Embedded.d.ts +0 -12
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -33
- package/decorators/Entity.js +0 -12
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -16
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -8
- package/decorators/Formula.d.ts +0 -4
- package/decorators/Formula.js +0 -15
- package/decorators/Indexed.d.ts +0 -19
- package/decorators/Indexed.js +0 -20
- package/decorators/ManyToMany.d.ts +0 -42
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -34
- package/decorators/ManyToOne.js +0 -14
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -17
- package/decorators/OneToOne.d.ts +0 -28
- package/decorators/OneToOne.js +0 -7
- package/decorators/PrimaryKey.d.ts +0 -8
- package/decorators/PrimaryKey.js +0 -20
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -32
- package/decorators/Transactional.d.ts +0 -14
- package/decorators/Transactional.js +0 -28
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -47
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -17
- package/entity/ArrayCollection.d.ts +0 -118
- package/entity/ArrayCollection.js +0 -407
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -150
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -44
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -28
package/EntityManager.d.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
|
-
import DataLoader from 'dataloader';
|
|
3
1
|
import { type Configuration } from './utils/Configuration.js';
|
|
4
2
|
import { Cursor } from './utils/Cursor.js';
|
|
5
3
|
import { EntityFactory } from './entity/EntityFactory.js';
|
|
6
4
|
import { type AssignOptions } from './entity/EntityAssigner.js';
|
|
7
|
-
import { EntityValidator } from './entity/EntityValidator.js';
|
|
8
5
|
import { type EntityRepository } from './entity/EntityRepository.js';
|
|
9
6
|
import { EntityLoader, type EntityLoaderOptions } from './entity/EntityLoader.js';
|
|
10
7
|
import { Reference } from './entity/Reference.js';
|
|
11
8
|
import { UnitOfWork } from './unit-of-work/UnitOfWork.js';
|
|
12
|
-
import type { CountOptions, DeleteOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions, GetReferenceOptions, IDatabaseDriver, LockOptions, NativeInsertUpdateOptions, UpdateOptions, UpsertManyOptions, UpsertOptions } from './drivers/IDatabaseDriver.js';
|
|
13
|
-
import type {
|
|
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, EntityClass, EntityData, EntityDictionary, EntityDTO, EntityMetadata, EntityName, FilterDef, FilterQuery, FromEntityType, GetRepository, IHydrator, IsSubset, Loaded, MergeLoaded, MergeSelected, ObjectQuery, PopulateOptions, Primary, Ref, RequiredEntityData, UnboxArray } from './typings.js';
|
|
14
11
|
import { FlushMode, LockMode, PopulatePath, type TransactionOptions } from './enums.js';
|
|
15
12
|
import type { MetadataStorage } from './metadata/MetadataStorage.js';
|
|
16
13
|
import type { Transaction } from './connections/Connection.js';
|
|
@@ -22,32 +19,18 @@ import type { EntityComparator } from './utils/EntityComparator.js';
|
|
|
22
19
|
* @template {IDatabaseDriver} Driver current driver type
|
|
23
20
|
*/
|
|
24
21
|
export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDriver> {
|
|
22
|
+
#private;
|
|
25
23
|
readonly config: Configuration;
|
|
26
24
|
protected readonly driver: Driver;
|
|
27
25
|
protected readonly metadata: MetadataStorage;
|
|
28
|
-
protected readonly useContext: boolean;
|
|
29
26
|
protected readonly eventManager: EventManager;
|
|
30
|
-
|
|
27
|
+
/** @internal */
|
|
28
|
+
readonly '~entities'?: unknown;
|
|
29
|
+
/** @internal */
|
|
31
30
|
readonly _id: number;
|
|
32
31
|
readonly global = false;
|
|
33
32
|
readonly name: string;
|
|
34
|
-
protected readonly refLoader: DataLoader<[Reference<any>, (Omit<import("./entity/Reference.js").LoadReferenceOptions<any, any, "*", never>, "dataloader"> | undefined)?], any, [Reference<any>, (Omit<import("./entity/Reference.js").LoadReferenceOptions<any, any, "*", never>, "dataloader"> | undefined)?]>;
|
|
35
|
-
protected readonly colLoader: DataLoader<[import("./index.js").Collection<any, object>, (Omit<import("./index.js").InitCollectionOptions<any, any, "*", never>, "dataloader"> | undefined)?], any, [import("./index.js").Collection<any, object>, (Omit<import("./index.js").InitCollectionOptions<any, any, "*", never>, "dataloader"> | undefined)?]>;
|
|
36
|
-
protected readonly colLoaderMtoN: DataLoader<[import("./index.js").Collection<any, object>, (Omit<import("./index.js").InitCollectionOptions<any, any, "*", never>, "dataloader"> | undefined)?], any, [import("./index.js").Collection<any, object>, (Omit<import("./index.js").InitCollectionOptions<any, any, "*", never>, "dataloader"> | undefined)?]>;
|
|
37
|
-
private readonly validator;
|
|
38
|
-
private readonly repositoryMap;
|
|
39
|
-
private readonly entityLoader;
|
|
40
|
-
protected readonly comparator: EntityComparator;
|
|
41
|
-
private readonly entityFactory;
|
|
42
|
-
private readonly unitOfWork;
|
|
43
|
-
private readonly resultCache;
|
|
44
|
-
private filters;
|
|
45
|
-
private filterParams;
|
|
46
33
|
protected loggerContext?: Dictionary;
|
|
47
|
-
private transactionContext?;
|
|
48
|
-
private disableTransactions;
|
|
49
|
-
private flushMode?;
|
|
50
|
-
private _schema?;
|
|
51
34
|
/**
|
|
52
35
|
* @internal
|
|
53
36
|
*/
|
|
@@ -73,14 +56,28 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
73
56
|
* Shortcut for `em.getRepository()`.
|
|
74
57
|
*/
|
|
75
58
|
repo<Entity extends object, Repository extends EntityRepository<Entity> = EntityRepository<Entity>>(entityName: EntityName<Entity>): GetRepository<Entity, Repository>;
|
|
76
|
-
/**
|
|
77
|
-
* Gets EntityValidator instance
|
|
78
|
-
*/
|
|
79
|
-
getValidator(): EntityValidator;
|
|
80
59
|
/**
|
|
81
60
|
* Finds all entities matching your `where` query. You can pass additional options via the `options` parameter.
|
|
82
61
|
*/
|
|
83
62
|
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>[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Finds all entities and returns an async iterable (async generator) that yields results one by one.
|
|
65
|
+
* The results are merged and mapped to entity instances, without adding them to the identity map.
|
|
66
|
+
* You can disable merging by passing the options `{ mergeResults: false }`.
|
|
67
|
+
* With `mergeResults` disabled, to-many collections will contain at most one item, and you will get duplicate
|
|
68
|
+
* root entities when there are multiple items in the populated collection.
|
|
69
|
+
* This is useful for processing large datasets without loading everything into memory at once.
|
|
70
|
+
*
|
|
71
|
+
* ```ts
|
|
72
|
+
* const stream = em.stream(Book, { populate: ['author'] });
|
|
73
|
+
*
|
|
74
|
+
* for await (const book of stream) {
|
|
75
|
+
* // book is an instance of Book entity
|
|
76
|
+
* console.log(book.title, book.author.name);
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
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>>;
|
|
84
81
|
/**
|
|
85
82
|
* Finds all entities of given type, optionally matching the `where` condition provided in the `options` parameter.
|
|
86
83
|
*/
|
|
@@ -89,19 +86,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
89
86
|
/**
|
|
90
87
|
* Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
|
|
91
88
|
*/
|
|
92
|
-
addFilter<
|
|
93
|
-
/**
|
|
94
|
-
* Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
|
|
95
|
-
*/
|
|
96
|
-
addFilter<T1, T2>(name: string, cond: FilterQuery<T1 | T2> | ((args: Dictionary) => MaybePromise<FilterQuery<T1 | T2>>), entityName?: [EntityName<T1>, EntityName<T2>], enabled?: boolean): void;
|
|
97
|
-
/**
|
|
98
|
-
* Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
|
|
99
|
-
*/
|
|
100
|
-
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;
|
|
101
|
-
/**
|
|
102
|
-
* Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
|
|
103
|
-
*/
|
|
104
|
-
addFilter(name: string, cond: Dictionary | ((args: Dictionary) => MaybePromise<FilterQuery<AnyEntity>>), entityName?: EntityName<AnyEntity> | EntityName<AnyEntity>[], enabled?: boolean): void;
|
|
89
|
+
addFilter<T extends EntityName | readonly EntityName[]>(options: FilterDef<T>): void;
|
|
105
90
|
/**
|
|
106
91
|
* Sets filter parameter values globally inside context defined by this entity manager.
|
|
107
92
|
* If you want to set shared value for all contexts, be sure to use the root entity manager.
|
|
@@ -121,19 +106,23 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
121
106
|
getLoggerContext<T extends Dictionary = Dictionary>(options?: {
|
|
122
107
|
disableContextResolution?: boolean;
|
|
123
108
|
}): T;
|
|
124
|
-
setFlushMode(flushMode?: FlushMode): void;
|
|
125
|
-
protected processWhere<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName:
|
|
126
|
-
protected
|
|
109
|
+
setFlushMode(flushMode?: FlushMode | `${FlushMode}`): void;
|
|
110
|
+
protected processWhere<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName: EntityName<Entity>, where: FilterQuery<Entity>, options: FindOptions<Entity, Hint, Fields, Excludes> | FindOneOptions<Entity, Hint, Fields, Excludes>, type: 'read' | 'update' | 'delete'): Promise<FilterQuery<Entity>>;
|
|
111
|
+
protected processUnionWhere<Entity extends object, Hint extends string = never>(entityName: EntityName<Entity>, options: FindOptions<Entity, Hint, any, any> | CountOptions<Entity, Hint> | UpdateOptions<Entity> | DeleteOptions<Entity>, type: 'read' | 'update' | 'delete'): Promise<void>;
|
|
112
|
+
protected applyDiscriminatorCondition<Entity extends object>(entityName: EntityName<Entity>, where: FilterQuery<Entity>): FilterQuery<Entity>;
|
|
127
113
|
protected createPopulateWhere<Entity extends object>(cond: ObjectQuery<Entity>, options: FindOptions<Entity, any, any, any> | FindOneOptions<Entity, any, any, any> | CountOptions<Entity, any>): ObjectQuery<Entity>;
|
|
128
|
-
protected getJoinedFilters<Entity extends object>(meta: EntityMetadata<Entity>,
|
|
114
|
+
protected getJoinedFilters<Entity extends object>(meta: EntityMetadata<Entity>, options: FindOptions<Entity, any, any, any> | FindOneOptions<Entity, any, any, any>): Promise<ObjectQuery<Entity> | undefined>;
|
|
129
115
|
/**
|
|
130
116
|
* 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.
|
|
131
117
|
*/
|
|
132
|
-
protected autoJoinRefsForFilters<T extends object>(meta: EntityMetadata<T>, options: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any
|
|
118
|
+
protected autoJoinRefsForFilters<T extends object>(meta: EntityMetadata<T>, options: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any>, parent?: {
|
|
119
|
+
class: EntityClass;
|
|
120
|
+
propName: string;
|
|
121
|
+
}): Promise<void>;
|
|
133
122
|
/**
|
|
134
123
|
* @internal
|
|
135
124
|
*/
|
|
136
|
-
applyFilters<Entity extends object>(entityName:
|
|
125
|
+
applyFilters<Entity extends object>(entityName: EntityName<Entity>, 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>;
|
|
137
126
|
/**
|
|
138
127
|
* Calls `em.find()` and `em.count()` with the same arguments (where applicable) and returns the results as tuple
|
|
139
128
|
* where the first element is the array of entities, and the second is the count.
|
|
@@ -153,21 +142,21 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
153
142
|
* - POJO/entity instance
|
|
154
143
|
*
|
|
155
144
|
* ```ts
|
|
156
|
-
* const currentCursor = await em.findByCursor(User, {
|
|
145
|
+
* const currentCursor = await em.findByCursor(User, {
|
|
157
146
|
* first: 10,
|
|
158
147
|
* after: previousCursor, // cursor instance
|
|
159
148
|
* orderBy: { id: 'desc' },
|
|
160
149
|
* });
|
|
161
150
|
*
|
|
162
151
|
* // to fetch next page
|
|
163
|
-
* const nextCursor = await em.findByCursor(User, {
|
|
152
|
+
* const nextCursor = await em.findByCursor(User, {
|
|
164
153
|
* first: 10,
|
|
165
154
|
* after: currentCursor.endCursor, // opaque string
|
|
166
155
|
* orderBy: { id: 'desc' },
|
|
167
156
|
* });
|
|
168
157
|
*
|
|
169
158
|
* // to fetch next page
|
|
170
|
-
* const nextCursor2 = await em.findByCursor(User, {
|
|
159
|
+
* const nextCursor2 = await em.findByCursor(User, {
|
|
171
160
|
* first: 10,
|
|
172
161
|
* after: { id: lastSeenId }, // entity-like POJO
|
|
173
162
|
* orderBy: { id: 'desc' },
|
|
@@ -195,7 +184,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
195
184
|
* }
|
|
196
185
|
* ```
|
|
197
186
|
*/
|
|
198
|
-
findByCursor<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never, IncludeCount extends boolean = true>(entityName: EntityName<Entity>,
|
|
187
|
+
findByCursor<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never, IncludeCount extends boolean = true>(entityName: EntityName<Entity>, options: FindByCursorOptions<Entity, Hint, Fields, Excludes, IncludeCount>): Promise<Cursor<Entity, Hint, Fields, Excludes, IncludeCount>>;
|
|
199
188
|
/**
|
|
200
189
|
* Refreshes the persistent state of an entity from the database, overriding any local changes that have not yet been
|
|
201
190
|
* persisted. Returns the same entity instance (same object reference), but re-hydrated. If the entity is no longer
|
|
@@ -358,7 +347,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
358
347
|
* The newly created entity will be automatically marked for persistence via `em.persist` unless you disable this
|
|
359
348
|
* behavior, either locally via `persist: false` option, or globally via `persistOnCreate` ORM config option.
|
|
360
349
|
*/
|
|
361
|
-
create<Entity extends object, Convert extends boolean = false>(entityName: EntityName<Entity>, data: RequiredEntityData<Entity, never, Convert>, options?: CreateOptions<Convert>): Entity;
|
|
350
|
+
create<Entity extends object, Convert extends boolean = false, Data extends RequiredEntityData<Entity, never, Convert> = RequiredEntityData<Entity, never, Convert>>(entityName: EntityName<Entity>, data: Data & IsSubset<RequiredEntityData<Entity, never, Convert>, Data>, options?: CreateOptions<Convert>): Entity;
|
|
362
351
|
/**
|
|
363
352
|
* Creates new instance of given entity and populates it with given data.
|
|
364
353
|
* The entity constructor will be used unless you provide `{ managed: true }` in the `options` parameter.
|
|
@@ -374,17 +363,33 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
374
363
|
* The newly created entity will be automatically marked for persistence via `em.persist` unless you disable this
|
|
375
364
|
* behavior, either locally via `persist: false` option, or globally via `persistOnCreate` ORM config option.
|
|
376
365
|
*/
|
|
377
|
-
create<Entity extends object, Convert extends boolean = false>(entityName: EntityName<Entity>, data: EntityData<Entity, Convert>, options: CreateOptions<Convert> & {
|
|
366
|
+
create<Entity extends object, Convert extends boolean = false, Data extends EntityData<Entity, Convert> = EntityData<Entity, Convert>>(entityName: EntityName<Entity>, data: Data & IsSubset<EntityData<Entity, Convert>, Data>, options: CreateOptions<Convert> & {
|
|
378
367
|
partial: true;
|
|
379
368
|
}): Entity;
|
|
380
369
|
/**
|
|
381
370
|
* Shortcut for `wrap(entity).assign(data, { em })`
|
|
382
371
|
*/
|
|
383
372
|
assign<Entity extends object, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Convert extends boolean = false, Data extends EntityData<Naked, Convert> | Partial<EntityDTO<Naked>> = EntityData<Naked, Convert> | Partial<EntityDTO<Naked>>>(entity: Entity | Partial<Entity>, data: Data & IsSubset<EntityData<Naked, Convert>, Data>, options?: AssignOptions<Convert>): MergeSelected<Entity, Naked, keyof Data & string>;
|
|
373
|
+
/**
|
|
374
|
+
* Gets a reference to the entity identified by the given type and alternate key property without actually loading it.
|
|
375
|
+
* The key option specifies which property to use for identity map lookup instead of the primary key.
|
|
376
|
+
*/
|
|
377
|
+
getReference<Entity extends object, K extends string & keyof Entity>(entityName: EntityName<Entity>, id: Entity[K], options: Omit<GetReferenceOptions, 'key' | 'wrapped'> & {
|
|
378
|
+
key: K;
|
|
379
|
+
wrapped: true;
|
|
380
|
+
}): Ref<Entity>;
|
|
381
|
+
/**
|
|
382
|
+
* Gets a reference to the entity identified by the given type and alternate key property without actually loading it.
|
|
383
|
+
* The key option specifies which property to use for identity map lookup instead of the primary key.
|
|
384
|
+
*/
|
|
385
|
+
getReference<Entity extends object, K extends string & keyof Entity>(entityName: EntityName<Entity>, id: Entity[K], options: Omit<GetReferenceOptions, 'key'> & {
|
|
386
|
+
key: K;
|
|
387
|
+
wrapped?: false;
|
|
388
|
+
}): Entity;
|
|
384
389
|
/**
|
|
385
390
|
* Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
|
|
386
391
|
*/
|
|
387
|
-
getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped'> & {
|
|
392
|
+
getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped' | 'key'> & {
|
|
388
393
|
wrapped: true;
|
|
389
394
|
}): Ref<Entity>;
|
|
390
395
|
/**
|
|
@@ -394,7 +399,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
394
399
|
/**
|
|
395
400
|
* Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
|
|
396
401
|
*/
|
|
397
|
-
getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped'> & {
|
|
402
|
+
getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped' | 'key'> & {
|
|
398
403
|
wrapped: false;
|
|
399
404
|
}): Entity;
|
|
400
405
|
/**
|
|
@@ -410,11 +415,6 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
410
415
|
* The entity will be entered into the database at or before transaction commit or as a result of the flush operation.
|
|
411
416
|
*/
|
|
412
417
|
persist<Entity extends object>(entity: Entity | Reference<Entity> | Iterable<Entity | Reference<Entity>>): this;
|
|
413
|
-
/**
|
|
414
|
-
* Persists your entity immediately, flushing all not yet persisted changes to the database too.
|
|
415
|
-
* Equivalent to `em.persist(e).flush()`.
|
|
416
|
-
*/
|
|
417
|
-
persistAndFlush(entity: AnyEntity | Reference<AnyEntity> | Iterable<AnyEntity | Reference<AnyEntity>>): Promise<void>;
|
|
418
418
|
/**
|
|
419
419
|
* Marks entity for removal.
|
|
420
420
|
* A removed entity will be removed from the database at or before transaction commit or as a result of the flush operation.
|
|
@@ -422,11 +422,6 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
422
422
|
* To remove entities by condition, use `em.nativeDelete()`.
|
|
423
423
|
*/
|
|
424
424
|
remove<Entity extends object>(entity: Entity | Reference<Entity> | Iterable<Entity | Reference<Entity>>): this;
|
|
425
|
-
/**
|
|
426
|
-
* Removes an entity instance immediately, flushing all not yet persisted changes to the database too.
|
|
427
|
-
* Equivalent to `em.remove(e).flush()`
|
|
428
|
-
*/
|
|
429
|
-
removeAndFlush(entity: AnyEntity | Reference<AnyEntity> | Iterable<AnyEntity | Reference<AnyEntity>>): Promise<void>;
|
|
430
425
|
/**
|
|
431
426
|
* Flushes all changes to objects that have been queued up to now to the database.
|
|
432
427
|
* This effectively synchronizes the in-memory state of managed objects with the database.
|
|
@@ -449,7 +444,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
449
444
|
/**
|
|
450
445
|
* Loads specified relations in batch. This will execute one query for each relation, that will populate it on all the specified entities.
|
|
451
446
|
*/
|
|
452
|
-
populate<Entity extends object, Naked extends FromEntityType<UnboxArray<Entity>> = FromEntityType<UnboxArray<Entity>>, Hint extends string = never, Fields extends string =
|
|
447
|
+
populate<Entity extends object, Naked extends FromEntityType<UnboxArray<Entity>> = FromEntityType<UnboxArray<Entity>>, Hint extends string = never, Fields extends string = never, 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>>;
|
|
453
448
|
/**
|
|
454
449
|
* Returns new EntityManager instance with its own identity map
|
|
455
450
|
*/
|
|
@@ -507,7 +502,8 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
507
502
|
private checkLockRequirements;
|
|
508
503
|
private lockAndPopulate;
|
|
509
504
|
private buildFields;
|
|
510
|
-
|
|
505
|
+
/** @internal */
|
|
506
|
+
preparePopulate<Entity extends object>(entityName: EntityName<Entity>, options: Pick<FindOptions<Entity, any, any, any>, 'populate' | 'strategy' | 'fields' | 'flags' | 'filters' | 'exclude' | 'populateHints'>, validate?: boolean): Promise<PopulateOptions<Entity>[]>;
|
|
511
507
|
/**
|
|
512
508
|
* when the entity is found in identity map, we check if it was partially loaded or we are trying to populate
|
|
513
509
|
* some additional lazy properties, if so, we reload and merge the data from database
|
|
@@ -517,20 +513,20 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
517
513
|
/**
|
|
518
514
|
* @internal
|
|
519
515
|
*/
|
|
520
|
-
cacheKey<T extends object>(entityName:
|
|
516
|
+
cacheKey<T extends object>(entityName: EntityName<T>, options: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any> | CountOptions<T, any>, method: string, where: FilterQuery<T>): unknown[];
|
|
521
517
|
/**
|
|
522
518
|
* @internal
|
|
523
519
|
*/
|
|
524
|
-
tryCache<T extends object, R>(entityName:
|
|
520
|
+
tryCache<T extends object, R>(entityName: EntityName<T>, config: boolean | number | [string, number] | undefined, key: unknown, refresh?: boolean, merge?: boolean): Promise<{
|
|
525
521
|
data?: R | null;
|
|
526
522
|
key: string;
|
|
527
523
|
} | undefined>;
|
|
528
524
|
/**
|
|
529
525
|
* @internal
|
|
530
526
|
*/
|
|
531
|
-
storeCache(config: boolean | number | [string, number] | undefined, key: {
|
|
527
|
+
storeCache<T>(config: boolean | number | [string, number] | undefined, key: {
|
|
532
528
|
key: string;
|
|
533
|
-
}, data:
|
|
529
|
+
}, data: T | (() => T)): Promise<void>;
|
|
534
530
|
/**
|
|
535
531
|
* Clears result cache for given cache key. If we want to be able to call this method,
|
|
536
532
|
* we need to set the cache key explicitly when storing the cache.
|
|
@@ -554,13 +550,13 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
554
550
|
* if executed inside request context handler.
|
|
555
551
|
*/
|
|
556
552
|
set schema(schema: string | null | undefined);
|
|
553
|
+
/** @internal */
|
|
554
|
+
getDataLoader(type: 'ref' | '1:m' | 'm:n'): Promise<any>;
|
|
557
555
|
/**
|
|
558
556
|
* Returns the ID of this EntityManager. Respects the context, so global EM will give you the contextual ID
|
|
559
557
|
* if executed inside request context handler.
|
|
560
558
|
*/
|
|
561
559
|
get id(): number;
|
|
562
|
-
/** @ignore */
|
|
563
|
-
[inspect.custom](): string;
|
|
564
560
|
}
|
|
565
561
|
export interface CreateOptions<Convert extends boolean> {
|
|
566
562
|
/** creates a managed entity instance instead, bypassing the constructor call */
|
|
@@ -584,9 +580,8 @@ export interface MergeOptions {
|
|
|
584
580
|
convertCustomTypes?: boolean;
|
|
585
581
|
schema?: string;
|
|
586
582
|
disableContextResolution?: boolean;
|
|
587
|
-
keepIdentity?: boolean;
|
|
588
583
|
validate?: boolean;
|
|
589
|
-
cascade?: boolean
|
|
584
|
+
cascade?: boolean /** @default true */;
|
|
590
585
|
}
|
|
591
586
|
export interface ForkOptions {
|
|
592
587
|
/** do we want a clear identity map? defaults to true */
|
|
@@ -600,7 +595,7 @@ export interface ForkOptions {
|
|
|
600
595
|
/** use this flag to ignore the current async context - this is required if we want to call `em.fork()` inside the `getContext` handler */
|
|
601
596
|
disableContextResolution?: boolean;
|
|
602
597
|
/** set flush mode for this fork, overrides the global option can be overridden locally via FindOptions */
|
|
603
|
-
flushMode?: FlushMode
|
|
598
|
+
flushMode?: FlushMode | `${FlushMode}`;
|
|
604
599
|
/** disable transactions for this fork */
|
|
605
600
|
disableTransactions?: boolean;
|
|
606
601
|
/** should we keep the transaction context of the parent EM? */
|