@tryghost/domain-events 3.0.3 → 3.1.0
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/LICENSE +21 -0
- package/README.md +1 -1
- package/lib/DomainEvents.js +26 -2
- package/lib/index.d.ts +1 -1
- package/package.json +18 -20
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013-2026 Ghost Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
package/lib/DomainEvents.js
CHANGED
|
@@ -18,7 +18,7 @@ class DomainEvents {
|
|
|
18
18
|
* @private
|
|
19
19
|
* @type EventEmitter
|
|
20
20
|
*/
|
|
21
|
-
static ee = new EventEmitter;
|
|
21
|
+
static ee = new EventEmitter();
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* @template Data
|
|
@@ -38,6 +38,8 @@ class DomainEvents {
|
|
|
38
38
|
}
|
|
39
39
|
if (this.#trackingEnabled) {
|
|
40
40
|
this.#onProcessed();
|
|
41
|
+
} else {
|
|
42
|
+
// Tracking is disabled outside tests.
|
|
41
43
|
}
|
|
42
44
|
});
|
|
43
45
|
}
|
|
@@ -61,6 +63,8 @@ class DomainEvents {
|
|
|
61
63
|
static dispatchRaw(name, data) {
|
|
62
64
|
if (this.#trackingEnabled) {
|
|
63
65
|
this.#dispatchCount += DomainEvents.ee.listenerCount(name);
|
|
66
|
+
} else {
|
|
67
|
+
// Tracking is disabled outside tests.
|
|
64
68
|
}
|
|
65
69
|
DomainEvents.ee.emit(name, data);
|
|
66
70
|
}
|
|
@@ -80,8 +84,9 @@ class DomainEvents {
|
|
|
80
84
|
// Resolve immediately if there are no events in the queue
|
|
81
85
|
resolve();
|
|
82
86
|
return;
|
|
87
|
+
} else {
|
|
88
|
+
this.#awaitQueue.push({ resolve });
|
|
83
89
|
}
|
|
84
|
-
this.#awaitQueue.push({resolve});
|
|
85
90
|
});
|
|
86
91
|
}
|
|
87
92
|
|
|
@@ -92,8 +97,27 @@ class DomainEvents {
|
|
|
92
97
|
item.resolve();
|
|
93
98
|
}
|
|
94
99
|
this.#awaitQueue = [];
|
|
100
|
+
} else {
|
|
101
|
+
// Wait for the remaining tracked listeners.
|
|
95
102
|
}
|
|
96
103
|
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Enable or disable dispatch/processed tracking. Test-only.
|
|
107
|
+
* @param {boolean} enabled
|
|
108
|
+
*/
|
|
109
|
+
static setTrackingEnabledForTest(enabled) {
|
|
110
|
+
this.#trackingEnabled = enabled;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Clear the await queue and reset dispatch/processed counts. Test-only.
|
|
115
|
+
*/
|
|
116
|
+
static resetTrackingStateForTest() {
|
|
117
|
+
this.#awaitQueue = [];
|
|
118
|
+
this.#dispatchCount = 0;
|
|
119
|
+
this.#processedCount = 0;
|
|
120
|
+
}
|
|
97
121
|
}
|
|
98
122
|
|
|
99
123
|
module.exports = DomainEvents;
|
package/lib/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare type ConstructorOf<T> = new (...args: any[]) => T
|
|
1
|
+
export declare type ConstructorOf<T> = new (...args: any[]) => T;
|
package/package.json
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/domain-events",
|
|
3
|
-
"version": "3.0
|
|
4
|
-
"publishConfig": {
|
|
5
|
-
"access": "public"
|
|
6
|
-
},
|
|
7
|
-
"author": "Ghost Foundation",
|
|
3
|
+
"version": "3.1.0",
|
|
8
4
|
"license": "MIT",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"test": "yarn test:unit",
|
|
15
|
-
"lint:code": "eslint *.js lib/ --ext .js --cache",
|
|
16
|
-
"lint": "yarn lint:code && yarn lint:test",
|
|
17
|
-
"lint:test": "eslint -c test/.eslintrc.js test/ --ext .js --cache"
|
|
5
|
+
"author": "Ghost Foundation",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/TryGhost/framework.git",
|
|
9
|
+
"directory": "packages/domain-events"
|
|
18
10
|
},
|
|
19
11
|
"files": [
|
|
20
12
|
"index.js",
|
|
21
13
|
"lib"
|
|
22
14
|
],
|
|
15
|
+
"main": "index.js",
|
|
16
|
+
"types": "types",
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
23
20
|
"devDependencies": {
|
|
24
|
-
"@tryghost/logging": "
|
|
21
|
+
"@tryghost/logging": "4.1.0"
|
|
25
22
|
},
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
23
|
+
"scripts": {
|
|
24
|
+
"dev": "echo \"Implement me!\"",
|
|
25
|
+
"test:unit": "NODE_ENV=testing vitest run --coverage --config ../../vitest.config.ts",
|
|
26
|
+
"test": "pnpm run test:unit",
|
|
27
|
+
"lint": "oxlint -c ../../.oxlintrc.json ."
|
|
30
28
|
}
|
|
31
|
-
}
|
|
29
|
+
}
|