@mikro-orm/core 7.0.4 → 7.0.5-dev.1
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 +583 -884
- package/EntityManager.js +1895 -1922
- package/MikroORM.d.ts +74 -103
- package/MikroORM.js +179 -178
- package/README.md +1 -1
- package/cache/CacheAdapter.d.ts +36 -36
- package/cache/FileCacheAdapter.d.ts +24 -30
- package/cache/FileCacheAdapter.js +78 -80
- package/cache/GeneratedCacheAdapter.d.ts +20 -18
- package/cache/GeneratedCacheAdapter.js +30 -30
- package/cache/MemoryCacheAdapter.d.ts +20 -18
- package/cache/MemoryCacheAdapter.js +36 -35
- package/cache/NullCacheAdapter.d.ts +16 -16
- package/cache/NullCacheAdapter.js +24 -24
- package/connections/Connection.d.ts +84 -95
- package/connections/Connection.js +168 -165
- package/drivers/DatabaseDriver.d.ts +80 -186
- package/drivers/DatabaseDriver.js +443 -450
- package/drivers/IDatabaseDriver.d.ts +301 -440
- package/entity/BaseEntity.d.ts +83 -120
- package/entity/BaseEntity.js +43 -43
- package/entity/Collection.d.ts +179 -212
- package/entity/Collection.js +721 -727
- package/entity/EntityAssigner.d.ts +77 -88
- package/entity/EntityAssigner.js +230 -231
- package/entity/EntityFactory.d.ts +54 -66
- package/entity/EntityFactory.js +383 -425
- package/entity/EntityHelper.d.ts +22 -34
- package/entity/EntityHelper.js +267 -280
- package/entity/EntityIdentifier.d.ts +4 -4
- package/entity/EntityIdentifier.js +10 -10
- package/entity/EntityLoader.d.ts +72 -98
- package/entity/EntityLoader.js +723 -753
- package/entity/EntityRepository.d.ts +201 -316
- package/entity/EntityRepository.js +213 -213
- package/entity/PolymorphicRef.d.ts +5 -5
- package/entity/PolymorphicRef.js +10 -10
- package/entity/Reference.d.ts +82 -126
- package/entity/Reference.js +274 -278
- package/entity/WrappedEntity.d.ts +72 -115
- package/entity/WrappedEntity.js +166 -168
- package/entity/defineEntity.d.ts +636 -1315
- package/entity/defineEntity.js +518 -527
- package/entity/utils.d.ts +3 -13
- package/entity/utils.js +73 -71
- package/entity/validators.js +43 -43
- package/entity/wrap.js +8 -8
- package/enums.d.ts +253 -258
- package/enums.js +252 -251
- package/errors.d.ts +72 -114
- package/errors.js +253 -350
- package/events/EventManager.d.ts +14 -26
- package/events/EventManager.js +77 -79
- package/events/EventSubscriber.d.ts +29 -29
- package/events/TransactionEventBroadcaster.d.ts +8 -15
- package/events/TransactionEventBroadcaster.js +14 -14
- package/exceptions.d.ts +40 -23
- package/exceptions.js +52 -35
- package/hydration/Hydrator.d.ts +17 -42
- package/hydration/Hydrator.js +43 -43
- package/hydration/ObjectHydrator.d.ts +17 -50
- package/hydration/ObjectHydrator.js +416 -481
- package/index.d.ts +2 -116
- package/index.js +1 -10
- package/logging/DefaultLogger.d.ts +32 -34
- package/logging/DefaultLogger.js +86 -86
- package/logging/Logger.d.ts +41 -41
- package/logging/SimpleLogger.d.ts +11 -13
- package/logging/SimpleLogger.js +22 -22
- package/logging/colors.d.ts +6 -6
- package/logging/colors.js +10 -11
- package/logging/inspect.js +7 -7
- package/metadata/EntitySchema.d.ts +127 -211
- package/metadata/EntitySchema.js +398 -397
- package/metadata/MetadataDiscovery.d.ts +114 -114
- package/metadata/MetadataDiscovery.js +1870 -1951
- package/metadata/MetadataProvider.d.ts +21 -24
- package/metadata/MetadataProvider.js +84 -82
- package/metadata/MetadataStorage.d.ts +32 -38
- package/metadata/MetadataStorage.js +118 -118
- package/metadata/MetadataValidator.d.ts +39 -39
- package/metadata/MetadataValidator.js +338 -381
- package/metadata/discover-entities.d.ts +2 -5
- package/metadata/discover-entities.js +37 -35
- package/metadata/types.d.ts +531 -615
- package/naming-strategy/AbstractNamingStrategy.d.ts +39 -54
- package/naming-strategy/AbstractNamingStrategy.js +85 -90
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
- package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
- package/naming-strategy/MongoNamingStrategy.d.ts +6 -6
- package/naming-strategy/MongoNamingStrategy.js +18 -18
- package/naming-strategy/NamingStrategy.d.ts +99 -109
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
- package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
- package/not-supported.js +4 -7
- package/package.json +1 -1
- package/platforms/ExceptionConverter.d.ts +1 -1
- package/platforms/ExceptionConverter.js +4 -4
- package/platforms/Platform.d.ts +301 -310
- package/platforms/Platform.js +640 -663
- package/serialization/EntitySerializer.d.ts +26 -49
- package/serialization/EntitySerializer.js +218 -224
- package/serialization/EntityTransformer.d.ts +6 -10
- package/serialization/EntityTransformer.js +217 -219
- package/serialization/SerializationContext.d.ts +23 -27
- package/serialization/SerializationContext.js +105 -105
- package/types/ArrayType.d.ts +8 -8
- package/types/ArrayType.js +33 -33
- package/types/BigIntType.d.ts +10 -17
- package/types/BigIntType.js +37 -37
- package/types/BlobType.d.ts +3 -3
- package/types/BlobType.js +13 -13
- package/types/BooleanType.d.ts +4 -4
- package/types/BooleanType.js +12 -12
- package/types/CharacterType.d.ts +2 -2
- package/types/CharacterType.js +6 -6
- package/types/DateTimeType.d.ts +5 -5
- package/types/DateTimeType.js +15 -15
- package/types/DateType.d.ts +5 -5
- package/types/DateType.js +15 -15
- package/types/DecimalType.d.ts +7 -7
- package/types/DecimalType.js +26 -26
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +12 -12
- package/types/EnumArrayType.d.ts +5 -5
- package/types/EnumArrayType.js +24 -24
- package/types/EnumType.d.ts +3 -3
- package/types/EnumType.js +11 -11
- package/types/FloatType.d.ts +3 -3
- package/types/FloatType.js +9 -9
- package/types/IntegerType.d.ts +3 -3
- package/types/IntegerType.js +9 -9
- package/types/IntervalType.d.ts +4 -4
- package/types/IntervalType.js +12 -12
- package/types/JsonType.d.ts +8 -8
- package/types/JsonType.js +32 -32
- package/types/MediumIntType.d.ts +1 -1
- package/types/MediumIntType.js +3 -3
- package/types/SmallIntType.d.ts +3 -3
- package/types/SmallIntType.js +9 -9
- package/types/StringType.d.ts +4 -4
- package/types/StringType.js +12 -12
- package/types/TextType.d.ts +3 -3
- package/types/TextType.js +9 -9
- package/types/TimeType.d.ts +5 -5
- package/types/TimeType.js +17 -17
- package/types/TinyIntType.d.ts +3 -3
- package/types/TinyIntType.js +10 -10
- package/types/Type.d.ts +79 -83
- package/types/Type.js +82 -82
- package/types/Uint8ArrayType.d.ts +4 -4
- package/types/Uint8ArrayType.js +21 -21
- package/types/UnknownType.d.ts +4 -4
- package/types/UnknownType.js +12 -12
- package/types/UuidType.d.ts +5 -5
- package/types/UuidType.js +19 -19
- package/types/index.d.ts +49 -75
- package/types/index.js +26 -52
- package/typings.d.ts +737 -1250
- package/typings.js +231 -244
- package/unit-of-work/ChangeSet.d.ts +26 -26
- package/unit-of-work/ChangeSet.js +56 -56
- package/unit-of-work/ChangeSetComputer.d.ts +12 -12
- package/unit-of-work/ChangeSetComputer.js +170 -178
- package/unit-of-work/ChangeSetPersister.d.ts +44 -63
- package/unit-of-work/ChangeSetPersister.js +421 -442
- package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
- package/unit-of-work/CommitOrderCalculator.js +88 -89
- package/unit-of-work/IdentityMap.d.ts +31 -31
- package/unit-of-work/IdentityMap.js +105 -105
- package/unit-of-work/UnitOfWork.d.ts +141 -181
- package/unit-of-work/UnitOfWork.js +1183 -1200
- package/utils/AbstractMigrator.d.ts +91 -111
- package/utils/AbstractMigrator.js +275 -275
- package/utils/AbstractSchemaGenerator.d.ts +34 -43
- package/utils/AbstractSchemaGenerator.js +122 -121
- package/utils/AsyncContext.d.ts +3 -3
- package/utils/AsyncContext.js +35 -34
- package/utils/Configuration.d.ts +808 -852
- package/utils/Configuration.js +344 -359
- package/utils/Cursor.d.ts +22 -40
- package/utils/Cursor.js +127 -135
- package/utils/DataloaderUtils.d.ts +43 -58
- package/utils/DataloaderUtils.js +198 -203
- package/utils/EntityComparator.d.ts +81 -98
- package/utils/EntityComparator.js +732 -828
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +3 -3
- package/utils/QueryHelper.d.ts +51 -79
- package/utils/QueryHelper.js +361 -372
- package/utils/RawQueryFragment.d.ts +34 -50
- package/utils/RawQueryFragment.js +105 -107
- package/utils/RequestContext.d.ts +32 -32
- package/utils/RequestContext.js +53 -52
- package/utils/TransactionContext.d.ts +16 -16
- package/utils/TransactionContext.js +27 -27
- package/utils/TransactionManager.d.ts +58 -58
- package/utils/TransactionManager.js +197 -199
- package/utils/Utils.d.ts +145 -204
- package/utils/Utils.js +812 -812
- package/utils/clone.js +113 -104
- package/utils/env-vars.js +88 -90
- package/utils/fs-utils.d.ts +15 -15
- package/utils/fs-utils.js +181 -180
- package/utils/upsert-utils.d.ts +5 -20
- package/utils/upsert-utils.js +116 -114
|
@@ -1,25 +1,6 @@
|
|
|
1
1
|
import type { PopulatePath } from '../enums.js';
|
|
2
2
|
import type { EntityManager } from '../EntityManager.js';
|
|
3
|
-
import type {
|
|
4
|
-
Dictionary,
|
|
5
|
-
EntityData,
|
|
6
|
-
EntityDictionary,
|
|
7
|
-
EntityMetadata,
|
|
8
|
-
IHydrator,
|
|
9
|
-
EntityKey,
|
|
10
|
-
PopulateOptions,
|
|
11
|
-
Primary,
|
|
12
|
-
AutoPath,
|
|
13
|
-
Ref,
|
|
14
|
-
AddEager,
|
|
15
|
-
LoadedReference,
|
|
16
|
-
EntityDTO,
|
|
17
|
-
Loaded,
|
|
18
|
-
SerializeDTO,
|
|
19
|
-
FromEntityType,
|
|
20
|
-
IsSubset,
|
|
21
|
-
MergeSelected,
|
|
22
|
-
} from '../typings.js';
|
|
3
|
+
import type { Dictionary, EntityData, EntityDictionary, EntityMetadata, IHydrator, EntityKey, PopulateOptions, Primary, AutoPath, Ref, AddEager, LoadedReference, EntityDTO, Loaded, SerializeDTO, FromEntityType, IsSubset, MergeSelected } from '../typings.js';
|
|
23
4
|
import { Reference } from './Reference.js';
|
|
24
5
|
import { type AssignOptions } from './EntityAssigner.js';
|
|
25
6
|
import type { EntityLoaderOptions } from './EntityLoader.js';
|
|
@@ -31,99 +12,75 @@ import type { Platform } from '../platforms/Platform.js';
|
|
|
31
12
|
import type { Configuration } from '../utils/Configuration.js';
|
|
32
13
|
/** @internal Wrapper attached to every managed entity, holding ORM state such as initialization flags, identity map references, and change tracking snapshots. */
|
|
33
14
|
export declare class WrappedEntity<Entity extends object> {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
entity
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
): Promise<Loaded<Entity, Hint, Fields, Excludes> | null>;
|
|
106
|
-
/** Loads the specified relations on this entity. */
|
|
107
|
-
populate<Hint extends string = never, Fields extends string = never>(
|
|
108
|
-
populate: AutoPath<Entity, Hint, PopulatePath.ALL>[] | false,
|
|
109
|
-
options?: EntityLoaderOptions<Entity, Fields>,
|
|
110
|
-
): Promise<Loaded<Entity, Hint>>;
|
|
111
|
-
/** Returns whether this entity has a primary key value set. */
|
|
112
|
-
hasPrimaryKey(): boolean;
|
|
113
|
-
/** Returns the primary key value, optionally converting custom types to their database representation. */
|
|
114
|
-
getPrimaryKey(convertCustomTypes?: boolean): Primary<Entity> | null;
|
|
115
|
-
/** Returns all primary key values as an array. Used internally for composite key handling. */
|
|
116
|
-
getPrimaryKeys(convertCustomTypes?: boolean): Primary<Entity>[] | null;
|
|
117
|
-
/** Returns the database schema this entity belongs to. */
|
|
118
|
-
getSchema(): string | undefined;
|
|
119
|
-
/** Sets the database schema for this entity. */
|
|
120
|
-
setSchema(schema?: string): void;
|
|
121
|
-
/** Sets the primary key value on the entity. */
|
|
122
|
-
setPrimaryKey(id: Primary<Entity> | null): void;
|
|
123
|
-
/** Returns the primary key serialized as a string suitable for identity map lookups. */
|
|
124
|
-
getSerializedPrimaryKey(): string;
|
|
125
|
-
get __meta(): EntityMetadata<Entity>;
|
|
126
|
-
get __platform(): Platform;
|
|
127
|
-
get __config(): Configuration;
|
|
128
|
-
get __primaryKeys(): Primary<Entity>[];
|
|
15
|
+
__initialized: boolean;
|
|
16
|
+
__populated?: boolean;
|
|
17
|
+
__managed?: boolean;
|
|
18
|
+
__onLoadFired?: boolean;
|
|
19
|
+
__schema?: string;
|
|
20
|
+
__em?: EntityManager;
|
|
21
|
+
__loadedProperties: Set<string>;
|
|
22
|
+
__data: Dictionary;
|
|
23
|
+
__processing: boolean;
|
|
24
|
+
__serializationContext: {
|
|
25
|
+
root?: SerializationContext<Entity>;
|
|
26
|
+
populate?: PopulateOptions<Entity>[];
|
|
27
|
+
fields?: Set<string>;
|
|
28
|
+
exclude?: readonly string[];
|
|
29
|
+
};
|
|
30
|
+
/** stores last known primary key, as its current state might be broken due to propagation/orphan removal, but we need to know the PK to be able t remove the entity */
|
|
31
|
+
__pk?: Primary<Entity>;
|
|
32
|
+
/** holds the reference wrapper instance (if created), so we can maintain the identity on reference wrappers too */
|
|
33
|
+
__reference?: Reference<Entity>;
|
|
34
|
+
/** holds last entity data snapshot, so we can compute changes when persisting managed entities */
|
|
35
|
+
__originalEntityData?: EntityData<Entity>;
|
|
36
|
+
/** holds wrapped primary key, so we can compute change set without eager commit */
|
|
37
|
+
__identifier?: EntityIdentifier;
|
|
38
|
+
private readonly entity;
|
|
39
|
+
private readonly hydrator;
|
|
40
|
+
private readonly pkGetter?;
|
|
41
|
+
private readonly pkSerializer?;
|
|
42
|
+
private readonly pkGetterConverted?;
|
|
43
|
+
constructor(entity: Entity, hydrator: IHydrator, pkGetter?: (e: Entity) => Primary<Entity>, pkSerializer?: (e: Entity) => string, pkGetterConverted?: (e: Entity) => Primary<Entity>);
|
|
44
|
+
/** Returns whether the entity has been fully loaded from the database. */
|
|
45
|
+
isInitialized(): boolean;
|
|
46
|
+
/** Returns whether the entity is managed by an EntityManager (tracked in the identity map). */
|
|
47
|
+
isManaged(): boolean;
|
|
48
|
+
/** Marks the entity as populated or not for serialization purposes. */
|
|
49
|
+
populated(populated?: boolean | undefined): void;
|
|
50
|
+
/** Sets the serialization context with populate hints, field selections, and exclusions. */
|
|
51
|
+
setSerializationContext<Hint extends string = never, Fields extends string = never, Exclude extends string = never>(options: LoadHint<Entity, Hint, Fields, Exclude>): void;
|
|
52
|
+
/** Returns a Reference wrapper for this entity, creating one if it does not already exist. */
|
|
53
|
+
toReference(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
|
|
54
|
+
/** Converts the entity to a plain object representation, optionally excluding specified fields. */
|
|
55
|
+
toObject<Ignored extends EntityKey<Entity> = never>(ignoreFields?: Ignored[]): Omit<EntityDTO<Entity>, Ignored>;
|
|
56
|
+
/** Serializes the entity with control over which relations and fields to include or exclude. */
|
|
57
|
+
serialize<Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Entity, Hint, Exclude>): SerializeDTO<Entity, Hint, Exclude>;
|
|
58
|
+
/** Converts the entity to a plain object, including all properties regardless of serialization rules. */
|
|
59
|
+
toPOJO(): EntityDTO<Entity>;
|
|
60
|
+
/** Serializes the entity using its `toJSON` method (supports `JSON.stringify`). */
|
|
61
|
+
toJSON(...args: any[]): EntityDictionary<Entity>;
|
|
62
|
+
/** Assigns the given data to this entity, updating its properties and relations. */
|
|
63
|
+
assign<Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Convert extends boolean = false, Data extends EntityData<Naked, Convert> | Partial<EntityDTO<Naked>> = EntityData<Naked, Convert> | Partial<EntityDTO<Naked>>>(data: Data & IsSubset<EntityData<Naked>, Data>, options?: AssignOptions<Convert>): MergeSelected<Entity, Naked, keyof Data & string>;
|
|
64
|
+
/** Initializes (refreshes) the entity by reloading it from the database. Returns null if not found. */
|
|
65
|
+
init<Hint extends string = never, Fields extends string = never, Excludes extends string = never>(options?: FindOneOptions<Entity, Hint, Fields, Excludes>): Promise<Loaded<Entity, Hint, Fields, Excludes> | null>;
|
|
66
|
+
/** Loads the specified relations on this entity. */
|
|
67
|
+
populate<Hint extends string = never, Fields extends string = never>(populate: AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity, Fields>): Promise<Loaded<Entity, Hint>>;
|
|
68
|
+
/** Returns whether this entity has a primary key value set. */
|
|
69
|
+
hasPrimaryKey(): boolean;
|
|
70
|
+
/** Returns the primary key value, optionally converting custom types to their database representation. */
|
|
71
|
+
getPrimaryKey(convertCustomTypes?: boolean): Primary<Entity> | null;
|
|
72
|
+
/** Returns all primary key values as an array. Used internally for composite key handling. */
|
|
73
|
+
getPrimaryKeys(convertCustomTypes?: boolean): Primary<Entity>[] | null;
|
|
74
|
+
/** Returns the database schema this entity belongs to. */
|
|
75
|
+
getSchema(): string | undefined;
|
|
76
|
+
/** Sets the database schema for this entity. */
|
|
77
|
+
setSchema(schema?: string): void;
|
|
78
|
+
/** Sets the primary key value on the entity. */
|
|
79
|
+
setPrimaryKey(id: Primary<Entity> | null): void;
|
|
80
|
+
/** Returns the primary key serialized as a string suitable for identity map lookups. */
|
|
81
|
+
getSerializedPrimaryKey(): string;
|
|
82
|
+
get __meta(): EntityMetadata<Entity>;
|
|
83
|
+
get __platform(): Platform;
|
|
84
|
+
get __config(): Configuration;
|
|
85
|
+
get __primaryKeys(): Primary<Entity>[];
|
|
129
86
|
}
|
package/entity/WrappedEntity.js
CHANGED
|
@@ -8,173 +8,171 @@ import { EntitySerializer } from '../serialization/EntitySerializer.js';
|
|
|
8
8
|
import { expandDotPaths } from './utils.js';
|
|
9
9
|
/** @internal Wrapper attached to every managed entity, holding ORM state such as initialization flags, identity map references, and change tracking snapshots. */
|
|
10
10
|
export class WrappedEntity {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
this.__pk
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
if (convertCustomTypes) {
|
|
122
|
-
return this.__pk ?? this.pkGetterConverted(this.entity);
|
|
123
|
-
}
|
|
124
|
-
return this.__pk ?? this.pkGetter(this.entity);
|
|
125
|
-
}
|
|
126
|
-
/** Returns all primary key values as an array. Used internally for composite key handling. */
|
|
127
|
-
// TODO: currently used only in `Driver.syncCollection` — candidate for removal
|
|
128
|
-
getPrimaryKeys(convertCustomTypes = false) {
|
|
129
|
-
const pk = this.getPrimaryKey(convertCustomTypes);
|
|
130
|
-
if (pk == null) {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
if (this.__meta.compositePK) {
|
|
134
|
-
return this.__meta.primaryKeys.reduce((ret, pk) => {
|
|
135
|
-
const child = this.entity[pk];
|
|
136
|
-
if (Utils.isEntity(child, true)) {
|
|
137
|
-
const childPk = helper(child).getPrimaryKeys(convertCustomTypes);
|
|
138
|
-
ret.push(...childPk);
|
|
139
|
-
} else {
|
|
140
|
-
ret.push(child);
|
|
11
|
+
constructor(entity, hydrator, pkGetter, pkSerializer, pkGetterConverted) {
|
|
12
|
+
this.entity = entity;
|
|
13
|
+
this.hydrator = hydrator;
|
|
14
|
+
this.pkGetter = pkGetter;
|
|
15
|
+
this.pkSerializer = pkSerializer;
|
|
16
|
+
this.pkGetterConverted = pkGetterConverted;
|
|
17
|
+
this.__initialized = true;
|
|
18
|
+
this.__serializationContext = {};
|
|
19
|
+
this.__loadedProperties = new Set();
|
|
20
|
+
this.__data = {};
|
|
21
|
+
this.__processing = false;
|
|
22
|
+
}
|
|
23
|
+
/** Returns whether the entity has been fully loaded from the database. */
|
|
24
|
+
isInitialized() {
|
|
25
|
+
return this.__initialized;
|
|
26
|
+
}
|
|
27
|
+
/** Returns whether the entity is managed by an EntityManager (tracked in the identity map). */
|
|
28
|
+
isManaged() {
|
|
29
|
+
return !!this.__managed;
|
|
30
|
+
}
|
|
31
|
+
/** Marks the entity as populated or not for serialization purposes. */
|
|
32
|
+
populated(populated = true) {
|
|
33
|
+
this.__populated = populated;
|
|
34
|
+
}
|
|
35
|
+
/** Sets the serialization context with populate hints, field selections, and exclusions. */
|
|
36
|
+
setSerializationContext(options) {
|
|
37
|
+
const exclude = options.exclude ?? [];
|
|
38
|
+
const context = this.__serializationContext;
|
|
39
|
+
const populate = expandDotPaths(this.__meta, options.populate);
|
|
40
|
+
context.populate = context.populate ? context.populate.concat(populate) : populate;
|
|
41
|
+
context.exclude = context.exclude ? context.exclude.concat(exclude) : exclude;
|
|
42
|
+
if (context.fields && options.fields) {
|
|
43
|
+
options.fields.forEach(f => context.fields.add(f));
|
|
44
|
+
}
|
|
45
|
+
else if (options.fields) {
|
|
46
|
+
context.fields = new Set(options.fields);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
context.fields = new Set(['*']);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Returns a Reference wrapper for this entity, creating one if it does not already exist. */
|
|
53
|
+
toReference() {
|
|
54
|
+
this.__reference ??= new Reference(this.entity);
|
|
55
|
+
return this.__reference;
|
|
56
|
+
}
|
|
57
|
+
/** Converts the entity to a plain object representation, optionally excluding specified fields. */
|
|
58
|
+
toObject(ignoreFields) {
|
|
59
|
+
return EntityTransformer.toObject(this.entity, ignoreFields);
|
|
60
|
+
}
|
|
61
|
+
/** Serializes the entity with control over which relations and fields to include or exclude. */
|
|
62
|
+
serialize(options) {
|
|
63
|
+
return EntitySerializer.serialize(this.entity, options);
|
|
64
|
+
}
|
|
65
|
+
/** Converts the entity to a plain object, including all properties regardless of serialization rules. */
|
|
66
|
+
toPOJO() {
|
|
67
|
+
return EntityTransformer.toObject(this.entity, [], true);
|
|
68
|
+
}
|
|
69
|
+
/** Serializes the entity using its `toJSON` method (supports `JSON.stringify`). */
|
|
70
|
+
toJSON(...args) {
|
|
71
|
+
// toJSON methods is added to the prototype during discovery to support automatic serialization via JSON.stringify()
|
|
72
|
+
return this.entity.toJSON(...args);
|
|
73
|
+
}
|
|
74
|
+
/** Assigns the given data to this entity, updating its properties and relations. */
|
|
75
|
+
assign(data, options) {
|
|
76
|
+
if ('assign' in this.entity) {
|
|
77
|
+
return this.entity.assign(data, options);
|
|
78
|
+
}
|
|
79
|
+
return EntityAssigner.assign(this.entity, data, options);
|
|
80
|
+
}
|
|
81
|
+
/** Initializes (refreshes) the entity by reloading it from the database. Returns null if not found. */
|
|
82
|
+
async init(options) {
|
|
83
|
+
if (!this.__em) {
|
|
84
|
+
throw ValidationError.entityNotManaged(this.entity);
|
|
85
|
+
}
|
|
86
|
+
return this.__em.findOne(this.entity.constructor, this.entity, {
|
|
87
|
+
...options,
|
|
88
|
+
refresh: true,
|
|
89
|
+
schema: this.__schema,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/** Loads the specified relations on this entity. */
|
|
93
|
+
async populate(populate, options = {}) {
|
|
94
|
+
if (!this.__em) {
|
|
95
|
+
throw ValidationError.entityNotManaged(this.entity);
|
|
96
|
+
}
|
|
97
|
+
// @ts-ignore hard to type
|
|
98
|
+
await this.__em.populate(this.entity, populate, options);
|
|
99
|
+
return this.entity;
|
|
100
|
+
}
|
|
101
|
+
/** Returns whether this entity has a primary key value set. */
|
|
102
|
+
hasPrimaryKey() {
|
|
103
|
+
const pk = this.getPrimaryKey();
|
|
104
|
+
return pk != null;
|
|
105
|
+
}
|
|
106
|
+
/** Returns the primary key value, optionally converting custom types to their database representation. */
|
|
107
|
+
getPrimaryKey(convertCustomTypes = false) {
|
|
108
|
+
const prop = this.__meta.getPrimaryProps()[0];
|
|
109
|
+
if (!prop) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
if (this.__pk != null && this.__meta.compositePK) {
|
|
113
|
+
return Utils.getCompositeKeyValue(this.__pk, this.__meta, convertCustomTypes ? 'convertToDatabaseValue' : false, this.__platform);
|
|
114
|
+
}
|
|
115
|
+
if (convertCustomTypes && this.__pk != null && prop.customType) {
|
|
116
|
+
return prop.customType.convertToDatabaseValue(this.__pk, this.__platform);
|
|
117
|
+
}
|
|
118
|
+
if (convertCustomTypes) {
|
|
119
|
+
return this.__pk ?? this.pkGetterConverted(this.entity);
|
|
141
120
|
}
|
|
142
|
-
return
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
121
|
+
return this.__pk ?? this.pkGetter(this.entity);
|
|
122
|
+
}
|
|
123
|
+
/** Returns all primary key values as an array. Used internally for composite key handling. */
|
|
124
|
+
// TODO: currently used only in `Driver.syncCollection` — candidate for removal
|
|
125
|
+
getPrimaryKeys(convertCustomTypes = false) {
|
|
126
|
+
const pk = this.getPrimaryKey(convertCustomTypes);
|
|
127
|
+
if (pk == null) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
if (this.__meta.compositePK) {
|
|
131
|
+
return this.__meta.primaryKeys.reduce((ret, pk) => {
|
|
132
|
+
const child = this.entity[pk];
|
|
133
|
+
if (Utils.isEntity(child, true)) {
|
|
134
|
+
const childPk = helper(child).getPrimaryKeys(convertCustomTypes);
|
|
135
|
+
ret.push(...childPk);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
ret.push(child);
|
|
139
|
+
}
|
|
140
|
+
return ret;
|
|
141
|
+
}, []);
|
|
142
|
+
}
|
|
143
|
+
return [pk];
|
|
144
|
+
}
|
|
145
|
+
/** Returns the database schema this entity belongs to. */
|
|
146
|
+
getSchema() {
|
|
147
|
+
return this.__schema;
|
|
148
|
+
}
|
|
149
|
+
/** Sets the database schema for this entity. */
|
|
150
|
+
setSchema(schema) {
|
|
151
|
+
this.__schema = schema;
|
|
152
|
+
}
|
|
153
|
+
/** Sets the primary key value on the entity. */
|
|
154
|
+
setPrimaryKey(id) {
|
|
155
|
+
this.entity[this.__meta.primaryKeys[0]] = id;
|
|
156
|
+
this.__pk = id;
|
|
157
|
+
}
|
|
158
|
+
/** Returns the primary key serialized as a string suitable for identity map lookups. */
|
|
159
|
+
getSerializedPrimaryKey() {
|
|
160
|
+
return this.pkSerializer(this.entity);
|
|
161
|
+
}
|
|
162
|
+
get __meta() {
|
|
163
|
+
return this.entity.__meta;
|
|
164
|
+
}
|
|
165
|
+
get __platform() {
|
|
166
|
+
return this.entity.__platform;
|
|
167
|
+
}
|
|
168
|
+
get __config() {
|
|
169
|
+
return this.__em?.config ?? this.entity.__config;
|
|
170
|
+
}
|
|
171
|
+
get __primaryKeys() {
|
|
172
|
+
return Utils.getPrimaryKeyValues(this.entity, this.__meta);
|
|
173
|
+
}
|
|
174
|
+
/** @ignore */
|
|
175
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
176
|
+
return `[WrappedEntity<${this.__meta.className}>]`;
|
|
177
|
+
}
|
|
180
178
|
}
|