@mikro-orm/core 7.0.0-dev.33 → 7.0.0-dev.331
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 +70 -75
- package/EntityManager.js +487 -402
- package/MikroORM.d.ts +45 -38
- package/MikroORM.js +123 -156
- package/README.md +7 -4
- package/cache/FileCacheAdapter.d.ts +2 -7
- package/cache/FileCacheAdapter.js +35 -30
- package/cache/GeneratedCacheAdapter.d.ts +1 -2
- package/cache/GeneratedCacheAdapter.js +6 -8
- package/cache/MemoryCacheAdapter.d.ts +1 -2
- package/cache/MemoryCacheAdapter.js +8 -8
- package/cache/index.d.ts +1 -2
- package/cache/index.js +0 -2
- package/connections/Connection.d.ts +12 -5
- package/connections/Connection.js +37 -15
- package/drivers/DatabaseDriver.d.ts +25 -18
- package/drivers/DatabaseDriver.js +144 -45
- package/drivers/IDatabaseDriver.d.ts +118 -23
- package/entity/BaseEntity.d.ts +63 -4
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +95 -31
- package/entity/Collection.js +487 -139
- package/entity/EntityAssigner.js +37 -25
- package/entity/EntityFactory.d.ts +8 -9
- package/entity/EntityFactory.js +152 -100
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +69 -27
- package/entity/EntityLoader.d.ts +12 -13
- package/entity/EntityLoader.js +286 -125
- package/entity/EntityRepository.d.ts +28 -8
- package/entity/EntityRepository.js +8 -2
- package/entity/PolymorphicRef.d.ts +12 -0
- package/entity/PolymorphicRef.js +18 -0
- package/entity/Reference.d.ts +3 -8
- package/entity/Reference.js +62 -29
- package/entity/WrappedEntity.d.ts +7 -10
- package/entity/WrappedEntity.js +6 -7
- package/entity/defineEntity.d.ts +472 -313
- package/entity/defineEntity.js +134 -290
- package/entity/index.d.ts +2 -2
- package/entity/index.js +2 -2
- package/entity/utils.d.ts +6 -1
- package/entity/utils.js +46 -11
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +66 -0
- package/enums.d.ts +8 -6
- package/enums.js +13 -17
- package/errors.d.ts +26 -16
- package/errors.js +63 -31
- package/events/EventManager.d.ts +3 -5
- package/events/EventManager.js +37 -26
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/exceptions.js +9 -2
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +5 -6
- package/hydration/ObjectHydrator.js +109 -50
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +3 -4
- package/logging/SimpleLogger.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +4 -6
- package/logging/index.d.ts +2 -1
- package/logging/index.js +1 -1
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +11 -0
- package/metadata/EntitySchema.d.ts +47 -23
- package/metadata/EntitySchema.js +103 -34
- package/metadata/MetadataDiscovery.d.ts +65 -18
- package/metadata/MetadataDiscovery.js +940 -424
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +71 -2
- package/metadata/MetadataStorage.d.ts +11 -13
- package/metadata/MetadataStorage.js +79 -48
- package/metadata/MetadataValidator.d.ts +32 -9
- package/metadata/MetadataValidator.js +214 -44
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/metadata/types.d.ts +577 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
- package/naming-strategy/AbstractNamingStrategy.js +26 -5
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +7 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
- package/naming-strategy/MongoNamingStrategy.js +6 -6
- package/naming-strategy/NamingStrategy.d.ts +28 -4
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/not-supported.d.ts +2 -0
- package/not-supported.js +8 -0
- package/package.json +47 -36
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +33 -15
- package/platforms/Platform.js +125 -69
- package/serialization/EntitySerializer.d.ts +6 -3
- package/serialization/EntitySerializer.js +54 -30
- package/serialization/EntityTransformer.js +37 -22
- package/serialization/SerializationContext.d.ts +10 -14
- package/serialization/SerializationContext.js +24 -19
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.js +1 -1
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +1 -0
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.js +2 -2
- package/types/DoubleType.js +1 -1
- package/types/EnumArrayType.js +1 -2
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/TinyIntType.js +1 -1
- package/types/Type.d.ts +2 -4
- package/types/Type.js +3 -3
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +1 -4
- package/types/UuidType.d.ts +2 -0
- package/types/UuidType.js +14 -2
- package/types/index.d.ts +3 -2
- package/typings.d.ts +427 -170
- package/typings.js +100 -45
- package/unit-of-work/ChangeSet.d.ts +4 -6
- package/unit-of-work/ChangeSet.js +8 -9
- package/unit-of-work/ChangeSetComputer.d.ts +2 -12
- package/unit-of-work/ChangeSetComputer.js +61 -38
- package/unit-of-work/ChangeSetPersister.d.ts +10 -17
- package/unit-of-work/ChangeSetPersister.js +136 -73
- package/unit-of-work/CommitOrderCalculator.d.ts +13 -14
- package/unit-of-work/CommitOrderCalculator.js +22 -20
- package/unit-of-work/IdentityMap.d.ts +12 -3
- package/unit-of-work/IdentityMap.js +51 -13
- package/unit-of-work/UnitOfWork.d.ts +39 -23
- package/unit-of-work/UnitOfWork.js +441 -246
- package/utils/AbstractMigrator.d.ts +101 -0
- package/utils/AbstractMigrator.js +303 -0
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +30 -18
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +647 -185
- package/utils/Configuration.js +215 -252
- package/utils/ConfigurationLoader.d.ts +1 -52
- package/utils/ConfigurationLoader.js +1 -330
- package/utils/Cursor.d.ts +3 -6
- package/utils/Cursor.js +32 -17
- package/utils/DataloaderUtils.d.ts +10 -5
- package/utils/DataloaderUtils.js +42 -22
- package/utils/EntityComparator.d.ts +21 -21
- package/utils/EntityComparator.js +224 -118
- package/utils/QueryHelper.d.ts +34 -7
- package/utils/QueryHelper.js +183 -72
- package/utils/RawQueryFragment.d.ts +28 -34
- package/utils/RawQueryFragment.js +37 -72
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.js +11 -8
- package/utils/Utils.d.ts +16 -127
- package/utils/Utils.js +104 -402
- package/utils/clone.js +13 -23
- package/utils/env-vars.d.ts +7 -0
- package/utils/env-vars.js +98 -0
- package/utils/fs-utils.d.ts +20 -0
- package/utils/fs-utils.js +193 -0
- package/utils/index.d.ts +1 -3
- package/utils/index.js +1 -3
- package/utils/upsert-utils.d.ts +9 -4
- package/utils/upsert-utils.js +51 -5
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -13
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -32
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -11
- package/decorators/Embedded.d.ts +0 -12
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -33
- package/decorators/Entity.js +0 -12
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -16
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -8
- package/decorators/Formula.d.ts +0 -4
- package/decorators/Formula.js +0 -15
- package/decorators/Indexed.d.ts +0 -19
- package/decorators/Indexed.js +0 -20
- package/decorators/ManyToMany.d.ts +0 -42
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -34
- package/decorators/ManyToOne.js +0 -14
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -17
- package/decorators/OneToOne.d.ts +0 -28
- package/decorators/OneToOne.js +0 -7
- package/decorators/PrimaryKey.d.ts +0 -8
- package/decorators/PrimaryKey.js +0 -20
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -32
- package/decorators/Transactional.d.ts +0 -14
- package/decorators/Transactional.js +0 -28
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -47
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -17
- package/entity/ArrayCollection.d.ts +0 -118
- package/entity/ArrayCollection.js +0 -407
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -150
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -44
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -28
|
@@ -1,40 +1,67 @@
|
|
|
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
9
|
store(item) {
|
|
8
10
|
this.getStore(item.__meta.root).set(this.getPkHash(item), item);
|
|
9
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Stores an entity under an alternate key (non-PK property).
|
|
14
|
+
* This allows looking up entities by unique properties that are not the primary key.
|
|
15
|
+
*/
|
|
16
|
+
storeByKey(item, key, value, schema) {
|
|
17
|
+
const hash = this.getKeyHash(key, value, schema);
|
|
18
|
+
this.getStore(item.__meta.root).set(hash, item);
|
|
19
|
+
// Track this alternate key so we can clean it up when the entity is deleted
|
|
20
|
+
let keys = this.#alternateKeys.get(item);
|
|
21
|
+
if (!keys) {
|
|
22
|
+
keys = new Set();
|
|
23
|
+
this.#alternateKeys.set(item, keys);
|
|
24
|
+
}
|
|
25
|
+
keys.add(hash);
|
|
26
|
+
}
|
|
10
27
|
delete(item) {
|
|
11
|
-
|
|
28
|
+
const meta = item.__meta.root;
|
|
29
|
+
const store = this.getStore(meta);
|
|
30
|
+
store.delete(this.getPkHash(item));
|
|
31
|
+
// Also delete any alternate key entries for this entity
|
|
32
|
+
const altKeys = this.#alternateKeys.get(item);
|
|
33
|
+
if (altKeys) {
|
|
34
|
+
for (const hash of altKeys) {
|
|
35
|
+
store.delete(hash);
|
|
36
|
+
}
|
|
37
|
+
this.#alternateKeys.delete(item);
|
|
38
|
+
}
|
|
12
39
|
}
|
|
13
40
|
getByHash(meta, hash) {
|
|
14
41
|
const store = this.getStore(meta);
|
|
15
42
|
return store.has(hash) ? store.get(hash) : undefined;
|
|
16
43
|
}
|
|
17
44
|
getStore(meta) {
|
|
18
|
-
const store = this
|
|
45
|
+
const store = this.#registry.get(meta.class);
|
|
19
46
|
if (store) {
|
|
20
47
|
return store;
|
|
21
48
|
}
|
|
22
49
|
const newStore = new Map();
|
|
23
|
-
this
|
|
50
|
+
this.#registry.set(meta.class, newStore);
|
|
24
51
|
return newStore;
|
|
25
52
|
}
|
|
26
53
|
clear() {
|
|
27
|
-
this
|
|
54
|
+
this.#registry.clear();
|
|
28
55
|
}
|
|
29
56
|
values() {
|
|
30
57
|
const ret = [];
|
|
31
|
-
for (const store of this
|
|
58
|
+
for (const store of this.#registry.values()) {
|
|
32
59
|
ret.push(...store.values());
|
|
33
60
|
}
|
|
34
61
|
return ret;
|
|
35
62
|
}
|
|
36
63
|
*[Symbol.iterator]() {
|
|
37
|
-
for (const store of this
|
|
64
|
+
for (const store of this.#registry.values()) {
|
|
38
65
|
for (const item of store.values()) {
|
|
39
66
|
yield item;
|
|
40
67
|
}
|
|
@@ -42,7 +69,7 @@ export class IdentityMap {
|
|
|
42
69
|
}
|
|
43
70
|
keys() {
|
|
44
71
|
const ret = [];
|
|
45
|
-
for (const [cls, store] of this
|
|
72
|
+
for (const [cls, store] of this.#registry) {
|
|
46
73
|
ret.push(...[...store.keys()].map(hash => `${cls.name}-${hash}`));
|
|
47
74
|
}
|
|
48
75
|
return ret;
|
|
@@ -52,18 +79,29 @@ export class IdentityMap {
|
|
|
52
79
|
*/
|
|
53
80
|
get(hash) {
|
|
54
81
|
const [name, id] = hash.split('-', 2);
|
|
55
|
-
const cls = [...this
|
|
82
|
+
const cls = [...this.#registry.keys()].find(k => k.name === name);
|
|
56
83
|
if (!cls) {
|
|
57
84
|
return undefined;
|
|
58
85
|
}
|
|
59
|
-
const store = this
|
|
86
|
+
const store = this.#registry.get(cls);
|
|
60
87
|
return store.has(id) ? store.get(id) : undefined;
|
|
61
88
|
}
|
|
62
89
|
getPkHash(item) {
|
|
63
90
|
const wrapped = item.__helper;
|
|
64
91
|
const meta = wrapped.__meta;
|
|
65
92
|
const hash = wrapped.getSerializedPrimaryKey();
|
|
66
|
-
const schema = wrapped.__schema ?? meta.root.schema ?? this
|
|
93
|
+
const schema = wrapped.__schema ?? meta.root.schema ?? this.#defaultSchema;
|
|
94
|
+
if (schema) {
|
|
95
|
+
return schema + ':' + hash;
|
|
96
|
+
}
|
|
97
|
+
return hash;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates a hash for an alternate key lookup.
|
|
101
|
+
* Format: `[key]value` or `schema:[key]value`
|
|
102
|
+
*/
|
|
103
|
+
getKeyHash(key, value, schema) {
|
|
104
|
+
const hash = `[${key}]${value}`;
|
|
67
105
|
if (schema) {
|
|
68
106
|
return schema + ':' + hash;
|
|
69
107
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyEntity, EntityData, EntityMetadata, EntityProperty, FilterQuery, Primary } from '../typings.js';
|
|
1
|
+
import type { AnyEntity, EntityData, EntityMetadata, EntityName, EntityProperty, FilterQuery, Primary } from '../typings.js';
|
|
2
2
|
import { Collection } from '../entity/Collection.js';
|
|
3
3
|
import { Reference } from '../entity/Reference.js';
|
|
4
4
|
import { ChangeSet, ChangeSetType } from './ChangeSet.js';
|
|
@@ -7,27 +7,15 @@ 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;
|
|
13
|
+
/**
|
|
14
|
+
* Entity data can wary in its shape, e.g. we might get a deep relation graph with joined strategy, but for diffing,
|
|
15
|
+
* we need to normalize the shape, so relation values are only raw FKs. This method handles that.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
normalizeEntityData<T extends object>(meta: EntityMetadata<T>, data: EntityData<T>): void;
|
|
31
19
|
/**
|
|
32
20
|
* @internal
|
|
33
21
|
*/
|
|
@@ -36,11 +24,28 @@ export declare class UnitOfWork {
|
|
|
36
24
|
* @internal
|
|
37
25
|
*/
|
|
38
26
|
dispatchOnLoadEvent(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
unmarkAsLoaded(entity: AnyEntity): void;
|
|
39
31
|
/**
|
|
40
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`.
|
|
41
33
|
*/
|
|
42
|
-
getById<T extends object>(entityName:
|
|
43
|
-
|
|
34
|
+
getById<T extends object>(entityName: EntityName<T>, id: Primary<T> | Primary<T>[], schema?: string, convertCustomTypes?: boolean): T | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Returns entity from the identity map by an alternate key (non-PK property).
|
|
37
|
+
* @param convertCustomTypes - If true, the value is in database format and will be converted to JS format for lookup.
|
|
38
|
+
* If false (default), the value is assumed to be in JS format already.
|
|
39
|
+
*/
|
|
40
|
+
getByKey<T extends object>(entityName: EntityName<T>, key: string, value: unknown, schema?: string, convertCustomTypes?: boolean): T | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Stores an entity in the identity map under an alternate key (non-PK property).
|
|
43
|
+
* Also sets the property value on the entity.
|
|
44
|
+
* @param convertCustomTypes - If true, the value is in database format and will be converted to JS format.
|
|
45
|
+
* If false (default), the value is assumed to be in JS format already.
|
|
46
|
+
*/
|
|
47
|
+
storeByKey<T extends object>(entity: T, key: string, value: unknown, schema?: string, convertCustomTypes?: boolean): void;
|
|
48
|
+
tryGetById<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, schema?: string, strict?: boolean): T | null;
|
|
44
49
|
/**
|
|
45
50
|
* Returns map of all managed entities.
|
|
46
51
|
*/
|
|
@@ -53,7 +58,13 @@ export declare class UnitOfWork {
|
|
|
53
58
|
getRemoveStack(): Set<AnyEntity>;
|
|
54
59
|
getChangeSets(): ChangeSet<AnyEntity>[];
|
|
55
60
|
getCollectionUpdates(): Collection<AnyEntity>[];
|
|
56
|
-
getExtraUpdates(): Set<[
|
|
61
|
+
getExtraUpdates(): Set<[
|
|
62
|
+
AnyEntity,
|
|
63
|
+
string | string[],
|
|
64
|
+
AnyEntity | AnyEntity[] | Reference<any> | Collection<any>,
|
|
65
|
+
ChangeSet<any> | undefined,
|
|
66
|
+
ChangeSetType
|
|
67
|
+
]>;
|
|
57
68
|
shouldAutoFlush<T extends object>(meta: EntityMetadata<T>): boolean;
|
|
58
69
|
clearActionsQueue(): void;
|
|
59
70
|
computeChangeSet<T extends object>(entity: T, type?: ChangeSetType): void;
|
|
@@ -77,6 +88,11 @@ export declare class UnitOfWork {
|
|
|
77
88
|
getOrphanRemoveStack(): Set<AnyEntity>;
|
|
78
89
|
getChangeSetPersister(): ChangeSetPersister;
|
|
79
90
|
private findNewEntities;
|
|
91
|
+
/**
|
|
92
|
+
* For TPT inheritance, creates separate changesets for each table in the hierarchy.
|
|
93
|
+
* Uses the same entity instance for all changesets - only the metadata and payload differ.
|
|
94
|
+
*/
|
|
95
|
+
private createTPTChangeSets;
|
|
80
96
|
/**
|
|
81
97
|
* Returns `true` when the change set should be skipped as it will be empty after the extra update.
|
|
82
98
|
*/
|