@mikro-orm/core 7.0.0-rc.2 → 7.0.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 +4 -16
- package/EntityManager.js +248 -181
- package/MikroORM.d.ts +4 -6
- package/MikroORM.js +24 -24
- package/README.md +5 -4
- package/cache/FileCacheAdapter.d.ts +1 -5
- package/cache/FileCacheAdapter.js +22 -24
- package/cache/GeneratedCacheAdapter.d.ts +1 -1
- package/cache/GeneratedCacheAdapter.js +6 -6
- package/cache/MemoryCacheAdapter.d.ts +1 -2
- package/cache/MemoryCacheAdapter.js +8 -8
- package/cache/index.d.ts +1 -1
- package/cache/index.js +0 -1
- package/connections/Connection.d.ts +1 -0
- package/connections/Connection.js +43 -14
- package/drivers/DatabaseDriver.d.ts +0 -2
- package/drivers/DatabaseDriver.js +28 -12
- package/drivers/IDatabaseDriver.d.ts +43 -0
- package/entity/Collection.d.ts +1 -9
- package/entity/Collection.js +124 -108
- package/entity/EntityAssigner.js +23 -11
- package/entity/EntityFactory.d.ts +1 -8
- package/entity/EntityFactory.js +79 -59
- package/entity/EntityHelper.js +25 -16
- package/entity/EntityLoader.d.ts +1 -3
- package/entity/EntityLoader.js +90 -60
- package/entity/Reference.d.ts +2 -3
- package/entity/Reference.js +48 -19
- package/entity/WrappedEntity.d.ts +4 -2
- package/entity/WrappedEntity.js +5 -1
- package/entity/defineEntity.d.ts +42 -85
- package/entity/utils.js +28 -26
- package/entity/validators.js +2 -1
- package/enums.d.ts +2 -1
- package/enums.js +13 -17
- package/errors.d.ts +11 -11
- package/errors.js +8 -8
- package/events/EventManager.d.ts +1 -4
- package/events/EventManager.js +26 -23
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/exceptions.js +9 -2
- package/hydration/ObjectHydrator.d.ts +1 -2
- package/hydration/ObjectHydrator.js +41 -27
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/logging/DefaultLogger.js +6 -7
- package/logging/Logger.d.ts +2 -1
- package/logging/colors.js +2 -5
- package/logging/index.d.ts +1 -1
- package/logging/index.js +0 -1
- package/metadata/EntitySchema.d.ts +3 -3
- package/metadata/EntitySchema.js +12 -2
- package/metadata/MetadataDiscovery.d.ts +1 -9
- package/metadata/MetadataDiscovery.js +251 -179
- package/metadata/MetadataProvider.js +26 -1
- package/metadata/MetadataStorage.d.ts +1 -5
- package/metadata/MetadataStorage.js +37 -39
- package/metadata/MetadataValidator.js +20 -5
- package/metadata/discover-entities.js +1 -1
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/metadata/types.d.ts +2 -2
- package/naming-strategy/AbstractNamingStrategy.js +6 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +1 -1
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/not-supported.js +5 -1
- package/package.json +38 -38
- package/platforms/Platform.d.ts +24 -1
- package/platforms/Platform.js +106 -27
- package/serialization/EntitySerializer.js +8 -4
- package/serialization/EntityTransformer.js +4 -1
- package/serialization/SerializationContext.d.ts +4 -8
- package/serialization/SerializationContext.js +21 -16
- package/types/UuidType.d.ts +2 -0
- package/types/UuidType.js +14 -2
- package/types/index.d.ts +2 -1
- package/typings.d.ts +35 -24
- package/typings.js +9 -9
- package/unit-of-work/ChangeSet.js +4 -4
- package/unit-of-work/ChangeSetComputer.d.ts +1 -6
- package/unit-of-work/ChangeSetComputer.js +29 -27
- package/unit-of-work/ChangeSetPersister.d.ts +1 -9
- package/unit-of-work/ChangeSetPersister.js +63 -58
- package/unit-of-work/CommitOrderCalculator.d.ts +1 -4
- package/unit-of-work/CommitOrderCalculator.js +17 -15
- package/unit-of-work/IdentityMap.d.ts +2 -5
- package/unit-of-work/IdentityMap.js +18 -18
- package/unit-of-work/UnitOfWork.d.ts +12 -20
- package/unit-of-work/UnitOfWork.js +228 -191
- package/utils/AbstractMigrator.d.ts +2 -2
- package/utils/AbstractMigrator.js +10 -12
- package/utils/AbstractSchemaGenerator.js +2 -1
- package/utils/AsyncContext.js +1 -1
- package/utils/Configuration.d.ts +90 -189
- package/utils/Configuration.js +97 -77
- package/utils/Cursor.d.ts +3 -3
- package/utils/Cursor.js +8 -6
- package/utils/DataloaderUtils.js +15 -12
- package/utils/EntityComparator.d.ts +8 -15
- package/utils/EntityComparator.js +100 -92
- package/utils/QueryHelper.d.ts +16 -1
- package/utils/QueryHelper.js +108 -50
- package/utils/RawQueryFragment.d.ts +4 -4
- package/utils/RawQueryFragment.js +3 -2
- package/utils/TransactionManager.js +3 -3
- package/utils/Utils.d.ts +2 -2
- package/utils/Utils.js +39 -32
- package/utils/clone.js +5 -0
- package/utils/env-vars.js +6 -5
- package/utils/fs-utils.d.ts +3 -17
- package/utils/fs-utils.js +2 -5
- package/utils/upsert-utils.js +7 -4
|
@@ -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
|
|
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
|
|
20
|
+
let keys = this.#alternateKeys.get(item);
|
|
21
21
|
if (!keys) {
|
|
22
22
|
keys = new Set();
|
|
23
|
-
this
|
|
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
|
|
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
|
|
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
|
|
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
|
|
50
|
+
this.#registry.set(meta.class, newStore);
|
|
51
51
|
return newStore;
|
|
52
52
|
}
|
|
53
53
|
clear() {
|
|
54
|
-
this
|
|
54
|
+
this.#registry.clear();
|
|
55
55
|
}
|
|
56
56
|
values() {
|
|
57
57
|
const ret = [];
|
|
58
|
-
for (const store of this
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
*/
|
|
@@ -72,7 +58,13 @@ export declare class UnitOfWork {
|
|
|
72
58
|
getRemoveStack(): Set<AnyEntity>;
|
|
73
59
|
getChangeSets(): ChangeSet<AnyEntity>[];
|
|
74
60
|
getCollectionUpdates(): Collection<AnyEntity>[];
|
|
75
|
-
getExtraUpdates(): Set<[
|
|
61
|
+
getExtraUpdates(): Set<[
|
|
62
|
+
AnyEntity,
|
|
63
|
+
string | string[],
|
|
64
|
+
AnyEntity | AnyEntity[] | Reference<any> | Collection<any>,
|
|
65
|
+
ChangeSet<any> | undefined,
|
|
66
|
+
ChangeSetType
|
|
67
|
+
]>;
|
|
76
68
|
shouldAutoFlush<T extends object>(meta: EntityMetadata<T>): boolean;
|
|
77
69
|
clearActionsQueue(): void;
|
|
78
70
|
computeChangeSet<T extends object>(entity: T, type?: ChangeSetType): void;
|