@mikro-orm/core 6.4.5-dev.7 → 6.4.5-dev.9

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.
@@ -4,7 +4,7 @@ import { type Configuration, Cursor } from './utils';
4
4
  import { type AssignOptions, EntityFactory, type EntityLoaderOptions, type EntityRepository, EntityValidator, Reference } from './entity';
5
5
  import { UnitOfWork } from './unit-of-work';
6
6
  import type { CountOptions, DeleteOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions, GetReferenceOptions, IDatabaseDriver, LockOptions, NativeInsertUpdateOptions, UpdateOptions, UpsertManyOptions, UpsertOptions } from './drivers';
7
- import type { AnyEntity, AnyString, ArrayElement, AutoPath, ConnectionType, Dictionary, EntityData, EntityDictionary, EntityDTO, EntityMetadata, EntityName, FilterQuery, FromEntityType, GetRepository, IHydrator, IsSubset, Loaded, MaybePromise, MergeLoaded, MergeSelected, ObjectQuery, Primary, Ref, RequiredEntityData, UnboxArray, NoInfer } from './typings';
7
+ import type { AnyEntity, AnyString, ArrayElement, AutoPath, ConnectionType, Dictionary, EntityData, EntityDictionary, EntityDTO, EntityMetadata, EntityName, FilterQuery, FromEntityType, GetRepository, IHydrator, IsSubset, Loaded, MaybePromise, MergeLoaded, MergeSelected, NoInfer, ObjectQuery, Primary, Ref, RequiredEntityData, UnboxArray } from './typings';
8
8
  import { FlushMode, LockMode, PopulatePath, type TransactionOptions } from './enums';
9
9
  import type { MetadataStorage } from './metadata';
10
10
  import type { Transaction } from './connections';
package/EntityManager.js CHANGED
@@ -384,12 +384,12 @@ class EntityManager {
384
384
  const em = this.getContext(false);
385
385
  await em.tryFlush(entityName, options);
386
386
  options.flushMode = 'commit'; // do not try to auto flush again
387
- const copy = utils_1.Utils.copy(where);
388
- const [entities, count] = await Promise.all([
389
- em.find(entityName, where, options),
390
- em.count(entityName, copy, options),
391
- ]);
392
- return [entities, count];
387
+ return utils_1.RawQueryFragment.run(async () => {
388
+ return Promise.all([
389
+ em.find(entityName, where, options),
390
+ em.count(entityName, where, options),
391
+ ]);
392
+ });
393
393
  }
394
394
  /**
395
395
  * Calls `em.find()` and `em.count()` with the same arguments (where applicable) and returns the results as {@apilink Cursor} object.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.4.5-dev.7",
3
+ "version": "6.4.5-dev.9",
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
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -64,7 +64,7 @@
64
64
  "esprima": "4.0.1",
65
65
  "fs-extra": "11.3.0",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.4.5-dev.7",
67
+ "mikro-orm": "6.4.5-dev.9",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -13,6 +13,7 @@ export declare class RawQueryFragment {
13
13
  /** @internal */
14
14
  assign(): void;
15
15
  clone(): RawQueryFragment;
16
+ static run<T>(cb: (...args: any[]) => Promise<T>): Promise<T>;
16
17
  /**
17
18
  * @internal allows testing we don't leak memory, as the raw fragments cache needs to be cleared automatically
18
19
  */
@@ -4,12 +4,14 @@ exports.ALIAS_REPLACEMENT_RE = exports.ALIAS_REPLACEMENT = exports.RawQueryFragm
4
4
  exports.raw = raw;
5
5
  exports.sql = sql;
6
6
  exports.createSqlFunction = createSqlFunction;
7
+ const node_async_hooks_1 = require("node:async_hooks");
7
8
  const node_util_1 = require("node:util");
8
9
  const Utils_1 = require("./Utils");
9
10
  class RawQueryFragment {
10
11
  sql;
11
12
  params;
12
13
  static #rawQueryCache = new Map();
14
+ static #storage = new node_async_hooks_1.AsyncLocalStorage();
13
15
  static #index = 0n;
14
16
  static cloneRegistry;
15
17
  #assigned = false;
@@ -45,6 +47,13 @@ class RawQueryFragment {
45
47
  RawQueryFragment.cloneRegistry?.add(this.#key);
46
48
  return new RawQueryFragment(this.sql, this.params);
47
49
  }
50
+ static async run(cb) {
51
+ const removeStack = new Set();
52
+ const res = await this.#storage.run(removeStack, cb);
53
+ removeStack.forEach(key => RawQueryFragment.remove(key));
54
+ removeStack.clear();
55
+ return res;
56
+ }
48
57
  /**
49
58
  * @internal allows testing we don't leak memory, as the raw fragments cache needs to be cleared automatically
50
59
  */
@@ -74,7 +83,13 @@ class RawQueryFragment {
74
83
  }
75
84
  raw.#used--;
76
85
  if (raw.#used <= 0) {
77
- this.#rawQueryCache.delete(key);
86
+ const removeStack = this.#storage.getStore();
87
+ if (removeStack) {
88
+ removeStack.add(key);
89
+ }
90
+ else {
91
+ this.#rawQueryCache.delete(key);
92
+ }
78
93
  }
79
94
  }
80
95
  /* istanbul ignore next */
package/utils/Utils.js CHANGED
@@ -38,7 +38,6 @@ function isRawSql(value) {
38
38
  return typeof value === 'object' && !!value && '__raw' in value;
39
39
  }
40
40
  function compareObjects(a, b) {
41
- // eslint-disable-next-line eqeqeq
42
41
  if (a === b || (a == null && b == null)) {
43
42
  return true;
44
43
  }