@mikro-orm/core 7.0.0-dev.99 → 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.
Files changed (104) hide show
  1. package/EntityManager.d.ts +34 -17
  2. package/EntityManager.js +88 -99
  3. package/MikroORM.d.ts +5 -5
  4. package/MikroORM.js +25 -20
  5. package/cache/FileCacheAdapter.js +11 -3
  6. package/connections/Connection.d.ts +3 -2
  7. package/connections/Connection.js +4 -3
  8. package/drivers/DatabaseDriver.d.ts +11 -11
  9. package/drivers/DatabaseDriver.js +91 -25
  10. package/drivers/IDatabaseDriver.d.ts +22 -16
  11. package/entity/BaseEntity.d.ts +61 -1
  12. package/entity/Collection.d.ts +8 -1
  13. package/entity/Collection.js +12 -13
  14. package/entity/EntityAssigner.js +9 -9
  15. package/entity/EntityFactory.d.ts +6 -1
  16. package/entity/EntityFactory.js +40 -22
  17. package/entity/EntityHelper.d.ts +2 -2
  18. package/entity/EntityHelper.js +27 -4
  19. package/entity/EntityLoader.d.ts +5 -4
  20. package/entity/EntityLoader.js +193 -80
  21. package/entity/EntityRepository.d.ts +27 -7
  22. package/entity/EntityRepository.js +8 -2
  23. package/entity/PolymorphicRef.d.ts +12 -0
  24. package/entity/PolymorphicRef.js +18 -0
  25. package/entity/WrappedEntity.d.ts +2 -2
  26. package/entity/WrappedEntity.js +1 -1
  27. package/entity/defineEntity.d.ts +88 -49
  28. package/entity/defineEntity.js +12 -0
  29. package/entity/index.d.ts +1 -0
  30. package/entity/index.js +1 -0
  31. package/entity/validators.js +2 -2
  32. package/enums.d.ts +2 -2
  33. package/enums.js +1 -0
  34. package/errors.d.ts +16 -8
  35. package/errors.js +40 -13
  36. package/hydration/ObjectHydrator.js +63 -21
  37. package/index.d.ts +1 -1
  38. package/logging/colors.d.ts +1 -1
  39. package/logging/colors.js +7 -6
  40. package/logging/inspect.js +1 -6
  41. package/metadata/EntitySchema.d.ts +43 -13
  42. package/metadata/EntitySchema.js +82 -27
  43. package/metadata/MetadataDiscovery.d.ts +60 -3
  44. package/metadata/MetadataDiscovery.js +665 -154
  45. package/metadata/MetadataProvider.js +3 -1
  46. package/metadata/MetadataStorage.d.ts +13 -6
  47. package/metadata/MetadataStorage.js +64 -19
  48. package/metadata/MetadataValidator.d.ts +32 -2
  49. package/metadata/MetadataValidator.js +196 -31
  50. package/metadata/discover-entities.js +5 -5
  51. package/metadata/types.d.ts +111 -14
  52. package/naming-strategy/AbstractNamingStrategy.d.ts +11 -3
  53. package/naming-strategy/AbstractNamingStrategy.js +12 -0
  54. package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
  55. package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
  56. package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
  57. package/naming-strategy/MongoNamingStrategy.js +6 -6
  58. package/naming-strategy/NamingStrategy.d.ts +17 -3
  59. package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
  60. package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
  61. package/package.json +2 -2
  62. package/platforms/Platform.d.ts +4 -2
  63. package/platforms/Platform.js +5 -2
  64. package/serialization/EntitySerializer.d.ts +3 -0
  65. package/serialization/EntitySerializer.js +15 -13
  66. package/serialization/EntityTransformer.js +6 -6
  67. package/serialization/SerializationContext.d.ts +6 -6
  68. package/typings.d.ts +320 -109
  69. package/typings.js +84 -17
  70. package/unit-of-work/ChangeSet.d.ts +4 -3
  71. package/unit-of-work/ChangeSet.js +2 -3
  72. package/unit-of-work/ChangeSetComputer.js +27 -6
  73. package/unit-of-work/ChangeSetPersister.d.ts +5 -0
  74. package/unit-of-work/ChangeSetPersister.js +45 -15
  75. package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
  76. package/unit-of-work/CommitOrderCalculator.js +13 -13
  77. package/unit-of-work/IdentityMap.d.ts +12 -0
  78. package/unit-of-work/IdentityMap.js +39 -1
  79. package/unit-of-work/UnitOfWork.d.ts +21 -3
  80. package/unit-of-work/UnitOfWork.js +201 -54
  81. package/utils/AbstractSchemaGenerator.js +17 -8
  82. package/utils/AsyncContext.d.ts +6 -0
  83. package/utils/AsyncContext.js +42 -0
  84. package/utils/Configuration.d.ts +52 -11
  85. package/utils/Configuration.js +12 -8
  86. package/utils/Cursor.js +21 -8
  87. package/utils/DataloaderUtils.js +13 -11
  88. package/utils/EntityComparator.d.ts +14 -7
  89. package/utils/EntityComparator.js +132 -46
  90. package/utils/QueryHelper.d.ts +16 -6
  91. package/utils/QueryHelper.js +53 -18
  92. package/utils/RawQueryFragment.d.ts +28 -23
  93. package/utils/RawQueryFragment.js +34 -56
  94. package/utils/RequestContext.js +2 -2
  95. package/utils/TransactionContext.js +2 -2
  96. package/utils/TransactionManager.js +1 -1
  97. package/utils/Utils.d.ts +7 -26
  98. package/utils/Utils.js +25 -79
  99. package/utils/clone.js +7 -21
  100. package/utils/env-vars.d.ts +4 -0
  101. package/utils/env-vars.js +13 -3
  102. package/utils/fs-utils.d.ts +21 -0
  103. package/utils/fs-utils.js +104 -9
  104. package/utils/upsert-utils.d.ts +4 -4
@@ -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, NoInfer, ObjectQuery, Primary, Ref, RequiredEntityData, UnboxArray } from './typings.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';
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<any> | readonly EntityName<any>[]>(options: FilterDef<T>): void;
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: string, 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: string, where: FilterQuery<Entity>): FilterQuery<Entity>;
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
- className: string;
131
+ class: EntityClass;
132
132
  propName: string;
133
133
  }): Promise<void>;
134
134
  /**
135
135
  * @internal
136
136
  */
137
- applyFilters<Entity extends object>(entityName: string, where: FilterQuery<Entity> | undefined, options: FilterOptions | undefined, type: 'read' | 'update' | 'delete', findOptions?: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any>): Promise<FilterQuery<Entity> | undefined>;
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>, where: FilterQuery<NoInfer<Entity>>, options: FindByCursorOptions<Entity, Hint, Fields, Excludes, IncludeCount>): Promise<Cursor<Entity, Hint, Fields, Excludes, IncludeCount>>;
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
- private preparePopulate;
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: string, options: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any> | CountOptions<T, any>, method: string, where: FilterQuery<T>): unknown[];
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: string, config: boolean | number | [string, number] | undefined, key: unknown, refresh?: boolean, merge?: boolean): Promise<{
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>;