@mikro-orm/core 7.2.0-dev.10 → 7.2.0-dev.11

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.
@@ -375,12 +375,10 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
375
375
  */
376
376
  nativeDelete<Entity extends object>(entityName: EntityName<Entity>, where: FilterQuery<NoInfer<Entity>>, options?: DeleteOptions<Entity>): Promise<number>;
377
377
  /**
378
- * Maps raw database result to an entity and merges it to this EntityManager.
378
+ * Maps raw database result to an entity and merges it to this EntityManager by default.
379
+ * Use `disableIdentityMap` to return an isolated entity without affecting the current context.
379
380
  */
380
- map<Entity extends object>(entityName: EntityName<Entity>, result: EntityDictionary<Entity>, options?: {
381
- schema?: string;
382
- mapped?: boolean;
383
- }): Entity;
381
+ map<Entity extends object>(entityName: EntityName<Entity>, result: EntityDictionary<Entity>, options?: MapOptions): Entity;
384
382
  /**
385
383
  * Merges given entity to this EntityManager so it becomes managed. You can force refreshing of existing entities
386
384
  * via second parameter. By default, it will return already loaded entities without modifying them.
@@ -667,6 +665,14 @@ export interface CreateOptions<Convert extends boolean> {
667
665
  */
668
666
  processOnCreateHooksEarly?: boolean;
669
667
  }
668
+ export interface MapOptions {
669
+ /** schema to use when mapping the entity */
670
+ schema?: string;
671
+ /** set to true when the result is already mapped to entity property names */
672
+ mapped?: boolean;
673
+ /** map the entity in an isolated context without adding it to the identity map */
674
+ disableIdentityMap?: boolean;
675
+ }
670
676
  export interface MergeOptions {
671
677
  refresh?: boolean;
672
678
  convertCustomTypes?: boolean;
package/EntityManager.js CHANGED
@@ -1399,10 +1399,18 @@ export class EntityManager {
1399
1399
  return res.affectedRows;
1400
1400
  }
1401
1401
  /**
1402
- * Maps raw database result to an entity and merges it to this EntityManager.
1402
+ * Maps raw database result to an entity and merges it to this EntityManager by default.
1403
+ * Use `disableIdentityMap` to return an isolated entity without affecting the current context.
1403
1404
  */
1404
1405
  map(entityName, result, options = {}) {
1405
- const { mapped, ...rest } = options;
1406
+ if (options.disableIdentityMap ?? this.config.get('disableIdentityMap')) {
1407
+ const em = this.getContext(false);
1408
+ const fork = em.fork({ keepTransactionContext: true });
1409
+ const ret = fork.map(entityName, result, { ...options, disableIdentityMap: false });
1410
+ fork.clear();
1411
+ return ret;
1412
+ }
1413
+ const { mapped, disableIdentityMap, ...rest } = options;
1406
1414
  const meta = this.metadata.get(entityName);
1407
1415
  const data = (mapped ? result : this.driver.mapResult(result, meta));
1408
1416
  for (const k of Object.keys(data)) {
@@ -1,5 +1,5 @@
1
1
  import type { PopulatePath } from '../enums.js';
2
- import type { CreateOptions, EntityManager, MergeOptions } from '../EntityManager.js';
2
+ import type { CreateOptions, EntityManager, MapOptions, MergeOptions } from '../EntityManager.js';
3
3
  import type { AssignOptions } from './EntityAssigner.js';
4
4
  import type { Dictionary, EntityData, EntityDictionary, EntityKey, EntityName, FilterQuery, Loaded, Primary, AutoPath, RequiredEntityData, Ref, EntityType, EntityDTO, MergeSelected, FromEntityType, IsSubset, MergeLoaded, ArrayElement, IndexFilterQuery, WithUsingOptions } from '../typings.js';
5
5
  import type { CountByOptions, CountOptions, DeleteOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions, GetReferenceOptions, NativeInsertUpdateOptions, StreamOptions, UpdateOptions, UpsertManyOptions, UpsertOptions } from '../drivers/IDatabaseDriver.js';
@@ -115,11 +115,10 @@ export declare class EntityRepository<Entity extends object> {
115
115
  */
116
116
  nativeDelete(where: FilterQuery<Entity>, options?: DeleteOptions<Entity>): Promise<number>;
117
117
  /**
118
- * Maps raw database result to an entity and merges it to this EntityManager.
118
+ * Maps raw database result to an entity and merges it to this EntityManager by default.
119
+ * Use `disableIdentityMap` to return an isolated entity without affecting the current context.
119
120
  */
120
- map(result: EntityDictionary<Entity>, options?: {
121
- schema?: string;
122
- }): Entity;
121
+ map(result: EntityDictionary<Entity>, options?: Omit<MapOptions, 'mapped'>): Entity;
123
122
  /**
124
123
  * Gets a reference to the entity identified by the given type and alternate key property without actually loading it.
125
124
  * The key option specifies which property to use for identity map lookup instead of the primary key.
@@ -131,7 +131,8 @@ export class EntityRepository {
131
131
  return this.getEntityManager().nativeDelete(this.entityName, where, options);
132
132
  }
133
133
  /**
134
- * Maps raw database result to an entity and merges it to this EntityManager.
134
+ * Maps raw database result to an entity and merges it to this EntityManager by default.
135
+ * Use `disableIdentityMap` to return an isolated entity without affecting the current context.
135
136
  */
136
137
  map(result, options) {
137
138
  return this.getEntityManager().map(this.entityName, result, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.2.0-dev.10",
3
+ "version": "7.2.0-dev.11",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "keywords": [
6
6
  "data-mapper",
package/utils/Utils.js CHANGED
@@ -153,7 +153,7 @@ export function parseJsonSafe(value) {
153
153
  /** Collection of general-purpose utility methods used throughout the ORM. */
154
154
  export class Utils {
155
155
  static PK_SEPARATOR = '~~~';
156
- static #ORM_VERSION = '7.2.0-dev.10';
156
+ static #ORM_VERSION = '7.2.0-dev.11';
157
157
  /**
158
158
  * Checks if the argument is instance of `Object`. Returns false for arrays.
159
159
  */