@mikro-orm/core 7.0.0-dev.98 → 7.0.0-rc.0
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 +34 -17
- package/EntityManager.js +88 -99
- package/MikroORM.d.ts +5 -5
- package/MikroORM.js +25 -20
- package/cache/FileCacheAdapter.js +11 -3
- package/connections/Connection.d.ts +3 -2
- package/connections/Connection.js +4 -3
- package/drivers/DatabaseDriver.d.ts +11 -11
- package/drivers/DatabaseDriver.js +91 -25
- package/drivers/IDatabaseDriver.d.ts +22 -16
- package/entity/BaseEntity.d.ts +61 -1
- package/entity/Collection.d.ts +8 -1
- package/entity/Collection.js +12 -13
- package/entity/EntityAssigner.js +9 -9
- package/entity/EntityFactory.d.ts +6 -1
- package/entity/EntityFactory.js +40 -22
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +27 -4
- package/entity/EntityLoader.d.ts +5 -4
- package/entity/EntityLoader.js +193 -80
- package/entity/EntityRepository.d.ts +27 -7
- package/entity/EntityRepository.js +8 -2
- package/entity/PolymorphicRef.d.ts +12 -0
- package/entity/PolymorphicRef.js +18 -0
- package/entity/WrappedEntity.d.ts +2 -2
- package/entity/WrappedEntity.js +1 -1
- package/entity/defineEntity.d.ts +88 -49
- package/entity/defineEntity.js +12 -0
- package/entity/index.d.ts +1 -0
- package/entity/index.js +1 -0
- package/entity/validators.js +2 -2
- package/enums.d.ts +2 -2
- package/enums.js +1 -0
- package/errors.d.ts +16 -8
- package/errors.js +40 -13
- package/hydration/ObjectHydrator.js +63 -21
- package/index.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +7 -6
- package/logging/inspect.js +1 -6
- package/metadata/EntitySchema.d.ts +43 -13
- package/metadata/EntitySchema.js +82 -27
- package/metadata/MetadataDiscovery.d.ts +60 -3
- package/metadata/MetadataDiscovery.js +665 -154
- package/metadata/MetadataProvider.js +3 -1
- package/metadata/MetadataStorage.d.ts +13 -6
- package/metadata/MetadataStorage.js +64 -19
- package/metadata/MetadataValidator.d.ts +32 -2
- package/metadata/MetadataValidator.js +196 -31
- package/metadata/discover-entities.js +5 -5
- package/metadata/types.d.ts +111 -14
- package/naming-strategy/AbstractNamingStrategy.d.ts +11 -3
- package/naming-strategy/AbstractNamingStrategy.js +12 -0
- 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 +17 -3
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/package.json +2 -2
- package/platforms/Platform.d.ts +4 -2
- package/platforms/Platform.js +5 -2
- package/serialization/EntitySerializer.d.ts +3 -0
- package/serialization/EntitySerializer.js +15 -13
- package/serialization/EntityTransformer.js +6 -6
- package/serialization/SerializationContext.d.ts +6 -6
- package/typings.d.ts +320 -109
- package/typings.js +84 -17
- package/unit-of-work/ChangeSet.d.ts +4 -3
- package/unit-of-work/ChangeSet.js +2 -3
- package/unit-of-work/ChangeSetComputer.js +27 -6
- package/unit-of-work/ChangeSetPersister.d.ts +5 -0
- package/unit-of-work/ChangeSetPersister.js +45 -15
- 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 +21 -3
- package/unit-of-work/UnitOfWork.js +201 -54
- package/utils/AbstractSchemaGenerator.js +17 -8
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +52 -11
- package/utils/Configuration.js +15 -8
- package/utils/Cursor.js +21 -8
- package/utils/DataloaderUtils.js +13 -11
- package/utils/EntityComparator.d.ts +14 -7
- package/utils/EntityComparator.js +132 -46
- package/utils/QueryHelper.d.ts +16 -6
- package/utils/QueryHelper.js +53 -18
- package/utils/RawQueryFragment.d.ts +28 -23
- package/utils/RawQueryFragment.js +34 -56
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.js +1 -1
- package/utils/Utils.d.ts +7 -26
- package/utils/Utils.js +25 -79
- package/utils/clone.js +7 -21
- package/utils/env-vars.d.ts +4 -0
- package/utils/env-vars.js +13 -3
- package/utils/fs-utils.d.ts +21 -0
- package/utils/fs-utils.js +104 -9
- package/utils/upsert-utils.d.ts +4 -4
package/EntityManager.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { EntityLoader, type EntityLoaderOptions } from './entity/EntityLoader.js
|
|
|
7
7
|
import { Reference } from './entity/Reference.js';
|
|
8
8
|
import { UnitOfWork } from './unit-of-work/UnitOfWork.js';
|
|
9
9
|
import type { CountOptions, DeleteOptions, FilterOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions, GetReferenceOptions, IDatabaseDriver, LockOptions, NativeInsertUpdateOptions, StreamOptions, UpdateOptions, UpsertManyOptions, UpsertOptions } from './drivers/IDatabaseDriver.js';
|
|
10
|
-
import type { AnyString, ArrayElement, AutoPath, ConnectionType, Dictionary, EntityData, EntityDictionary, EntityDTO, EntityMetadata, EntityName, FilterDef, FilterQuery, FromEntityType, GetRepository, IHydrator, IsSubset, Loaded, MergeLoaded, MergeSelected,
|
|
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';
|
|
11
11
|
import { FlushMode, LockMode, PopulatePath, type TransactionOptions } from './enums.js';
|
|
12
12
|
import type { MetadataStorage } from './metadata/MetadataStorage.js';
|
|
13
13
|
import type { Transaction } from './connections/Connection.js';
|
|
@@ -99,7 +99,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
99
99
|
/**
|
|
100
100
|
* Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
|
|
101
101
|
*/
|
|
102
|
-
addFilter<T extends EntityName
|
|
102
|
+
addFilter<T extends EntityName | readonly EntityName[]>(options: FilterDef<T>): void;
|
|
103
103
|
/**
|
|
104
104
|
* Sets filter parameter values globally inside context defined by this entity manager.
|
|
105
105
|
* If you want to set shared value for all contexts, be sure to use the root entity manager.
|
|
@@ -120,21 +120,21 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
120
120
|
disableContextResolution?: boolean;
|
|
121
121
|
}): T;
|
|
122
122
|
setFlushMode(flushMode?: FlushMode | `${FlushMode}`): void;
|
|
123
|
-
protected processWhere<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName:
|
|
124
|
-
protected applyDiscriminatorCondition<Entity extends object>(entityName:
|
|
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 applyDiscriminatorCondition<Entity extends object>(entityName: EntityName<Entity>, where: FilterQuery<Entity>): FilterQuery<Entity>;
|
|
125
125
|
protected createPopulateWhere<Entity extends object>(cond: ObjectQuery<Entity>, options: FindOptions<Entity, any, any, any> | FindOneOptions<Entity, any, any, any> | CountOptions<Entity, any>): ObjectQuery<Entity>;
|
|
126
126
|
protected getJoinedFilters<Entity extends object>(meta: EntityMetadata<Entity>, options: FindOptions<Entity, any, any, any> | FindOneOptions<Entity, any, any, any>): Promise<ObjectQuery<Entity> | undefined>;
|
|
127
127
|
/**
|
|
128
128
|
* When filters are active on M:1 or 1:1 relations, we need to ref join them eagerly as they might affect the FK value.
|
|
129
129
|
*/
|
|
130
130
|
protected autoJoinRefsForFilters<T extends object>(meta: EntityMetadata<T>, options: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any>, parent?: {
|
|
131
|
-
|
|
131
|
+
class: EntityClass;
|
|
132
132
|
propName: string;
|
|
133
133
|
}): Promise<void>;
|
|
134
134
|
/**
|
|
135
135
|
* @internal
|
|
136
136
|
*/
|
|
137
|
-
applyFilters<Entity extends object>(entityName:
|
|
137
|
+
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>;
|
|
138
138
|
/**
|
|
139
139
|
* Calls `em.find()` and `em.count()` with the same arguments (where applicable) and returns the results as tuple
|
|
140
140
|
* where the first element is the array of entities, and the second is the count.
|
|
@@ -154,21 +154,21 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
154
154
|
* - POJO/entity instance
|
|
155
155
|
*
|
|
156
156
|
* ```ts
|
|
157
|
-
* const currentCursor = await em.findByCursor(User, {
|
|
157
|
+
* const currentCursor = await em.findByCursor(User, {
|
|
158
158
|
* first: 10,
|
|
159
159
|
* after: previousCursor, // cursor instance
|
|
160
160
|
* orderBy: { id: 'desc' },
|
|
161
161
|
* });
|
|
162
162
|
*
|
|
163
163
|
* // to fetch next page
|
|
164
|
-
* const nextCursor = await em.findByCursor(User, {
|
|
164
|
+
* const nextCursor = await em.findByCursor(User, {
|
|
165
165
|
* first: 10,
|
|
166
166
|
* after: currentCursor.endCursor, // opaque string
|
|
167
167
|
* orderBy: { id: 'desc' },
|
|
168
168
|
* });
|
|
169
169
|
*
|
|
170
170
|
* // to fetch next page
|
|
171
|
-
* const nextCursor2 = await em.findByCursor(User, {
|
|
171
|
+
* const nextCursor2 = await em.findByCursor(User, {
|
|
172
172
|
* first: 10,
|
|
173
173
|
* after: { id: lastSeenId }, // entity-like POJO
|
|
174
174
|
* orderBy: { id: 'desc' },
|
|
@@ -196,7 +196,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
196
196
|
* }
|
|
197
197
|
* ```
|
|
198
198
|
*/
|
|
199
|
-
findByCursor<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never, IncludeCount extends boolean = true>(entityName: EntityName<Entity>,
|
|
199
|
+
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>>;
|
|
200
200
|
/**
|
|
201
201
|
* Refreshes the persistent state of an entity from the database, overriding any local changes that have not yet been
|
|
202
202
|
* persisted. Returns the same entity instance (same object reference), but re-hydrated. If the entity is no longer
|
|
@@ -359,7 +359,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
359
359
|
* The newly created entity will be automatically marked for persistence via `em.persist` unless you disable this
|
|
360
360
|
* behavior, either locally via `persist: false` option, or globally via `persistOnCreate` ORM config option.
|
|
361
361
|
*/
|
|
362
|
-
create<Entity extends object, Convert extends boolean = false>(entityName: EntityName<Entity>, data: RequiredEntityData<Entity, never, Convert>, options?: CreateOptions<Convert>): Entity;
|
|
362
|
+
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;
|
|
363
363
|
/**
|
|
364
364
|
* Creates new instance of given entity and populates it with given data.
|
|
365
365
|
* The entity constructor will be used unless you provide `{ managed: true }` in the `options` parameter.
|
|
@@ -375,17 +375,33 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
375
375
|
* The newly created entity will be automatically marked for persistence via `em.persist` unless you disable this
|
|
376
376
|
* behavior, either locally via `persist: false` option, or globally via `persistOnCreate` ORM config option.
|
|
377
377
|
*/
|
|
378
|
-
create<Entity extends object, Convert extends boolean = false>(entityName: EntityName<Entity>, data: EntityData<Entity, Convert>, options: CreateOptions<Convert> & {
|
|
378
|
+
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> & {
|
|
379
379
|
partial: true;
|
|
380
380
|
}): Entity;
|
|
381
381
|
/**
|
|
382
382
|
* Shortcut for `wrap(entity).assign(data, { em })`
|
|
383
383
|
*/
|
|
384
384
|
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>;
|
|
385
|
+
/**
|
|
386
|
+
* Gets a reference to the entity identified by the given type and alternate key property without actually loading it.
|
|
387
|
+
* The key option specifies which property to use for identity map lookup instead of the primary key.
|
|
388
|
+
*/
|
|
389
|
+
getReference<Entity extends object, K extends string & keyof Entity>(entityName: EntityName<Entity>, id: Entity[K], options: Omit<GetReferenceOptions, 'key' | 'wrapped'> & {
|
|
390
|
+
key: K;
|
|
391
|
+
wrapped: true;
|
|
392
|
+
}): Ref<Entity>;
|
|
393
|
+
/**
|
|
394
|
+
* Gets a reference to the entity identified by the given type and alternate key property without actually loading it.
|
|
395
|
+
* The key option specifies which property to use for identity map lookup instead of the primary key.
|
|
396
|
+
*/
|
|
397
|
+
getReference<Entity extends object, K extends string & keyof Entity>(entityName: EntityName<Entity>, id: Entity[K], options: Omit<GetReferenceOptions, 'key'> & {
|
|
398
|
+
key: K;
|
|
399
|
+
wrapped?: false;
|
|
400
|
+
}): Entity;
|
|
385
401
|
/**
|
|
386
402
|
* Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
|
|
387
403
|
*/
|
|
388
|
-
getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped'> & {
|
|
404
|
+
getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped' | 'key'> & {
|
|
389
405
|
wrapped: true;
|
|
390
406
|
}): Ref<Entity>;
|
|
391
407
|
/**
|
|
@@ -395,7 +411,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
395
411
|
/**
|
|
396
412
|
* Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
|
|
397
413
|
*/
|
|
398
|
-
getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped'> & {
|
|
414
|
+
getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped' | 'key'> & {
|
|
399
415
|
wrapped: false;
|
|
400
416
|
}): Entity;
|
|
401
417
|
/**
|
|
@@ -498,7 +514,8 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
498
514
|
private checkLockRequirements;
|
|
499
515
|
private lockAndPopulate;
|
|
500
516
|
private buildFields;
|
|
501
|
-
|
|
517
|
+
/** @internal */
|
|
518
|
+
preparePopulate<Entity extends object>(entityName: EntityName<Entity>, options: Pick<FindOptions<Entity, any, any, any>, 'populate' | 'strategy' | 'fields' | 'flags' | 'filters' | 'exclude'>, validate?: boolean): Promise<PopulateOptions<Entity>[]>;
|
|
502
519
|
/**
|
|
503
520
|
* when the entity is found in identity map, we check if it was partially loaded or we are trying to populate
|
|
504
521
|
* some additional lazy properties, if so, we reload and merge the data from database
|
|
@@ -508,11 +525,11 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
508
525
|
/**
|
|
509
526
|
* @internal
|
|
510
527
|
*/
|
|
511
|
-
cacheKey<T extends object>(entityName:
|
|
528
|
+
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[];
|
|
512
529
|
/**
|
|
513
530
|
* @internal
|
|
514
531
|
*/
|
|
515
|
-
tryCache<T extends object, R>(entityName:
|
|
532
|
+
tryCache<T extends object, R>(entityName: EntityName<T>, config: boolean | number | [string, number] | undefined, key: unknown, refresh?: boolean, merge?: boolean): Promise<{
|
|
516
533
|
data?: R | null;
|
|
517
534
|
key: string;
|
|
518
535
|
} | undefined>;
|