@open-wa/hyperemitter 5.0.0-alpha.8 → 5.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 +202 -0
- package/README.md +2 -2
- package/dist/index.d.cts +4 -6
- package/dist/index.d.cts.map +1 -1
- package/package.json +13 -6
- package/.turbo/turbo-build.log +0 -13
- package/CHANGELOG.md +0 -68
- package/LICENSE.md +0 -67
- package/benchmarks/baseline/README.md +0 -9
- package/benchmarks/baseline/results/baseline-node-20.8.0.json +0 -51
- package/benchmarks/baseline/run-baseline.js +0 -215
- package/src/core/HyperEmitter.ts +0 -337
- package/src/index.ts +0 -7
- package/src/routing/RadixNode.ts +0 -19
- package/src/routing/RadixTree.ts +0 -124
- package/src/types/index.ts +0 -39
- package/src/utils/listener.ts +0 -59
- package/tsconfig.json +0 -21
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# HyperEmitter (planning scaffold)
|
|
2
2
|
|
|
3
|
-
This package
|
|
3
|
+
This package is a placeholder for the HyperEmitter benchmarks and developer tools. The emitter code will arrive later. This package records competitor performance and defines build and CI expectations.
|
|
4
4
|
|
|
5
5
|
## Baseline benchmarks
|
|
6
6
|
|
|
@@ -24,4 +24,4 @@ Outputs JSON to `packages/hyperemitter/benchmarks/baseline/results/baseline-node
|
|
|
24
24
|
- Dual ESM/CJS outputs with typed entrypoints.
|
|
25
25
|
- Adapters for `EventTarget`, Node `EventEmitter`, and worker threads.
|
|
26
26
|
- Optional plugins (TTL/maxListeners/tracing) kept out of the hot path.
|
|
27
|
-
-
|
|
27
|
+
- CI will enforce performance budgets after HyperEmitter arrives. The targets are a 5% tseep envelope for exact events and 10x EE2 for wildcards.
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { EventEmitter } from "node:events";
|
|
2
|
-
import * as _$_open_wa_logger0 from "@open-wa/logger";
|
|
3
|
-
|
|
4
2
|
//#region src/types/index.d.ts
|
|
5
3
|
type EventMap = {
|
|
6
4
|
[key: string]: unknown;
|
|
@@ -16,12 +14,12 @@ interface HyperEmitterOptions {
|
|
|
16
14
|
captureRejections?: boolean;
|
|
17
15
|
onError?: (error: unknown) => void;
|
|
18
16
|
debug?: boolean;
|
|
19
|
-
logger?:
|
|
20
|
-
loggerContext?:
|
|
17
|
+
logger?: import('@open-wa/logger').Logger;
|
|
18
|
+
loggerContext?: import('@open-wa/logger').LogContext;
|
|
21
19
|
}
|
|
22
20
|
//#endregion
|
|
23
21
|
//#region src/core/HyperEmitter.d.ts
|
|
24
|
-
declare class HyperEmitter<TMap extends object = Record<string, unknown>> {
|
|
22
|
+
export declare class HyperEmitter<TMap extends object = Record<string, unknown>> {
|
|
25
23
|
private readonly delimiter;
|
|
26
24
|
private readonly captureRejections;
|
|
27
25
|
private readonly onError?;
|
|
@@ -55,5 +53,5 @@ declare class HyperEmitter<TMap extends object = Record<string, unknown>> {
|
|
|
55
53
|
private logDebug;
|
|
56
54
|
}
|
|
57
55
|
//#endregion
|
|
58
|
-
export {
|
|
56
|
+
export type { EventListener, EventMap, HyperEmitterOptions, ListenerOptions };
|
|
59
57
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types/index.ts","../src/core/HyperEmitter.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":["NodeEmitter"],"sources":["../src/types/index.ts","../src/core/HyperEmitter.ts"],"mappings":";;KAEY;GAAc;;KAEd,cAAc,MAAM,SAAS,aAAa;UAErC;EAIf,SAAS;EAKT;EAIA;;UAGe;EACf;EACA;EACA,WAAW;EAIX;EAIA,mCAAmC;EAInC,0CAA0C;;;;qBCvB/B,aAAa,sBAAsB;mBAC7B;mBACA;mBACA;mBACA;mBACA;mBACA;mBACA;UAET;UACA;UACA;UACA;UACA;EAER,YAAY,UAAS;EA2BrB,GAAG,gBAAgB,eACjB,OAAO,GACP,WAAW,SAAS,KAAK,cAAc,eACvC,UAAS;EAOX,KAAK,gBAAgB,eACnB,OAAO,GACP,WAAW,SAAS,KAAK,cAAc,eACvC,UAAS;EAQX,IAAI,gBAAgB,eAAe,OAAO,GAAG,WAAW,SAAS,KAAK,cAAc;EAgBpF,KAAK,gBAAgB,eACnB,OAAO,GACP,SAAS,KAAK;EAuBhB,MAAM,WAAW,eAAe;EAQhC,OAAO,WAAW,eAAe;EAKjC,cAAc,cAAc;EAS5B,mBAAmB,cAAc;EAgCjC,gBAAgB,SAASA,cAAa;EAYtC,cAAc,QAAQA;EAgBtB,cAAc,QAAQ,aAAa,cAAc,iBAAiB;UAS1D;UAwBA;UAwBA;UAeA;UAmBA;UA6BA;UAYA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-wa/hyperemitter",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "HyperEmitter: high-performance, schema-driven event emitter for the open-wa v5 stack.",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"types": "dist/index.d.cts",
|
|
@@ -24,15 +24,22 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@open-wa/logger": "5.
|
|
27
|
+
"@open-wa/logger": "5.1.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"emittery": "^1.0
|
|
30
|
+
"emittery": "^2.1.0",
|
|
31
31
|
"eventemitter2": "^6.4.9",
|
|
32
|
-
"eventemitter3": "^5.0.
|
|
32
|
+
"eventemitter3": "^5.0.4",
|
|
33
33
|
"mitt": "^3.0.1",
|
|
34
|
-
"tseep": "^1.
|
|
35
|
-
"typescript": "^
|
|
34
|
+
"tseep": "^1.3.1",
|
|
35
|
+
"typescript": "^7.0.2"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/open-wa/wa-automate-nodejs.git"
|
|
36
43
|
},
|
|
37
44
|
"scripts": {
|
|
38
45
|
"build": "tsdown src/index.ts --format cjs",
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
$ tsdown src/index.ts --format cjs
|
|
2
|
-
[34mℹ[39m [34mtsdown v0.21.7[39m powered by [38;2;255;126;23mrolldown v1.0.0-rc.12[39m
|
|
3
|
-
[34mℹ[39m entry: [34msrc/index.ts[39m
|
|
4
|
-
[34mℹ[39m tsconfig: [34mtsconfig.json[39m
|
|
5
|
-
[34mℹ[39m Build start
|
|
6
|
-
[34mℹ[39m [2mdist/[22m[1mindex.cjs[22m [2m10.87 kB[22m [2m│ gzip: 3.01 kB[22m
|
|
7
|
-
[34mℹ[39m 1 files, total: 10.87 kB
|
|
8
|
-
[34mℹ[39m [2mdist/[22mindex.d.cts.map [2m1.46 kB[22m [2m│ gzip: 0.53 kB[22m
|
|
9
|
-
[34mℹ[39m [2mdist/[22m[32m[1mindex.d.cts[22m[39m [2m2.31 kB[22m [2m│ gzip: 0.77 kB[22m
|
|
10
|
-
[34mℹ[39m 2 files, total: 3.77 kB
|
|
11
|
-
[33m[PLUGIN_TIMINGS] Warning:[0m Your build spent significant time in plugin `rolldown-plugin-dts:generate`. See https://rolldown.rs/options/checks#plugintimings for more details.
|
|
12
|
-
|
|
13
|
-
[32m✔[39m Build complete in [32m3301ms[39m
|
package/CHANGELOG.md
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# @open-wa/hyperemitter
|
|
2
|
-
|
|
3
|
-
## 5.0.0-alpha.8
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- Updated dependencies []:
|
|
8
|
-
- @open-wa/logger@5.0.0-alpha.8
|
|
9
|
-
|
|
10
|
-
## 5.0.0-alpha.7
|
|
11
|
-
|
|
12
|
-
### Patch Changes
|
|
13
|
-
|
|
14
|
-
- Updated dependencies []:
|
|
15
|
-
- @open-wa/logger@5.0.0-alpha.7
|
|
16
|
-
|
|
17
|
-
## 5.0.0-alpha.6
|
|
18
|
-
|
|
19
|
-
### Patch Changes
|
|
20
|
-
|
|
21
|
-
- Updated dependencies []:
|
|
22
|
-
- @open-wa/logger@5.0.0-alpha.6
|
|
23
|
-
|
|
24
|
-
## 5.0.0-alpha.5
|
|
25
|
-
|
|
26
|
-
### Patch Changes
|
|
27
|
-
|
|
28
|
-
- Updated dependencies []:
|
|
29
|
-
- @open-wa/logger@5.0.0-alpha.5
|
|
30
|
-
|
|
31
|
-
## 5.0.0-alpha.4
|
|
32
|
-
|
|
33
|
-
### Patch Changes
|
|
34
|
-
|
|
35
|
-
- Updated dependencies []:
|
|
36
|
-
- @open-wa/logger@5.0.0-alpha.4
|
|
37
|
-
|
|
38
|
-
## 5.0.0-alpha.3
|
|
39
|
-
|
|
40
|
-
### Patch Changes
|
|
41
|
-
|
|
42
|
-
- Updated dependencies []:
|
|
43
|
-
- @open-wa/logger@5.0.0-alpha.3
|
|
44
|
-
|
|
45
|
-
## 5.0.0-alpha.2
|
|
46
|
-
|
|
47
|
-
### Patch Changes
|
|
48
|
-
|
|
49
|
-
- Publish HyperEmitter with the v5 alpha package group.
|
|
50
|
-
|
|
51
|
-
- Updated dependencies []:
|
|
52
|
-
- @open-wa/logger@5.0.0-alpha.2
|
|
53
|
-
|
|
54
|
-
## 6.0.0-alpha.2
|
|
55
|
-
|
|
56
|
-
### Patch Changes
|
|
57
|
-
|
|
58
|
-
- Updated dependencies []:
|
|
59
|
-
- @open-wa/logger@6.0.0-alpha.2
|
|
60
|
-
|
|
61
|
-
## 5.0.1-alpha.2
|
|
62
|
-
|
|
63
|
-
### Patch Changes
|
|
64
|
-
|
|
65
|
-
- Dry run patch bump
|
|
66
|
-
|
|
67
|
-
- Updated dependencies []:
|
|
68
|
-
- @open-wa/logger@5.0.1-alpha.2
|
package/LICENSE.md
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
### Copyright (c) 2020 Mohammed Shah
|
|
2
|
-
|
|
3
|
-
# Hippocratic + Do Not Harm (H-DNH) Version 1.1
|
|
4
|
-
|
|
5
|
-
## Preamble
|
|
6
|
-
|
|
7
|
-
Most software today is developed with little to no thought of how it will be used, or the consequences for our society and planet.
|
|
8
|
-
|
|
9
|
-
As software developers, we engineer the infrastructure of the 21st century. We recognise that our infrastructure has great power to shape the world and the lives of those we share it with, and we choose to consciously take responsibility for the social and environmental impacts of what we build.
|
|
10
|
-
|
|
11
|
-
We envisage a world free from injustice, inequality, and the reckless destruction of lives and our planet. We reject slavery in all its forms, whether by force, indebtedness, or by algorithms that hack human vulnerabilities. We seek a world where humankind is at peace with our neighbours, nature, and ourselves. We want our work to enrich the physical, mental and spiritual wellbeing of all society.
|
|
12
|
-
|
|
13
|
-
We build software to further this vision of a just world, or at the very least, to not put that vision further from reach.
|
|
14
|
-
|
|
15
|
-
## Terms
|
|
16
|
-
|
|
17
|
-
Licensor hereby grants permission by this license ("License"), free of charge, to any person or entity (the "Licensee") obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
18
|
-
|
|
19
|
-
1. All redistribution of source code or binary form, including any modifications must be under these terms. You must inform recipients that the code is governed by these conditions, and how they can obtain a copy of this license. You may not attempt to alter the conditions of who may/may not use this software.
|
|
20
|
-
|
|
21
|
-
2. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
22
|
-
|
|
23
|
-
3. This software must not be used by any organisation, website, product or service that:
|
|
24
|
-
|
|
25
|
-
a) lobbies for, promotes, or derives a majority of income from actions that support or contribute to:
|
|
26
|
-
* sex trafficking
|
|
27
|
-
* human trafficking
|
|
28
|
-
* slavery
|
|
29
|
-
* indentured servitude
|
|
30
|
-
* gambling
|
|
31
|
-
* tobacco
|
|
32
|
-
* adversely addictive behaviours
|
|
33
|
-
* nuclear energy
|
|
34
|
-
* warfare
|
|
35
|
-
* weapons manufacturing
|
|
36
|
-
* war crimes
|
|
37
|
-
* settler colonialism
|
|
38
|
-
* apartheid
|
|
39
|
-
* vaccine misinformation
|
|
40
|
-
* climate misinformation
|
|
41
|
-
* child endangerment
|
|
42
|
-
* violence (except when required to protect public safety)
|
|
43
|
-
* burning of forests
|
|
44
|
-
* deforestation
|
|
45
|
-
* hate speech or discrimination based on age, gender, gender identity, race, sexuality, religion, nationality
|
|
46
|
-
|
|
47
|
-
b) lobbies against, or derives a majority of income from actions that discourage or frustrate:
|
|
48
|
-
* peace
|
|
49
|
-
* access to the rights set out in the Universal Declaration of Human Rights and the Convention on the Rights of the Child
|
|
50
|
-
* peaceful assembly and association (including worker associations)
|
|
51
|
-
* a safe environment or action to curtail the use of fossil fuels or prevent climate change
|
|
52
|
-
* democratic processes
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
4. Compliance with Human Rights Laws and Human Rights Principles:
|
|
56
|
-
|
|
57
|
-
a. **Human Rights Laws**. The Software shall not be used by any person or entity for any systems, activities, or other uses that violate any applicable laws, regulations, or rules that protect human, civil, labor, privacy, political, environmental, security, economic, due process, or similar rights (the "Human Rights Laws"). Where the Human Rights Laws of more than one jurisdiction are applicable to the use of the Software, the Human Rights Laws that are most protective of the individuals or groups harmed shall apply.
|
|
58
|
-
|
|
59
|
-
b. **Human Rights Principles**. Licensee is advised to consult the articles of the United Nations Universal Declaration of Human Rights (https://www.un.org/en/universal-declaration-human-rights/) and the United Nations Global Compact (https://www.unglobalcompact.org/ what-is-gc/mission/principles) that define recognized principles of international human rights (the "Human Rights Principles"). It is Licensor's express intent that all use of the Software be consistent with Human Rights Principles. If Licensor receives notification or otherwise learns of an alleged violation of any Human Rights Principles relating to Licensee's use of the Software, Licensor may in its discretion and without obligation (i) (a) notify Licensee of such allegation and (b) allow Licensee 90 days from notification under (i)(a) to investigate and respond to Licensor regarding the allegation and (ii) (a) after the earlier of 90 days from notification under (i)(a), or Licensee's response under (i)(b), notify Licensee of License termination and (b) allow Licensee an additional 90 days from notification under (ii)(a) to cease use of the Software.
|
|
60
|
-
|
|
61
|
-
c. **Indemnity**. Licensee shall hold harmless and indemnify Licensor against all losses, damages, liabilities, deficiencies, claims, actions, judgments, settlements, interest, awards, penalties, fines, costs, or expenses of whatever kind, including Licensor's reasonable attorneys' fees, arising out of or relating to Licensee's non-compliance with this License or use of the Software in violation of Human Rights Laws or Human Rights Principles.
|
|
62
|
-
|
|
63
|
-
5. Enforceability: If any portion or provision of this License is determined to be invalid, illegal, or unenforceable by a court of competent jurisdiction, then such invalidity, illegality, or unenforceability shall not affect any other term or provision of this License or invalidate or render unenforceable such term or provision in any other jurisdiction. Upon a determination that any term or provision is invalid, illegal, or unenforceable, to the extent permitted by applicable law, the court may modify this License to affect the original intent of the parties as closely as possible. The section headings are for convenience only and are not intended to affect the construction or interpretation of this License. Any rule of construction to the effect that ambiguities are to be resolved against the drafting party shall not apply in interpreting this License. The language in this License shall be interpreted as to its fair meaning and not strictly for or against any party.
|
|
64
|
-
|
|
65
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
66
|
-
|
|
67
|
-
This license is an extension of the Hippocratic License - an Ethical Source license (https://ethicalsource.dev) and the Do Not Harm License - (https://github.com/raisely/NoHarm)
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
Baseline benchmark harness for competitor emitters. Runs before HyperEmitter lands to capture regression targets.
|
|
2
|
-
|
|
3
|
-
Usage:
|
|
4
|
-
- `pnpm --filter @open-wa/hyperemitter bench:baseline` (writes to `benchmarks/baseline/results/`)
|
|
5
|
-
- `node benchmarks/baseline/run-baseline.js --iterations 750000 --output custom.json`
|
|
6
|
-
|
|
7
|
-
Notes:
|
|
8
|
-
- Skips libraries that are not installed; install dev deps in this package to populate all competitors.
|
|
9
|
-
- Includes exact-match (3 args) and wildcard runs where the library supports wildcards.
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"meta": {
|
|
3
|
-
"nodeVersion": "20.8.0",
|
|
4
|
-
"date": "2025-12-10T21:01:48.069Z",
|
|
5
|
-
"iterations": 200000,
|
|
6
|
-
"warmup": 20000
|
|
7
|
-
},
|
|
8
|
-
"exact": {
|
|
9
|
-
"node:events": {
|
|
10
|
-
"opsPerSec": 24776623.201804563,
|
|
11
|
-
"nsPerOp": 40.360625088214874,
|
|
12
|
-
"durationMs": 8.072125017642975
|
|
13
|
-
},
|
|
14
|
-
"eventemitter3": {
|
|
15
|
-
"opsPerSec": 65228913.23291844,
|
|
16
|
-
"nsPerOp": 15.330624878406525,
|
|
17
|
-
"durationMs": 3.066124975681305
|
|
18
|
-
},
|
|
19
|
-
"eventemitter2": {
|
|
20
|
-
"opsPerSec": 33949372.862869516,
|
|
21
|
-
"nsPerOp": 29.455625116825104,
|
|
22
|
-
"durationMs": 5.891125023365021
|
|
23
|
-
},
|
|
24
|
-
"emittery": {
|
|
25
|
-
"opsPerSec": 513965.4579144545,
|
|
26
|
-
"nsPerOp": 1945.656044781208,
|
|
27
|
-
"durationMs": 389.1312089562416
|
|
28
|
-
},
|
|
29
|
-
"mitt": {
|
|
30
|
-
"opsPerSec": 18363434.3054735,
|
|
31
|
-
"nsPerOp": 54.45604473352432,
|
|
32
|
-
"durationMs": 10.891208946704865
|
|
33
|
-
},
|
|
34
|
-
"tseep": {
|
|
35
|
-
"skipped": true,
|
|
36
|
-
"reason": "module not installed"
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
"wildcard": {
|
|
40
|
-
"eventemitter2": {
|
|
41
|
-
"opsPerSec": 2834857.194209256,
|
|
42
|
-
"nsPerOp": 352.7514550089836,
|
|
43
|
-
"durationMs": 70.55029100179672
|
|
44
|
-
},
|
|
45
|
-
"emittery": {
|
|
46
|
-
"opsPerSec": 250568.0195367393,
|
|
47
|
-
"nsPerOp": 3990.932289958,
|
|
48
|
-
"durationMs": 798.1864579916
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Baseline benchmark runner for competitor event emitters.
|
|
4
|
-
* Captures exact-match (3 args) and wildcard (if supported) throughput.
|
|
5
|
-
* Designed to run before HyperEmitter lands, producing JSON baselines for regression checks.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const fs = require('node:fs');
|
|
9
|
-
const path = require('node:path');
|
|
10
|
-
const { performance } = require('node:perf_hooks');
|
|
11
|
-
|
|
12
|
-
const args = process.argv.slice(2);
|
|
13
|
-
const ciMode = args.includes('--ci');
|
|
14
|
-
const iterationsArg = getArgValue(args, '--iterations');
|
|
15
|
-
const outputArg = getArgValue(args, '--output');
|
|
16
|
-
|
|
17
|
-
const ITERATIONS = iterationsArg ? Number(iterationsArg) : 500_000;
|
|
18
|
-
const WARMUP = 20_000;
|
|
19
|
-
|
|
20
|
-
const OUT_DIR = path.join(__dirname, 'results');
|
|
21
|
-
const OUT_FILE =
|
|
22
|
-
outputArg ||
|
|
23
|
-
path.join(OUT_DIR, `baseline-node-${process.versions.node}.json`);
|
|
24
|
-
|
|
25
|
-
ensureDir(OUT_DIR);
|
|
26
|
-
|
|
27
|
-
const competitors = [
|
|
28
|
-
{
|
|
29
|
-
name: 'node:events',
|
|
30
|
-
supportsWildcard: false,
|
|
31
|
-
setupExact: () => {
|
|
32
|
-
const { EventEmitter } = require('node:events');
|
|
33
|
-
const emitter = new EventEmitter();
|
|
34
|
-
const handler = noop;
|
|
35
|
-
emitter.on('test.event', handler);
|
|
36
|
-
return () => emitter.emit('test.event', 1, 2, 3);
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: 'eventemitter3',
|
|
41
|
-
module: 'eventemitter3',
|
|
42
|
-
supportsWildcard: false,
|
|
43
|
-
setupExact: (mod) => {
|
|
44
|
-
const emitter = new mod();
|
|
45
|
-
const handler = noop;
|
|
46
|
-
emitter.on('test.event', handler);
|
|
47
|
-
return () => emitter.emit('test.event', 1, 2, 3);
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
name: 'eventemitter2',
|
|
52
|
-
module: 'eventemitter2',
|
|
53
|
-
supportsWildcard: true,
|
|
54
|
-
setupExact: (mod) => {
|
|
55
|
-
const emitter = new mod();
|
|
56
|
-
const handler = noop;
|
|
57
|
-
emitter.on('test.event', handler);
|
|
58
|
-
return () => emitter.emit('test.event', 1, 2, 3);
|
|
59
|
-
},
|
|
60
|
-
setupWildcard: (mod) => {
|
|
61
|
-
const emitter = new mod({ wildcard: true, delimiter: '.' });
|
|
62
|
-
const handler = noop;
|
|
63
|
-
emitter.on('a.**', handler); // multi-level wildcard
|
|
64
|
-
return () => emitter.emit('a.b.c', 1, 2, 3);
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
name: 'emittery',
|
|
69
|
-
module: 'emittery',
|
|
70
|
-
supportsWildcard: true,
|
|
71
|
-
setupExact: (mod) => {
|
|
72
|
-
const emitter = new mod();
|
|
73
|
-
const handler = noop;
|
|
74
|
-
emitter.on('test.event', handler);
|
|
75
|
-
return () => emitter.emit('test.event', { args: [1, 2, 3] });
|
|
76
|
-
},
|
|
77
|
-
setupWildcard: (mod) => {
|
|
78
|
-
const emitter = new mod();
|
|
79
|
-
const handler = noop;
|
|
80
|
-
emitter.on('a.*', handler);
|
|
81
|
-
return () => emitter.emit('a.b', { args: [1, 2, 3] });
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
name: 'mitt',
|
|
86
|
-
module: 'mitt',
|
|
87
|
-
supportsWildcard: false,
|
|
88
|
-
setupExact: (mod) => {
|
|
89
|
-
const emitter = mod.default ? mod.default() : mod();
|
|
90
|
-
const handler = noop;
|
|
91
|
-
emitter.on('test.event', handler);
|
|
92
|
-
return () => emitter.emit('test.event', { args: [1, 2, 3] });
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
name: 'tseep',
|
|
97
|
-
module: 'tseep',
|
|
98
|
-
supportsWildcard: false,
|
|
99
|
-
setupExact: (mod) => {
|
|
100
|
-
const emitter = new mod();
|
|
101
|
-
const handler = noop;
|
|
102
|
-
emitter.on('test.event', handler);
|
|
103
|
-
return () => emitter.emit('test.event', 1, 2, 3);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
];
|
|
107
|
-
|
|
108
|
-
const results = {
|
|
109
|
-
meta: {
|
|
110
|
-
nodeVersion: process.versions.node,
|
|
111
|
-
date: new Date().toISOString(),
|
|
112
|
-
iterations: ITERATIONS,
|
|
113
|
-
warmup: WARMUP
|
|
114
|
-
},
|
|
115
|
-
exact: {},
|
|
116
|
-
wildcard: {}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
for (const competitor of competitors) {
|
|
120
|
-
const mod = competitor.module ? tryRequire(competitor.module) : null;
|
|
121
|
-
if (competitor.module && !mod) {
|
|
122
|
-
results.exact[competitor.name] = skip('module not installed');
|
|
123
|
-
if (competitor.supportsWildcard) {
|
|
124
|
-
results.wildcard[competitor.name] = skip('module not installed');
|
|
125
|
-
}
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Exact match benchmark
|
|
130
|
-
if (competitor.setupExact) {
|
|
131
|
-
const runner = competitor.setupExact(mod);
|
|
132
|
-
results.exact[competitor.name] = runBenchmark(runner);
|
|
133
|
-
} else {
|
|
134
|
-
results.exact[competitor.name] = skip('no exact benchmark');
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// Wildcard benchmark
|
|
138
|
-
if (competitor.supportsWildcard && competitor.setupWildcard) {
|
|
139
|
-
const runner = competitor.setupWildcard(mod);
|
|
140
|
-
results.wildcard[competitor.name] = runBenchmark(runner);
|
|
141
|
-
} else if (competitor.supportsWildcard) {
|
|
142
|
-
results.wildcard[competitor.name] = skip('no wildcard benchmark');
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
fs.writeFileSync(OUT_FILE, JSON.stringify(results, null, 2));
|
|
147
|
-
|
|
148
|
-
if (!ciMode) {
|
|
149
|
-
console.log('Baseline benchmarks complete.');
|
|
150
|
-
console.log(`Saved to: ${OUT_FILE}`);
|
|
151
|
-
console.table(formatTable(results.exact, 'exact ops/sec'));
|
|
152
|
-
if (Object.keys(results.wildcard).length) {
|
|
153
|
-
console.table(formatTable(results.wildcard, 'wildcard ops/sec'));
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function runBenchmark(fn) {
|
|
158
|
-
// Warmup
|
|
159
|
-
for (let i = 0; i < WARMUP; i++) {
|
|
160
|
-
fn();
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
const start = performance.now();
|
|
164
|
-
for (let i = 0; i < ITERATIONS; i++) {
|
|
165
|
-
fn();
|
|
166
|
-
}
|
|
167
|
-
const end = performance.now();
|
|
168
|
-
|
|
169
|
-
const durationMs = end - start;
|
|
170
|
-
const opsPerSec = (ITERATIONS / durationMs) * 1000;
|
|
171
|
-
const nsPerOp = (durationMs * 1_000_000) / ITERATIONS;
|
|
172
|
-
|
|
173
|
-
return {
|
|
174
|
-
opsPerSec,
|
|
175
|
-
nsPerOp,
|
|
176
|
-
durationMs
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function tryRequire(name) {
|
|
181
|
-
try {
|
|
182
|
-
return require(name);
|
|
183
|
-
} catch (err) {
|
|
184
|
-
if (!ciMode) {
|
|
185
|
-
console.warn(`Skipping ${name}: ${err.message}`);
|
|
186
|
-
}
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function skip(reason) {
|
|
192
|
-
return { skipped: true, reason };
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function ensureDir(dir) {
|
|
196
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function getArgValue(argv, key) {
|
|
200
|
-
const idx = argv.indexOf(key);
|
|
201
|
-
if (idx === -1) return undefined;
|
|
202
|
-
return argv[idx + 1];
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function formatTable(map, label) {
|
|
206
|
-
const table = {};
|
|
207
|
-
for (const [name, result] of Object.entries(map)) {
|
|
208
|
-
table[name] = result.skipped
|
|
209
|
-
? result.reason
|
|
210
|
-
: `${result.opsPerSec.toFixed(2)} ops/s (${result.nsPerOp.toFixed(2)} ns/op)`;
|
|
211
|
-
}
|
|
212
|
-
return table;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function noop() {}
|
package/src/core/HyperEmitter.ts
DELETED
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
import { EventEmitter as NodeEmitter } from 'node:events';
|
|
2
|
-
import { RadixTree } from '../routing/RadixTree.js';
|
|
3
|
-
import { ListenerOptions, HyperEmitterOptions } from '../types/index.js';
|
|
4
|
-
import {
|
|
5
|
-
ListenerRecord,
|
|
6
|
-
attachAbort,
|
|
7
|
-
cleanupAbort,
|
|
8
|
-
createRecord
|
|
9
|
-
} from '../utils/listener.js';
|
|
10
|
-
import { createLogger, Logger } from '@open-wa/logger';
|
|
11
|
-
import type { LogContext } from '@open-wa/logger';
|
|
12
|
-
|
|
13
|
-
type AnyFn = (...args: any[]) => any;
|
|
14
|
-
|
|
15
|
-
export class HyperEmitter<TMap extends object = Record<string, unknown>> {
|
|
16
|
-
private readonly delimiter: string;
|
|
17
|
-
private readonly captureRejections: boolean;
|
|
18
|
-
private readonly onError?: (err: unknown) => void;
|
|
19
|
-
private readonly finalizer?: FinalizationRegistry<unknown>;
|
|
20
|
-
private readonly logger?: Logger;
|
|
21
|
-
private readonly debugEnabled: boolean;
|
|
22
|
-
private readonly baseLogContext: LogContext;
|
|
23
|
-
|
|
24
|
-
private exactListeners: Map<string, ListenerRecord<AnyFn>[]>;
|
|
25
|
-
private wildcardTree: RadixTree<ListenerRecord<AnyFn>>;
|
|
26
|
-
private wildcardIndex: Map<ListenerRecord<AnyFn>, string>;
|
|
27
|
-
private hasWildcards = false;
|
|
28
|
-
private anyListeners: Set<(event: string, payload: any) => void> = new Set();
|
|
29
|
-
|
|
30
|
-
constructor(options: HyperEmitterOptions = {}) {
|
|
31
|
-
this.delimiter = options.delimiter ?? '.';
|
|
32
|
-
this.captureRejections = options.captureRejections ?? false;
|
|
33
|
-
this.onError = options.onError;
|
|
34
|
-
this.debugEnabled = !!options.debug;
|
|
35
|
-
this.baseLogContext = {
|
|
36
|
-
component: 'hyperemitter',
|
|
37
|
-
...options.loggerContext
|
|
38
|
-
};
|
|
39
|
-
this.logger =
|
|
40
|
-
options.logger?.withContext?.(this.baseLogContext) ??
|
|
41
|
-
createLogger({ component: 'hyperemitter', ...options.loggerContext });
|
|
42
|
-
|
|
43
|
-
// WeakRef support
|
|
44
|
-
if (typeof FinalizationRegistry !== 'undefined') {
|
|
45
|
-
this.finalizer = new FinalizationRegistry((token: unknown) => {
|
|
46
|
-
if (token && typeof token === 'object') {
|
|
47
|
-
// token is used only for unregister; actual removal is handled during emit via deref
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.exactListeners = new Map();
|
|
53
|
-
this.wildcardTree = new RadixTree<ListenerRecord<AnyFn>>(this.delimiter);
|
|
54
|
-
this.wildcardIndex = new Map();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
on<K extends keyof TMap & string>(
|
|
58
|
-
event: K,
|
|
59
|
-
listener: (payload: TMap[K]) => void | Promise<void>,
|
|
60
|
-
options: ListenerOptions = {}
|
|
61
|
-
): this {
|
|
62
|
-
const record = createRecord(listener as AnyFn, options, this.finalizer as any);
|
|
63
|
-
this.add(event, record);
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
once<K extends keyof TMap & string>(
|
|
68
|
-
event: K,
|
|
69
|
-
listener: (payload: TMap[K]) => void | Promise<void>,
|
|
70
|
-
options: ListenerOptions = {}
|
|
71
|
-
): this {
|
|
72
|
-
const record = createRecord(listener as AnyFn, options, this.finalizer as any);
|
|
73
|
-
record.once = true;
|
|
74
|
-
this.add(event, record);
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
off<K extends keyof TMap & string>(event: K, listener: (payload: TMap[K]) => void | Promise<void>): this {
|
|
79
|
-
const list = this.exactListeners.get(event);
|
|
80
|
-
if (list) {
|
|
81
|
-
const idx = list.findIndex(l => l.fn === listener);
|
|
82
|
-
if (idx !== -1) {
|
|
83
|
-
cleanupAbort(list[idx]);
|
|
84
|
-
list.splice(idx, 1);
|
|
85
|
-
}
|
|
86
|
-
if (list.length === 0) this.exactListeners.delete(event);
|
|
87
|
-
}
|
|
88
|
-
if (this.hasWildcards && (event.includes('+') || event.includes('#'))) {
|
|
89
|
-
this.removeWildcard(event, listener as AnyFn);
|
|
90
|
-
}
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
emit<K extends keyof TMap & string>(
|
|
95
|
-
event: K,
|
|
96
|
-
payload: TMap[K]
|
|
97
|
-
): boolean {
|
|
98
|
-
const exact = this.exactListeners.get(event as string);
|
|
99
|
-
const wildcard = this.hasWildcards
|
|
100
|
-
? this.wildcardTree.match(event as string)
|
|
101
|
-
: undefined;
|
|
102
|
-
|
|
103
|
-
const called = this.dispatch(exact, [payload]) | this.dispatch(wildcard, [payload]);
|
|
104
|
-
|
|
105
|
-
// Notify catch-all listeners
|
|
106
|
-
for (const listener of this.anyListeners) {
|
|
107
|
-
try {
|
|
108
|
-
listener(event as string, payload);
|
|
109
|
-
} catch { /* swallow */ }
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return Boolean(called);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Register a catch-all listener that fires on every emit with (event, payload).
|
|
117
|
-
* Useful for event bridging / debugging.
|
|
118
|
-
*/
|
|
119
|
-
onAny(listener: (event: string, payload: any) => void): this {
|
|
120
|
-
this.anyListeners.add(listener);
|
|
121
|
-
return this;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Remove a catch-all listener registered via onAny.
|
|
126
|
-
*/
|
|
127
|
-
offAny(listener: (event: string, payload: any) => void): this {
|
|
128
|
-
this.anyListeners.delete(listener);
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
listenerCount(event?: keyof TMap & string): number {
|
|
133
|
-
if (!event) {
|
|
134
|
-
let total = 0;
|
|
135
|
-
for (const arr of this.exactListeners.values()) total += arr.length;
|
|
136
|
-
return total;
|
|
137
|
-
}
|
|
138
|
-
return this.exactListeners.get(event)?.length ?? 0;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
removeAllListeners(event?: keyof TMap & string): this {
|
|
142
|
-
if (!event) {
|
|
143
|
-
for (const arr of this.exactListeners.values()) {
|
|
144
|
-
arr.forEach(cleanupAbort);
|
|
145
|
-
}
|
|
146
|
-
this.exactListeners.clear();
|
|
147
|
-
this.wildcardTree = new RadixTree<ListenerRecord<AnyFn>>(this.delimiter);
|
|
148
|
-
this.hasWildcards = false;
|
|
149
|
-
this.wildcardIndex.clear();
|
|
150
|
-
return this;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const list = this.exactListeners.get(event);
|
|
154
|
-
if (list) {
|
|
155
|
-
list.forEach(cleanupAbort);
|
|
156
|
-
this.exactListeners.delete(event);
|
|
157
|
-
}
|
|
158
|
-
// Wildcards: best effort clear by rebuilding tree
|
|
159
|
-
if (this.hasWildcards && (event.includes('+') || event.includes('#'))) {
|
|
160
|
-
for (const [record, pattern] of this.wildcardIndex.entries()) {
|
|
161
|
-
if (pattern === event) {
|
|
162
|
-
this.wildcardTree.remove(pattern, record);
|
|
163
|
-
this.wildcardIndex.delete(record);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return this;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Bridge from a Node EventEmitter: forward Node events into this emitter.
|
|
172
|
-
*/
|
|
173
|
-
fromNodeEmitter(emitter: NodeEmitter, event: string): () => void {
|
|
174
|
-
const handler = (...args: any[]) => {
|
|
175
|
-
// @ts-expect-error safe runtime emit
|
|
176
|
-
this.emit(event as any, ...args);
|
|
177
|
-
};
|
|
178
|
-
emitter.on(event, handler);
|
|
179
|
-
return () => emitter.off(event, handler);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Bridge to a Node EventEmitter: emit HyperEmitter events on a provided Node emitter.
|
|
184
|
-
*/
|
|
185
|
-
toNodeEmitter(target: NodeEmitter): () => void {
|
|
186
|
-
const forwarder = (event: string, args: any[]) => target.emit(event, ...args);
|
|
187
|
-
// naive bridge: wrap emit; caller can replace as needed
|
|
188
|
-
const original = (this as any).emit;
|
|
189
|
-
(this as any).emit = (ev: string, ...args: any[]) => {
|
|
190
|
-
forwarder(ev, args);
|
|
191
|
-
return original.call(this, ev, ...args);
|
|
192
|
-
};
|
|
193
|
-
return () => {
|
|
194
|
-
(this as any).emit = original;
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Attach a handler to an EventTarget and re-emit through HyperEmitter.
|
|
200
|
-
*/
|
|
201
|
-
onEventTarget(target: EventTarget, type: string, eventName: keyof TMap & string) {
|
|
202
|
-
const handler = (ev: Event) => {
|
|
203
|
-
// @ts-expect-error forwarding payload
|
|
204
|
-
this.emit(eventName, ev);
|
|
205
|
-
};
|
|
206
|
-
target.addEventListener(type, handler);
|
|
207
|
-
return () => target.removeEventListener(type, handler);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
private add(event: string, record: ListenerRecord<AnyFn>) {
|
|
211
|
-
// Wildcard patterns contain '+' or '#'
|
|
212
|
-
const isWildcard = event.includes('+') || event.includes('#');
|
|
213
|
-
if (isWildcard) {
|
|
214
|
-
this.hasWildcards = true;
|
|
215
|
-
this.wildcardTree.insert(event, record);
|
|
216
|
-
this.wildcardIndex.set(record, event);
|
|
217
|
-
} else {
|
|
218
|
-
const list = this.exactListeners.get(event);
|
|
219
|
-
if (list) {
|
|
220
|
-
list.push(record);
|
|
221
|
-
} else {
|
|
222
|
-
this.exactListeners.set(event, [record]);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
attachAbort(record, () => this.off(event as any, record.fn as any));
|
|
227
|
-
this.logDebug('listener_registered', {
|
|
228
|
-
event,
|
|
229
|
-
once: record.once,
|
|
230
|
-
wildcard: isWildcard
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
private dispatch(list: ListenerRecord<AnyFn>[] | undefined, args: any[]): number {
|
|
235
|
-
if (!list || list.length === 0) return 0;
|
|
236
|
-
// Copy-on-write to avoid mutation during emit.
|
|
237
|
-
const snapshot = list.slice();
|
|
238
|
-
let called = 0;
|
|
239
|
-
for (const record of snapshot) {
|
|
240
|
-
// WeakRef cleanup: if target gone, remove and skip.
|
|
241
|
-
if (record.weakRef && !record.weakRef.deref()) {
|
|
242
|
-
this.offListener(record);
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
called++;
|
|
247
|
-
const result = this.invoke(record, args);
|
|
248
|
-
if (record.once) {
|
|
249
|
-
this.offListener(record);
|
|
250
|
-
}
|
|
251
|
-
if (result && typeof result.then === 'function') {
|
|
252
|
-
result.catch((err: unknown) => this.handleRejection(record, err));
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return called;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
private invoke(record: ListenerRecord<AnyFn>, args: any[]) {
|
|
259
|
-
switch (args.length) {
|
|
260
|
-
case 0:
|
|
261
|
-
return record.fn();
|
|
262
|
-
case 1:
|
|
263
|
-
return record.fn(args[0]);
|
|
264
|
-
case 2:
|
|
265
|
-
return record.fn(args[0], args[1]);
|
|
266
|
-
case 3:
|
|
267
|
-
return record.fn(args[0], args[1], args[2]);
|
|
268
|
-
default:
|
|
269
|
-
return record.fn(...args);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
private offListener(record: ListenerRecord<AnyFn>) {
|
|
274
|
-
// Exact listeners
|
|
275
|
-
for (const [event, arr] of this.exactListeners.entries()) {
|
|
276
|
-
const idx = arr.indexOf(record);
|
|
277
|
-
if (idx !== -1) {
|
|
278
|
-
cleanupAbort(arr[idx]);
|
|
279
|
-
arr.splice(idx, 1);
|
|
280
|
-
if (arr.length === 0) this.exactListeners.delete(event);
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
// Wildcard listeners (pattern tracked)
|
|
285
|
-
const pattern = this.wildcardIndex.get(record);
|
|
286
|
-
if (pattern) {
|
|
287
|
-
this.wildcardTree.remove(pattern, record);
|
|
288
|
-
this.wildcardIndex.delete(record);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
private handleRejection(record: ListenerRecord<AnyFn>, err: unknown) {
|
|
293
|
-
const shouldCapture =
|
|
294
|
-
record.captureRejections !== undefined
|
|
295
|
-
? record.captureRejections
|
|
296
|
-
: this.captureRejections;
|
|
297
|
-
|
|
298
|
-
if (!shouldCapture) {
|
|
299
|
-
queueMicrotask(() => {
|
|
300
|
-
throw err;
|
|
301
|
-
});
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (this.onError) {
|
|
306
|
-
try {
|
|
307
|
-
this.onError(err);
|
|
308
|
-
} catch {
|
|
309
|
-
// swallow secondary errors
|
|
310
|
-
}
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// Fallback logging
|
|
315
|
-
this.logger?.error('listener_rejection', {
|
|
316
|
-
error: err as any,
|
|
317
|
-
...this.baseLogContext
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
private removeWildcard(event: string, listener: AnyFn) {
|
|
322
|
-
// Slow path: tree removal requires record reference; search recorded patterns.
|
|
323
|
-
for (const [record, pattern] of this.wildcardIndex.entries()) {
|
|
324
|
-
if (pattern === event && record.fn === listener) {
|
|
325
|
-
this.wildcardTree.remove(pattern, record);
|
|
326
|
-
this.wildcardIndex.delete(record);
|
|
327
|
-
cleanupAbort(record);
|
|
328
|
-
break;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
private logDebug(message: string, meta?: LogContext) {
|
|
334
|
-
if (!this.debugEnabled) return;
|
|
335
|
-
this.logger?.debug(message, { ...this.baseLogContext, ...meta });
|
|
336
|
-
}
|
|
337
|
-
}
|
package/src/index.ts
DELETED
package/src/routing/RadixNode.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Monomorphic radix tree node for MQTT-style wildcard routing.
|
|
3
|
-
*/
|
|
4
|
-
export class RadixNode<T> {
|
|
5
|
-
segment: string;
|
|
6
|
-
listeners: T[];
|
|
7
|
-
children: Map<string, RadixNode<T>> | null;
|
|
8
|
-
wildcardSingle: RadixNode<T> | null; // '+'
|
|
9
|
-
wildcardMulti: RadixNode<T> | null; // '#'
|
|
10
|
-
|
|
11
|
-
constructor(segment: string) {
|
|
12
|
-
// Preserve property order for hidden-class stability.
|
|
13
|
-
this.segment = segment;
|
|
14
|
-
this.listeners = [];
|
|
15
|
-
this.children = null;
|
|
16
|
-
this.wildcardSingle = null;
|
|
17
|
-
this.wildcardMulti = null;
|
|
18
|
-
}
|
|
19
|
-
}
|
package/src/routing/RadixTree.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { RadixNode } from './RadixNode.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Radix tree with MQTT-style wildcards.
|
|
5
|
-
* Complexity: O(K) where K = number of path segments.
|
|
6
|
-
*/
|
|
7
|
-
export class RadixTree<T> {
|
|
8
|
-
private readonly delimiter: string;
|
|
9
|
-
private readonly root: RadixNode<T>;
|
|
10
|
-
|
|
11
|
-
constructor(delimiter = '.') {
|
|
12
|
-
this.delimiter = delimiter;
|
|
13
|
-
this.root = new RadixNode<T>('');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
insert(pattern: string, value: T) {
|
|
17
|
-
const segments = this.tokenize(pattern);
|
|
18
|
-
let node = this.root;
|
|
19
|
-
|
|
20
|
-
for (const segment of segments) {
|
|
21
|
-
if (segment === '+') {
|
|
22
|
-
if (!node.wildcardSingle) node.wildcardSingle = new RadixNode<T>('+');
|
|
23
|
-
node = node.wildcardSingle;
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
if (segment === '#') {
|
|
27
|
-
if (!node.wildcardMulti) node.wildcardMulti = new RadixNode<T>('#');
|
|
28
|
-
node = node.wildcardMulti;
|
|
29
|
-
break; // '#' consumes the rest
|
|
30
|
-
}
|
|
31
|
-
if (!node.children) node.children = new Map();
|
|
32
|
-
let child = node.children.get(segment);
|
|
33
|
-
if (!child) {
|
|
34
|
-
child = new RadixNode<T>(segment);
|
|
35
|
-
node.children.set(segment, child);
|
|
36
|
-
}
|
|
37
|
-
node = child;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
node.listeners.push(value);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
remove(pattern: string, value: T) {
|
|
44
|
-
const path: Array<[RadixNode<T>, string]> = [];
|
|
45
|
-
let node = this.root;
|
|
46
|
-
const segments = this.tokenize(pattern);
|
|
47
|
-
|
|
48
|
-
for (const segment of segments) {
|
|
49
|
-
path.push([node, segment]);
|
|
50
|
-
if (segment === '+') {
|
|
51
|
-
if (!node.wildcardSingle) return;
|
|
52
|
-
node = node.wildcardSingle;
|
|
53
|
-
} else if (segment === '#') {
|
|
54
|
-
if (!node.wildcardMulti) return;
|
|
55
|
-
node = node.wildcardMulti;
|
|
56
|
-
break;
|
|
57
|
-
} else {
|
|
58
|
-
if (!node.children) return;
|
|
59
|
-
const next = node.children.get(segment);
|
|
60
|
-
if (!next) return;
|
|
61
|
-
node = next;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const idx = node.listeners.indexOf(value);
|
|
66
|
-
if (idx !== -1) {
|
|
67
|
-
node.listeners.splice(idx, 1);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
match(event: string): T[] {
|
|
72
|
-
const segments = this.tokenize(event);
|
|
73
|
-
const stack: Array<{ node: RadixNode<T>; index: number }> = [
|
|
74
|
-
{ node: this.root, index: 0 }
|
|
75
|
-
];
|
|
76
|
-
const results: T[] = [];
|
|
77
|
-
|
|
78
|
-
while (stack.length > 0) {
|
|
79
|
-
const { node, index } = stack.pop()!;
|
|
80
|
-
|
|
81
|
-
if (index === segments.length) {
|
|
82
|
-
// Exact depth match
|
|
83
|
-
if (node.listeners.length) results.push(...node.listeners);
|
|
84
|
-
// '#' can also match empty suffix
|
|
85
|
-
if (node.wildcardMulti && node.wildcardMulti.listeners.length) {
|
|
86
|
-
results.push(...node.wildcardMulti.listeners);
|
|
87
|
-
}
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const seg = segments[index];
|
|
92
|
-
|
|
93
|
-
// Exact child
|
|
94
|
-
if (node.children) {
|
|
95
|
-
const child = node.children.get(seg);
|
|
96
|
-
if (child) {
|
|
97
|
-
stack.push({ node: child, index: index + 1 });
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Single-level wildcard '+'
|
|
102
|
-
if (node.wildcardSingle) {
|
|
103
|
-
stack.push({ node: node.wildcardSingle, index: index + 1 });
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Multi-level wildcard '#'
|
|
107
|
-
if (node.wildcardMulti) {
|
|
108
|
-
// '#' consumes the rest, so we can collect listeners directly
|
|
109
|
-
if (node.wildcardMulti.listeners.length) {
|
|
110
|
-
results.push(...node.wildcardMulti.listeners);
|
|
111
|
-
}
|
|
112
|
-
// But it can also match additional segments
|
|
113
|
-
stack.push({ node: node.wildcardMulti, index: index + 1 });
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return results;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
private tokenize(path: string): string[] {
|
|
121
|
-
// Simple tokenizer; allocations are acceptable for initial implementation.
|
|
122
|
-
return path.split(this.delimiter);
|
|
123
|
-
}
|
|
124
|
-
}
|
package/src/types/index.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export type AnyFn = (...args: any[]) => any;
|
|
2
|
-
|
|
3
|
-
export type EventMap = { [key: string]: unknown };
|
|
4
|
-
|
|
5
|
-
export type EventListener<T> = (payload: T) => void | Promise<void>;
|
|
6
|
-
|
|
7
|
-
export interface ListenerOptions {
|
|
8
|
-
/**
|
|
9
|
-
* AbortSignal to auto-remove the listener when aborted.
|
|
10
|
-
*/
|
|
11
|
-
signal?: AbortSignal;
|
|
12
|
-
/**
|
|
13
|
-
* Mark the listener as weak; provide a target object to track.
|
|
14
|
-
* When the target is GC'd, the listener is removed.
|
|
15
|
-
*/
|
|
16
|
-
weak?: object;
|
|
17
|
-
/**
|
|
18
|
-
* Enable captureRejections for this listener (fallbacks to emitter-level).
|
|
19
|
-
*/
|
|
20
|
-
captureRejections?: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface HyperEmitterOptions {
|
|
24
|
-
delimiter?: string;
|
|
25
|
-
captureRejections?: boolean;
|
|
26
|
-
onError?: (error: unknown) => void;
|
|
27
|
-
/**
|
|
28
|
-
* Enable debug logging (uses @open-wa/logger).
|
|
29
|
-
*/
|
|
30
|
-
debug?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Optional logger instance; if omitted, a child logger will be created.
|
|
33
|
-
*/
|
|
34
|
-
logger?: import('@open-wa/logger').Logger;
|
|
35
|
-
/**
|
|
36
|
-
* Additional bound context for logger child.
|
|
37
|
-
*/
|
|
38
|
-
loggerContext?: import('@open-wa/logger').LogContext;
|
|
39
|
-
}
|
package/src/utils/listener.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { ListenerOptions } from '../types/index.js';
|
|
2
|
-
|
|
3
|
-
export type ListenerFn = (...args: any[]) => any;
|
|
4
|
-
|
|
5
|
-
export interface ListenerRecord<T extends ListenerFn> {
|
|
6
|
-
fn: T;
|
|
7
|
-
once: boolean;
|
|
8
|
-
signal?: AbortSignal;
|
|
9
|
-
abortHandler?: () => void;
|
|
10
|
-
weakRef?: WeakRef<object>;
|
|
11
|
-
finalizerToken?: object;
|
|
12
|
-
captureRejections?: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function createRecord<T extends ListenerFn>(
|
|
16
|
-
fn: T,
|
|
17
|
-
opts: ListenerOptions,
|
|
18
|
-
finalizer?: FinalizationRegistry<unknown>
|
|
19
|
-
): ListenerRecord<T> {
|
|
20
|
-
const record: ListenerRecord<T> = {
|
|
21
|
-
fn,
|
|
22
|
-
once: false,
|
|
23
|
-
signal: opts.signal,
|
|
24
|
-
captureRejections: opts.captureRejections
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
if (opts.weak && typeof WeakRef !== 'undefined') {
|
|
28
|
-
const weakRef = new WeakRef(opts.weak);
|
|
29
|
-
record.weakRef = weakRef;
|
|
30
|
-
if (finalizer) {
|
|
31
|
-
const token = {};
|
|
32
|
-
record.finalizerToken = token;
|
|
33
|
-
finalizer.register(opts.weak, token, token);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return record;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function attachAbort(
|
|
41
|
-
record: ListenerRecord<any>,
|
|
42
|
-
remove: () => void
|
|
43
|
-
) {
|
|
44
|
-
if (!record.signal) return;
|
|
45
|
-
if (record.signal.aborted) {
|
|
46
|
-
remove();
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const handler = () => remove();
|
|
50
|
-
record.abortHandler = handler;
|
|
51
|
-
record.signal.addEventListener('abort', handler, { once: true });
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function cleanupAbort(record: ListenerRecord<any>) {
|
|
55
|
-
if (record.signal && record.abortHandler) {
|
|
56
|
-
record.signal.removeEventListener('abort', record.abortHandler);
|
|
57
|
-
record.abortHandler = undefined;
|
|
58
|
-
}
|
|
59
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "src",
|
|
5
|
-
"outDir": "dist",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationMap": true,
|
|
8
|
-
"sourceMap": true,
|
|
9
|
-
"module": "ESNext",
|
|
10
|
-
"target": "ES2022",
|
|
11
|
-
"lib": ["ES2022"],
|
|
12
|
-
"moduleResolution": "Bundler",
|
|
13
|
-
"strict": true,
|
|
14
|
-
"noEmit": false,
|
|
15
|
-
"stripInternal": true,
|
|
16
|
-
"composite": true
|
|
17
|
-
},
|
|
18
|
-
"include": [
|
|
19
|
-
"src/**/*"
|
|
20
|
-
]
|
|
21
|
-
}
|