@mikro-orm/core 7.0.0-dev.3 → 7.0.0-dev.300
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 +114 -63
- package/EntityManager.js +385 -310
- package/MikroORM.d.ts +44 -35
- package/MikroORM.js +109 -143
- package/README.md +3 -2
- package/cache/FileCacheAdapter.d.ts +1 -1
- package/cache/FileCacheAdapter.js +17 -8
- package/cache/GeneratedCacheAdapter.d.ts +0 -1
- package/cache/GeneratedCacheAdapter.js +0 -2
- package/cache/index.d.ts +0 -1
- package/cache/index.js +0 -1
- package/connections/Connection.d.ts +16 -7
- package/connections/Connection.js +23 -14
- package/drivers/DatabaseDriver.d.ts +25 -16
- package/drivers/DatabaseDriver.js +119 -36
- package/drivers/IDatabaseDriver.d.ts +125 -23
- package/entity/BaseEntity.d.ts +63 -4
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +102 -31
- package/entity/Collection.js +446 -108
- package/entity/EntityAssigner.d.ts +1 -1
- package/entity/EntityAssigner.js +26 -18
- package/entity/EntityFactory.d.ts +13 -1
- package/entity/EntityFactory.js +106 -60
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +65 -20
- package/entity/EntityLoader.d.ts +13 -11
- package/entity/EntityLoader.js +257 -107
- 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 +9 -12
- package/entity/Reference.js +34 -9
- package/entity/WrappedEntity.d.ts +3 -8
- package/entity/WrappedEntity.js +3 -8
- package/entity/defineEntity.d.ts +753 -0
- package/entity/defineEntity.js +537 -0
- package/entity/index.d.ts +4 -2
- package/entity/index.js +4 -2
- package/entity/utils.d.ts +13 -1
- package/entity/utils.js +49 -4
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +65 -0
- package/enums.d.ts +23 -8
- package/enums.js +15 -1
- package/errors.d.ts +25 -9
- package/errors.js +67 -21
- package/events/EventManager.d.ts +2 -1
- package/events/EventManager.js +19 -11
- package/events/EventSubscriber.d.ts +3 -1
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +4 -4
- package/hydration/ObjectHydrator.js +89 -36
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +1 -0
- package/logging/SimpleLogger.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +7 -6
- package/logging/index.d.ts +1 -0
- package/logging/index.js +1 -0
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +11 -0
- package/metadata/EntitySchema.d.ts +53 -27
- package/metadata/EntitySchema.js +125 -52
- package/metadata/MetadataDiscovery.d.ts +64 -10
- package/metadata/MetadataDiscovery.js +823 -344
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +66 -2
- package/metadata/MetadataStorage.d.ts +13 -11
- package/metadata/MetadataStorage.js +71 -38
- package/metadata/MetadataValidator.d.ts +32 -9
- package/metadata/MetadataValidator.js +198 -42
- 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 +1 -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 +20 -2
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
- 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/not-supported.d.ts +2 -0
- package/not-supported.js +4 -0
- package/package.json +22 -11
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +14 -16
- package/platforms/Platform.js +24 -44
- package/serialization/EntitySerializer.d.ts +8 -3
- package/serialization/EntitySerializer.js +47 -27
- package/serialization/EntityTransformer.js +33 -21
- package/serialization/SerializationContext.d.ts +6 -6
- package/serialization/SerializationContext.js +16 -13
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.d.ts +9 -6
- package/types/BigIntType.js +4 -1
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +2 -1
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.d.ts +6 -4
- package/types/DecimalType.js +3 -3
- package/types/DoubleType.js +2 -2
- 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/index.d.ts +1 -1
- package/typings.d.ts +469 -175
- package/typings.js +120 -45
- package/unit-of-work/ChangeSet.d.ts +4 -6
- package/unit-of-work/ChangeSet.js +4 -5
- package/unit-of-work/ChangeSetComputer.d.ts +3 -8
- package/unit-of-work/ChangeSetComputer.js +44 -21
- package/unit-of-work/ChangeSetPersister.d.ts +15 -12
- package/unit-of-work/ChangeSetPersister.js +113 -45
- package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
- package/unit-of-work/CommitOrderCalculator.js +13 -13
- package/unit-of-work/IdentityMap.d.ts +12 -0
- package/unit-of-work/IdentityMap.js +39 -1
- package/unit-of-work/UnitOfWork.d.ts +28 -3
- package/unit-of-work/UnitOfWork.js +315 -110
- package/utils/AbstractMigrator.d.ts +101 -0
- package/utils/AbstractMigrator.js +305 -0
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +32 -18
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +801 -207
- package/utils/Configuration.js +150 -191
- package/utils/ConfigurationLoader.d.ts +1 -54
- package/utils/ConfigurationLoader.js +1 -352
- package/utils/Cursor.d.ts +3 -6
- package/utils/Cursor.js +27 -11
- package/utils/DataloaderUtils.d.ts +15 -5
- package/utils/DataloaderUtils.js +65 -17
- package/utils/EntityComparator.d.ts +21 -10
- package/utils/EntityComparator.js +243 -106
- package/utils/QueryHelper.d.ts +24 -6
- package/utils/QueryHelper.js +122 -26
- package/utils/RawQueryFragment.d.ts +60 -32
- package/utils/RawQueryFragment.js +69 -66
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +223 -0
- package/utils/Utils.d.ts +15 -122
- package/utils/Utils.js +108 -376
- package/utils/clone.js +8 -23
- package/utils/env-vars.d.ts +7 -0
- package/utils/env-vars.js +97 -0
- package/utils/fs-utils.d.ts +34 -0
- package/utils/fs-utils.js +196 -0
- package/utils/index.d.ts +2 -3
- package/utils/index.js +2 -3
- package/utils/upsert-utils.d.ts +9 -4
- package/utils/upsert-utils.js +55 -4
- 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 -18
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -18
- package/decorators/Entity.js +0 -13
- 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 -5
- package/decorators/Formula.js +0 -15
- package/decorators/Indexed.d.ts +0 -17
- package/decorators/Indexed.js +0 -20
- package/decorators/ManyToMany.d.ts +0 -40
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -30
- 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 -24
- package/decorators/OneToOne.js +0 -7
- package/decorators/PrimaryKey.d.ts +0 -9
- 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 -13
- 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 -116
- package/entity/ArrayCollection.js +0 -395
- 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
|
-
import { type EntityLoaderOptions } from './entity/EntityLoader.js';
|
|
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';
|
|
@@ -27,13 +24,13 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
27
24
|
protected readonly metadata: MetadataStorage;
|
|
28
25
|
protected readonly useContext: boolean;
|
|
29
26
|
protected readonly eventManager: EventManager;
|
|
27
|
+
/** @internal */
|
|
28
|
+
readonly '~entities'?: unknown;
|
|
30
29
|
private static counter;
|
|
31
30
|
readonly _id: number;
|
|
32
31
|
readonly global = false;
|
|
33
32
|
readonly name: string;
|
|
34
|
-
|
|
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
|
-
private readonly validator;
|
|
33
|
+
private readonly loaders;
|
|
37
34
|
private readonly repositoryMap;
|
|
38
35
|
private readonly entityLoader;
|
|
39
36
|
protected readonly comparator: EntityComparator;
|
|
@@ -72,14 +69,28 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
72
69
|
* Shortcut for `em.getRepository()`.
|
|
73
70
|
*/
|
|
74
71
|
repo<Entity extends object, Repository extends EntityRepository<Entity> = EntityRepository<Entity>>(entityName: EntityName<Entity>): GetRepository<Entity, Repository>;
|
|
75
|
-
/**
|
|
76
|
-
* Gets EntityValidator instance
|
|
77
|
-
*/
|
|
78
|
-
getValidator(): EntityValidator;
|
|
79
72
|
/**
|
|
80
73
|
* Finds all entities matching your `where` query. You can pass additional options via the `options` parameter.
|
|
81
74
|
*/
|
|
82
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>>;
|
|
83
94
|
/**
|
|
84
95
|
* Finds all entities of given type, optionally matching the `where` condition provided in the `options` parameter.
|
|
85
96
|
*/
|
|
@@ -88,19 +99,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
88
99
|
/**
|
|
89
100
|
* Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
|
|
90
101
|
*/
|
|
91
|
-
addFilter<
|
|
92
|
-
/**
|
|
93
|
-
* Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
|
|
94
|
-
*/
|
|
95
|
-
addFilter<T1, T2>(name: string, cond: FilterQuery<T1 | T2> | ((args: Dictionary) => MaybePromise<FilterQuery<T1 | T2>>), entityName?: [EntityName<T1>, EntityName<T2>], enabled?: boolean): void;
|
|
96
|
-
/**
|
|
97
|
-
* Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
|
|
98
|
-
*/
|
|
99
|
-
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;
|
|
100
|
-
/**
|
|
101
|
-
* Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
|
|
102
|
-
*/
|
|
103
|
-
addFilter(name: string, cond: Dictionary | ((args: Dictionary) => MaybePromise<FilterQuery<AnyEntity>>), entityName?: EntityName<AnyEntity> | EntityName<AnyEntity>[], enabled?: boolean): void;
|
|
102
|
+
addFilter<T extends EntityName | readonly EntityName[]>(options: FilterDef<T>): void;
|
|
104
103
|
/**
|
|
105
104
|
* Sets filter parameter values globally inside context defined by this entity manager.
|
|
106
105
|
* If you want to set shared value for all contexts, be sure to use the root entity manager.
|
|
@@ -117,20 +116,26 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
117
116
|
/**
|
|
118
117
|
* Gets logger context for this entity manager.
|
|
119
118
|
*/
|
|
120
|
-
getLoggerContext<T extends Dictionary = Dictionary>(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
getLoggerContext<T extends Dictionary = Dictionary>(options?: {
|
|
120
|
+
disableContextResolution?: boolean;
|
|
121
|
+
}): T;
|
|
122
|
+
setFlushMode(flushMode?: FlushMode | `${FlushMode}`): void;
|
|
123
|
+
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>>;
|
|
124
|
+
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>;
|
|
125
|
+
protected applyDiscriminatorCondition<Entity extends object>(entityName: EntityName<Entity>, where: FilterQuery<Entity>): FilterQuery<Entity>;
|
|
124
126
|
protected createPopulateWhere<Entity extends object>(cond: ObjectQuery<Entity>, options: FindOptions<Entity, any, any, any> | FindOneOptions<Entity, any, any, any> | CountOptions<Entity, any>): ObjectQuery<Entity>;
|
|
125
|
-
protected getJoinedFilters<Entity extends object>(meta: EntityMetadata<Entity>,
|
|
127
|
+
protected getJoinedFilters<Entity extends object>(meta: EntityMetadata<Entity>, options: FindOptions<Entity, any, any, any> | FindOneOptions<Entity, any, any, any>): Promise<ObjectQuery<Entity> | undefined>;
|
|
126
128
|
/**
|
|
127
129
|
* 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.
|
|
128
130
|
*/
|
|
129
|
-
protected autoJoinRefsForFilters<T extends object>(meta: EntityMetadata<T>, options: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any
|
|
131
|
+
protected autoJoinRefsForFilters<T extends object>(meta: EntityMetadata<T>, options: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any>, parent?: {
|
|
132
|
+
class: EntityClass;
|
|
133
|
+
propName: string;
|
|
134
|
+
}): Promise<void>;
|
|
130
135
|
/**
|
|
131
136
|
* @internal
|
|
132
137
|
*/
|
|
133
|
-
applyFilters<Entity extends object>(entityName:
|
|
138
|
+
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>;
|
|
134
139
|
/**
|
|
135
140
|
* Calls `em.find()` and `em.count()` with the same arguments (where applicable) and returns the results as tuple
|
|
136
141
|
* where the first element is the array of entities, and the second is the count.
|
|
@@ -150,27 +155,31 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
150
155
|
* - POJO/entity instance
|
|
151
156
|
*
|
|
152
157
|
* ```ts
|
|
153
|
-
* const currentCursor = await em.findByCursor(User, {
|
|
158
|
+
* const currentCursor = await em.findByCursor(User, {
|
|
154
159
|
* first: 10,
|
|
155
160
|
* after: previousCursor, // cursor instance
|
|
156
161
|
* orderBy: { id: 'desc' },
|
|
157
162
|
* });
|
|
158
163
|
*
|
|
159
164
|
* // to fetch next page
|
|
160
|
-
* const nextCursor = await em.findByCursor(User, {
|
|
165
|
+
* const nextCursor = await em.findByCursor(User, {
|
|
161
166
|
* first: 10,
|
|
162
167
|
* after: currentCursor.endCursor, // opaque string
|
|
163
168
|
* orderBy: { id: 'desc' },
|
|
164
169
|
* });
|
|
165
170
|
*
|
|
166
171
|
* // to fetch next page
|
|
167
|
-
* const nextCursor2 = await em.findByCursor(User, {
|
|
172
|
+
* const nextCursor2 = await em.findByCursor(User, {
|
|
168
173
|
* first: 10,
|
|
169
174
|
* after: { id: lastSeenId }, // entity-like POJO
|
|
170
175
|
* orderBy: { id: 'desc' },
|
|
171
176
|
* });
|
|
172
177
|
* ```
|
|
173
178
|
*
|
|
179
|
+
* The options also support an `includeCount` (true by default) option. If set to false, the `totalCount` is not
|
|
180
|
+
* returned as part of the cursor. This is useful for performance reason, when you don't care about the total number
|
|
181
|
+
* of pages.
|
|
182
|
+
*
|
|
174
183
|
* The `Cursor` object provides the following interface:
|
|
175
184
|
*
|
|
176
185
|
* ```ts
|
|
@@ -180,7 +189,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
180
189
|
* User { ... },
|
|
181
190
|
* User { ... },
|
|
182
191
|
* ],
|
|
183
|
-
* totalCount: 50,
|
|
192
|
+
* totalCount: 50, // not included if `includeCount: false`
|
|
184
193
|
* startCursor: 'WzRd',
|
|
185
194
|
* endCursor: 'WzZd',
|
|
186
195
|
* hasPrevPage: true,
|
|
@@ -188,7 +197,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
188
197
|
* }
|
|
189
198
|
* ```
|
|
190
199
|
*/
|
|
191
|
-
findByCursor<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName: EntityName<Entity>,
|
|
200
|
+
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>>;
|
|
192
201
|
/**
|
|
193
202
|
* Refreshes the persistent state of an entity from the database, overriding any local changes that have not yet been
|
|
194
203
|
* persisted. Returns the same entity instance (same object reference), but re-hydrated. If the entity is no longer
|
|
@@ -263,6 +272,29 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
263
272
|
upsertMany<Entity extends object, Fields extends string = any>(entityNameOrEntity: EntityName<Entity> | Entity[], data?: (EntityData<Entity> | NoInfer<Entity>)[], options?: UpsertManyOptions<Entity, Fields>): Promise<Entity[]>;
|
|
264
273
|
/**
|
|
265
274
|
* Runs your callback wrapped inside a database transaction.
|
|
275
|
+
*
|
|
276
|
+
* If a transaction is already active, a new savepoint (nested transaction) will be created by default. This behavior
|
|
277
|
+
* can be controlled via the `propagation` option. Use the provided EntityManager instance for all operations that
|
|
278
|
+
* should be part of the transaction. You can safely use a global EntityManager instance from a DI container, as this
|
|
279
|
+
* method automatically creates an async context for the transaction.
|
|
280
|
+
*
|
|
281
|
+
* **Concurrency note:** When running multiple transactions concurrently (e.g. in parallel requests or jobs), use the
|
|
282
|
+
* `clear: true` option. This ensures the callback runs in a clear fork of the EntityManager, providing full isolation
|
|
283
|
+
* between concurrent transactional handlers. Using `clear: true` is an alternative to forking explicitly and calling
|
|
284
|
+
* the method on the new fork – it already provides the necessary isolation for safe concurrent usage.
|
|
285
|
+
*
|
|
286
|
+
* **Propagation note:** Changes made within a transaction (whether top-level or nested) are always propagated to the
|
|
287
|
+
* parent context, unless the parent context is a global one. If you want to avoid that, fork the EntityManager first
|
|
288
|
+
* and then call this method on the fork.
|
|
289
|
+
*
|
|
290
|
+
* **Example:**
|
|
291
|
+
* ```ts
|
|
292
|
+
* await em.transactional(async (em) => {
|
|
293
|
+
* const author = new Author('Jon');
|
|
294
|
+
* em.persist(author);
|
|
295
|
+
* // flush is called automatically at the end of the callback
|
|
296
|
+
* });
|
|
297
|
+
* ```
|
|
266
298
|
*/
|
|
267
299
|
transactional<T>(cb: (em: this) => T | Promise<T>, options?: TransactionOptions): Promise<T>;
|
|
268
300
|
/**
|
|
@@ -328,7 +360,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
328
360
|
* The newly created entity will be automatically marked for persistence via `em.persist` unless you disable this
|
|
329
361
|
* behavior, either locally via `persist: false` option, or globally via `persistOnCreate` ORM config option.
|
|
330
362
|
*/
|
|
331
|
-
create<Entity extends object, Convert extends boolean = false>(entityName: EntityName<Entity>, data: RequiredEntityData<Entity, never, Convert>, options?: CreateOptions<Convert>): Entity;
|
|
363
|
+
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;
|
|
332
364
|
/**
|
|
333
365
|
* Creates new instance of given entity and populates it with given data.
|
|
334
366
|
* The entity constructor will be used unless you provide `{ managed: true }` in the `options` parameter.
|
|
@@ -344,17 +376,33 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
344
376
|
* The newly created entity will be automatically marked for persistence via `em.persist` unless you disable this
|
|
345
377
|
* behavior, either locally via `persist: false` option, or globally via `persistOnCreate` ORM config option.
|
|
346
378
|
*/
|
|
347
|
-
create<Entity extends object, Convert extends boolean = false>(entityName: EntityName<Entity>, data: EntityData<Entity, Convert>, options: CreateOptions<Convert> & {
|
|
379
|
+
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> & {
|
|
348
380
|
partial: true;
|
|
349
381
|
}): Entity;
|
|
350
382
|
/**
|
|
351
383
|
* Shortcut for `wrap(entity).assign(data, { em })`
|
|
352
384
|
*/
|
|
353
385
|
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>;
|
|
386
|
+
/**
|
|
387
|
+
* Gets a reference to the entity identified by the given type and alternate key property without actually loading it.
|
|
388
|
+
* The key option specifies which property to use for identity map lookup instead of the primary key.
|
|
389
|
+
*/
|
|
390
|
+
getReference<Entity extends object, K extends string & keyof Entity>(entityName: EntityName<Entity>, id: Entity[K], options: Omit<GetReferenceOptions, 'key' | 'wrapped'> & {
|
|
391
|
+
key: K;
|
|
392
|
+
wrapped: true;
|
|
393
|
+
}): Ref<Entity>;
|
|
394
|
+
/**
|
|
395
|
+
* Gets a reference to the entity identified by the given type and alternate key property without actually loading it.
|
|
396
|
+
* The key option specifies which property to use for identity map lookup instead of the primary key.
|
|
397
|
+
*/
|
|
398
|
+
getReference<Entity extends object, K extends string & keyof Entity>(entityName: EntityName<Entity>, id: Entity[K], options: Omit<GetReferenceOptions, 'key'> & {
|
|
399
|
+
key: K;
|
|
400
|
+
wrapped?: false;
|
|
401
|
+
}): Entity;
|
|
354
402
|
/**
|
|
355
403
|
* Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
|
|
356
404
|
*/
|
|
357
|
-
getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped'> & {
|
|
405
|
+
getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped' | 'key'> & {
|
|
358
406
|
wrapped: true;
|
|
359
407
|
}): Ref<Entity>;
|
|
360
408
|
/**
|
|
@@ -364,7 +412,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
364
412
|
/**
|
|
365
413
|
* Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
|
|
366
414
|
*/
|
|
367
|
-
getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped'> & {
|
|
415
|
+
getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped' | 'key'> & {
|
|
368
416
|
wrapped: false;
|
|
369
417
|
}): Entity;
|
|
370
418
|
/**
|
|
@@ -380,11 +428,6 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
380
428
|
* The entity will be entered into the database at or before transaction commit or as a result of the flush operation.
|
|
381
429
|
*/
|
|
382
430
|
persist<Entity extends object>(entity: Entity | Reference<Entity> | Iterable<Entity | Reference<Entity>>): this;
|
|
383
|
-
/**
|
|
384
|
-
* Persists your entity immediately, flushing all not yet persisted changes to the database too.
|
|
385
|
-
* Equivalent to `em.persist(e).flush()`.
|
|
386
|
-
*/
|
|
387
|
-
persistAndFlush(entity: AnyEntity | Reference<AnyEntity> | Iterable<AnyEntity | Reference<AnyEntity>>): Promise<void>;
|
|
388
431
|
/**
|
|
389
432
|
* Marks entity for removal.
|
|
390
433
|
* A removed entity will be removed from the database at or before transaction commit or as a result of the flush operation.
|
|
@@ -392,11 +435,6 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
392
435
|
* To remove entities by condition, use `em.nativeDelete()`.
|
|
393
436
|
*/
|
|
394
437
|
remove<Entity extends object>(entity: Entity | Reference<Entity> | Iterable<Entity | Reference<Entity>>): this;
|
|
395
|
-
/**
|
|
396
|
-
* Removes an entity instance immediately, flushing all not yet persisted changes to the database too.
|
|
397
|
-
* Equivalent to `em.remove(e).flush()`
|
|
398
|
-
*/
|
|
399
|
-
removeAndFlush(entity: AnyEntity | Reference<AnyEntity> | Iterable<AnyEntity | Reference<AnyEntity>>): Promise<void>;
|
|
400
438
|
/**
|
|
401
439
|
* Flushes all changes to objects that have been queued up to now to the database.
|
|
402
440
|
* This effectively synchronizes the in-memory state of managed objects with the database.
|
|
@@ -419,7 +457,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
419
457
|
/**
|
|
420
458
|
* Loads specified relations in batch. This will execute one query for each relation, that will populate it on all the specified entities.
|
|
421
459
|
*/
|
|
422
|
-
populate<Entity extends object, Naked extends FromEntityType<UnboxArray<Entity>> = FromEntityType<UnboxArray<Entity>>, Hint extends string = never, Fields extends string =
|
|
460
|
+
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>>;
|
|
423
461
|
/**
|
|
424
462
|
* Returns new EntityManager instance with its own identity map
|
|
425
463
|
*/
|
|
@@ -432,6 +470,10 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
432
470
|
* Gets the EntityFactory used by the EntityManager.
|
|
433
471
|
*/
|
|
434
472
|
getEntityFactory(): EntityFactory;
|
|
473
|
+
/**
|
|
474
|
+
* @internal use `em.populate()` as the user facing API, this is exposed only for internal usage
|
|
475
|
+
*/
|
|
476
|
+
getEntityLoader(): EntityLoader;
|
|
435
477
|
/**
|
|
436
478
|
* Gets the Hydrator used by the EntityManager.
|
|
437
479
|
*/
|
|
@@ -473,30 +515,31 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
473
515
|
private checkLockRequirements;
|
|
474
516
|
private lockAndPopulate;
|
|
475
517
|
private buildFields;
|
|
476
|
-
|
|
518
|
+
/** @internal */
|
|
519
|
+
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>[]>;
|
|
477
520
|
/**
|
|
478
521
|
* when the entity is found in identity map, we check if it was partially loaded or we are trying to populate
|
|
479
522
|
* some additional lazy properties, if so, we reload and merge the data from database
|
|
480
523
|
*/
|
|
481
524
|
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;
|
|
482
|
-
protected prepareOptions(options: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any>): void;
|
|
525
|
+
protected prepareOptions(options: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any> | CountOptions<any, any>): void;
|
|
483
526
|
/**
|
|
484
527
|
* @internal
|
|
485
528
|
*/
|
|
486
|
-
cacheKey<T extends object>(entityName:
|
|
529
|
+
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[];
|
|
487
530
|
/**
|
|
488
531
|
* @internal
|
|
489
532
|
*/
|
|
490
|
-
tryCache<T extends object, R>(entityName:
|
|
491
|
-
data?: R;
|
|
533
|
+
tryCache<T extends object, R>(entityName: EntityName<T>, config: boolean | number | [string, number] | undefined, key: unknown, refresh?: boolean, merge?: boolean): Promise<{
|
|
534
|
+
data?: R | null;
|
|
492
535
|
key: string;
|
|
493
536
|
} | undefined>;
|
|
494
537
|
/**
|
|
495
538
|
* @internal
|
|
496
539
|
*/
|
|
497
|
-
storeCache(config: boolean | number | [string, number] | undefined, key: {
|
|
540
|
+
storeCache<T>(config: boolean | number | [string, number] | undefined, key: {
|
|
498
541
|
key: string;
|
|
499
|
-
}, data:
|
|
542
|
+
}, data: T | (() => T)): Promise<void>;
|
|
500
543
|
/**
|
|
501
544
|
* Clears result cache for given cache key. If we want to be able to call this method,
|
|
502
545
|
* we need to set the cache key explicitly when storing the cache.
|
|
@@ -520,13 +563,13 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
520
563
|
* if executed inside request context handler.
|
|
521
564
|
*/
|
|
522
565
|
set schema(schema: string | null | undefined);
|
|
566
|
+
/** @internal */
|
|
567
|
+
getDataLoader(type: 'ref' | '1:m' | 'm:n'): Promise<any>;
|
|
523
568
|
/**
|
|
524
569
|
* Returns the ID of this EntityManager. Respects the context, so global EM will give you the contextual ID
|
|
525
570
|
* if executed inside request context handler.
|
|
526
571
|
*/
|
|
527
572
|
get id(): number;
|
|
528
|
-
/** @ignore */
|
|
529
|
-
[inspect.custom](): string;
|
|
530
573
|
}
|
|
531
574
|
export interface CreateOptions<Convert extends boolean> {
|
|
532
575
|
/** creates a managed entity instance instead, bypassing the constructor call */
|
|
@@ -539,11 +582,19 @@ export interface CreateOptions<Convert extends boolean> {
|
|
|
539
582
|
partial?: boolean;
|
|
540
583
|
/** convert raw database values based on mapped types (by default, already converted values are expected) */
|
|
541
584
|
convertCustomTypes?: Convert;
|
|
585
|
+
/**
|
|
586
|
+
* Property `onCreate` hooks are normally executed during `flush` operation.
|
|
587
|
+
* With this option, they will be processed early inside `em.create()` method.
|
|
588
|
+
*/
|
|
589
|
+
processOnCreateHooksEarly?: boolean;
|
|
542
590
|
}
|
|
543
591
|
export interface MergeOptions {
|
|
544
592
|
refresh?: boolean;
|
|
545
593
|
convertCustomTypes?: boolean;
|
|
546
594
|
schema?: string;
|
|
595
|
+
disableContextResolution?: boolean;
|
|
596
|
+
validate?: boolean;
|
|
597
|
+
cascade?: boolean; /** @default true */
|
|
547
598
|
}
|
|
548
599
|
export interface ForkOptions {
|
|
549
600
|
/** do we want a clear identity map? defaults to true */
|
|
@@ -557,7 +608,7 @@ export interface ForkOptions {
|
|
|
557
608
|
/** use this flag to ignore the current async context - this is required if we want to call `em.fork()` inside the `getContext` handler */
|
|
558
609
|
disableContextResolution?: boolean;
|
|
559
610
|
/** set flush mode for this fork, overrides the global option can be overridden locally via FindOptions */
|
|
560
|
-
flushMode?: FlushMode
|
|
611
|
+
flushMode?: FlushMode | `${FlushMode}`;
|
|
561
612
|
/** disable transactions for this fork */
|
|
562
613
|
disableTransactions?: boolean;
|
|
563
614
|
/** should we keep the transaction context of the parent EM? */
|