@mikro-orm/core 6.6.2-dev.0 → 6.6.2-dev.10
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 +2 -0
- package/EntityManager.js +2 -0
- package/MikroORM.d.ts +9 -5
- package/MikroORM.js +16 -17
- package/events/EventManager.d.ts +2 -1
- package/events/EventManager.js +19 -11
- package/package.json +2 -2
- package/utils/Configuration.d.ts +1 -1
- package/utils/Configuration.js +1 -1
- package/utils/EntityComparator.js +4 -0
package/EntityManager.d.ts
CHANGED
|
@@ -410,6 +410,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
410
410
|
/**
|
|
411
411
|
* Persists your entity immediately, flushing all not yet persisted changes to the database too.
|
|
412
412
|
* Equivalent to `em.persist(e).flush()`.
|
|
413
|
+
* @deprecated use `em.persist(e).flush()` instead
|
|
413
414
|
*/
|
|
414
415
|
persistAndFlush(entity: AnyEntity | Reference<AnyEntity> | Iterable<AnyEntity | Reference<AnyEntity>>): Promise<void>;
|
|
415
416
|
/**
|
|
@@ -422,6 +423,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
|
|
|
422
423
|
/**
|
|
423
424
|
* Removes an entity instance immediately, flushing all not yet persisted changes to the database too.
|
|
424
425
|
* Equivalent to `em.remove(e).flush()`
|
|
426
|
+
* @deprecated use `em.remove(e).flush()` instead
|
|
425
427
|
*/
|
|
426
428
|
removeAndFlush(entity: AnyEntity | Reference<AnyEntity> | Iterable<AnyEntity | Reference<AnyEntity>>): Promise<void>;
|
|
427
429
|
/**
|
package/EntityManager.js
CHANGED
|
@@ -1315,6 +1315,7 @@ class EntityManager {
|
|
|
1315
1315
|
/**
|
|
1316
1316
|
* Persists your entity immediately, flushing all not yet persisted changes to the database too.
|
|
1317
1317
|
* Equivalent to `em.persist(e).flush()`.
|
|
1318
|
+
* @deprecated use `em.persist(e).flush()` instead
|
|
1318
1319
|
*/
|
|
1319
1320
|
async persistAndFlush(entity) {
|
|
1320
1321
|
await this.persist(entity).flush();
|
|
@@ -1345,6 +1346,7 @@ class EntityManager {
|
|
|
1345
1346
|
/**
|
|
1346
1347
|
* Removes an entity instance immediately, flushing all not yet persisted changes to the database too.
|
|
1347
1348
|
* Equivalent to `em.remove(e).flush()`
|
|
1349
|
+
* @deprecated use `em.remove(e).flush()` instead
|
|
1348
1350
|
*/
|
|
1349
1351
|
async removeAndFlush(entity) {
|
|
1350
1352
|
await this.remove(entity).flush();
|
package/MikroORM.d.ts
CHANGED
|
@@ -71,34 +71,38 @@ export declare class MikroORM<D extends IDatabaseDriver = IDatabaseDriver, EM ex
|
|
|
71
71
|
discoverEntity<T extends Constructor | EntitySchema>(entities: T | T[], reset?: string | string[]): void;
|
|
72
72
|
/**
|
|
73
73
|
* Gets the SchemaGenerator.
|
|
74
|
+
* @deprecated use `orm.schema` instead
|
|
74
75
|
*/
|
|
75
76
|
getSchemaGenerator(): ReturnType<ReturnType<D['getPlatform']>['getSchemaGenerator']>;
|
|
76
77
|
/**
|
|
77
78
|
* Gets the EntityGenerator.
|
|
79
|
+
* @deprecated use `orm.entityGenerator` instead
|
|
78
80
|
*/
|
|
79
81
|
getEntityGenerator<T extends IEntityGenerator = IEntityGenerator>(): T;
|
|
80
82
|
/**
|
|
81
83
|
* Gets the Migrator.
|
|
84
|
+
* @deprecated use `orm.migrator` instead
|
|
82
85
|
*/
|
|
83
86
|
getMigrator<T extends IMigrator = IMigrator>(): T;
|
|
84
87
|
/**
|
|
85
88
|
* Gets the SeedManager
|
|
89
|
+
* @deprecated use `orm.seeder` instead
|
|
86
90
|
*/
|
|
87
91
|
getSeeder<T extends ISeedManager = ISeedManager>(): T;
|
|
88
92
|
/**
|
|
89
|
-
*
|
|
93
|
+
* Gets the SchemaGenerator.
|
|
90
94
|
*/
|
|
91
|
-
get schema(): ReturnType<ReturnType<D[
|
|
95
|
+
get schema(): ReturnType<ReturnType<D['getPlatform']>['getSchemaGenerator']>;
|
|
92
96
|
/**
|
|
93
|
-
*
|
|
97
|
+
* Gets the SeedManager
|
|
94
98
|
*/
|
|
95
99
|
get seeder(): ISeedManager;
|
|
96
100
|
/**
|
|
97
|
-
*
|
|
101
|
+
* Gets the Migrator.
|
|
98
102
|
*/
|
|
99
103
|
get migrator(): IMigrator;
|
|
100
104
|
/**
|
|
101
|
-
*
|
|
105
|
+
* Gets the EntityGenerator.
|
|
102
106
|
*/
|
|
103
107
|
get entityGenerator(): IEntityGenerator;
|
|
104
108
|
}
|
package/MikroORM.js
CHANGED
|
@@ -209,56 +209,55 @@ class MikroORM {
|
|
|
209
209
|
}
|
|
210
210
|
/**
|
|
211
211
|
* Gets the SchemaGenerator.
|
|
212
|
+
* @deprecated use `orm.schema` instead
|
|
212
213
|
*/
|
|
213
214
|
getSchemaGenerator() {
|
|
214
|
-
|
|
215
|
-
if (extension) {
|
|
216
|
-
return extension;
|
|
217
|
-
}
|
|
218
|
-
/* istanbul ignore next */
|
|
219
|
-
throw new Error(`SchemaGenerator extension not registered.`);
|
|
215
|
+
return this.schema;
|
|
220
216
|
}
|
|
221
217
|
/**
|
|
222
218
|
* Gets the EntityGenerator.
|
|
219
|
+
* @deprecated use `orm.entityGenerator` instead
|
|
223
220
|
*/
|
|
224
221
|
getEntityGenerator() {
|
|
225
|
-
return this.
|
|
222
|
+
return this.entityGenerator;
|
|
226
223
|
}
|
|
227
224
|
/**
|
|
228
225
|
* Gets the Migrator.
|
|
226
|
+
* @deprecated use `orm.migrator` instead
|
|
229
227
|
*/
|
|
230
228
|
getMigrator() {
|
|
231
|
-
return this.
|
|
229
|
+
return this.migrator;
|
|
232
230
|
}
|
|
233
231
|
/**
|
|
234
232
|
* Gets the SeedManager
|
|
233
|
+
* @deprecated use `orm.seeder` instead
|
|
235
234
|
*/
|
|
236
235
|
getSeeder() {
|
|
237
|
-
return this.
|
|
236
|
+
return this.seeder;
|
|
238
237
|
}
|
|
239
238
|
/**
|
|
240
|
-
*
|
|
239
|
+
* Gets the SchemaGenerator.
|
|
241
240
|
*/
|
|
242
241
|
get schema() {
|
|
243
|
-
return this.
|
|
242
|
+
return this.config.getExtension('@mikro-orm/schema-generator');
|
|
244
243
|
}
|
|
245
244
|
/**
|
|
246
|
-
*
|
|
245
|
+
* Gets the SeedManager
|
|
247
246
|
*/
|
|
248
247
|
get seeder() {
|
|
249
|
-
return this.
|
|
248
|
+
return this.driver.getPlatform().getExtension('SeedManager', '@mikro-orm/seeder', '@mikro-orm/seeder', this.em);
|
|
250
249
|
}
|
|
251
250
|
/**
|
|
252
|
-
*
|
|
251
|
+
* Gets the Migrator.
|
|
253
252
|
*/
|
|
254
253
|
get migrator() {
|
|
255
|
-
return this.
|
|
254
|
+
return this.driver.getPlatform().getExtension('Migrator', '@mikro-orm/migrator', '@mikro-orm/migrations', this.em);
|
|
256
255
|
}
|
|
257
256
|
/**
|
|
258
|
-
*
|
|
257
|
+
* Gets the EntityGenerator.
|
|
259
258
|
*/
|
|
260
259
|
get entityGenerator() {
|
|
261
|
-
return this.
|
|
260
|
+
return this.driver.getPlatform().getExtension('EntityGenerator', '@mikro-orm/entity-generator', '@mikro-orm/entity-generator', this.em);
|
|
262
261
|
}
|
|
263
262
|
}
|
|
264
263
|
exports.MikroORM = MikroORM;
|
package/events/EventManager.d.ts
CHANGED
|
@@ -6,8 +6,9 @@ export declare class EventManager {
|
|
|
6
6
|
private readonly entities;
|
|
7
7
|
private readonly cache;
|
|
8
8
|
private readonly subscribers;
|
|
9
|
-
constructor(subscribers: EventSubscriber
|
|
9
|
+
constructor(subscribers: Iterable<EventSubscriber>);
|
|
10
10
|
registerSubscriber(subscriber: EventSubscriber): void;
|
|
11
|
+
getSubscribers(): Set<EventSubscriber>;
|
|
11
12
|
dispatchEvent<T extends object>(event: TransactionEventType, args: TransactionEventArgs, meta?: EntityMetadata<T>): unknown;
|
|
12
13
|
dispatchEvent<T extends object>(event: EventType.onInit, args: Partial<EventArgs<T>>, meta?: EntityMetadata<T>): unknown;
|
|
13
14
|
dispatchEvent<T extends object>(event: EventType, args: Partial<EventArgs<T> | FlushEventArgs>, meta?: EntityMetadata<T>): Promise<unknown>;
|
package/events/EventManager.js
CHANGED
|
@@ -7,21 +7,29 @@ class EventManager {
|
|
|
7
7
|
listeners = {};
|
|
8
8
|
entities = new Map();
|
|
9
9
|
cache = new Map();
|
|
10
|
-
subscribers =
|
|
10
|
+
subscribers = new Set();
|
|
11
11
|
constructor(subscribers) {
|
|
12
|
-
|
|
12
|
+
for (const subscriber of subscribers) {
|
|
13
|
+
this.registerSubscriber(subscriber);
|
|
14
|
+
}
|
|
13
15
|
}
|
|
14
16
|
registerSubscriber(subscriber) {
|
|
15
|
-
this.subscribers.
|
|
17
|
+
if (this.subscribers.has(subscriber)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
this.subscribers.add(subscriber);
|
|
16
21
|
this.entities.set(subscriber, this.getSubscribedEntities(subscriber));
|
|
17
22
|
this.cache.clear();
|
|
18
23
|
utils_1.Utils.keys(enums_1.EventType)
|
|
19
24
|
.filter(event => event in subscriber)
|
|
20
25
|
.forEach(event => {
|
|
21
|
-
this.listeners[event] ??=
|
|
22
|
-
this.listeners[event].
|
|
26
|
+
this.listeners[event] ??= new Set();
|
|
27
|
+
this.listeners[event].add(subscriber);
|
|
23
28
|
});
|
|
24
29
|
}
|
|
30
|
+
getSubscribers() {
|
|
31
|
+
return this.subscribers;
|
|
32
|
+
}
|
|
25
33
|
dispatchEvent(event, args, meta) {
|
|
26
34
|
const listeners = [];
|
|
27
35
|
const entity = args.entity;
|
|
@@ -33,9 +41,9 @@ class EventManager {
|
|
|
33
41
|
const handler = typeof hook === 'function' ? hook : entity[hook] ?? prototypeHook;
|
|
34
42
|
return handler.bind(entity);
|
|
35
43
|
}));
|
|
36
|
-
for (const listener of this.listeners[event]
|
|
44
|
+
for (const listener of this.listeners[event] ?? new Set()) {
|
|
37
45
|
const entities = this.entities.get(listener);
|
|
38
|
-
if (entities.
|
|
46
|
+
if (entities.size === 0 || !entity || entities.has(entity.constructor.name)) {
|
|
39
47
|
listeners.push(listener[event].bind(listener));
|
|
40
48
|
}
|
|
41
49
|
}
|
|
@@ -54,9 +62,9 @@ class EventManager {
|
|
|
54
62
|
this.cache.set(cacheKey, true);
|
|
55
63
|
return true;
|
|
56
64
|
}
|
|
57
|
-
for (const listener of this.listeners[event] ??
|
|
65
|
+
for (const listener of this.listeners[event] ?? new Set()) {
|
|
58
66
|
const entities = this.entities.get(listener);
|
|
59
|
-
if (entities.
|
|
67
|
+
if (entities.size === 0 || entities.has(meta.className)) {
|
|
60
68
|
this.cache.set(cacheKey, true);
|
|
61
69
|
return true;
|
|
62
70
|
}
|
|
@@ -69,9 +77,9 @@ class EventManager {
|
|
|
69
77
|
}
|
|
70
78
|
getSubscribedEntities(listener) {
|
|
71
79
|
if (!listener.getSubscribedEntities) {
|
|
72
|
-
return
|
|
80
|
+
return new Set();
|
|
73
81
|
}
|
|
74
|
-
return listener.getSubscribedEntities().map(name => utils_1.Utils.className(name));
|
|
82
|
+
return new Set(listener.getSubscribedEntities().map(name => utils_1.Utils.className(name)));
|
|
75
83
|
}
|
|
76
84
|
}
|
|
77
85
|
exports.EventManager = EventManager;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.6.2-dev.
|
|
3
|
+
"version": "6.6.2-dev.10",
|
|
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.2",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.6.2-dev.
|
|
67
|
+
"mikro-orm": "6.6.2-dev.10",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/utils/Configuration.d.ts
CHANGED
|
@@ -321,7 +321,7 @@ export interface MikroORMOptions<D extends IDatabaseDriver = IDatabaseDriver, EM
|
|
|
321
321
|
extensions: {
|
|
322
322
|
register: (orm: MikroORM) => void;
|
|
323
323
|
}[];
|
|
324
|
-
subscribers:
|
|
324
|
+
subscribers: Iterable<EventSubscriber | Constructor<EventSubscriber>>;
|
|
325
325
|
filters: Dictionary<{
|
|
326
326
|
name?: string;
|
|
327
327
|
} & Omit<FilterDef, 'name'>>;
|
package/utils/Configuration.js
CHANGED
|
@@ -345,7 +345,7 @@ class Configuration {
|
|
|
345
345
|
if (!this.options.filtersOnRelations) {
|
|
346
346
|
this.options.autoJoinRefsForFilters ??= false;
|
|
347
347
|
}
|
|
348
|
-
this.options.subscribers =
|
|
348
|
+
this.options.subscribers = [...this.options.subscribers].map(subscriber => {
|
|
349
349
|
return subscriber.constructor.name === 'Function' ? new subscriber() : subscriber;
|
|
350
350
|
});
|
|
351
351
|
this.sync();
|
|
@@ -288,10 +288,14 @@ class EntityComparator {
|
|
|
288
288
|
lines.push(`${padding} if (${value} == null || ${value} instanceof Date) {`);
|
|
289
289
|
lines.push(`${padding} ${key} = ${value};`);
|
|
290
290
|
if (!tz || tz === 'local') {
|
|
291
|
+
lines.push(`${padding} } else if (typeof ${value} === 'bigint') {`);
|
|
292
|
+
lines.push(`${padding} ${key} = parseDate(Number(${value}));`);
|
|
291
293
|
lines.push(`${padding} } else {`);
|
|
292
294
|
lines.push(`${padding} ${key} = parseDate(${value});`);
|
|
293
295
|
}
|
|
294
296
|
else {
|
|
297
|
+
lines.push(`${padding} } else if (typeof ${value} === 'bigint') {`);
|
|
298
|
+
lines.push(`${padding} ${key} = parseDate(Number(${value}));`);
|
|
295
299
|
lines.push(`${padding} } else if (typeof ${value} === 'number' || ${value}.includes('+') || ${value}.lastIndexOf('-') > 10 || ${value}.endsWith('Z')) {`);
|
|
296
300
|
lines.push(`${padding} ${key} = parseDate(${value});`);
|
|
297
301
|
lines.push(`${padding} } else {`);
|