@mikro-orm/core 6.6.2-dev.2 → 6.6.2-dev.4
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
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.4",
|
|
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.4",
|
|
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 {`);
|