@mikro-orm/core 7.0.0-dev.8 → 7.0.0-dev.80
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 +85 -48
- package/EntityManager.js +300 -225
- package/MikroORM.d.ts +40 -31
- package/MikroORM.js +98 -137
- package/README.md +3 -2
- package/cache/FileCacheAdapter.d.ts +1 -1
- package/cache/FileCacheAdapter.js +6 -5
- 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 +11 -7
- package/connections/Connection.js +16 -14
- package/drivers/DatabaseDriver.d.ts +11 -5
- package/drivers/DatabaseDriver.js +17 -8
- package/drivers/IDatabaseDriver.d.ts +27 -5
- package/entity/BaseEntity.d.ts +0 -1
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +98 -30
- package/entity/Collection.js +432 -93
- package/entity/EntityAssigner.d.ts +1 -1
- package/entity/EntityAssigner.js +15 -7
- package/entity/EntityFactory.d.ts +7 -0
- package/entity/EntityFactory.js +64 -41
- package/entity/EntityHelper.js +26 -9
- package/entity/EntityLoader.d.ts +5 -4
- package/entity/EntityLoader.js +73 -40
- package/entity/EntityRepository.d.ts +1 -1
- package/entity/Reference.d.ts +9 -7
- package/entity/Reference.js +33 -6
- package/entity/WrappedEntity.d.ts +2 -4
- package/entity/WrappedEntity.js +1 -5
- package/entity/defineEntity.d.ts +549 -0
- package/entity/defineEntity.js +529 -0
- package/entity/index.d.ts +3 -2
- package/entity/index.js +3 -2
- package/entity/utils.d.ts +7 -0
- package/entity/utils.js +16 -4
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +65 -0
- package/enums.d.ts +21 -6
- package/enums.js +14 -1
- package/errors.d.ts +6 -2
- package/errors.js +14 -9
- package/events/EventSubscriber.d.ts +3 -1
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +4 -4
- package/hydration/ObjectHydrator.js +36 -25
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/SimpleLogger.d.ts +1 -1
- package/metadata/EntitySchema.d.ts +9 -13
- package/metadata/EntitySchema.js +44 -26
- package/metadata/MetadataDiscovery.d.ts +6 -9
- package/metadata/MetadataDiscovery.js +167 -206
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +44 -2
- package/metadata/MetadataStorage.d.ts +1 -6
- package/metadata/MetadataStorage.js +6 -18
- package/metadata/MetadataValidator.d.ts +0 -7
- package/metadata/MetadataValidator.js +4 -13
- 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 +480 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +5 -1
- package/naming-strategy/AbstractNamingStrategy.js +8 -2
- package/naming-strategy/NamingStrategy.d.ts +11 -1
- package/not-supported.d.ts +2 -0
- package/not-supported.js +4 -0
- package/package.json +18 -10
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +6 -10
- package/platforms/Platform.js +14 -39
- package/serialization/EntitySerializer.d.ts +2 -0
- package/serialization/EntitySerializer.js +32 -14
- package/serialization/EntityTransformer.js +22 -12
- package/serialization/SerializationContext.js +16 -13
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.d.ts +8 -6
- package/types/BigIntType.js +1 -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/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/TinyIntType.js +1 -1
- package/types/Type.d.ts +2 -1
- package/types/Type.js +1 -1
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +1 -4
- package/types/index.d.ts +1 -1
- package/typings.d.ts +113 -77
- package/typings.js +41 -35
- package/unit-of-work/ChangeSetComputer.d.ts +1 -3
- package/unit-of-work/ChangeSetComputer.js +11 -9
- package/unit-of-work/ChangeSetPersister.d.ts +5 -4
- package/unit-of-work/ChangeSetPersister.js +58 -20
- package/unit-of-work/UnitOfWork.d.ts +8 -1
- package/unit-of-work/UnitOfWork.js +115 -57
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +11 -9
- package/utils/Configuration.d.ts +757 -206
- package/utils/Configuration.js +139 -187
- package/utils/ConfigurationLoader.d.ts +1 -54
- package/utils/ConfigurationLoader.js +1 -352
- package/utils/Cursor.d.ts +3 -3
- package/utils/Cursor.js +4 -1
- package/utils/DataloaderUtils.d.ts +15 -5
- package/utils/DataloaderUtils.js +54 -8
- package/utils/EntityComparator.d.ts +8 -4
- package/utils/EntityComparator.js +111 -64
- package/utils/QueryHelper.d.ts +9 -1
- package/utils/QueryHelper.js +70 -9
- package/utils/RawQueryFragment.d.ts +36 -4
- package/utils/RawQueryFragment.js +35 -14
- package/utils/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +223 -0
- package/utils/Utils.d.ts +8 -97
- package/utils/Utils.js +88 -303
- package/utils/clone.js +2 -3
- 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 +96 -0
- package/utils/index.d.ts +2 -1
- package/utils/index.js +2 -1
- package/utils/upsert-utils.d.ts +7 -2
- 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 -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 -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 -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 -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 -402
- 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,14 @@
|
|
|
1
1
|
import { inspect } from 'node:util';
|
|
2
|
-
import DataLoader from 'dataloader';
|
|
3
2
|
import { type Configuration } from './utils/Configuration.js';
|
|
4
3
|
import { Cursor } from './utils/Cursor.js';
|
|
5
4
|
import { EntityFactory } from './entity/EntityFactory.js';
|
|
6
5
|
import { type AssignOptions } from './entity/EntityAssigner.js';
|
|
7
|
-
import { EntityValidator } from './entity/EntityValidator.js';
|
|
8
6
|
import { type EntityRepository } from './entity/EntityRepository.js';
|
|
9
|
-
import { type EntityLoaderOptions } from './entity/EntityLoader.js';
|
|
7
|
+
import { EntityLoader, type EntityLoaderOptions } from './entity/EntityLoader.js';
|
|
10
8
|
import { Reference } from './entity/Reference.js';
|
|
11
9
|
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 {
|
|
10
|
+
import type { CountOptions, DeleteOptions, FilterOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions, GetReferenceOptions, IDatabaseDriver, LockOptions, NativeInsertUpdateOptions, StreamOptions, UpdateOptions, UpsertManyOptions, UpsertOptions } from './drivers/IDatabaseDriver.js';
|
|
11
|
+
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';
|
|
14
12
|
import { FlushMode, LockMode, PopulatePath, type TransactionOptions } from './enums.js';
|
|
15
13
|
import type { MetadataStorage } from './metadata/MetadataStorage.js';
|
|
16
14
|
import type { Transaction } from './connections/Connection.js';
|
|
@@ -27,13 +25,13 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
27
25
|
protected readonly metadata: MetadataStorage;
|
|
28
26
|
protected readonly useContext: boolean;
|
|
29
27
|
protected readonly eventManager: EventManager;
|
|
28
|
+
/** @internal */
|
|
29
|
+
readonly '~entities'?: unknown;
|
|
30
30
|
private static counter;
|
|
31
31
|
readonly _id: number;
|
|
32
32
|
readonly global = false;
|
|
33
33
|
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;
|
|
34
|
+
private readonly loaders;
|
|
37
35
|
private readonly repositoryMap;
|
|
38
36
|
private readonly entityLoader;
|
|
39
37
|
protected readonly comparator: EntityComparator;
|
|
@@ -72,14 +70,28 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
72
70
|
* Shortcut for `em.getRepository()`.
|
|
73
71
|
*/
|
|
74
72
|
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
73
|
/**
|
|
80
74
|
* Finds all entities matching your `where` query. You can pass additional options via the `options` parameter.
|
|
81
75
|
*/
|
|
82
76
|
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>[]>;
|
|
77
|
+
/**
|
|
78
|
+
* Finds all entities and returns an async iterable (async generator) that yields results one by one.
|
|
79
|
+
* The results are merged and mapped to entity instances, without adding them to the identity map.
|
|
80
|
+
* You can disable merging by passing the options `{ mergeResults: false }`.
|
|
81
|
+
* With `mergeResults` disabled, to-many collections will contain at most one item, and you will get duplicate
|
|
82
|
+
* root entities when there are multiple items in the populated collection.
|
|
83
|
+
* This is useful for processing large datasets without loading everything into memory at once.
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* const stream = em.stream(Book, { populate: ['author'] });
|
|
87
|
+
*
|
|
88
|
+
* for await (const book of stream) {
|
|
89
|
+
* // book is an instance of Book entity
|
|
90
|
+
* console.log(book.title, book.author.name);
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
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
95
|
/**
|
|
84
96
|
* Finds all entities of given type, optionally matching the `where` condition provided in the `options` parameter.
|
|
85
97
|
*/
|
|
@@ -88,19 +100,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
88
100
|
/**
|
|
89
101
|
* Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
|
|
90
102
|
*/
|
|
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;
|
|
103
|
+
addFilter<T extends EntityName<any> | readonly EntityName<any>[]>(options: FilterDef<T>): void;
|
|
104
104
|
/**
|
|
105
105
|
* Sets filter parameter values globally inside context defined by this entity manager.
|
|
106
106
|
* If you want to set shared value for all contexts, be sure to use the root entity manager.
|
|
@@ -117,20 +117,25 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
117
117
|
/**
|
|
118
118
|
* Gets logger context for this entity manager.
|
|
119
119
|
*/
|
|
120
|
-
getLoggerContext<T extends Dictionary = Dictionary>(
|
|
121
|
-
|
|
120
|
+
getLoggerContext<T extends Dictionary = Dictionary>(options?: {
|
|
121
|
+
disableContextResolution?: boolean;
|
|
122
|
+
}): T;
|
|
123
|
+
setFlushMode(flushMode?: FlushMode | `${FlushMode}`): void;
|
|
122
124
|
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>>;
|
|
123
125
|
protected applyDiscriminatorCondition<Entity extends object>(entityName: string, 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
|
+
className: string;
|
|
133
|
+
propName: string;
|
|
134
|
+
}): Promise<void>;
|
|
130
135
|
/**
|
|
131
136
|
* @internal
|
|
132
137
|
*/
|
|
133
|
-
applyFilters<Entity extends object>(entityName: string, where: FilterQuery<Entity> | undefined, options:
|
|
138
|
+
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>;
|
|
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.
|
|
@@ -171,6 +176,10 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
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>, where: FilterQuery<NoInfer<Entity>>, options: FindByCursorOptions<Entity, Hint, Fields, Excludes>): Promise<Cursor<Entity, Hint, Fields, Excludes>>;
|
|
200
|
+
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>>;
|
|
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
|
/**
|
|
@@ -380,11 +412,6 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
380
412
|
* The entity will be entered into the database at or before transaction commit or as a result of the flush operation.
|
|
381
413
|
*/
|
|
382
414
|
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
415
|
/**
|
|
389
416
|
* Marks entity for removal.
|
|
390
417
|
* A removed entity will be removed from the database at or before transaction commit or as a result of the flush operation.
|
|
@@ -392,11 +419,6 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
392
419
|
* To remove entities by condition, use `em.nativeDelete()`.
|
|
393
420
|
*/
|
|
394
421
|
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
422
|
/**
|
|
401
423
|
* Flushes all changes to objects that have been queued up to now to the database.
|
|
402
424
|
* This effectively synchronizes the in-memory state of managed objects with the database.
|
|
@@ -419,7 +441,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
419
441
|
/**
|
|
420
442
|
* Loads specified relations in batch. This will execute one query for each relation, that will populate it on all the specified entities.
|
|
421
443
|
*/
|
|
422
|
-
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>>;
|
|
444
|
+
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>>;
|
|
423
445
|
/**
|
|
424
446
|
* Returns new EntityManager instance with its own identity map
|
|
425
447
|
*/
|
|
@@ -432,6 +454,10 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
432
454
|
* Gets the EntityFactory used by the EntityManager.
|
|
433
455
|
*/
|
|
434
456
|
getEntityFactory(): EntityFactory;
|
|
457
|
+
/**
|
|
458
|
+
* @internal use `em.populate()` as the user facing API, this is exposed only for internal usage
|
|
459
|
+
*/
|
|
460
|
+
getEntityLoader(): EntityLoader;
|
|
435
461
|
/**
|
|
436
462
|
* Gets the Hydrator used by the EntityManager.
|
|
437
463
|
*/
|
|
@@ -479,7 +505,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
479
505
|
* some additional lazy properties, if so, we reload and merge the data from database
|
|
480
506
|
*/
|
|
481
507
|
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;
|
|
508
|
+
protected prepareOptions(options: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any> | CountOptions<any, any>): void;
|
|
483
509
|
/**
|
|
484
510
|
* @internal
|
|
485
511
|
*/
|
|
@@ -488,15 +514,15 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
488
514
|
* @internal
|
|
489
515
|
*/
|
|
490
516
|
tryCache<T extends object, R>(entityName: string, config: boolean | number | [string, number] | undefined, key: unknown, refresh?: boolean, merge?: boolean): Promise<{
|
|
491
|
-
data?: R;
|
|
517
|
+
data?: R | null;
|
|
492
518
|
key: string;
|
|
493
519
|
} | undefined>;
|
|
494
520
|
/**
|
|
495
521
|
* @internal
|
|
496
522
|
*/
|
|
497
|
-
storeCache(config: boolean | number | [string, number] | undefined, key: {
|
|
523
|
+
storeCache<T>(config: boolean | number | [string, number] | undefined, key: {
|
|
498
524
|
key: string;
|
|
499
|
-
}, data:
|
|
525
|
+
}, data: T | (() => T)): Promise<void>;
|
|
500
526
|
/**
|
|
501
527
|
* Clears result cache for given cache key. If we want to be able to call this method,
|
|
502
528
|
* we need to set the cache key explicitly when storing the cache.
|
|
@@ -520,6 +546,8 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
520
546
|
* if executed inside request context handler.
|
|
521
547
|
*/
|
|
522
548
|
set schema(schema: string | null | undefined);
|
|
549
|
+
/** @internal */
|
|
550
|
+
getDataLoader(type: 'ref' | '1:m' | 'm:n'): Promise<any>;
|
|
523
551
|
/**
|
|
524
552
|
* Returns the ID of this EntityManager. Respects the context, so global EM will give you the contextual ID
|
|
525
553
|
* if executed inside request context handler.
|
|
@@ -539,11 +567,20 @@ export interface CreateOptions<Convert extends boolean> {
|
|
|
539
567
|
partial?: boolean;
|
|
540
568
|
/** convert raw database values based on mapped types (by default, already converted values are expected) */
|
|
541
569
|
convertCustomTypes?: Convert;
|
|
570
|
+
/**
|
|
571
|
+
* Property `onCreate` hooks are normally executed during `flush` operation.
|
|
572
|
+
* With this option, they will be processed early inside `em.create()` method.
|
|
573
|
+
*/
|
|
574
|
+
processOnCreateHooksEarly?: boolean;
|
|
542
575
|
}
|
|
543
576
|
export interface MergeOptions {
|
|
544
577
|
refresh?: boolean;
|
|
545
578
|
convertCustomTypes?: boolean;
|
|
546
579
|
schema?: string;
|
|
580
|
+
disableContextResolution?: boolean;
|
|
581
|
+
keepIdentity?: boolean;
|
|
582
|
+
validate?: boolean;
|
|
583
|
+
cascade?: boolean; /** @default true */
|
|
547
584
|
}
|
|
548
585
|
export interface ForkOptions {
|
|
549
586
|
/** do we want a clear identity map? defaults to true */
|
|
@@ -557,7 +594,7 @@ export interface ForkOptions {
|
|
|
557
594
|
/** use this flag to ignore the current async context - this is required if we want to call `em.fork()` inside the `getContext` handler */
|
|
558
595
|
disableContextResolution?: boolean;
|
|
559
596
|
/** set flush mode for this fork, overrides the global option can be overridden locally via FindOptions */
|
|
560
|
-
flushMode?: FlushMode
|
|
597
|
+
flushMode?: FlushMode | `${FlushMode}`;
|
|
561
598
|
/** disable transactions for this fork */
|
|
562
599
|
disableTransactions?: boolean;
|
|
563
600
|
/** should we keep the transaction context of the parent EM? */
|