@mikro-orm/core 7.0.0-dev.84 → 7.0.0-dev.85
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/events/EventManager.d.ts +2 -1
- package/events/EventManager.js +19 -11
- package/package.json +1 -1
- package/utils/Configuration.d.ts +1 -1
- package/utils/Configuration.js +1 -1
- package/utils/EntityComparator.js +4 -0
- package/utils/Utils.js +1 -1
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
|
@@ -4,21 +4,29 @@ export class EventManager {
|
|
|
4
4
|
listeners = {};
|
|
5
5
|
entities = new Map();
|
|
6
6
|
cache = new Map();
|
|
7
|
-
subscribers =
|
|
7
|
+
subscribers = new Set();
|
|
8
8
|
constructor(subscribers) {
|
|
9
|
-
|
|
9
|
+
for (const subscriber of subscribers) {
|
|
10
|
+
this.registerSubscriber(subscriber);
|
|
11
|
+
}
|
|
10
12
|
}
|
|
11
13
|
registerSubscriber(subscriber) {
|
|
12
|
-
this.subscribers.
|
|
14
|
+
if (this.subscribers.has(subscriber)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
this.subscribers.add(subscriber);
|
|
13
18
|
this.entities.set(subscriber, this.getSubscribedEntities(subscriber));
|
|
14
19
|
this.cache.clear();
|
|
15
20
|
Utils.keys(EventType)
|
|
16
21
|
.filter(event => event in subscriber)
|
|
17
22
|
.forEach(event => {
|
|
18
|
-
this.listeners[event] ??=
|
|
19
|
-
this.listeners[event].
|
|
23
|
+
this.listeners[event] ??= new Set();
|
|
24
|
+
this.listeners[event].add(subscriber);
|
|
20
25
|
});
|
|
21
26
|
}
|
|
27
|
+
getSubscribers() {
|
|
28
|
+
return this.subscribers;
|
|
29
|
+
}
|
|
22
30
|
dispatchEvent(event, args, meta) {
|
|
23
31
|
const listeners = [];
|
|
24
32
|
const entity = args.entity;
|
|
@@ -30,9 +38,9 @@ export class EventManager {
|
|
|
30
38
|
const handler = typeof hook === 'function' ? hook : entity[hook] ?? prototypeHook;
|
|
31
39
|
return handler.bind(entity);
|
|
32
40
|
}));
|
|
33
|
-
for (const listener of this.listeners[event]
|
|
41
|
+
for (const listener of this.listeners[event] ?? new Set()) {
|
|
34
42
|
const entities = this.entities.get(listener);
|
|
35
|
-
if (entities.
|
|
43
|
+
if (entities.size === 0 || !entity || entities.has(entity.constructor.name)) {
|
|
36
44
|
listeners.push(listener[event].bind(listener));
|
|
37
45
|
}
|
|
38
46
|
}
|
|
@@ -51,9 +59,9 @@ export class EventManager {
|
|
|
51
59
|
this.cache.set(cacheKey, true);
|
|
52
60
|
return true;
|
|
53
61
|
}
|
|
54
|
-
for (const listener of this.listeners[event] ??
|
|
62
|
+
for (const listener of this.listeners[event] ?? new Set()) {
|
|
55
63
|
const entities = this.entities.get(listener);
|
|
56
|
-
if (entities.
|
|
64
|
+
if (entities.size === 0 || entities.has(meta.className)) {
|
|
57
65
|
this.cache.set(cacheKey, true);
|
|
58
66
|
return true;
|
|
59
67
|
}
|
|
@@ -66,8 +74,8 @@ export class EventManager {
|
|
|
66
74
|
}
|
|
67
75
|
getSubscribedEntities(listener) {
|
|
68
76
|
if (!listener.getSubscribedEntities) {
|
|
69
|
-
return
|
|
77
|
+
return new Set();
|
|
70
78
|
}
|
|
71
|
-
return listener.getSubscribedEntities().map(name => Utils.className(name));
|
|
79
|
+
return new Set(listener.getSubscribedEntities().map(name => Utils.className(name)));
|
|
72
80
|
}
|
|
73
81
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-dev.
|
|
4
|
+
"version": "7.0.0-dev.85",
|
|
5
5
|
"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.",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./package.json": "./package.json",
|
package/utils/Configuration.d.ts
CHANGED
|
@@ -480,7 +480,7 @@ export interface Options<Driver extends IDatabaseDriver = IDatabaseDriver, EM ex
|
|
|
480
480
|
* Event subscribers to register.
|
|
481
481
|
* Can be class references or instances.
|
|
482
482
|
*/
|
|
483
|
-
subscribers?:
|
|
483
|
+
subscribers?: Iterable<EventSubscriber | Constructor<EventSubscriber>>;
|
|
484
484
|
/**
|
|
485
485
|
* Global entity filters to apply.
|
|
486
486
|
* Filters are applied by default unless explicitly disabled.
|
package/utils/Configuration.js
CHANGED
|
@@ -319,7 +319,7 @@ export class Configuration {
|
|
|
319
319
|
if (!this.options.filtersOnRelations) {
|
|
320
320
|
this.options.autoJoinRefsForFilters ??= false;
|
|
321
321
|
}
|
|
322
|
-
this.options.subscribers =
|
|
322
|
+
this.options.subscribers = [...this.options.subscribers].map(subscriber => {
|
|
323
323
|
return subscriber.constructor.name === 'Function' ? new subscriber() : subscriber;
|
|
324
324
|
});
|
|
325
325
|
this.sync();
|
|
@@ -285,10 +285,14 @@ export class EntityComparator {
|
|
|
285
285
|
lines.push(`${padding} if (${value} == null || ${value} instanceof Date) {`);
|
|
286
286
|
lines.push(`${padding} ${key} = ${value};`);
|
|
287
287
|
if (!tz || tz === 'local') {
|
|
288
|
+
lines.push(`${padding} } else if (typeof ${value} === 'bigint') {`);
|
|
289
|
+
lines.push(`${padding} ${key} = parseDate(Number(${value}));`);
|
|
288
290
|
lines.push(`${padding} } else {`);
|
|
289
291
|
lines.push(`${padding} ${key} = parseDate(${value});`);
|
|
290
292
|
}
|
|
291
293
|
else {
|
|
294
|
+
lines.push(`${padding} } else if (typeof ${value} === 'bigint') {`);
|
|
295
|
+
lines.push(`${padding} ${key} = parseDate(Number(${value}));`);
|
|
292
296
|
lines.push(`${padding} } else if (typeof ${value} === 'number' || ${value}.includes('+') || ${value}.lastIndexOf('-') > 10 || ${value}.endsWith('Z')) {`);
|
|
293
297
|
lines.push(`${padding} ${key} = parseDate(${value});`);
|
|
294
298
|
lines.push(`${padding} } else {`);
|