@mikro-orm/core 7.0.0-dev.8 → 7.0.0-dev.80
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 +85 -48
- package/EntityManager.js +300 -225
- package/MikroORM.d.ts +40 -31
- package/MikroORM.js +98 -137
- package/README.md +3 -2
- package/cache/FileCacheAdapter.d.ts +1 -1
- package/cache/FileCacheAdapter.js +6 -5
- package/cache/GeneratedCacheAdapter.d.ts +0 -1
- package/cache/GeneratedCacheAdapter.js +0 -2
- package/cache/index.d.ts +0 -1
- package/cache/index.js +0 -1
- package/connections/Connection.d.ts +11 -7
- package/connections/Connection.js +16 -14
- package/drivers/DatabaseDriver.d.ts +11 -5
- package/drivers/DatabaseDriver.js +17 -8
- package/drivers/IDatabaseDriver.d.ts +27 -5
- package/entity/BaseEntity.d.ts +0 -1
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +98 -30
- package/entity/Collection.js +432 -93
- package/entity/EntityAssigner.d.ts +1 -1
- package/entity/EntityAssigner.js +15 -7
- package/entity/EntityFactory.d.ts +7 -0
- package/entity/EntityFactory.js +64 -41
- package/entity/EntityHelper.js +26 -9
- package/entity/EntityLoader.d.ts +5 -4
- package/entity/EntityLoader.js +73 -40
- package/entity/EntityRepository.d.ts +1 -1
- package/entity/Reference.d.ts +9 -7
- package/entity/Reference.js +33 -6
- package/entity/WrappedEntity.d.ts +2 -4
- package/entity/WrappedEntity.js +1 -5
- package/entity/defineEntity.d.ts +549 -0
- package/entity/defineEntity.js +529 -0
- package/entity/index.d.ts +3 -2
- package/entity/index.js +3 -2
- package/entity/utils.d.ts +7 -0
- package/entity/utils.js +16 -4
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +65 -0
- package/enums.d.ts +21 -6
- package/enums.js +14 -1
- package/errors.d.ts +6 -2
- package/errors.js +14 -9
- package/events/EventSubscriber.d.ts +3 -1
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +4 -4
- package/hydration/ObjectHydrator.js +36 -25
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/SimpleLogger.d.ts +1 -1
- package/metadata/EntitySchema.d.ts +9 -13
- package/metadata/EntitySchema.js +44 -26
- package/metadata/MetadataDiscovery.d.ts +6 -9
- package/metadata/MetadataDiscovery.js +167 -206
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +44 -2
- package/metadata/MetadataStorage.d.ts +1 -6
- package/metadata/MetadataStorage.js +6 -18
- package/metadata/MetadataValidator.d.ts +0 -7
- package/metadata/MetadataValidator.js +4 -13
- 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 +1 -1
- package/metadata/types.d.ts +480 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +5 -1
- package/naming-strategy/AbstractNamingStrategy.js +8 -2
- package/naming-strategy/NamingStrategy.d.ts +11 -1
- package/not-supported.d.ts +2 -0
- package/not-supported.js +4 -0
- package/package.json +18 -10
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +6 -10
- package/platforms/Platform.js +14 -39
- package/serialization/EntitySerializer.d.ts +2 -0
- package/serialization/EntitySerializer.js +32 -14
- package/serialization/EntityTransformer.js +22 -12
- package/serialization/SerializationContext.js +16 -13
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.d.ts +8 -6
- package/types/BigIntType.js +1 -1
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +2 -1
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.d.ts +6 -4
- package/types/DecimalType.js +3 -3
- package/types/DoubleType.js +2 -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 -1
- package/types/Type.js +1 -1
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +1 -4
- package/types/index.d.ts +1 -1
- package/typings.d.ts +113 -77
- package/typings.js +41 -35
- package/unit-of-work/ChangeSetComputer.d.ts +1 -3
- package/unit-of-work/ChangeSetComputer.js +11 -9
- package/unit-of-work/ChangeSetPersister.d.ts +5 -4
- package/unit-of-work/ChangeSetPersister.js +58 -20
- package/unit-of-work/UnitOfWork.d.ts +8 -1
- package/unit-of-work/UnitOfWork.js +115 -57
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +11 -9
- package/utils/Configuration.d.ts +757 -206
- package/utils/Configuration.js +139 -187
- package/utils/ConfigurationLoader.d.ts +1 -54
- package/utils/ConfigurationLoader.js +1 -352
- package/utils/Cursor.d.ts +3 -3
- package/utils/Cursor.js +4 -1
- package/utils/DataloaderUtils.d.ts +15 -5
- package/utils/DataloaderUtils.js +54 -8
- package/utils/EntityComparator.d.ts +8 -4
- package/utils/EntityComparator.js +111 -64
- package/utils/QueryHelper.d.ts +9 -1
- package/utils/QueryHelper.js +70 -9
- package/utils/RawQueryFragment.d.ts +36 -4
- package/utils/RawQueryFragment.js +35 -14
- package/utils/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +223 -0
- package/utils/Utils.d.ts +8 -97
- package/utils/Utils.js +88 -303
- package/utils/clone.js +2 -3
- package/utils/env-vars.d.ts +3 -0
- package/utils/env-vars.js +87 -0
- package/utils/fs-utils.d.ts +12 -0
- package/utils/fs-utils.js +96 -0
- package/utils/index.d.ts +2 -1
- package/utils/index.js +2 -1
- package/utils/upsert-utils.d.ts +7 -2
- package/utils/upsert-utils.js +55 -4
- 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 -18
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -18
- 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 -40
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -30
- 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 -24
- 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 -13
- 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 -116
- package/entity/ArrayCollection.js +0 -402
- 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,4 +1,3 @@
|
|
|
1
|
-
import { URL } from 'node:url';
|
|
2
1
|
import { Utils } from '../utils/Utils.js';
|
|
3
2
|
export class Connection {
|
|
4
3
|
config;
|
|
@@ -33,23 +32,35 @@ export class Connection {
|
|
|
33
32
|
.forEach(k => delete this.options[k]);
|
|
34
33
|
}
|
|
35
34
|
/**
|
|
36
|
-
* Ensure the connection exists, this is used to support lazy connect when using `MikroORM
|
|
35
|
+
* Ensure the connection exists, this is used to support lazy connect when using `new MikroORM()` instead of the async `init` method.
|
|
37
36
|
*/
|
|
38
37
|
async ensureConnection() {
|
|
39
38
|
if (!this.connected) {
|
|
40
39
|
await this.connect();
|
|
41
40
|
}
|
|
42
41
|
}
|
|
42
|
+
async onConnect() {
|
|
43
|
+
const schemaGenerator = this.config.getExtension('@mikro-orm/schema-generator');
|
|
44
|
+
if (this.type === 'write' && schemaGenerator) {
|
|
45
|
+
if (this.config.get('ensureDatabase')) {
|
|
46
|
+
const options = this.config.get('ensureDatabase');
|
|
47
|
+
await schemaGenerator.ensureDatabase(typeof options === 'boolean' ? {} : { ...options, forceCheck: true });
|
|
48
|
+
}
|
|
49
|
+
if (this.config.get('ensureIndexes')) {
|
|
50
|
+
await schemaGenerator.ensureIndexes();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
43
54
|
async transactional(cb, options) {
|
|
44
55
|
throw new Error(`Transactions are not supported by current driver`);
|
|
45
56
|
}
|
|
46
57
|
async begin(options) {
|
|
47
58
|
throw new Error(`Transactions are not supported by current driver`);
|
|
48
59
|
}
|
|
49
|
-
async commit(ctx, eventBroadcaster) {
|
|
60
|
+
async commit(ctx, eventBroadcaster, loggerContext) {
|
|
50
61
|
throw new Error(`Transactions are not supported by current driver`);
|
|
51
62
|
}
|
|
52
|
-
async rollback(ctx, eventBroadcaster) {
|
|
63
|
+
async rollback(ctx, eventBroadcaster, loggerContext) {
|
|
53
64
|
throw new Error(`Transactions are not supported by current driver`);
|
|
54
65
|
}
|
|
55
66
|
getConnectionOptions() {
|
|
@@ -67,7 +78,7 @@ export class Connection {
|
|
|
67
78
|
}
|
|
68
79
|
}
|
|
69
80
|
else {
|
|
70
|
-
const url = new URL(this.config.
|
|
81
|
+
const url = new URL(this.config.get('clientUrl'));
|
|
71
82
|
this.options.host = ret.host = this.options.host ?? this.config.get('host', decodeURIComponent(url.hostname));
|
|
72
83
|
this.options.port = ret.port = this.options.port ?? this.config.get('port', +url.port);
|
|
73
84
|
this.options.user = ret.user = this.options.user ?? this.config.get('user', decodeURIComponent(url.username));
|
|
@@ -76,15 +87,6 @@ export class Connection {
|
|
|
76
87
|
}
|
|
77
88
|
return ret;
|
|
78
89
|
}
|
|
79
|
-
getClientUrl() {
|
|
80
|
-
const options = this.getConnectionOptions();
|
|
81
|
-
const url = new URL(this.config.getClientUrl(true));
|
|
82
|
-
const password = options.password ? ':*****' : '';
|
|
83
|
-
const schema = options.schema && options.schema !== this.platform.getDefaultSchemaName()
|
|
84
|
-
? `?schema=${options.schema}`
|
|
85
|
-
: '';
|
|
86
|
-
return `${url.protocol}//${options.user}${password}@${options.host}:${options.port}${schema}`;
|
|
87
|
-
}
|
|
88
90
|
setMetadata(metadata) {
|
|
89
91
|
this.metadata = metadata;
|
|
90
92
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type CountOptions, type DeleteOptions, type DriverMethodOptions, EntityManagerType, type FindOneOptions, type FindOptions, type IDatabaseDriver, type LockOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type OrderDefinition } from './IDatabaseDriver.js';
|
|
2
|
-
import type { ConnectionType, Dictionary, EntityData, EntityDictionary, EntityMetadata, EntityProperty, FilterQuery, PopulateOptions, Primary } from '../typings.js';
|
|
1
|
+
import { type CountOptions, type DeleteOptions, type DriverMethodOptions, EntityManagerType, type FindOneOptions, type FindOptions, type IDatabaseDriver, type LockOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type OrderDefinition, type StreamOptions } from './IDatabaseDriver.js';
|
|
2
|
+
import type { ConnectionType, Dictionary, EntityData, EntityDictionary, EntityMetadata, EntityName, EntityProperty, FilterQuery, PopulateOptions, Primary } from '../typings.js';
|
|
3
3
|
import type { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
4
4
|
import type { Connection, QueryResult, Transaction } from '../connections/Connection.js';
|
|
5
5
|
import { type Configuration, type ConnectionOptions } from '../utils/Configuration.js';
|
|
@@ -30,20 +30,25 @@ export declare abstract class DatabaseDriver<C extends Connection> implements ID
|
|
|
30
30
|
abstract nativeDelete<T extends object>(entityName: string, where: FilterQuery<T>, options?: DeleteOptions<T>): Promise<QueryResult<T>>;
|
|
31
31
|
abstract count<T extends object, P extends string = never>(entityName: string, where: FilterQuery<T>, options?: CountOptions<T, P>): Promise<number>;
|
|
32
32
|
createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
|
|
33
|
-
findVirtual<T extends object>(entityName:
|
|
33
|
+
findVirtual<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
|
|
34
34
|
countVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: CountOptions<T, any>): Promise<number>;
|
|
35
35
|
aggregate(entityName: string, pipeline: any[]): Promise<any[]>;
|
|
36
36
|
loadFromPivotTable<T extends object, O extends object>(prop: EntityProperty, owners: Primary<O>[][], where?: FilterQuery<any>, orderBy?: OrderDefinition<T>, ctx?: Transaction, options?: FindOptions<T, any, any, any>, pivotJoin?: boolean): Promise<Dictionary<T[]>>;
|
|
37
37
|
syncCollections<T extends object, O extends object>(collections: Iterable<Collection<T, O>>, options?: DriverMethodOptions): Promise<void>;
|
|
38
38
|
mapResult<T extends object>(result: EntityDictionary<T>, meta?: EntityMetadata<T>, populate?: PopulateOptions<T>[]): EntityData<T> | null;
|
|
39
|
-
connect(
|
|
40
|
-
|
|
39
|
+
connect(options?: {
|
|
40
|
+
skipOnConnect?: boolean;
|
|
41
|
+
}): Promise<C>;
|
|
42
|
+
reconnect(options?: {
|
|
43
|
+
skipOnConnect?: boolean;
|
|
44
|
+
}): Promise<C>;
|
|
41
45
|
getConnection(type?: ConnectionType): C;
|
|
42
46
|
close(force?: boolean): Promise<void>;
|
|
43
47
|
getPlatform(): Platform;
|
|
44
48
|
setMetadata(metadata: MetadataStorage): void;
|
|
45
49
|
getMetadata(): MetadataStorage;
|
|
46
50
|
getDependencies(): string[];
|
|
51
|
+
protected isPopulated<T extends object>(meta: EntityMetadata<T>, prop: EntityProperty<T>, hint: PopulateOptions<T>, name?: string): boolean;
|
|
47
52
|
protected processCursorOptions<T extends object, P extends string>(meta: EntityMetadata<T>, options: FindOptions<T, P, any, any>, orderBy: OrderDefinition<T>): {
|
|
48
53
|
orderBy: OrderDefinition<T>[];
|
|
49
54
|
where: FilterQuery<T>;
|
|
@@ -55,6 +60,7 @@ export declare abstract class DatabaseDriver<C extends Connection> implements ID
|
|
|
55
60
|
protected getPrimaryKeyFields(entityName: string): string[];
|
|
56
61
|
protected createReplicas(cb: (c: ConnectionOptions) => C): C[];
|
|
57
62
|
lockPessimistic<T extends object>(entity: T, options: LockOptions): Promise<void>;
|
|
63
|
+
abstract stream<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: StreamOptions<T>): AsyncIterableIterator<T>;
|
|
58
64
|
/**
|
|
59
65
|
* @inheritDoc
|
|
60
66
|
*/
|
|
@@ -31,11 +31,11 @@ export class DatabaseDriver {
|
|
|
31
31
|
const EntityManagerClass = this.config.get('entityManager', EntityManager);
|
|
32
32
|
return new EntityManagerClass(this.config, this, this.metadata, useContext);
|
|
33
33
|
}
|
|
34
|
-
/* v8 ignore next
|
|
34
|
+
/* v8 ignore next */
|
|
35
35
|
async findVirtual(entityName, where, options) {
|
|
36
36
|
throw new Error(`Virtual entities are not supported by ${this.constructor.name} driver.`);
|
|
37
37
|
}
|
|
38
|
-
/* v8 ignore next
|
|
38
|
+
/* v8 ignore next */
|
|
39
39
|
async countVirtual(entityName, where, options) {
|
|
40
40
|
throw new Error(`Counting virtual entities is not supported by ${this.constructor.name} driver.`);
|
|
41
41
|
}
|
|
@@ -53,7 +53,7 @@ export class DatabaseDriver {
|
|
|
53
53
|
}
|
|
54
54
|
continue;
|
|
55
55
|
}
|
|
56
|
-
/* v8 ignore next
|
|
56
|
+
/* v8 ignore next */
|
|
57
57
|
const pk = coll.property.targetMeta.primaryKeys[0];
|
|
58
58
|
const data = { [coll.property.name]: coll.getIdentifiers(pk) };
|
|
59
59
|
await this.nativeUpdate(coll.owner.constructor.name, helper(coll.owner).getPrimaryKey(), data, options);
|
|
@@ -65,14 +65,14 @@ export class DatabaseDriver {
|
|
|
65
65
|
}
|
|
66
66
|
return this.comparator.mapResult(meta.className, result);
|
|
67
67
|
}
|
|
68
|
-
async connect() {
|
|
69
|
-
await this.connection.connect();
|
|
68
|
+
async connect(options) {
|
|
69
|
+
await this.connection.connect(options);
|
|
70
70
|
await Promise.all(this.replicas.map(replica => replica.connect()));
|
|
71
71
|
return this.connection;
|
|
72
72
|
}
|
|
73
|
-
async reconnect() {
|
|
73
|
+
async reconnect(options) {
|
|
74
74
|
await this.close(true);
|
|
75
|
-
await this.connect();
|
|
75
|
+
await this.connect(options);
|
|
76
76
|
return this.connection;
|
|
77
77
|
}
|
|
78
78
|
getConnection(type = 'write') {
|
|
@@ -105,6 +105,15 @@ export class DatabaseDriver {
|
|
|
105
105
|
getDependencies() {
|
|
106
106
|
return this.dependencies;
|
|
107
107
|
}
|
|
108
|
+
isPopulated(meta, prop, hint, name) {
|
|
109
|
+
if (hint.field === prop.name || hint.field === name || hint.all) {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
if (prop.embedded && hint.children && meta.properties[prop.embedded[0]].name === hint.field) {
|
|
113
|
+
return hint.children.some(c => this.isPopulated(meta, prop, c, prop.embedded[1]));
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
108
117
|
processCursorOptions(meta, options, orderBy) {
|
|
109
118
|
const { first, last, before, after, overfetch } = options;
|
|
110
119
|
const limit = first ?? last;
|
|
@@ -244,7 +253,7 @@ export class DatabaseDriver {
|
|
|
244
253
|
return data;
|
|
245
254
|
}
|
|
246
255
|
inlineEmbeddables(meta, data, where) {
|
|
247
|
-
/* v8 ignore next
|
|
256
|
+
/* v8 ignore next */
|
|
248
257
|
if (data == null) {
|
|
249
258
|
return;
|
|
250
259
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ConnectionType, EntityData, EntityMetadata, EntityProperty, FilterQuery, Primary, Dictionary, QBFilterQuery, IPrimaryKey, PopulateOptions, EntityDictionary, AutoPath, ObjectQuery, FilterObject, Populate } from '../typings.js';
|
|
1
|
+
import type { ConnectionType, EntityData, EntityMetadata, EntityProperty, FilterQuery, Primary, Dictionary, QBFilterQuery, IPrimaryKey, PopulateOptions, EntityDictionary, AutoPath, ObjectQuery, FilterObject, Populate, EntityName } from '../typings.js';
|
|
2
2
|
import type { Connection, QueryResult, Transaction } from '../connections/Connection.js';
|
|
3
3
|
import type { FlushMode, LockMode, QueryOrderMap, QueryFlag, LoadStrategy, PopulateHint, PopulatePath } from '../enums.js';
|
|
4
4
|
import type { Platform } from '../platforms/Platform.js';
|
|
@@ -14,9 +14,13 @@ export interface IDatabaseDriver<C extends Connection = Connection> {
|
|
|
14
14
|
[EntityManagerType]: EntityManager<this>;
|
|
15
15
|
readonly config: Configuration;
|
|
16
16
|
createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
|
|
17
|
-
connect(
|
|
17
|
+
connect(options?: {
|
|
18
|
+
skipOnConnect?: boolean;
|
|
19
|
+
}): Promise<C>;
|
|
18
20
|
close(force?: boolean): Promise<void>;
|
|
19
|
-
reconnect(
|
|
21
|
+
reconnect(options?: {
|
|
22
|
+
skipOnConnect?: boolean;
|
|
23
|
+
}): Promise<C>;
|
|
20
24
|
getConnection(type?: ConnectionType): C;
|
|
21
25
|
/**
|
|
22
26
|
* Finds selection of entities
|
|
@@ -27,6 +31,7 @@ export interface IDatabaseDriver<C extends Connection = Connection> {
|
|
|
27
31
|
*/
|
|
28
32
|
findOne<T extends object, P extends string = never, F extends string = '*', E extends string = never>(entityName: string, where: FilterQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>;
|
|
29
33
|
findVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
|
|
34
|
+
stream<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: StreamOptions<T>): AsyncIterableIterator<T>;
|
|
30
35
|
nativeInsert<T extends object>(entityName: string, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
|
|
31
36
|
nativeInsertMany<T extends object>(entityName: string, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>, transform?: (sql: string) => string): Promise<QueryResult<T>>;
|
|
32
37
|
nativeUpdate<T extends object>(entityName: string, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
|
|
@@ -68,6 +73,18 @@ export type OrderDefinition<T> = (QueryOrderMap<T> & {
|
|
|
68
73
|
export interface FindAllOptions<T, P extends string = never, F extends string = '*', E extends string = never> extends FindOptions<T, P, F, E> {
|
|
69
74
|
where?: FilterQuery<T>;
|
|
70
75
|
}
|
|
76
|
+
export interface StreamOptions<Entity, Populate extends string = never, Fields extends string = '*', Exclude extends string = never> extends Omit<FindAllOptions<Entity, Populate, Fields, Exclude>, 'cache' | 'before' | 'after' | 'first' | 'last' | 'overfetch' | 'strategy'> {
|
|
77
|
+
/**
|
|
78
|
+
* When populating to-many relations, the ORM streams fully merged entities instead of yielding every row.
|
|
79
|
+
* You can opt out of this behavior by specifying `mergeResults: false`. This will yield every row from
|
|
80
|
+
* the SQL result, but still mapped to entities, meaning that to-many collections will contain at most
|
|
81
|
+
* a single item, and you will get duplicate root entities when they have multiple items in the populated
|
|
82
|
+
* collection.
|
|
83
|
+
*
|
|
84
|
+
* @default true
|
|
85
|
+
*/
|
|
86
|
+
mergeResults?: boolean;
|
|
87
|
+
}
|
|
71
88
|
export type FilterOptions = Dictionary<boolean | Dictionary> | string[] | boolean;
|
|
72
89
|
export interface LoadHint<Entity, Hint extends string = never, Fields extends string = PopulatePath.ALL, Excludes extends string = never> {
|
|
73
90
|
populate?: Populate<Entity, Hint>;
|
|
@@ -149,9 +166,10 @@ export interface FindOptions<Entity, Hint extends string = never, Fields extends
|
|
|
149
166
|
/** @internal used to apply filters to the auto-joined relations */
|
|
150
167
|
em?: EntityManager;
|
|
151
168
|
}
|
|
152
|
-
export interface FindByCursorOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'offset'> {
|
|
169
|
+
export interface FindByCursorOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never, I extends boolean = true> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'offset'> {
|
|
170
|
+
includeCount?: I;
|
|
153
171
|
}
|
|
154
|
-
export interface FindOneOptions<T
|
|
172
|
+
export interface FindOneOptions<T, P extends string = never, F extends string = '*', E extends string = never> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'lockMode'> {
|
|
155
173
|
lockMode?: LockMode;
|
|
156
174
|
lockVersion?: number | Date;
|
|
157
175
|
}
|
|
@@ -165,6 +183,7 @@ export interface NativeInsertUpdateOptions<T> {
|
|
|
165
183
|
schema?: string;
|
|
166
184
|
/** `nativeUpdate()` only option */
|
|
167
185
|
upsert?: boolean;
|
|
186
|
+
loggerContext?: LogContext;
|
|
168
187
|
}
|
|
169
188
|
export interface NativeInsertUpdateManyOptions<T> extends NativeInsertUpdateOptions<T> {
|
|
170
189
|
processCollections?: boolean;
|
|
@@ -199,6 +218,8 @@ export interface CountOptions<T extends object, P extends string = never> {
|
|
|
199
218
|
hintComments?: string | string[];
|
|
200
219
|
loggerContext?: LogContext;
|
|
201
220
|
logging?: LoggingOptions;
|
|
221
|
+
/** @internal used to apply filters to the auto-joined relations */
|
|
222
|
+
em?: EntityManager;
|
|
202
223
|
}
|
|
203
224
|
export interface UpdateOptions<T> {
|
|
204
225
|
filters?: FilterOptions;
|
|
@@ -220,6 +241,7 @@ export interface LockOptions extends DriverMethodOptions {
|
|
|
220
241
|
export interface DriverMethodOptions {
|
|
221
242
|
ctx?: Transaction;
|
|
222
243
|
schema?: string;
|
|
244
|
+
loggerContext?: LogContext;
|
|
223
245
|
}
|
|
224
246
|
export interface GetReferenceOptions {
|
|
225
247
|
wrapped?: boolean;
|
package/entity/BaseEntity.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { type SerializeOptions } from '../serialization/EntitySerializer.js';
|
|
|
6
6
|
import type { FindOneOptions } from '../drivers/IDatabaseDriver.js';
|
|
7
7
|
export declare abstract class BaseEntity {
|
|
8
8
|
isInitialized(): boolean;
|
|
9
|
-
isTouched(): boolean;
|
|
10
9
|
populated(populated?: boolean): void;
|
|
11
10
|
populate<Entity extends this = this, Hint extends string = never>(populate: AutoPath<Entity, Hint>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
|
|
12
11
|
toReference<Entity extends this = this>(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
|
package/entity/BaseEntity.js
CHANGED
package/entity/Collection.d.ts
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
import type { EntityDTO, EntityKey, EntityProperty, FilterQuery, IPrimaryKey, Loaded, LoadedCollection, Populate, Primary } from '../typings.js';
|
|
3
3
|
import { Reference } from './Reference.js';
|
|
4
4
|
import type { Transaction } from '../connections/Connection.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { CountOptions, FindOptions } from '../drivers/IDatabaseDriver.js';
|
|
6
6
|
import type { EntityLoaderOptions } from './EntityLoader.js';
|
|
7
7
|
export interface MatchingOptions<T extends object, P extends string = never> extends FindOptions<T, P> {
|
|
8
8
|
where?: FilterQuery<T>;
|
|
9
9
|
store?: boolean;
|
|
10
10
|
ctx?: Transaction;
|
|
11
11
|
}
|
|
12
|
-
export declare class Collection<T extends object, O extends object = object>
|
|
12
|
+
export declare class Collection<T extends object, O extends object = object> {
|
|
13
|
+
readonly owner: O;
|
|
14
|
+
[k: number]: T;
|
|
15
|
+
protected readonly items: Set<T>;
|
|
16
|
+
protected initialized: boolean;
|
|
17
|
+
protected dirty: boolean;
|
|
18
|
+
protected partial: boolean;
|
|
19
|
+
protected snapshot: T[] | undefined;
|
|
13
20
|
private readonly?;
|
|
21
|
+
protected _count?: number;
|
|
22
|
+
private _property?;
|
|
14
23
|
private _populated?;
|
|
15
|
-
private _snapshot?;
|
|
16
24
|
constructor(owner: O, items?: T[], initialized?: boolean);
|
|
17
25
|
/**
|
|
18
26
|
* Creates new Collection instance, assigns it to the owning entity and sets the items to it (propagating them to their inverse sides)
|
|
@@ -39,59 +47,119 @@ export declare class Collection<T extends object, O extends object = object> ext
|
|
|
39
47
|
*/
|
|
40
48
|
getItems(check?: boolean): T[];
|
|
41
49
|
toJSON<TT extends T>(): EntityDTO<TT>[];
|
|
42
|
-
add<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>>, ...entities: (TT | Reference<TT>)[]):
|
|
50
|
+
add<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>>, ...entities: (TT | Reference<TT>)[]): number;
|
|
43
51
|
/**
|
|
44
|
-
*
|
|
52
|
+
* Remove specified item(s) from the collection. Note that removing item from collection does not necessarily imply deleting the target entity,
|
|
53
|
+
* it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
|
|
54
|
+
* is not the same as `em.remove()`. If we want to delete the entity by removing it from collection, we need to enable `orphanRemoval: true`,
|
|
55
|
+
* which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
|
|
45
56
|
*/
|
|
46
|
-
remove<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>> | ((item: TT) => boolean), ...entities: (TT | Reference<TT>)[]):
|
|
57
|
+
remove<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>> | ((item: TT) => boolean), ...entities: (TT | Reference<TT>)[]): number;
|
|
47
58
|
contains<TT extends T>(item: TT | Reference<TT>, check?: boolean): boolean;
|
|
48
59
|
count(): number;
|
|
49
60
|
isEmpty(): boolean;
|
|
61
|
+
shouldPopulate(populated?: boolean): boolean;
|
|
62
|
+
populated(populated?: boolean | undefined): void;
|
|
63
|
+
init<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<LoadedCollection<Loaded<TT, P>>>;
|
|
64
|
+
private getEntityManager;
|
|
65
|
+
private createCondition;
|
|
66
|
+
private createOrderBy;
|
|
67
|
+
private createManyToManyCondition;
|
|
68
|
+
private createLoadCountCondition;
|
|
69
|
+
private checkInitialized;
|
|
70
|
+
/**
|
|
71
|
+
* re-orders items after searching with `$in` operator
|
|
72
|
+
*/
|
|
73
|
+
private reorderItems;
|
|
74
|
+
private cancelOrphanRemoval;
|
|
75
|
+
private validateModification;
|
|
76
|
+
toArray<TT extends T>(): EntityDTO<TT>[];
|
|
77
|
+
getIdentifiers<U extends IPrimaryKey = Primary<T> & IPrimaryKey>(field?: string | string[]): U[];
|
|
78
|
+
/**
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
addWithoutPropagation(entity: T): void;
|
|
82
|
+
set(items: Iterable<T | Reference<T>>): void;
|
|
83
|
+
private compare;
|
|
84
|
+
/**
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
hydrate(items: T[], forcePropagate?: boolean, partial?: boolean): void;
|
|
88
|
+
/**
|
|
89
|
+
* Remove all items from the collection. Note that removing items from collection does not necessarily imply deleting the target entity,
|
|
90
|
+
* it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
|
|
91
|
+
* is not the same as `em.remove()`. If we want to delete the entity by removing it from collection, we need to enable `orphanRemoval: true`,
|
|
92
|
+
* which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
|
|
93
|
+
*/
|
|
94
|
+
removeAll(): void;
|
|
95
|
+
/**
|
|
96
|
+
* @internal
|
|
97
|
+
*/
|
|
98
|
+
removeWithoutPropagation(entity: T): void;
|
|
50
99
|
/**
|
|
51
|
-
*
|
|
100
|
+
* Extracts a slice of the collection items starting at position start to end (exclusive) of the collection.
|
|
101
|
+
* If end is null it returns all elements from start to the end of the collection.
|
|
52
102
|
*/
|
|
53
103
|
slice(start?: number, end?: number): T[];
|
|
54
104
|
/**
|
|
55
|
-
*
|
|
105
|
+
* Tests for the existence of an element that satisfies the given predicate.
|
|
56
106
|
*/
|
|
57
107
|
exists(cb: (item: T) => boolean): boolean;
|
|
58
108
|
/**
|
|
59
|
-
*
|
|
109
|
+
* Returns the first element of this collection that satisfies the predicate.
|
|
60
110
|
*/
|
|
61
111
|
find(cb: (item: T, index: number) => boolean): T | undefined;
|
|
62
112
|
/**
|
|
63
|
-
*
|
|
113
|
+
* Extracts a subset of the collection items.
|
|
64
114
|
*/
|
|
65
115
|
filter(cb: (item: T, index: number) => boolean): T[];
|
|
66
116
|
/**
|
|
67
|
-
*
|
|
117
|
+
* Maps the collection items based on your provided mapper function.
|
|
68
118
|
*/
|
|
69
119
|
map<R>(mapper: (item: T, index: number) => R): R[];
|
|
70
120
|
/**
|
|
71
|
-
*
|
|
121
|
+
* Maps the collection items based on your provided mapper function to a single object.
|
|
122
|
+
*/
|
|
123
|
+
reduce<R>(cb: (obj: R, item: T, index: number) => R, initial?: R): R;
|
|
124
|
+
/**
|
|
125
|
+
* Maps the collection items to a dictionary, indexed by the key you specify.
|
|
126
|
+
* If there are more items with the same key, only the first one will be present.
|
|
72
127
|
*/
|
|
73
128
|
indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1): Record<T[K1] & PropertyKey, T>;
|
|
74
129
|
/**
|
|
75
|
-
*
|
|
130
|
+
* Maps the collection items to a dictionary, indexed by the key you specify.
|
|
131
|
+
* If there are more items with the same key, only the first one will be present.
|
|
76
132
|
*/
|
|
77
133
|
indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1, valueKey: K2): Record<T[K1] & PropertyKey, T[K2]>;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
private createManyToManyCondition;
|
|
85
|
-
private createLoadCountCondition;
|
|
86
|
-
private modify;
|
|
87
|
-
private checkInitialized;
|
|
134
|
+
isInitialized(fully?: boolean): boolean;
|
|
135
|
+
isDirty(): boolean;
|
|
136
|
+
isPartial(): boolean;
|
|
137
|
+
setDirty(dirty?: boolean): void;
|
|
138
|
+
get length(): number;
|
|
139
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
88
140
|
/**
|
|
89
|
-
*
|
|
141
|
+
* @internal
|
|
90
142
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
143
|
+
takeSnapshot(forcePropagate?: boolean): void;
|
|
144
|
+
/**
|
|
145
|
+
* @internal
|
|
146
|
+
*/
|
|
147
|
+
getSnapshot(): T[] | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* @internal
|
|
150
|
+
*/
|
|
151
|
+
get property(): EntityProperty;
|
|
152
|
+
/**
|
|
153
|
+
* @internal
|
|
154
|
+
*/
|
|
155
|
+
set property(prop: EntityProperty);
|
|
156
|
+
protected propagate(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
|
|
157
|
+
protected propagateToInverseSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
|
|
158
|
+
protected propagateToOwningSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
|
|
159
|
+
protected shouldPropagateToCollection(collection: Collection<O, T>, method: 'add' | 'remove' | 'takeSnapshot'): boolean;
|
|
160
|
+
protected incrementCount(value: number): void;
|
|
161
|
+
/** @ignore */
|
|
162
|
+
[inspect.custom](depth?: number): string;
|
|
95
163
|
}
|
|
96
164
|
export interface InitCollectionOptions<T, P extends string = never, F extends string = '*', E extends string = never> extends EntityLoaderOptions<T, F, E> {
|
|
97
165
|
dataloader?: boolean;
|