@mikro-orm/core 7.0.0-dev.32 → 7.0.0-dev.321
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 +71 -63
- package/EntityManager.js +365 -283
- package/MikroORM.d.ts +44 -35
- package/MikroORM.js +109 -142
- package/README.md +7 -4
- package/cache/FileCacheAdapter.d.ts +1 -2
- package/cache/FileCacheAdapter.js +19 -14
- package/cache/GeneratedCacheAdapter.d.ts +0 -1
- package/cache/GeneratedCacheAdapter.js +0 -2
- 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 +101 -29
- package/entity/Collection.js +473 -115
- package/entity/EntityAssigner.js +37 -25
- package/entity/EntityFactory.d.ts +7 -1
- package/entity/EntityFactory.js +116 -64
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +69 -27
- package/entity/EntityLoader.d.ts +11 -10
- package/entity/EntityLoader.js +264 -102
- 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 +2 -6
- package/entity/Reference.js +52 -19
- package/entity/WrappedEntity.d.ts +3 -8
- package/entity/WrappedEntity.js +6 -7
- package/entity/defineEntity.d.ts +525 -311
- 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 +20 -10
- package/errors.js +63 -31
- package/events/EventManager.d.ts +2 -1
- package/events/EventManager.js +24 -13
- 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 +4 -4
- package/hydration/ObjectHydrator.js +105 -46
- 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 +5 -7
- 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 +64 -9
- package/metadata/MetadataDiscovery.js +867 -354
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +71 -2
- package/metadata/MetadataStorage.d.ts +13 -11
- package/metadata/MetadataStorage.js +72 -41
- 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 +6 -5
- 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 +53 -29
- package/serialization/EntityTransformer.js +33 -21
- package/serialization/SerializationContext.d.ts +6 -6
- package/serialization/SerializationContext.js +4 -4
- 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 +3 -8
- package/unit-of-work/ChangeSetComputer.js +49 -26
- package/unit-of-work/ChangeSetPersister.d.ts +13 -12
- package/unit-of-work/ChangeSetPersister.js +107 -44
- package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
- package/unit-of-work/CommitOrderCalculator.js +17 -15
- package/unit-of-work/IdentityMap.d.ts +12 -0
- package/unit-of-work/IdentityMap.js +39 -1
- package/unit-of-work/UnitOfWork.d.ts +34 -4
- package/unit-of-work/UnitOfWork.js +294 -107
- 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 +796 -211
- package/utils/Configuration.js +160 -197
- package/utils/ConfigurationLoader.d.ts +1 -52
- package/utils/ConfigurationLoader.js +1 -330
- package/utils/Cursor.d.ts +0 -3
- package/utils/Cursor.js +29 -14
- package/utils/DataloaderUtils.d.ts +10 -5
- package/utils/DataloaderUtils.js +42 -22
- package/utils/EntityComparator.d.ts +16 -9
- package/utils/EntityComparator.js +202 -96
- 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 -7
- package/utils/Utils.d.ts +16 -127
- package/utils/Utils.js +106 -401
- 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 +34 -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
|
@@ -2,7 +2,7 @@ import type { PopulatePath } from '../enums.js';
|
|
|
2
2
|
import type { CreateOptions, EntityManager, MergeOptions } from '../EntityManager.js';
|
|
3
3
|
import type { AssignOptions } from './EntityAssigner.js';
|
|
4
4
|
import type { EntityData, EntityName, Primary, Loaded, FilterQuery, EntityDictionary, AutoPath, RequiredEntityData, Ref, EntityType, EntityDTO, MergeSelected, FromEntityType, IsSubset, MergeLoaded, ArrayElement } from '../typings.js';
|
|
5
|
-
import type { CountOptions, DeleteOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions, GetReferenceOptions, NativeInsertUpdateOptions, UpdateOptions, UpsertManyOptions, UpsertOptions } from '../drivers/IDatabaseDriver.js';
|
|
5
|
+
import type { CountOptions, DeleteOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions, GetReferenceOptions, NativeInsertUpdateOptions, StreamOptions, UpdateOptions, UpsertManyOptions, UpsertOptions } from '../drivers/IDatabaseDriver.js';
|
|
6
6
|
import type { EntityLoaderOptions } from './EntityLoader.js';
|
|
7
7
|
import type { Cursor } from '../utils/Cursor.js';
|
|
8
8
|
export declare class EntityRepository<Entity extends object> {
|
|
@@ -80,11 +80,15 @@ export declare class EntityRepository<Entity extends object> {
|
|
|
80
80
|
/**
|
|
81
81
|
* @inheritDoc EntityManager.findByCursor
|
|
82
82
|
*/
|
|
83
|
-
findByCursor<Hint extends string = never, Fields extends string = '*', Excludes extends string = never, IncludeCount extends boolean = true>(
|
|
83
|
+
findByCursor<Hint extends string = never, Fields extends string = '*', Excludes extends string = never, IncludeCount extends boolean = true>(options: FindByCursorOptions<Entity, Hint, Fields, Excludes, IncludeCount>): Promise<Cursor<Entity, Hint, Fields, Excludes, IncludeCount>>;
|
|
84
84
|
/**
|
|
85
85
|
* Finds all entities of given type. You can pass additional options via the `options` parameter.
|
|
86
86
|
*/
|
|
87
87
|
findAll<Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(options?: FindAllOptions<Entity, Hint, Fields, Excludes>): Promise<Loaded<Entity, Hint, Fields, Excludes>[]>;
|
|
88
|
+
/**
|
|
89
|
+
* @inheritDoc EntityManager.stream
|
|
90
|
+
*/
|
|
91
|
+
stream<Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(options?: StreamOptions<Entity, Hint, Fields, Excludes>): AsyncIterableIterator<Loaded<Entity, Hint, Fields, Excludes>>;
|
|
88
92
|
/**
|
|
89
93
|
* @inheritDoc EntityManager.insert
|
|
90
94
|
*/
|
|
@@ -107,10 +111,26 @@ export declare class EntityRepository<Entity extends object> {
|
|
|
107
111
|
map(result: EntityDictionary<Entity>, options?: {
|
|
108
112
|
schema?: string;
|
|
109
113
|
}): Entity;
|
|
114
|
+
/**
|
|
115
|
+
* Gets a reference to the entity identified by the given type and alternate key property without actually loading it.
|
|
116
|
+
* The key option specifies which property to use for identity map lookup instead of the primary key.
|
|
117
|
+
*/
|
|
118
|
+
getReference<K extends string & keyof Entity>(id: Entity[K], options: Omit<GetReferenceOptions, 'key' | 'wrapped'> & {
|
|
119
|
+
key: K;
|
|
120
|
+
wrapped: true;
|
|
121
|
+
}): Ref<Entity>;
|
|
122
|
+
/**
|
|
123
|
+
* Gets a reference to the entity identified by the given type and alternate key property without actually loading it.
|
|
124
|
+
* The key option specifies which property to use for identity map lookup instead of the primary key.
|
|
125
|
+
*/
|
|
126
|
+
getReference<K extends string & keyof Entity>(id: Entity[K], options: Omit<GetReferenceOptions, 'key'> & {
|
|
127
|
+
key: K;
|
|
128
|
+
wrapped?: false;
|
|
129
|
+
}): Entity;
|
|
110
130
|
/**
|
|
111
131
|
* Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
|
|
112
132
|
*/
|
|
113
|
-
getReference(id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped'> & {
|
|
133
|
+
getReference(id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped' | 'key'> & {
|
|
114
134
|
wrapped: true;
|
|
115
135
|
}): Ref<Entity>;
|
|
116
136
|
/**
|
|
@@ -120,7 +140,7 @@ export declare class EntityRepository<Entity extends object> {
|
|
|
120
140
|
/**
|
|
121
141
|
* Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
|
|
122
142
|
*/
|
|
123
|
-
getReference(id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped'> & {
|
|
143
|
+
getReference(id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped' | 'key'> & {
|
|
124
144
|
wrapped: false;
|
|
125
145
|
}): Entity;
|
|
126
146
|
/**
|
|
@@ -130,7 +150,7 @@ export declare class EntityRepository<Entity extends object> {
|
|
|
130
150
|
/**
|
|
131
151
|
* Loads specified relations in batch. This will execute one query for each relation, that will populate it on all the specified entities.
|
|
132
152
|
*/
|
|
133
|
-
populate<Ent extends Entity | Entity[], Hint extends string = never, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Fields extends string =
|
|
153
|
+
populate<Ent extends Entity | Entity[], Hint extends string = never, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Fields extends string = never, Excludes extends string = never>(entities: Ent, populate: AutoPath<Naked, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Naked, Fields, Excludes>): Promise<Ent extends object[] ? MergeLoaded<ArrayElement<Ent>, Naked, Hint, Fields, Excludes>[] : MergeLoaded<Ent, Naked, Hint, Fields, Excludes>>;
|
|
134
154
|
/**
|
|
135
155
|
* Creates new instance of given entity and populates it with given data.
|
|
136
156
|
* The entity constructor will be used unless you provide `{ managed: true }` in the `options` parameter.
|
|
@@ -146,13 +166,13 @@ export declare class EntityRepository<Entity extends object> {
|
|
|
146
166
|
* The newly created entity will be automatically marked for persistence via `em.persist` unless you disable this
|
|
147
167
|
* behavior, either locally via `persist: false` option, or globally via `persistOnCreate` ORM config option.
|
|
148
168
|
*/
|
|
149
|
-
create<Convert extends boolean = false>(data: RequiredEntityData<Entity, never, Convert>, options?: CreateOptions<Convert>): Entity;
|
|
169
|
+
create<Convert extends boolean = false, Data extends RequiredEntityData<Entity, never, Convert> = RequiredEntityData<Entity, never, Convert>>(data: Data & IsSubset<RequiredEntityData<Entity, never, Convert>, Data>, options?: CreateOptions<Convert>): Entity;
|
|
150
170
|
/**
|
|
151
171
|
* Creates new instance of given entity and populates it with given data.
|
|
152
172
|
* The entity constructor will be used unless you provide `{ managed: true }` in the `options` parameter.
|
|
153
173
|
* The constructor will be given parameters based on the defined constructor of the entity. If the constructor
|
|
154
174
|
* parameter matches a property name, its value will be extracted from `data`. If no matching property exists,
|
|
155
|
-
* the whole `data` parameter will be
|
|
175
|
+
* the whole `data` parameter will be pass. This means we can also define `constructor(data: Partial<T>)` and
|
|
156
176
|
* `em.create()` will pass the data into it (unless we have a property named `data` too).
|
|
157
177
|
*
|
|
158
178
|
* The parameters are strictly checked, you need to provide all required properties. You can use `OptionalProps`
|
|
@@ -162,7 +182,7 @@ export declare class EntityRepository<Entity extends object> {
|
|
|
162
182
|
* The newly created entity will be automatically marked for persistence via `em.persist` unless you disable this
|
|
163
183
|
* behavior, either locally via `persist: false` option, or globally via `persistOnCreate` ORM config option.
|
|
164
184
|
*/
|
|
165
|
-
create<Convert extends boolean = false>(data: EntityData<Entity, Convert>, options: CreateOptions<Convert> & {
|
|
185
|
+
create<Convert extends boolean = false, Data extends EntityData<Entity, Convert> = EntityData<Entity, Convert>>(data: Data & IsSubset<EntityData<Entity, Convert>, Data>, options: CreateOptions<Convert> & {
|
|
166
186
|
partial: true;
|
|
167
187
|
}): Entity;
|
|
168
188
|
/**
|
|
@@ -90,8 +90,8 @@ export class EntityRepository {
|
|
|
90
90
|
/**
|
|
91
91
|
* @inheritDoc EntityManager.findByCursor
|
|
92
92
|
*/
|
|
93
|
-
async findByCursor(
|
|
94
|
-
return this.getEntityManager().findByCursor(this.entityName,
|
|
93
|
+
async findByCursor(options) {
|
|
94
|
+
return this.getEntityManager().findByCursor(this.entityName, options);
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
97
|
* Finds all entities of given type. You can pass additional options via the `options` parameter.
|
|
@@ -99,6 +99,12 @@ export class EntityRepository {
|
|
|
99
99
|
async findAll(options) {
|
|
100
100
|
return this.getEntityManager().findAll(this.entityName, options);
|
|
101
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* @inheritDoc EntityManager.stream
|
|
104
|
+
*/
|
|
105
|
+
async *stream(options) {
|
|
106
|
+
yield* this.getEntityManager().stream(this.entityName, options);
|
|
107
|
+
}
|
|
102
108
|
/**
|
|
103
109
|
* @inheritDoc EntityManager.insert
|
|
104
110
|
*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrapper class for polymorphic relation reference data.
|
|
3
|
+
* Holds the discriminator value (type identifier) and the primary key value(s).
|
|
4
|
+
* Used internally to track polymorphic FK values before hydration.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PolymorphicRef {
|
|
7
|
+
readonly discriminator: string;
|
|
8
|
+
id: unknown;
|
|
9
|
+
constructor(discriminator: string, id: unknown);
|
|
10
|
+
/** Returns `[discriminator, ...idValues]` tuple suitable for column-level expansion. */
|
|
11
|
+
toTuple(): unknown[];
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Utils } from '../utils/Utils.js';
|
|
2
|
+
/**
|
|
3
|
+
* Wrapper class for polymorphic relation reference data.
|
|
4
|
+
* Holds the discriminator value (type identifier) and the primary key value(s).
|
|
5
|
+
* Used internally to track polymorphic FK values before hydration.
|
|
6
|
+
*/
|
|
7
|
+
export class PolymorphicRef {
|
|
8
|
+
discriminator;
|
|
9
|
+
id;
|
|
10
|
+
constructor(discriminator, id) {
|
|
11
|
+
this.discriminator = discriminator;
|
|
12
|
+
this.id = id;
|
|
13
|
+
}
|
|
14
|
+
/** Returns `[discriminator, ...idValues]` tuple suitable for column-level expansion. */
|
|
15
|
+
toTuple() {
|
|
16
|
+
return [this.discriminator, ...Utils.asArray(this.id)];
|
|
17
|
+
}
|
|
18
|
+
}
|
package/entity/Reference.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import type { AddEager, AddOptional, Dictionary, EntityClass, EntityKey, EntityProperty, Loaded, LoadedReference, Primary, Ref } from '../typings.js';
|
|
3
2
|
import type { FindOneOptions, FindOneOrFailOptions } from '../drivers/IDatabaseDriver.js';
|
|
4
3
|
export declare class Reference<T extends object> {
|
|
5
4
|
private entity;
|
|
5
|
+
private property?;
|
|
6
6
|
constructor(entity: T);
|
|
7
7
|
static create<T extends object>(entity: T | Ref<T>): Ref<T>;
|
|
8
8
|
static createFromPK<T extends object>(entityType: EntityClass<T>, pk: Primary<T>, options?: {
|
|
@@ -42,8 +42,6 @@ export declare class Reference<T extends object> {
|
|
|
42
42
|
isInitialized(): boolean;
|
|
43
43
|
populated(populated?: boolean): void;
|
|
44
44
|
toJSON(...args: any[]): Dictionary;
|
|
45
|
-
/** @ignore */
|
|
46
|
-
[inspect.custom](depth?: number): string;
|
|
47
45
|
}
|
|
48
46
|
export declare class ScalarReference<Value> {
|
|
49
47
|
private value?;
|
|
@@ -65,8 +63,6 @@ export declare class ScalarReference<Value> {
|
|
|
65
63
|
bind<Entity extends object>(entity: Entity, property: EntityKey<Entity>): void;
|
|
66
64
|
unwrap(): Value | undefined;
|
|
67
65
|
isInitialized(): boolean;
|
|
68
|
-
/** @ignore */
|
|
69
|
-
[inspect.custom](): string;
|
|
70
66
|
}
|
|
71
67
|
export interface LoadReferenceOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never> extends FindOneOptions<T, P, F, E> {
|
|
72
68
|
dataloader?: boolean;
|
|
@@ -77,7 +73,7 @@ export interface LoadReferenceOrFailOptions<T extends object, P extends string =
|
|
|
77
73
|
/**
|
|
78
74
|
* shortcut for `wrap(entity).toReference()`
|
|
79
75
|
*/
|
|
80
|
-
export declare function ref<I extends unknown | Ref<unknown> | undefined | null, T extends I & {}>(entity: I): Ref<T> & LoadedReference<Loaded<T, AddEager<T>>> | AddOptional<typeof entity>;
|
|
76
|
+
export declare function ref<I extends unknown | Ref<unknown> | undefined | null, T extends I & {}>(entity: I): (Ref<T> & LoadedReference<Loaded<T, AddEager<T>>>) | AddOptional<typeof entity>;
|
|
81
77
|
/**
|
|
82
78
|
* shortcut for `Reference.createFromPK(entityType, pk)`
|
|
83
79
|
*/
|
package/entity/Reference.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { DataloaderType } from '../enums.js';
|
|
3
2
|
import { helper, wrap } from './wrap.js';
|
|
4
3
|
import { Utils } from '../utils/Utils.js';
|
|
4
|
+
import { QueryHelper } from '../utils/QueryHelper.js';
|
|
5
5
|
import { NotFoundError } from '../errors.js';
|
|
6
|
+
import { inspect } from '../logging/inspect.js';
|
|
6
7
|
export class Reference {
|
|
7
8
|
entity;
|
|
9
|
+
property;
|
|
8
10
|
constructor(entity) {
|
|
9
11
|
this.entity = entity;
|
|
10
12
|
this.set(entity);
|
|
@@ -64,7 +66,9 @@ export class Reference {
|
|
|
64
66
|
*/
|
|
65
67
|
static wrapReference(entity, prop) {
|
|
66
68
|
if (entity && prop.ref && !Reference.isReference(entity)) {
|
|
67
|
-
|
|
69
|
+
const ref = Reference.create(entity);
|
|
70
|
+
ref.property = prop;
|
|
71
|
+
return ref;
|
|
68
72
|
}
|
|
69
73
|
return entity;
|
|
70
74
|
}
|
|
@@ -84,13 +88,15 @@ export class Reference {
|
|
|
84
88
|
if (!wrapped.__em) {
|
|
85
89
|
return this.entity;
|
|
86
90
|
}
|
|
91
|
+
options = { ...options, filters: QueryHelper.mergePropertyFilters(this.property?.filters, options.filters) };
|
|
87
92
|
if (this.isInitialized() && !options.refresh && options.populate) {
|
|
88
93
|
await wrapped.__em.populate(this.entity, options.populate, options);
|
|
89
94
|
}
|
|
90
95
|
if (!this.isInitialized() || options.refresh) {
|
|
91
|
-
if (options.dataloader ??
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
if (options.dataloader ??
|
|
97
|
+
[DataloaderType.ALL, DataloaderType.REFERENCE].includes(wrapped.__em.config.getDataloaderType())) {
|
|
98
|
+
const dataLoader = await wrapped.__em.getDataLoader('ref');
|
|
99
|
+
return dataLoader.load([this, options]);
|
|
94
100
|
}
|
|
95
101
|
return wrapped.init(options);
|
|
96
102
|
}
|
|
@@ -141,9 +147,9 @@ export class Reference {
|
|
|
141
147
|
return wrap(this.entity).toJSON(...args);
|
|
142
148
|
}
|
|
143
149
|
/** @ignore */
|
|
144
|
-
[inspect.custom](depth = 2) {
|
|
150
|
+
[Symbol.for('nodejs.util.inspect.custom')](depth = 2) {
|
|
145
151
|
const object = { ...this };
|
|
146
|
-
const hidden = ['meta'];
|
|
152
|
+
const hidden = ['meta', 'property'];
|
|
147
153
|
hidden.forEach(k => delete object[k]);
|
|
148
154
|
const ret = inspect(object, { depth });
|
|
149
155
|
const wrapped = helper(this.entity);
|
|
@@ -183,12 +189,11 @@ export class ScalarReference {
|
|
|
183
189
|
*/
|
|
184
190
|
async loadOrFail(options = {}) {
|
|
185
191
|
const ret = await this.load(options);
|
|
186
|
-
if (
|
|
192
|
+
if (ret == null) {
|
|
187
193
|
const wrapped = helper(this.entity);
|
|
188
194
|
options.failHandler ??= wrapped.__em.config.get('findOneOrFailHandler');
|
|
189
195
|
const entityName = this.entity.constructor.name;
|
|
190
|
-
|
|
191
|
-
throw new NotFoundError(`${entityName} (${where}) failed to load property '${this.property}'`);
|
|
196
|
+
throw NotFoundError.failedToLoadProperty(entityName, this.property, wrapped.getPrimaryKey());
|
|
192
197
|
}
|
|
193
198
|
return ret;
|
|
194
199
|
}
|
|
@@ -207,24 +212,52 @@ export class ScalarReference {
|
|
|
207
212
|
isInitialized() {
|
|
208
213
|
return this.initialized;
|
|
209
214
|
}
|
|
210
|
-
/* v8 ignore next 4 */
|
|
211
215
|
/** @ignore */
|
|
212
|
-
|
|
216
|
+
/* v8 ignore next */
|
|
217
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
213
218
|
return this.initialized ? `Ref<${inspect(this.value)}>` : `Ref<?>`;
|
|
214
219
|
}
|
|
215
220
|
}
|
|
216
221
|
Object.defineProperties(Reference.prototype, {
|
|
217
222
|
__reference: { value: true, enumerable: false },
|
|
218
|
-
__meta: {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
+
__meta: {
|
|
224
|
+
get() {
|
|
225
|
+
return this.entity.__meta;
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
__platform: {
|
|
229
|
+
get() {
|
|
230
|
+
return this.entity.__platform;
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
__helper: {
|
|
234
|
+
get() {
|
|
235
|
+
return this.entity.__helper;
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
$: {
|
|
239
|
+
get() {
|
|
240
|
+
return this.entity;
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
get: {
|
|
244
|
+
get() {
|
|
245
|
+
return () => this.entity;
|
|
246
|
+
},
|
|
247
|
+
},
|
|
223
248
|
});
|
|
224
249
|
Object.defineProperties(ScalarReference.prototype, {
|
|
225
250
|
__scalarReference: { value: true, enumerable: false },
|
|
226
|
-
$: {
|
|
227
|
-
|
|
251
|
+
$: {
|
|
252
|
+
get() {
|
|
253
|
+
return this.value;
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
get: {
|
|
257
|
+
get() {
|
|
258
|
+
return () => this.value;
|
|
259
|
+
},
|
|
260
|
+
},
|
|
228
261
|
});
|
|
229
262
|
/**
|
|
230
263
|
* shortcut for `wrap(entity).toReference()`
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { PopulatePath } from '../enums.js';
|
|
2
|
-
import { inspect } from 'node:util';
|
|
3
2
|
import type { EntityManager } from '../EntityManager.js';
|
|
4
|
-
import type { Dictionary, EntityData, EntityDictionary, EntityMetadata, IHydrator, EntityKey, PopulateOptions, Primary, AutoPath, Ref, AddEager, LoadedReference, EntityDTO, Loaded, FromEntityType, IsSubset, MergeSelected } 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';
|
|
5
4
|
import { Reference } from './Reference.js';
|
|
6
5
|
import { type AssignOptions } from './EntityAssigner.js';
|
|
7
6
|
import type { EntityLoaderOptions } from './EntityLoader.js';
|
|
@@ -11,7 +10,6 @@ import { type SerializeOptions } from '../serialization/EntitySerializer.js';
|
|
|
11
10
|
import type { FindOneOptions, LoadHint } from '../drivers/IDatabaseDriver.js';
|
|
12
11
|
export declare class WrappedEntity<Entity extends object> {
|
|
13
12
|
__initialized: boolean;
|
|
14
|
-
__touched: boolean;
|
|
15
13
|
__populated?: boolean;
|
|
16
14
|
__managed?: boolean;
|
|
17
15
|
__onLoadFired?: boolean;
|
|
@@ -41,18 +39,17 @@ export declare class WrappedEntity<Entity extends object> {
|
|
|
41
39
|
private readonly pkGetterConverted?;
|
|
42
40
|
constructor(entity: Entity, hydrator: IHydrator, pkGetter?: (e: Entity) => Primary<Entity>, pkSerializer?: (e: Entity) => string, pkGetterConverted?: (e: Entity) => Primary<Entity>);
|
|
43
41
|
isInitialized(): boolean;
|
|
44
|
-
isTouched(): boolean;
|
|
45
42
|
isManaged(): boolean;
|
|
46
43
|
populated(populated?: boolean | undefined): void;
|
|
47
44
|
setSerializationContext<Hint extends string = never, Fields extends string = '*', Exclude extends string = never>(options: LoadHint<Entity, Hint, Fields, Exclude>): void;
|
|
48
45
|
toReference(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
|
|
49
46
|
toObject<Ignored extends EntityKey<Entity> = never>(ignoreFields?: Ignored[]): Omit<EntityDTO<Entity>, Ignored>;
|
|
50
|
-
serialize<Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Entity, Hint, Exclude>):
|
|
47
|
+
serialize<Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Entity, Hint, Exclude>): SerializeDTO<Entity, Hint, Exclude>;
|
|
51
48
|
toPOJO(): EntityDTO<Entity>;
|
|
52
49
|
toJSON(...args: any[]): EntityDictionary<Entity>;
|
|
53
50
|
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>;
|
|
54
51
|
init<Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(options?: FindOneOptions<Entity, Hint, Fields, Excludes>): Promise<Loaded<Entity, Hint, Fields, Excludes> | null>;
|
|
55
|
-
populate<Hint extends string = never>(populate: AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
|
|
52
|
+
populate<Hint extends string = never, Fields extends string = never>(populate: AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity, Fields>): Promise<Loaded<Entity, Hint>>;
|
|
56
53
|
hasPrimaryKey(): boolean;
|
|
57
54
|
getPrimaryKey(convertCustomTypes?: boolean): Primary<Entity> | null;
|
|
58
55
|
getPrimaryKeys(convertCustomTypes?: boolean): Primary<Entity>[] | null;
|
|
@@ -64,6 +61,4 @@ export declare class WrappedEntity<Entity extends object> {
|
|
|
64
61
|
get __platform(): import("../index.js").Platform;
|
|
65
62
|
get __config(): import("../index.js").Configuration<import("../drivers/IDatabaseDriver.js").IDatabaseDriver<import("../index.js").Connection>, EntityManager<import("../drivers/IDatabaseDriver.js").IDatabaseDriver<import("../index.js").Connection>>>;
|
|
66
63
|
get __primaryKeys(): Primary<Entity>[];
|
|
67
|
-
/** @ignore */
|
|
68
|
-
[inspect.custom](): string;
|
|
69
64
|
}
|
package/entity/WrappedEntity.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
1
|
import { Reference } from './Reference.js';
|
|
3
2
|
import { EntityTransformer } from '../serialization/EntityTransformer.js';
|
|
4
3
|
import { EntityAssigner } from './EntityAssigner.js';
|
|
@@ -15,7 +14,6 @@ export class WrappedEntity {
|
|
|
15
14
|
this.pkSerializer = pkSerializer;
|
|
16
15
|
this.pkGetterConverted = pkGetterConverted;
|
|
17
16
|
this.__initialized = true;
|
|
18
|
-
this.__touched = false;
|
|
19
17
|
this.__serializationContext = {};
|
|
20
18
|
this.__loadedProperties = new Set();
|
|
21
19
|
this.__data = {};
|
|
@@ -24,9 +22,6 @@ export class WrappedEntity {
|
|
|
24
22
|
isInitialized() {
|
|
25
23
|
return this.__initialized;
|
|
26
24
|
}
|
|
27
|
-
isTouched() {
|
|
28
|
-
return this.__touched;
|
|
29
|
-
}
|
|
30
25
|
isManaged() {
|
|
31
26
|
return !!this.__managed;
|
|
32
27
|
}
|
|
@@ -76,7 +71,11 @@ export class WrappedEntity {
|
|
|
76
71
|
if (!this.__em) {
|
|
77
72
|
throw ValidationError.entityNotManaged(this.entity);
|
|
78
73
|
}
|
|
79
|
-
return this.__em.findOne(this.entity.constructor
|
|
74
|
+
return this.__em.findOne(this.entity.constructor, this.entity, {
|
|
75
|
+
...options,
|
|
76
|
+
refresh: true,
|
|
77
|
+
schema: this.__schema,
|
|
78
|
+
});
|
|
80
79
|
}
|
|
81
80
|
async populate(populate, options = {}) {
|
|
82
81
|
if (!this.__em) {
|
|
@@ -153,7 +152,7 @@ export class WrappedEntity {
|
|
|
153
152
|
return Utils.getPrimaryKeyValues(this.entity, this.__meta);
|
|
154
153
|
}
|
|
155
154
|
/** @ignore */
|
|
156
|
-
[inspect.custom]() {
|
|
155
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
157
156
|
return `[WrappedEntity<${this.__meta.className}>]`;
|
|
158
157
|
}
|
|
159
158
|
}
|