@mikro-orm/core 7.0.0-dev.321 → 7.0.0-dev.322

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 (50) hide show
  1. package/EntityManager.d.ts +2 -15
  2. package/EntityManager.js +155 -152
  3. package/MikroORM.d.ts +1 -3
  4. package/MikroORM.js +20 -20
  5. package/cache/FileCacheAdapter.d.ts +1 -5
  6. package/cache/FileCacheAdapter.js +22 -22
  7. package/cache/GeneratedCacheAdapter.d.ts +1 -1
  8. package/cache/GeneratedCacheAdapter.js +6 -6
  9. package/cache/MemoryCacheAdapter.d.ts +1 -2
  10. package/cache/MemoryCacheAdapter.js +8 -8
  11. package/entity/Collection.d.ts +2 -10
  12. package/entity/Collection.js +95 -105
  13. package/entity/EntityFactory.d.ts +1 -8
  14. package/entity/EntityFactory.js +48 -48
  15. package/entity/EntityLoader.d.ts +1 -3
  16. package/entity/EntityLoader.js +33 -34
  17. package/entity/Reference.d.ts +1 -2
  18. package/entity/Reference.js +11 -11
  19. package/events/EventManager.d.ts +1 -4
  20. package/events/EventManager.js +21 -21
  21. package/hydration/ObjectHydrator.d.ts +1 -2
  22. package/hydration/ObjectHydrator.js +11 -11
  23. package/metadata/MetadataDiscovery.d.ts +1 -9
  24. package/metadata/MetadataDiscovery.js +147 -144
  25. package/metadata/MetadataStorage.d.ts +1 -5
  26. package/metadata/MetadataStorage.js +36 -36
  27. package/package.json +1 -1
  28. package/serialization/SerializationContext.d.ts +2 -6
  29. package/serialization/SerializationContext.js +14 -14
  30. package/unit-of-work/ChangeSetComputer.d.ts +1 -6
  31. package/unit-of-work/ChangeSetComputer.js +21 -21
  32. package/unit-of-work/ChangeSetPersister.d.ts +1 -9
  33. package/unit-of-work/ChangeSetPersister.js +51 -51
  34. package/unit-of-work/CommitOrderCalculator.d.ts +1 -4
  35. package/unit-of-work/CommitOrderCalculator.js +13 -13
  36. package/unit-of-work/IdentityMap.d.ts +2 -5
  37. package/unit-of-work/IdentityMap.js +18 -18
  38. package/unit-of-work/UnitOfWork.d.ts +5 -19
  39. package/unit-of-work/UnitOfWork.js +181 -173
  40. package/utils/AbstractMigrator.d.ts +1 -1
  41. package/utils/AbstractMigrator.js +6 -6
  42. package/utils/Configuration.d.ts +1 -6
  43. package/utils/Configuration.js +78 -78
  44. package/utils/Cursor.d.ts +1 -1
  45. package/utils/Cursor.js +3 -3
  46. package/utils/EntityComparator.d.ts +2 -11
  47. package/utils/EntityComparator.js +44 -44
  48. package/utils/TransactionManager.js +1 -2
  49. package/utils/Utils.js +1 -1
  50. package/utils/clone.js +1 -1
@@ -17,26 +17,26 @@ export var NodeState;
17
17
  */
18
18
  export class CommitOrderCalculator {
19
19
  /** Matrix of nodes, keys are provided hashes and values are the node definition objects. */
20
- nodes = new Map();
20
+ #nodes = new Map();
21
21
  /** Volatile variable holding calculated nodes during sorting process. */
22
- sortedNodeList = [];
22
+ #sortedNodeList = [];
23
23
  /**
24
24
  * Checks for node existence in graph.
25
25
  */
26
26
  hasNode(hash) {
27
- return this.nodes.has(hash);
27
+ return this.#nodes.has(hash);
28
28
  }
29
29
  /**
30
30
  * Adds a new node to the graph, assigning its hash.
31
31
  */
32
32
  addNode(hash) {
33
- this.nodes.set(hash, { hash, state: 0 /* NodeState.NOT_VISITED */, dependencies: new Map() });
33
+ this.#nodes.set(hash, { hash, state: 0 /* NodeState.NOT_VISITED */, dependencies: new Map() });
34
34
  }
35
35
  /**
36
36
  * Adds a new dependency (edge) to the graph using their hashes.
37
37
  */
38
38
  addDependency(from, to, weight) {
39
- this.nodes.get(from).dependencies.set(to, { from, to, weight });
39
+ this.#nodes.get(from).dependencies.set(to, { from, to, weight });
40
40
  }
41
41
  discoverProperty(prop, entityName) {
42
42
  const toOneOwner = (prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner) || prop.kind === ReferenceKind.MANY_TO_ONE;
@@ -57,15 +57,15 @@ export class CommitOrderCalculator {
57
57
  * @internal Highly performance-sensitive method.
58
58
  */
59
59
  sort() {
60
- for (const vertex of this.nodes.values()) {
60
+ for (const vertex of this.#nodes.values()) {
61
61
  if (vertex.state !== 0 /* NodeState.NOT_VISITED */) {
62
62
  continue;
63
63
  }
64
64
  this.visit(vertex);
65
65
  }
66
- const sortedList = this.sortedNodeList.reverse();
67
- this.nodes = new Map();
68
- this.sortedNodeList = [];
66
+ const sortedList = this.#sortedNodeList.reverse();
67
+ this.#nodes = new Map();
68
+ this.#sortedNodeList = [];
69
69
  return sortedList;
70
70
  }
71
71
  /**
@@ -76,7 +76,7 @@ export class CommitOrderCalculator {
76
76
  visit(node) {
77
77
  node.state = 1 /* NodeState.IN_PROGRESS */;
78
78
  for (const edge of node.dependencies.values()) {
79
- const target = this.nodes.get(edge.to);
79
+ const target = this.#nodes.get(edge.to);
80
80
  switch (target.state) {
81
81
  case 2 /* NodeState.VISITED */:
82
82
  break; // Do nothing, since node was already visited
@@ -89,7 +89,7 @@ export class CommitOrderCalculator {
89
89
  }
90
90
  if (node.state !== 2 /* NodeState.VISITED */) {
91
91
  node.state = 2 /* NodeState.VISITED */;
92
- this.sortedNodeList.push(node.hash);
92
+ this.#sortedNodeList.push(node.hash);
93
93
  }
94
94
  }
95
95
  /**
@@ -100,12 +100,12 @@ export class CommitOrderCalculator {
100
100
  return;
101
101
  }
102
102
  for (const edge of target.dependencies.values()) {
103
- const targetNode = this.nodes.get(edge.to);
103
+ const targetNode = this.#nodes.get(edge.to);
104
104
  if (targetNode.state === 0 /* NodeState.NOT_VISITED */) {
105
105
  this.visit(targetNode);
106
106
  }
107
107
  }
108
108
  target.state = 2 /* NodeState.VISITED */;
109
- this.sortedNodeList.push(target.hash);
109
+ this.#sortedNodeList.push(target.hash);
110
110
  }
111
111
  }
@@ -1,10 +1,7 @@
1
1
  import type { AnyEntity, EntityMetadata } from '../typings.js';
2
2
  export declare class IdentityMap {
3
- private readonly defaultSchema?;
4
- constructor(defaultSchema?: string | undefined);
5
- private readonly registry;
6
- /** Tracks alternate key hashes for each entity so we can clean them up on delete */
7
- private readonly alternateKeys;
3
+ #private;
4
+ constructor(defaultSchema?: string);
8
5
  store<T>(item: T): void;
9
6
  /**
10
7
  * Stores an entity under an alternate key (non-PK property).
@@ -1,11 +1,11 @@
1
1
  export class IdentityMap {
2
- defaultSchema;
2
+ #defaultSchema;
3
+ #registry = new Map();
4
+ /** Tracks alternate key hashes for each entity so we can clean them up on delete */
5
+ #alternateKeys = new WeakMap();
3
6
  constructor(defaultSchema) {
4
- this.defaultSchema = defaultSchema;
7
+ this.#defaultSchema = defaultSchema;
5
8
  }
6
- registry = new Map();
7
- /** Tracks alternate key hashes for each entity so we can clean them up on delete */
8
- alternateKeys = new WeakMap();
9
9
  store(item) {
10
10
  this.getStore(item.__meta.root).set(this.getPkHash(item), item);
11
11
  }
@@ -17,10 +17,10 @@ export class IdentityMap {
17
17
  const hash = this.getKeyHash(key, value, schema);
18
18
  this.getStore(item.__meta.root).set(hash, item);
19
19
  // Track this alternate key so we can clean it up when the entity is deleted
20
- let keys = this.alternateKeys.get(item);
20
+ let keys = this.#alternateKeys.get(item);
21
21
  if (!keys) {
22
22
  keys = new Set();
23
- this.alternateKeys.set(item, keys);
23
+ this.#alternateKeys.set(item, keys);
24
24
  }
25
25
  keys.add(hash);
26
26
  }
@@ -29,12 +29,12 @@ export class IdentityMap {
29
29
  const store = this.getStore(meta);
30
30
  store.delete(this.getPkHash(item));
31
31
  // Also delete any alternate key entries for this entity
32
- const altKeys = this.alternateKeys.get(item);
32
+ const altKeys = this.#alternateKeys.get(item);
33
33
  if (altKeys) {
34
34
  for (const hash of altKeys) {
35
35
  store.delete(hash);
36
36
  }
37
- this.alternateKeys.delete(item);
37
+ this.#alternateKeys.delete(item);
38
38
  }
39
39
  }
40
40
  getByHash(meta, hash) {
@@ -42,26 +42,26 @@ export class IdentityMap {
42
42
  return store.has(hash) ? store.get(hash) : undefined;
43
43
  }
44
44
  getStore(meta) {
45
- const store = this.registry.get(meta.class);
45
+ const store = this.#registry.get(meta.class);
46
46
  if (store) {
47
47
  return store;
48
48
  }
49
49
  const newStore = new Map();
50
- this.registry.set(meta.class, newStore);
50
+ this.#registry.set(meta.class, newStore);
51
51
  return newStore;
52
52
  }
53
53
  clear() {
54
- this.registry.clear();
54
+ this.#registry.clear();
55
55
  }
56
56
  values() {
57
57
  const ret = [];
58
- for (const store of this.registry.values()) {
58
+ for (const store of this.#registry.values()) {
59
59
  ret.push(...store.values());
60
60
  }
61
61
  return ret;
62
62
  }
63
63
  *[Symbol.iterator]() {
64
- for (const store of this.registry.values()) {
64
+ for (const store of this.#registry.values()) {
65
65
  for (const item of store.values()) {
66
66
  yield item;
67
67
  }
@@ -69,7 +69,7 @@ export class IdentityMap {
69
69
  }
70
70
  keys() {
71
71
  const ret = [];
72
- for (const [cls, store] of this.registry) {
72
+ for (const [cls, store] of this.#registry) {
73
73
  ret.push(...[...store.keys()].map(hash => `${cls.name}-${hash}`));
74
74
  }
75
75
  return ret;
@@ -79,18 +79,18 @@ export class IdentityMap {
79
79
  */
80
80
  get(hash) {
81
81
  const [name, id] = hash.split('-', 2);
82
- const cls = [...this.registry.keys()].find(k => k.name === name);
82
+ const cls = [...this.#registry.keys()].find(k => k.name === name);
83
83
  if (!cls) {
84
84
  return undefined;
85
85
  }
86
- const store = this.registry.get(cls);
86
+ const store = this.#registry.get(cls);
87
87
  return store.has(id) ? store.get(id) : undefined;
88
88
  }
89
89
  getPkHash(item) {
90
90
  const wrapped = item.__helper;
91
91
  const meta = wrapped.__meta;
92
92
  const hash = wrapped.getSerializedPrimaryKey();
93
- const schema = wrapped.__schema ?? meta.root.schema ?? this.defaultSchema;
93
+ const schema = wrapped.__schema ?? meta.root.schema ?? this.#defaultSchema;
94
94
  if (schema) {
95
95
  return schema + ':' + hash;
96
96
  }
@@ -7,25 +7,7 @@ import type { EntityManager } from '../EntityManager.js';
7
7
  import { IdentityMap } from './IdentityMap.js';
8
8
  import type { LockOptions } from '../drivers/IDatabaseDriver.js';
9
9
  export declare class UnitOfWork {
10
- private readonly em;
11
- /** map of references to managed entities */
12
- private readonly identityMap;
13
- private readonly persistStack;
14
- private readonly removeStack;
15
- private readonly orphanRemoveStack;
16
- private readonly changeSets;
17
- private readonly collectionUpdates;
18
- private readonly extraUpdates;
19
- private readonly metadata;
20
- private readonly platform;
21
- private readonly eventManager;
22
- private readonly comparator;
23
- private readonly changeSetComputer;
24
- private readonly changeSetPersister;
25
- private readonly queuedActions;
26
- private readonly loadedEntities;
27
- private readonly flushQueue;
28
- private working;
10
+ #private;
29
11
  constructor(em: EntityManager);
30
12
  merge<T extends object>(entity: T, visited?: Set<AnyEntity>): void;
31
13
  /**
@@ -42,6 +24,10 @@ export declare class UnitOfWork {
42
24
  * @internal
43
25
  */
44
26
  dispatchOnLoadEvent(): Promise<void>;
27
+ /**
28
+ * @internal
29
+ */
30
+ unmarkAsLoaded(entity: AnyEntity): void;
45
31
  /**
46
32
  * Returns entity from the identity map. For composite keys, you need to pass an array of PKs in the same order as they are defined in `meta.primaryKeys`.
47
33
  */