@mikro-orm/core 6.4.17-dev.60 → 6.4.17-dev.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EntityManager.d.ts +4 -2
- package/EntityManager.js +5 -7
- package/connections/Connection.d.ts +4 -2
- package/connections/Connection.js +2 -2
- package/drivers/IDatabaseDriver.d.ts +2 -0
- package/package.json +2 -2
- package/unit-of-work/ChangeSetPersister.d.ts +4 -2
- package/unit-of-work/ChangeSetPersister.js +13 -9
- package/unit-of-work/UnitOfWork.js +9 -2
package/EntityManager.d.ts
CHANGED
|
@@ -112,7 +112,9 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
112
112
|
/**
|
|
113
113
|
* Gets logger context for this entity manager.
|
|
114
114
|
*/
|
|
115
|
-
getLoggerContext<T extends Dictionary = Dictionary>(
|
|
115
|
+
getLoggerContext<T extends Dictionary = Dictionary>(options?: {
|
|
116
|
+
disableContextResolution?: boolean;
|
|
117
|
+
}): T;
|
|
116
118
|
setFlushMode(flushMode?: FlushMode): void;
|
|
117
119
|
protected processWhere<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName: string, where: FilterQuery<Entity>, options: FindOptions<Entity, Hint, Fields, Excludes> | FindOneOptions<Entity, Hint, Fields, Excludes>, type: 'read' | 'update' | 'delete'): Promise<FilterQuery<Entity>>;
|
|
118
120
|
protected applyDiscriminatorCondition<Entity extends object>(entityName: string, where: FilterQuery<Entity>): FilterQuery<Entity>;
|
|
@@ -482,7 +484,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
482
484
|
* some additional lazy properties, if so, we reload and merge the data from database
|
|
483
485
|
*/
|
|
484
486
|
protected shouldRefresh<T extends object, P extends string = never, F extends string = '*', E extends string = never>(meta: EntityMetadata<T>, entity: T, options: FindOneOptions<T, P, F, E>): boolean;
|
|
485
|
-
protected prepareOptions(options: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any>): void;
|
|
487
|
+
protected prepareOptions(options: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any> | CountOptions<any, any>): void;
|
|
486
488
|
/**
|
|
487
489
|
* @internal
|
|
488
490
|
*/
|
package/EntityManager.js
CHANGED
|
@@ -226,8 +226,8 @@ class EntityManager {
|
|
|
226
226
|
/**
|
|
227
227
|
* Gets logger context for this entity manager.
|
|
228
228
|
*/
|
|
229
|
-
getLoggerContext() {
|
|
230
|
-
const em = this.getContext();
|
|
229
|
+
getLoggerContext(options) {
|
|
230
|
+
const em = options?.disableContextResolution ? this : this.getContext();
|
|
231
231
|
em.loggerContext ??= {};
|
|
232
232
|
return em.loggerContext;
|
|
233
233
|
}
|
|
@@ -1256,10 +1256,8 @@ class EntityManager {
|
|
|
1256
1256
|
async count(entityName, where = {}, options = {}) {
|
|
1257
1257
|
const em = this.getContext(false);
|
|
1258
1258
|
// Shallow copy options since the object will be modified when deleting orderBy
|
|
1259
|
-
options = {
|
|
1260
|
-
|
|
1261
|
-
...options,
|
|
1262
|
-
};
|
|
1259
|
+
options = { ...options };
|
|
1260
|
+
em.prepareOptions(options);
|
|
1263
1261
|
entityName = utils_1.Utils.className(entityName);
|
|
1264
1262
|
await em.tryFlush(entityName, options);
|
|
1265
1263
|
where = await em.processWhere(entityName, where, options, 'read');
|
|
@@ -1680,7 +1678,7 @@ class EntityManager {
|
|
|
1680
1678
|
throw new errors_1.ValidationError(`Cannot combine 'fields' and 'exclude' option.`);
|
|
1681
1679
|
}
|
|
1682
1680
|
options.schema ??= this._schema;
|
|
1683
|
-
options.logging = utils_1.Utils.merge({ id: this.id }, this.loggerContext, options.loggerContext, options.logging);
|
|
1681
|
+
options.logging = options.loggerContext = utils_1.Utils.merge({ id: this.id }, this.loggerContext, options.loggerContext, options.logging);
|
|
1684
1682
|
}
|
|
1685
1683
|
/**
|
|
1686
1684
|
* @internal
|
|
@@ -49,15 +49,17 @@ export declare abstract class Connection {
|
|
|
49
49
|
readOnly?: boolean;
|
|
50
50
|
ctx?: Transaction;
|
|
51
51
|
eventBroadcaster?: TransactionEventBroadcaster;
|
|
52
|
+
loggerContext?: LogContext;
|
|
52
53
|
}): Promise<T>;
|
|
53
54
|
begin(options?: {
|
|
54
55
|
isolationLevel?: IsolationLevel;
|
|
55
56
|
readOnly?: boolean;
|
|
56
57
|
ctx?: Transaction;
|
|
57
58
|
eventBroadcaster?: TransactionEventBroadcaster;
|
|
59
|
+
loggerContext?: LogContext;
|
|
58
60
|
}): Promise<Transaction>;
|
|
59
|
-
commit(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
|
|
60
|
-
rollback(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
|
|
61
|
+
commit(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster, loggerContext?: LogContext): Promise<void>;
|
|
62
|
+
rollback(ctx: Transaction, eventBroadcaster?: TransactionEventBroadcaster, loggerContext?: LogContext): Promise<void>;
|
|
61
63
|
abstract execute<T>(query: string, params?: any[], method?: 'all' | 'get' | 'run', ctx?: Transaction): Promise<QueryResult<T> | any | any[]>;
|
|
62
64
|
getConnectionOptions(): ConnectionConfig;
|
|
63
65
|
getClientUrl(): string;
|
|
@@ -49,10 +49,10 @@ class Connection {
|
|
|
49
49
|
async begin(options) {
|
|
50
50
|
throw new Error(`Transactions are not supported by current driver`);
|
|
51
51
|
}
|
|
52
|
-
async commit(ctx, eventBroadcaster) {
|
|
52
|
+
async commit(ctx, eventBroadcaster, loggerContext) {
|
|
53
53
|
throw new Error(`Transactions are not supported by current driver`);
|
|
54
54
|
}
|
|
55
|
-
async rollback(ctx, eventBroadcaster) {
|
|
55
|
+
async rollback(ctx, eventBroadcaster, loggerContext) {
|
|
56
56
|
throw new Error(`Transactions are not supported by current driver`);
|
|
57
57
|
}
|
|
58
58
|
getConnectionOptions() {
|
|
@@ -166,6 +166,7 @@ export interface NativeInsertUpdateOptions<T> {
|
|
|
166
166
|
schema?: string;
|
|
167
167
|
/** `nativeUpdate()` only option */
|
|
168
168
|
upsert?: boolean;
|
|
169
|
+
loggerContext?: LogContext;
|
|
169
170
|
}
|
|
170
171
|
export interface NativeInsertUpdateManyOptions<T> extends NativeInsertUpdateOptions<T> {
|
|
171
172
|
processCollections?: boolean;
|
|
@@ -223,6 +224,7 @@ export interface LockOptions extends DriverMethodOptions {
|
|
|
223
224
|
export interface DriverMethodOptions {
|
|
224
225
|
ctx?: Transaction;
|
|
225
226
|
schema?: string;
|
|
227
|
+
loggerContext?: LogContext;
|
|
226
228
|
}
|
|
227
229
|
export interface GetReferenceOptions {
|
|
228
230
|
wrapped?: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.4.17-dev.
|
|
3
|
+
"version": "6.4.17-dev.61",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"esprima": "4.0.1",
|
|
65
65
|
"fs-extra": "11.3.0",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.4.17-dev.
|
|
67
|
+
"mikro-orm": "6.4.17-dev.61",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -4,6 +4,7 @@ import { type EntityFactory, type EntityValidator } from '../entity';
|
|
|
4
4
|
import { type ChangeSet } from './ChangeSet';
|
|
5
5
|
import { type Configuration } from '../utils';
|
|
6
6
|
import type { DriverMethodOptions, IDatabaseDriver } from '../drivers';
|
|
7
|
+
import type { EntityManager } from '../EntityManager';
|
|
7
8
|
export declare class ChangeSetPersister {
|
|
8
9
|
private readonly driver;
|
|
9
10
|
private readonly metadata;
|
|
@@ -11,10 +12,11 @@ export declare class ChangeSetPersister {
|
|
|
11
12
|
private readonly factory;
|
|
12
13
|
private readonly validator;
|
|
13
14
|
private readonly config;
|
|
15
|
+
private readonly em;
|
|
14
16
|
private readonly platform;
|
|
15
17
|
private readonly comparator;
|
|
16
18
|
private readonly usesReturningStatement;
|
|
17
|
-
constructor(driver: IDatabaseDriver, metadata: MetadataStorage, hydrator: IHydrator, factory: EntityFactory, validator: EntityValidator, config: Configuration);
|
|
19
|
+
constructor(driver: IDatabaseDriver, metadata: MetadataStorage, hydrator: IHydrator, factory: EntityFactory, validator: EntityValidator, config: Configuration, em: EntityManager);
|
|
18
20
|
executeInserts<T extends object>(changeSets: ChangeSet<T>[], options?: DriverMethodOptions, withSchema?: boolean): Promise<void>;
|
|
19
21
|
executeUpdates<T extends object>(changeSets: ChangeSet<T>[], batched: boolean, options?: DriverMethodOptions, withSchema?: boolean): Promise<void>;
|
|
20
22
|
executeDeletes<T extends object>(changeSets: ChangeSet<T>[], options?: DriverMethodOptions, withSchema?: boolean): Promise<void>;
|
|
@@ -22,7 +24,7 @@ export declare class ChangeSetPersister {
|
|
|
22
24
|
private processProperties;
|
|
23
25
|
private persistNewEntity;
|
|
24
26
|
private persistNewEntities;
|
|
25
|
-
private
|
|
27
|
+
private prepareOptions;
|
|
26
28
|
private persistNewEntitiesBatch;
|
|
27
29
|
private persistManagedEntity;
|
|
28
30
|
private persistManagedEntities;
|
|
@@ -13,16 +13,18 @@ class ChangeSetPersister {
|
|
|
13
13
|
factory;
|
|
14
14
|
validator;
|
|
15
15
|
config;
|
|
16
|
+
em;
|
|
16
17
|
platform;
|
|
17
18
|
comparator;
|
|
18
19
|
usesReturningStatement;
|
|
19
|
-
constructor(driver, metadata, hydrator, factory, validator, config) {
|
|
20
|
+
constructor(driver, metadata, hydrator, factory, validator, config, em) {
|
|
20
21
|
this.driver = driver;
|
|
21
22
|
this.metadata = metadata;
|
|
22
23
|
this.hydrator = hydrator;
|
|
23
24
|
this.factory = factory;
|
|
24
25
|
this.validator = validator;
|
|
25
26
|
this.config = config;
|
|
27
|
+
this.em = em;
|
|
26
28
|
this.platform = this.driver.getPlatform();
|
|
27
29
|
this.comparator = this.config.getComparator(this.metadata);
|
|
28
30
|
this.usesReturningStatement = this.platform.usesReturningStatement() || this.platform.usesOutputStatement();
|
|
@@ -63,7 +65,7 @@ class ChangeSetPersister {
|
|
|
63
65
|
for (let i = 0; i < changeSets.length; i += size) {
|
|
64
66
|
const chunk = changeSets.slice(i, i + size);
|
|
65
67
|
const pks = chunk.map(cs => cs.getPrimaryKey());
|
|
66
|
-
options = this.
|
|
68
|
+
options = this.prepareOptions(meta, options);
|
|
67
69
|
await this.driver.nativeDelete(meta.root.className, { [pk]: { $in: pks } }, options);
|
|
68
70
|
}
|
|
69
71
|
}
|
|
@@ -91,7 +93,7 @@ class ChangeSetPersister {
|
|
|
91
93
|
}
|
|
92
94
|
async persistNewEntity(meta, changeSet, options) {
|
|
93
95
|
const wrapped = (0, entity_1.helper)(changeSet.entity);
|
|
94
|
-
options = this.
|
|
96
|
+
options = this.prepareOptions(meta, options, {
|
|
95
97
|
convertCustomTypes: false,
|
|
96
98
|
});
|
|
97
99
|
const res = await this.driver.nativeInsertMany(meta.className, [changeSet.payload], options);
|
|
@@ -117,15 +119,17 @@ class ChangeSetPersister {
|
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
|
-
|
|
122
|
+
prepareOptions(meta, options, additionalOptions) {
|
|
123
|
+
const loggerContext = utils_1.Utils.merge({ id: this.em._id }, this.em.getLoggerContext({ disableContextResolution: true }));
|
|
121
124
|
return {
|
|
122
125
|
...options,
|
|
123
126
|
...additionalOptions,
|
|
124
127
|
schema: options?.schema ?? meta.schema,
|
|
128
|
+
loggerContext,
|
|
125
129
|
};
|
|
126
130
|
}
|
|
127
131
|
async persistNewEntitiesBatch(meta, changeSets, options) {
|
|
128
|
-
options = this.
|
|
132
|
+
options = this.prepareOptions(meta, options, {
|
|
129
133
|
convertCustomTypes: false,
|
|
130
134
|
processCollections: false,
|
|
131
135
|
});
|
|
@@ -176,7 +180,7 @@ class ChangeSetPersister {
|
|
|
176
180
|
}
|
|
177
181
|
async persistManagedEntitiesBatch(meta, changeSets, options) {
|
|
178
182
|
await this.checkOptimisticLocks(meta, changeSets, options);
|
|
179
|
-
options = this.
|
|
183
|
+
options = this.prepareOptions(meta, options, {
|
|
180
184
|
convertCustomTypes: false,
|
|
181
185
|
processCollections: false,
|
|
182
186
|
});
|
|
@@ -236,7 +240,7 @@ class ChangeSetPersister {
|
|
|
236
240
|
}
|
|
237
241
|
async updateEntity(meta, changeSet, options) {
|
|
238
242
|
const cond = changeSet.getPrimaryKey(true);
|
|
239
|
-
options = this.
|
|
243
|
+
options = this.prepareOptions(meta, options, {
|
|
240
244
|
convertCustomTypes: false,
|
|
241
245
|
});
|
|
242
246
|
if (meta.concurrencyCheckKeys.size === 0 && (!meta.versionProperty || changeSet.entity[meta.versionProperty] == null)) {
|
|
@@ -263,7 +267,7 @@ class ChangeSetPersister {
|
|
|
263
267
|
return cond;
|
|
264
268
|
});
|
|
265
269
|
const primaryKeys = meta.primaryKeys.concat(...meta.concurrencyCheckKeys);
|
|
266
|
-
options = this.
|
|
270
|
+
options = this.prepareOptions(meta, options, {
|
|
267
271
|
fields: primaryKeys,
|
|
268
272
|
});
|
|
269
273
|
const res = await this.driver.find(meta.root.className, { $or }, options);
|
|
@@ -322,7 +326,7 @@ class ChangeSetPersister {
|
|
|
322
326
|
}
|
|
323
327
|
return val;
|
|
324
328
|
});
|
|
325
|
-
options = this.
|
|
329
|
+
options = this.prepareOptions(meta, options, {
|
|
326
330
|
fields: utils_1.Utils.unique(reloadProps.map(prop => prop.name)),
|
|
327
331
|
});
|
|
328
332
|
const data = await this.driver.find(meta.className, { [pk]: { $in: pks } }, options);
|
|
@@ -42,7 +42,7 @@ class UnitOfWork {
|
|
|
42
42
|
this.eventManager = this.em.getEventManager();
|
|
43
43
|
this.comparator = this.em.getComparator();
|
|
44
44
|
this.changeSetComputer = new ChangeSetComputer_1.ChangeSetComputer(this.em.getValidator(), this.collectionUpdates, this.metadata, this.platform, this.em.config, this.em);
|
|
45
|
-
this.changeSetPersister = new ChangeSetPersister_1.ChangeSetPersister(this.em.getDriver(), this.metadata, this.em.config.getHydrator(this.metadata), this.em.getEntityFactory(), this.em.getValidator(), this.em.config);
|
|
45
|
+
this.changeSetPersister = new ChangeSetPersister_1.ChangeSetPersister(this.em.getDriver(), this.metadata, this.em.config.getHydrator(this.metadata), this.em.getEntityFactory(), this.em.getValidator(), this.em.config, this.em);
|
|
46
46
|
}
|
|
47
47
|
merge(entity, visited) {
|
|
48
48
|
const wrapped = (0, entity_1.helper)(entity);
|
|
@@ -312,9 +312,11 @@ class UnitOfWork {
|
|
|
312
312
|
const platform = this.em.getPlatform();
|
|
313
313
|
const runInTransaction = !this.em.isInTransaction() && platform.supportsTransactions() && this.em.config.get('implicitTransactions');
|
|
314
314
|
if (runInTransaction) {
|
|
315
|
+
const loggerContext = Utils_1.Utils.merge({ id: this.em._id }, this.em.getLoggerContext({ disableContextResolution: true }));
|
|
315
316
|
await this.em.getConnection('write').transactional(trx => this.persistToDatabase(groups, trx), {
|
|
316
317
|
ctx: oldTx,
|
|
317
318
|
eventBroadcaster: new events_1.TransactionEventBroadcaster(this.em, this),
|
|
319
|
+
loggerContext,
|
|
318
320
|
});
|
|
319
321
|
}
|
|
320
322
|
else {
|
|
@@ -888,7 +890,12 @@ class UnitOfWork {
|
|
|
888
890
|
}
|
|
889
891
|
async commitCollectionUpdates(ctx) {
|
|
890
892
|
this.filterCollectionUpdates();
|
|
891
|
-
|
|
893
|
+
const loggerContext = Utils_1.Utils.merge({ id: this.em._id }, this.em.getLoggerContext({ disableContextResolution: true }));
|
|
894
|
+
await this.em.getDriver().syncCollections(this.collectionUpdates, {
|
|
895
|
+
ctx,
|
|
896
|
+
schema: this.em.schema,
|
|
897
|
+
loggerContext,
|
|
898
|
+
});
|
|
892
899
|
for (const coll of this.collectionUpdates) {
|
|
893
900
|
coll.takeSnapshot();
|
|
894
901
|
}
|